Skip to content

Commit 30b9cbd

Browse files
committed
Add uBlox GPS
1 parent 3d36579 commit 30b9cbd

File tree

13 files changed

+3675
-55
lines changed

13 files changed

+3675
-55
lines changed

src/madflight/bb/bb_sdcard/BBFS_SD_ESP32.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ SOFTWARE.
3030
#include "SD_MMC.h"
3131

3232
#define _BB_SDFS SD_MMC
33-
#define _BB_SETUP_STR "BB: BB_USE_SDMMC"
33+
#define _BB_SETUP_STR "BB: BB_USE_SDMMC"
3434

3535
#else
3636

3737
#include "SPI.h"
3838
#include "SD.h"
3939

4040
#define _BB_SDFS SD
41-
#define _BB_SETUP_STR "BB: BB_USE_SD"
41+
#define _BB_SETUP_STR "BB: BB_USE_SD"
4242
extern SPIClass *bb_spi;
4343

4444
#endif
@@ -70,14 +70,14 @@ class BBFS_SD : public BBFS {
7070

7171
sd_logOpen(BB_LOG_DIR_NAME);
7272
if(file) {
73-
Serial.printf("BB: start OK - attempt=%d file=%s\n", attempt, filename.c_str());
73+
Serial.printf("BB: start OK - attempt=%d file=%s\n", attempt, filename.c_str());
7474
return true;
7575
}
7676
}
7777

7878
setup_done = false; //force setup to re-run
7979
}
80-
Serial.println("BB: start FAILED");
80+
Serial.println("BB: start FAILED");
8181
return false;
8282
}
8383

