GPS: first fix timeout as a saved setting (gps firstfix), 1 h by default

A cold start can take up to ~30 min with a weak sky view, so the default
limit before the first fix since boot goes from 15 min to 1 h.

The limit is now a GPS preference, set with `gps firstfix <duration>`
(0 = no limit, at most 1 day) and saved with the other GPS settings, so
repeaters and companions can use different values without a rebuild.
GPS_FIRST_FIX_TIMEOUT_MS stays as the build default.
This commit is contained in:
Olexandr Tyshchenko committed 2026-11-13 14:29:02 +02:00
1 parent be9d278a96
commit 407cb9abac
7 files changed
+95 -15

No files matched your search

@@ -12,10 +12,11 @@
#ifndef GPS_PERIODIC_ACQUISITION_TIMEOUT_MS
#define GPS_PERIODIC_ACQUISITION_TIMEOUT_MS 300000UL
#endif
// limit for the periodic window before the first fix since boot (cold start can be long,
// a full almanac takes 12.5 min); 0 = keep searching until a fix
// default limit for the periodic window before the first fix since boot (a cold start
// can take up to ~30 min with a weak sky view); 0 = keep searching until a fix.
// Can be changed at runtime with `gps firstfix`.
#ifndef GPS_FIRST_FIX_TIMEOUT_MS
#define GPS_FIRST_FIX_TIMEOUT_MS 900000UL
#define GPS_FIRST_FIX_TIMEOUT_MS 3600000UL
#endif
// in periodic mode, keep reading after the first valid fix until enough satellites
@@ -41,6 +42,7 @@ class MicroNMEALocationProvider : public LocationProvider {
long time_valid = 0;
unsigned long _last_time_sync = 0;
uint32_t _gpsPeriodSeconds = 0;
uint32_t _firstFixTimeoutSeconds = GPS_FIRST_FIX_TIMEOUT_MS / 1000UL;
unsigned long _nextAcquisition = 0;
unsigned long _acquisitionStarted = 0;
unsigned long _firstFixInWindow = 0;
@@ -204,6 +206,14 @@ public:
return _gpsPeriodSeconds;
}
void setFirstFixTimeout(uint32_t seconds) override {
_firstFixTimeoutSeconds = seconds;
}
uint32_t getFirstFixTimeout() const override {
return _firstFixTimeoutSeconds;
}
uint32_t getAcquisitionAge() const override {
return (uint32_t)(millis() - _acquisitionStarted) / 1000UL;
}
@@ -371,7 +381,7 @@ public:
// a longer limit until a first fix has been obtained (cold start can be long)
if (_acquiringPeriodically) {
const uint32_t limit = _lastFix.valid ? GPS_PERIODIC_ACQUISITION_TIMEOUT_MS
: GPS_FIRST_FIX_TIMEOUT_MS;
: _firstFixTimeoutSeconds * 1000UL;
if (limit > 0 && (uint32_t)(millis() - _acquisitionStarted) >= limit) {
finishPeriodicAcquisition();
}