From 3c5a096873fe709d9260b80089a4fdafde136283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Wed, 18 May 2022 16:16:59 +0200 Subject: [PATCH 1/3] Streamline GPS Init --- src/gps/GPS.cpp | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index ee210e9a8..a5d5fb6c3 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -26,18 +26,9 @@ bool GPS::getACK(uint8_t c, uint8_t i) { uint8_t b; uint8_t ack = 0; const uint8_t ackP[2] = {c, i}; - uint8_t buf[250]; + uint8_t buf[10] = {0xB5, 0x62, 0x05, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00}; unsigned long startTime = millis(); - buf[0] = 0xB5; - buf[1] = 0x62; - buf[2] = 0x05; - buf[3] = 0x01; - buf[4] = 0x02; - buf[5] = 0x00; - buf[8] = 0x00; - buf[9] = 0x00; - for (int j = 2; j < 6; j++) { buf[8] += buf[j]; buf[9] += buf[8]; @@ -53,7 +44,7 @@ bool GPS::getACK(uint8_t c, uint8_t i) { if (ack > 9) { return true; } - if (millis() - startTime > 2000) { + if (millis() - startTime > 1000) { return false; } if (_serial_gps->available()) { @@ -103,7 +94,6 @@ bool GPS::setupGPS() // Switch to Vehicle Mode, since SoftRF enables Aviation < 2g _serial_gps->write("$PCAS11,3*1E\r\n"); delay(250); - #endif #ifdef GPS_UBLOX // Set the UART port to output NMEA only @@ -115,27 +105,42 @@ bool GPS::setupGPS() // disable GGL byte _message_GGL[] = {0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0xF0, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x05, 0x3A}; _serial_gps->write(_message_GGL, sizeof(_message_GGL)); - if (!getACK(0x06, 0x01)) DEBUG_MSG("WARNING: Unable to disable NMEA GGL.\n"); + if (!getACK(0x06, 0x01)) { + DEBUG_MSG("WARNING: Unable to disable NMEA GGL.\n"); + return true; + } // disable GSA byte _message_GSA[] = {0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0xF0, 0x02, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x06, 0x41}; _serial_gps->write(_message_GSA, sizeof(_message_GSA)); - if (!getACK(0x06, 0x01)) DEBUG_MSG("WARNING: Unable to disable NMEA GSA.\n"); + if (!getACK(0x06, 0x01)) { + DEBUG_MSG("WARNING: Unable to disable NMEA GSA.\n"); + return true; + } // disable GSV byte _message_GSV[] = {0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0xF0, 0x03, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x07, 0x48}; _serial_gps->write(_message_GSV, sizeof(_message_GSV)); - if (!getACK(0x06, 0x01)) DEBUG_MSG("WARNING: Unable to disable NMEA GSV.\n"); + if (!getACK(0x06, 0x01)) { + DEBUG_MSG("WARNING: Unable to disable NMEA GSV.\n"); + return true; + } // disable VTG byte _message_VTG[] = {0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0xF0, 0x05, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x09, 0x56}; _serial_gps->write(_message_VTG, sizeof(_message_VTG)); - if (!getACK(0x06, 0x01)) DEBUG_MSG("WARNING: Unable to disable NMEA VTG.\n"); + if (!getACK(0x06, 0x01)) { + DEBUG_MSG("WARNING: Unable to disable NMEA VTG.\n"); + return true; + } // enable RMC byte _message_RMC[] = {0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0xF0, 0x04, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x09, 0x54}; _serial_gps->write(_message_RMC, sizeof(_message_RMC)); - if (!getACK(0x06, 0x01)) DEBUG_MSG("WARNING: Unable to enable NMEA RMC.\n"); + if (!getACK(0x06, 0x01)) { + DEBUG_MSG("WARNING: Unable to enable NMEA RMC.\n"); + return true; + } // enable GGA byte _message_GGA[] = {0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0xF0, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x05, 0x38}; From 5e82423331edeeddea67204e00aa00dc9e286097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Wed, 18 May 2022 18:16:23 +0200 Subject: [PATCH 2/3] More UBX fixes --- src/gps/GPS.cpp | 15 ++++++++++++++- src/gps/NMEAGPS.cpp | 13 +++++++++++++ src/gps/NMEAGPS.h | 2 ++ src/main.cpp | 1 + 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index a5d5fb6c3..70052dcfe 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -96,11 +96,15 @@ bool GPS::setupGPS() delay(250); #endif #ifdef GPS_UBLOX + delay(250); // Set the UART port to output NMEA only byte _message_nmea[] = {0xB5, 0x62, 0x06, 0x00, 0x14, 0x00, 0x01, 0x00, 0x00, 0x00, 0xC0, 0x08, 0x00, 0x00, 0x80, 0x25, 0x00, 0x00, 0x07, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x91, 0xAF}; _serial_gps->write(_message_nmea, sizeof(_message_nmea)); - if (!getACK(0x06, 0x00)) DEBUG_MSG("WARNING: Unable to set UART.\n"); + if (!getACK(0x06, 0x00)) { + DEBUG_MSG("WARNING: Unable to enable NMEA Mode.\n"); + return true; + } // disable GGL byte _message_GGL[] = {0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0xF0, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x05, 0x3A}; @@ -316,6 +320,15 @@ int32_t GPS::runOnce() if (whileIdle()) { // if we have received valid NMEA claim we are connected setConnected(); + } else { +#ifdef GPS_UBLOX + // reset the GPS on next bootup + if(devicestate.did_gps_reset && (millis() > 60000)) { + DEBUG_MSG("GPS is not communicating, trying factory reset on next bootup.\n"); + devicestate.did_gps_reset = false; + nodeDB.saveToDisk(); + } +#endif } // If we are overdue for an update, turn on the GPS and at least publish the current status diff --git a/src/gps/NMEAGPS.cpp b/src/gps/NMEAGPS.cpp index 8a8181f3b..6e6a1f513 100644 --- a/src/gps/NMEAGPS.cpp +++ b/src/gps/NMEAGPS.cpp @@ -17,6 +17,19 @@ static int32_t toDegInt(RawDegrees d) return r; } +bool NMEAGPS::factoryReset() +{ +#ifdef GPS_UBLOX + // Factory Reset + byte _message_reset[] = {0xB5, 0x62, 0x06, 0x09, 0x0D, 0x00, 0xFF, + 0xFB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0x00, 0x00, 0x17, 0x2B, 0x7E}; + _serial_gps->write(_message_reset,sizeof(_message_reset)); + delay(1000); + return true; +#endif +} + bool NMEAGPS::setupGPS() { GPS::setupGPS(); diff --git a/src/gps/NMEAGPS.h b/src/gps/NMEAGPS.h index 6133925dd..6ef560962 100644 --- a/src/gps/NMEAGPS.h +++ b/src/gps/NMEAGPS.h @@ -25,6 +25,8 @@ class NMEAGPS : public GPS public: virtual bool setupGPS() override; + virtual bool factoryReset() override; + protected: /** Subclasses should look for serial rx characters here and feed it to their GPS parser * diff --git a/src/main.cpp b/src/main.cpp index 51dbeb805..b8c45c9c9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -310,6 +310,7 @@ void setup() // ONCE we will factory reset the GPS for bug #327 if (gps && !devicestate.did_gps_reset) { + DEBUG_MSG("GPS FactoryReset requested\n"); if (gps->factoryReset()) { // If we don't succeed try again next time devicestate.did_gps_reset = true; nodeDB.saveToDisk(); From 3d0d45a69540f3b8e3b9de2c9186d1d2f126e3e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Wed, 18 May 2022 18:29:26 +0200 Subject: [PATCH 3/3] More UBX stuff from 1.2 --- src/configuration.h | 8 ++++---- src/gps/NMEAGPS.cpp | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/configuration.h b/src/configuration.h index 7ae279736..16262d97f 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -107,10 +107,6 @@ along with this program. If not, see . #define GPS_TX_PIN 12 #endif -#ifndef TTGO_T_ECHO -#define GPS_UBLOX -#endif - // ----------------------------------------------------------------------------- // LoRa SPI // ----------------------------------------------------------------------------- @@ -125,6 +121,10 @@ along with this program. If not, see . #endif +#ifndef TTGO_T_ECHO +#define GPS_UBLOX +#endif + // // Standard definitions for !ESP32 targets // diff --git a/src/gps/NMEAGPS.cpp b/src/gps/NMEAGPS.cpp index 6e6a1f513..98b7834f9 100644 --- a/src/gps/NMEAGPS.cpp +++ b/src/gps/NMEAGPS.cpp @@ -20,14 +20,14 @@ static int32_t toDegInt(RawDegrees d) bool NMEAGPS::factoryReset() { #ifdef GPS_UBLOX - // Factory Reset - byte _message_reset[] = {0xB5, 0x62, 0x06, 0x09, 0x0D, 0x00, 0xFF, - 0xFB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0x00, 0x00, 0x17, 0x2B, 0x7E}; - _serial_gps->write(_message_reset,sizeof(_message_reset)); - delay(1000); - return true; + // Factory Reset + byte _message_reset[] = {0xB5, 0x62, 0x06, 0x09, 0x0D, 0x00, 0xFF, + 0xFB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0x00, 0x00, 0x17, 0x2B, 0x7E}; + _serial_gps->write(_message_reset,sizeof(_message_reset)); + delay(1000); #endif + return true; } bool NMEAGPS::setupGPS()