@@ -135,13 +135,13 @@ class BBFS_SD : public BBFS {
135135

136136
buf = (uint8_t*)malloc(512);
137137
if(!buf) {
138-
Serial.println("BB: bench - malloc failed");
138+
Serial.println("BB: bench - malloc failed");
139139
return;
140140
}
141141

142142
file = _BB_SDFS.open(path, FILE_WRITE);
143143
if(!file){
144-
Serial.println("BB: bench - Failed to open file for writing");
144+
Serial.println("BB: bench - Failed to open file for writing");
145145
free(buf);
146146
return;
147147
}
@@ -156,12 +156,12 @@ class BBFS_SD : public BBFS {
156156
}
157157
end = millis() - start;
158158
flen = 2048 * 512;
159-
Serial.printf("BB: %s %u bytes written in %u ms %f kbps\r\n", path, (int)flen, (int)end, (float)flen/end);
159+
Serial.printf("BB: %s %u bytes written in %u ms %f kbps\r\n", path, (int)flen, (int)end, (float)flen/end);
160160
file.close();
161161

162162
file = _BB_SDFS.open(path);
163163
if(!file){
164-
Serial.println("BB: bench - Failed to open file for reading");
164+
Serial.println("BB: bench - Failed to open file for reading");
165165
free(buf);
166166
return;
167167
}
@@ -177,7 +177,7 @@ class BBFS_SD : public BBFS {
177177
len -= toRead;
178178
}
179179
end = millis() - start;
180-
Serial.printf("BB: %s %u bytes read in %u ms %f kbps\r\n", path, (int)flen, (int)end, (float)flen/end);
180+
Serial.printf("BB: %s %u bytes read in %u ms %f kbps\r\n", path, (int)flen, (int)end, (float)flen/end);
181181
file.close();
182182

183183
free(buf);
@@ -217,20 +217,20 @@ class BBFS_SD : public BBFS {
217217
#if BB_USE == BB_USE_SDMMC
218218
_BB_SDFS.setPins(HW_PIN_SDMMC_CLK, HW_PIN_SDMMC_CMD, HW_PIN_SDMMC_DATA);
219219
if (!_BB_SDFS.begin("/sdcard", true, true, SDMMC_FREQ_DEFAULT, 5)) {
220-
Serial.println("BB_USE_SDMMC Card Mount Failed");
220+
Serial.println("BB: BB_USE_SDMMC Card Mount Failed");
221221
return setup_done;
222222
}
223223
#else
224224
bb_spi->begin(HW_PIN_SPI2_SCLK, HW_PIN_SPI2_MISO, HW_PIN_SPI2_MOSI, HW_PIN_BB_CS);
225225
if (!_BB_SDFS.begin(HW_PIN_BB_CS, *bb_spi)) {
226-
Serial.println("BB_USE_SD Card Mount Failed");
226+
Serial.println("BB: BB_USE_SD Card Mount Failed");
227227
return setup_done;
228228
}
229229
#endif
230230

231231
uint8_t cardType = _BB_SDFS.cardType();
232232
if(cardType == CARD_NONE){
233-
Serial.println("BB: No SD card attached");
233+
Serial.println("BB: No SD card attached");
234234
return setup_done;
235235
}
236236

@@ -284,17 +284,17 @@ class BBFS_SD : public BBFS {
284284
File root = _BB_SDFS.open(dirname);
285285
if(!root){
286286
if(!_BB_SDFS.mkdir(dirname)){
287-
Serial.println("BB: mkdir /log failed");
287+
Serial.println("BB: mkdir /log failed");
288288
return;
289289
}
290290
root = _BB_SDFS.open(dirname);
291291
if(!root) {
292-
Serial.println("BB: mkdir /log failed");
292+
Serial.println("BB: mkdir /log failed");
293293
return;
294294
}
295295
}
296296
if(!root.isDirectory()){
297-
Serial.println("BB: /log is not a directory");
297+
Serial.println("BB: /log is not a directory");
298298
return;
299299
}
300300

src/madflight/bb/bb_sdcard/BBFS_SD_RP2040.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class BBFS_SD : public BBFS {
4242
public:
4343
//setup the file system
4444
void setup() override {
45-
Serial.println("BB: BB_USE_SD");
45+
Serial.println("BB: BB_USE_SD");
4646
sd_setup();
4747
}
4848

@@ -57,15 +57,15 @@ class BBFS_SD : public BBFS {
5757

5858
sd_logOpen(BB_LOG_DIR_NAME);
5959
if(file) {
60-
Serial.printf("BB: start OK - attempt=%d file=%s\n", attempt, filename.c_str());
60+
Serial.printf("BB: start OK - attempt=%d file=%s\n", attempt, filename.c_str());
6161
return true;
6262
}
6363
}
6464

65-
Serial.println("BB: start retry");
65+
Serial.println("BB: start retry");
6666
setup_done = false; //force setup to re-run
6767
}
68-
Serial.println("BB: start FAILED");
68+
Serial.println("BB: start FAILED");
6969
return false;
7070
}
7171

@@ -100,7 +100,7 @@ class BBFS_SD : public BBFS {
100100
int len = file.size();
101101
file.close();
102102
file = {};
103-
Serial.printf("BB: stop file=%s len=%d\n", filename.c_str(), len);
103+
Serial.printf("BB: stop file=%s len=%d\n", filename.c_str(), len);
104104
}
105105
}
106106

@@ -131,7 +131,7 @@ class BBFS_SD : public BBFS {
131131

132132
buf = (uint8_t*)malloc(512);
133133
if(!buf) {
134-
Serial.println("BB: bench - malloc failed");
134+
Serial.println("BB: bench - malloc failed");
135135
return;
136136
}
137137

@@ -141,7 +141,7 @@ class BBFS_SD : public BBFS {
141141

142142
file = SD.open(path, FILE_WRITE);
143143
if(!file){
144-
Serial.println("BB: bench - Failed to open file for writing");
144+
Serial.println("BB: bench - Failed to open file for writing");
145145
free(buf);
146146
return;
147147
}
@@ -156,12 +156,12 @@ class BBFS_SD : public BBFS {
156156
}
157157
end = millis() - start;
158158
flen = 2048 * 512;
159-
Serial.printf("BB: %s %u bytes written in %u ms %f kbps\r\n", path, (int)flen, (int)end, (float)flen/end);
159+
Serial.printf("BB: %s %u bytes written in %u ms %f kbps\r\n", path, (int)flen, (int)end, (float)flen/end);
160160
file.close();
161161

162162
file = SD.open(path);
163163
if(!file){
164-
Serial.println("BB: bench - Failed to open file for reading");
164+
Serial.println("BB: bench - Failed to open file for reading");
165165
free(buf);
166166
return;
167167
}
@@ -177,7 +177,7 @@ class BBFS_SD : public BBFS {
177177
len -= toRead;
178178
}
179179
end = millis() - start;
180-
Serial.printf("BB: %s %u bytes read in %u ms %f kbps\r\n", path, (int)flen, (int)end, (float)flen/end);
180+
Serial.printf("BB: %s %u bytes read in %u ms %f kbps\r\n", path, (int)flen, (int)end, (float)flen/end);
181181
file.close();
182182

183183
free(buf);
@@ -283,7 +283,7 @@ class BBFS_SD : public BBFS {
283283
*/
284284

285285
if (!SD.begin(HW_PIN_BB_CS, *bb_spi)) {
286-
Serial.println("BB: Card Mount Failed");
286+
Serial.println("BB: Card Mount Failed");
287287
setup_done = false;
288288
return setup_done;
289289
}
@@ -338,17 +338,17 @@ class BBFS_SD : public BBFS {
338338
File root = SD.open(dirname);
339339
if(!root){
340340
if(!SD.mkdir(dirname)){
341-
Serial.println("BB: mkdir /log failed");
341+
Serial.println("BB: mkdir /log failed");
342342
return;
343343
}
344344
root = SD.open(dirname);
345345
if(!root) {
346-
Serial.println("BB: mkdir /log failed");
346+
Serial.println("BB: mkdir /log failed");
347347
return;
348348
}
349349
}
350350
if(!root.isDirectory()){
351-
Serial.println("BB: /log is not a directory");
351+
Serial.println("BB: /log is not a directory");
352352
return;
353353
}
354354

src/madflight/bb/bb_sdcard/bb_sdcard.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,14 @@ class BinLog {
266266
FMT_msglen += datalen;
267267
if (FMT_msglen >= MAX_MSG_LEN) {
268268
error = true;
269-
Serial.printf("BB: ERROR data too long for msg %s\n", FMT.name);
269+
Serial.printf("BB: ERROR data too long for msg %s\n", FMT.name);
270270
return;
271271
}
272272

273273
//datatype
274274
if (FMT_fmt >= 16) {
275275
error = true;
276-
Serial.printf("BB: ERROR too many fields for msg %s\n", FMT.name);
276+
Serial.printf("BB: ERROR too many fields for msg %s\n", FMT.name);
277277
return;
278278
}
279279
FMT.format[FMT_fmt] = fmt;
@@ -303,7 +303,7 @@ class BinLog {
303303
int lbl_len = strlen(label);
304304
if (FMT_lbl + 1 + lbl_len > 64) {
305305
FMT.format[0]=0;
306-
Serial.printf("BB: ERROR labels too long for msg %s\n", FMT.name);
306+
Serial.printf("BB: ERROR labels too long for msg %s\n", FMT.name);
307307
return;
308308
}
309309
if (FMT_lbl) FMT.labels[FMT_lbl++] = ',';
@@ -497,7 +497,7 @@ class BinLog {
497497
static void setup() {
498498
queue = xQueueCreateStatic(QUEUE_LENGTH, sizeof(msg_t), ucQueueStorageArea, &xStaticQueue);
499499
if(xTaskCreate(bb_task, "BB", FREERTOS_DEFAULT_STACK_SIZE, NULL, uxTaskPriorityGet(NULL), &xHandle) != pdPASS ){
500-
Serial.println("BB: Task creation failed");
500+
Serial.println("BB: Task creation failed");
501501
}
502502
}
503503

src/madflight/cli/cli.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ static void cli_print_baro() {
146146

147147
void cli_print_gps() {
148148
Serial.printf("gps.time:%d\t", (int)gps.time);
149-
Serial.printf("date:%d\t", (int)gps.date);
149+
Serial.printf("fix:%d\t", (int)gps.fix);
150+
//Serial.printf("date:%d\t", (int)gps.date);
150151
Serial.printf("sat:%d\t", (int)gps.sat);
151152
Serial.printf("lat:%d\t", (int)gps.lat);
152153
Serial.printf("lon:%d\t", (int)gps.lon);
@@ -478,17 +479,17 @@ class CLI {
478479
}
479480

480481
void print_i2cScan() {
481-
Serial.printf("I2C: Scanning ...\n");
482+
Serial.printf("I2C: Scanning ...\n");
482483
byte count = 0;
483484
//i2c->begin();
484485
for (byte i = 8; i < 120; i++) {
485486
i2c->beginTransmission(i); // Begin I2C transmission Address (i)
486487
if (i2c->endTransmission() == 0) { // Receive 0 = success (ACK response)
487-
Serial.printf("I2C: Found address: 0x%02X (%d)\n",i,i);
488+
Serial.printf("I2C: Found address: 0x%02X (%d)\n",i,i);
488489
count++;
489490
}
490491
}
491-
Serial.printf("I2C: Found %d device(s)\n", count);
492+
Serial.printf("I2C: Found %d device(s)\n", count);
492493
}
493494

494495
//========================================================================================================================//
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# GPS-uBlox - Platform agnostic C++ uBlox GPS driver
2+
3+
Ported from tried and tested Ardupilot GPS UBLOX driver.
4+
5+
Features:
6+
7+
- Platform agnostic C++ (Arduino, PlatformIO, Linux, Windows, whatever...)
8+
- Supports uBlox-6 to uBlox-M10 GPS
9+
- Automatically configures baudrate
10+
- Uses high speed ubx protocol
11+
- Auto reconnect on communication loss
12+
- Optionally save the config to the GPS module for faster restarts
13+
14+
Changes from ArduPilot:
15+
16+
- Moved all external dependencies into AP_GPS_UBLOX.h & .cpp
17+
- Added pure virtual I_xxx methods as interface to the outside world
18+
- Removed float (except LOGGING)
19+
20+
Requirements:
21+
22+
See example directory. Basically, implement the 7 pure virtual methods to get going.

0 commit comments

Comments
 (0)