Skip to content

Commit

Permalink
Add uBlox GPS
Browse files Browse the repository at this point in the history
  • Loading branch information
qqqlab committed Feb 11, 2025
1 parent 3d36579 commit 30b9cbd
Show file tree
Hide file tree
Showing 13 changed files with 3,675 additions and 55 deletions.
30 changes: 15 additions & 15 deletions src/madflight/bb/bb_sdcard/BBFS_SD_ESP32.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ SOFTWARE.
#include "SD_MMC.h"

#define _BB_SDFS SD_MMC
#define _BB_SETUP_STR "BB: BB_USE_SDMMC"
#define _BB_SETUP_STR "BB: BB_USE_SDMMC"

#else

#include "SPI.h"
#include "SD.h"

#define _BB_SDFS SD
#define _BB_SETUP_STR "BB: BB_USE_SD"
#define _BB_SETUP_STR "BB: BB_USE_SD"
extern SPIClass *bb_spi;

#endif
Expand Down Expand Up @@ -70,14 +70,14 @@ class BBFS_SD : public BBFS {

sd_logOpen(BB_LOG_DIR_NAME);
if(file) {
Serial.printf("BB: start OK - attempt=%d file=%s\n", attempt, filename.c_str());
Serial.printf("BB: start OK - attempt=%d file=%s\n", attempt, filename.c_str());
return true;
}
}

setup_done = false; //force setup to re-run
}
Serial.println("BB: start FAILED");
Serial.println("BB: start FAILED");
return false;
}

Expand Down Expand Up @@ -135,13 +135,13 @@ class BBFS_SD : public BBFS {

buf = (uint8_t*)malloc(512);
if(!buf) {
Serial.println("BB: bench - malloc failed");
Serial.println("BB: bench - malloc failed");
return;
}

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

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

free(buf);
Expand Down Expand Up @@ -217,20 +217,20 @@ class BBFS_SD : public BBFS {
#if BB_USE == BB_USE_SDMMC
_BB_SDFS.setPins(HW_PIN_SDMMC_CLK, HW_PIN_SDMMC_CMD, HW_PIN_SDMMC_DATA);
if (!_BB_SDFS.begin("/sdcard", true, true, SDMMC_FREQ_DEFAULT, 5)) {
Serial.println("BB_USE_SDMMC Card Mount Failed");
Serial.println("BB: BB_USE_SDMMC Card Mount Failed");
return setup_done;
}
#else
bb_spi->begin(HW_PIN_SPI2_SCLK, HW_PIN_SPI2_MISO, HW_PIN_SPI2_MOSI, HW_PIN_BB_CS);
if (!_BB_SDFS.begin(HW_PIN_BB_CS, *bb_spi)) {
Serial.println("BB_USE_SD Card Mount Failed");
Serial.println("BB: BB_USE_SD Card Mount Failed");
return setup_done;
}
#endif

uint8_t cardType = _BB_SDFS.cardType();
if(cardType == CARD_NONE){
Serial.println("BB: No SD card attached");
Serial.println("BB: No SD card attached");
return setup_done;
}

Expand Down Expand Up @@ -284,17 +284,17 @@ class BBFS_SD : public BBFS {
File root = _BB_SDFS.open(dirname);
if(!root){
if(!_BB_SDFS.mkdir(dirname)){
Serial.println("BB: mkdir /log failed");
Serial.println("BB: mkdir /log failed");
return;
}
root = _BB_SDFS.open(dirname);
if(!root) {
Serial.println("BB: mkdir /log failed");
Serial.println("BB: mkdir /log failed");
return;
}
}
if(!root.isDirectory()){
Serial.println("BB: /log is not a directory");
Serial.println("BB: /log is not a directory");
return;
}

Expand Down
28 changes: 14 additions & 14 deletions src/madflight/bb/bb_sdcard/BBFS_SD_RP2040.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class BBFS_SD : public BBFS {
public:
//setup the file system
void setup() override {
Serial.println("BB: BB_USE_SD");
Serial.println("BB: BB_USE_SD");
sd_setup();
}

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

sd_logOpen(BB_LOG_DIR_NAME);
if(file) {
Serial.printf("BB: start OK - attempt=%d file=%s\n", attempt, filename.c_str());
Serial.printf("BB: start OK - attempt=%d file=%s\n", attempt, filename.c_str());
return true;
}
}

Serial.println("BB: start retry");
Serial.println("BB: start retry");
setup_done = false; //force setup to re-run
}
Serial.println("BB: start FAILED");
Serial.println("BB: start FAILED");
return false;
}

Expand Down Expand Up @@ -100,7 +100,7 @@ class BBFS_SD : public BBFS {
int len = file.size();
file.close();
file = {};
Serial.printf("BB: stop file=%s len=%d\n", filename.c_str(), len);
Serial.printf("BB: stop file=%s len=%d\n", filename.c_str(), len);
}
}

