diff --git a/docs/software/nrf52-TODO.md b/docs/software/nrf52-TODO.md index 59a467fe..a60cf2af 100644 --- a/docs/software/nrf52-TODO.md +++ b/docs/software/nrf52-TODO.md @@ -8,7 +8,6 @@ Minimum items needed to make sure hardware is good. - use "variants" to get all gpio bindings - plug in correct variants for the real board - Use the PMU driver on real hardware -- add a NEMA based GPS driver to test GPS - Use new radio driver on real hardware - Use UC1701 LCD driver on real hardware. Still need to create at startup and probe on SPI - test the LEDs @@ -101,6 +100,7 @@ Nice ideas worth considering someday... - DONE neg 7 error code from receive - DONE remove unused sx1262 lib from github - at boot we are starting our message IDs at 1, rather we should start them at a random number. also, seed random based on timer. this could be the cause of our first message not seen bug. +- add a NEMA based GPS driver to test GPS ``` diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index d8d73784..bb2d30b5 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -61,7 +61,7 @@ void perhapsSetRTC(struct tm &t) tv.tv_sec = res; tv.tv_usec = 0; // time.centisecond() * (10 / 1000); - DEBUG_MSG("Got time from GPS month=%d, year=%d, unixtime=%ld\n", t.tm_mon, t.tm_year, tv.tv_sec); + // DEBUG_MSG("Got time from GPS month=%d, year=%d, unixtime=%ld\n", t.tm_mon, t.tm_year, tv.tv_sec); if (t.tm_year < 0 || t.tm_year >= 300) DEBUG_MSG("Ignoring invalid GPS time\n"); else diff --git a/src/gps/NEMAGPS.cpp b/src/gps/NEMAGPS.cpp index 74cdf760..7d19f886 100644 --- a/src/gps/NEMAGPS.cpp +++ b/src/gps/NEMAGPS.cpp @@ -12,45 +12,54 @@ static int32_t toDegInt(RawDegrees d) void NEMAGPS::loop() { + while (_serial_gps.available() > 0) { int c = _serial_gps.read(); - Serial.write(c); + // Serial.write(c); reader.encode(c); } - auto ti = reader.time; - auto d = reader.date; - if (ti.isUpdated() && ti.isValid() && d.isValid()) { - /* Convert to unix time -The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 -(midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z). -*/ - struct tm t; - t.tm_sec = ti.second(); - t.tm_min = ti.minute(); - t.tm_hour = ti.hour(); - t.tm_mday = d.day(); - t.tm_mon = d.month() - 1; - t.tm_year = d.year() - 1900; - t.tm_isdst = false; - perhapsSetRTC(t); - } + uint32_t now = millis(); + if ((now - lastUpdateMsec) > 20 * 1000) { // Ugly hack for now - limit update checks to once every 20 secs (but still consume + // serial chars at whatever rate) + lastUpdateMsec = now; - if (reader.altitude.isUpdated() || reader.location.isUpdated()) { // probably get updated at the same time - if (reader.altitude.isValid()) - altitude = reader.altitude.meters(); + auto ti = reader.time; + auto d = reader.date; + if (ti.isUpdated() && ti.isValid() && d.isValid()) { + /* Convert to unix time + The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 + (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z). + */ + struct tm t; + t.tm_sec = ti.second(); + t.tm_min = ti.minute(); + t.tm_hour = ti.hour(); + t.tm_mday = d.day(); + t.tm_mon = d.month() - 1; + t.tm_year = d.year() - 1900; + t.tm_isdst = false; + perhapsSetRTC(t); - auto loc = reader.location; - if (loc.isValid()) { - latitude = toDegInt(loc.rawLat()); - longitude = toDegInt(loc.rawLng()); + isConnected = true; // we seem to have a real GPS (but not necessarily a lock) } - // expect gps pos lat=37.520825, lon=-122.309162, alt=158 - DEBUG_MSG("new NEMA GPS pos lat=%f, lon=%f, alt=%d\n", latitude * 1e-7, longitude * 1e-7, altitude); + if (reader.location.isUpdated()) { + if (reader.altitude.isValid()) + altitude = reader.altitude.meters(); - hasValidLocation = (latitude != 0) || (longitude != 0); // bogus lat lon is reported as 0,0 - if (hasValidLocation) - notifyObservers(NULL); + if (reader.location.isValid()) { + auto loc = reader.location.value(); + latitude = toDegInt(loc.lat); + longitude = toDegInt(loc.lng); + } + + // expect gps pos lat=37.520825, lon=-122.309162, alt=158 + DEBUG_MSG("new NEMA GPS pos lat=%f, lon=%f, alt=%d\n", latitude * 1e-7, longitude * 1e-7, altitude); + + hasValidLocation = (latitude != 0) || (longitude != 0); // bogus lat lon is reported as 0,0 + if (hasValidLocation) + notifyObservers(NULL); + } } } \ No newline at end of file diff --git a/src/gps/NEMAGPS.h b/src/gps/NEMAGPS.h index ddaf77ee..5bea0d41 100644 --- a/src/gps/NEMAGPS.h +++ b/src/gps/NEMAGPS.h @@ -13,6 +13,8 @@ class NEMAGPS : public GPS { TinyGPSPlus reader; + + uint32_t lastUpdateMsec = 0; public: virtual void loop(); diff --git a/src/gps/UBloxGPS.cpp b/src/gps/UBloxGPS.cpp index 54f7810e..560c52fa 100644 --- a/src/gps/UBloxGPS.cpp +++ b/src/gps/UBloxGPS.cpp @@ -28,7 +28,7 @@ bool UBloxGPS::setup() if (isConnected) { DEBUG_MSG("Connected to UBLOX GPS successfully\n"); - bool factoryReset = true; + bool factoryReset = false; bool ok; if (factoryReset) { // It is useful to force back into factory defaults (9600baud, NEMA to test the behavior of boards that don't have