From 809531acce24a12ed3b8463a0dd6e976c9c50b9f Mon Sep 17 00:00:00 2001 From: Bertrand Lemasle Date: Mon, 6 Aug 2018 12:23:47 +1200 Subject: [PATCH] Fix network not being powered off if not available --- Core.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Core.cpp b/Core.cpp index 5c72ba7..c53faf3 100644 --- a/Core.cpp +++ b/Core.cpp @@ -65,7 +65,10 @@ namespace core { network::powerOn(); networkStatus = network::waitForRegistered(NETWORK_DEFAULT_TOTAL_TIMEOUT_MS); - if (!network::isAvailable(networkStatus.stat)) return NO_ALERTS_NOTIFIED; + if (!network::isAvailable(networkStatus.stat)) { + network::powerOff(); + return NO_ALERTS_NOTIFIED; + } strncpy_P(buffer, PSTR("Alerts !"), SMS_BUFFER_SIZE); if (bitRead(triggered, ALERT_BATTERY_LEVEL_1) || bitRead(triggered, ALERT_BATTERY_LEVEL_2)) { @@ -102,7 +105,7 @@ namespace core { float distance = gps::getDistanceFromPrevious(); //did we missed positions because we were sleeping ? if (distance > GPS_DEFAULT_MISSED_POSITION_GAP_KM) stoppedInARow = 0; else stoppedInARow = min(stoppedInARow + 1, SLEEP_DEFAULT_STOPPED_THRESHOLD + 1); //avoid overflow on REALLY long stops - + if (stoppedInARow < SLEEP_DEFAULT_STOPPED_THRESHOLD) { result = SLEEP_DEFAULT_PAUSING_TIME_SECONDS; } @@ -119,14 +122,14 @@ namespace core { uint16_t mapSleepTime(uint8_t velocity) { uint16_t result; uint16_t currentTime = 0xFFFF; - + if (rtc::isAccurate()) { tmElements_t time; rtc::getTime(time); currentTime = SLEEP_TIMING_TIME(time.Hour, time.Minute); } - + for (uint8_t i = flash::getArraySize(config::defaultSleepTimings); i--;) { sleepTimings_t timing; flash::read(&config::defaultSleepTimings[i], timing);