mirror of
https://github.com/meshtastic/firmware.git
synced 2025-02-26 22:33:24 +00:00
Don't attempt to save NodeDB on low-batt shutdown to prevent FS corruption (#5312)
This commit is contained in:
parent
ff33a27789
commit
a84324c4fa
@ -614,7 +614,7 @@ void Power::shutdown()
|
|||||||
#ifdef PIN_LED3
|
#ifdef PIN_LED3
|
||||||
ledOff(PIN_LED3);
|
ledOff(PIN_LED3);
|
||||||
#endif
|
#endif
|
||||||
doDeepSleep(DELAY_FOREVER, false);
|
doDeepSleep(DELAY_FOREVER, false, false);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,9 +55,14 @@ static void sdsEnter()
|
|||||||
{
|
{
|
||||||
LOG_DEBUG("State: SDS");
|
LOG_DEBUG("State: SDS");
|
||||||
// FIXME - make sure GPS and LORA radio are off first - because we want close to zero current draw
|
// FIXME - make sure GPS and LORA radio are off first - because we want close to zero current draw
|
||||||
doDeepSleep(Default::getConfiguredOrDefaultMs(config.power.sds_secs), false);
|
doDeepSleep(Default::getConfiguredOrDefaultMs(config.power.sds_secs), false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void lowBattSDSEnter()
|
||||||
|
{
|
||||||
|
LOG_DEBUG("State: Lower batt SDS");
|
||||||
|
doDeepSleep(Default::getConfiguredOrDefaultMs(config.power.sds_secs), false, true);
|
||||||
|
}
|
||||||
extern Power *power;
|
extern Power *power;
|
||||||
|
|
||||||
static void shutdownEnter()
|
static void shutdownEnter()
|
||||||
@ -247,6 +252,7 @@ static void bootEnter()
|
|||||||
|
|
||||||
State stateSHUTDOWN(shutdownEnter, NULL, NULL, "SHUTDOWN");
|
State stateSHUTDOWN(shutdownEnter, NULL, NULL, "SHUTDOWN");
|
||||||
State stateSDS(sdsEnter, NULL, NULL, "SDS");
|
State stateSDS(sdsEnter, NULL, NULL, "SDS");
|
||||||
|
State stateLowBattSDS(lowBattSDSEnter, NULL, NULL, "SDS");
|
||||||
State stateLS(lsEnter, lsIdle, lsExit, "LS");
|
State stateLS(lsEnter, lsIdle, lsExit, "LS");
|
||||||
State stateNB(nbEnter, NULL, NULL, "NB");
|
State stateNB(nbEnter, NULL, NULL, "NB");
|
||||||
State stateDARK(darkEnter, NULL, NULL, "DARK");
|
State stateDARK(darkEnter, NULL, NULL, "DARK");
|
||||||
@ -291,12 +297,12 @@ void PowerFSM_setup()
|
|||||||
"Press"); // Allow button to work while in serial API
|
"Press"); // Allow button to work while in serial API
|
||||||
|
|
||||||
// Handle critically low power battery by forcing deep sleep
|
// Handle critically low power battery by forcing deep sleep
|
||||||
powerFSM.add_transition(&stateBOOT, &stateSDS, EVENT_LOW_BATTERY, NULL, "LowBat");
|
powerFSM.add_transition(&stateBOOT, &stateLowBattSDS, EVENT_LOW_BATTERY, NULL, "LowBat");
|
||||||
powerFSM.add_transition(&stateLS, &stateSDS, EVENT_LOW_BATTERY, NULL, "LowBat");
|
powerFSM.add_transition(&stateLS, &stateLowBattSDS, EVENT_LOW_BATTERY, NULL, "LowBat");
|
||||||
powerFSM.add_transition(&stateNB, &stateSDS, EVENT_LOW_BATTERY, NULL, "LowBat");
|
powerFSM.add_transition(&stateNB, &stateLowBattSDS, EVENT_LOW_BATTERY, NULL, "LowBat");
|
||||||
powerFSM.add_transition(&stateDARK, &stateSDS, EVENT_LOW_BATTERY, NULL, "LowBat");
|
powerFSM.add_transition(&stateDARK, &stateLowBattSDS, EVENT_LOW_BATTERY, NULL, "LowBat");
|
||||||
powerFSM.add_transition(&stateON, &stateSDS, EVENT_LOW_BATTERY, NULL, "LowBat");
|
powerFSM.add_transition(&stateON, &stateLowBattSDS, EVENT_LOW_BATTERY, NULL, "LowBat");
|
||||||
powerFSM.add_transition(&stateSERIAL, &stateSDS, EVENT_LOW_BATTERY, NULL, "LowBat");
|
powerFSM.add_transition(&stateSERIAL, &stateLowBattSDS, EVENT_LOW_BATTERY, NULL, "LowBat");
|
||||||
|
|
||||||
// Handle being told to power off
|
// Handle being told to power off
|
||||||
powerFSM.add_transition(&stateBOOT, &stateSHUTDOWN, EVENT_SHUTDOWN, NULL, "Shutdown");
|
powerFSM.add_transition(&stateBOOT, &stateSHUTDOWN, EVENT_SHUTDOWN, NULL, "Shutdown");
|
||||||
|
@ -364,7 +364,7 @@ int32_t PositionModule::runOnce()
|
|||||||
sleepOnNextExecution = false;
|
sleepOnNextExecution = false;
|
||||||
uint32_t nightyNightMs = Default::getConfiguredOrDefaultMs(config.position.position_broadcast_secs);
|
uint32_t nightyNightMs = Default::getConfiguredOrDefaultMs(config.position.position_broadcast_secs);
|
||||||
LOG_DEBUG("Sleep for %ims, then awaking to send position again", nightyNightMs);
|
LOG_DEBUG("Sleep for %ims, then awaking to send position again", nightyNightMs);
|
||||||
doDeepSleep(nightyNightMs, false);
|
doDeepSleep(nightyNightMs, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(nodeDB->getNodeNum());
|
meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(nodeDB->getNodeNum());
|
||||||
|
@ -111,7 +111,7 @@ int32_t PowerStressModule::runOnce()
|
|||||||
setBluetoothEnable(true);
|
setBluetoothEnable(true);
|
||||||
break;
|
break;
|
||||||
case meshtastic_PowerStressMessage_Opcode_CPU_DEEPSLEEP:
|
case meshtastic_PowerStressMessage_Opcode_CPU_DEEPSLEEP:
|
||||||
doDeepSleep(sleep_msec, true);
|
doDeepSleep(sleep_msec, true, true);
|
||||||
break;
|
break;
|
||||||
case meshtastic_PowerStressMessage_Opcode_CPU_FULLON: {
|
case meshtastic_PowerStressMessage_Opcode_CPU_FULLON: {
|
||||||
uint32_t start_msec = millis();
|
uint32_t start_msec = millis();
|
||||||
|
@ -74,7 +74,7 @@ int32_t EnvironmentTelemetryModule::runOnce()
|
|||||||
uint32_t nightyNightMs = Default::getConfiguredOrDefaultMs(moduleConfig.telemetry.environment_update_interval,
|
uint32_t nightyNightMs = Default::getConfiguredOrDefaultMs(moduleConfig.telemetry.environment_update_interval,
|
||||||
default_telemetry_broadcast_interval_secs);
|
default_telemetry_broadcast_interval_secs);
|
||||||
LOG_DEBUG("Sleep for %ims, then awake to send metrics again", nightyNightMs);
|
LOG_DEBUG("Sleep for %ims, then awake to send metrics again", nightyNightMs);
|
||||||
doDeepSleep(nightyNightMs, true);
|
doDeepSleep(nightyNightMs, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t result = UINT32_MAX;
|
uint32_t result = UINT32_MAX;
|
||||||
|
@ -40,7 +40,7 @@ int32_t HealthTelemetryModule::runOnce()
|
|||||||
uint32_t nightyNightMs = Default::getConfiguredOrDefaultMs(moduleConfig.telemetry.health_update_interval,
|
uint32_t nightyNightMs = Default::getConfiguredOrDefaultMs(moduleConfig.telemetry.health_update_interval,
|
||||||
default_telemetry_broadcast_interval_secs);
|
default_telemetry_broadcast_interval_secs);
|
||||||
LOG_DEBUG("Sleep for %ims, then awake to send metrics again", nightyNightMs);
|
LOG_DEBUG("Sleep for %ims, then awake to send metrics again", nightyNightMs);
|
||||||
doDeepSleep(nightyNightMs, true);
|
doDeepSleep(nightyNightMs, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t result = UINT32_MAX;
|
uint32_t result = UINT32_MAX;
|
||||||
|
@ -28,7 +28,7 @@ int32_t PowerTelemetryModule::runOnce()
|
|||||||
uint32_t nightyNightMs = Default::getConfiguredOrDefaultMs(moduleConfig.telemetry.power_update_interval,
|
uint32_t nightyNightMs = Default::getConfiguredOrDefaultMs(moduleConfig.telemetry.power_update_interval,
|
||||||
default_telemetry_broadcast_interval_secs);
|
default_telemetry_broadcast_interval_secs);
|
||||||
LOG_DEBUG("Sleep for %ims, then awake to send metrics again", nightyNightMs);
|
LOG_DEBUG("Sleep for %ims, then awake to send metrics again", nightyNightMs);
|
||||||
doDeepSleep(nightyNightMs, true);
|
doDeepSleep(nightyNightMs, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t result = UINT32_MAX;
|
uint32_t result = UINT32_MAX;
|
||||||
|
@ -187,7 +187,7 @@ static void waitEnterSleep(bool skipPreflight = false)
|
|||||||
notifySleep.notifyObservers(NULL);
|
notifySleep.notifyObservers(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void doDeepSleep(uint32_t msecToWake, bool skipPreflight = false)
|
void doDeepSleep(uint32_t msecToWake, bool skipPreflight = false, bool skipSaveNodeDb = false)
|
||||||
{
|
{
|
||||||
if (INCLUDE_vTaskSuspend && (msecToWake == portMAX_DELAY)) {
|
if (INCLUDE_vTaskSuspend && (msecToWake == portMAX_DELAY)) {
|
||||||
LOG_INFO("Enter deep sleep forever");
|
LOG_INFO("Enter deep sleep forever");
|
||||||
@ -219,7 +219,9 @@ void doDeepSleep(uint32_t msecToWake, bool skipPreflight = false)
|
|||||||
|
|
||||||
screen->doDeepSleep(); // datasheet says this will draw only 10ua
|
screen->doDeepSleep(); // datasheet says this will draw only 10ua
|
||||||
|
|
||||||
|
if (!skipSaveNodeDb) {
|
||||||
nodeDB->saveToDisk();
|
nodeDB->saveToDisk();
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef PIN_POWER_EN
|
#ifdef PIN_POWER_EN
|
||||||
pinMode(PIN_POWER_EN, INPUT); // power off peripherals
|
pinMode(PIN_POWER_EN, INPUT); // power off peripherals
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include "Observer.h"
|
#include "Observer.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
|
|
||||||
void doDeepSleep(uint32_t msecToWake, bool skipPreflight), cpuDeepSleep(uint32_t msecToWake);
|
void doDeepSleep(uint32_t msecToWake, bool skipPreflight, bool skipSaveNodeDb), cpuDeepSleep(uint32_t msecToWake);
|
||||||
|
|
||||||
#ifdef ARCH_ESP32
|
#ifdef ARCH_ESP32
|
||||||
#include "esp_sleep.h"
|
#include "esp_sleep.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user