From d41aee832e4252ebe2ab87899ee55f1217b798fe Mon Sep 17 00:00:00 2001 From: Florent Date: Wed, 4 Nov 2026 20:34:28 -0400 Subject: [PATCH] gps: guard the clock sync against stalled and too old fixes --- src/helpers/sensors/MicroNMEALocationProvider.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/helpers/sensors/MicroNMEALocationProvider.h b/src/helpers/sensors/MicroNMEALocationProvider.h index db279acb..dddcce19 100644 --- a/src/helpers/sensors/MicroNMEALocationProvider.h +++ b/src/helpers/sensors/MicroNMEALocationProvider.h @@ -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(); }