diff --git a/src/Config.cpp b/src/Config.cpp index 2d63a50..5eff62b 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -4,24 +4,24 @@ #include "Flash.h" const char VERSION_STRING[] PROGMEM = VERSION; -const config_t DEFAULT_CONFIG PROGMEM = { +const config_t CONFIG PROGMEM = { CONFIG_SEED, VERSION, 0xFFFF, 0xFFFF, #if BACKUP_ENABLE_NETWORK { - POSITIONS_CONFIG_NET_DEFAULT_SAVE_THRESHOLD, + POSITIONS_CONFIG_NET_SAVE_THRESHOLD, 0xFFFF, - POSITIONS_CONFIG_NET_DEFAULT_APN, - POSITIONS_CONFIG_NET_DEFAULT_URL + POSITIONS_CONFIG_NET_APN, + POSITIONS_CONFIG_NET_URL }, #endif - CONFIG_DEFAULT_BATTERY_ALERT_LEVEL1, - CONFIG_DEFAULT_BATTERY_ALERT_LEVEL2, - CONFIG_DEFAULT_BATTERY_ALERT_CLEAR, - CONFIG_DEFAULT_ACTIVE_ALERTS, - CONFIG_DEFAULT_CONTACT_PHONE + CONFIG_BATTERY_ALERT_LEVEL1, + CONFIG_BATTERY_ALERT_LEVEL2, + CONFIG_BATTERY_ALERT_CLEAR, + CONFIG_ACTIVE_ALERTS, + CONFIG_CONTACT_PHONE }; namespace config { @@ -45,19 +45,19 @@ namespace config { #if BACKUP_ENABLE_NETWORK //networkConfig_t c = { - // POSITIONS_CONFIG_NET_DEFAULT_SAVE_THRESHOLD, + // POSITIONS_CONFIG_NET_SAVE_THRESHOLD, // 0xFFFF, - // POSITIONS_CONFIG_NET_DEFAULT_APN, - // POSITIONS_CONFIG_NET_DEFAULT_URL, + // POSITIONS_CONFIG_NET_APN, + // POSITIONS_CONFIG_NET_URL, //}; //value.network = c; #endif /*strcpy_P(value.version, VERSION_STRING); - value.alertBatteryLevel1 = CONFIG_DEFAULT_BATTERY_ALERT_LEVEL1; - value.alertBatteryLevel2 = CONFIG_DEFAULT_BATTERY_ALERT_LEVEL2; - value.alertBatteryLevelClear = CONFIG_DEFAULT_BATTERY_ALERT_CLEAR; - value.activeAlerts = CONFIG_DEFAULT_ACTIVE_ALERTS; - strcpy_P(config.contactPhone, PSTR(CONFIG_DEFAULT_CONTACT_PHONE));*/ + value.alertBatteryLevel1 = CONFIG_BATTERY_ALERT_LEVEL1; + value.alertBatteryLevel2 = CONFIG_BATTERY_ALERT_LEVEL2; + value.alertBatteryLevelClear = CONFIG_BATTERY_ALERT_CLEAR; + value.activeAlerts = CONFIG_ACTIVE_ALERTS; + strcpy_P(config.contactPhone, PSTR(CONFIG_CONTACT_PHONE));*/ } void write() { @@ -88,7 +88,7 @@ namespace config { #define CURRENT_LOGGER_FUNCTION "reset" NOTICE; - utils::flash::read(&DEFAULT_CONFIG, value); + utils::flash::read(&CONFIG, value); save(); } diff --git a/src/Core.cpp b/src/Core.cpp index e9c3304..8d83215 100644 --- a/src/Core.cpp +++ b/src/Core.cpp @@ -16,8 +16,8 @@ using namespace utils; namespace core { #define CURRENT_LOGGER "core" - uint16_t sleepTime = SLEEP_DEFAULT_TIME_SECONDS; - uint8_t stoppedInARow = SLEEP_DEFAULT_STOPPED_THRESHOLD - 1; + uint16_t sleepTime = SLEEP_TIME_SECONDS; + uint8_t stoppedInARow = SLEEP_STOPPED_THRESHOLD - 1; TRACKER_MOVING_STATE movingState = TRACKER_MOVING_STATE::MOVING; namespace details { @@ -78,7 +78,7 @@ namespace core { if (!triggered) return NO_ALERTS_NOTIFIED; network::powerOn(); - networkStatus = network::waitForRegistered(NETWORK_DEFAULT_TOTAL_TIMEOUT_MS); + networkStatus = network::waitForRegistered(NETWORK_TOTAL_TIMEOUT_MS); if (network::isAvailable(networkStatus)) { strncpy_P(buffer, PSTR("Alerts !"), SMS_BUFFER_SIZE); @@ -123,16 +123,16 @@ namespace core { if (velocity < SLEEP_TIMING_MIN_MOVING_VELOCITY) { float distance = gps::getDistanceFromPrevious(); //did we missed positions because we were sleeping ? - if (distance > GPS_DEFAULT_MISSED_POSITION_GAP_KM) stoppedInARow = 0; - else stoppedInARow = min(stoppedInARow + 1, SLEEP_DEFAULT_STOPPED_THRESHOLD + 1); //avoid overflow on REALLY long stops + if (distance > GPS_MISSED_POSITION_GAP_KM) stoppedInARow = 0; + else stoppedInARow = min(stoppedInARow + 1, SLEEP_STOPPED_THRESHOLD + 1); //avoid overflow on REALLY long stops - if (stoppedInARow < SLEEP_DEFAULT_STOPPED_THRESHOLD) { - sleepTime = SLEEP_DEFAULT_PAUSING_TIME_SECONDS; - state = stoppedInARow == SLEEP_DEFAULT_STOPPED_THRESHOLD - 1 ? + if (stoppedInARow < SLEEP_STOPPED_THRESHOLD) { + sleepTime = SLEEP_PAUSING_TIME_SECONDS; + state = stoppedInARow == SLEEP_STOPPED_THRESHOLD - 1 ? TRACKER_MOVING_STATE::ABOUT_TO_STOP : TRACKER_MOVING_STATE::PAUSED; } - else if (stoppedInARow == SLEEP_DEFAULT_STOPPED_THRESHOLD) state = TRACKER_MOVING_STATE::STOPPED; + else if (stoppedInARow == SLEEP_STOPPED_THRESHOLD) state = TRACKER_MOVING_STATE::STOPPED; else state = TRACKER_MOVING_STATE::STATIC; } else stoppedInARow = 0; diff --git a/src/Debug.cpp b/src/Debug.cpp index 5b3e617..09f4688 100644 --- a/src/Debug.cpp +++ b/src/Debug.cpp @@ -163,7 +163,7 @@ namespace debug { void getAndDisplayGpsPosition() { #define CURRENT_LOGGER_FUNCTION "getAndDisplayGpsPosition" - SIM808_GPS_STATUS gpsStatus = gps::acquireCurrentPosition(GPS_DEFAULT_TOTAL_TIMEOUT_MS); + SIM808_GPS_STATUS gpsStatus = gps::acquireCurrentPosition(GPS_TOTAL_TIMEOUT_MS); NOTICE_FORMAT("%d %s", gpsStatus, gps::lastPosition); } diff --git a/src/Gps.cpp b/src/Gps.cpp index c53dde8..016c0ce 100644 --- a/src/Gps.cpp +++ b/src/Gps.cpp @@ -42,8 +42,8 @@ namespace gps { if (currentStatus > SIM808_GPS_STATUS::FIX) break; //if we have an accurate fix, break right now NOTICE_FORMAT("%d", currentStatus); - mainunit::deepSleep(GPS_DEFAULT_INTERMEDIATE_TIMEOUT_MS / 1000); - timeout -= GPS_DEFAULT_INTERMEDIATE_TIMEOUT_MS; + mainunit::deepSleep(GPS_INTERMEDIATE_TIMEOUT_MS / 1000); + timeout -= GPS_INTERMEDIATE_TIMEOUT_MS; } while (timeout > 1); if (currentStatus > SIM808_GPS_STATUS::NO_FIX) { diff --git a/src/Network.cpp b/src/Network.cpp index 129c20b..f8a61eb 100644 --- a/src/Network.cpp +++ b/src/Network.cpp @@ -44,15 +44,15 @@ namespace network { if (isAvailable(currentStatus)) break; details::print(currentStatus, report); - if (report.rssi < NETWORK_DEFAULT_NO_NETWORK_QUALITY_THRESHOLD) noReliableNetwork++; + if (report.rssi < NETWORK_NO_NETWORK_QUALITY_THRESHOLD) noReliableNetwork++; else noReliableNetwork = 0; - if (noReliableNetwork > NETWORK_DEFAULT_NO_NETWORK_TRIES) { + if (noReliableNetwork > NETWORK_NO_NETWORK_TRIES) { NOTICE_MSG("No reliable signal"); break; //after a while, no network really means no network. Bailing out } - mainunit::deepSleep(NETWORK_DEFAULT_INTERMEDIATE_TIMEOUT_MS / 1000); - timeout -= NETWORK_DEFAULT_INTERMEDIATE_TIMEOUT_MS; + mainunit::deepSleep(NETWORK_INTERMEDIATE_TIMEOUT_MS / 1000); + timeout -= NETWORK_INTERMEDIATE_TIMEOUT_MS; currentStatus = hardware::sim808::device.getNetworkRegistrationStatus(); report = hardware::sim808::device.getSignalQuality(); diff --git a/src/NetworkPositionsBackup.cpp b/src/NetworkPositionsBackup.cpp index b208fca..cebf8a8 100644 --- a/src/NetworkPositionsBackup.cpp +++ b/src/NetworkPositionsBackup.cpp @@ -53,7 +53,7 @@ namespace positions { ); NOTICE_FORMAT("Response : %d", responseCode); - return responseCode == POSITIONS_CONFIG_NET_DEFAULT_EXPECTED_RESPONSE; + return responseCode == POSITIONS_CONFIG_NET_EXPECTED_RESPONSE; } void NetworkPositionsBackup::appendPositions() { @@ -67,14 +67,14 @@ namespace positions { if (!positions::count(config::main::value.network.lastSavedEntry)) return; network::powerOn(); - networkStatus = network::waitForRegistered(NETWORK_DEFAULT_TOTAL_TIMEOUT_MS); + networkStatus = network::waitForRegistered(NETWORK_TOTAL_TIMEOUT_MS); if (networkStatus == SIM808_NETWORK_REGISTRATION_STATE::ERROR || (!network::isAvailable(networkStatus) || !network::enableGprs())) { - networkUnavailableInARow = min(networkUnavailableInARow + 1, POSITIONS_CONFIG_NET_DEFAULT_UNAVAILABLE_NETWORK_POSTPONE_THRESHOLD + 1); //avoid increment overflow + networkUnavailableInARow = min(networkUnavailableInARow + 1, POSITIONS_CONFIG_NET_UNAVAILABLE_NETWORK_POSTPONE_THRESHOLD + 1); //avoid increment overflow NOTICE_MSG("network or gprs unavailable"); - if (networkUnavailableInARow > POSITIONS_CONFIG_NET_DEFAULT_UNAVAILABLE_NETWORK_POSTPONE_THRESHOLD) { + if (networkUnavailableInARow > POSITIONS_CONFIG_NET_UNAVAILABLE_NETWORK_POSTPONE_THRESHOLD) { networkUnavailablePostpone++; } } diff --git a/src/Positions.cpp b/src/Positions.cpp index 67aca18..fffa7b7 100644 --- a/src/Positions.cpp +++ b/src/Positions.cpp @@ -80,7 +80,7 @@ namespace positions { gps::powerOn(); before = rtc::getTime(); - SIM808_GPS_STATUS gpsStatus = gps::acquireCurrentPosition(GPS_DEFAULT_TOTAL_TIMEOUT_MS); + SIM808_GPS_STATUS gpsStatus = gps::acquireCurrentPosition(GPS_TOTAL_TIMEOUT_MS); uint16_t timeToFix = rtc::getTime() - before; SIM808ChargingStatus battery = hardware::sim808::device.getChargingState(); gps::powerOff(); diff --git a/src/SdPositionsConfig.cpp b/src/SdPositionsConfig.cpp index 416bee3..1b94cf6 100644 --- a/src/SdPositionsConfig.cpp +++ b/src/SdPositionsConfig.cpp @@ -60,8 +60,8 @@ namespace config { SdPositionConfig_t config = { POSITIONS_CONFIG_SEED, - POSITIONS_CONFIG_DEFAULT_SAVE_THRESHOLD, - POSITIONS_CONFIG_DEFAULT_MAX_RECORDS_PER_FILE, + POSITIONS_CONFIG_SAVE_THRESHOLD, + POSITIONS_CONFIG_MAX_RECORDS_PER_FILE, 0xFFFF, 0, 0, diff --git a/src/config/Alerts.h b/src/config/Alerts.h index 0c7aa4c..14e9ef6 100644 --- a/src/config/Alerts.h +++ b/src/config/Alerts.h @@ -12,11 +12,11 @@ */ #define ALERTS_ON_SERIAL _DEBUG ///< Display alerts on serial when connected rather than sending an SMS. -#define CONFIG_DEFAULT_BATTERY_ALERT_LEVEL1 45 ///< Battery percentage at which to trigger the first low battery alert. -#define CONFIG_DEFAULT_BATTERY_ALERT_LEVEL2 38 ///< Battery percentage at which to trigger the final low battery alert. -#define CONFIG_DEFAULT_BATTERY_ALERT_CLEAR 60 ///< Battery percentage at which to clear all battery alerts. -#define CONFIG_DEFAULT_ACTIVE_ALERTS 0 ///< Default active alerts -#define CONFIG_DEFAULT_CONTACT_PHONE "+642568452" ///< Default phone number to send the alert SMS to. +#define CONFIG_BATTERY_ALERT_LEVEL1 45 ///< Battery percentage at which to trigger the first low battery alert. +#define CONFIG_BATTERY_ALERT_LEVEL2 38 ///< Battery percentage at which to trigger the final low battery alert. +#define CONFIG_BATTERY_ALERT_CLEAR 60 ///< Battery percentage at which to clear all battery alerts. +#define CONFIG_ACTIVE_ALERTS 0 ///< Default active alerts +#define CONFIG_CONTACT_PHONE "+642568452" ///< Default phone number to send the alert SMS to. #define ALERT_SUSPICIOUS_RTC_TEMPERATURE 0 ///< Temperature at which to consider the RTC module as failling. diff --git a/src/config/BackupNetwork.h b/src/config/BackupNetwork.h index 86c0394..edf8f8f 100644 --- a/src/config/BackupNetwork.h +++ b/src/config/BackupNetwork.h @@ -4,11 +4,11 @@ #pragma once -#define POSITIONS_CONFIG_NET_DEFAULT_SAVE_THRESHOLD 30 ///< Determines how many positions will be saved before a network backup is needed (only when not moving though). -#define POSITIONS_CONFIG_NET_DEFAULT_APN "Vodafone" ///< APN used for GPRS context -#define POSITIONS_CONFIG_NET_DEFAULT_URL "http://yourserver.com/endpoint" ///< URL to which positions data will be send through an HTTP POST request -#define POSITIONS_CONFIG_NET_DEFAULT_EXPECTED_RESPONSE 201 ///< Expected response code from the server that indicates that the positions has been successfully backuped. -#define POSITIONS_CONFIG_NET_DEFAULT_UNAVAILABLE_NETWORK_POSTPONE_THRESHOLD 5 ///< Determines how many times to deal with an unreliable network before postponing the backup. +#define POSITIONS_CONFIG_NET_SAVE_THRESHOLD 30 ///< Determines how many positions will be saved before a network backup is needed (only when not moving though). +#define POSITIONS_CONFIG_NET_APN "Vodafone" ///< APN used for GPRS context +#define POSITIONS_CONFIG_NET_URL "http://yourserver.com/endpoint" ///< URL to which positions data will be send through an HTTP POST request +#define POSITIONS_CONFIG_NET_EXPECTED_RESPONSE 201 ///< Expected response code from the server that indicates that the positions has been successfully backuped. +#define POSITIONS_CONFIG_NET_UNAVAILABLE_NETWORK_POSTPONE_THRESHOLD 5 ///< Determines how many times to deal with an unreliable network before postponing the backup. ///< In an area where cell reception isn't good, this avoid to try to backup the positions ///< every single time, which would rapidly consumes all the battery. diff --git a/src/config/BackupSd.h b/src/config/BackupSd.h index 9142470..3052e62 100644 --- a/src/config/BackupSd.h +++ b/src/config/BackupSd.h @@ -5,5 +5,5 @@ #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 +#define POSITIONS_CONFIG_SAVE_THRESHOLD 10 +#define POSITIONS_CONFIG_MAX_RECORDS_PER_FILE 5 \ No newline at end of file diff --git a/src/config/Gps.h b/src/config/Gps.h index 18b0ab0..e0b45ae 100644 --- a/src/config/Gps.h +++ b/src/config/Gps.h @@ -4,9 +4,9 @@ #pragma once -#define GPS_DEFAULT_INTERMEDIATE_TIMEOUT_MS 10000L ///< Time to sleeps between each GPS signal assessment. -#define GPS_DEFAULT_TOTAL_TIMEOUT_MS 80000L ///< Timeout after which to stop trying to get a GPS signal. -#define GPS_DEFAULT_MISSED_POSITION_GAP_KM 2 ///< Gap between the current and previous position above which to consider - ///< that the tracker has moved. Even if stopped, this will trigger a whole - ///< new "cycle" of positions acquisition, and will avoid missing positions - ///< because while moving, the tracker woke up while stopped at a light traffic for instance. \ No newline at end of file +#define GPS_INTERMEDIATE_TIMEOUT_MS 10000L ///< Time to sleeps between each GPS signal assessment. +#define GPS_TOTAL_TIMEOUT_MS 80000L ///< Timeout after which to stop trying to get a GPS signal. +#define GPS_MISSED_POSITION_GAP_KM 2 ///< Gap between the current and previous position above which to consider + ///< that the tracker has moved. Even if stopped, this will trigger a whole + ///< new "cycle" of positions acquisition, and will avoid missing positions + ///< because while moving, the tracker woke up while stopped at a light traffic for instance. \ No newline at end of file diff --git a/src/config/Hardware.h b/src/config/Hardware.h index 7560219..a585d49 100644 --- a/src/config/Hardware.h +++ b/src/config/Hardware.h @@ -5,7 +5,7 @@ #include #include -#define E24_ADDRESS E24_DEFAULT_ADDR ///< I2C address of the 24xxx chip +#define E24_ADDRESS E24_ADDR ///< I2C address of the 24xxx chip #define E24_SIZE E24Size_t::E24_512K ///< 24xxx chip size #define SIM808_BAUDRATE 4800 ///< Control the baudrate use to communicate with the SIM808 module diff --git a/src/config/Network.h b/src/config/Network.h index a5da437..608b6c6 100644 --- a/src/config/Network.h +++ b/src/config/Network.h @@ -4,7 +4,7 @@ #pragma onces -#define NETWORK_DEFAULT_NO_NETWORK_QUALITY_THRESHOLD 8 ///< Minimum signal quality to consider the cellphone reception as reliable. -#define NETWORK_DEFAULT_NO_NETWORK_TRIES 5 ///< Maximum tries before considering an unreliable cellphone reception as no reception at all. -#define NETWORK_DEFAULT_INTERMEDIATE_TIMEOUT_MS 10000L ///< Intermediate time to sleep between each cellphone reception assessment. -#define NETWORK_DEFAULT_TOTAL_TIMEOUT_MS 80000L ///< Timeout after which to stop trying to register to the network. +#define NETWORK_NO_NETWORK_QUALITY_THRESHOLD 8 ///< Minimum signal quality to consider the cellphone reception as reliable. +#define NETWORK_NO_NETWORK_TRIES 5 ///< Maximum tries before considering an unreliable cellphone reception as no reception at all. +#define NETWORK_INTERMEDIATE_TIMEOUT_MS 10000L ///< Intermediate time to sleep between each cellphone reception assessment. +#define NETWORK_TOTAL_TIMEOUT_MS 80000L ///< Timeout after which to stop trying to register to the network. diff --git a/src/config/Sleeps.h b/src/config/Sleeps.h index b728531..e186306 100644 --- a/src/config/Sleeps.h +++ b/src/config/Sleeps.h @@ -6,10 +6,10 @@ #define SLEEP_TIMING_TIME(hours, minutes) hours * 60 + minutes -#define SLEEP_DEFAULT_TIME_SECONDS 1800 ///< Default sleep time +#define SLEEP_TIME_SECONDS 1800 ///< Default sleep time #define SLEEP_TIMING_MIN_MOVING_VELOCITY 5 ///< Speed under which to consider the tracker as not moving -#define SLEEP_DEFAULT_PAUSING_TIME_SECONDS 270 ///< Sleep time to use when not moving -#define SLEEP_DEFAULT_STOPPED_THRESHOLD 5 ///< Number of successive positions acquired as not moving before considering the tracker as stopped +#define SLEEP_PAUSING_TIME_SECONDS 270 ///< Sleep time to use when not moving +#define SLEEP_STOPPED_THRESHOLD 5 ///< Number of successive positions acquired as not moving before considering the tracker as stopped #define SLEEP_TIMING_MIN SLEEP_TIMING_TIME(0, 0) #define SLEEP_TIMING_MAX SLEEP_TIMING_TIME(23, 59) @@ -36,8 +36,8 @@ namespace config { static const sleepTimings_t defaultSleepTimings[] PROGMEM = { // Sleep timings when not moving { 0, SLEEP_TIMING_TIME(16, 00), SLEEP_TIMING_TIME(19, 59), 3600 }, ///< 1 hour between 16:00 and 20:00 UTC (04:00 to 08:00 UTC+12) - { 0, SLEEP_TIMING_TIME(20, 00), SLEEP_TIMING_MAX, SLEEP_DEFAULT_TIME_SECONDS }, ///< default (30 minutes) between 20:00 and 00:00 UTC (08:00 to 12:00 UTC+12) - { 0, SLEEP_TIMING_MIN, SLEEP_TIMING_TIME(8, 29), SLEEP_DEFAULT_TIME_SECONDS }, ///< default (30 minutes) between 00:00 and 8:30 UTC (12:00 to 20:30 UTC+12) + { 0, SLEEP_TIMING_TIME(20, 00), SLEEP_TIMING_MAX, SLEEP_TIME_SECONDS }, ///< default (30 minutes) between 20:00 and 00:00 UTC (08:00 to 12:00 UTC+12) + { 0, SLEEP_TIMING_MIN, SLEEP_TIMING_TIME(8, 29), SLEEP_TIME_SECONDS }, ///< default (30 minutes) between 00:00 and 8:30 UTC (12:00 to 20:30 UTC+12) { 0, SLEEP_TIMING_TIME(8, 30), SLEEP_TIMING_TIME(15, 59), 10800 }, ///< 3 hours between 20:30 and 16:00 UTC (20:30 to 04:00 UTC+12) // Sleep timings while moving