diff --git a/src/Core.cpp b/src/Core.cpp index 987e57e..0a56745 100644 --- a/src/Core.cpp +++ b/src/Core.cpp @@ -1,6 +1,10 @@ #include "Core.h" #include "Config.h" #include "Flash.h" +#include "MainUnit.h" +#include "Gps.h" +#include "Network.h" +#include "Rtc.h" #include "Alerts.h" #include "Logging.h" diff --git a/src/Core.h b/src/Core.h index 7338ece..9f9beea 100644 --- a/src/Core.h +++ b/src/Core.h @@ -1,11 +1,6 @@ #pragma once #include - -#include "Gps.h" -#include "MainUnit.h" -#include "Network.h" -#include "Rtc.h" #include "Positions.h" enum class TRACKER_MOVING_STATE : uint8_t { diff --git a/src/Debug.cpp b/src/Debug.cpp index 84d4633..748bb0b 100644 --- a/src/Debug.cpp +++ b/src/Debug.cpp @@ -1,5 +1,8 @@ #include "Debug.h" #include "MainUnit.h" +#include "Hardware.h" +#include "Gps.h" +#include "Rtc.h" #include "Flash.h" #include "Positions.h" #include "Core.h" diff --git a/src/Gps.h b/src/Gps.h index 27a6cc0..aac10d2 100644 --- a/src/Gps.h +++ b/src/Gps.h @@ -1,25 +1,26 @@ -#pragma once - -#include - -#include "Hardware.h" -#include "Time2.h" - -#define GPS_POSITION_SIZE 128 - -namespace gps { - - extern char lastPosition[GPS_POSITION_SIZE]; - extern SIM808_GPS_STATUS lastStatus; - - inline void powerOn() { hardware::sim808::gpsPowerOn(); } - inline void powerOff() { hardware::sim808::gpsPowerOff(); } - - SIM808_GPS_STATUS acquireCurrentPosition(int32_t timeout); - - uint8_t getVelocity(); - float getDistanceFromPrevious(); - void getTime(tmElements_t &time); - - void preserveCurrentCoordinates(); +#pragma once + +#include +#include + +#include "Hardware.h" +#include "Time2.h" + +#define GPS_POSITION_SIZE 128 + +namespace gps { + + extern char lastPosition[GPS_POSITION_SIZE]; + extern SIM808_GPS_STATUS lastStatus; + + inline void powerOn() { hardware::sim808::gpsPowerOn(); } + inline void powerOff() { hardware::sim808::gpsPowerOff(); } + + SIM808_GPS_STATUS acquireCurrentPosition(int32_t timeout); + + uint8_t getVelocity(); + float getDistanceFromPrevious(); + void getTime(tmElements_t &time); + + void preserveCurrentCoordinates(); } \ No newline at end of file diff --git a/src/GpsTracker.ino b/src/GpsTracker.ino index 7963c48..28332fb 100644 --- a/src/GpsTracker.ino +++ b/src/GpsTracker.ino @@ -2,6 +2,9 @@ #include #include "Debug.h" +#include "MainUnit.h" +#include "Hardware.h" +#include "Gps.h" #include "Config.h" #include "Core.h" #include "Positions.h" diff --git a/src/Hardware.h b/src/Hardware.h index e245f13..f73c3ed 100644 --- a/src/Hardware.h +++ b/src/Hardware.h @@ -1,8 +1,9 @@ #pragma once -#include "config/Hardware.h" +#include #include #include +#include "config/Hardware.h" namespace hardware { diff --git a/src/Logging.h b/src/Logging.h index c8460a3..6955805 100644 --- a/src/Logging.h +++ b/src/Logging.h @@ -1,35 +1,35 @@ -#pragma once -#include "Config.h" - -//#define DISABLE_LOGGING 1 -#include - -#define LOG_SERIAL_SPEED 115200 -#if _DEBUG -#define LOG_LEVEL LOG_LEVEL_VERBOSE -#else -#define LOG_LEVEL LOG_LEVEL_NOTICE -#endif - -#define LOG(level, f) Log.level(F("[" LOGGER_NAME "::" f "]\n")) -#define LOG_MSG(level, f, msg) Log.level(F("[" LOGGER_NAME "::" f "] " msg "\n")) -#define LOG_FORMAT(level, f, msg, ...) Log.level(F("[" LOGGER_NAME "::" f "] " msg "\n"), __VA_ARGS__) - -#if _DEBUG -#define VERBOSE(f) LOG(verbose, f) -#define VERBOSE_MSG(f, msg) LOG_MSG(verbose, f, msg) -#define VERBOSE_FORMAT(f, msg, ...) LOG_FORMAT(verbose, f, msg, __VA_ARGS__) -#else -#define VERBOSE(f) -#define VERBOSE_MSG(f, msg) -#define VERBOSE_FORMAT(f, msg, ...) -#endif - -#define NOTICE(f) LOG(notice, f) -#define NOTICE_MSG(f, msg) LOG_MSG(notice, f, msg) -#define NOTICE_FORMAT(f, msg, ...) LOG_FORMAT(notice, f, msg, __VA_ARGS__) - - -namespace logging { - void setup(); +#pragma once + +//#define DISABLE_LOGGING 1 +#include +#include "Config.h" + +#define LOG_SERIAL_SPEED 115200 +#if _DEBUG +#define LOG_LEVEL LOG_LEVEL_VERBOSE +#else +#define LOG_LEVEL LOG_LEVEL_NOTICE +#endif + +#define LOG(level, f) Log.level(F("[" LOGGER_NAME "::" f "]\n")) +#define LOG_MSG(level, f, msg) Log.level(F("[" LOGGER_NAME "::" f "] " msg "\n")) +#define LOG_FORMAT(level, f, msg, ...) Log.level(F("[" LOGGER_NAME "::" f "] " msg "\n"), __VA_ARGS__) + +#if _DEBUG +#define VERBOSE(f) LOG(verbose, f) +#define VERBOSE_MSG(f, msg) LOG_MSG(verbose, f, msg) +#define VERBOSE_FORMAT(f, msg, ...) LOG_FORMAT(verbose, f, msg, __VA_ARGS__) +#else +#define VERBOSE(f) +#define VERBOSE_MSG(f, msg) +#define VERBOSE_FORMAT(f, msg, ...) +#endif + +#define NOTICE(f) LOG(notice, f) +#define NOTICE_MSG(f, msg) LOG_MSG(notice, f, msg) +#define NOTICE_FORMAT(f, msg, ...) LOG_FORMAT(notice, f, msg, __VA_ARGS__) + + +namespace logging { + void setup(); } \ No newline at end of file diff --git a/src/Network.h b/src/Network.h index 80334e8..a03e1fd 100644 --- a/src/Network.h +++ b/src/Network.h @@ -1,15 +1,16 @@ -#pragma once - -#include "Hardware.h" - -namespace network { - - void powerOn(); - void powerOff(); - - SIM808RegistrationStatus waitForRegistered(uint32_t timeout, bool relativeToPowerOnTime = true); - bool isAvailable(SIM808_NETWORK_REGISTRATION_STATE state); - bool enableGprs(); - - bool sendSms(const char * msg); +#pragma once + +#include +#include "Hardware.h" + +namespace network { + + void powerOn(); + void powerOff(); + + SIM808RegistrationStatus waitForRegistered(uint32_t timeout, bool relativeToPowerOnTime = true); + bool isAvailable(SIM808_NETWORK_REGISTRATION_STATE state); + bool enableGprs(); + + bool sendSms(const char * msg); } \ No newline at end of file diff --git a/src/NetworkPositionsBackup.h b/src/NetworkPositionsBackup.h index dbc9c74..528c22b 100644 --- a/src/NetworkPositionsBackup.h +++ b/src/NetworkPositionsBackup.h @@ -1,7 +1,6 @@ #pragma once #include "PositionsBackup.h" -#include "Time2.h" #include "Positions.h" namespace positions { diff --git a/src/Positions.h b/src/Positions.h index 574ddcc..bc552f5 100644 --- a/src/Positions.h +++ b/src/Positions.h @@ -1,32 +1,33 @@ -#pragma once - -#include - -#define POSITION_SIZE 115 - -struct PositionEntryMetadata { - int8_t batteryLevel; //sizeof = 1 - int16_t batteryVoltage; //sizeof = 2 - int16_t temperature; //sizeof = 2 - uint16_t timeToFix; //sizeof = 2 - SIM808_GPS_STATUS status; //sizeof = 1 -}; //sizeof = 8 - -struct PositionEntry { - PositionEntryMetadata metadata; //sizeof = 8 - char position[POSITION_SIZE]; //sizeof = 115 -}; //sizeof = 123 - -namespace positions { - - void setup(); - bool acquire(PositionEntryMetadata &metadata); - void appendLast(const PositionEntryMetadata &metadata); - - bool get(uint16_t index, PositionEntry &entry); - bool moveNext(uint16_t &index); - uint16_t count(uint16_t fromIndex); - - void prepareBackup(); - void doBackup(bool force); +#pragma once + +#include +#include + +#define POSITION_SIZE 115 + +struct PositionEntryMetadata { + int8_t batteryLevel; //sizeof = 1 + int16_t batteryVoltage; //sizeof = 2 + int16_t temperature; //sizeof = 2 + uint16_t timeToFix; //sizeof = 2 + SIM808_GPS_STATUS status; //sizeof = 1 +}; //sizeof = 8 + +struct PositionEntry { + PositionEntryMetadata metadata; //sizeof = 8 + char position[POSITION_SIZE]; //sizeof = 115 +}; //sizeof = 123 + +namespace positions { + + void setup(); + bool acquire(PositionEntryMetadata &metadata); + void appendLast(const PositionEntryMetadata &metadata); + + bool get(uint16_t index, PositionEntry &entry); + bool moveNext(uint16_t &index); + uint16_t count(uint16_t fromIndex); + + void prepareBackup(); + void doBackup(bool force); } \ No newline at end of file diff --git a/src/Rtc.h b/src/Rtc.h index 15b271f..138a6d0 100644 --- a/src/Rtc.h +++ b/src/Rtc.h @@ -1,17 +1,18 @@ -#pragma once - -#include "Time2.h" - -namespace rtc { - void setup(); - - int16_t getTemperature(); - - bool isAccurate(); - timestamp_t getTime(); - void getTime(tmElements_t &time); - void setTime(const tmElements_t &time); - - void setAlarm(uint16_t seconds); - void setAlarm(const tmElements_t &time); +#pragma once + +#include +#include "Time2.h" + +namespace rtc { + void setup(); + + int16_t getTemperature(); + + bool isAccurate(); + timestamp_t getTime(); + void getTime(tmElements_t &time); + void setTime(const tmElements_t &time); + + void setAlarm(uint16_t seconds); + void setAlarm(const tmElements_t &time); } \ No newline at end of file diff --git a/src/SdPositionsConfig.h b/src/SdPositionsConfig.h index f6f06fc..cdfb815 100644 --- a/src/SdPositionsConfig.h +++ b/src/SdPositionsConfig.h @@ -1,35 +1,28 @@ -#pragma once - -#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 -#define POSITIONS_CONFIG_DEFAULT_MAX_RECORDS_PER_FILE 5 - -struct SdPositionConfig_t { - uint8_t seed; - uint8_t saveThreshold; - uint8_t maxRecordsPerFile; - uint16_t lastSavedEntry; - uint16_t fileIndex; - uint32_t filePosition; - size_t fileRecords; -}; - -namespace config { - namespace backup { - namespace sd { - - void setup(); - - SdPositionConfig_t get(); - void set(SdPositionConfig_t config); - void reset(); - - } - } +#pragma once + +#include +#include "config/BackupSd.h" + +struct SdPositionConfig_t { + uint8_t seed; + uint8_t saveThreshold; + uint8_t maxRecordsPerFile; + uint16_t lastSavedEntry; + uint16_t fileIndex; + uint32_t filePosition; + size_t fileRecords; +}; + +namespace config { + namespace backup { + namespace sd { + + void setup(); + + SdPositionConfig_t get(); + void set(SdPositionConfig_t config); + void reset(); + + } + } } \ No newline at end of file diff --git a/src/Time2.h b/src/Time2.h index fee192d..6f9947a 100644 --- a/src/Time2.h +++ b/src/Time2.h @@ -1,12 +1,12 @@ -#pragma once - -#include -#include - -namespace utils { - namespace time { - - void breakTime(const timestamp_t time, tmElements_t &tm); - timestamp_t makeTimestamp(const tmElements_t &tm); - } -} +#pragma once + +#include +#include + +namespace utils { + namespace time { + + void breakTime(const timestamp_t time, tmElements_t &tm); + timestamp_t makeTimestamp(const tmElements_t &tm); + } +} diff --git a/src/config/BackupSd.h b/src/config/BackupSd.h index 7b9637e..9142470 100644 --- a/src/config/BackupSd.h +++ b/src/config/BackupSd.h @@ -1 +1,9 @@ -#pragma once \ No newline at end of file +#pragma once + +#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 +#define POSITIONS_CONFIG_DEFAULT_MAX_RECORDS_PER_FILE 5 \ No newline at end of file