feat(t1000-e): gps duty cycle — deska ho neměla vůbec
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
6a8044a36f
commit
7e330c4e3f
4 files changed
+82
-20
No files matched your search
@@ -9,6 +9,26 @@
|
||||
|
||||
#define TELEM_CHANNEL_SELF 1 // LPP data channel for 'self' device
|
||||
|
||||
// GPS duty cycle (`gps duty`, gps_enabled == 2). A repeater that runs GPS only
|
||||
// for the clock does not need a continuous fix: the receiver is powered just
|
||||
// long enough to sync the RTC, then cut. On a solar node this is the single
|
||||
// biggest lever there is -- an L76K draws 25-35 mA, an order of magnitude more
|
||||
// than the whole radio + MCU budget it is being spent next to.
|
||||
#ifndef GPS_DUTY_SYNC_INTERVAL_SECS
|
||||
// Same cadence as MicroNMEALocationProvider::TIME_SYNC_INTERVAL, so clock
|
||||
// accuracy is unchanged from `gps on` -- only the power in between differs.
|
||||
#define GPS_DUTY_SYNC_INTERVAL_SECS 1800
|
||||
#endif
|
||||
#ifndef GPS_DUTY_MAX_AWAKE_SECS
|
||||
// Cap on one sync attempt: a blocked sky must not turn duty cycle back into
|
||||
// "always on". A cold fix is tens of seconds, so this is deliberately loose.
|
||||
#define GPS_DUTY_MAX_AWAKE_SECS 300
|
||||
#endif
|
||||
#ifndef GPS_DUTY_RETRY_SECS
|
||||
// Backoff after a window that produced no fix (antenna, snow, indoors).
|
||||
#define GPS_DUTY_RETRY_SECS 3600
|
||||
#endif
|
||||
|
||||
class SensorManager {
|
||||
public:
|
||||
double node_lat, node_lon; // modify these, if you want to affect Advert location
|
||||
|
||||
@@ -4,26 +4,6 @@
|
||||
#include <helpers/SensorManager.h>
|
||||
#include <helpers/sensors/LocationProvider.h>
|
||||
|
||||
// GPS duty cycle (`gps duty`, gps_enabled == 2). A repeater that runs GPS only
|
||||
// for the clock does not need a continuous fix: the receiver is powered just
|
||||
// long enough to sync the RTC, then cut. On a solar node this is the single
|
||||
// biggest lever there is -- an L76K draws 25-35 mA, an order of magnitude more
|
||||
// than the whole radio + MCU budget it is being spent next to.
|
||||
#ifndef GPS_DUTY_SYNC_INTERVAL_SECS
|
||||
// Same cadence as MicroNMEALocationProvider::TIME_SYNC_INTERVAL, so clock
|
||||
// accuracy is unchanged from `gps on` -- only the power in between differs.
|
||||
#define GPS_DUTY_SYNC_INTERVAL_SECS 1800
|
||||
#endif
|
||||
#ifndef GPS_DUTY_MAX_AWAKE_SECS
|
||||
// Cap on one sync attempt: a blocked sky must not turn duty cycle back into
|
||||
// "always on". A cold fix is tens of seconds, so this is deliberately loose.
|
||||
#define GPS_DUTY_MAX_AWAKE_SECS 300
|
||||
#endif
|
||||
#ifndef GPS_DUTY_RETRY_SECS
|
||||
// Backoff after a window that produced no fix (antenna, snow, indoors).
|
||||
#define GPS_DUTY_RETRY_SECS 3600
|
||||
#endif
|
||||
|
||||
class EnvironmentSensorManager : public SensorManager {
|
||||
protected:
|
||||
static const int MAX_ACTIVE_SENSORS = 16;
|
||||
|
||||
@@ -128,6 +128,42 @@ void T1000SensorManager::stop_gps() {
|
||||
}
|
||||
|
||||
|
||||
// Powers the receiver only around a clock sync. Same cadence and the same
|
||||
// reasoning as EnvironmentSensorManager::gpsDutyLoop() -- the GPS is by far the
|
||||
// biggest consumer on the node (46 mA measured), and a node that runs it only
|
||||
// to keep its RTC set does not need a continuous fix.
|
||||
//
|
||||
// One deliberate difference from the environment manager: the off-state here is
|
||||
// sleep_gps(), not stop_gps(). Sleep keeps GPS_VRTC_EN asserted, so the receiver
|
||||
// retains its almanac and the next window gets a warm fix; stop cuts VRTC too and
|
||||
// would buy a cold start every 30 minutes -- which is exactly what duty cycling
|
||||
// is trying not to pay for.
|
||||
void T1000SensorManager::gpsDutyLoop() {
|
||||
if (!gps_duty) return;
|
||||
|
||||
// int32_t deltas, so the 49-day millis() wrap does not park GPS on (or off)
|
||||
// forever.
|
||||
if (!gps_active) {
|
||||
if ((int32_t)(millis() - gps_wake_at) >= 0) {
|
||||
start_gps();
|
||||
_nmea->syncTime(); // clears the parser + arms the sync request
|
||||
gps_awake_until = millis() + (uint32_t)GPS_DUTY_MAX_AWAKE_SECS * 1000;
|
||||
MESH_DEBUG_PRINTLN("gps duty: awake, waiting for fix");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_nmea->waitingTimeSync()) { // RTC got set -> nothing left to stay on for
|
||||
sleep_gps();
|
||||
gps_wake_at = millis() + (uint32_t)GPS_DUTY_SYNC_INTERVAL_SECS * 1000;
|
||||
MESH_DEBUG_PRINTLN("gps duty: synced, off for %d s", (int)GPS_DUTY_SYNC_INTERVAL_SECS);
|
||||
} else if ((int32_t)(millis() - gps_awake_until) >= 0) {
|
||||
sleep_gps();
|
||||
gps_wake_at = millis() + (uint32_t)GPS_DUTY_RETRY_SECS * 1000;
|
||||
MESH_DEBUG_PRINTLN("gps duty: no fix in window, retry in %d s", (int)GPS_DUTY_RETRY_SECS);
|
||||
}
|
||||
}
|
||||
|
||||
bool T1000SensorManager::begin() {
|
||||
// init GPS
|
||||
Serial1.begin(115200);
|
||||
@@ -150,6 +186,7 @@ void T1000SensorManager::loop() {
|
||||
static long next_gps_update = 0;
|
||||
|
||||
_nmea->loop();
|
||||
gpsDutyLoop();
|
||||
|
||||
if (millis() > next_gps_update) {
|
||||
if (gps_active && _nmea->isValid()) {
|
||||
@@ -169,6 +206,10 @@ const char* T1000SensorManager::getSettingName(int i) const {
|
||||
}
|
||||
const char* T1000SensorManager::getSettingValue(int i) const {
|
||||
if (i == 0) {
|
||||
// In duty mode report the mode, not the momentary power state: asleep
|
||||
// between syncs is not the same thing as `gps off`, and something that
|
||||
// round-trips this value must not silently downgrade the mode.
|
||||
if (gps_duty) return "2";
|
||||
return gps_active ? "1" : "0";
|
||||
}
|
||||
return NULL;
|
||||
@@ -176,8 +217,20 @@ const char* T1000SensorManager::getSettingValue(int i) const {
|
||||
bool T1000SensorManager::setSettingValue(const char* name, const char* value) {
|
||||
if (strcmp(name, "gps") == 0) {
|
||||
if (strcmp(value, "0") == 0) {
|
||||
gps_duty = false;
|
||||
sleep_gps(); // sleep for faster fix !
|
||||
} else if (strcmp(value, "2") == 0) {
|
||||
// Duty cycle: power up now (the clock is volatile, so the first sync is
|
||||
// wanted immediately at boot) and let gpsDutyLoop() cut power once the
|
||||
// RTC is set. The awake deadline MUST be armed here as well as in the
|
||||
// loop -- left at 0 it is already in the past, and the first loop pass
|
||||
// would cut GPS before it ever saw a satellite and back off for an hour.
|
||||
gps_duty = true;
|
||||
gps_wake_at = millis();
|
||||
gps_awake_until = millis() + (uint32_t)GPS_DUTY_MAX_AWAKE_SECS * 1000;
|
||||
start_gps();
|
||||
} else {
|
||||
gps_duty = false;
|
||||
start_gps();
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -16,9 +16,18 @@ class T1000SensorManager: public SensorManager {
|
||||
bool gps_active = false;
|
||||
LocationProvider * _nmea;
|
||||
|
||||
// Duty-cycle state, mirroring EnvironmentSensorManager: `gps_duty` is the
|
||||
// MODE, `gps_active` stays the truth about the receiver's power right now.
|
||||
// This board has its own manager, so the state machine cannot simply be
|
||||
// inherited -- see gpsDutyLoop() for the one T1000-specific difference.
|
||||
bool gps_duty = false;
|
||||
uint32_t gps_wake_at = 0; // millis of the next sync attempt
|
||||
uint32_t gps_awake_until = 0; // millis the current attempt gives up at
|
||||
|
||||
void start_gps();
|
||||
void sleep_gps();
|
||||
void stop_gps();
|
||||
void gpsDutyLoop();
|
||||
public:
|
||||
T1000SensorManager(LocationProvider &nmea): _nmea(&nmea) { }
|
||||
bool begin() override;
|
||||
|
||||
Reference in new issue
Block a user