gps: periodic acquisition rules (timeout, sats and settle time), isEnabled renamed isActive

This commit is contained in:
Florent committed 2026-11-08 08:47:34 -04:00
1 parent e58be9ab11
commit e9d197cf79
9 files changed
+46 -20

No files matched your search

+3 -1
View File
@@ -39,7 +39,7 @@ bool CommonGpsPrefs::handleCommand(const char* command, SensorManager& sensors,
strcpy(reply, "gps provider not found"); strcpy(reply, "gps provider not found");
} else if (location->isGpsOn()) { } else if (location->isGpsOn()) {
const char* activity = "active"; const char* activity = "active";
if (!location->isEnabled()) { if (!location->isActive()) {
if (location->hasHardwareEnableState() && !location->isHardwareEnabled()) { if (location->hasHardwareEnableState() && !location->isHardwareEnabled()) {
activity = "off(hw)"; activity = "off(hw)";
} else if (getGpsPeriod() > 0) { } else if (getGpsPeriod() > 0) {
@@ -56,6 +56,8 @@ bool CommonGpsPrefs::handleCommand(const char* command, SensorManager& sensors,
strcpy(fix, "no fix"); strcpy(fix, "no fix");
} }
snprintf(reply, 160, "on, %s, %s, mode: %s", activity, fix, mode); snprintf(reply, 160, "on, %s, %s, mode: %s", activity, fix, mode);
} else {
snprintf(reply, 160, "off, mode: %s", mode);
} }
return true; return true;
} }
+1 -1
View File
@@ -77,7 +77,7 @@ public:
NmeaGpsDriver::stop(); NmeaGpsDriver::stop();
} }
bool isEnabled() const override { bool isActive() const override {
return digitalRead(GPS_EN) == HIGH; return digitalRead(GPS_EN) == HIGH;
} }
}; };
@@ -631,7 +631,7 @@ bool EnvironmentSensorManager::querySensors(uint8_t requester_permissions, Cayen
next_available_channel = TELEM_CHANNEL_SELF + 1; next_available_channel = TELEM_CHANNEL_SELF + 1;
#if ENV_INCLUDE_GPS #if ENV_INCLUDE_GPS
if (requester_permissions & TELEM_PERM_LOCATION && _location->isEnabled()) { if (requester_permissions & TELEM_PERM_LOCATION && _location->isGpsOn()) {
telemetry.addGPS(TELEM_CHANNEL_SELF, node_lat, node_lon, node_altitude); telemetry.addGPS(TELEM_CHANNEL_SELF, node_lat, node_lon, node_altitude);
} }
#endif #endif
@@ -748,7 +748,7 @@ void EnvironmentSensorManager::loop() {
_location->loop(); _location->loop();
if ((long)(millis() - next_gps_update) > 0) { if ((long)(millis() - next_gps_update) > 0) {
if (_location->isEnabled() && _location->isValid()) { if (_location->isGpsOn() && _location->hasValidFix()) {
node_lat = ((double)_location->getLatitude())/1000000.; node_lat = ((double)_location->getLatitude())/1000000.;
node_lon = ((double)_location->getLongitude())/1000000.; node_lon = ((double)_location->getLongitude())/1000000.;
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon); MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
+1 -1
View File
@@ -9,7 +9,7 @@ public:
virtual void begin() = 0; virtual void begin() = 0;
virtual void reset() = 0; virtual void reset() = 0;
virtual void stop() = 0; virtual void stop() = 0;
virtual bool isEnabled() const = 0; virtual bool isActive() const = 0;
virtual bool hasHardwareEnableState() const { return false; } virtual bool hasHardwareEnableState() const { return false; }
virtual bool isHardwareEnabled() const { return true; } virtual bool isHardwareEnabled() const { return true; }
// Returns true when the switch explicitly enables GPS in software. // Returns true when the switch explicitly enables GPS in software.
+2 -2
View File
@@ -63,14 +63,14 @@ public:
virtual void begin() = 0; virtual void begin() = 0;
virtual void stop() = 0; virtual void stop() = 0;
virtual void loop() = 0; virtual void loop() = 0;
virtual bool isEnabled() = 0; virtual bool isActive() = 0;
// Format compact diagnostics in the caller-provided buffer. Providers that // Format compact diagnostics in the caller-provided buffer. Providers that
// have more information (for example UART counters) can override this. // have more information (for example UART counters) can override this.
virtual void formatDiagnostics(char* out, size_t out_size) { virtual void formatDiagnostics(char* out, size_t out_size) {
if (out_size == 0) return; if (out_size == 0) return;
snprintf(out, out_size, "en:%u sat:%ld fix:%u", snprintf(out, out_size, "en:%u sat:%ld fix:%u",
isEnabled() ? 1U : 0U, isActive() ? 1U : 0U,
satellitesCount(), satellitesCount(),
isValid() ? 1U : 0U); isValid() ? 1U : 0U);
} }
@@ -7,7 +7,16 @@
#include <string.h> #include <string.h>
#ifndef GPS_PERIODIC_ACQUISITION_TIMEOUT_MS #ifndef GPS_PERIODIC_ACQUISITION_TIMEOUT_MS
#define GPS_PERIODIC_ACQUISITION_TIMEOUT_MS 120000UL #define GPS_PERIODIC_ACQUISITION_TIMEOUT_MS 300000UL
#endif
// in periodic mode, keep reading after the first valid fix until enough satellites
// are used or the settle time has elapsed
#ifndef GPS_MIN_SATS_FOR_FIX
#define GPS_MIN_SATS_FOR_FIX 5
#endif
#ifndef GPS_FIX_SETTLE_MS
#define GPS_FIX_SETTLE_MS 10000UL
#endif #endif
class MicroNMEALocationProvider : public LocationProvider { class MicroNMEALocationProvider : public LocationProvider {
@@ -22,6 +31,7 @@ class MicroNMEALocationProvider : public LocationProvider {
uint32_t _gpsPeriodSeconds = 0; uint32_t _gpsPeriodSeconds = 0;
unsigned long _nextAcquisition = 0; unsigned long _nextAcquisition = 0;
unsigned long _acquisitionStarted = 0; unsigned long _acquisitionStarted = 0;
unsigned long _firstFixInWindow = 0;
bool _acquiringPeriodically = false; bool _acquiringPeriodically = false;
static const unsigned long TIME_SYNC_INTERVAL = 1800000; static const unsigned long TIME_SYNC_INTERVAL = 1800000;
@@ -54,6 +64,7 @@ class MicroNMEALocationProvider : public LocationProvider {
_driver->reset(); _driver->reset();
_acquiringPeriodically = true; _acquiringPeriodically = true;
_acquisitionStarted = millis(); _acquisitionStarted = millis();
_firstFixInWindow = 0;
} }
void finishPeriodicAcquisition() { void finishPeriodicAcquisition() {
@@ -122,11 +133,12 @@ public:
void begin() override { void begin() override {
_begin_calls++; _begin_calls++;
_driver->begin(); _driver->begin();
if (_gpsPeriodSeconds > 0 && _driver->isEnabled()) { if (_gpsPeriodSeconds > 0 && _driver->isActive()) {
nmea.clear(); nmea.clear();
time_valid = 0; time_valid = 0;
_acquiringPeriodically = true; _acquiringPeriodically = true;
_acquisitionStarted = millis(); _acquisitionStarted = millis();
_firstFixInWindow = 0;
} }
} }
@@ -140,8 +152,8 @@ public:
_driver->stop(); _driver->stop();
} }
bool isEnabled() override { bool isActive() override {
return _driver->isEnabled(); return _driver->isActive();
} }
bool hasHardwareEnableState() const override { bool hasHardwareEnableState() const override {
@@ -249,7 +261,13 @@ public:
if (parsed && nmea.isValid() && if (parsed && nmea.isValid() &&
(strcmp(messageId, "GGA") == 0 || strcmp(messageId, "RMC") == 0)) { (strcmp(messageId, "GGA") == 0 || strcmp(messageId, "RMC") == 0)) {
saveFix(); saveFix();
if (_acquiringPeriodically) finishPeriodicAcquisition(); if (_acquiringPeriodically) {
if (_firstFixInWindow == 0) _firstFixInWindow = millis();
if (nmea.getNumSatellites() >= GPS_MIN_SATS_FOR_FIX ||
(uint32_t)(millis() - _firstFixInWindow) >= GPS_FIX_SETTLE_MS) {
finishPeriodicAcquisition();
}
}
} }
} else { } else {
_nmea_checksum_bad++; _nmea_checksum_bad++;
@@ -257,7 +275,8 @@ public:
} }
} }
if (_acquiringPeriodically && // no timeout until a first fix has been obtained (cold start can be long)
if (_acquiringPeriodically && _lastFix.valid &&
(uint32_t)(millis() - _acquisitionStarted) >= GPS_PERIODIC_ACQUISITION_TIMEOUT_MS) { (uint32_t)(millis() - _acquisitionStarted) >= GPS_PERIODIC_ACQUISITION_TIMEOUT_MS) {
finishPeriodicAcquisition(); finishPeriodicAcquisition();
} }
@@ -277,7 +296,7 @@ public:
snprintf(out, out_size, snprintf(out, out_size,
"en:%u ub:%lu ua:%s ok:%lu bad:%lu na:%s sat:%ld fix:%u fa:%s bc:%lu sc:%lu", "en:%u ub:%lu ua:%s ok:%lu bad:%lu na:%s sat:%ld fix:%u fa:%s bc:%lu sc:%lu",
isEnabled() ? 1U : 0U, isActive() ? 1U : 0U,
(unsigned long)_uart_bytes, (unsigned long)_uart_bytes,
uart_age, uart_age,
(unsigned long)_nmea_checksum_ok, (unsigned long)_nmea_checksum_ok,
+1 -1
View File
@@ -183,7 +183,7 @@ public:
stopHardware(); stopHardware();
} }
bool isEnabled() const override { bool isActive() const override {
return _started && isHardwareEnabled(); return _started && isHardwareEnabled();
} }
+2 -2
View File
@@ -77,8 +77,8 @@ public:
_serialDriver.stop(); _serialDriver.stop();
} }
bool isEnabled() const override { bool isActive() const override {
return _usingRak12500 ? true : _serialDriver.isEnabled(); return _usingRak12500 ? true : _serialDriver.isActive();
} }
bool detect(uint32_t) override { bool detect(uint32_t) override {
+8 -3
View File
@@ -137,7 +137,7 @@ public:
_driver.stop(); _driver.stop();
_acquiringPeriodically = false; _acquiringPeriodically = false;
_nextAcquisition = millis() + _gpsPeriodSeconds * 1000UL; _nextAcquisition = millis() + _gpsPeriodSeconds * 1000UL;
} else if (_gpsPeriodSeconds > 0 && _acquiringPeriodically && } else if (_gpsPeriodSeconds > 0 && _acquiringPeriodically && _lastFix.valid &&
(uint32_t)(millis() - _acquisitionStarted) >= (uint32_t)(millis() - _acquisitionStarted) >=
GPS_PERIODIC_ACQUISITION_TIMEOUT_MS) { GPS_PERIODIC_ACQUISITION_TIMEOUT_MS) {
_driver.stop(); _driver.stop();
@@ -150,8 +150,8 @@ public:
} }
} }
bool isEnabled() override { bool isActive() override {
return _driver.isEnabled(); return _driver.isActive();
} }
void setGpsPeriod(uint32_t seconds) override { void setGpsPeriod(uint32_t seconds) override {
@@ -163,4 +163,9 @@ public:
uint32_t getGpsPeriod() const override { uint32_t getGpsPeriod() const override {
return _gpsPeriodSeconds; return _gpsPeriodSeconds;
} }
void setGpsOn(bool on) override {
if (_driver.usesRak12500()) LocationProvider::setGpsOn(on);
else { _gpsOn = on; _nmea.setGpsOn(on); }
}
}; };