From fda3aaa2c7b21b7ff5fd36cf3b7710801cc9e802 Mon Sep 17 00:00:00 2001 From: Bertrand Lemasle Date: Tue, 13 Mar 2018 19:52:00 +1300 Subject: [PATCH] Conditionnaly include sdcard backup into code --- GpsTracker/Config.h | 2 ++ GpsTracker/GpsTracker.h | 2 -- GpsTracker/GpsTracker.ino | 2 -- GpsTracker/Positions.cpp | 31 ++++++++++++++++++++++--------- GpsTracker/SdCard.cpp | 6 +++++- GpsTracker/SdPositionsBackup.cpp | 9 ++++++--- GpsTracker/SdPositionsBackup.h | 5 ----- GpsTracker/SdPositionsConfig.cpp | 4 +++- GpsTracker/SdPositionsConfig.h | 3 +++ 9 files changed, 41 insertions(+), 23 deletions(-) diff --git a/GpsTracker/Config.h b/GpsTracker/Config.h index c9f8786..f8c6ead 100644 --- a/GpsTracker/Config.h +++ b/GpsTracker/Config.h @@ -2,6 +2,8 @@ #include +//#define BACKUP_ENABLE_SDCARD 1 + struct sleepTimings_t { uint8_t speed; uint16_t seconds; diff --git a/GpsTracker/GpsTracker.h b/GpsTracker/GpsTracker.h index c1c5eca..6863ac7 100644 --- a/GpsTracker/GpsTracker.h +++ b/GpsTracker/GpsTracker.h @@ -1,12 +1,10 @@ #pragma once #include -#include #include #include "Debug.h" #include "Config.h" #include "Core.h" -#include "SdCard.h" #define LOGGER_NAME "GpsTracker" diff --git a/GpsTracker/GpsTracker.ino b/GpsTracker/GpsTracker.ino index 2aa55b3..782c2ab 100644 --- a/GpsTracker/GpsTracker.ino +++ b/GpsTracker/GpsTracker.ino @@ -12,9 +12,7 @@ void setup() { #endif rtc::setup(); - hardware::sdcard::setup(); hardware::sim808::setup(); - positions::setup(); } diff --git a/GpsTracker/Positions.cpp b/GpsTracker/Positions.cpp index 115ef22..b7f9a80 100644 --- a/GpsTracker/Positions.cpp +++ b/GpsTracker/Positions.cpp @@ -1,8 +1,15 @@ +#include "Config.h" #include "Positions.h" + +#if defined(BACKUP_ENABLE_SDCARD) +#define BACKUPS_ENABLED BACKUP_ENABLE_SDCARD +#endif + +#ifdef BACKUP_ENABLE_SDCARD #include "SdPositionsBackup.h" +#endif #include "Debug.h" -#include "Config.h" #include "Gps.h" #include "Network.h" @@ -12,9 +19,9 @@ #define ENTRIES_ADDR ENTRY_RESERVED_SIZE namespace positions { - +#ifdef BACKUPS_ENABLED backup::PositionsBackup **_backups; - size_t _backupLength; +#endif namespace details { uint16_t maxEntryIndex = (E24_MAX_ADDRESS(hardware::i2c::eeprom.getSize()) - ENTRIES_ADDR) / ENTRY_RESERVED_SIZE; @@ -27,11 +34,15 @@ namespace positions { void setup() { //TODO : enable/disable based on config - _backupLength = 1; - _backups = new backup::PositionsBackup*[_backupLength]; - - _backups[0] = new backup::sd::SdPositionsBackup(); - _backups[0]->setup(); +#ifdef BACKUPS_ENABLED + uint8_t backupIdx = 0; + _backups = new backup::PositionsBackup*[BACKUPS_ENABLED]; + +#ifdef BACKUP_ENABLE_SDCARD + _backups[backupIdx] = new backup::sd::SdPositionsBackup(); + _backups[backupIdx++]->setup(); +#endif +#endif } bool acquire(PositionEntryMetadata &metadata) { @@ -119,8 +130,10 @@ namespace positions { } void doBackup() { - for (int i = 0; i < _backupLength; i++) { +#ifdef BACKUPS_ENABLED + for (int i = 0; i < BACKUPS_ENABLED; i++) { _backups[i]->backup(); } +#endif } } \ No newline at end of file diff --git a/GpsTracker/SdCard.cpp b/GpsTracker/SdCard.cpp index d33185a..406258a 100644 --- a/GpsTracker/SdCard.cpp +++ b/GpsTracker/SdCard.cpp @@ -1,3 +1,6 @@ +#include "Config.h" + +#ifdef BACKUP_ENABLE_SDCARD #include "SdCard.h" namespace hardware { @@ -11,4 +14,5 @@ namespace hardware { } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/GpsTracker/SdPositionsBackup.cpp b/GpsTracker/SdPositionsBackup.cpp index c971a20..baa3f2b 100644 --- a/GpsTracker/SdPositionsBackup.cpp +++ b/GpsTracker/SdPositionsBackup.cpp @@ -3,12 +3,12 @@ #include "SdCard.h" #include "Hardware.h" #include "Config.h" -#include "SdFat.h" #include "Positions.h" #include "Debug.h" #define LOGGER_NAME "Positions::backup::sd" +#ifdef BACKUP_ENABLE_SDCARD namespace positions { namespace backup { namespace sd { @@ -95,7 +95,9 @@ namespace positions { } } - void SdPositionsBackup::setup() { } + void SdPositionsBackup::setup() { + hardware::sdcard::setup(); + } void SdPositionsBackup::backup() { VERBOSE("backup"); @@ -113,4 +115,5 @@ namespace positions { } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/GpsTracker/SdPositionsBackup.h b/GpsTracker/SdPositionsBackup.h index 33cf0d3..f26aad9 100644 --- a/GpsTracker/SdPositionsBackup.h +++ b/GpsTracker/SdPositionsBackup.h @@ -2,11 +2,6 @@ #include "PositionsBackup.h" -#define POSITIONS_FOLDER "positions" -#define POSITIONS_FILENAME "positions-%05d.csv" -#define POSITIONS_FILENAME_LENGTH 19 - - namespace positions { namespace backup { namespace sd { diff --git a/GpsTracker/SdPositionsConfig.cpp b/GpsTracker/SdPositionsConfig.cpp index f4fb33f..529db60 100644 --- a/GpsTracker/SdPositionsConfig.cpp +++ b/GpsTracker/SdPositionsConfig.cpp @@ -4,6 +4,7 @@ #define LOGGER_NAME "Config::backup::sd" +#ifdef BACKUP_ENABLE_SDCARD namespace config { namespace backup { namespace sd { @@ -66,4 +67,5 @@ namespace config { } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/GpsTracker/SdPositionsConfig.h b/GpsTracker/SdPositionsConfig.h index 935448e..f6f06fc 100644 --- a/GpsTracker/SdPositionsConfig.h +++ b/GpsTracker/SdPositionsConfig.h @@ -2,6 +2,9 @@ #include +#define POSITIONS_FOLDER "positions" +#define POSITIONS_FILENAME "positions-%05d.csv" +#define POSITIONS_FILENAME_LENGTH 19 #define POSITIONS_CONFIG_FILENAME "positions.config" #define POSITIONS_CONFIG_SEED 45 #define POSITIONS_CONFIG_DEFAULT_SAVE_THRESHOLD 10