gps: guard the clock sync against stalled and too old fixes

This commit is contained in:
Florent committed 2026-11-08 08:47:34 -04:00
1 parent a134188c62
commit d41aee832e
1 file changed
+8 -2
@@ -70,6 +70,8 @@ class MicroNMEALocationProvider : public LocationProvider {
void finishPeriodicAcquisition() {
if (_firstFixInWindow == 0) fixStatsMiss();
_driver->stop();
nmea.clear(); // the parser keeps the last time as valid otherwise
time_valid = 0;
_acquiringPeriodically = false;
_nextAcquisition = millis() + _gpsPeriodSeconds * 1000UL;
}
@@ -95,7 +97,7 @@ class MicroNMEALocationProvider : public LocationProvider {
}
void updateTime() {
if (!isValid()) time_valid = 0;
if (!isValid() || (millis() - _last_nmea_ms) > 2000) time_valid = 0; // no stale time
if ((long)(millis() - next_check) <= 0) return;
next_check = millis() + 1000;
@@ -156,6 +158,8 @@ public:
_stop_calls++;
_acquiringPeriodically = false;
_driver->stop();
nmea.clear();
time_valid = 0;
}
bool isActive() override {
@@ -274,7 +278,9 @@ public:
fixStatsFix((uint32_t)(_firstFixInWindow - _acquisitionStarted));
}
if (_acquiringPeriodically) {
if (nmea.getNumSatellites() >= GPS_MIN_SATS_FOR_FIX ||
// stay on until a pending time sync is done (or the settle time is over)
const bool synced = _clock == nullptr || !_time_sync_needed;
if ((nmea.getNumSatellites() >= GPS_MIN_SATS_FOR_FIX && synced) ||
(uint32_t)(millis() - _firstFixInWindow) >= GPS_FIX_SETTLE_MS) {
finishPeriodicAcquisition();
}