From bd41cd8c0a301738195fd1281be2de23ad07698b Mon Sep 17 00:00:00 2001 From: Jens Kassel Date: Thu, 13 Feb 2025 21:22:00 +0100 Subject: [PATCH 01/16] Add ability for gps cold-start (reset) for now as hidden http adress /cold --- src/configServer.cpp | 13 +++++++++++++ src/gps.cpp | 14 ++++++++++++++ src/gps.h | 2 ++ 3 files changed, 29 insertions(+) diff --git a/src/configServer.cpp b/src/configServer.cpp index 272fac2..0783a88 100644 --- a/src/configServer.cpp +++ b/src/configServer.cpp @@ -230,6 +230,9 @@ static const char* const development = static const char* const rebootIndex = "

Device reboots now.

"; +static const char* const gpsColdIndex = + "

GPS cold start

"; + // ######################################### // Wifi // ######################################### @@ -456,6 +459,7 @@ static void handleNotFound(HTTPRequest * req, HTTPResponse * res); static void handleIndex(HTTPRequest * req, HTTPResponse * res); static void handleAbout(HTTPRequest * req, HTTPResponse * res); static void handleReboot(HTTPRequest * req, HTTPResponse * res); +static void handleColdStartGPS(HTTPRequest * req, HTTPResponse * res); static void handleBackup(HTTPRequest * req, HTTPResponse * res); static void handleBackupDownload(HTTPRequest * req, HTTPResponse * res); static void handleBackupRestore(HTTPRequest * req, HTTPResponse * res); @@ -546,6 +550,7 @@ void registerPages(HTTPServer * httpServer) { httpServer->registerNode(new ResourceNode("/", HTTP_GET, handleIndex)); httpServer->registerNode(new ResourceNode("/about", HTTP_GET, handleAbout)); httpServer->registerNode(new ResourceNode("/reboot", HTTP_GET, handleReboot)); + httpServer->registerNode(new ResourceNode("/cold", HTTP_GET, handleColdStartGPS)); httpServer->registerNode(new ResourceNode("/settings/backup", HTTP_GET, handleBackup)); httpServer->registerNode(new ResourceNode("/settings/backup.json", HTTP_GET, handleBackupDownload)); httpServer->registerNode(new ResourceNode("/settings/restore", HTTP_POST, handleBackupRestore)); @@ -1123,6 +1128,14 @@ static void handleReboot(HTTPRequest *, HTTPResponse * res) { ESP.restart(); } +static void handleColdStartGPS(HTTPRequest *, HTTPResponse * res) { + String html = createPage(gpsColdIndex); + html = replaceDefault(html, "Navigation"); + sendHtml(res, html); + gps.coldResetGps(); + res->finalize(); +} + static void handleBackup(HTTPRequest *, HTTPResponse * res) { String html = createPage(backupIndex, xhrUpload); diff --git a/src/gps.cpp b/src/gps.cpp index b1f4db7..f0ac083 100644 --- a/src/gps.cpp +++ b/src/gps.cpp @@ -304,6 +304,20 @@ void Gps::softResetGps() { log_i("Soft-RESET GPS! Done"); } +void Gps::coldResetGps() { + log_i("Cold START GPS!"); + handle(); + const uint8_t UBX_CFG_RST[] = {0xFF, 0xFF, 0x04, 0x00}; // Cold START, 0x04 = Hardware reset (watchdog) after shutdown + // we had the case where the reset took several seconds + // see https://github.com/openbikesensor/OpenBikeSensorFirmware/issues/309 + // Newer firmware (like M10 and likely also M8) will not ack this + // message so we do not wait for the ACK + sendUbx(UBX_MSG::CFG_RST, UBX_CFG_RST, 4); + waitForData(1000); + handle(); + log_i("Cold START GPS! Done"); +} + /* There had been changes for the satellites used for SBAS * in europe since the firmware of our GPS module was built * we configure the module to use the 2 satellites that are diff --git a/src/gps.h b/src/gps.h index e5fccab..1517ce6 100644 --- a/src/gps.h +++ b/src/gps.h @@ -107,6 +107,8 @@ class Gps { uint32_t getNumberOfAlpBytesSent() const; uint32_t getUnexpectedCharReceivedCount() const; + void coldResetGps(); + private: /* ALP msgs up to 0x16A seen might be more? */ static const int MAX_MESSAGE_LENGTH = 128 * 3; From fe3f8ea865eb835dd4f072e87a2e237c6f3a3186 Mon Sep 17 00:00:00 2001 From: Jens Kassel Date: Thu, 13 Feb 2025 21:30:27 +0100 Subject: [PATCH 02/16] Fix Mon-HW --- src/gps.cpp | 12 ++++++++++-- src/gps.h | 5 +++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/gps.cpp b/src/gps.cpp index f0ac083..489c330 100644 --- a/src/gps.cpp +++ b/src/gps.cpp @@ -1115,8 +1115,16 @@ void Gps::parseUbxMessage() { } break; case (uint16_t) UBX_MSG::MON_HW: { - log_v("MON-HW Antenna Status %d, noise level %d", mGpsBuffer.monHw.aStatus, - mGpsBuffer.monHw.noisePerMs); + const char* aStatus; + switch (mGpsBuffer.monHw.aStatus) { + case mGpsBuffer.monHw.INIT: aStatus = "init"; break; + case mGpsBuffer.monHw.DONTKNOW: aStatus = "?"; break; + case mGpsBuffer.monHw.OK: aStatus = "ok"; break; + case mGpsBuffer.monHw.SHORT: aStatus = "short"; break; + case mGpsBuffer.monHw.OPEN: aStatus = "open"; break; + default: aStatus = "invalid"; + } + log_v("MON-HW Antenna Status %d %s, Antenna Power %d, Gain (0-8191) %d, noise level %d", mGpsBuffer.monHw.aStatus, aStatus, mGpsBuffer.monHw.aPower, mGpsBuffer.monHw.agcCnt, mGpsBuffer.monHw.noisePerMs); mLastNoiseLevel = mGpsBuffer.monHw.noisePerMs; } break; diff --git a/src/gps.h b/src/gps.h index 1517ce6..416cf01 100644 --- a/src/gps.h +++ b/src/gps.h @@ -290,6 +290,7 @@ class Gps { uint32_t pinDir; uint32_t pinVal; uint16_t noisePerMs; + uint16_t agcCnt; // AGC (Automatic Gain Control) Monitor, as percentage of maximum gain,range 0 to 8191 (100%) enum ANT_STATUS : uint8_t { INIT = 0, DONTKNOW = 1, @@ -305,8 +306,8 @@ class Gps { uint8_t flags; uint8_t reserved1; uint32_t usedMask; - uint8_t vp[25]; - uint8_t jamInd; + uint8_t vp[25]; //M8 only 17bytes? + uint8_t jamInd; //cwSuppression / CW interference suppression level, scaled (0 = no CW jamming, 255 = strong CW jamming) uint16_t reserved3; uint32_t pinIrq; uint32_t pullH; From b0a521e6640a9c4b2f2b7fbfd53b3f48723df32a Mon Sep 17 00:00:00 2001 From: Jens Kassel Date: Thu, 13 Feb 2025 21:31:39 +0100 Subject: [PATCH 03/16] adapt debug logging --- src/gps.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gps.cpp b/src/gps.cpp index 489c330..0213d06 100644 --- a/src/gps.cpp +++ b/src/gps.cpp @@ -1124,7 +1124,7 @@ void Gps::parseUbxMessage() { case mGpsBuffer.monHw.OPEN: aStatus = "open"; break; default: aStatus = "invalid"; } - log_v("MON-HW Antenna Status %d %s, Antenna Power %d, Gain (0-8191) %d, noise level %d", mGpsBuffer.monHw.aStatus, aStatus, mGpsBuffer.monHw.aPower, mGpsBuffer.monHw.agcCnt, mGpsBuffer.monHw.noisePerMs); + log_d("MON-HW Antenna Status %d %s, Antenna Power %d, Gain (0-8191) %d, noise level %d", mGpsBuffer.monHw.aStatus, aStatus, mGpsBuffer.monHw.aPower, mGpsBuffer.monHw.agcCnt, mGpsBuffer.monHw.noisePerMs); mLastNoiseLevel = mGpsBuffer.monHw.noisePerMs; } break; @@ -1152,7 +1152,7 @@ void Gps::parseUbxMessage() { } break; case (uint16_t) UBX_MSG::NAV_SOL: { - log_v("SOL: iTOW: %u, gpsFix: %d, flags: %02x, numSV: %d, pDop: %04d.", + log_d("SOL: iTOW: %u, gpsFix: %d, flags: %02x, numSV: %d, pDop: %04d.", mGpsBuffer.navSol.iTow, mGpsBuffer.navSol.gpsFix, mGpsBuffer.navSol.flags, mGpsBuffer.navSol.numSv, mGpsBuffer.navSol.pDop); if (mGpsBuffer.navSol.flags & 4) { // WKNSET @@ -1170,7 +1170,7 @@ void Gps::parseUbxMessage() { } break; case (uint16_t) UBX_MSG::NAV_PVT: { - log_v("PVT: iTOW: %u, fixType: %d, flags: %02x, numSV: %d, pDop: %04d.", + log_d("PVT: iTOW: %u, fixType: %d, flags: %02x, numSV: %d, pDop: %04d.", mGpsBuffer.navPvt.iTow, mGpsBuffer.navPvt.fixType, mGpsBuffer.navPvt.flags, mGpsBuffer.navPvt.numSV, mGpsBuffer.navPvt.pDOP); prepareGpsData(mGpsBuffer.navPvt.iTow, mMessageStarted); @@ -1178,7 +1178,7 @@ void Gps::parseUbxMessage() { } break; case (uint16_t) UBX_MSG::NAV_VELNED: { - log_v("VELNED: iTOW: %u, speed: %d cm/s, gSpeed: %d cm/s, heading: %d," + log_d("VELNED: iTOW: %u, speed: %d cm/s, gSpeed: %d cm/s, heading: %d," " speedAcc: %d, cAcc: %d", mGpsBuffer.navVelned.iTow, mGpsBuffer.navVelned.speed, mGpsBuffer.navVelned.gSpeed, mGpsBuffer.navVelned.heading, mGpsBuffer.navVelned.sAcc, mGpsBuffer.navVelned.cAcc); @@ -1311,7 +1311,7 @@ void Gps::parseUbxMessage() { log_d("CFG_GNSS"); break; default: - log_e("Got UBX_MESSAGE! Id: 0x%04x Len %d iTOW %d", mGpsBuffer.ubxHeader.ubxMsgId, + log_e("Got unparsed UBX_MESSAGE! Id: 0x%04x Len %d iTOW %d", mGpsBuffer.ubxHeader.ubxMsgId, mGpsBuffer.ubxHeader.length, mGpsBuffer.navStatus.iTow); } } From dae9abc1280f7b1ab9710b71e07ae207c1c3883a Mon Sep 17 00:00:00 2001 From: Jens Kassel Date: Thu, 13 Feb 2025 21:37:05 +0100 Subject: [PATCH 04/16] monitor antenna gain --- src/gps.cpp | 4 +++- src/gps.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gps.cpp b/src/gps.cpp index 0213d06..6884412 100644 --- a/src/gps.cpp +++ b/src/gps.cpp @@ -795,7 +795,8 @@ void Gps::showWaitStatus(DisplayDevice const * display) const { if (mValidMessagesReceived == 0) { // could not get any valid char from GPS module satellitesString[0] = "OFF?"; } else if (mLastTimeTimeSet == 0) { - satellitesString[0] = String(mCurrentGpsRecord.mSatellitesUsed) + "sats SN:" + String(mLastNoiseLevel); + satellitesString[0] = "aGain:" + String(mLastGain); + satellitesString[1] = String(mCurrentGpsRecord.mSatellitesUsed) + "sats SN:" + String(mLastNoiseLevel); } else { satellitesString[0] = "GPS " + TimeUtils::timeToString(); satellitesString[1] = String(mCurrentGpsRecord.mSatellitesUsed) + "sats SN:" + String(mLastNoiseLevel); @@ -1126,6 +1127,7 @@ void Gps::parseUbxMessage() { } log_d("MON-HW Antenna Status %d %s, Antenna Power %d, Gain (0-8191) %d, noise level %d", mGpsBuffer.monHw.aStatus, aStatus, mGpsBuffer.monHw.aPower, mGpsBuffer.monHw.agcCnt, mGpsBuffer.monHw.noisePerMs); mLastNoiseLevel = mGpsBuffer.monHw.noisePerMs; + mLastGain = mGpsBuffer.monHw.agcCnt; } break; case (uint16_t) UBX_MSG::NAV_STATUS: { diff --git a/src/gps.h b/src/gps.h index 416cf01..4db2424 100644 --- a/src/gps.h +++ b/src/gps.h @@ -553,6 +553,7 @@ class Gps { uint32_t mUnexpectedCharReceivedCount = 0; uint8_t mNmeaChk; uint16_t mLastNoiseLevel; + uint16_t mLastGain; AlpData mAlpData; bool mAidIniSent = false; /* record that was last received */ From db00da71dc8fc4385b24a691cefac82c06e18c7e Mon Sep 17 00:00:00 2001 From: Jens Kassel Date: Fri, 14 Feb 2025 12:06:57 +0100 Subject: [PATCH 05/16] Show AntennaGain and JammingLevel in about page --- src/configServer.cpp | 2 ++ src/gps.cpp | 9 +++++++++ src/gps.h | 7 ++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/configServer.cpp b/src/configServer.cpp index 0783a88..7902f27 100644 --- a/src/configServer.cpp +++ b/src/configServer.cpp @@ -1070,6 +1070,8 @@ static void handleAbout(HTTPRequest *req, HTTPResponse * res) { page += keyValue("GPS satellites", gps.getValidSatellites()); page += keyValue("GPS uptime", gps.getUptime(), "ms"); page += keyValue("GPS noise level", gps.getLastNoiseLevel()); + page += keyValue("GPS Antenna Gain", gps.getLastAntennaGain()); + page += keyValue("GPS Jamming Level", gps.getLastJamInd()); page += keyValue("GPS baud rate", gps.getBaudRate()); page += keyValue("GPS ALP bytes", gps.getNumberOfAlpBytesSent()); page += keyValue("GPS messages", gps.getMessagesHtml()); diff --git a/src/gps.cpp b/src/gps.cpp index 6884412..9ef0c21 100644 --- a/src/gps.cpp +++ b/src/gps.cpp @@ -1128,6 +1128,7 @@ void Gps::parseUbxMessage() { log_d("MON-HW Antenna Status %d %s, Antenna Power %d, Gain (0-8191) %d, noise level %d", mGpsBuffer.monHw.aStatus, aStatus, mGpsBuffer.monHw.aPower, mGpsBuffer.monHw.agcCnt, mGpsBuffer.monHw.noisePerMs); mLastNoiseLevel = mGpsBuffer.monHw.noisePerMs; mLastGain = mGpsBuffer.monHw.agcCnt; + mLastJamInd = mGpsBuffer.monHw.jamInd; } break; case (uint16_t) UBX_MSG::NAV_STATUS: { @@ -1435,6 +1436,14 @@ uint16_t Gps::getLastNoiseLevel() const { return mLastNoiseLevel; } +uint16_t Gps::getLastAntennaGain() const { + return mLastGain; +} + +uint8_t Gps::getLastJamInd() const { + return mLastJamInd; +} + uint32_t Gps::getBaudRate() { return mSerial.baudRate(); } diff --git a/src/gps.h b/src/gps.h index 4db2424..663e13d 100644 --- a/src/gps.h +++ b/src/gps.h @@ -70,6 +70,10 @@ class Gps { uint16_t getLastNoiseLevel() const; + uint16_t getLastAntennaGain() const; + + uint8_t getLastJamInd() const; + /* Collected informational messages as String. */ String getMessages() const; @@ -306,7 +310,7 @@ class Gps { uint8_t flags; uint8_t reserved1; uint32_t usedMask; - uint8_t vp[25]; //M8 only 17bytes? + uint8_t vp[17]; //M6 25bytes, M8 only 17bytes? uint8_t jamInd; //cwSuppression / CW interference suppression level, scaled (0 = no CW jamming, 255 = strong CW jamming) uint16_t reserved3; uint32_t pinIrq; @@ -554,6 +558,7 @@ class Gps { uint8_t mNmeaChk; uint16_t mLastNoiseLevel; uint16_t mLastGain; + uint8_t mLastJamInd; AlpData mAlpData; bool mAidIniSent = false; /* record that was last received */ From 015297ec008765a52ce3caef7ac9f28059a629e0 Mon Sep 17 00:00:00 2001 From: gluap Date: Sun, 16 Feb 2025 18:04:32 +0100 Subject: [PATCH 06/16] a bunch of experiments for neo8m and debugoutput on display. --- src/OpenBikeSensorFirmware.cpp | 2 +- src/gps.cpp | 39 ++++++++++++++++++++++------------ src/gpsrecord.cpp | 2 ++ src/gpsrecord.h | 3 ++- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/OpenBikeSensorFirmware.cpp b/src/OpenBikeSensorFirmware.cpp index 39b26cd..84988d3 100644 --- a/src/OpenBikeSensorFirmware.cpp +++ b/src/OpenBikeSensorFirmware.cpp @@ -446,7 +446,7 @@ void setup() { gps.handle(); setupBluetooth(cfg, trackUniqueIdentifier); - + obsDisplay->clear(); obsDisplay->showTextOnGrid(2, obsDisplay->newLine(), "Wait for GPS"); obsDisplay->newLine(); gps.handle(); diff --git a/src/gps.cpp b/src/gps.cpp index b1f4db7..1ada880 100644 --- a/src/gps.cpp +++ b/src/gps.cpp @@ -34,10 +34,10 @@ const String Gps::INF_SEVERITY_STRING[] = { void Gps::begin() { setBaud(); softResetGps(); - if (mGpsNeedsConfigUpdate) { + //if (mGpsNeedsConfigUpdate) { configureGpsModule(); - } - enableAlpIfDataIsAvailable(); + //} + // enableAlpIfDataIsAvailable(); pollStatistics(); if (mLastTimeTimeSet == 0) { #ifdef UBX_M10 @@ -249,6 +249,14 @@ void Gps::configureGpsModule() { } else { addStatisticsMessage("No ack for setting timepulse in either new or old format"); } + const uint8_t UBX_CFG_RATE[] = {0xE8, 0x03, 0x01, 0x00, 0x00, 0x00}; + if (!sendAndWaitForAck(UBX_MSG::CFG_TP5, UBX_CFG_TP5, sizeof(UBX_CFG_RATE))) { + addStatisticsMessage("Successfully set rate"); + obsDisplay->showTextOnGrid(0, 5, "rate set"); + } else{ + obsDisplay->showTextOnGrid(0, 5, "rate not set"); + } + } #endif @@ -292,8 +300,8 @@ void Gps::configureGpsModule() { void Gps::softResetGps() { log_i("Soft-RESET GPS!"); handle(); - const uint8_t UBX_CFG_RST[] = {0x00, 0x00, 0x02, 0x00}; // WARM START -// const uint8_t UBX_CFG_RST[] = {0xFF, 0xFF, 0x02, 0x00}; // Cold START + //const uint8_t UBX_CFG_RST[] = {0x00, 0x00, 0x02, 0x00}; // WARM START + const uint8_t UBX_CFG_RST[] = {0xFF, 0x81, 0x04, 0x00}; // Cold START '0xFF, 0x81, 0x04, 0x00' // we had the case where the reset took several seconds // see https://github.com/openbikesensor/OpenBikeSensorFirmware/issues/309 // Newer firmware (like M10 and likely also M8) will not ack this @@ -777,7 +785,7 @@ int32_t Gps::getMessagesWithFailedCrcCount() const { } void Gps::showWaitStatus(DisplayDevice const * display) const { - String satellitesString[2]; + String satellitesString[3]; if (mValidMessagesReceived == 0) { // could not get any valid char from GPS module satellitesString[0] = "OFF?"; } else if (mLastTimeTimeSet == 0) { @@ -786,13 +794,15 @@ void Gps::showWaitStatus(DisplayDevice const * display) const { satellitesString[0] = "GPS " + TimeUtils::timeToString(); satellitesString[1] = String(mCurrentGpsRecord.mSatellitesUsed) + "sats SN:" + String(mLastNoiseLevel); } + satellitesString[2] = String(mCurrentGpsRecord.mFixStatus) + "" + String(mValidMessagesReceived); - if (satellitesString[1].isEmpty()) { - obsDisplay->showTextOnGrid(2, display->currentLine(), satellitesString[0]); - } else { obsDisplay->showTextOnGrid(2, display->currentLine() - 1, satellitesString[0]); obsDisplay->showTextOnGrid(2, display->currentLine(), satellitesString[1]); - } + obsDisplay->showTextOnGrid(0, 1, satellitesString[2]); + obsDisplay->showTextOnGrid(0, 2, String(mCurrentGpsRecord.mLatitude)); + obsDisplay->showTextOnGrid(0, 3, String(mCurrentGpsRecord.mLongitude)); + obsDisplay->showTextOnGrid(0, 4, String(mCurrentGpsRecord.hwVer)); + obsDisplay->showTextOnGrid(0, 5, String(mCurrentGpsRecord.swVer)); } bool Gps::moduleIsAlive() const { @@ -1098,6 +1108,8 @@ void Gps::parseUbxMessage() { String(mGpsBuffer.monVer.swVersion).c_str(), String(mGpsBuffer.monVer.hwVersion).c_str(), mGpsBuffer.ubxHeader.length); + mIncomingGpsRecord.swVer = String(mGpsBuffer.monVer.swVersion); + mIncomingGpsRecord.hwVer = String(mGpsBuffer.monVer.hwVersion); } break; case (uint16_t) UBX_MSG::MON_HW: { @@ -1314,10 +1326,9 @@ void Gps::handleUbxNavTimeGps(const GpsBuffer::UbxNavTimeGps &message, const uin mIncomingGpsRecord.setWeek(mLastGpsWeek); } if ((message.valid & 0x03) == 0x03 // WEEK && TOW - && delayMs < 250 && message.tAcc < (20 * 1000 * 1000 /* 20ms */) - && (mLastTimeTimeSet == 0 - || (mLastTimeTimeSet + (2 * 60 * 1000 /* 2 minutes */)) < receivedMs)) { + && ((mLastTimeTimeSet == 0) + || ((mLastTimeTimeSet + (2 * 60 * 1000 /* 2 minutes */)) < receivedMs))) { String oldTime = TimeUtils::dateTimeToString(); TimeUtils::setClockByGps(message.iTow, message.fTow, message.week); String newTime = TimeUtils::dateTimeToString(); @@ -1331,7 +1342,7 @@ void Gps::handleUbxNavTimeGps(const GpsBuffer::UbxNavTimeGps &message, const uin mLastTimeTimeSet = receivedMs; // This triggers another NAV-TIMEGPS message! #ifdef UBX_M6 - setMessageInterval(UBX_MSG::NAV_TIMEGPS, 240, false); // every 4 minutes + setMessageInterval(UBX_MSG::NAV_TIMEGPS, (delayMs>200) ? 5 : 240, false); // every 4 minutes #endif #ifdef UBX_M10 setMessageInterval(UBX_CFG_KEY_ID::CFG_MSGOUT_UBX_NAV_TIMEGPS_UART1, 240, false); // every 4 minutes diff --git a/src/gpsrecord.cpp b/src/gpsrecord.cpp index 52dcd0b..8c13ae2 100644 --- a/src/gpsrecord.cpp +++ b/src/gpsrecord.cpp @@ -40,6 +40,8 @@ void GpsRecord::reset(uint32_t tow, uint32_t gpsWeek, uint32_t createdAtMillisTi mVelocitySet = false; mInfoSet = false; mHdopSet = false; + hwVer = "unknown"; + swVer = "unknown"; } void GpsRecord::setWeek(uint32_t week) { diff --git a/src/gpsrecord.h b/src/gpsrecord.h index 9a89af3..13cfee9 100644 --- a/src/gpsrecord.h +++ b/src/gpsrecord.h @@ -102,7 +102,8 @@ class GpsRecord { uint32_t mCreatedAtMillisTicks; static const int32_t pow10[10]; static String toScaledString(int32_t value, uint16_t scale); - + String hwVer; + String swVer; }; From 6f1726cca901f5c8fecbf6373783414de280d0c1 Mon Sep 17 00:00:00 2001 From: gluap Date: Sun, 16 Feb 2025 21:35:26 +0100 Subject: [PATCH 07/16] Runtime check for neo6 or neo8 --- src/OpenBikeSensorFirmware.cpp | 1 - src/gps.cpp | 89 +++++++++++++++++++++++++++++----- src/gps.h | 7 +++ src/gpsrecord.cpp | 2 - src/gpsrecord.h | 2 - 5 files changed, 84 insertions(+), 17 deletions(-) diff --git a/src/OpenBikeSensorFirmware.cpp b/src/OpenBikeSensorFirmware.cpp index 84988d3..ecd9050 100644 --- a/src/OpenBikeSensorFirmware.cpp +++ b/src/OpenBikeSensorFirmware.cpp @@ -446,7 +446,6 @@ void setup() { gps.handle(); setupBluetooth(cfg, trackUniqueIdentifier); - obsDisplay->clear(); obsDisplay->showTextOnGrid(2, obsDisplay->newLine(), "Wait for GPS"); obsDisplay->newLine(); gps.handle(); diff --git a/src/gps.cpp b/src/gps.cpp index 1ada880..45c9f39 100644 --- a/src/gps.cpp +++ b/src/gps.cpp @@ -31,14 +31,56 @@ const String Gps::INF_SEVERITY_STRING[] = { String("TST"), String("DBG") }; +bool Gps::is_neo6() const { + if (String(hwString).substring(0,4) == String("00040007").substring(0,4)) { + return true; + } + return false; +} + +bool Gps::is_neo8() const { + if (String(hwString).substring(0,4) == String("00080000").substring(0,4)) { + return true; + } + return false; +} + +bool Gps::is_neo10() const { + if (String(hwString).substring(0,4) == String("000A0000").substring(0,4)) { + return true; + } + return false; +} + +String Gps::hw() const { + if (is_neo6()){ + return "Neo6"; + } + if (is_neo8()){ + return "Neo8"; + } + if (is_neo10()) { + return "NeoA"; + } + return "Neo" + String(hwString).substring(3,4); +} + void Gps::begin() { setBaud(); softResetGps(); - //if (mGpsNeedsConfigUpdate) { + if (mGpsNeedsConfigUpdate) { configureGpsModule(); - //} - // enableAlpIfDataIsAvailable(); + } + pollStatistics(); + if(is_neo8()) { + coldStartGps(); + } pollStatistics(); + + if (is_neo6()) { + enableAlpIfDataIsAvailable(); + } + if (mLastTimeTimeSet == 0) { #ifdef UBX_M10 setMessageInterval(UBX_CFG_KEY_ID::CFG_MSGOUT_UBX_NAV_TIMEGPS_UART1, 1); @@ -300,6 +342,21 @@ void Gps::configureGpsModule() { void Gps::softResetGps() { log_i("Soft-RESET GPS!"); handle(); + const uint8_t UBX_CFG_RST[] = {0x00, 0x00, 0x02, 0x00}; // WARM START + //const uint8_t UBX_CFG_RST[] = {0xFF, 0x81, 0x04, 0x00}; // Cold START '0xFF, 0x81, 0x04, 0x00' + // we had the case where the reset took several seconds + // see https://github.com/openbikesensor/OpenBikeSensorFirmware/issues/309 + // Newer firmware (like M10 and likely also M8) will not ack this + // message so we do not wait for the ACK + sendUbx(UBX_MSG::CFG_RST, UBX_CFG_RST, 4); + waitForData(1000); + handle(); + log_i("Soft-RESET GPS! Done"); +} + +void Gps::coldStartGps() { + log_i("Cold-Start GPS!"); + handle(); //const uint8_t UBX_CFG_RST[] = {0x00, 0x00, 0x02, 0x00}; // WARM START const uint8_t UBX_CFG_RST[] = {0xFF, 0x81, 0x04, 0x00}; // Cold START '0xFF, 0x81, 0x04, 0x00' // we had the case where the reset took several seconds @@ -309,7 +366,7 @@ void Gps::softResetGps() { sendUbx(UBX_MSG::CFG_RST, UBX_CFG_RST, 4); waitForData(1000); handle(); - log_i("Soft-RESET GPS! Done"); + log_i("Cold Start GPS! Done"); } /* There had been changes for the satellites used for SBAS @@ -785,24 +842,31 @@ int32_t Gps::getMessagesWithFailedCrcCount() const { } void Gps::showWaitStatus(DisplayDevice const * display) const { + static bool clear = false; + if (!is_neo6() && !clear) { + obsDisplay->clear(); + clear = true; + } String satellitesString[3]; if (mValidMessagesReceived == 0) { // could not get any valid char from GPS module satellitesString[0] = "OFF?"; } else if (mLastTimeTimeSet == 0) { satellitesString[0] = String(mCurrentGpsRecord.mSatellitesUsed) + "sats SN:" + String(mLastNoiseLevel); } else { - satellitesString[0] = "GPS " + TimeUtils::timeToString(); + satellitesString[0] = String(hw()).substring(1) + TimeUtils::timeToString(); satellitesString[1] = String(mCurrentGpsRecord.mSatellitesUsed) + "sats SN:" + String(mLastNoiseLevel); } satellitesString[2] = String(mCurrentGpsRecord.mFixStatus) + "" + String(mValidMessagesReceived); obsDisplay->showTextOnGrid(2, display->currentLine() - 1, satellitesString[0]); obsDisplay->showTextOnGrid(2, display->currentLine(), satellitesString[1]); - obsDisplay->showTextOnGrid(0, 1, satellitesString[2]); - obsDisplay->showTextOnGrid(0, 2, String(mCurrentGpsRecord.mLatitude)); - obsDisplay->showTextOnGrid(0, 3, String(mCurrentGpsRecord.mLongitude)); - obsDisplay->showTextOnGrid(0, 4, String(mCurrentGpsRecord.hwVer)); - obsDisplay->showTextOnGrid(0, 5, String(mCurrentGpsRecord.swVer)); + if (!is_neo6()){ + obsDisplay->showTextOnGrid(0, 1, satellitesString[2]); + obsDisplay->showTextOnGrid(0, 2, String(mCurrentGpsRecord.mLatitude)); + obsDisplay->showTextOnGrid(0, 3, String(mCurrentGpsRecord.mLongitude)); + obsDisplay->showTextOnGrid(0, 4, String(hw())+" Detail"); + + } } bool Gps::moduleIsAlive() const { @@ -1108,8 +1172,9 @@ void Gps::parseUbxMessage() { String(mGpsBuffer.monVer.swVersion).c_str(), String(mGpsBuffer.monVer.hwVersion).c_str(), mGpsBuffer.ubxHeader.length); - mIncomingGpsRecord.swVer = String(mGpsBuffer.monVer.swVersion); - mIncomingGpsRecord.hwVer = String(mGpsBuffer.monVer.hwVersion); + for (int i = 0; i < sizeof(hwString) && i < sizeof(mGpsBuffer.monVer.hwVersion) ; i++) { + hwString[i]=mGpsBuffer.monVer.hwVersion[i]; + } } break; case (uint16_t) UBX_MSG::MON_HW: { diff --git a/src/gps.h b/src/gps.h index e5fccab..48a90db 100644 --- a/src/gps.h +++ b/src/gps.h @@ -567,11 +567,17 @@ class Gps { bool mGpsNeedsConfigUpdate = false; static const String INF_SEVERITY_STRING[]; + char hwString[10]; + void configureGpsModule(); bool encode(uint8_t data); bool setBaud(); + bool is_neo6() const; + bool is_neo8() const; + bool is_neo10() const; + String hw() const; bool checkCommunication(); @@ -625,6 +631,7 @@ class Gps { void prepareGpsData(uint32_t tow, uint32_t messageStartedMillisTicks); void softResetGps(); + void coldStartGps(); void handleUbxNavTimeGps(const GpsBuffer::UbxNavTimeGps & message, const uint32_t receivedMs, const uint32_t delayMs); void handleUbxAidIni(const GpsBuffer::AidIni &message) const; diff --git a/src/gpsrecord.cpp b/src/gpsrecord.cpp index 8c13ae2..52dcd0b 100644 --- a/src/gpsrecord.cpp +++ b/src/gpsrecord.cpp @@ -40,8 +40,6 @@ void GpsRecord::reset(uint32_t tow, uint32_t gpsWeek, uint32_t createdAtMillisTi mVelocitySet = false; mInfoSet = false; mHdopSet = false; - hwVer = "unknown"; - swVer = "unknown"; } void GpsRecord::setWeek(uint32_t week) { diff --git a/src/gpsrecord.h b/src/gpsrecord.h index 13cfee9..60c6dc8 100644 --- a/src/gpsrecord.h +++ b/src/gpsrecord.h @@ -102,8 +102,6 @@ class GpsRecord { uint32_t mCreatedAtMillisTicks; static const int32_t pow10[10]; static String toScaledString(int32_t value, uint16_t scale); - String hwVer; - String swVer; }; From 9278e80f018c7f101274aa9c04d3b506c678a731 Mon Sep 17 00:00:00 2001 From: gluap Date: Mon, 17 Feb 2025 21:24:30 +0100 Subject: [PATCH 08/16] Adapt the two implementations of "coldstart"; move the gain display so it is always visible. Keep Coldstarting on boot for neo8m --- src/configServer.cpp | 2 +- src/gps.cpp | 10 +++++----- src/gps.h | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/configServer.cpp b/src/configServer.cpp index 7902f27..7e7163b 100644 --- a/src/configServer.cpp +++ b/src/configServer.cpp @@ -1134,7 +1134,7 @@ static void handleColdStartGPS(HTTPRequest *, HTTPResponse * res) { String html = createPage(gpsColdIndex); html = replaceDefault(html, "Navigation"); sendHtml(res, html); - gps.coldResetGps(); + gps.coldStartGps(); res->finalize(); } diff --git a/src/gps.cpp b/src/gps.cpp index 753a123..c86264c 100644 --- a/src/gps.cpp +++ b/src/gps.cpp @@ -862,11 +862,11 @@ void Gps::showWaitStatus(DisplayDevice const * display) const { obsDisplay->showTextOnGrid(2, display->currentLine() - 1, satellitesString[0]); obsDisplay->showTextOnGrid(2, display->currentLine(), satellitesString[1]); if (!is_neo6()){ - obsDisplay->showTextOnGrid(0, 1, satellitesString[2]); - obsDisplay->showTextOnGrid(0, 2, String(mCurrentGpsRecord.mLatitude)); - obsDisplay->showTextOnGrid(0, 3, String(mCurrentGpsRecord.mLongitude)); - obsDisplay->showTextOnGrid(0, 4, String(hw())+" Detail"); - + obsDisplay->showTextOnGrid(0, 1, String(hw())+" Detail"); + obsDisplay->showTextOnGrid(0, 2, satellitesString[2]); + obsDisplay->showTextOnGrid(0, 3, String(mCurrentGpsRecord.mLatitude)); + obsDisplay->showTextOnGrid(0, 4, String(mCurrentGpsRecord.mLongitude)); + obsDisplay->showTextOnGrid(0, 5, "Gain:" + String(mLastGain) + " Jam:" + String(mLastJamInd)); } } diff --git a/src/gps.h b/src/gps.h index 549e726..dd9e603 100644 --- a/src/gps.h +++ b/src/gps.h @@ -111,7 +111,8 @@ class Gps { uint32_t getNumberOfAlpBytesSent() const; uint32_t getUnexpectedCharReceivedCount() const; - void coldResetGps(); + void coldStartGps(); + private: /* ALP msgs up to 0x16A seen might be more? */ @@ -640,7 +641,6 @@ class Gps { void prepareGpsData(uint32_t tow, uint32_t messageStartedMillisTicks); void softResetGps(); - void coldStartGps(); void handleUbxNavTimeGps(const GpsBuffer::UbxNavTimeGps & message, const uint32_t receivedMs, const uint32_t delayMs); void handleUbxAidIni(const GpsBuffer::AidIni &message) const; From 5b282fa82989bbd504f9c4fc110e0017131bb28d Mon Sep 17 00:00:00 2001 From: gluap Date: Mon, 17 Feb 2025 22:00:51 +0100 Subject: [PATCH 09/16] Make note how to generate the codes with relative ease via pyubx2; better display layout --- src/gps.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/gps.cpp b/src/gps.cpp index c86264c..a951dd0 100644 --- a/src/gps.cpp +++ b/src/gps.cpp @@ -359,6 +359,11 @@ void Gps::coldStartGps() { handle(); //const uint8_t UBX_CFG_RST[] = {0x00, 0x00, 0x02, 0x00}; // WARM START const uint8_t UBX_CFG_RST[] = {0xFF, 0x81, 0x04, 0x00}; // Cold START '0xFF, 0x81, 0x04, 0x00' + // https://content.u-blox.com/sites/default/files/products/documents/u-blox8-M8_ReceiverDescrProtSpec_UBX-13003221.pdf?utm_content=UBX-13003221 + // eph=1, alm=1, health=1, klob=1, pos=1, clkd=1, osc=1, utc=1, rtc=1, aop=1, resetMode=4, reserved0=0 + // can be generated via pyubx2 UBXMessage reset = pyubx2.UBXMessage(...) + // output via ", ".join([f"0x{b:02X}" for b in reset.payload]) + // we had the case where the reset took several seconds // see https://github.com/openbikesensor/OpenBikeSensorFirmware/issues/309 // Newer firmware (like M10 and likely also M8) will not ack this @@ -863,10 +868,10 @@ void Gps::showWaitStatus(DisplayDevice const * display) const { obsDisplay->showTextOnGrid(2, display->currentLine(), satellitesString[1]); if (!is_neo6()){ obsDisplay->showTextOnGrid(0, 1, String(hw())+" Detail"); - obsDisplay->showTextOnGrid(0, 2, satellitesString[2]); - obsDisplay->showTextOnGrid(0, 3, String(mCurrentGpsRecord.mLatitude)); - obsDisplay->showTextOnGrid(0, 4, String(mCurrentGpsRecord.mLongitude)); - obsDisplay->showTextOnGrid(0, 5, "Gain:" + String(mLastGain) + " Jam:" + String(mLastJamInd)); + obsDisplay->showTextOnGrid(0, 2, "Gain:" + String(mLastGain) + " Jam:" + String(mLastJamInd)); + obsDisplay->showTextOnGrid(0, 3, satellitesString[2]); + obsDisplay->showTextOnGrid(0, 4, String(mCurrentGpsRecord.mLatitude)); + obsDisplay->showTextOnGrid(0, 5, String(mCurrentGpsRecord.mLongitude)); } } From 07ac35663eb9cc7205d3e8cf4980def8902f6229 Mon Sep 17 00:00:00 2001 From: gluap Date: Sun, 23 Feb 2025 21:20:02 +0100 Subject: [PATCH 10/16] ALP only on neo6m; conditional resstarts on neo6m when AID has issues and others (always) --- src/gps.cpp | 19 +++++++++++++++---- src/utils/alpdata.cpp | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/gps.cpp b/src/gps.cpp index a951dd0..31e5804 100644 --- a/src/gps.cpp +++ b/src/gps.cpp @@ -72,7 +72,14 @@ void Gps::begin() { configureGpsModule(); } pollStatistics(); - if(is_neo8()) { + if((!is_neo6()) || (!SD.exists(AID_INI_DATA_FILE_NAME))) { + // we're on a non-6 neo and avoid AID_INI because is deprecated + // or we're on a neo6 but last boot we didn't get far enough to receive fresh + // ALP_INI data after initializing + // so restart GPS for good measure. + if (is_neo6()) log_i("We found no AID_INI on with neo6 on boot - coldstart gps in case its in a state where it doesn't get fixes"); + if (!is_neo6()) log_i("Coldstart because we found that newer neos profit from that."); + coldStartGps(); } pollStatistics(); @@ -414,11 +421,15 @@ void Gps::enableAlpIfDataIsAvailable() { /* Poll or refresh one time statistics, also spends some time * to collect the results. */ + void Gps::pollStatistics() { - handle(); - sendUbx(UBX_MSG::AID_ALP); handle(); sendUbx(UBX_MSG::MON_VER); + handle(20); + if (is_neo6()){ + // AID_ALP is a neo6-only thing + sendUbx(UBX_MSG::AID_ALP); + } handle(); sendUbx(UBX_MSG::MON_HW); handle(); @@ -1206,7 +1217,7 @@ void Gps::parseUbxMessage() { mGpsUptime = mGpsBuffer.navStatus.msss; if (mGpsBuffer.navStatus.ttff != 0) { addStatisticsMessage("TimeToFix: " + String(mGpsBuffer.navStatus.ttff) + "ms"); - } else if (!mAidIniSent) { + } else if (!mAidIniSent and is_neo6()) { mAidIniSent = true; aidIni(); } diff --git a/src/utils/alpdata.cpp b/src/utils/alpdata.cpp index baff084..fe9b549 100644 --- a/src/utils/alpdata.cpp +++ b/src/utils/alpdata.cpp @@ -172,6 +172,7 @@ size_t AlpData::loadMessage(uint8_t *data, size_t size) { result = f.read(data, size); f.close(); log_d("Read %d bytes", result); + SD.remove(AID_INI_DATA_FILE_NAME); } return result; } From a2b626391af7d71e67ee7814fa2336a8a589070a Mon Sep 17 00:00:00 2001 From: gluap Date: Fri, 28 Feb 2025 21:09:19 +0100 Subject: [PATCH 11/16] implement reviewer notes --- src/gps.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/gps.cpp b/src/gps.cpp index 31e5804..5cd4dd6 100644 --- a/src/gps.cpp +++ b/src/gps.cpp @@ -32,21 +32,21 @@ const String Gps::INF_SEVERITY_STRING[] = { }; bool Gps::is_neo6() const { - if (String(hwString).substring(0,4) == String("00040007").substring(0,4)) { + if (String(hwString).substring(0,4) == String("0004")) { return true; } return false; } bool Gps::is_neo8() const { - if (String(hwString).substring(0,4) == String("00080000").substring(0,4)) { + if (String(hwString).substring(0,4) == String("0008")) { return true; } return false; } bool Gps::is_neo10() const { - if (String(hwString).substring(0,4) == String("000A0000").substring(0,4)) { + if (String(hwString).substring(0,4) == String("000A")) { return true; } return false; @@ -298,14 +298,6 @@ void Gps::configureGpsModule() { } else { addStatisticsMessage("No ack for setting timepulse in either new or old format"); } - const uint8_t UBX_CFG_RATE[] = {0xE8, 0x03, 0x01, 0x00, 0x00, 0x00}; - if (!sendAndWaitForAck(UBX_MSG::CFG_TP5, UBX_CFG_TP5, sizeof(UBX_CFG_RATE))) { - addStatisticsMessage("Successfully set rate"); - obsDisplay->showTextOnGrid(0, 5, "rate set"); - } else{ - obsDisplay->showTextOnGrid(0, 5, "rate not set"); - } - } #endif @@ -1418,6 +1410,7 @@ void Gps::handleUbxNavTimeGps(const GpsBuffer::UbxNavTimeGps &message, const uin mIncomingGpsRecord.setWeek(mLastGpsWeek); } if ((message.valid & 0x03) == 0x03 // WEEK && TOW + && delayMs < 1000 && message.tAcc < (20 * 1000 * 1000 /* 20ms */) && ((mLastTimeTimeSet == 0) || ((mLastTimeTimeSet + (2 * 60 * 1000 /* 2 minutes */)) < receivedMs))) { @@ -1431,10 +1424,12 @@ void Gps::handleUbxNavTimeGps(const GpsBuffer::UbxNavTimeGps &message, const uin + "ms. tAcc:" + String(message.tAcc) + "ns"); } if (mLastTimeTimeSet == 0) { - mLastTimeTimeSet = receivedMs; - // This triggers another NAV-TIMEGPS message! + if (delayMs < 100) { // keep mLastTimeTimeSet at 0 unless reasonable delayMs + mLastTimeTimeSet = receivedMs; + } + // This triggers another NAV-TIMEGPS message! more often until good time is received #ifdef UBX_M6 - setMessageInterval(UBX_MSG::NAV_TIMEGPS, (delayMs>200) ? 5 : 240, false); // every 4 minutes + setMessageInterval(UBX_MSG::NAV_TIMEGPS, (delayMs>100) ? 5 : 240, false); // every 4 minutes #endif #ifdef UBX_M10 setMessageInterval(UBX_CFG_KEY_ID::CFG_MSGOUT_UBX_NAV_TIMEGPS_UART1, 240, false); // every 4 minutes From 1d09a7fbde2106fc10f7b1b8b10aafccc6fa0178 Mon Sep 17 00:00:00 2001 From: gluap Date: Sat, 1 Mar 2025 10:53:32 +0100 Subject: [PATCH 12/16] change coldstart command --- src/gps.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/gps.cpp b/src/gps.cpp index 5cd4dd6..3d89847 100644 --- a/src/gps.cpp +++ b/src/gps.cpp @@ -342,7 +342,6 @@ void Gps::softResetGps() { log_i("Soft-RESET GPS!"); handle(); const uint8_t UBX_CFG_RST[] = {0x00, 0x00, 0x02, 0x00}; // WARM START - //const uint8_t UBX_CFG_RST[] = {0xFF, 0x81, 0x04, 0x00}; // Cold START '0xFF, 0x81, 0x04, 0x00' // we had the case where the reset took several seconds // see https://github.com/openbikesensor/OpenBikeSensorFirmware/issues/309 // Newer firmware (like M10 and likely also M8) will not ack this @@ -356,13 +355,7 @@ void Gps::softResetGps() { void Gps::coldStartGps() { log_i("Cold-Start GPS!"); handle(); - //const uint8_t UBX_CFG_RST[] = {0x00, 0x00, 0x02, 0x00}; // WARM START - const uint8_t UBX_CFG_RST[] = {0xFF, 0x81, 0x04, 0x00}; // Cold START '0xFF, 0x81, 0x04, 0x00' - // https://content.u-blox.com/sites/default/files/products/documents/u-blox8-M8_ReceiverDescrProtSpec_UBX-13003221.pdf?utm_content=UBX-13003221 - // eph=1, alm=1, health=1, klob=1, pos=1, clkd=1, osc=1, utc=1, rtc=1, aop=1, resetMode=4, reserved0=0 - // can be generated via pyubx2 UBXMessage reset = pyubx2.UBXMessage(...) - // output via ", ".join([f"0x{b:02X}" for b in reset.payload]) - + const uint8_t UBX_CFG_RST[] = {0xFF, 0xFF, 0x00, 0x00}; // we had the case where the reset took several seconds // see https://github.com/openbikesensor/OpenBikeSensorFirmware/issues/309 // Newer firmware (like M10 and likely also M8) will not ack this From 434aacd633fc6482f136fd34837f8fc8cec550e5 Mon Sep 17 00:00:00 2001 From: gluap Date: Sat, 1 Mar 2025 11:03:33 +0100 Subject: [PATCH 13/16] skip ALP download on non-neo6 gpses --- src/configServer.cpp | 2 +- src/gps.h | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/configServer.cpp b/src/configServer.cpp index 7e7163b..9db6406 100644 --- a/src/configServer.cpp +++ b/src/configServer.cpp @@ -729,7 +729,7 @@ static void wifiConnectedActions() { if (WiFiClass::status() == WL_CONNECTED) { TimeUtils::setClockByNtpAndWait(WiFi.gatewayIP().toString().c_str()); } - if (SD.begin() && WiFiClass::status() == WL_CONNECTED) { + if (SD.begin() && WiFiClass::status() == WL_CONNECTED && gps.is_neo6()) { AlpData::update(obsDisplay); } diff --git a/src/gps.h b/src/gps.h index dd9e603..c15a0bf 100644 --- a/src/gps.h +++ b/src/gps.h @@ -113,6 +113,9 @@ class Gps { void coldStartGps(); + bool is_neo6() const; + bool is_neo8() const; + bool is_neo10() const; private: /* ALP msgs up to 0x16A seen might be more? */ @@ -584,9 +587,7 @@ class Gps { bool encode(uint8_t data); bool setBaud(); - bool is_neo6() const; - bool is_neo8() const; - bool is_neo10() const; + String hw() const; bool checkCommunication(); From 40eac723fb78ce2a1e1433ca9d7924fd33939951 Mon Sep 17 00:00:00 2001 From: gluap Date: Sat, 1 Mar 2025 11:15:40 +0100 Subject: [PATCH 14/16] differentiate between Neo6m and newer dialects for MON_HW --- src/gps.cpp | 37 ++++++++++++++++++++++++++----------- src/gps.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 11 deletions(-) diff --git a/src/gps.cpp b/src/gps.cpp index 3d89847..68c1fcb 100644 --- a/src/gps.cpp +++ b/src/gps.cpp @@ -1181,18 +1181,33 @@ void Gps::parseUbxMessage() { break; case (uint16_t) UBX_MSG::MON_HW: { const char* aStatus; - switch (mGpsBuffer.monHw.aStatus) { - case mGpsBuffer.monHw.INIT: aStatus = "init"; break; - case mGpsBuffer.monHw.DONTKNOW: aStatus = "?"; break; - case mGpsBuffer.monHw.OK: aStatus = "ok"; break; - case mGpsBuffer.monHw.SHORT: aStatus = "short"; break; - case mGpsBuffer.monHw.OPEN: aStatus = "open"; break; - default: aStatus = "invalid"; + if (is_neo6()) { + switch (mGpsBuffer.monHw.aStatus) { + case mGpsBuffer.monHw.INIT: aStatus = "init"; break; + case mGpsBuffer.monHw.DONTKNOW: aStatus = "?"; break; + case mGpsBuffer.monHw.OK: aStatus = "ok"; break; + case mGpsBuffer.monHw.SHORT: aStatus = "short"; break; + case mGpsBuffer.monHw.OPEN: aStatus = "open"; break; + default: aStatus = "invalid"; + } + log_d("MON-HW Antenna Status %d %s, Antenna Power %d, Gain (0-8191) %d, noise level %d", mGpsBuffer.monHw.aStatus, aStatus, mGpsBuffer.monHw.aPower, mGpsBuffer.monHw.agcCnt, mGpsBuffer.monHw.noisePerMs); + mLastNoiseLevel = mGpsBuffer.monHw.noisePerMs; + mLastGain = mGpsBuffer.monHw.agcCnt; + mLastJamInd = mGpsBuffer.monHw.jamInd; + } else { + switch (mGpsBuffer.monHwNew.aStatus) { + case mGpsBuffer.monHwNew.INIT: aStatus = "init"; break; + case mGpsBuffer.monHwNew.DONTKNOW: aStatus = "?"; break; + case mGpsBuffer.monHwNew.OK: aStatus = "ok"; break; + case mGpsBuffer.monHwNew.SHORT: aStatus = "short"; break; + case mGpsBuffer.monHwNew.OPEN: aStatus = "open"; break; + default: aStatus = "invalid"; + } + log_d("MON-HW Antenna Status %d %s, Antenna Power %d, Gain (0-8191) %d, noise level %d", mGpsBuffer.monHwNew.aStatus, aStatus, mGpsBuffer.monHwNew.aPower, mGpsBuffer.monHwNew.agcCnt, mGpsBuffer.monHwNew.noisePerMs); + mLastNoiseLevel = mGpsBuffer.monHwNew.noisePerMs; + mLastGain = mGpsBuffer.monHwNew.agcCnt; + mLastJamInd = mGpsBuffer.monHwNew.jamInd; } - log_d("MON-HW Antenna Status %d %s, Antenna Power %d, Gain (0-8191) %d, noise level %d", mGpsBuffer.monHw.aStatus, aStatus, mGpsBuffer.monHw.aPower, mGpsBuffer.monHw.agcCnt, mGpsBuffer.monHw.noisePerMs); - mLastNoiseLevel = mGpsBuffer.monHw.noisePerMs; - mLastGain = mGpsBuffer.monHw.agcCnt; - mLastJamInd = mGpsBuffer.monHw.jamInd; } break; case (uint16_t) UBX_MSG::NAV_STATUS: { diff --git a/src/gps.h b/src/gps.h index c15a0bf..a5cd341 100644 --- a/src/gps.h +++ b/src/gps.h @@ -320,6 +320,36 @@ class Gps { uint32_t pinIrq; uint32_t pullH; uint32_t pullL; + } monHwNew; + struct __attribute__((__packed__)) { + UBX_HEADER ubxHeader; + uint32_t pinSel; + uint32_t pinBank; + uint32_t pinDir; + uint32_t pinVal; + uint16_t noisePerMs; + uint16_t agcCnt; // AGC (Automatic Gain Control) Monitor, as percentage of maximum gain,range 0 to 8191 (100%) + enum ANT_STATUS : uint8_t { + INIT = 0, + DONTKNOW = 1, + OK = 2, + SHORT = 3, + OPEN = 4, + } aStatus; + enum ANT_POWER : uint8_t { + OFF = 0, + ON = 1, + POWER_DONTKNOW = 2, + } aPower; + uint8_t flags; + uint8_t reserved1; + uint32_t usedMask; + uint8_t vp[25]; + uint8_t jamInd; + uint16_t reserved3; + uint32_t pinIrq; + uint32_t pullH; + uint32_t pullL; } monHw; struct __attribute__((__packed__)) { UBX_HEADER ubxHeader; From 1c1956bcf47962f30750b08495dffbbbfedf0b52 Mon Sep 17 00:00:00 2001 From: gluap Date: Sun, 2 Mar 2025 12:30:46 +0100 Subject: [PATCH 15/16] reorder GPS display --- src/gps.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/gps.cpp b/src/gps.cpp index 68c1fcb..11ee1de 100644 --- a/src/gps.cpp +++ b/src/gps.cpp @@ -848,7 +848,7 @@ void Gps::showWaitStatus(DisplayDevice const * display) const { obsDisplay->clear(); clear = true; } - String satellitesString[3]; + String satellitesString[2]; if (mValidMessagesReceived == 0) { // could not get any valid char from GPS module satellitesString[0] = "OFF?"; } else if (mLastTimeTimeSet == 0) { @@ -858,17 +858,21 @@ void Gps::showWaitStatus(DisplayDevice const * display) const { satellitesString[0] = String(hw()).substring(1) + TimeUtils::timeToString(); satellitesString[1] = String(mCurrentGpsRecord.mSatellitesUsed) + "sats SN:" + String(mLastNoiseLevel); } - satellitesString[2] = String(mCurrentGpsRecord.mFixStatus) + "" + String(mValidMessagesReceived); + obsDisplay->showTextOnGrid(2, display->currentLine() - 1, satellitesString[0]); + obsDisplay->showTextOnGrid(2, display->currentLine(), satellitesString[1]); + if (!is_neo6()){ + obsDisplay->showTextOnGrid(0, 1, String(hw())+" GPS"); + obsDisplay->showTextOnGrid(2, 1, "HDOP: " + getHdopAsString() + "D"); - obsDisplay->showTextOnGrid(2, display->currentLine() - 1, satellitesString[0]); - obsDisplay->showTextOnGrid(2, display->currentLine(), satellitesString[1]); - if (!is_neo6()){ - obsDisplay->showTextOnGrid(0, 1, String(hw())+" Detail"); - obsDisplay->showTextOnGrid(0, 2, "Gain:" + String(mLastGain) + " Jam:" + String(mLastJamInd)); - obsDisplay->showTextOnGrid(0, 3, satellitesString[2]); - obsDisplay->showTextOnGrid(0, 4, String(mCurrentGpsRecord.mLatitude)); - obsDisplay->showTextOnGrid(0, 5, String(mCurrentGpsRecord.mLongitude)); - } + obsDisplay->showTextOnGrid(0, 2, "Jam: " + String(mLastJamInd)); + obsDisplay->showTextOnGrid(2, 2, "Msgs: " + String(mValidMessagesReceived)); + obsDisplay->showTextOnGrid(2, 3, "Fix: " + String(mCurrentGpsRecord.mFixStatus) + "D"); + obsDisplay->showTextOnGrid(0, 3, "lat,lon:"); + + + obsDisplay->showTextOnGrid(0, 4, String(mCurrentGpsRecord.mLatitude)); + obsDisplay->showTextOnGrid(0, 5, String(mCurrentGpsRecord.mLongitude)); + } } bool Gps::moduleIsAlive() const { From ae10650831d49f5d3202798eba30ba0d2f72f8f7 Mon Sep 17 00:00:00 2001 From: gluap Date: Mon, 3 Mar 2025 22:36:24 +0100 Subject: [PATCH 16/16] Fix conditional alp download; increase wait to ensure compliance inc ase of slow reset. --- src/OpenBikeSensorFirmware.cpp | 3 ++- src/configServer.cpp | 3 ++- src/gps.cpp | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/OpenBikeSensorFirmware.cpp b/src/OpenBikeSensorFirmware.cpp index ecd9050..bc32a01 100644 --- a/src/OpenBikeSensorFirmware.cpp +++ b/src/OpenBikeSensorFirmware.cpp @@ -399,9 +399,10 @@ void setup() { esp_bt_mem_release(ESP_BT_MODE_BTDM)); // no bluetooth at all here. delay(200); - startServer(&cfg); + obsDisplay->showTextOnGrid(2, obsDisplay->newLine(), "Start GPS..."); gps.begin(); gps.setStatisticsIntervalInSeconds(2); // ?? + startServer(&cfg); while (true) { yield(); serverLoop(); diff --git a/src/configServer.cpp b/src/configServer.cpp index 9db6406..7b1b4fb 100644 --- a/src/configServer.cpp +++ b/src/configServer.cpp @@ -729,7 +729,8 @@ static void wifiConnectedActions() { if (WiFiClass::status() == WL_CONNECTED) { TimeUtils::setClockByNtpAndWait(WiFi.gatewayIP().toString().c_str()); } - if (SD.begin() && WiFiClass::status() == WL_CONNECTED && gps.is_neo6()) { + if (SD.begin() && WiFiClass::status() == WL_CONNECTED + && (!gps.moduleIsAlive() || gps.is_neo6())) { AlpData::update(obsDisplay); } diff --git a/src/gps.cpp b/src/gps.cpp index 11ee1de..a364059 100644 --- a/src/gps.cpp +++ b/src/gps.cpp @@ -361,7 +361,7 @@ void Gps::coldStartGps() { // Newer firmware (like M10 and likely also M8) will not ack this // message so we do not wait for the ACK sendUbx(UBX_MSG::CFG_RST, UBX_CFG_RST, 4); - waitForData(1000); + waitForData(3000); handle(); log_i("Cold Start GPS! Done"); }