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

+44 -10
View File
@@ -46,6 +46,8 @@ bool CommonGpsPrefs::apply(SensorManager& sensors) const {
LocationProvider* location = sensors.getLocationProvider();
if (location == nullptr) return false;
applyGuardReference(sensors);
uint32_t first_fix;
if (getFirstFixTimeout(first_fix)) location->setFirstFixTimeout(first_fix);
location->setGpsPeriod(getGpsPeriod());
location->setGpsOn(isGpsEnabled());
return true;
@@ -62,6 +64,20 @@ static void formatDuration(char* buf, size_t size, uint32_t seconds) {
}
}
// "<n>[s|m|h|d]", seconds by default
static bool parseDuration(const char* text, uint32_t& seconds) {
char* end;
unsigned long value = strtoul(text, &end, 10);
unsigned long mult = 1;
if (*end == 'm') mult = 60;
else if (*end == 'h') mult = 3600;
else if (*end == 'd') mult = 86400;
if (mult > 1 || *end == 's') end++; // skip the suffix char
if (text[0] == '\0' || *end != '\0') return false;
seconds = (uint32_t)(value * mult);
return true;
}
bool CommonGpsPrefs::handleCommand(const char* command, SensorManager& sensors, char* reply) {
if (strcmp(command, "gps") == 0) {
LocationProvider* location = sensors.getLocationProvider();
@@ -180,17 +196,10 @@ bool CommonGpsPrefs::handleCommand(const char* command, SensorManager& sensors,
return true;
}
if (memcmp(command, "gps period ", 11) == 0) {
char* end;
unsigned long period = strtoul(command + 11, &end, 10);
unsigned long mult = 1;
if (*end == 'm') mult = 60;
else if (*end == 'h') mult = 3600;
else if (*end == 'd') mult = 86400;
if (mult > 1 || *end == 's') end++; // skip the suffix char
if (command[11] == '\0' || *end != '\0') {
uint32_t period;
if (!parseDuration(command + 11, period)) {
strcpy(reply, "Error, invalid gps period");
} else if (!setGpsPeriod(sensors, (uint32_t)(period * mult)) ||
} else if (!setGpsPeriod(sensors, period) ||
!setGpsEnabled(sensors, true)) {
strcpy(reply, "Error, gps provider not found");
} else {
@@ -198,6 +207,31 @@ bool CommonGpsPrefs::handleCommand(const char* command, SensorManager& sensors,
}
return true;
}
if (strcmp(command, "gps firstfix") == 0) {
LocationProvider* location = sensors.getLocationProvider();
if (location == nullptr) {
strcpy(reply, "Error, gps provider not found");
} else if (location->getFirstFixTimeout() == 0) {
strcpy(reply, "> 0 (no limit)");
} else {
sprintf(reply, "> %lu", (unsigned long)location->getFirstFixTimeout());
}
return true;
}
if (memcmp(command, "gps firstfix ", 13) == 0) {
LocationProvider* location = sensors.getLocationProvider();
uint32_t seconds;
if (location == nullptr) {
strcpy(reply, "Error, gps provider not found");
} else if (!parseDuration(command + 13, seconds) || seconds > 86400UL) { // at most a day
strcpy(reply, "Error, invalid first fix timeout");
} else {
location->setFirstFixTimeout(seconds);
setFirstFixTimeout(seconds); // saved by the caller (isDirty)
strcpy(reply, "OK");
}
return true;
}
if (memcmp(command, "gps sync", 8) == 0) {
LocationProvider* location = sensors.getLocationProvider();
if (location == nullptr) {