From c7063a5698b96b91e445a1947f07f550b052a4ac Mon Sep 17 00:00:00 2001 From: Bertrand Lemasle Date: Thu, 2 Aug 2018 23:13:45 +1200 Subject: [PATCH] Moved RTC time update from GPS to Core workflow rather than position acquisition. Avoid edge cases where the spend time measurement could be wrong because of time update in between the two measure points. --- GpsTracker/Core.cpp | 17 +++++++++++++++-- GpsTracker/Core.h | 1 + GpsTracker/Positions.cpp | 4 ---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/GpsTracker/Core.cpp b/GpsTracker/Core.cpp index 386e33d..b144619 100644 --- a/GpsTracker/Core.cpp +++ b/GpsTracker/Core.cpp @@ -7,14 +7,19 @@ using namespace utils; namespace core { + uint16_t sleepTime = SLEEP_DEFAULT_TIME_SECONDS; uint8_t stoppedInARow = SLEEP_DEFAULT_STOPPED_THRESHOLD - 1; void main() { bool forceBackup = false; - positions::prepareBackup(); + bool acquired = false; PositionEntryMetadata metadata; - if (positions::acquire(metadata)) { + + positions::prepareBackup(); + acquired = positions::acquire(metadata); + + if (acquired) { positions::appendLast(metadata); forceBackup = updateSleepTime(); @@ -22,9 +27,17 @@ namespace core { } positions::doBackup(forceBackup); + + if (acquired) updateRtcTime(); mainunit::deepSleep(sleepTime); } + void updateRtcTime() { + tmElements_t time; + gps::getTime(time); + rtc::setTime(time); + } + bool updateSleepTime() { uint8_t velocity = gps::getVelocity(); uint16_t result = mapSleepTime(velocity); diff --git a/GpsTracker/Core.h b/GpsTracker/Core.h index 8e4e5b2..c21c2ab 100644 --- a/GpsTracker/Core.h +++ b/GpsTracker/Core.h @@ -14,6 +14,7 @@ namespace core { extern uint16_t sleepTime; void main(); + void updateRtcTime(); bool updateSleepTime(); uint16_t mapSleepTime(uint8_t velocity); } \ No newline at end of file diff --git a/GpsTracker/Positions.cpp b/GpsTracker/Positions.cpp index 14e0253..81d2d52 100644 --- a/GpsTracker/Positions.cpp +++ b/GpsTracker/Positions.cpp @@ -70,10 +70,6 @@ namespace positions { uint16_t timeToFix = rtc::getTime() - before; - tmElements_t time; - gps::getTime(time); - rtc::setTime(time); - metadata = { battery.level, battery.voltage,