diff --git a/docs/software/gps-todo.txt b/docs/software/gps-todo.txt index 4cda7dac..38781d92 100644 --- a/docs/software/gps-todo.txt +++ b/docs/software/gps-todo.txt @@ -3,19 +3,27 @@ gps todo - bug 376 for taiwan region: bin/run.sh --set region 8 -change defaults to 2 min +time only mode +./bin/run.sh --set gps_operation 3 + +do new power measurements fix has_gps based on new logic +don't send locations if the user has forbidden that (lie to phone so phone won't either) + have loop methods return allowable sleep time (from their perspective) increase main cpu sleep time add set router mode in python tool - it will also set GPS to stationary +make sure location still gets set once per boot and stays marked as valid on the gui +send position updates super rarely (which will shrink DARK and NB period to zero and make light_sleep very long) warn people about crummy gps antennas - add to faq + gps states Active - for gps_attempt_time seconds diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp index 030e9a8a..92a0d9b1 100644 --- a/src/PowerFSM.cpp +++ b/src/PowerFSM.cpp @@ -12,7 +12,7 @@ static void sdsEnter() { // FIXME - make sure GPS and LORA radio are off first - because we want close to zero current draw - doDeepSleep(radioConfig.preferences.sds_secs * 1000LL); + doDeepSleep(getPref_sds_secs() * 1000LL); } #include "error.h" @@ -21,7 +21,7 @@ static uint32_t secsSlept; static void lsEnter() { - DEBUG_MSG("lsEnter begin, ls_secs=%u\n", radioConfig.preferences.ls_secs); + DEBUG_MSG("lsEnter begin, ls_secs=%u\n", getPref_ls_secs()); screen.setOn(false); secsSlept = 0; // How long have we been sleeping this time @@ -30,13 +30,13 @@ static void lsEnter() static void lsIdle() { - // DEBUG_MSG("lsIdle begin ls_secs=%u\n", radioConfig.preferences.ls_secs); + // DEBUG_MSG("lsIdle begin ls_secs=%u\n", getPref_ls_secs()); #ifndef NO_ESP32 esp_sleep_source_t wakeCause = ESP_SLEEP_WAKEUP_UNDEFINED; // Do we have more sleeping to do? - if (secsSlept < radioConfig.preferences.ls_secs) { + if (secsSlept < getPref_ls_secs()) { // Briefly come out of sleep long enough to blink the led once every few seconds uint32_t sleepTime = 30; @@ -158,7 +158,7 @@ Fsm powerFSM(&stateBOOT); void PowerFSM_setup() { // If we already have AC power go to POWER state after init, otherwise go to ON - bool hasPower = powerStatus && powerStatus->getHasUSB(); + bool hasPower = false && powerStatus && powerStatus->getHasUSB(); DEBUG_MSG("PowerFSM init, USB power=%d\n", hasPower); powerFSM.add_timed_transition(&stateBOOT, hasPower ? &statePOWER : &stateON, 3 * 1000, NULL, "boot timeout"); @@ -217,22 +217,20 @@ void PowerFSM_setup() powerFSM.add_transition(&stateNB, &stateDARK, EVENT_PACKET_FOR_PHONE, NULL, "Packet for phone"); - powerFSM.add_timed_transition(&stateON, &stateDARK, radioConfig.preferences.screen_on_secs * 1000, NULL, "Screen-on timeout"); + powerFSM.add_timed_transition(&stateON, &stateDARK, getPref_screen_on_secs() * 1000, NULL, "Screen-on timeout"); - powerFSM.add_timed_transition(&stateDARK, &stateNB, radioConfig.preferences.phone_timeout_secs * 1000, NULL, "Phone timeout"); + powerFSM.add_timed_transition(&stateDARK, &stateNB, getPref_phone_timeout_secs() * 1000, NULL, "Phone timeout"); #ifndef NRF52_SERIES // We never enter light-sleep state on NRF52 (because the CPU uses so little power normally) - powerFSM.add_timed_transition(&stateNB, &stateLS, radioConfig.preferences.min_wake_secs * 1000, NULL, "Min wake timeout"); + powerFSM.add_timed_transition(&stateNB, &stateLS, getPref_min_wake_secs() * 1000, NULL, "Min wake timeout"); - powerFSM.add_timed_transition(&stateDARK, &stateLS, radioConfig.preferences.wait_bluetooth_secs * 1000, NULL, - "Bluetooth timeout"); + powerFSM.add_timed_transition(&stateDARK, &stateLS, getPref_wait_bluetooth_secs() * 1000, NULL, "Bluetooth timeout"); #endif - powerFSM.add_timed_transition(&stateLS, &stateSDS, radioConfig.preferences.mesh_sds_timeout_secs * 1000, NULL, - "mesh timeout"); + powerFSM.add_timed_transition(&stateLS, &stateSDS, getPref_mesh_sds_timeout_secs() * 1000, NULL, "mesh timeout"); // removing for now, because some users don't even have phones - // powerFSM.add_timed_transition(&stateLS, &stateSDS, radioConfig.preferences.phone_sds_timeout_sec * 1000, NULL, "phone + // powerFSM.add_timed_transition(&stateLS, &stateSDS, getPref_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 diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 8baed24c..b514b0c5 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -52,7 +52,7 @@ static uint32_t sendOwnerCb() { service.sendOurOwner(); - return radioConfig.preferences.send_owner_interval * radioConfig.preferences.position_broadcast_secs * 1000; + return getPref_send_owner_interval() * getPref_position_broadcast_secs() * 1000; } static concurrency::Periodic sendOwnerPeriod(sendOwnerCb); @@ -318,7 +318,7 @@ int MeshService::onGPSChanged(const meshtastic::GPSStatus *unused) // We limit our GPS broadcasts to a max rate static uint32_t lastGpsSend; uint32_t now = millis(); - if (lastGpsSend == 0 || now - lastGpsSend > radioConfig.preferences.position_broadcast_secs * 1000) { + if (lastGpsSend == 0 || now - lastGpsSend > getPref_position_broadcast_secs() * 1000) { lastGpsSend = now; DEBUG_MSG("Sending position to mesh\n"); diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 1f34eb5d..349e7e67 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -116,18 +116,9 @@ bool NodeDB::resetRadioConfig() DEBUG_MSG("Performing factory reset!\n"); installDefaultDeviceState(); didFactoryReset = true; - } else if (radioConfig.preferences.sds_secs == 0) { - DEBUG_MSG("Fixing bogus RadioConfig!\n"); + } else if (!channelSettings.psk.size) { + DEBUG_MSG("Setting default preferences!\n"); - radioConfig.preferences.send_owner_interval = 4; // per sw-design.md - radioConfig.preferences.position_broadcast_secs = 15 * 60; - radioConfig.preferences.wait_bluetooth_secs = 120; - radioConfig.preferences.screen_on_secs = 5 * 60; - radioConfig.preferences.mesh_sds_timeout_secs = 2 * 60 * 60; - radioConfig.preferences.phone_sds_timeout_sec = 2 * 60 * 60; - radioConfig.preferences.sds_secs = 365 * 24 * 60 * 60; // one year - radioConfig.preferences.ls_secs = 60 * 60; - radioConfig.preferences.phone_timeout_secs = 15 * 60; radioConfig.has_channel_settings = true; radioConfig.has_preferences = true; diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index e1a1b77d..20dc47cf 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -47,9 +47,9 @@ class NodeDB void saveToDisk(); /** Reinit radio config if needed, because either: - * a) sometimes a buggy android app might send us bogus settings or + * a) sometimes a buggy android app might send us bogus settings or * b) the client set factory_reset - * + * * @return true if the config was completely reset, in that case, we should send it back to the client */ bool resetRadioConfig(); @@ -137,4 +137,18 @@ their nodes * * https://github.com/meshtastic/Meshtastic-device/issues/269 */ -const char *getChannelName(); \ No newline at end of file +const char *getChannelName(); + +#define PREF_GET(name, defaultVal) \ + inline uint32_t getPref_##name() { return radioConfig.preferences.name ? radioConfig.preferences.name : (defaultVal); } + +PREF_GET(send_owner_interval, 4) +PREF_GET(position_broadcast_secs, 15 * 60) +PREF_GET(wait_bluetooth_secs, 120) +PREF_GET(screen_on_secs, 60) +PREF_GET(mesh_sds_timeout_secs, 2 * 60 * 60) +PREF_GET(phone_sds_timeout_sec, 2 * 60 * 60) +PREF_GET(sds_secs, 365 * 24 * 60 * 60) +PREF_GET(ls_secs, 60 * 60) +PREF_GET(phone_timeout_secs, 15 * 60) +PREF_GET(min_wake_secs, 10) diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index 9ae5955d..3cbcef17 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -20,7 +20,7 @@ void PhoneAPI::init() void PhoneAPI::checkConnectionTimeout() { if (isConnected) { - bool newConnected = (millis() - lastContactMsec < radioConfig.preferences.phone_timeout_secs * 1000L); + bool newConnected = (millis() - lastContactMsec < getPref_phone_timeout_secs() * 1000L); if (!newConnected) { isConnected = false; onConnectionChanged(isConnected);