Browse Source

Conditionnaly include sdcard backup into code

tags/v1.2.0
Bertrand Lemasle 7 years ago
parent
commit
fda3aaa2c7
9 changed files with 41 additions and 23 deletions
  1. +2
    -0
      GpsTracker/Config.h
  2. +0
    -2
      GpsTracker/GpsTracker.h
  3. +0
    -2
      GpsTracker/GpsTracker.ino
  4. +22
    -9
      GpsTracker/Positions.cpp
  5. +5
    -1
      GpsTracker/SdCard.cpp
  6. +6
    -3
      GpsTracker/SdPositionsBackup.cpp
  7. +0
    -5
      GpsTracker/SdPositionsBackup.h
  8. +3
    -1
      GpsTracker/SdPositionsConfig.cpp
  9. +3
    -0
      GpsTracker/SdPositionsConfig.h

+ 2
- 0
GpsTracker/Config.h View File

@@ -2,6 +2,8 @@


#include <Arduino.h> #include <Arduino.h>


//#define BACKUP_ENABLE_SDCARD 1

struct sleepTimings_t { struct sleepTimings_t {
uint8_t speed; uint8_t speed;
uint16_t seconds; uint16_t seconds;


+ 0
- 2
GpsTracker/GpsTracker.h View File

@@ -1,12 +1,10 @@
#pragma once #pragma once


#include <Arduino.h> #include <Arduino.h>
#include <SoftwareSerial.h>
#include <SIM808.h> #include <SIM808.h>


#include "Debug.h" #include "Debug.h"
#include "Config.h" #include "Config.h"
#include "Core.h" #include "Core.h"
#include "SdCard.h"


#define LOGGER_NAME "GpsTracker" #define LOGGER_NAME "GpsTracker"

+ 0
- 2
GpsTracker/GpsTracker.ino View File

@@ -12,9 +12,7 @@ void setup() {
#endif #endif


rtc::setup(); rtc::setup();
hardware::sdcard::setup();
hardware::sim808::setup(); hardware::sim808::setup();

positions::setup(); positions::setup();
} }




+ 22
- 9
GpsTracker/Positions.cpp View File

@@ -1,8 +1,15 @@
#include "Config.h"
#include "Positions.h" #include "Positions.h"

#if defined(BACKUP_ENABLE_SDCARD)
#define BACKUPS_ENABLED BACKUP_ENABLE_SDCARD
#endif

#ifdef BACKUP_ENABLE_SDCARD
#include "SdPositionsBackup.h" #include "SdPositionsBackup.h"
#endif


#include "Debug.h" #include "Debug.h"
#include "Config.h"
#include "Gps.h" #include "Gps.h"
#include "Network.h" #include "Network.h"


@@ -12,9 +19,9 @@
#define ENTRIES_ADDR ENTRY_RESERVED_SIZE #define ENTRIES_ADDR ENTRY_RESERVED_SIZE


namespace positions { namespace positions {
#ifdef BACKUPS_ENABLED
backup::PositionsBackup **_backups; backup::PositionsBackup **_backups;
size_t _backupLength;
#endif


namespace details { namespace details {
uint16_t maxEntryIndex = (E24_MAX_ADDRESS(hardware::i2c::eeprom.getSize()) - ENTRIES_ADDR) / ENTRY_RESERVED_SIZE; uint16_t maxEntryIndex = (E24_MAX_ADDRESS(hardware::i2c::eeprom.getSize()) - ENTRIES_ADDR) / ENTRY_RESERVED_SIZE;
@@ -27,11 +34,15 @@ namespace positions {


void setup() { void setup() {
//TODO : enable/disable based on config //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) { bool acquire(PositionEntryMetadata &metadata) {
@@ -119,8 +130,10 @@ namespace positions {
} }


void doBackup() { void doBackup() {
for (int i = 0; i < _backupLength; i++) {
#ifdef BACKUPS_ENABLED
for (int i = 0; i < BACKUPS_ENABLED; i++) {
_backups[i]->backup(); _backups[i]->backup();
} }
#endif
} }
} }

+ 5
- 1
GpsTracker/SdCard.cpp View File

@@ -1,3 +1,6 @@
#include "Config.h"

#ifdef BACKUP_ENABLE_SDCARD
#include "SdCard.h" #include "SdCard.h"


namespace hardware { namespace hardware {
@@ -11,4 +14,5 @@ namespace hardware {
} }


} }
}
}
#endif

+ 6
- 3
GpsTracker/SdPositionsBackup.cpp View File

@@ -3,12 +3,12 @@
#include "SdCard.h" #include "SdCard.h"
#include "Hardware.h" #include "Hardware.h"
#include "Config.h" #include "Config.h"
#include "SdFat.h"
#include "Positions.h" #include "Positions.h"
#include "Debug.h" #include "Debug.h"


#define LOGGER_NAME "Positions::backup::sd" #define LOGGER_NAME "Positions::backup::sd"


#ifdef BACKUP_ENABLE_SDCARD
namespace positions { namespace positions {
namespace backup { namespace backup {
namespace sd { namespace sd {
@@ -95,7 +95,9 @@ namespace positions {
} }
} }


void SdPositionsBackup::setup() { }
void SdPositionsBackup::setup() {
hardware::sdcard::setup();
}


void SdPositionsBackup::backup() { void SdPositionsBackup::backup() {
VERBOSE("backup"); VERBOSE("backup");
@@ -113,4 +115,5 @@ namespace positions {


} }
} }
}
}
#endif

+ 0
- 5
GpsTracker/SdPositionsBackup.h View File

@@ -2,11 +2,6 @@


#include "PositionsBackup.h" #include "PositionsBackup.h"


#define POSITIONS_FOLDER "positions"
#define POSITIONS_FILENAME "positions-%05d.csv"
#define POSITIONS_FILENAME_LENGTH 19


namespace positions { namespace positions {
namespace backup { namespace backup {
namespace sd { namespace sd {


+ 3
- 1
GpsTracker/SdPositionsConfig.cpp View File

@@ -4,6 +4,7 @@


#define LOGGER_NAME "Config::backup::sd" #define LOGGER_NAME "Config::backup::sd"


#ifdef BACKUP_ENABLE_SDCARD
namespace config { namespace config {
namespace backup { namespace backup {
namespace sd { namespace sd {
@@ -66,4 +67,5 @@ namespace config {


} }
} }
}
}
#endif

+ 3
- 0
GpsTracker/SdPositionsConfig.h View File

@@ -2,6 +2,9 @@


#include <Arduino.h> #include <Arduino.h>


#define POSITIONS_FOLDER "positions"
#define POSITIONS_FILENAME "positions-%05d.csv"
#define POSITIONS_FILENAME_LENGTH 19
#define POSITIONS_CONFIG_FILENAME "positions.config" #define POSITIONS_CONFIG_FILENAME "positions.config"
#define POSITIONS_CONFIG_SEED 45 #define POSITIONS_CONFIG_SEED 45
#define POSITIONS_CONFIG_DEFAULT_SAVE_THRESHOLD 10 #define POSITIONS_CONFIG_DEFAULT_SAVE_THRESHOLD 10


Loading…
Cancel
Save