From 9143e494ebabd579b6bdcd544ea1b75af06dac51 Mon Sep 17 00:00:00 2001 From: Bertrand Lemasle Date: Tue, 13 Mar 2018 20:20:28 +1300 Subject: [PATCH] Conditionnal includes of backup code work for more than one implementation --- GpsTracker/Config.h | 24 +++++++++++++----------- GpsTracker/NetworkPositionsBackup.h | 3 +++ GpsTracker/Positions.cpp | 19 ++++++++++--------- GpsTracker/SdCard.cpp | 2 +- GpsTracker/SdPositionsBackup.cpp | 2 +- GpsTracker/SdPositionsConfig.cpp | 2 +- 6 files changed, 29 insertions(+), 23 deletions(-) create mode 100644 GpsTracker/NetworkPositionsBackup.h diff --git a/GpsTracker/Config.h b/GpsTracker/Config.h index f8c6ead..7805c2c 100644 --- a/GpsTracker/Config.h +++ b/GpsTracker/Config.h @@ -2,7 +2,18 @@ #include -//#define BACKUP_ENABLE_SDCARD 1 +#define BACKUP_ENABLE_SDCARD 0 +#define BACKUP_ENABLE_NETWORK 0 + +#define CONFIG_ADDR 0 +#define CONFIG_RESERVED_SIZE 128 +#define CONFIG_SEED "UIYA" +#define VERSION "1.00" + +#define SLEEP_DEFAULT_TIME_SECONDS 1800 + +#define GPS_DEFAULT_INTERMEDIATE_TIMEOUT_MS 10000 +#define GPS_DEFAULT_TOTAL_TIMEOUT_MS 180000 struct sleepTimings_t { uint8_t speed; @@ -17,19 +28,10 @@ struct Config_t { uint16_t lastEntry; }; -#define CONFIG_ADDR 0 -#define CONFIG_SEED "UIYA" -#define VERSION "1.00" - -#define SLEEP_DEFAULT_TIME_SECONDS 1800 - -#define GPS_DEFAULT_INTERMEDIATE_TIMEOUT_MS 10000 -#define GPS_DEFAULT_TOTAL_TIMEOUT_MS 180000 - namespace config { static const sleepTimings_t defaultSleepTimings[] PROGMEM = { - { 5, SLEEP_DEFAULT_TIME_SECONDS }, + { 5, SLEEP_DEFAULT_TIME_SECONDS }, { 10, 1200 }, { 20, 600 }, { 30, 540 }, diff --git a/GpsTracker/NetworkPositionsBackup.h b/GpsTracker/NetworkPositionsBackup.h new file mode 100644 index 0000000..8c75944 --- /dev/null +++ b/GpsTracker/NetworkPositionsBackup.h @@ -0,0 +1,3 @@ +#pragma once + +#include "PositionsBackup.h" \ No newline at end of file diff --git a/GpsTracker/Positions.cpp b/GpsTracker/Positions.cpp index b7f9a80..493b543 100644 --- a/GpsTracker/Positions.cpp +++ b/GpsTracker/Positions.cpp @@ -1,22 +1,24 @@ #include "Config.h" +#include "Debug.h" #include "Positions.h" +#include "Gps.h" -#if defined(BACKUP_ENABLE_SDCARD) -#define BACKUPS_ENABLED BACKUP_ENABLE_SDCARD +#if BACKUP_ENABLE_SDCARD || BACKUP_ENABLE_NETWORK +#define BACKUPS_ENABLED BACKUP_ENABLE_SDCARD + BACKUP_ENABLE_NETWORK #endif -#ifdef BACKUP_ENABLE_SDCARD +#if BACKUP_ENABLE_SDCARD #include "SdPositionsBackup.h" #endif -#include "Debug.h" -#include "Gps.h" -#include "Network.h" +#if BACKUP_ENABLE_NETWORK +#include "NetworkPositionsBackup.h" +#endif #define LOGGER_NAME "Positions" #define ENTRY_RESERVED_SIZE 128 -#define ENTRIES_ADDR ENTRY_RESERVED_SIZE +#define ENTRIES_ADDR CONFIG_RESERVED_SIZE namespace positions { #ifdef BACKUPS_ENABLED @@ -33,12 +35,11 @@ namespace positions { } void setup() { - //TODO : enable/disable based on config #ifdef BACKUPS_ENABLED uint8_t backupIdx = 0; _backups = new backup::PositionsBackup*[BACKUPS_ENABLED]; -#ifdef BACKUP_ENABLE_SDCARD +#if BACKUP_ENABLE_SDCARD _backups[backupIdx] = new backup::sd::SdPositionsBackup(); _backups[backupIdx++]->setup(); #endif diff --git a/GpsTracker/SdCard.cpp b/GpsTracker/SdCard.cpp index 406258a..9a37dd3 100644 --- a/GpsTracker/SdCard.cpp +++ b/GpsTracker/SdCard.cpp @@ -1,6 +1,6 @@ #include "Config.h" -#ifdef BACKUP_ENABLE_SDCARD +#if BACKUP_ENABLE_SDCARD #include "SdCard.h" namespace hardware { diff --git a/GpsTracker/SdPositionsBackup.cpp b/GpsTracker/SdPositionsBackup.cpp index baa3f2b..426e583 100644 --- a/GpsTracker/SdPositionsBackup.cpp +++ b/GpsTracker/SdPositionsBackup.cpp @@ -8,7 +8,7 @@ #define LOGGER_NAME "Positions::backup::sd" -#ifdef BACKUP_ENABLE_SDCARD +#if BACKUP_ENABLE_SDCARD namespace positions { namespace backup { namespace sd { diff --git a/GpsTracker/SdPositionsConfig.cpp b/GpsTracker/SdPositionsConfig.cpp index 529db60..d963f36 100644 --- a/GpsTracker/SdPositionsConfig.cpp +++ b/GpsTracker/SdPositionsConfig.cpp @@ -4,7 +4,7 @@ #define LOGGER_NAME "Config::backup::sd" -#ifdef BACKUP_ENABLE_SDCARD +#if BACKUP_ENABLE_SDCARD namespace config { namespace backup { namespace sd {