Browse Source

Ability to force backup. Forcing backup when "stopping"

tags/v1.2.0
Bertrand Lemasle 7 years ago
parent
commit
6b41da4c9a
11 changed files with 25 additions and 21 deletions
  1. +11
    -7
      GpsTracker/Core.cpp
  2. +2
    -2
      GpsTracker/Core.h
  3. +2
    -2
      GpsTracker/Debug.cpp
  4. +1
    -1
      GpsTracker/GpsTracker.ino
  5. +2
    -2
      GpsTracker/NetworkPositionsBackup.cpp
  6. +1
    -1
      GpsTracker/NetworkPositionsBackup.h
  7. +2
    -2
      GpsTracker/Positions.cpp
  8. +1
    -1
      GpsTracker/Positions.h
  9. +1
    -1
      GpsTracker/PositionsBackup.h
  10. +1
    -1
      GpsTracker/SdPositionsBackup.cpp
  11. +1
    -1
      GpsTracker/SdPositionsBackup.h

+ 11
- 7
GpsTracker/Core.cpp View File

@@ -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;


+ 2
- 2
GpsTracker/Core.h View File

@@ -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);
} }

+ 2
- 2
GpsTracker/Debug.cpp View File

@@ -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");


+ 1
- 1
GpsTracker/GpsTracker.ino View File

@@ -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);


+ 2
- 2
GpsTracker/NetworkPositionsBackup.cpp View File

@@ -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();
} }
} }


+ 1
- 1
GpsTracker/NetworkPositionsBackup.h View File

@@ -20,7 +20,7 @@ namespace positions {
void setup(); void setup();


void prepare(); void prepare();
void backup();
void backup(bool force);
}; };


} }


+ 2
- 2
GpsTracker/Positions.cpp View File

@@ -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
} }

+ 1
- 1
GpsTracker/Positions.h View File

@@ -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);
} }

+ 1
- 1
GpsTracker/PositionsBackup.h View File

@@ -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;
}; };


} }

+ 1
- 1
GpsTracker/SdPositionsBackup.cpp View File

@@ -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) {


+ 1
- 1
GpsTracker/SdPositionsBackup.h View File

@@ -10,7 +10,7 @@ namespace positions {
private: private:
public: public:
void setup(); void setup();
void backup();
void backup(bool force);
}; };


} }


Loading…
Cancel
Save