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 <noreply@anthropic.com>
This commit is contained in:
Mark RoseandClaude Opus 5.5 committed 2026-11-28 16:12:35 -06:00
1 parent 96db79dbc0
commit 16a68f218a
1 file changed
+18 -2
+18 -2
View File
@@ -3,6 +3,7 @@
#include "GpsDriver.h"
#include <SparkFun_u-blox_GNSS_Arduino_Library.h>
#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));
}
};