(needs testing) fixed the following during a plane flight

* Have state machine properly enter deep sleep based on loss of mesh and phone comms.
* Default to enter deep sleep if no LORA received for two hours (indicates user has probably left the mesh).

Signed-off-by: Kevin Hester <kevinh@geeksville.com>
This commit is contained in:
Kevin Hester
2020-03-03 13:31:44 -08:00
parent fe5703c684
commit 375804c9e4
5 changed files with 33 additions and 17 deletions

View File

@@ -9,6 +9,7 @@
#include "GPS.h"
#include "screen.h"
#include "Periodic.h"
#include "PowerFSM.h"
/*
receivedPacketQueue - this is a queue of messages we've received from the mesh, which we are keeping to deliver to the phone.
@@ -144,11 +145,13 @@ void MeshService::handleIncomingPosition(MeshPacket *mp)
void MeshService::handleFromRadio(MeshPacket *mp)
{
powerFSM.trigger(EVENT_RECEIVED_PACKET); // Possibly keep the node from sleeping
mp->rx_time = gps.getValidTime(); // store the arrival timestamp for the phone
// If it is a position packet, perhaps set our clock (if we don't have a GPS of our own, otherwise wait for that to work)
if(!myNodeInfo.has_gps)
handleIncomingPosition(mp);
if (!myNodeInfo.has_gps)
handleIncomingPosition(mp);
if (mp->has_payload && mp->payload.which_variant == SubPacket_user_tag)
{

View File

@@ -54,9 +54,9 @@ void NodeDB::init()
radioConfig.preferences.position_broadcast_secs = 15 * 60;
radioConfig.preferences.wait_bluetooth_secs = 120;
radioConfig.preferences.screen_on_secs = 30;
radioConfig.preferences.mesh_sds_timeout_secs = 60 * 60;
radioConfig.preferences.phone_sds_timeout_sec = 60 * 60;
radioConfig.preferences.sds_secs = 60 * 60;
radioConfig.preferences.mesh_sds_timeout_secs = 2 * 60 * 60;
radioConfig.preferences.phone_sds_timeout_sec = 2 * 260 * 60;
radioConfig.preferences.sds_secs = 365 * 24 * 60 * 60; // one year
radioConfig.preferences.ls_secs = 60 * 60;
radioConfig.preferences.phone_timeout_secs = 15 * 60;

View File

@@ -30,16 +30,17 @@ static void lsEnter()
gps.prepareSleep(); // abandon in-process parsing
if(!isUSBPowered) // FIXME - temp hack until we can put gps in sleep mode, if we have AC when we go to sleep then leave GPS on
setGPSPower(false); // kill GPS power
if (!isUSBPowered) // FIXME - temp hack until we can put gps in sleep mode, if we have AC when we go to sleep then leave GPS on
setGPSPower(false); // kill GPS power
}
static void lsIdle()
{
uint32_t secsSlept = 0;
esp_sleep_source_t wakeCause = ESP_SLEEP_WAKEUP_UNDEFINED;
bool reached_ls_secs = false;
while (secsSlept < radioConfig.preferences.ls_secs)
while (!reached_ls_secs)
{
// Briefly come out of sleep long enough to blink the led once every few seconds
uint32_t sleepTime = 5;
@@ -55,11 +56,20 @@ static void lsIdle()
break;
secsSlept += sleepTime;
reached_ls_secs = secsSlept >= radioConfig.preferences.ls_secs;
}
setLed(false);
// Regardless of why we woke (for now) just transition to NB (and that state will handle stuff like IRQs etc)
powerFSM.trigger(EVENT_WAKE_TIMER);
if (reached_ls_secs)
{
// stay in LS mode but let loop check whatever it wants
DEBUG_MSG("reached ls_secs, servicing loop()\n");
}
else
{
// Regardless of why we woke just transition to NB (and that state will handle stuff like IRQs etc)
powerFSM.trigger(EVENT_WAKE_TIMER);
}
}
static void lsExit()
@@ -147,5 +157,8 @@ void PowerFSM_setup()
powerFSM.add_timed_transition(&stateDARK, &stateLS, radioConfig.preferences.wait_bluetooth_secs * 1000, NULL, "Bluetooth timeout");
powerFSM.add_timed_transition(&stateLS, &stateSDS, radioConfig.preferences.mesh_sds_timeout_secs * 1000, NULL, "mesh timeout");
powerFSM.add_timed_transition(&stateLS, &stateSDS, radioConfig.preferences.phone_sds_timeout_sec * 1000, NULL, "phone timeout");
powerFSM.run_machine(); // run one interation of the state machine, so we run our on enter tasks for the initial DARK state
}