mirror of
https://github.com/alexhopeoconnor/firmware.git
synced 2026-10-15 16:01:19 +10:00
Fix SENSOR power saving deep sleep truncating TX and skipping sleep on failed reads (#10939)
* Fix SENSOR power saving deep sleep behavior Deep sleep could be entered while a telemetry packet was still queued or on air, truncating the transmission. canSleep() gained a deepSleep parameter and now vetoes in that case; light sleep is unchanged. Telemetry modules defer a pending deep sleep (bounded to 30s) until the radio is idle and no longer let the sensor polling interval override the 5s pre-sleep grace period. A failed sensor read still arms deep sleep instead of leaving the node awake for a full telemetry interval. Fixes #10890 Fixes #10932 * Deduplicate telemetry deep sleep deferral logic Move the radio-busy deferral and its counter into BaseTelemetryModule and add an isPowerSavingSensor() helper. Removes the telemetry-specific counter from OSThread. The sleep arming block stays per module because it needs protected OSThread members not visible to the base class.
This commit is contained in:
@@ -34,6 +34,8 @@ extern void drawCommonHeader(OLEDDisplay *display, int16_t x, int16_t y, const c
|
||||
int32_t PowerTelemetryModule::runOnce()
|
||||
{
|
||||
if (sleepOnNextExecution == true) {
|
||||
if (shouldDeferDeepSleep())
|
||||
return PREFLIGHT_SLEEP_RETRY_MS;
|
||||
sleepOnNextExecution = false;
|
||||
uint32_t nightyNightMs = Default::getConfiguredOrDefaultMs(moduleConfig.telemetry.power_update_interval,
|
||||
default_telemetry_broadcast_interval_secs);
|
||||
@@ -106,6 +108,11 @@ int32_t PowerTelemetryModule::runOnce()
|
||||
lastSentToPhone = millis();
|
||||
}
|
||||
}
|
||||
if (sleepOnNextExecution) {
|
||||
// Honor the pre-sleep grace period armed in sendTelemetry(): OSThread reschedules with
|
||||
// this return value, which would otherwise override setIntervalFromNow()
|
||||
return FIVE_SECONDS_MS;
|
||||
}
|
||||
return min(sendToPhoneIntervalMs, sendToMeshIntervalMs);
|
||||
}
|
||||
|
||||
@@ -258,7 +265,8 @@ bool PowerTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly)
|
||||
meshtastic_Telemetry m = meshtastic_Telemetry_init_zero;
|
||||
m.which_variant = meshtastic_Telemetry_power_metrics_tag;
|
||||
m.time = getTime();
|
||||
if (getPowerTelemetry(&m)) {
|
||||
bool validTelemetry = getPowerTelemetry(&m);
|
||||
if (validTelemetry) {
|
||||
LOG_INFO("Send: ch1_voltage=%f, ch1_current=%f, ch2_voltage=%f, ch2_current=%f, "
|
||||
"ch3_voltage=%f, ch3_current=%f",
|
||||
m.variant.power_metrics.ch1_voltage, m.variant.power_metrics.ch1_current, m.variant.power_metrics.ch2_voltage,
|
||||
@@ -284,16 +292,21 @@ bool PowerTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly)
|
||||
} else {
|
||||
LOG_INFO("Send packet to mesh");
|
||||
service->sendToMesh(p, RX_SRC_LOCAL, true);
|
||||
|
||||
if (config.device.role == meshtastic_Config_DeviceConfig_Role_SENSOR && config.power.is_power_saving) {
|
||||
LOG_DEBUG("Start next execution in 5s then sleep");
|
||||
sleepOnNextExecution = true;
|
||||
setIntervalFromNow(5000);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
// Arm the pre-sleep sequence even when no valid reading was available this cycle: a
|
||||
// power-saving SENSOR node must still return to deep sleep, otherwise it stays awake
|
||||
// until the next telemetry interval and drains its battery
|
||||
if (!phoneOnly && isPowerSavingSensor()) {
|
||||
if (!validTelemetry)
|
||||
LOG_WARN("Power telemetry unavailable this cycle, sleep without sending");
|
||||
sleepOnNextExecution = true;
|
||||
preflightSleepDeferrals = 0;
|
||||
LOG_DEBUG("Start next execution in 5s then sleep");
|
||||
setIntervalFromNow(FIVE_SECONDS_MS);
|
||||
}
|
||||
return validTelemetry;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user