Expand Down Expand Up @@ -131,7 +131,7 @@ class BBFS_SD : public BBFS {

buf = (uint8_t*)malloc(512);
if(!buf) {
Serial.println("BB: bench - malloc failed");
Serial.println("BB: bench - malloc failed");
return;
}

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

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

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

free(buf);
Expand Down Expand Up @@ -283,7 +283,7 @@ class BBFS_SD : public BBFS {
*/

if (!SD.begin(HW_PIN_BB_CS, *bb_spi)) {
Serial.println("BB: Card Mount Failed");
Serial.println("BB: Card Mount Failed");
setup_done = false;
return setup_done;
}
Expand Down Expand Up @@ -338,17 +338,17 @@ class BBFS_SD : public BBFS {
File root = SD.open(dirname);
if(!root){
if(!SD.mkdir(dirname)){
Serial.println("BB: mkdir /log failed");
Serial.println("BB: mkdir /log failed");
return;
}
root = SD.open(dirname);
if(!root) {
Serial.println("BB: mkdir /log failed");
Serial.println("BB: mkdir /log failed");
return;
}
}
if(!root.isDirectory()){
Serial.println("BB: /log is not a directory");
Serial.println("BB: /log is not a directory");
return;
}

Expand Down
8 changes: 4 additions & 4 deletions src/madflight/bb/bb_sdcard/bb_sdcard.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,14 @@ class BinLog {
FMT_msglen += datalen;
if (FMT_msglen >= MAX_MSG_LEN) {
error = true;
Serial.printf("BB: ERROR data too long for msg %s\n", FMT.name);
Serial.printf("BB: ERROR data too long for msg %s\n", FMT.name);
return;
}

//datatype
if (FMT_fmt >= 16) {
error = true;
Serial.printf("BB: ERROR too many fields for msg %s\n", FMT.name);
Serial.printf("BB: ERROR too many fields for msg %s\n", FMT.name);
return;
}
FMT.format[FMT_fmt] = fmt;
Expand Down Expand Up @@ -303,7 +303,7 @@ class BinLog {
int lbl_len = strlen(label);
if (FMT_lbl + 1 + lbl_len > 64) {
FMT.format[0]=0;
Serial.printf("BB: ERROR labels too long for msg %s\n", FMT.name);
Serial.printf("BB: ERROR labels too long for msg %s\n", FMT.name);
return;
}
if (FMT_lbl) FMT.labels[FMT_lbl++] = ',';
Expand Down Expand Up @@ -497,7 +497,7 @@ class BinLog {
static void setup() {
queue = xQueueCreateStatic(QUEUE_LENGTH, sizeof(msg_t), ucQueueStorageArea, &xStaticQueue);
if(xTaskCreate(bb_task, "BB", FREERTOS_DEFAULT_STACK_SIZE, NULL, uxTaskPriorityGet(NULL), &xHandle) != pdPASS ){
Serial.println("BB: Task creation failed");
Serial.println("BB: Task creation failed");
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/madflight/cli/cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ static void cli_print_baro() {

void cli_print_gps() {
Serial.printf("gps.time:%d\t", (int)gps.time);
Serial.printf("date:%d\t", (int)gps.date);
Serial.printf("fix:%d\t", (int)gps.fix);
//Serial.printf("date:%d\t", (int)gps.date);
Serial.printf("sat:%d\t", (int)gps.sat);
Serial.printf("lat:%d\t", (int)gps.lat);
Serial.printf("lon:%d\t", (int)gps.lon);
Expand Down Expand Up @@ -478,17 +479,17 @@ class CLI {
}

void print_i2cScan() {
Serial.printf("I2C: Scanning ...\n");
Serial.printf("I2C: Scanning ...\n");
byte count = 0;
//i2c->begin();
for (byte i = 8; i < 120; i++) {
i2c->beginTransmission(i); // Begin I2C transmission Address (i)
if (i2c->endTransmission() == 0) { // Receive 0 = success (ACK response)
Serial.printf("I2C: Found address: 0x%02X (%d)\n",i,i);
Serial.printf("I2C: Found address: 0x%02X (%d)\n",i,i);
count++;
}
}
Serial.printf("I2C: Found %d device(s)\n", count);
Serial.printf("I2C: Found %d device(s)\n", count);
}

//========================================================================================================================//
Expand Down
22 changes: 22 additions & 0 deletions src/madflight/gps/GPS-uBlox/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# GPS-uBlox - Platform agnostic C++ uBlox GPS driver

Ported from tried and tested Ardupilot GPS UBLOX driver.

Features:

- Platform agnostic C++ (Arduino, PlatformIO, Linux, Windows, whatever...)
- Supports uBlox-6 to uBlox-M10 GPS
- Automatically configures baudrate
- Uses high speed ubx protocol
- Auto reconnect on communication loss
- Optionally save the config to the GPS module for faster restarts

Changes from ArduPilot:

- Moved all external dependencies into AP_GPS_UBLOX.h & .cpp
- Added pure virtual I_xxx methods as interface to the outside world
- Removed float (except LOGGING)

Requirements:

See example directory. Basically, implement the 7 pure virtual methods to get going.
Loading

0 comments on commit 30b9cbd

Please sign in to comment.