From 16a68f218a56709f0be2e14e2309706bbeaee10f Mon Sep 17 00:00:00 2001 From: Mark Rose Date: Sat, 28 Nov 2026 16:12:35 -0600 Subject: [PATCH] RAK12500 GPS: range-check the module's date, wait for the first NAV-PVT getTimestamp() called the SparkFun library's getUnixEpoch(), which indexes its day tables with the module's year and month unchecked. Use GpsGuard::epochFromFields() instead, which returns 0 (already treated as "no time" by RakLocationProvider) for an implausible date. hasFix() returned the library's fix flag before any NAV-PVT had arrived. The library doesn't clear that record, so until the first reply the flag, position and date were whatever was on the heap. Wait for the first NAV-PVT. Co-Authored-By: Claude Opus 5.5 --- src/helpers/sensors/RakI2cGpsDriver.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/helpers/sensors/RakI2cGpsDriver.h b/src/helpers/sensors/RakI2cGpsDriver.h index 74327c6a..e3df6349 100644 --- a/src/helpers/sensors/RakI2cGpsDriver.h +++ b/src/helpers/sensors/RakI2cGpsDriver.h @@ -3,6 +3,7 @@ #include "GpsDriver.h" #include +#include "GpsGuard.h" // epochFromFields() // Driver for the RAK12500 (u-blox, I2C). Serial NMEA modules are handled by NmeaGpsDriver. class RakI2cGpsDriver : public GpsDriver { @@ -11,6 +12,7 @@ class RakI2cGpsDriver : public GpsDriver { uint8_t _powerPin = 0; bool _detected = false; bool _started = false; + bool _pvtSeen = false; // a NAV-PVT has been received since boot bool probeRak12500(uint8_t powerPin) { #if defined(ETHERNET_ENABLED) && defined(RAK_BOARD) @@ -95,10 +97,24 @@ public: bool isDetected() const { return _detected; } - bool hasFix() { return _started && _gnss.getGnssFixOk(8); } + bool hasFix() { + if (!_started) return false; + // The library allocates its NAV-PVT record without clearing it: until the first reply has + // arrived, the fix flag and every other field are whatever was on the heap. + if (!_pvtSeen) { + if (!_gnss.getPVT(8)) return false; + _pvtSeen = true; + } + return _gnss.getGnssFixOk(8); + } long getLatitude() { return _gnss.getLatitude(2) / 10; } long getLongitude() { return _gnss.getLongitude(2) / 10; } long getAltitude() { return _gnss.getAltitude(2); } long getSatellites() { return _gnss.getSIV(2); } - long getTimestamp() { return _gnss.getUnixEpoch(2); } + // Not getUnixEpoch(): it indexes its day tables with the module's year and month unchecked. + // 0 (no time; RakLocationProvider then leaves the clock alone) for a date or time out of range. + long getTimestamp() { + return GpsGuard::epochFromFields(_gnss.getYear(2), _gnss.getMonth(2), _gnss.getDay(2), + _gnss.getHour(2), _gnss.getMinute(2), _gnss.getSecond(2)); + } };