Parcourir la source

Avoid backup while the tracker is moving

tags/v1.2.0
Bertrand Lemasle il y a 6 ans
Parent
révision
7cc36c6258
2 fichiers modifiés avec 21 ajouts et 9 suppressions
  1. +13
    -8
      src/Core.cpp
  2. +8
    -1
      src/Core.h

+ 13
- 8
src/Core.cpp Voir le fichier

@@ -13,6 +13,7 @@ namespace core {


uint16_t sleepTime = SLEEP_DEFAULT_TIME_SECONDS; uint16_t sleepTime = SLEEP_DEFAULT_TIME_SECONDS;
uint8_t stoppedInARow = SLEEP_DEFAULT_STOPPED_THRESHOLD - 1; uint8_t stoppedInARow = SLEEP_DEFAULT_STOPPED_THRESHOLD - 1;
TRACKER_MOVING_STATE movingState = TRACKER_MOVING_STATE::MOVING;


namespace details { namespace details {


@@ -30,23 +31,25 @@ namespace core {
} }


void main() { void main() {
bool forceBackup = false;
bool acquired = false; bool acquired = false;
PositionEntryMetadata metadata; PositionEntryMetadata metadata;


positions::prepareBackup();
if(movingState >= TRACKER_MOVING_STATE::STOPPED) positions::prepareBackup();
acquired = positions::acquire(metadata); acquired = positions::acquire(metadata);


if (acquired) { if (acquired) {
positions::appendLast(metadata); positions::appendLast(metadata);


forceBackup = updateSleepTime();
movingState = updateSleepTime();
gps::preserveCurrentCoordinates(); gps::preserveCurrentCoordinates();
} }


alerts::clear(metadata); alerts::clear(metadata);
alerts::add(notifyFailures(metadata)); alerts::add(notifyFailures(metadata));
positions::doBackup(forceBackup);

if(movingState >= TRACKER_MOVING_STATE::STOPPED) {
positions::doBackup(movingState == TRACKER_MOVING_STATE::STOPPED); //do not force on STATIC
}


if (acquired) updateRtcTime(); if (acquired) updateRtcTime();
mainunit::deepSleep(sleepTime); mainunit::deepSleep(sleepTime);
@@ -104,8 +107,8 @@ namespace core {
rtc::setTime(time); rtc::setTime(time);
} }


bool updateSleepTime() {
bool goingLongSleep = false;
TRACKER_MOVING_STATE updateSleepTime() {
TRACKER_MOVING_STATE state = TRACKER_MOVING_STATE::MOVING;
uint8_t velocity = gps::getVelocity(); uint8_t velocity = gps::getVelocity();


sleepTime = mapSleepTime(velocity); sleepTime = mapSleepTime(velocity);
@@ -117,13 +120,15 @@ namespace core {


if (stoppedInARow < SLEEP_DEFAULT_STOPPED_THRESHOLD) { if (stoppedInARow < SLEEP_DEFAULT_STOPPED_THRESHOLD) {
sleepTime = SLEEP_DEFAULT_PAUSING_TIME_SECONDS; sleepTime = SLEEP_DEFAULT_PAUSING_TIME_SECONDS;
state = TRACKER_MOVING_STATE::PAUSED;
} }
else if (stoppedInARow == SLEEP_DEFAULT_STOPPED_THRESHOLD) goingLongSleep = true;
else if (stoppedInARow == SLEEP_DEFAULT_STOPPED_THRESHOLD) state = TRACKER_MOVING_STATE::STOPPED;
else state = TRACKER_MOVING_STATE::STATIC;
} }
else stoppedInARow = 0; else stoppedInARow = 0;


NOTICE_FORMAT("updateSleepTime", "%dkmh => %d seconds", velocity, sleepTime); NOTICE_FORMAT("updateSleepTime", "%dkmh => %d seconds", velocity, sleepTime);
return goingLongSleep;
return state;
} }


uint16_t mapSleepTime(uint8_t velocity) { uint16_t mapSleepTime(uint8_t velocity) {


+ 8
- 1
src/Core.h Voir le fichier

@@ -10,12 +10,19 @@
#include "Pins.h" #include "Pins.h"
#include "Positions.h" #include "Positions.h"


enum class TRACKER_MOVING_STATE : uint8_t {
MOVING = 0,
PAUSED = 1,
STOPPED = 2,
STATIC = 3
};

namespace core { namespace core {
extern uint16_t sleepTime; extern uint16_t sleepTime;


void main(); void main();
void updateRtcTime(); void updateRtcTime();
bool updateSleepTime();
TRACKER_MOVING_STATE updateSleepTime();
uint16_t mapSleepTime(uint8_t velocity); uint16_t mapSleepTime(uint8_t velocity);


uint8_t notifyFailures(PositionEntryMetadata &metadata); uint8_t notifyFailures(PositionEntryMetadata &metadata);

Chargement…
Annuler
Enregistrer