@@ -7,38 +7,42 @@ | |||||
using namespace utils; | using namespace utils; | ||||
namespace core { | namespace core { | ||||
uint16_t sleepTime = SLEEP_DEFAULT_TIME_SECONDS;; | |||||
uint16_t sleepTime = SLEEP_DEFAULT_TIME_SECONDS; | |||||
uint8_t stoppedInARow = 0; | uint8_t stoppedInARow = 0; | ||||
void main() { | void main() { | ||||
bool forceBackup = false; | |||||
positions::prepareBackup(); | positions::prepareBackup(); | ||||
PositionEntryMetadata metadata; | PositionEntryMetadata metadata; | ||||
if (positions::acquire(metadata)) { | if (positions::acquire(metadata)) { | ||||
positions::appendLast(metadata); | positions::appendLast(metadata); | ||||
updateSleepTime(gps::getVelocity()); | |||||
forceBackup = updateSleepTime(gps::getVelocity()); | |||||
} | } | ||||
positions::doBackup(); | |||||
positions::doBackup(forceBackup); | |||||
mainunit::deepSleep(sleepTime); | mainunit::deepSleep(sleepTime); | ||||
} | } | ||||
void updateSleepTime(uint8_t velocity) { | |||||
uint16_t result = computeSleepTime(velocity); | |||||
bool updateSleepTime(uint8_t velocity) { | |||||
uint16_t result = mapSleepTime(velocity); | |||||
bool goingLongSleep = false; | |||||
if (velocity < SLEEP_TIMING_MIN_MOVING_VELOCITY) { | if (velocity < SLEEP_TIMING_MIN_MOVING_VELOCITY) { | ||||
stoppedInARow++; | stoppedInARow++; | ||||
if (stoppedInARow < SLEEP_DEFAULT_STOPPED_THRESHOLD) { | if (stoppedInARow < SLEEP_DEFAULT_STOPPED_THRESHOLD) { | ||||
result = SLEEP_DEFAULT_PAUSING_TIME_SECONDS; | result = SLEEP_DEFAULT_PAUSING_TIME_SECONDS; | ||||
} | } | ||||
else goingLongSleep = true; | |||||
} | } | ||||
else stoppedInARow = 0; | else stoppedInARow = 0; | ||||
sleepTime = result; | sleepTime = result; | ||||
NOTICE_FORMAT("updateSleepTime", "%dkmh => %d seconds", velocity, sleepTime); | NOTICE_FORMAT("updateSleepTime", "%dkmh => %d seconds", velocity, sleepTime); | ||||
return goingLongSleep; | |||||
} | } | ||||
uint16_t computeSleepTime(uint8_t velocity) { | |||||
uint16_t mapSleepTime(uint8_t velocity) { | |||||
uint16_t result; | uint16_t result; | ||||
uint16_t currentTime = 0xFFFF; | uint16_t currentTime = 0xFFFF; | ||||
@@ -14,6 +14,6 @@ namespace core { | |||||
extern uint16_t sleepTime; | extern uint16_t sleepTime; | ||||
void main(); | void main(); | ||||
void updateSleepTime(uint8_t velocity); | |||||
uint16_t computeSleepTime(uint8_t velocity); | |||||
bool updateSleepTime(uint8_t velocity); | |||||
uint16_t mapSleepTime(uint8_t velocity); | |||||
} | } |
@@ -168,7 +168,7 @@ namespace debug { | |||||
NOTICE_FORMAT("setFakeGpsPosition", "Last position set to : %s", gps::lastPosition); | NOTICE_FORMAT("setFakeGpsPosition", "Last position set to : %s", gps::lastPosition); | ||||
NOTICE_FORMAT("setFakeGpsPosition", "Speed : %d", gps::getVelocity()); | NOTICE_FORMAT("setFakeGpsPosition", "Speed : %d", gps::getVelocity()); | ||||
NOTICE_FORMAT("setFakeGpsPosition", "Sleep time : %d", core::computeSleepTime(gps::getVelocity())); | |||||
NOTICE_FORMAT("setFakeGpsPosition", "Sleep time : %d", core::mapSleepTime(gps::getVelocity())); | |||||
} | } | ||||
void getAndDisplayBattery() { | void getAndDisplayBattery() { | ||||
@@ -198,7 +198,7 @@ namespace debug { | |||||
utils::flash::read(&config::defaultSleepTimings[arraySize - 1], maxSpeedTiming); | utils::flash::read(&config::defaultSleepTimings[arraySize - 1], maxSpeedTiming); | ||||
for (int i = 0; i <= maxSpeedTiming.speed; i++) { | for (int i = 0; i <= maxSpeedTiming.speed; i++) { | ||||
core::computeSleepTime(i); | |||||
core::mapSleepTime(i); | |||||
} | } | ||||
NOTICE_MSG("getAndDisplaySleepTimes", "Done"); | NOTICE_MSG("getAndDisplaySleepTimes", "Done"); | ||||
@@ -78,7 +78,7 @@ void loop() { | |||||
debug::addLastPositionToEeprom(); | debug::addLastPositionToEeprom(); | ||||
break; | break; | ||||
case debug::GPSTRACKER_DEBUG_COMMAND::EEPROM_BACKUP_ENTRIES: | case debug::GPSTRACKER_DEBUG_COMMAND::EEPROM_BACKUP_ENTRIES: | ||||
positions::doBackup(); | |||||
positions::doBackup(false); | |||||
break; | break; | ||||
case debug::GPSTRACKER_DEBUG_COMMAND::SLEEP: | case debug::GPSTRACKER_DEBUG_COMMAND::SLEEP: | ||||
mainunit::sleep(period_t::SLEEP_8S); | mainunit::sleep(period_t::SLEEP_8S); | ||||
@@ -106,10 +106,10 @@ namespace positions { | |||||
_prepareTime = rtc::getTime(); | _prepareTime = rtc::getTime(); | ||||
} | } | ||||
void NetworkPositionsBackup::backup() { | |||||
void NetworkPositionsBackup::backup(bool force) { | |||||
NOTICE("backup"); | NOTICE("backup"); | ||||
if (!isBackupNeeded(false)) return; | |||||
if (!force || !isBackupNeeded(false)) return; | |||||
appendPositions(); | appendPositions(); | ||||
} | } | ||||
} | } | ||||
@@ -20,7 +20,7 @@ namespace positions { | |||||
void setup(); | void setup(); | ||||
void prepare(); | void prepare(); | ||||
void backup(); | |||||
void backup(bool force); | |||||
}; | }; | ||||
} | } | ||||
@@ -154,10 +154,10 @@ namespace positions { | |||||
#endif | #endif | ||||
} | } | ||||
void doBackup() { | |||||
void doBackup(bool force) { | |||||
#ifdef BACKUPS_ENABLED | #ifdef BACKUPS_ENABLED | ||||
for (int i = 0; i < BACKUPS_ENABLED; i++) { | for (int i = 0; i < BACKUPS_ENABLED; i++) { | ||||
_backups[i]->backup(); | |||||
_backups[i]->backup(force); | |||||
} | } | ||||
#endif | #endif | ||||
} | } |
@@ -28,5 +28,5 @@ namespace positions { | |||||
uint16_t count(uint16_t fromIndex); | uint16_t count(uint16_t fromIndex); | ||||
void prepareBackup(); | void prepareBackup(); | ||||
void doBackup(); | |||||
void doBackup(bool force); | |||||
} | } |
@@ -9,7 +9,7 @@ namespace positions { | |||||
virtual void setup() = 0; | virtual void setup() = 0; | ||||
virtual void prepare() = 0; | virtual void prepare() = 0; | ||||
virtual void backup() = 0; | |||||
virtual void backup(bool force) = 0; | |||||
}; | }; | ||||
} | } |
@@ -99,7 +99,7 @@ namespace positions { | |||||
hardware::sdcard::setup(); | hardware::sdcard::setup(); | ||||
} | } | ||||
void SdPositionsBackup::backup() { | |||||
void SdPositionsBackup::backup(bool force) { | |||||
VERBOSE("backup"); | VERBOSE("backup"); | ||||
if (!hardware::sdcard::available) { | if (!hardware::sdcard::available) { | ||||
@@ -10,7 +10,7 @@ namespace positions { | |||||
private: | private: | ||||
public: | public: | ||||
void setup(); | void setup(); | ||||
void backup(); | |||||
void backup(bool force); | |||||
}; | }; | ||||
} | } | ||||