From 6a2a305cd1aa0ab5c44fe5cc02ad3358e1114eec Mon Sep 17 00:00:00 2001 From: Bertrand Lemasle Date: Sat, 17 Mar 2018 23:03:30 +1300 Subject: [PATCH] Adjusted log levels --- GpsTracker/Core.cpp | 1 + GpsTracker/Debug.cpp | 6 +++--- GpsTracker/Debug.h | 4 +--- GpsTracker/GpsTracker.ino | 2 +- GpsTracker/Log.cpp | 27 --------------------------- GpsTracker/Logging.cpp | 18 ++++++++++++++++++ GpsTracker/{Log.h => Logging.h} | 12 +++++++++--- GpsTracker/MainUnit.cpp | 4 ++-- GpsTracker/Positions.cpp | 6 ++++-- GpsTracker/Rtc.cpp | 2 +- 10 files changed, 40 insertions(+), 42 deletions(-) delete mode 100644 GpsTracker/Log.cpp create mode 100644 GpsTracker/Logging.cpp rename GpsTracker/{Log.h => Logging.h} (81%) diff --git a/GpsTracker/Core.cpp b/GpsTracker/Core.cpp index ce756f3..492b278 100644 --- a/GpsTracker/Core.cpp +++ b/GpsTracker/Core.cpp @@ -34,6 +34,7 @@ namespace core { else increaseInARow = 0; sleepTime = result; + NOTICE_FORMAT("updateSleepTime", "%dkmh => %d seconds", velocity, sleepTime); } uint16_t computeSleepTime(uint8_t velocity) { diff --git a/GpsTracker/Debug.cpp b/GpsTracker/Debug.cpp index 8df8fd6..a095885 100644 --- a/GpsTracker/Debug.cpp +++ b/GpsTracker/Debug.cpp @@ -9,7 +9,7 @@ const char FAKE_GPS_ENTRY[] PROGMEM = "1,1,20170924184842.000,49.454862,1.144537,71.900,67.99,172.6,1,,1.3,2.2,1.8,,11,7,,,37,,"; -MENU_ENTRY(HEADER, "-- Debug Menu --"); +MENU_ENTRY(HEADER, "-- Menu --"); MENU_ENTRY(SEPARATOR, "----"); MENU_ENTRY(RUN, "[R] Run"); @@ -244,8 +244,8 @@ namespace debug { uint16_t lastEntryIndex = config::main::value.lastEntry; PositionEntry lastEntry; - positions::get(lastEntryIndex, lastEntry); - details::displayPosition(lastEntry); + if(positions::get(lastEntryIndex, lastEntry)) details::displayPosition(lastEntry); + else Log.notice(F("No position recorded\n")); } void addLastPositionToEeprom() { diff --git a/GpsTracker/Debug.h b/GpsTracker/Debug.h index e0ca6f7..71644bc 100644 --- a/GpsTracker/Debug.h +++ b/GpsTracker/Debug.h @@ -2,7 +2,7 @@ #include #include "Config.h" -#include "Log.h" +#include "Logging.h" #include "Core.h" @@ -10,8 +10,6 @@ #include "Gps.h" #include "Rtc.h" -#define DEBUG_SERIAL_SPEED 115200 - namespace debug { enum class GPSTRACKER_DEBUG_COMMAND : uint8_t { diff --git a/GpsTracker/GpsTracker.ino b/GpsTracker/GpsTracker.ino index eecf0ba..6d2cde8 100644 --- a/GpsTracker/GpsTracker.ino +++ b/GpsTracker/GpsTracker.ino @@ -10,7 +10,7 @@ bool bypassMenu = false; void setup() { - log::setup(); + logging::setup(); config::main::setup(); rtc::setup(); diff --git a/GpsTracker/Log.cpp b/GpsTracker/Log.cpp deleted file mode 100644 index 57a66f2..0000000 --- a/GpsTracker/Log.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "Log.h" - -namespace log { - - namespace details { - - void waitForSerial() { - while (!Serial); - Serial.begin(DEBUG_SERIAL_SPEED); - } - - } - void setup() { -#if _DEBUG - details::waitForSerial(); - Log.begin(LOG_LEVEL_VERBOSE, &Serial); -#else - if (Serial) { - Serial.begin(DEBUG_SERIAL_SPEED); - Log.begin(LOG_LEVEL_NOTICE, &Serial); - } -#endif - - if (Serial) Serial.println(F("=============================")); - } - -} \ No newline at end of file diff --git a/GpsTracker/Logging.cpp b/GpsTracker/Logging.cpp new file mode 100644 index 0000000..0c1d2d9 --- /dev/null +++ b/GpsTracker/Logging.cpp @@ -0,0 +1,18 @@ +#include "Logging.h" + +namespace logging { + + void setup() { +#if _DEBUG + while (!Serial); +#endif + + if (Serial) { + Serial.begin(LOG_SERIAL_SPEED); + Serial.println(F("=============================")); + + Log.begin(LOG_LEVEL, &Serial); + } + } + +} \ No newline at end of file diff --git a/GpsTracker/Log.h b/GpsTracker/Logging.h similarity index 81% rename from GpsTracker/Log.h rename to GpsTracker/Logging.h index 572a4ca..c8460a3 100644 --- a/GpsTracker/Log.h +++ b/GpsTracker/Logging.h @@ -1,9 +1,15 @@ #pragma once +#include "Config.h" -#define DISABLE_LOGGING 1 +//#define DISABLE_LOGGING 1 #include -#include "Config.h" +#define LOG_SERIAL_SPEED 115200 +#if _DEBUG +#define LOG_LEVEL LOG_LEVEL_VERBOSE +#else +#define LOG_LEVEL LOG_LEVEL_NOTICE +#endif #define LOG(level, f) Log.level(F("[" LOGGER_NAME "::" f "]\n")) #define LOG_MSG(level, f, msg) Log.level(F("[" LOGGER_NAME "::" f "] " msg "\n")) @@ -24,6 +30,6 @@ #define NOTICE_FORMAT(f, msg, ...) LOG_FORMAT(notice, f, msg, __VA_ARGS__) -namespace log { +namespace logging { void setup(); } \ No newline at end of file diff --git a/GpsTracker/MainUnit.cpp b/GpsTracker/MainUnit.cpp index b665c04..80b3448 100644 --- a/GpsTracker/MainUnit.cpp +++ b/GpsTracker/MainUnit.cpp @@ -36,7 +36,7 @@ namespace mainunit { } void sleep(period_t period) { - NOTICE_FORMAT("sleep", "Sleeping for period : %d", period); + NOTICE_FORMAT("sleep", "Period : %d", period); details::prepareSleep(); LowPower.powerDown(period, ADC_OFF, BOD_OFF); details::wokeUp(); @@ -44,7 +44,7 @@ namespace mainunit { } void deepSleep(uint16_t seconds) { - NOTICE_FORMAT("deepSleep", "Deep sleeping for %d seconds", seconds); + NOTICE_FORMAT("deepSleep", "%d seconds", seconds); interruptIn(seconds); details::prepareSleep(); LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF); diff --git a/GpsTracker/Positions.cpp b/GpsTracker/Positions.cpp index 4251cbe..569b078 100644 --- a/GpsTracker/Positions.cpp +++ b/GpsTracker/Positions.cpp @@ -53,7 +53,7 @@ namespace positions { } bool acquire(PositionEntryMetadata &metadata) { - VERBOSE("acquire"); + NOTICE("acquire"); timestamp_t before; @@ -63,6 +63,8 @@ namespace positions { SIM808ChargingStatus battery = hardware::sim808::device.getChargingState(); gps::powerOff(); + NOTICE_FORMAT("acquire", "status : %d", gpsStatus); + if (gpsStatus < SIM808_GPS_STATUS::FIX) return false; uint16_t timeToFix = rtc::getTime() - before; @@ -98,7 +100,7 @@ namespace positions { hardware::i2c::powerOn(); hardware::i2c::eeprom.writeBlock(entryAddress, entry); - VERBOSE_FORMAT("appendLast", "Written to EEPROM @ %X : [%d%% @ %dmV] [%f°C] [TTF : %d, Status : %d, Position : %s]", entryAddress, entry.metadata.batteryLevel, entry.metadata.batteryVoltage, entry.metadata.temperature, entry.metadata.timeToFix, entry.metadata.status, entry.position); + NOTICE_FORMAT("appendLast", "Saved @ %X : [%d%% @ %dmV] [%f°C] [TTF : %d, Status : %d, Position : %s]", entryAddress, entry.metadata.batteryLevel, entry.metadata.batteryVoltage, entry.metadata.temperature, entry.metadata.timeToFix, entry.metadata.status, entry.position); config->lastEntry++; if (config->lastEntry > details::maxEntryIndex) config->lastEntry = 0; diff --git a/GpsTracker/Rtc.cpp b/GpsTracker/Rtc.cpp index b971178..019d577 100644 --- a/GpsTracker/Rtc.cpp +++ b/GpsTracker/Rtc.cpp @@ -71,7 +71,7 @@ namespace rtc { RTC.control(DS3231_A1_INT_ENABLE, DS3231_ON); //Alarm 1 ON RTC.control(DS3231_INT_ENABLE, DS3231_ON); //INTCN ON - NOTICE_FORMAT("setAlarm", "Next alarm : %d:%d:%d", time.Hour, time.Minute, time.Second); + VERBOSE_FORMAT("setAlarm", "Next alarm : %d:%d:%d", time.Hour, time.Minute, time.Second); hardware::i2c::powerOff(); }