@@ -5,9 +5,8 @@ | |||||
#include "Rtc.h" | #include "Rtc.h" | ||||
#include "Logging.h" | #include "Logging.h" | ||||
#define LOGGER_NAME "Alerts" | |||||
namespace alerts { | namespace alerts { | ||||
#define CURRENT_LOGGER "alerts" | |||||
uint8_t getTriggered(PositionEntryMetadata &metadata) { | uint8_t getTriggered(PositionEntryMetadata &metadata) { | ||||
config_t* config = &config::main::value; | config_t* config = &config::main::value; | ||||
@@ -2,9 +2,10 @@ | |||||
#include "Hardware.h" | #include "Hardware.h" | ||||
#include "Logging.h" | #include "Logging.h" | ||||
#define LOGGER_NAME "Config" | |||||
namespace config { | namespace config { | ||||
#define CURRENT_LOGGER "config" | |||||
namespace main { | namespace main { | ||||
config_t value; | config_t value; | ||||
@@ -12,16 +13,17 @@ namespace config { | |||||
namespace details { | namespace details { | ||||
void read() { | void read() { | ||||
VERBOSE("read"); | |||||
#define CURRENT_LOGGER_FUNCTION "read" | |||||
VERBOSE; | |||||
hardware::i2c::powerOn(); | hardware::i2c::powerOn(); | ||||
hardware::i2c::eeprom.readBlock(CONFIG_ADDR, value); | hardware::i2c::eeprom.readBlock(CONFIG_ADDR, value); | ||||
if (CONFIG_SEED != value.seed) reset(); //todo : reset network if seed for network is not right | if (CONFIG_SEED != value.seed) reset(); //todo : reset network if seed for network is not right | ||||
hardware::i2c::powerOff(); | hardware::i2c::powerOff(); | ||||
NOTICE_FORMAT("read", "%d, %s, %d, %d, %d, %d, %d, %B, %s", value.seed, value.version, value.firstEntry, value.lastEntry, value.alertBatteryLevel1, value.alertBatteryLevel2, value.alertBatteryLevelClear, value.activeAlerts, value.contactPhone); | |||||
NOTICE_FORMAT("%d, %s, %d, %d, %d, %d, %d, %B, %s", value.seed, value.version, value.firstEntry, value.lastEntry, value.alertBatteryLevel1, value.alertBatteryLevel2, value.alertBatteryLevelClear, value.activeAlerts, value.contactPhone); | |||||
#if BACKUP_ENABLE_NETWORK | #if BACKUP_ENABLE_NETWORK | ||||
NOTICE_FORMAT("read", "%d, %d, %s, %s", value.network.saveThreshold, value.network.lastSavedEntry, value.network.apn, value.network.url); | |||||
NOTICE_FORMAT("%d, %d, %s, %s", value.network.saveThreshold, value.network.lastSavedEntry, value.network.apn, value.network.url); | |||||
//networkConfig_t c = { | //networkConfig_t c = { | ||||
// POSITIONS_CONFIG_NET_DEFAULT_SAVE_THRESHOLD, | // POSITIONS_CONFIG_NET_DEFAULT_SAVE_THRESHOLD, | ||||
// 0xFFFF, | // 0xFFFF, | ||||
@@ -39,9 +41,11 @@ namespace config { | |||||
} | } | ||||
void write() { | void write() { | ||||
NOTICE_FORMAT("write", "%d, %s, %d, %d, %d, %d, %d, %B, %s", value.seed, value.version, value.firstEntry, value.lastEntry, value.alertBatteryLevel1, value.alertBatteryLevel2, value.alertBatteryLevelClear, value.activeAlerts, value.contactPhone); | |||||
#define CURRENT_LOGGER_FUNCTION "write" | |||||
NOTICE_FORMAT("%d, %s, %d, %d, %d, %d, %d, %B, %s", value.seed, value.version, value.firstEntry, value.lastEntry, value.alertBatteryLevel1, value.alertBatteryLevel2, value.alertBatteryLevelClear, value.activeAlerts, value.contactPhone); | |||||
#if BACKUP_ENABLE_NETWORK | #if BACKUP_ENABLE_NETWORK | ||||
NOTICE_FORMAT("write", "%d, %d, %s, %s", value.network.saveThreshold, value.network.lastSavedEntry, value.network.apn, value.network.url); | |||||
NOTICE_FORMAT("%d, %d, %s, %s", value.network.saveThreshold, value.network.lastSavedEntry, value.network.apn, value.network.url); | |||||
#endif | #endif | ||||
hardware::i2c::powerOn(); | hardware::i2c::powerOn(); | ||||
int written = hardware::i2c::eeprom.writeBlock(CONFIG_ADDR, value); | int written = hardware::i2c::eeprom.writeBlock(CONFIG_ADDR, value); | ||||
@@ -63,7 +67,8 @@ namespace config { | |||||
} | } | ||||
void reset() { | void reset() { | ||||
VERBOSE("reset"); | |||||
#define CURRENT_LOGGER_FUNCTION "reset" | |||||
VERBOSE; | |||||
config_t config = {}; | config_t config = {}; | ||||
config.seed = CONFIG_SEED; | config.seed = CONFIG_SEED; | ||||
@@ -8,13 +8,13 @@ | |||||
#include "Alerts.h" | #include "Alerts.h" | ||||
#include "Logging.h" | #include "Logging.h" | ||||
#define LOGGER_NAME "Core" | |||||
#define SMS_BUFFER_SIZE 140 | #define SMS_BUFFER_SIZE 140 | ||||
#define NO_ALERTS_NOTIFIED 0 | #define NO_ALERTS_NOTIFIED 0 | ||||
using namespace utils; | using namespace utils; | ||||
namespace core { | namespace core { | ||||
#define CURRENT_LOGGER "core" | |||||
uint16_t sleepTime = SLEEP_DEFAULT_TIME_SECONDS; | uint16_t sleepTime = SLEEP_DEFAULT_TIME_SECONDS; | ||||
uint8_t stoppedInARow = SLEEP_DEFAULT_STOPPED_THRESHOLD - 1; | uint8_t stoppedInARow = SLEEP_DEFAULT_STOPPED_THRESHOLD - 1; | ||||
@@ -61,6 +61,8 @@ namespace core { | |||||
} | } | ||||
uint8_t notifyFailures(PositionEntryMetadata &metadata) { | uint8_t notifyFailures(PositionEntryMetadata &metadata) { | ||||
#define CURRENT_LOGGER_FUNCTION "notifyFailures" | |||||
SIM808_NETWORK_REGISTRATION_STATE networkStatus; | SIM808_NETWORK_REGISTRATION_STATE networkStatus; | ||||
char buffer[SMS_BUFFER_SIZE]; | char buffer[SMS_BUFFER_SIZE]; | ||||
const __FlashStringHelper * backupFailureString = F(" Backup battery failure ?"); | const __FlashStringHelper * backupFailureString = F(" Backup battery failure ?"); | ||||
@@ -69,7 +71,7 @@ namespace core { | |||||
uint8_t triggered = alerts::getTriggered(metadata); | uint8_t triggered = alerts::getTriggered(metadata); | ||||
if (!triggered) return NO_ALERTS_NOTIFIED; | if (!triggered) return NO_ALERTS_NOTIFIED; | ||||
NOTICE_FORMAT("notifyFailures", "triggered : %B", triggered); | |||||
NOTICE_FORMAT("triggered : %B", triggered); | |||||
network::powerOn(); | network::powerOn(); | ||||
networkStatus = network::waitForRegistered(NETWORK_DEFAULT_TOTAL_TIMEOUT_MS); | networkStatus = network::waitForRegistered(NETWORK_DEFAULT_TOTAL_TIMEOUT_MS); | ||||
@@ -89,12 +91,12 @@ namespace core { | |||||
} | } | ||||
#if ALERTS_ON_SERIAL | #if ALERTS_ON_SERIAL | ||||
NOTICE_FORMAT("notifyFailure", "%s", buffer); | |||||
NOTICE_FORMAT("%s", buffer); | |||||
notified = true; | notified = true; | ||||
#else | #else | ||||
notified = network::sendSms(buffer); | notified = network::sendSms(buffer); | ||||
#endif | #endif | ||||
if (!notified) NOTICE_MSG("notifyFailure", "SMS not sent !"); | |||||
if (!notified) NOTICE_MSG("SMS not sent !"); | |||||
} | } | ||||
network::powerOff(); | network::powerOff(); | ||||
@@ -108,6 +110,8 @@ namespace core { | |||||
} | } | ||||
TRACKER_MOVING_STATE updateSleepTime() { | TRACKER_MOVING_STATE updateSleepTime() { | ||||
#define CURRENT_LOGGER_FUNCTION "updateSleepTime" | |||||
TRACKER_MOVING_STATE state = TRACKER_MOVING_STATE::MOVING; | TRACKER_MOVING_STATE state = TRACKER_MOVING_STATE::MOVING; | ||||
uint8_t velocity = gps::getVelocity(); | uint8_t velocity = gps::getVelocity(); | ||||
@@ -127,11 +131,13 @@ namespace core { | |||||
} | } | ||||
else stoppedInARow = 0; | else stoppedInARow = 0; | ||||
NOTICE_FORMAT("updateSleepTime", "%dkmh => %d seconds", velocity, sleepTime); | |||||
NOTICE_FORMAT("%dkmh => %d seconds", velocity, sleepTime); | |||||
return state; | return state; | ||||
} | } | ||||
uint16_t mapSleepTime(uint8_t velocity) { | uint16_t mapSleepTime(uint8_t velocity) { | ||||
#define CURRENT_LOGGER_FUNCTION "mapSleepTime" | |||||
uint16_t result; | uint16_t result; | ||||
uint16_t currentTime = 0xFFFF; | uint16_t currentTime = 0xFFFF; | ||||
@@ -154,7 +160,7 @@ namespace core { | |||||
} | } | ||||
VERBOSE_FORMAT("mapSleepTime", "%d,%d", velocity, result); | |||||
VERBOSE_FORMAT("%d,%d", velocity, result); | |||||
return result; | return result; | ||||
} | } | ||||
} | } |
@@ -9,8 +9,6 @@ | |||||
#include "Alerts.h" | #include "Alerts.h" | ||||
#include "Logging.h" | #include "Logging.h" | ||||
#define LOGGER_NAME "Debug" | |||||
#define MENU_ENTRY(name, text) const char MENU_##name[] PROGMEM = text | #define MENU_ENTRY(name, text) const char MENU_##name[] PROGMEM = text | ||||
const char FAKE_GPS_ENTRY[] PROGMEM = "1,1,20170924184842.000,49.454862,1.144537,71.900,2.70,172.6,1,,1.3,2.2,1.8,,11,7,,,37,,"; | const char FAKE_GPS_ENTRY[] PROGMEM = "1,1,20170924184842.000,49.454862,1.144537,71.900,2.70,172.6,1,,1.3,2.2,1.8,,11,7,,,37,,"; | ||||
@@ -116,10 +114,12 @@ static const PositionEntryMetadata fakeMetadata PROGMEM = { | |||||
using namespace utils; | using namespace utils; | ||||
namespace debug { | namespace debug { | ||||
#define CURRENT_LOGGER "debug" | |||||
namespace details { | namespace details { | ||||
inline void displayPosition(PositionEntry entry) { | inline void displayPosition(PositionEntry entry) { | ||||
Log.notice(F("%d,%d,%d,%d,%d,%s"), | |||||
#define CURRENT_LOGGER_FUNCTION "displayPosition" | |||||
NOTICE_FORMAT("%d,%d,%d,%d,%d,%s", | |||||
entry.metadata.batteryLevel, | entry.metadata.batteryLevel, | ||||
entry.metadata.batteryVoltage, | entry.metadata.batteryVoltage, | ||||
entry.metadata.temperature, | entry.metadata.temperature, | ||||
@@ -130,7 +130,8 @@ namespace debug { | |||||
} | } | ||||
void displayFreeRam() { | void displayFreeRam() { | ||||
Log.notice(F("RAM: %d\n"), mainunit::freeRam()); | |||||
#define CURRENT_LOGGER_FUNCTION "displayFreeRam" | |||||
NOTICE_FORMAT("%d", mainunit::freeRam()); | |||||
} | } | ||||
GPSTRACKER_DEBUG_COMMAND parseCommand(char id) { | GPSTRACKER_DEBUG_COMMAND parseCommand(char id) { | ||||
@@ -146,6 +147,8 @@ namespace debug { | |||||
} | } | ||||
GPSTRACKER_DEBUG_COMMAND menu(uint16_t timeout) { | GPSTRACKER_DEBUG_COMMAND menu(uint16_t timeout) { | ||||
#define CURRENT_LOGGER_FUNCTION "menu" | |||||
GPSTRACKER_DEBUG_COMMAND command; | GPSTRACKER_DEBUG_COMMAND command; | ||||
size_t menuSize = flash::getArraySize(MENU_ENTRIES); | size_t menuSize = flash::getArraySize(MENU_ENTRIES); | ||||
@@ -159,7 +162,7 @@ namespace debug { | |||||
delay(MENU_INTERMEDIATE_TIMEOUT); | delay(MENU_INTERMEDIATE_TIMEOUT); | ||||
timeout -= MENU_INTERMEDIATE_TIMEOUT; | timeout -= MENU_INTERMEDIATE_TIMEOUT; | ||||
if (timeout <= 0) { | if (timeout <= 0) { | ||||
NOTICE_MSG("menu", "Timeout expired."); | |||||
NOTICE_MSG("Timeout expired."); | |||||
return GPSTRACKER_DEBUG_COMMAND::RUN; | return GPSTRACKER_DEBUG_COMMAND::RUN; | ||||
} | } | ||||
} | } | ||||
@@ -172,32 +175,36 @@ namespace debug { | |||||
} | } | ||||
void getAndDisplayGpsPosition() { | 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_DEFAULT_TOTAL_TIMEOUT_MS); | ||||
NOTICE_FORMAT("getAndDisplayGpsPosition", "%d %s", gpsStatus, gps::lastPosition); | |||||
NOTICE_FORMAT("%d %s", gpsStatus, gps::lastPosition); | |||||
} | } | ||||
void setFakeGpsPosition() { | void setFakeGpsPosition() { | ||||
#define CURRENT_LOGGER_FUNCTION "setFakeGpsPosition" | |||||
strlcpy_P(gps::lastPosition, FAKE_GPS_ENTRY, GPS_POSITION_SIZE); | strlcpy_P(gps::lastPosition, FAKE_GPS_ENTRY, GPS_POSITION_SIZE); | ||||
NOTICE_FORMAT("setFakeGpsPosition", "Last position set to : %s", gps::lastPosition); | |||||
NOTICE_FORMAT("setFakeGpsPosition", "Speed : %d", gps::getVelocity()); | |||||
NOTICE_FORMAT("setFakeGpsPosition", "Sleep time : %d", core::mapSleepTime(gps::getVelocity())); | |||||
NOTICE_FORMAT("Last position set to : %s", gps::lastPosition); | |||||
NOTICE_FORMAT("Speed : %d", gps::getVelocity()); | |||||
NOTICE_FORMAT("Sleep time : %d", core::mapSleepTime(gps::getVelocity())); | |||||
} | } | ||||
void getAndDisplayBattery() { | void getAndDisplayBattery() { | ||||
#define CURRENT_LOGGER_FUNCTION "getAndDisplayBattery" | |||||
hardware::sim808::powerOn(); | hardware::sim808::powerOn(); | ||||
SIM808ChargingStatus status = hardware::sim808::device.getChargingState(); | SIM808ChargingStatus status = hardware::sim808::device.getChargingState(); | ||||
hardware::sim808::powerOff(); | hardware::sim808::powerOff(); | ||||
NOTICE_FORMAT("getAndDisplayBattery", "%d %d%% %dmV", status.state, status.level, status.voltage); | |||||
NOTICE_FORMAT("%d %d%% %dmV", status.state, status.level, status.voltage); | |||||
} | } | ||||
void getAndDisplayRtcTime() { | void getAndDisplayRtcTime() { | ||||
#define CURRENT_LOGGER_FUNCTION "getAndDisplayRtcTime" | |||||
tmElements_t time; | tmElements_t time; | ||||
rtc::getTime(time); | rtc::getTime(time); | ||||
NOTICE_FORMAT("getAndDisplayRtcTime", "%d/%d/%d %d:%d:%d %t %d", time.year, time.month, time.day, time.hour, time.minute, time.second, rtc::isAccurate(), rtc::getTemperature()); | |||||
NOTICE_FORMAT("%d/%d/%d %d:%d:%d %t %d", time.year, time.month, time.day, time.hour, time.minute, time.second, rtc::isAccurate(), rtc::getTemperature()); | |||||
} | } | ||||
void setRtcTime() { | void setRtcTime() { | ||||
@@ -207,6 +214,8 @@ namespace debug { | |||||
} | } | ||||
void getAndDisplaySleepTimes() { | void getAndDisplaySleepTimes() { | ||||
#define CURRENT_LOGGER_FUNCTION "getAndDisplaySleepTimes" | |||||
size_t arraySize = flash::getArraySize(config::defaultSleepTimings); | size_t arraySize = flash::getArraySize(config::defaultSleepTimings); | ||||
sleepTimings_t maxSpeedTiming; | sleepTimings_t maxSpeedTiming; | ||||
utils::flash::read(&config::defaultSleepTimings[arraySize - 1], maxSpeedTiming); | utils::flash::read(&config::defaultSleepTimings[arraySize - 1], maxSpeedTiming); | ||||
@@ -215,7 +224,7 @@ namespace debug { | |||||
core::mapSleepTime(i); | core::mapSleepTime(i); | ||||
} | } | ||||
NOTICE_MSG("getAndDisplaySleepTimes", "Done"); | |||||
NOTICE_MSG("Done"); | |||||
} | } | ||||
void getAndDisplayEepromConfig() { | void getAndDisplayEepromConfig() { | ||||
@@ -223,6 +232,8 @@ namespace debug { | |||||
} | } | ||||
void getAndDisplayEepromContent() { | void getAndDisplayEepromContent() { | ||||
#define CURRENT_LOGGER_FUNCTION "getAndDisplayEepromContent" | |||||
char buffer[128]; | char buffer[128]; | ||||
hardware::i2c::powerOn(); | hardware::i2c::powerOn(); | ||||
@@ -235,7 +246,7 @@ namespace debug { | |||||
Serial.println(); | Serial.println(); | ||||
hardware::i2c::powerOff(); | hardware::i2c::powerOff(); | ||||
NOTICE_MSG("getAndDisplayEepromContent", "Done"); | |||||
NOTICE_MSG("Done"); | |||||
} | } | ||||
void getAndDisplayEepromPositions() { | void getAndDisplayEepromPositions() { | ||||
@@ -251,11 +262,12 @@ namespace debug { | |||||
} | } | ||||
void getAndDisplayEepromLastPosition() { | void getAndDisplayEepromLastPosition() { | ||||
#define CURRENT_LOGGER_FUNCTION "getAndDisplayEepromLastPosition" | |||||
uint16_t lastEntryIndex = config::main::value.lastEntry; | uint16_t lastEntryIndex = config::main::value.lastEntry; | ||||
PositionEntry lastEntry; | PositionEntry lastEntry; | ||||
if(positions::get(lastEntryIndex, lastEntry)) details::displayPosition(lastEntry); | if(positions::get(lastEntryIndex, lastEntry)) details::displayPosition(lastEntry); | ||||
else Log.notice(F("No position recorded\n")); | |||||
else NOTICE_MSG("No position recorded"); | |||||
} | } | ||||
void addLastPositionToEeprom() { | void addLastPositionToEeprom() { | ||||
@@ -275,13 +287,15 @@ namespace debug { | |||||
} | } | ||||
void notifyFailures() { | void notifyFailures() { | ||||
#define CURRENT_LOGGER_FUNCTION "notifyFailures" | |||||
PositionEntryMetadata metadata = {}; | PositionEntryMetadata metadata = {}; | ||||
flash::read(&fakeMetadata, metadata); | flash::read(&fakeMetadata, metadata); | ||||
metadata.batteryLevel = 1; | metadata.batteryLevel = 1; | ||||
metadata.temperature = ALERT_SUSPICIOUS_RTC_TEMPERATURE; | metadata.temperature = ALERT_SUSPICIOUS_RTC_TEMPERATURE; | ||||
uint8_t alerts = core::notifyFailures(metadata); | uint8_t alerts = core::notifyFailures(metadata); | ||||
NOTICE_FORMAT("notifyFailures", "result : %B", alerts); | |||||
NOTICE_FORMAT("result : %B", alerts); | |||||
alerts::add(alerts); | alerts::add(alerts); | ||||
} | } | ||||
@@ -5,8 +5,6 @@ | |||||
#include "MainUnit.h" | #include "MainUnit.h" | ||||
#include "Logging.h" | #include "Logging.h" | ||||
#define LOGGER_NAME "Gps" | |||||
#define TIME_YEAR_OFFSET 0 | #define TIME_YEAR_OFFSET 0 | ||||
#define TIME_MONTH_OFFSET 4 | #define TIME_MONTH_OFFSET 4 | ||||
#define TIME_DAY_OFFSET 6 | #define TIME_DAY_OFFSET 6 | ||||
@@ -16,7 +14,9 @@ | |||||
#define EARTH_RADIUS 6371 //kilometers | #define EARTH_RADIUS 6371 //kilometers | ||||
namespace gps { | namespace gps { | ||||
#define CURRENT_LOGGER "gps" | |||||
namespace details { | namespace details { | ||||
uint16_t parseSubstring(char *buffer, char *start, uint8_t size) { | uint16_t parseSubstring(char *buffer, char *start, uint8_t size) { | ||||
@@ -25,6 +25,7 @@ namespace gps { | |||||
} | } | ||||
} | } | ||||
char lastPosition[GPS_POSITION_SIZE]; | char lastPosition[GPS_POSITION_SIZE]; | ||||
SIM808_GPS_STATUS lastStatus; | SIM808_GPS_STATUS lastStatus; | ||||
@@ -32,13 +33,15 @@ namespace gps { | |||||
float previousLng = 0; | float previousLng = 0; | ||||
SIM808_GPS_STATUS acquireCurrentPosition(int32_t timeout) { | SIM808_GPS_STATUS acquireCurrentPosition(int32_t timeout) { | ||||
#define CURRENT_LOGGER_FUNCTION "acquireCurrentPosition" | |||||
SIM808_GPS_STATUS currentStatus = SIM808_GPS_STATUS::OFF; | SIM808_GPS_STATUS currentStatus = SIM808_GPS_STATUS::OFF; | ||||
do { | do { | ||||
currentStatus = hardware::sim808::device.getGpsStatus(lastPosition, GPS_POSITION_SIZE); | currentStatus = hardware::sim808::device.getGpsStatus(lastPosition, GPS_POSITION_SIZE); | ||||
if (currentStatus > SIM808_GPS_STATUS::FIX) break; //if we have an accurate fix, break right now | if (currentStatus > SIM808_GPS_STATUS::FIX) break; //if we have an accurate fix, break right now | ||||
NOTICE_FORMAT("acquireCurrentPosition", "%d", currentStatus); | |||||
NOTICE_FORMAT("%d", currentStatus); | |||||
mainunit::deepSleep(GPS_DEFAULT_INTERMEDIATE_TIMEOUT_MS / 1000); | mainunit::deepSleep(GPS_DEFAULT_INTERMEDIATE_TIMEOUT_MS / 1000); | ||||
timeout -= GPS_DEFAULT_INTERMEDIATE_TIMEOUT_MS; | timeout -= GPS_DEFAULT_INTERMEDIATE_TIMEOUT_MS; | ||||
} while (timeout > 1); | } while (timeout > 1); | ||||
@@ -47,7 +50,7 @@ namespace gps { | |||||
lastStatus = currentStatus; | lastStatus = currentStatus; | ||||
} | } | ||||
NOTICE_FORMAT("acquireCurrentPosition", "%d", currentStatus); | |||||
NOTICE_FORMAT("%d", currentStatus); | |||||
return currentStatus; | return currentStatus; | ||||
} | } | ||||
@@ -62,12 +65,14 @@ namespace gps { | |||||
} | } | ||||
float getDistanceFromPrevious() { | float getDistanceFromPrevious() { | ||||
#define CURRENT_LOGGER_FUNCTION "getDistanceFromPrevious" | |||||
float lat1, lng1, lat2, lng2; | float lat1, lng1, lat2, lng2; | ||||
if(!hardware::sim808::device.getGpsField(lastPosition, SIM808_GPS_FIELD::LATITUDE, &lat2)) return 0; | if(!hardware::sim808::device.getGpsField(lastPosition, SIM808_GPS_FIELD::LATITUDE, &lat2)) return 0; | ||||
if(!hardware::sim808::device.getGpsField(lastPosition, SIM808_GPS_FIELD::LONGITUDE, &lng2)) return 0; | if(!hardware::sim808::device.getGpsField(lastPosition, SIM808_GPS_FIELD::LONGITUDE, &lng2)) return 0; | ||||
VERBOSE_FORMAT("distanceFromPrevious", "%s, %F, %F, %F, %F", lastPosition, previousLat, previousLng, lat2, lng2); | |||||
VERBOSE_FORMAT("%s, %F, %F, %F, %F", lastPosition, previousLat, previousLng, lat2, lng2); | |||||
lat1 = radians(previousLat); | lat1 = radians(previousLat); | ||||
lng1 = radians(previousLng); | lng1 = radians(previousLng); | ||||
@@ -85,25 +90,29 @@ namespace gps { | |||||
a = EARTH_RADIUS * (2 * atan2(sqrt(a), sqrt(1 - a))); //kilometers | a = EARTH_RADIUS * (2 * atan2(sqrt(a), sqrt(1 - a))); //kilometers | ||||
NOTICE_FORMAT("distanceFromPrevious", "%Fkm", a); | |||||
NOTICE_FORMAT("%Fkm", a); | |||||
return a; | return a; | ||||
} | } | ||||
uint8_t getVelocity() { | uint8_t getVelocity() { | ||||
#define CURRENT_LOGGER_FUNCTION "getVelocity" | |||||
int16_t velocity; | int16_t velocity; | ||||
if (!hardware::sim808::device.getGpsField(lastPosition, SIM808_GPS_FIELD::SPEED, &velocity)) velocity = 0; | if (!hardware::sim808::device.getGpsField(lastPosition, SIM808_GPS_FIELD::SPEED, &velocity)) velocity = 0; | ||||
VERBOSE_FORMAT("getVelocity", "%d", velocity); | |||||
VERBOSE_FORMAT("%d", velocity); | |||||
return velocity; | return velocity; | ||||
} | } | ||||
void getTime(tmElements_t &time) { | void getTime(tmElements_t &time) { | ||||
#define CURRENT_LOGGER_FUNCTION "getTime" | |||||
char *timeStr; | char *timeStr; | ||||
char buffer[5]; | char buffer[5]; | ||||
hardware::sim808::device.getGpsField(lastPosition, SIM808_GPS_FIELD::UTC, &timeStr); | hardware::sim808::device.getGpsField(lastPosition, SIM808_GPS_FIELD::UTC, &timeStr); | ||||
VERBOSE_FORMAT("getTime", "%s", timeStr); | |||||
VERBOSE_FORMAT("%s", timeStr); | |||||
time.year = details::parseSubstring(buffer, timeStr + TIME_YEAR_OFFSET, 4); | time.year = details::parseSubstring(buffer, timeStr + TIME_YEAR_OFFSET, 4); | ||||
time.month = details::parseSubstring(buffer, timeStr + TIME_MONTH_OFFSET, 2); | time.month = details::parseSubstring(buffer, timeStr + TIME_MONTH_OFFSET, 2); | ||||
@@ -112,6 +121,6 @@ namespace gps { | |||||
time.minute = details::parseSubstring(buffer, timeStr + TIME_MINUTE_OFFSET, 2); | time.minute = details::parseSubstring(buffer, timeStr + TIME_MINUTE_OFFSET, 2); | ||||
time.second = details::parseSubstring(buffer, timeStr + TIME_SECOND_OFFSET, 2); | time.second = details::parseSubstring(buffer, timeStr + TIME_SECOND_OFFSET, 2); | ||||
NOTICE_FORMAT("getTime", "%d/%d/%d %d:%d:%d", time.year, time.month, time.day, time.hour, time.minute, time.second); | |||||
NOTICE_FORMAT("%d/%d/%d %d:%d:%d", time.year, time.month, time.day, time.hour, time.minute, time.second); | |||||
} | } | ||||
} | } |
@@ -10,7 +10,7 @@ | |||||
#include "Positions.h" | #include "Positions.h" | ||||
#include "Logging.h" | #include "Logging.h" | ||||
#define LOGGER_NAME "GpsTracker" | |||||
#define CURRENT_LOGGER "GpsTracker" | |||||
bool bypassMenu = false; | bool bypassMenu = false; | ||||
uint16_t menuTimeout = MENU_TIMEOUT; | uint16_t menuTimeout = MENU_TIMEOUT; | ||||
@@ -26,6 +26,7 @@ void setup() { | |||||
} | } | ||||
void loop() { | void loop() { | ||||
#define CURRENT_LOGGER_FUNCTION "loop" | |||||
debug::GPSTRACKER_DEBUG_COMMAND command = debug::GPSTRACKER_DEBUG_COMMAND::RUN; | debug::GPSTRACKER_DEBUG_COMMAND command = debug::GPSTRACKER_DEBUG_COMMAND::RUN; | ||||
if (Serial && !bypassMenu) command = debug::menu(menuTimeout); | if (Serial && !bypassMenu) command = debug::menu(menuTimeout); | ||||
@@ -95,6 +96,6 @@ void loop() { | |||||
mainunit::deepSleep(10); | mainunit::deepSleep(10); | ||||
break; | break; | ||||
default: | default: | ||||
NOTICE_MSG("loop", "Unsupported"); | |||||
NOTICE_MSG("Unsupported"); | |||||
} | } | ||||
} | } |
@@ -5,16 +5,18 @@ | |||||
namespace hardware { | namespace hardware { | ||||
#define LOGGER_NAME "Hardware::sim808" | |||||
namespace sim808 { | namespace sim808 { | ||||
#define CURRENT_LOGGER "hardware::sim808" | |||||
SIM_SERIAL_TYPE simSerial = SIM_SERIAL; | SIM_SERIAL_TYPE simSerial = SIM_SERIAL; | ||||
SIM808 device = SIM808(SIM_RST, SIM_PWR, SIM_STATUS); | SIM808 device = SIM808(SIM_RST, SIM_PWR, SIM_STATUS); | ||||
uint8_t networkPoweredCount = 0; | uint8_t networkPoweredCount = 0; | ||||
uint8_t gpsPoweredCount = 0; | uint8_t gpsPoweredCount = 0; | ||||
void powerOn() { | void powerOn() { | ||||
VERBOSE("powerOn"); | |||||
#define CURRENT_LOGGER_FUNCTION "powerOn" | |||||
VERBOSE; | |||||
bool poweredOn = device.powerOnOff(true); | bool poweredOn = device.powerOnOff(true); | ||||
if (!poweredOn) return; | if (!poweredOn) return; | ||||
@@ -23,7 +25,9 @@ namespace hardware { | |||||
} | } | ||||
void powerOff() { | void powerOff() { | ||||
VERBOSE("powerOff"); | |||||
#define CURRENT_LOGGER_FUNCTION "powerOff" | |||||
VERBOSE; | |||||
device.powerOnOff(false); | device.powerOnOff(false); | ||||
networkPoweredCount = gpsPoweredCount = 0; | networkPoweredCount = gpsPoweredCount = 0; | ||||
} | } | ||||
@@ -41,19 +45,22 @@ namespace hardware { | |||||
} | } | ||||
void setup() { | void setup() { | ||||
NOTICE("setup"); | |||||
#define CURRENT_LOGGER_FUNCTION "setup" | |||||
NOTICE; | |||||
simSerial.begin(SIM808_BAUDRATE); | simSerial.begin(SIM808_BAUDRATE); | ||||
device.begin(simSerial); | device.begin(simSerial); | ||||
powerOff(); //ensure powerOff on start | powerOff(); //ensure powerOff on start | ||||
} | } | ||||
void gpsPowerOn() { | void gpsPowerOn() { | ||||
#define CURRENT_LOGGER_FUNCTION "gpsPowerOn" | |||||
if(gpsPoweredCount) { | if(gpsPoweredCount) { | ||||
gpsPoweredCount++; | gpsPoweredCount++; | ||||
return; | return; | ||||
} | } | ||||
VERBOSE("gpsPowerOn"); | |||||
VERBOSE; | |||||
powerOn(); | powerOn(); | ||||
if(!networkPoweredCount) { | if(!networkPoweredCount) { | ||||
//SIM808 turns phone on by default but we don't need it for gps only | //SIM808 turns phone on by default but we don't need it for gps only | ||||
@@ -63,6 +70,8 @@ namespace hardware { | |||||
} | } | ||||
void gpsPowerOff() { | void gpsPowerOff() { | ||||
#define CURRENT_LOGGER_FUNCTION "gpsPowerOff" | |||||
if (!device.powered()) { | if (!device.powered()) { | ||||
networkPoweredCount = gpsPoweredCount = 0; //just to be sure counts == 0 | networkPoweredCount = gpsPoweredCount = 0; //just to be sure counts == 0 | ||||
return; | return; | ||||
@@ -73,23 +82,27 @@ namespace hardware { | |||||
return; | return; | ||||
} | } | ||||
VERBOSE("gpsPowerOff"); | |||||
VERBOSE; | |||||
device.powerOnOffGps(false); | device.powerOnOffGps(false); | ||||
powerOffIfUnused(); | powerOffIfUnused(); | ||||
} | } | ||||
void networkPowerOn() { | void networkPowerOn() { | ||||
#define CURRENT_LOGGER_FUNCTION "networkPowerOn" | |||||
if(networkPoweredCount) { | if(networkPoweredCount) { | ||||
networkPoweredCount++; | networkPoweredCount++; | ||||
return; | return; | ||||
} | } | ||||
VERBOSE("networkPowerOn"); | |||||
VERBOSE; | |||||
powerOn(); | powerOn(); | ||||
device.setPhoneFunctionality(SIM808_PHONE_FUNCTIONALITY::FULL); | device.setPhoneFunctionality(SIM808_PHONE_FUNCTIONALITY::FULL); | ||||
} | } | ||||
void networkPowerOff() { | void networkPowerOff() { | ||||
#define CURRENT_LOGGER_FUNCTION "networkPowerOff" | |||||
if (!device.powered()) { | if (!device.powered()) { | ||||
networkPoweredCount = gpsPoweredCount = 0; //just to be sure counts == 0 | networkPoweredCount = gpsPoweredCount = 0; //just to be sure counts == 0 | ||||
return; | return; | ||||
@@ -100,27 +113,28 @@ namespace hardware { | |||||
return; | return; | ||||
} | } | ||||
VERBOSE("networkPowerOff"); | |||||
VERBOSE; | |||||
device.disableGprs(); | device.disableGprs(); | ||||
device.setPhoneFunctionality(SIM808_PHONE_FUNCTIONALITY::MINIMUM); | device.setPhoneFunctionality(SIM808_PHONE_FUNCTIONALITY::MINIMUM); | ||||
powerOffIfUnused(); | powerOffIfUnused(); | ||||
} | } | ||||
} | } | ||||
#define LOGGER_NAME "Hardware::i2c" | |||||
namespace i2c { | namespace i2c { | ||||
#define CURRENT_LOGGER "hardware::i2c" | |||||
E24 eeprom = E24(E24_SIZE, E24_ADDRESS); | E24 eeprom = E24(E24_SIZE, E24_ADDRESS); | ||||
uint8_t poweredCount = 0; | uint8_t poweredCount = 0; | ||||
void powerOn() { | void powerOn() { | ||||
#define CURRENT_LOGGER_FUNCTION "powerOn" | |||||
if(poweredCount) { | if(poweredCount) { | ||||
poweredCount++; | poweredCount++; | ||||
return; | return; | ||||
} | } | ||||
VERBOSE("powerOn"); | |||||
VERBOSE; | |||||
digitalWrite(I2C_PWR, HIGH); | digitalWrite(I2C_PWR, HIGH); | ||||
pinMode(I2C_PWR, OUTPUT); | pinMode(I2C_PWR, OUTPUT); | ||||
@@ -129,12 +143,14 @@ namespace hardware { | |||||
} | } | ||||
void powerOff(bool forced = false) { | void powerOff(bool forced = false) { | ||||
#define CURRENT_LOGGER_FUNCTION "powerOff" | |||||
if(poweredCount > 1 && !forced) { | if(poweredCount > 1 && !forced) { | ||||
poweredCount--; | poweredCount--; | ||||
return; | return; | ||||
} | } | ||||
VERBOSE("powerOff"); | |||||
VERBOSE; | |||||
pinMode(I2C_PWR, INPUT); | pinMode(I2C_PWR, INPUT); | ||||
digitalWrite(I2C_PWR, LOW); | digitalWrite(I2C_PWR, LOW); | ||||
@@ -2,33 +2,43 @@ | |||||
//#define DISABLE_LOGGING 1 | //#define DISABLE_LOGGING 1 | ||||
#include <ArduinoLog.h> | #include <ArduinoLog.h> | ||||
#include <SIMComAT.Common.h> //reusing flash string utilities | |||||
#include "Config.h" | #include "Config.h" | ||||
#define LOG_SERIAL_SPEED 115200 | #define LOG_SERIAL_SPEED 115200 | ||||
#if _DEBUG | #if _DEBUG | ||||
#define LOG_LEVEL LOG_LEVEL_VERBOSE | |||||
#define LOG_LEVEL LOG_LEVEL_VERBOSE | |||||
#define LOG_LEVEL_VERBOSE_ENABLED | |||||
#define LOG_LEVEL_NOTICE_ENABLED | |||||
#else | #else | ||||
#define LOG_LEVEL LOG_LEVEL_NOTICE | |||||
#define LOG_LEVEL LOG_LEVEL_NOTICE | |||||
#define LOG_LEVEL_NOTICE_ENABLED | |||||
#endif | #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__) | |||||
#define NL "\n" | |||||
#define LOG(level) LOG_MSG(level, "") | |||||
#define LOG_MSG(level, msg) Log.level(F("[" CURRENT_LOGGER "::" CURRENT_LOGGER_FUNCTION "]" msg NL)) | |||||
#define LOG_FORMAT(level, msg, ...) Log.level(F("[" CURRENT_LOGGER "::" CURRENT_LOGGER_FUNCTION "]" msg NL), __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__) | |||||
#if defined(LOG_LEVEL_VERBOSE_ENABLED) | |||||
#define VERBOSE LOG(verbose) | |||||
#define VERBOSE_MSG(msg) LOG_MSG(verbose, msg) | |||||
#define VERBOSE_FORMAT(msg, ...) LOG_FORMAT(verbose, msg, __VA_ARGS__) | |||||
#else | #else | ||||
#define VERBOSE(f) | |||||
#define VERBOSE_MSG(f, msg) | |||||
#define VERBOSE_FORMAT(f, msg, ...) | |||||
#define VERBOSE | |||||
#define VERBOSE_MSG(msg) | |||||
#define VERBOSE_FORMAT(msg, ...) | |||||
#endif | #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__) | |||||
#if defined(LOG_LEVEL_NOTICE_ENABLED) | |||||
#define NOTICE LOG(notice) | |||||
#define NOTICE_MSG(msg) LOG_MSG(notice, msg) | |||||
#define NOTICE_FORMAT(msg, ...) LOG_FORMAT(notice, msg, __VA_ARGS__) | |||||
#else | |||||
#define NOTICE | |||||
#define NOTICE_MSG(msg) | |||||
#define NOTICE_FORMAT(msg, ...) | |||||
#endif | |||||
namespace logging { | namespace logging { | ||||
void setup(); | void setup(); |
@@ -4,11 +4,11 @@ | |||||
#include "config/Pins.h" | #include "config/Pins.h" | ||||
#include "Logging.h" | #include "Logging.h" | ||||
#define LOGGER_NAME "MainUnit" | |||||
extern int __heap_start, *__brkval; | extern int __heap_start, *__brkval; | ||||
namespace mainunit { | namespace mainunit { | ||||
#define CURRENT_LOGGER "mainunit" | |||||
namespace details { | namespace details { | ||||
@@ -18,9 +18,11 @@ namespace mainunit { | |||||
} | } | ||||
void wokeUp() { | void wokeUp() { | ||||
#define CURRENT_LOGGER_FUNCTION "wokeUp" | |||||
tmElements_t wokeUpTime; | tmElements_t wokeUpTime; | ||||
rtc::getTime(wokeUpTime); | rtc::getTime(wokeUpTime); | ||||
VERBOSE_FORMAT("wokeUp", "%d:%d:%d", wokeUpTime.hour, wokeUpTime.minute, wokeUpTime.second); | |||||
VERBOSE_FORMAT("%d:%d:%d", wokeUpTime.hour, wokeUpTime.minute, wokeUpTime.second); | |||||
hardware::sim808::simSerial.listen(); | hardware::sim808::simSerial.listen(); | ||||
} | } | ||||
@@ -39,7 +41,9 @@ namespace mainunit { | |||||
} | } | ||||
void deepSleep(uint16_t seconds) { | void deepSleep(uint16_t seconds) { | ||||
NOTICE_FORMAT("deepSleep", "%d seconds", seconds); | |||||
#define CURRENT_LOGGER_FUNCTION "deepSleep" | |||||
NOTICE_FORMAT("%d seconds", seconds); | |||||
interruptIn(seconds); | interruptIn(seconds); | ||||
details::prepareSleep(); | details::prepareSleep(); | ||||
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF); | LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF); | ||||
@@ -5,10 +5,8 @@ | |||||
#include "Config.h" | #include "Config.h" | ||||
#include "Logging.h" | #include "Logging.h" | ||||
#define LOGGER_NAME "Network" | |||||
namespace network { | namespace network { | ||||
#define CURRENT_LOGGER "network" | |||||
timestamp_t _poweredOnTime; | timestamp_t _poweredOnTime; | ||||
void powerOn() { | void powerOn() { | ||||
@@ -23,6 +21,7 @@ namespace network { | |||||
__attribute__((__optimize__("O2"))) | __attribute__((__optimize__("O2"))) | ||||
SIM808_NETWORK_REGISTRATION_STATE waitForRegistered(uint32_t timeout, bool relativeToPowerOnTime = true) { | SIM808_NETWORK_REGISTRATION_STATE waitForRegistered(uint32_t timeout, bool relativeToPowerOnTime = true) { | ||||
#define CURRENT_LOGGER_FUNCTION "waitForRegistered" | |||||
SIM808_NETWORK_REGISTRATION_STATE currentStatus; | SIM808_NETWORK_REGISTRATION_STATE currentStatus; | ||||
SIM808SignalQualityReport report; | SIM808SignalQualityReport report; | ||||
@@ -36,12 +35,12 @@ namespace network { | |||||
do { | do { | ||||
if (isAvailable(currentStatus)) break; | if (isAvailable(currentStatus)) break; | ||||
NOTICE_FORMAT("waitForRegistered", "%d, [%d %ddBm]", currentStatus, report.rssi, report.attenuation); | |||||
NOTICE_FORMAT("%d, [%d %ddBm]", currentStatus, report.rssi, report.attenuation); | |||||
if (report.rssi < NETWORK_DEFAULT_NO_NETWORK_QUALITY_THRESHOLD) noReliableNetwork++; | if (report.rssi < NETWORK_DEFAULT_NO_NETWORK_QUALITY_THRESHOLD) noReliableNetwork++; | ||||
else noReliableNetwork = 0; | else noReliableNetwork = 0; | ||||
if (noReliableNetwork > NETWORK_DEFAULT_NO_NETWORK_TRIES) { | if (noReliableNetwork > NETWORK_DEFAULT_NO_NETWORK_TRIES) { | ||||
NOTICE_MSG("waitForRegistered", "No reliable signal"); | |||||
NOTICE_MSG("No reliable signal"); | |||||
break; //after a while, no network really means no network. Bailing out | break; //after a while, no network really means no network. Bailing out | ||||
} | } | ||||
@@ -52,7 +51,7 @@ namespace network { | |||||
report = hardware::sim808::device.getSignalQuality(); | report = hardware::sim808::device.getSignalQuality(); | ||||
} while (timeout > 1); | } while (timeout > 1); | ||||
NOTICE_FORMAT("waitForRegistered", "%d, [%d %ddBm]", currentStatus, report.rssi, report.attenuation); | |||||
NOTICE_FORMAT("%d, [%d %ddBm]", currentStatus, report.rssi, report.attenuation); | |||||
return currentStatus; | return currentStatus; | ||||
} | } | ||||
@@ -69,9 +68,10 @@ namespace network { | |||||
#endif | #endif | ||||
bool sendSms(const char * msg) { | bool sendSms(const char * msg) { | ||||
#define CURRENT_LOGGER_FUNCTION "sendSms" | |||||
const char * phoneNumber = config::main::value.contactPhone; | const char * phoneNumber = config::main::value.contactPhone; | ||||
NOTICE_FORMAT("sendSms", "%s, %s", phoneNumber, msg); | |||||
NOTICE_FORMAT("%s, %s", phoneNumber, msg); | |||||
return hardware::sim808::device.sendSms(phoneNumber, msg); | return hardware::sim808::device.sendSms(phoneNumber, msg); | ||||
} | } | ||||
} | } |
@@ -9,11 +9,12 @@ | |||||
#include "Network.h" | #include "Network.h" | ||||
#include "Logging.h" | #include "Logging.h" | ||||
#define LOGGER_NAME "Positions::backup::network" | |||||
#define BUFFER_SIZE 170 | #define BUFFER_SIZE 170 | ||||
namespace positions { | namespace positions { | ||||
#define CURRENT_LOGGER "Positions::backup::network" | |||||
namespace backup { | namespace backup { | ||||
namespace net { | namespace net { | ||||
@@ -27,6 +28,8 @@ namespace positions { | |||||
} | } | ||||
bool NetworkPositionsBackup::appendPosition(PositionEntry &entry, int8_t signalAttenuation = 0) { | bool NetworkPositionsBackup::appendPosition(PositionEntry &entry, int8_t signalAttenuation = 0) { | ||||
#define CURRENT_LOGGER_FUNCTION "appendPosition" | |||||
char buffer[BUFFER_SIZE]; | char buffer[BUFFER_SIZE]; | ||||
if(signalAttenuation == 0) signalAttenuation = hardware::sim808::device.getSignalQuality().attenuation; | if(signalAttenuation == 0) signalAttenuation = hardware::sim808::device.getSignalQuality().attenuation; | ||||
@@ -40,7 +43,7 @@ namespace positions { | |||||
entry.metadata.timeToFix, | entry.metadata.timeToFix, | ||||
entry.position); | entry.position); | ||||
NOTICE_FORMAT("appendPosition", "Sending : %s", buffer); | |||||
NOTICE_FORMAT("Sending : %s", buffer); | |||||
uint16_t responseCode = hardware::sim808::device.httpPost( | uint16_t responseCode = hardware::sim808::device.httpPost( | ||||
config::main::value.network.url, | config::main::value.network.url, | ||||
F("text/gpstracker"), | F("text/gpstracker"), | ||||
@@ -49,12 +52,14 @@ namespace positions { | |||||
BUFFER_SIZE | BUFFER_SIZE | ||||
); | ); | ||||
NOTICE_FORMAT("appendPosition", "Response : %d", responseCode); | |||||
NOTICE_FORMAT("Response : %d", responseCode); | |||||
return responseCode == POSITIONS_CONFIG_NET_DEFAULT_EXPECTED_RESPONSE; | return responseCode == POSITIONS_CONFIG_NET_DEFAULT_EXPECTED_RESPONSE; | ||||
} | } | ||||
//__attribute__((__optimize__("O2"))) | //__attribute__((__optimize__("O2"))) | ||||
void NetworkPositionsBackup::appendPositions() { | void NetworkPositionsBackup::appendPositions() { | ||||
#define CURRENT_LOGGER_FUNCTION "appendPositions" | |||||
uint16_t currentEntryIndex = config::main::value.network.lastSavedEntry + 1; | uint16_t currentEntryIndex = config::main::value.network.lastSavedEntry + 1; | ||||
PositionEntry currentEntry; | PositionEntry currentEntry; | ||||
SIM808_NETWORK_REGISTRATION_STATE networkStatus; | SIM808_NETWORK_REGISTRATION_STATE networkStatus; | ||||
@@ -67,7 +72,7 @@ namespace positions { | |||||
if (!network::isAvailable(networkStatus) || !network::enableGprs()) { | if (!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_DEFAULT_UNAVAILABLE_NETWORK_POSTPONE_THRESHOLD + 1); //avoid increment overflow | ||||
NOTICE_MSG("appendPositions", "network or gprs unavailable"); | |||||
NOTICE_MSG("network or gprs unavailable"); | |||||
if (networkUnavailableInARow > POSITIONS_CONFIG_NET_DEFAULT_UNAVAILABLE_NETWORK_POSTPONE_THRESHOLD) { | if (networkUnavailableInARow > POSITIONS_CONFIG_NET_DEFAULT_UNAVAILABLE_NETWORK_POSTPONE_THRESHOLD) { | ||||
networkUnavailablePostpone++; | networkUnavailablePostpone++; | ||||
@@ -96,14 +101,16 @@ namespace positions { | |||||
void NetworkPositionsBackup::setup() {} | void NetworkPositionsBackup::setup() {} | ||||
void NetworkPositionsBackup::prepare() { | void NetworkPositionsBackup::prepare() { | ||||
NOTICE("prepare"); | |||||
#define CURRENT_LOGGER_FUNCTION "prepare" | |||||
NOTICE; | |||||
if (!isBackupNeeded(true)) return; | if (!isBackupNeeded(true)) return; | ||||
network::powerOn(); | network::powerOn(); | ||||
} | } | ||||
void NetworkPositionsBackup::backup(bool force) { | void NetworkPositionsBackup::backup(bool force) { | ||||
NOTICE("backup"); | |||||
#define CURRENT_LOGGER_FUNCTION "backup" | |||||
NOTICE; | |||||
if (force || isBackupNeeded(false)) { | if (force || isBackupNeeded(false)) { | ||||
appendPositions(); | appendPositions(); | ||||
@@ -16,12 +16,12 @@ | |||||
#include "NetworkPositionsBackup.h" | #include "NetworkPositionsBackup.h" | ||||
#endif | #endif | ||||
#define LOGGER_NAME "Positions" | |||||
#define ENTRY_RESERVED_SIZE 128 | #define ENTRY_RESERVED_SIZE 128 | ||||
#define ENTRIES_ADDR CONFIG_RESERVED_SIZE | #define ENTRIES_ADDR CONFIG_RESERVED_SIZE | ||||
namespace positions { | namespace positions { | ||||
#define CURRENT_LOGGER "positions" | |||||
#if BACKUPS_ENABLED > 1 | #if BACKUPS_ENABLED > 1 | ||||
backup::PositionsBackup **_backups; | backup::PositionsBackup **_backups; | ||||
#elif BACKUPS_ENABLED == 1 | #elif BACKUPS_ENABLED == 1 | ||||
@@ -73,7 +73,8 @@ namespace positions { | |||||
} | } | ||||
bool acquire(PositionEntryMetadata &metadata) { | bool acquire(PositionEntryMetadata &metadata) { | ||||
NOTICE("acquire"); | |||||
#define CURRENT_LOGGER_FUNCTION "acquire" | |||||
NOTICE; | |||||
timestamp_t before; | timestamp_t before; | ||||
@@ -85,7 +86,7 @@ namespace positions { | |||||
gps::powerOff(); | gps::powerOff(); | ||||
bool acquired = gpsStatus >= SIM808_GPS_STATUS::FIX; //prety useless wins 14 bytes on the hex size rather than return gpStatus >= ... | bool acquired = gpsStatus >= SIM808_GPS_STATUS::FIX; //prety useless wins 14 bytes on the hex size rather than return gpStatus >= ... | ||||
NOTICE_FORMAT("acquire", "Status : %d", gpsStatus); | |||||
NOTICE_FORMAT("Status : %d", gpsStatus); | |||||
metadata = { | metadata = { | ||||
battery.level, | battery.level, | ||||
@@ -99,7 +100,8 @@ namespace positions { | |||||
} | } | ||||
void appendLast(const PositionEntryMetadata &metadata) { | void appendLast(const PositionEntryMetadata &metadata) { | ||||
VERBOSE("appendLast"); | |||||
#define CURRENT_LOGGER_FUNCTION "appendLast" | |||||
VERBOSE; | |||||
uint16_t entryIndex; | uint16_t entryIndex; | ||||
uint16_t entryAddress; | uint16_t entryAddress; | ||||
@@ -114,7 +116,7 @@ namespace positions { | |||||
hardware::i2c::powerOn(); | hardware::i2c::powerOn(); | ||||
hardware::i2c::eeprom.writeBlock(entryAddress, entry); | hardware::i2c::eeprom.writeBlock(entryAddress, entry); | ||||
NOTICE_FORMAT("appendLast", "Saved @ %X : %d,%d,%d,%d,%d,%s", | |||||
NOTICE_FORMAT("Saved @ %X : %d,%d,%d,%d,%d,%s", | |||||
entryAddress, | entryAddress, | ||||
entry.metadata.batteryLevel, | entry.metadata.batteryLevel, | ||||
entry.metadata.batteryVoltage, | entry.metadata.batteryVoltage, | ||||
@@ -133,18 +135,19 @@ namespace positions { | |||||
} | } | ||||
bool get(uint16_t index, PositionEntry &entry) { | bool get(uint16_t index, PositionEntry &entry) { | ||||
VERBOSE("get"); | |||||
#define CURRENT_LOGGER_FUNCTION "get" | |||||
VERBOSE; | |||||
uint16_t entryAddress = details::getEntryAddress(index); | uint16_t entryAddress = details::getEntryAddress(index); | ||||
if (entryAddress == -1) return false; | if (entryAddress == -1) return false; | ||||
VERBOSE_FORMAT("get", "Reading entry %d @ %X", index, entryAddress); | |||||
VERBOSE_FORMAT("Reading entry %d @ %X", index, entryAddress); | |||||
hardware::i2c::powerOn(); | hardware::i2c::powerOn(); | ||||
hardware::i2c::eeprom.readBlock(entryAddress, entry); | hardware::i2c::eeprom.readBlock(entryAddress, entry); | ||||
hardware::i2c::powerOff(); | hardware::i2c::powerOff(); | ||||
NOTICE_FORMAT("get", "Read from EEPROM @ %X : %d,%d,%d,%d,%d,%s", | |||||
NOTICE_FORMAT("Read from EEPROM @ %X : %d,%d,%d,%d,%d,%s", | |||||
entryAddress, | entryAddress, | ||||
entry.metadata.batteryLevel, | entry.metadata.batteryLevel, | ||||
entry.metadata.batteryVoltage, | entry.metadata.batteryVoltage, | ||||
@@ -5,15 +5,17 @@ | |||||
#include <Wire.h> | #include <Wire.h> | ||||
#define LOGGER_NAME "Rtc" | |||||
using namespace utils; | using namespace utils; | ||||
namespace rtc { | namespace rtc { | ||||
#define CURRENT_LOGGER "rtc" | |||||
RTC_A_CLASS RTC_A; | RTC_A_CLASS RTC_A; | ||||
void setup() { | void setup() { | ||||
VERBOSE("setup"); | |||||
#define CURRENT_LOGGER_FUNCTION "setup" | |||||
VERBOSE; | |||||
hardware::i2c::powerOn(); | hardware::i2c::powerOn(); | ||||
RTC_A.control(DS3231_12H, DS3231_OFF); //24 hours clock | RTC_A.control(DS3231_12H, DS3231_OFF); //24 hours clock | ||||
RTC_A.control(DS3231_A1_INT_ENABLE, DS3231_OFF); //Alarm 1 OFF | RTC_A.control(DS3231_A1_INT_ENABLE, DS3231_OFF); //Alarm 1 OFF | ||||
@@ -44,15 +46,18 @@ namespace rtc { | |||||
} | } | ||||
void getTime(tmElements_t &time) { | void getTime(tmElements_t &time) { | ||||
#define CURRENT_LOGGER_FUNCTION "getTime" | |||||
hardware::i2c::powerOn(); | hardware::i2c::powerOn(); | ||||
RTC_A.readTime(time); | RTC_A.readTime(time); | ||||
hardware::i2c::powerOff(); | hardware::i2c::powerOff(); | ||||
VERBOSE_FORMAT("getTime", "%d/%d/%d %d:%d:%d", time.year, time.month, time.day, time.hour, time.minute, time.second); | |||||
VERBOSE_FORMAT("%d/%d/%d %d:%d:%d", time.year, time.month, time.day, time.hour, time.minute, time.second); | |||||
} | } | ||||
void setTime(const tmElements_t &time) { | void setTime(const tmElements_t &time) { | ||||
VERBOSE_FORMAT("setTime", "%d/%d/%d %d:%d:%d", time.year, time.month, time.day, time.hour, time.minute, time.second); | |||||
#define CURRENT_LOGGER_FUNCTION "setTime" | |||||
VERBOSE_FORMAT("%d/%d/%d %d:%d:%d", time.year, time.month, time.day, time.hour, time.minute, time.second); | |||||
hardware::i2c::powerOn(); | hardware::i2c::powerOn(); | ||||
RTC_A.writeTime(time); | RTC_A.writeTime(time); | ||||
@@ -71,6 +76,8 @@ namespace rtc { | |||||
} | } | ||||
void setAlarm(const tmElements_t &time) { | void setAlarm(const tmElements_t &time) { | ||||
#define CURRENT_LOGGER_FUNCTION "setAlarm" | |||||
hardware::i2c::powerOn(); | hardware::i2c::powerOn(); | ||||
WRITE_ALARM_1(time); | WRITE_ALARM_1(time); | ||||
@@ -78,7 +85,7 @@ namespace rtc { | |||||
RTC_A.control(DS3231_A1_INT_ENABLE, DS3231_ON); //Alarm 1 ON | RTC_A.control(DS3231_A1_INT_ENABLE, DS3231_ON); //Alarm 1 ON | ||||
RTC_A.control(DS3231_INT_ENABLE, DS3231_ON); //INTCN ON | RTC_A.control(DS3231_INT_ENABLE, DS3231_ON); //INTCN ON | ||||
NOTICE_FORMAT("setAlarm", "Next alarm : %d:%d:%d", time.hour, time.minute, time.second); | |||||
NOTICE_FORMAT("Next alarm : %d:%d:%d", time.hour, time.minute, time.second); | |||||
hardware::i2c::powerOff(); | hardware::i2c::powerOff(); | ||||
} | } | ||||
@@ -6,10 +6,10 @@ | |||||
#include "Positions.h" | #include "Positions.h" | ||||
#include "Logging.h" | #include "Logging.h" | ||||
#define LOGGER_NAME "Positions::backup::sd" | |||||
#if BACKUP_ENABLE_SDCARD | #if BACKUP_ENABLE_SDCARD | ||||
namespace positions { | namespace positions { | ||||
#define CURRENT_LOGGER "positions::backup::sd" | |||||
namespace backup { | namespace backup { | ||||
namespace sd { | namespace sd { | ||||
@@ -60,7 +60,8 @@ namespace positions { | |||||
} | } | ||||
void appendPosition(File &file, SdPositionConfig_t &sdConfig, PositionEntry &entry) { | void appendPosition(File &file, SdPositionConfig_t &sdConfig, PositionEntry &entry) { | ||||
VERBOSE("appendPosition"); | |||||
#define CURRENT_LOGGER_FUNCTION "appendPosition" | |||||
VERBOSE; | |||||
const char fieldTerminator = ','; | const char fieldTerminator = ','; | ||||
@@ -75,7 +76,8 @@ namespace positions { | |||||
} | } | ||||
void appendPositions(SdPositionConfig_t &sdConfig) { | void appendPositions(SdPositionConfig_t &sdConfig) { | ||||
VERBOSE("appendPositions"); | |||||
#define CURRENT_LOGGER_FUNCTION "appendPositions" | |||||
VERBOSE; | |||||
uint16_t currentEntryIndex = sdConfig.lastSavedEntry + 1; | uint16_t currentEntryIndex = sdConfig.lastSavedEntry + 1; | ||||
PositionEntry currentEntry; | PositionEntry currentEntry; | ||||
@@ -100,10 +102,11 @@ namespace positions { | |||||
} | } | ||||
void SdPositionsBackup::backup(bool force) { | void SdPositionsBackup::backup(bool force) { | ||||
VERBOSE("backup"); | |||||
#define CURRENT_LOGGER_FUNCTION "backup" | |||||
VERBOSE; | |||||
if (!hardware::sdcard::available) { | if (!hardware::sdcard::available) { | ||||
VERBOSE_MSG("backup", "not available"); | |||||
VERBOSE_MSG("not available"); | |||||
return; | return; | ||||
} | } | ||||
@@ -2,10 +2,11 @@ | |||||
#include "SdCard.h" | #include "SdCard.h" | ||||
#include "Logging.h" | #include "Logging.h" | ||||
#define LOGGER_NAME "Config::backup::sd" | |||||
#if BACKUP_ENABLE_SDCARD | #if BACKUP_ENABLE_SDCARD | ||||
namespace config { | namespace config { | ||||
#define CURRENT_LOGGER "config::backup::sd" | |||||
namespace backup { | namespace backup { | ||||
namespace sd { | namespace sd { | ||||
@@ -24,14 +25,18 @@ namespace config { | |||||
} | } | ||||
void read() { | void read() { | ||||
VERBOSE("read"); | |||||
#define CURRENT_LOGGER_FUNCTION "read" | |||||
VERBOSE; | |||||
ensureOpened(); | ensureOpened(); | ||||
configFile.read((void*)&value, sizeof(value)); | configFile.read((void*)&value, sizeof(value)); | ||||
if (value.seed != POSITIONS_CONFIG_SEED) reset(); | if (value.seed != POSITIONS_CONFIG_SEED) reset(); | ||||
} | } | ||||
void write() { | void write() { | ||||
VERBOSE("write"); | |||||
#define CURRENT_LOGGER_FUNCTION "write" | |||||
VERBOSE; | |||||
ensureOpened(); | ensureOpened(); | ||||
configFile.write((void*)&value, sizeof(value)); | configFile.write((void*)&value, sizeof(value)); | ||||
} | } | ||||
@@ -50,7 +55,9 @@ namespace config { | |||||
} | } | ||||
void reset() { | void reset() { | ||||
VERBOSE("reset"); | |||||
#define CURRENT_LOGGER_FUNCTION "reset" | |||||
VERBOSE; | |||||
SdPositionConfig_t config = { | SdPositionConfig_t config = { | ||||
POSITIONS_CONFIG_SEED, | POSITIONS_CONFIG_SEED, | ||||
POSITIONS_CONFIG_DEFAULT_SAVE_THRESHOLD, | POSITIONS_CONFIG_DEFAULT_SAVE_THRESHOLD, | ||||