diff --git a/src/Alerts.cpp b/src/Alerts.cpp index 65a4049..da53a73 100644 --- a/src/Alerts.cpp +++ b/src/Alerts.cpp @@ -5,9 +5,8 @@ #include "Rtc.h" #include "Logging.h" -#define LOGGER_NAME "Alerts" - namespace alerts { + #define CURRENT_LOGGER "alerts" uint8_t getTriggered(PositionEntryMetadata &metadata) { config_t* config = &config::main::value; diff --git a/src/Config.cpp b/src/Config.cpp index 3338e9e..dfac240 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -2,9 +2,11 @@ #include "Hardware.h" #include "Logging.h" -#define LOGGER_NAME "Config" namespace config { + #define CURRENT_LOGGER "config" + const char VERSION_STRING[] PROGMEM = VERSION; + namespace main { config_t value; @@ -12,16 +14,16 @@ namespace config { namespace details { void read() { - VERBOSE("read"); + #define CURRENT_LOGGER_FUNCTION "read" + NOTICE; hardware::i2c::powerOn(); hardware::i2c::eeprom.readBlock(CONFIG_ADDR, value); + print(); if (CONFIG_SEED != value.seed) reset(); //todo : reset network if seed for network is not right 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); #if BACKUP_ENABLE_NETWORK - NOTICE_FORMAT("read", "%d, %d, %s, %s", value.network.saveThreshold, value.network.lastSavedEntry, value.network.apn, value.network.url); //networkConfig_t c = { // POSITIONS_CONFIG_NET_DEFAULT_SAVE_THRESHOLD, // 0xFFFF, @@ -30,7 +32,7 @@ namespace config { //}; //value.network = c; #endif - /*strcpy_P(value.version, PSTR(VERSION)); + /*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; @@ -39,10 +41,10 @@ namespace config { } 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); -#if BACKUP_ENABLE_NETWORK - NOTICE_FORMAT("write", "%d, %d, %s, %s", value.network.saveThreshold, value.network.lastSavedEntry, value.network.apn, value.network.url); -#endif + #define CURRENT_LOGGER_FUNCTION "write" + NOTICE; + + print(); hardware::i2c::powerOn(); int written = hardware::i2c::eeprom.writeBlock(CONFIG_ADDR, value); hardware::i2c::powerOff(); @@ -52,8 +54,8 @@ namespace config { void setup() { details::read(); - if(strcasecmp_P(value.version, PSTR(VERSION))) { - strcpy_P(value.version, PSTR(VERSION)); + if(strcasecmp_P(value.version, VERSION_STRING)) { + strcpy_P(value.version, VERSION_STRING); details::write(); } } @@ -63,11 +65,12 @@ namespace config { } void reset() { - VERBOSE("reset"); + #define CURRENT_LOGGER_FUNCTION "reset" + NOTICE; config_t config = {}; config.seed = CONFIG_SEED; - strcpy_P(config.version, PSTR(VERSION)); + strcpy_P(config.version, VERSION_STRING); config.firstEntry = config.lastEntry = 0xFFFF; config.alertBatteryLevel1 = CONFIG_DEFAULT_BATTERY_ALERT_LEVEL1; config.alertBatteryLevel2 = CONFIG_DEFAULT_BATTERY_ALERT_LEVEL2; @@ -86,5 +89,14 @@ namespace config { save(); } + void print() { + #define CURRENT_LOGGER_FUNCTION "print" + + 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 + NOTICE_FORMAT("%d, %d, %s, %s", value.network.saveThreshold, value.network.lastSavedEntry, value.network.apn, value.network.url); +#endif + } + } } \ No newline at end of file diff --git a/src/Config.h b/src/Config.h index e165fc2..85ea75d 100644 --- a/src/Config.h +++ b/src/Config.h @@ -29,5 +29,7 @@ namespace config { void save(); void reset(); + + void print(); } } \ No newline at end of file diff --git a/src/Core.cpp b/src/Core.cpp index f67898f..e9c3304 100644 --- a/src/Core.cpp +++ b/src/Core.cpp @@ -8,13 +8,13 @@ #include "Alerts.h" #include "Logging.h" -#define LOGGER_NAME "Core" #define SMS_BUFFER_SIZE 140 #define NO_ALERTS_NOTIFIED 0 using namespace utils; namespace core { + #define CURRENT_LOGGER "core" uint16_t sleepTime = SLEEP_DEFAULT_TIME_SECONDS; uint8_t stoppedInARow = SLEEP_DEFAULT_STOPPED_THRESHOLD - 1; @@ -39,7 +39,11 @@ namespace core { bool acquired = false; PositionEntryMetadata metadata; - if(movingState >= TRACKER_MOVING_STATE::STOPPED) positions::prepareBackup(); + if(movingState >= TRACKER_MOVING_STATE::ABOUT_TO_STOP) { + //forcing when the tracker is about to stop (which should result in STOPPED a few lines below) + positions::prepareBackup(movingState == TRACKER_MOVING_STATE::ABOUT_TO_STOP); + } + acquired = positions::acquire(metadata); if (acquired) { @@ -53,7 +57,7 @@ namespace core { alerts::add(notifyFailures(metadata)); if(movingState >= TRACKER_MOVING_STATE::STOPPED) { - positions::doBackup(movingState == TRACKER_MOVING_STATE::STOPPED); //do not force on STATIC + positions::doBackup(movingState == TRACKER_MOVING_STATE::STOPPED); //forcing at the moment the tracker stop } if (acquired) updateRtcTime(); @@ -61,20 +65,22 @@ namespace core { } uint8_t notifyFailures(PositionEntryMetadata &metadata) { - SIM808RegistrationStatus networkStatus; + #define CURRENT_LOGGER_FUNCTION "notifyFailures" + + SIM808_NETWORK_REGISTRATION_STATE networkStatus; char buffer[SMS_BUFFER_SIZE]; const __FlashStringHelper * backupFailureString = F(" Backup battery failure ?"); bool notified = false; uint8_t triggered = alerts::getTriggered(metadata); - if (!triggered) return NO_ALERTS_NOTIFIED; + NOTICE_FORMAT("triggered : %B", triggered); - NOTICE_FORMAT("notifyFailures", "triggered : %B", triggered); + if (!triggered) return NO_ALERTS_NOTIFIED; network::powerOn(); networkStatus = network::waitForRegistered(NETWORK_DEFAULT_TOTAL_TIMEOUT_MS); - if (network::isAvailable(networkStatus.stat)) { + if (network::isAvailable(networkStatus)) { strncpy_P(buffer, PSTR("Alerts !"), SMS_BUFFER_SIZE); if (bitRead(triggered, ALERT_BATTERY_LEVEL_1) || bitRead(triggered, ALERT_BATTERY_LEVEL_2)) { details::appendToSmsBuffer(buffer, PSTR("\n- Battery at %d%%."), metadata.batteryLevel); @@ -89,12 +95,12 @@ namespace core { } #if ALERTS_ON_SERIAL - NOTICE_FORMAT("notifyFailure", "%s", buffer); + NOTICE_FORMAT("%s", buffer); notified = true; #else notified = network::sendSms(buffer); #endif - if (!notified) NOTICE_MSG("notifyFailure", "SMS not sent !"); + if (!notified) NOTICE_MSG("SMS not sent !"); } network::powerOff(); @@ -108,6 +114,8 @@ namespace core { } TRACKER_MOVING_STATE updateSleepTime() { + #define CURRENT_LOGGER_FUNCTION "updateSleepTime" + TRACKER_MOVING_STATE state = TRACKER_MOVING_STATE::MOVING; uint8_t velocity = gps::getVelocity(); @@ -120,18 +128,22 @@ namespace core { if (stoppedInARow < SLEEP_DEFAULT_STOPPED_THRESHOLD) { sleepTime = SLEEP_DEFAULT_PAUSING_TIME_SECONDS; - state = TRACKER_MOVING_STATE::PAUSED; + state = stoppedInARow == SLEEP_DEFAULT_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 state = TRACKER_MOVING_STATE::STATIC; } else stoppedInARow = 0; - NOTICE_FORMAT("updateSleepTime", "%dkmh => %d seconds", velocity, sleepTime); + NOTICE_FORMAT("stop %d, state %d, %dkmh => %ds", stoppedInARow, state, velocity, sleepTime); return state; } uint16_t mapSleepTime(uint8_t velocity) { + #define CURRENT_LOGGER_FUNCTION "mapSleepTime" + uint16_t result; uint16_t currentTime = 0xFFFF; @@ -154,7 +166,7 @@ namespace core { } - VERBOSE_FORMAT("mapSleepTime", "%d,%d", velocity, result); + VERBOSE_FORMAT("%d,%d", velocity, result); return result; } } \ No newline at end of file diff --git a/src/Core.h b/src/Core.h index 9f9beea..54542c2 100644 --- a/src/Core.h +++ b/src/Core.h @@ -6,8 +6,9 @@ enum class TRACKER_MOVING_STATE : uint8_t { MOVING = 0, PAUSED = 1, - STOPPED = 2, - STATIC = 3 + ABOUT_TO_STOP = 2, + STOPPED = 3, + STATIC = 4 }; namespace core { diff --git a/src/Debug.cpp b/src/Debug.cpp index 9254119..5b3e617 100644 --- a/src/Debug.cpp +++ b/src/Debug.cpp @@ -9,8 +9,6 @@ #include "Alerts.h" #include "Logging.h" -#define LOGGER_NAME "Debug" - #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,,"; @@ -116,21 +114,11 @@ static const PositionEntryMetadata fakeMetadata PROGMEM = { using namespace utils; namespace debug { - - namespace details { - inline void displayPosition(PositionEntry entry) { - Log.notice(F("%d,%d,%d,%d,%d,%s"), - entry.metadata.batteryLevel, - entry.metadata.batteryVoltage, - entry.metadata.temperature, - static_cast(entry.metadata.status), - entry.metadata.timeToFix, - entry.position); - } - } + #define CURRENT_LOGGER "debug" 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) { @@ -146,6 +134,8 @@ namespace debug { } GPSTRACKER_DEBUG_COMMAND menu(uint16_t timeout) { + #define CURRENT_LOGGER_FUNCTION "menu" + GPSTRACKER_DEBUG_COMMAND command; size_t menuSize = flash::getArraySize(MENU_ENTRIES); @@ -159,7 +149,7 @@ namespace debug { delay(MENU_INTERMEDIATE_TIMEOUT); timeout -= MENU_INTERMEDIATE_TIMEOUT; if (timeout <= 0) { - NOTICE_MSG("menu", "Timeout expired."); + NOTICE_MSG("Timeout expired."); return GPSTRACKER_DEBUG_COMMAND::RUN; } } @@ -172,32 +162,36 @@ namespace debug { } void getAndDisplayGpsPosition() { + #define CURRENT_LOGGER_FUNCTION "getAndDisplayGpsPosition" 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() { + #define CURRENT_LOGGER_FUNCTION "setFakeGpsPosition" 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() { + #define CURRENT_LOGGER_FUNCTION "getAndDisplayBattery" hardware::sim808::powerOn(); SIM808ChargingStatus status = hardware::sim808::device.getChargingState(); 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() { + #define CURRENT_LOGGER_FUNCTION "getAndDisplayRtcTime" tmElements_t 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() { @@ -207,6 +201,8 @@ namespace debug { } void getAndDisplaySleepTimes() { + #define CURRENT_LOGGER_FUNCTION "getAndDisplaySleepTimes" + size_t arraySize = flash::getArraySize(config::defaultSleepTimings); sleepTimings_t maxSpeedTiming; utils::flash::read(&config::defaultSleepTimings[arraySize - 1], maxSpeedTiming); @@ -215,7 +211,7 @@ namespace debug { core::mapSleepTime(i); } - NOTICE_MSG("getAndDisplaySleepTimes", "Done"); + NOTICE_MSG("Done"); } void getAndDisplayEepromConfig() { @@ -223,6 +219,8 @@ namespace debug { } void getAndDisplayEepromContent() { + #define CURRENT_LOGGER_FUNCTION "getAndDisplayEepromContent" + char buffer[128]; hardware::i2c::powerOn(); @@ -235,29 +233,21 @@ namespace debug { Serial.println(); hardware::i2c::powerOff(); - NOTICE_MSG("getAndDisplayEepromContent", "Done"); + NOTICE_MSG("Done"); } - void getAndDisplayEepromPositions() { - uint16_t currentEntryIndex = config::main::value.firstEntry; + void getAndDisplayEepromPositions(uint16_t firstIndex) { + uint16_t currentEntryIndex = firstIndex; PositionEntry currentEntry; hardware::i2c::powerOn(); do { if (!positions::get(currentEntryIndex, currentEntry)) break; - details::displayPosition(currentEntry); - } while (positions::moveNext(currentEntryIndex)); + positions::print(currentEntryIndex, currentEntry); + } while(positions::moveNext(currentEntryIndex)); hardware::i2c::powerOff(); } - void getAndDisplayEepromLastPosition() { - uint16_t lastEntryIndex = config::main::value.lastEntry; - PositionEntry lastEntry; - - if(positions::get(lastEntryIndex, lastEntry)) details::displayPosition(lastEntry); - else Log.notice(F("No position recorded\n")); - } - void addLastPositionToEeprom() { hardware::sim808::powerOn(); SIM808ChargingStatus status = hardware::sim808::device.getChargingState(); @@ -275,13 +265,15 @@ namespace debug { } void notifyFailures() { + #define CURRENT_LOGGER_FUNCTION "notifyFailures" + PositionEntryMetadata metadata = {}; flash::read(&fakeMetadata, metadata); metadata.batteryLevel = 1; metadata.temperature = ALERT_SUSPICIOUS_RTC_TEMPERATURE; uint8_t alerts = core::notifyFailures(metadata); - NOTICE_FORMAT("notifyFailures", "result : %B", alerts); + NOTICE_FORMAT("result : %B", alerts); alerts::add(alerts); } diff --git a/src/Debug.h b/src/Debug.h index dbe40f4..0fd191f 100644 --- a/src/Debug.h +++ b/src/Debug.h @@ -44,8 +44,7 @@ namespace debug { void getAndDisplayEepromConfig(); void getAndDisplayEepromContent(); - void getAndDisplayEepromPositions(); - void getAndDisplayEepromLastPosition(); + void getAndDisplayEepromPositions(uint16_t firstIndex); void addLastPositionToEeprom(); void notifyFailures(); diff --git a/src/Gps.cpp b/src/Gps.cpp index 3529cf1..c53dde8 100644 --- a/src/Gps.cpp +++ b/src/Gps.cpp @@ -5,8 +5,6 @@ #include "MainUnit.h" #include "Logging.h" -#define LOGGER_NAME "Gps" - #define TIME_YEAR_OFFSET 0 #define TIME_MONTH_OFFSET 4 #define TIME_DAY_OFFSET 6 @@ -16,7 +14,9 @@ #define EARTH_RADIUS 6371 //kilometers + namespace gps { + #define CURRENT_LOGGER "gps" namespace details { uint16_t parseSubstring(char *buffer, char *start, uint8_t size) { @@ -25,6 +25,7 @@ namespace gps { } } + char lastPosition[GPS_POSITION_SIZE]; SIM808_GPS_STATUS lastStatus; @@ -32,13 +33,15 @@ namespace gps { float previousLng = 0; SIM808_GPS_STATUS acquireCurrentPosition(int32_t timeout) { + #define CURRENT_LOGGER_FUNCTION "acquireCurrentPosition" + SIM808_GPS_STATUS currentStatus = SIM808_GPS_STATUS::OFF; do { - currentStatus = hardware::sim808::device.getGpsStatus(lastPosition); + 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 - NOTICE_FORMAT("acquireCurrentPosition", "%d", currentStatus); + NOTICE_FORMAT("%d", currentStatus); mainunit::deepSleep(GPS_DEFAULT_INTERMEDIATE_TIMEOUT_MS / 1000); timeout -= GPS_DEFAULT_INTERMEDIATE_TIMEOUT_MS; } while (timeout > 1); @@ -47,7 +50,7 @@ namespace gps { lastStatus = currentStatus; } - NOTICE_FORMAT("acquireCurrentPosition", "%d", currentStatus); + NOTICE_FORMAT("%d", currentStatus); return currentStatus; } @@ -62,12 +65,14 @@ namespace gps { } float getDistanceFromPrevious() { + #define CURRENT_LOGGER_FUNCTION "getDistanceFromPrevious" + 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::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); lng1 = radians(previousLng); @@ -85,25 +90,29 @@ namespace gps { a = EARTH_RADIUS * (2 * atan2(sqrt(a), sqrt(1 - a))); //kilometers - NOTICE_FORMAT("distanceFromPrevious", "%fkm", a); + NOTICE_FORMAT("%Fkm", a); return a; } uint8_t getVelocity() { - uint8_t velocity; + #define CURRENT_LOGGER_FUNCTION "getVelocity" + + int16_t velocity; if (!hardware::sim808::device.getGpsField(lastPosition, SIM808_GPS_FIELD::SPEED, &velocity)) velocity = 0; - VERBOSE_FORMAT("getVelocity", "%d", velocity); + VERBOSE_FORMAT("%d", velocity); return velocity; } void getTime(tmElements_t &time) { + #define CURRENT_LOGGER_FUNCTION "getTime" + char *timeStr; char buffer[5]; 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.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.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); } } \ No newline at end of file diff --git a/src/Gps.h b/src/Gps.h index aac10d2..7fbd585 100644 --- a/src/Gps.h +++ b/src/Gps.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include "Hardware.h" #include "Time2.h" diff --git a/src/GpsTracker.ino b/src/GpsTracker.ino index 28332fb..64f0714 100644 --- a/src/GpsTracker.ino +++ b/src/GpsTracker.ino @@ -10,7 +10,7 @@ #include "Positions.h" #include "Logging.h" -#define LOGGER_NAME "GpsTracker" +#define CURRENT_LOGGER "GpsTracker" bool bypassMenu = false; uint16_t menuTimeout = MENU_TIMEOUT; @@ -26,6 +26,7 @@ void setup() { } void loop() { + #define CURRENT_LOGGER_FUNCTION "loop" debug::GPSTRACKER_DEBUG_COMMAND command = debug::GPSTRACKER_DEBUG_COMMAND::RUN; if (Serial && !bypassMenu) command = debug::menu(menuTimeout); @@ -74,10 +75,10 @@ void loop() { debug::getAndDisplayEepromContent(); break; case debug::GPSTRACKER_DEBUG_COMMAND::EEPROM_GET_ENTRIES: - debug::getAndDisplayEepromPositions(); + debug::getAndDisplayEepromPositions(config::main::value.firstEntry); break; case debug::GPSTRACKER_DEBUG_COMMAND::EEPROM_GET_LAST_ENTRY: - debug::getAndDisplayEepromLastPosition(); + debug::getAndDisplayEepromPositions(config::main::value.lastEntry); break; case debug::GPSTRACKER_DEBUG_COMMAND::EEPROM_ADD_ENTRY: debug::addLastPositionToEeprom(); @@ -95,6 +96,6 @@ void loop() { mainunit::deepSleep(10); break; default: - NOTICE_MSG("loop", "Unsupported"); + NOTICE_MSG("Unsupported"); } } diff --git a/src/Hardware.cpp b/src/Hardware.cpp index 246cff2..7615e76 100644 --- a/src/Hardware.cpp +++ b/src/Hardware.cpp @@ -5,16 +5,18 @@ namespace hardware { -#define LOGGER_NAME "Hardware::sim808" - namespace sim808 { + #define CURRENT_LOGGER "hardware::sim808" + SIM_SERIAL_TYPE simSerial = SIM_SERIAL; SIM808 device = SIM808(SIM_RST, SIM_PWR, SIM_STATUS); uint8_t networkPoweredCount = 0; uint8_t gpsPoweredCount = 0; void powerOn() { - VERBOSE("powerOn"); + #define CURRENT_LOGGER_FUNCTION "powerOn" + VERBOSE; + bool poweredOn = device.powerOnOff(true); if (!poweredOn) return; @@ -23,7 +25,9 @@ namespace hardware { } void powerOff() { - VERBOSE("powerOff"); + #define CURRENT_LOGGER_FUNCTION "powerOff" + VERBOSE; + device.powerOnOff(false); networkPoweredCount = gpsPoweredCount = 0; } @@ -41,28 +45,35 @@ namespace hardware { } void setup() { - NOTICE("setup"); + #define CURRENT_LOGGER_FUNCTION "setup" + VERBOSE; + simSerial.begin(SIM808_BAUDRATE); device.begin(simSerial); powerOff(); //ensure powerOff on start } void gpsPowerOn() { + #define CURRENT_LOGGER_FUNCTION "gpsPowerOn" if(gpsPoweredCount) { gpsPoweredCount++; return; } - VERBOSE("gpsPowerOn"); + VERBOSE; powerOn(); if(!networkPoweredCount) { //SIM808 turns phone on by default but we don't need it for gps only device.setPhoneFunctionality(SIM808_PHONE_FUNCTIONALITY::MINIMUM); } - device.enableGps(); + + device.powerOnOffGps(true); + gpsPoweredCount = 1; } void gpsPowerOff() { + #define CURRENT_LOGGER_FUNCTION "gpsPowerOff" + if (!device.powered()) { networkPoweredCount = gpsPoweredCount = 0; //just to be sure counts == 0 return; @@ -73,23 +84,30 @@ namespace hardware { return; } - VERBOSE("gpsPowerOff"); - device.disableGps(); + VERBOSE; + device.powerOnOffGps(false); + gpsPoweredCount = 0; + powerOffIfUnused(); } void networkPowerOn() { + #define CURRENT_LOGGER_FUNCTION "networkPowerOn" + if(networkPoweredCount) { networkPoweredCount++; return; } - VERBOSE("networkPowerOn"); + VERBOSE; powerOn(); device.setPhoneFunctionality(SIM808_PHONE_FUNCTIONALITY::FULL); + networkPoweredCount = 1; } void networkPowerOff() { + #define CURRENT_LOGGER_FUNCTION "networkPowerOff" + if (!device.powered()) { networkPoweredCount = gpsPoweredCount = 0; //just to be sure counts == 0 return; @@ -100,27 +118,30 @@ namespace hardware { return; } - VERBOSE("networkPowerOff"); + VERBOSE; device.disableGprs(); device.setPhoneFunctionality(SIM808_PHONE_FUNCTIONALITY::MINIMUM); + networkPoweredCount = 0; + powerOffIfUnused(); } } -#define LOGGER_NAME "Hardware::i2c" - namespace i2c { + #define CURRENT_LOGGER "hardware::i2c" E24 eeprom = E24(E24_SIZE, E24_ADDRESS); uint8_t poweredCount = 0; void powerOn() { + #define CURRENT_LOGGER_FUNCTION "powerOn" + if(poweredCount) { poweredCount++; return; } - VERBOSE("powerOn"); + VERBOSE; digitalWrite(I2C_PWR, HIGH); pinMode(I2C_PWR, OUTPUT); @@ -129,12 +150,14 @@ namespace hardware { } void powerOff(bool forced = false) { + #define CURRENT_LOGGER_FUNCTION "powerOff" + if(poweredCount > 1 && !forced) { poweredCount--; return; } - VERBOSE("powerOff"); + VERBOSE; pinMode(I2C_PWR, INPUT); digitalWrite(I2C_PWR, LOW); diff --git a/src/Logging.h b/src/Logging.h index 6955805..dd855e3 100644 --- a/src/Logging.h +++ b/src/Logging.h @@ -2,33 +2,43 @@ //#define DISABLE_LOGGING 1 #include +#include //reusing flash string utilities #include "Config.h" #define LOG_SERIAL_SPEED 115200 #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 -#define LOG_LEVEL LOG_LEVEL_NOTICE + #define LOG_LEVEL LOG_LEVEL_NOTICE + #define LOG_LEVEL_NOTICE_ENABLED #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 -#define VERBOSE(f) -#define VERBOSE_MSG(f, msg) -#define VERBOSE_FORMAT(f, msg, ...) + #define VERBOSE + #define VERBOSE_MSG(msg) + #define VERBOSE_FORMAT(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__) - +#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 { void setup(); diff --git a/src/MainUnit.cpp b/src/MainUnit.cpp index 1455b8d..37b51df 100644 --- a/src/MainUnit.cpp +++ b/src/MainUnit.cpp @@ -4,11 +4,11 @@ #include "config/Pins.h" #include "Logging.h" -#define LOGGER_NAME "MainUnit" extern int __heap_start, *__brkval; namespace mainunit { + #define CURRENT_LOGGER "mainunit" namespace details { @@ -18,9 +18,11 @@ namespace mainunit { } void wokeUp() { + #define CURRENT_LOGGER_FUNCTION "wokeUp" + tmElements_t 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(); } @@ -39,7 +41,9 @@ namespace mainunit { } void deepSleep(uint16_t seconds) { - NOTICE_FORMAT("deepSleep", "%d seconds", seconds); + #define CURRENT_LOGGER_FUNCTION "deepSleep" + NOTICE_FORMAT("%ds", seconds); + interruptIn(seconds); details::prepareSleep(); LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF); diff --git a/src/Network.cpp b/src/Network.cpp index 0cab1c0..129c20b 100644 --- a/src/Network.cpp +++ b/src/Network.cpp @@ -5,12 +5,18 @@ #include "Config.h" #include "Logging.h" -#define LOGGER_NAME "Network" - namespace network { - + #define CURRENT_LOGGER "network" timestamp_t _poweredOnTime; + namespace details { + + void print(SIM808_NETWORK_REGISTRATION_STATE state, SIM808SignalQualityReport &report) { + #define CURRENT_LOGGER_FUNCTION "print" + NOTICE_FORMAT("%d, [%d %ddBm]", state, report.rssi, report.attenuation); + } + + } void powerOn() { hardware::sim808::networkPowerOn(); _poweredOnTime = rtc::getTime(); @@ -21,10 +27,11 @@ namespace network { _poweredOnTime = 0; } - __attribute__((__optimize__("O2"))) - SIM808RegistrationStatus waitForRegistered(uint32_t timeout, bool relativeToPowerOnTime = true) { + SIM808_NETWORK_REGISTRATION_STATE waitForRegistered(uint32_t timeout, bool relativeToPowerOnTime = true) { + #define CURRENT_LOGGER_FUNCTION "waitForRegistered" + NOTICE; - SIM808RegistrationStatus currentStatus; + SIM808_NETWORK_REGISTRATION_STATE currentStatus; SIM808SignalQualityReport report; uint8_t noReliableNetwork = 0; @@ -34,14 +41,13 @@ namespace network { report = hardware::sim808::device.getSignalQuality(); do { - if (isAvailable(currentStatus.stat)) break; - - NOTICE_FORMAT("waitForRegistered", "%d, [%d %ddBm]", currentStatus.stat, report.rssi, report.attenuation); + if (isAvailable(currentStatus)) break; + details::print(currentStatus, report); if (report.rssi < NETWORK_DEFAULT_NO_NETWORK_QUALITY_THRESHOLD) noReliableNetwork++; else noReliableNetwork = 0; 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 } @@ -52,7 +58,7 @@ namespace network { report = hardware::sim808::device.getSignalQuality(); } while (timeout > 1); - NOTICE_FORMAT("waitForRegistered", "%d, [%d %ddBm]", currentStatus.stat, report.rssi, report.attenuation); + details::print(currentStatus, report); return currentStatus; } @@ -69,9 +75,10 @@ namespace network { #endif bool sendSms(const char * msg) { + #define CURRENT_LOGGER_FUNCTION "sendSms" 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); } } \ No newline at end of file diff --git a/src/Network.h b/src/Network.h index 555e20e..061c3c4 100644 --- a/src/Network.h +++ b/src/Network.h @@ -8,7 +8,7 @@ namespace network { void powerOn(); void powerOff(); - SIM808RegistrationStatus waitForRegistered(uint32_t timeout, bool relativeToPowerOnTime = true); + SIM808_NETWORK_REGISTRATION_STATE waitForRegistered(uint32_t timeout, bool relativeToPowerOnTime = true); bool isAvailable(SIM808_NETWORK_REGISTRATION_STATE state); #if BACKUP_ENABLE_NETWORK bool enableGprs(); diff --git a/src/NetworkPositionsBackup.cpp b/src/NetworkPositionsBackup.cpp index 4b90370..b208fca 100644 --- a/src/NetworkPositionsBackup.cpp +++ b/src/NetworkPositionsBackup.cpp @@ -9,11 +9,12 @@ #include "Network.h" #include "Logging.h" -#define LOGGER_NAME "Positions::backup::network" - #define BUFFER_SIZE 170 + namespace positions { + #define CURRENT_LOGGER "Positions::backup::network" + namespace backup { namespace net { @@ -27,6 +28,8 @@ namespace positions { } bool NetworkPositionsBackup::appendPosition(PositionEntry &entry, int8_t signalAttenuation = 0) { + #define CURRENT_LOGGER_FUNCTION "appendPosition" + char buffer[BUFFER_SIZE]; if(signalAttenuation == 0) signalAttenuation = hardware::sim808::device.getSignalQuality().attenuation; @@ -40,7 +43,7 @@ namespace positions { entry.metadata.timeToFix, entry.position); - NOTICE_FORMAT("appendPosition", "Sending : %s", buffer); + NOTICE_FORMAT("Sending : %s", buffer); uint16_t responseCode = hardware::sim808::device.httpPost( config::main::value.network.url, F("text/gpstracker"), @@ -49,15 +52,16 @@ namespace positions { BUFFER_SIZE ); - NOTICE_FORMAT("appendPosition", "Response : %d", responseCode); + NOTICE_FORMAT("Response : %d", responseCode); return responseCode == POSITIONS_CONFIG_NET_DEFAULT_EXPECTED_RESPONSE; } - //__attribute__((__optimize__("O2"))) void NetworkPositionsBackup::appendPositions() { + #define CURRENT_LOGGER_FUNCTION "appendPositions" + uint16_t currentEntryIndex = config::main::value.network.lastSavedEntry + 1; PositionEntry currentEntry; - SIM808RegistrationStatus networkStatus; + SIM808_NETWORK_REGISTRATION_STATE networkStatus; //avoid edge case where if 0, whole set of positions will be sent again if (!positions::count(config::main::value.network.lastSavedEntry)) return; @@ -65,9 +69,10 @@ namespace positions { network::powerOn(); networkStatus = network::waitForRegistered(NETWORK_DEFAULT_TOTAL_TIMEOUT_MS); - if (!network::isAvailable(networkStatus.stat) || !network::enableGprs()) { + 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 - NOTICE_MSG("appendPositions", "network or gprs unavailable"); + NOTICE_MSG("network or gprs unavailable"); if (networkUnavailableInARow > POSITIONS_CONFIG_NET_DEFAULT_UNAVAILABLE_NETWORK_POSTPONE_THRESHOLD) { networkUnavailablePostpone++; @@ -95,20 +100,22 @@ namespace positions { void NetworkPositionsBackup::setup() {} - void NetworkPositionsBackup::prepare() { - NOTICE("prepare"); + void NetworkPositionsBackup::prepare(bool force) { + #define CURRENT_LOGGER_FUNCTION "prepare" + + if (!(force || isBackupNeeded(true))) return; - if (!isBackupNeeded(true)) return; + NOTICE; network::powerOn(); } void NetworkPositionsBackup::backup(bool force) { - NOTICE("backup"); + #define CURRENT_LOGGER_FUNCTION "backup" - if (force || isBackupNeeded(false)) { - appendPositions(); - } + if (!(force || isBackupNeeded(false))) return; + NOTICE; + appendPositions(); network::powerOff(); } } diff --git a/src/NetworkPositionsBackup.h b/src/NetworkPositionsBackup.h index 7247fe8..dd2912e 100644 --- a/src/NetworkPositionsBackup.h +++ b/src/NetworkPositionsBackup.h @@ -16,7 +16,7 @@ namespace positions { public: void setup(); - void prepare(); + void prepare(bool force); void backup(bool force); }; diff --git a/src/Positions.cpp b/src/Positions.cpp index d4c8440..67aca18 100644 --- a/src/Positions.cpp +++ b/src/Positions.cpp @@ -16,12 +16,12 @@ #include "NetworkPositionsBackup.h" #endif -#define LOGGER_NAME "Positions" - #define ENTRY_RESERVED_SIZE 128 #define ENTRIES_ADDR CONFIG_RESERVED_SIZE namespace positions { + #define CURRENT_LOGGER "positions" + #if BACKUPS_ENABLED > 1 backup::PositionsBackup **_backups; #elif BACKUPS_ENABLED == 1 @@ -73,7 +73,8 @@ namespace positions { } bool acquire(PositionEntryMetadata &metadata) { - NOTICE("acquire"); + #define CURRENT_LOGGER_FUNCTION "acquire" + NOTICE; timestamp_t before; @@ -85,7 +86,7 @@ namespace positions { gps::powerOff(); 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 = { battery.level, @@ -99,7 +100,8 @@ namespace positions { } void appendLast(const PositionEntryMetadata &metadata) { - VERBOSE("appendLast"); + #define CURRENT_LOGGER_FUNCTION "appendLast" + VERBOSE; uint16_t entryIndex; uint16_t entryAddress; @@ -110,18 +112,12 @@ namespace positions { entryIndex = config->lastEntry + 1; entryAddress = details::getEntryAddress(entryIndex); + print(entryIndex, entry); hardware::i2c::powerOn(); hardware::i2c::eeprom.writeBlock(entryAddress, entry); - NOTICE_FORMAT("appendLast", "Saved @ %X : %d,%d,%d,%d,%d,%s", - entryAddress, - entry.metadata.batteryLevel, - entry.metadata.batteryVoltage, - entry.metadata.temperature, - static_cast(entry.metadata.status), - entry.metadata.timeToFix, - entry.position); + NOTICE_MSG("Saved"); config->lastEntry++; if (config->lastEntry > details::maxEntryIndex) config->lastEntry = 0; @@ -133,26 +129,19 @@ namespace positions { } bool get(uint16_t index, PositionEntry &entry) { - VERBOSE("get"); + #define CURRENT_LOGGER_FUNCTION "get" + VERBOSE; uint16_t entryAddress = details::getEntryAddress(index); 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::eeprom.readBlock(entryAddress, entry); hardware::i2c::powerOff(); - NOTICE_FORMAT("get", "Read from EEPROM @ %X : %d,%d,%d,%d,%d,%s", - entryAddress, - entry.metadata.batteryLevel, - entry.metadata.batteryVoltage, - entry.metadata.temperature, - static_cast(entry.metadata.status), - entry.metadata.timeToFix, - entry.position); - + print(index, entry); return true; } @@ -174,13 +163,13 @@ namespace positions { return lastEntry - fromIndex; } - void prepareBackup() { + void prepareBackup(bool force) { #if BACKUPS_ENABLED > 1 for (int i = 0; i < BACKUPS_ENABLED; i++) { - _backups[i]->prepare(); + _backups[i]->prepare(force); } #elif BACKUPS_ENABLED == 1 - _backup->prepare(); + _backup->prepare(force); #endif } @@ -193,4 +182,18 @@ namespace positions { _backup->backup(force); #endif } + + void print(uint16_t index, PositionEntry &entry) { + #define CURRENT_LOGGER_FUNCTION "print" + + uint16_t address = details::getEntryAddress(index); + NOTICE_FORMAT("%X : %d,%d,%d,%d,%d,%s", + address, + entry.metadata.batteryLevel, + entry.metadata.batteryVoltage, + entry.metadata.temperature, + static_cast(entry.metadata.status), + entry.metadata.timeToFix, + entry.position); + } } \ No newline at end of file diff --git a/src/Positions.h b/src/Positions.h index bc552f5..a6313e3 100644 --- a/src/Positions.h +++ b/src/Positions.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #define POSITION_SIZE 115 @@ -28,6 +28,8 @@ namespace positions { bool moveNext(uint16_t &index); uint16_t count(uint16_t fromIndex); - void prepareBackup(); + void prepareBackup(bool force); void doBackup(bool force); + + void print(uint16_t index, PositionEntry &entry); } \ No newline at end of file diff --git a/src/PositionsBackup.h b/src/PositionsBackup.h index 340ec4b..f837f52 100644 --- a/src/PositionsBackup.h +++ b/src/PositionsBackup.h @@ -1,16 +1,16 @@ -#pragma once - -namespace positions { - namespace backup { - - class PositionsBackup { - public: - ~PositionsBackup(); - virtual void setup() = 0; - - virtual void prepare() = 0; - virtual void backup(bool force) = 0; - }; - - } +#pragma once + +namespace positions { + namespace backup { + + class PositionsBackup { + public: + ~PositionsBackup(); + virtual void setup() = 0; + + virtual void prepare(bool force) = 0; + virtual void backup(bool force) = 0; + }; + + } } \ No newline at end of file diff --git a/src/Rtc.cpp b/src/Rtc.cpp index 508411e..37298c5 100644 --- a/src/Rtc.cpp +++ b/src/Rtc.cpp @@ -5,15 +5,17 @@ #include -#define LOGGER_NAME "Rtc" using namespace utils; namespace rtc { + #define CURRENT_LOGGER "rtc" RTC_A_CLASS RTC_A; void setup() { - VERBOSE("setup"); + #define CURRENT_LOGGER_FUNCTION "setup" + VERBOSE; + hardware::i2c::powerOn(); RTC_A.control(DS3231_12H, DS3231_OFF); //24 hours clock RTC_A.control(DS3231_A1_INT_ENABLE, DS3231_OFF); //Alarm 1 OFF @@ -44,15 +46,18 @@ namespace rtc { } void getTime(tmElements_t &time) { + #define CURRENT_LOGGER_FUNCTION "getTime" + hardware::i2c::powerOn(); RTC_A.readTime(time); 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) { - 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(); RTC_A.writeTime(time); @@ -64,13 +69,17 @@ namespace rtc { tmElements_t currentTime; tmElements_t alarmTime; + hardware::i2c::powerOn(); getTime(currentTime); time::breakTime(time::makeTimestamp(currentTime) + seconds, alarmTime); setAlarm(alarmTime); + hardware::i2c::powerOff(); } void setAlarm(const tmElements_t &time) { + #define CURRENT_LOGGER_FUNCTION "setAlarm" + hardware::i2c::powerOn(); WRITE_ALARM_1(time); @@ -78,7 +87,9 @@ namespace rtc { RTC_A.control(DS3231_A1_INT_ENABLE, DS3231_ON); //Alarm 1 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); + tmElements_t alarmTime; + READ_ALARM_1(alarmTime); + NOTICE_FORMAT("Next alarm : %d:%d:%d", alarmTime.hour, alarmTime.minute, alarmTime.second); hardware::i2c::powerOff(); } diff --git a/src/RtcAbstraction.cpp b/src/RtcAbstraction.cpp index b3ece36..11cbe04 100644 --- a/src/RtcAbstraction.cpp +++ b/src/RtcAbstraction.cpp @@ -35,6 +35,7 @@ boolean MD_DS3231_Ext::writeTime(const tmElements_t &time) { boolean MD_DS3231_Ext::readAlarm1(almType_t &almType, tmElements_t &time) { almType = MD_DS3231::getAlarm1Type(); bool result = MD_DS3231::readAlarm1(); + unpack(time); return result; } diff --git a/src/RtcAbstraction.h b/src/RtcAbstraction.h index ff5a6e1..00ceeee 100644 --- a/src/RtcAbstraction.h +++ b/src/RtcAbstraction.h @@ -12,6 +12,7 @@ #define RTC_A_CLASS uDS3231 #define WRITE_ALARM_1(t) RTC_A.writeAlarm1(DS3231_ALM_HMS, t) + #define READ_ALARM_1(t) almType_t almDummy; RTC_A.readAlarm1(almDummy, t) #else #include @@ -39,4 +40,5 @@ #define RTC_A_CLASS MD_DS3231_Ext #define WRITE_ALARM_1(t) RTC_A.writeAlarm1(DS3231_ALM_HMS, t) + #define READ_ALARM_1(t) almType_t almDummy; RTC_A.readAlarm1(almDummy, t) #endif \ No newline at end of file diff --git a/src/SdPositionsBackup.cpp b/src/SdPositionsBackup.cpp index fceeee9..8dea093 100644 --- a/src/SdPositionsBackup.cpp +++ b/src/SdPositionsBackup.cpp @@ -6,10 +6,10 @@ #include "Positions.h" #include "Logging.h" -#define LOGGER_NAME "Positions::backup::sd" - #if BACKUP_ENABLE_SDCARD namespace positions { + #define CURRENT_LOGGER "positions::backup::sd" + namespace backup { namespace sd { @@ -60,7 +60,8 @@ namespace positions { } void appendPosition(File &file, SdPositionConfig_t &sdConfig, PositionEntry &entry) { - VERBOSE("appendPosition"); + #define CURRENT_LOGGER_FUNCTION "appendPosition" + VERBOSE; const char fieldTerminator = ','; @@ -75,7 +76,8 @@ namespace positions { } void appendPositions(SdPositionConfig_t &sdConfig) { - VERBOSE("appendPositions"); + #define CURRENT_LOGGER_FUNCTION "appendPositions" + VERBOSE; uint16_t currentEntryIndex = sdConfig.lastSavedEntry + 1; PositionEntry currentEntry; @@ -95,15 +97,16 @@ namespace positions { } } - void SdPositionsBackup::setup() { + void SdPositionsBackup::setup(bool force) { hardware::sdcard::setup(); } void SdPositionsBackup::backup(bool force) { - VERBOSE("backup"); + #define CURRENT_LOGGER_FUNCTION "backup" + VERBOSE; if (!hardware::sdcard::available) { - VERBOSE_MSG("backup", "not available"); + VERBOSE_MSG("not available"); return; } diff --git a/src/SdPositionsBackup.h b/src/SdPositionsBackup.h index 87aa92b..9eb071e 100644 --- a/src/SdPositionsBackup.h +++ b/src/SdPositionsBackup.h @@ -1,18 +1,18 @@ -#pragma once - -#include "PositionsBackup.h" - -namespace positions { - namespace backup { - namespace sd { - - class SdPositionsBackup : public PositionsBackup { - private: - public: - void setup(); - void backup(bool force); - }; - - } - } +#pragma once + +#include "PositionsBackup.h" + +namespace positions { + namespace backup { + namespace sd { + + class SdPositionsBackup : public PositionsBackup { + private: + public: + void setup(bool force); + void backup(bool force); + }; + + } + } } \ No newline at end of file diff --git a/src/SdPositionsConfig.cpp b/src/SdPositionsConfig.cpp index 29a0550..416bee3 100644 --- a/src/SdPositionsConfig.cpp +++ b/src/SdPositionsConfig.cpp @@ -2,10 +2,11 @@ #include "SdCard.h" #include "Logging.h" -#define LOGGER_NAME "Config::backup::sd" #if BACKUP_ENABLE_SDCARD namespace config { + #define CURRENT_LOGGER "config::backup::sd" + namespace backup { namespace sd { @@ -24,14 +25,18 @@ namespace config { } void read() { - VERBOSE("read"); + #define CURRENT_LOGGER_FUNCTION "read" + VERBOSE; + ensureOpened(); configFile.read((void*)&value, sizeof(value)); if (value.seed != POSITIONS_CONFIG_SEED) reset(); } void write() { - VERBOSE("write"); + #define CURRENT_LOGGER_FUNCTION "write" + VERBOSE; + ensureOpened(); configFile.write((void*)&value, sizeof(value)); } @@ -50,7 +55,9 @@ namespace config { } void reset() { - VERBOSE("reset"); + #define CURRENT_LOGGER_FUNCTION "reset" + VERBOSE; + SdPositionConfig_t config = { POSITIONS_CONFIG_SEED, POSITIONS_CONFIG_DEFAULT_SAVE_THRESHOLD, diff --git a/src/Time2.cpp b/src/Time2.cpp index a150e87..2012d00 100644 --- a/src/Time2.cpp +++ b/src/Time2.cpp @@ -16,8 +16,7 @@ namespace utils { namespace time { - __attribute__((__optimize__("O2"))) - timestamp_t makeTimestamp(const tmElements_t &time) { + timestamp_t makeTimestamp(const tmElements_t &time) { timestamp_t timestamp; timestamp += (time.day - 1) * SECS_PER_DAY; @@ -28,8 +27,7 @@ namespace utils { return timestamp; } - __attribute__((__optimize__("O2"))) - void breakTime(timestamp_t timestamp, tmElements_t &time) { + void breakTime(timestamp_t timestamp, tmElements_t &time) { time.year = 0; time.month = 0; diff --git a/src/config/System.h b/src/config/System.h index 331672c..c82e618 100644 --- a/src/config/System.h +++ b/src/config/System.h @@ -20,7 +20,7 @@ \def VERSION Version string, only used for indicative purpose */ -#define VERSION "1.30" +#define VERSION "1.40" /**