瀏覽代碼

Adjusted log levels

tags/v1.2.0
Bertrand Lemasle 7 年之前
父節點
當前提交
6a2a305cd1
共有 10 個檔案被更改,包括 40 行新增42 行删除
  1. +1
    -0
      GpsTracker/Core.cpp
  2. +3
    -3
      GpsTracker/Debug.cpp
  3. +1
    -3
      GpsTracker/Debug.h
  4. +1
    -1
      GpsTracker/GpsTracker.ino
  5. +0
    -27
      GpsTracker/Log.cpp
  6. +18
    -0
      GpsTracker/Logging.cpp
  7. +9
    -3
      GpsTracker/Logging.h
  8. +2
    -2
      GpsTracker/MainUnit.cpp
  9. +4
    -2
      GpsTracker/Positions.cpp
  10. +1
    -1
      GpsTracker/Rtc.cpp

+ 1
- 0
GpsTracker/Core.cpp 查看文件

@@ -34,6 +34,7 @@ namespace core {
else increaseInARow = 0; else increaseInARow = 0;


sleepTime = result; sleepTime = result;
NOTICE_FORMAT("updateSleepTime", "%dkmh => %d seconds", velocity, sleepTime);
} }


uint16_t computeSleepTime(uint8_t velocity) { uint16_t computeSleepTime(uint8_t velocity) {


+ 3
- 3
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,,"; 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(SEPARATOR, "----");


MENU_ENTRY(RUN, "[R] Run"); MENU_ENTRY(RUN, "[R] Run");
@@ -244,8 +244,8 @@ namespace debug {
uint16_t lastEntryIndex = config::main::value.lastEntry; uint16_t lastEntryIndex = config::main::value.lastEntry;
PositionEntry 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() { void addLastPositionToEeprom() {


+ 1
- 3
GpsTracker/Debug.h 查看文件

@@ -2,7 +2,7 @@


#include <Arduino.h> #include <Arduino.h>
#include "Config.h" #include "Config.h"
#include "Log.h"
#include "Logging.h"


#include "Core.h" #include "Core.h"


@@ -10,8 +10,6 @@
#include "Gps.h" #include "Gps.h"
#include "Rtc.h" #include "Rtc.h"


#define DEBUG_SERIAL_SPEED 115200

namespace debug { namespace debug {


enum class GPSTRACKER_DEBUG_COMMAND : uint8_t { enum class GPSTRACKER_DEBUG_COMMAND : uint8_t {


+ 1
- 1
GpsTracker/GpsTracker.ino 查看文件

@@ -10,7 +10,7 @@
bool bypassMenu = false; bool bypassMenu = false;


void setup() { void setup() {
log::setup();
logging::setup();


config::main::setup(); config::main::setup();
rtc::setup(); rtc::setup();


+ 0
- 27
GpsTracker/Log.cpp 查看文件

@@ -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("============================="));
}

}

+ 18
- 0
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);
}
}

}

GpsTracker/Log.h → GpsTracker/Logging.h 查看文件

@@ -1,9 +1,15 @@
#pragma once #pragma once
#include "Config.h"


#define DISABLE_LOGGING 1
//#define DISABLE_LOGGING 1
#include <ArduinoLog.h> #include <ArduinoLog.h>


#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(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_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__) #define NOTICE_FORMAT(f, msg, ...) LOG_FORMAT(notice, f, msg, __VA_ARGS__)




namespace log {
namespace logging {
void setup(); void setup();
} }

+ 2
- 2
GpsTracker/MainUnit.cpp 查看文件

@@ -36,7 +36,7 @@ namespace mainunit {
} }


void sleep(period_t period) { void sleep(period_t period) {
NOTICE_FORMAT("sleep", "Sleeping for period : %d", period);
NOTICE_FORMAT("sleep", "Period : %d", period);
details::prepareSleep(); details::prepareSleep();
LowPower.powerDown(period, ADC_OFF, BOD_OFF); LowPower.powerDown(period, ADC_OFF, BOD_OFF);
details::wokeUp(); details::wokeUp();
@@ -44,7 +44,7 @@ namespace mainunit {
} }


void deepSleep(uint16_t seconds) { void deepSleep(uint16_t seconds) {
NOTICE_FORMAT("deepSleep", "Deep sleeping for %d seconds", seconds);
NOTICE_FORMAT("deepSleep", "%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);


+ 4
- 2
GpsTracker/Positions.cpp 查看文件

@@ -53,7 +53,7 @@ namespace positions {
} }


bool acquire(PositionEntryMetadata &metadata) { bool acquire(PositionEntryMetadata &metadata) {
VERBOSE("acquire");
NOTICE("acquire");


timestamp_t before; timestamp_t before;


@@ -63,6 +63,8 @@ namespace positions {
SIM808ChargingStatus battery = hardware::sim808::device.getChargingState(); SIM808ChargingStatus battery = hardware::sim808::device.getChargingState();
gps::powerOff(); gps::powerOff();


NOTICE_FORMAT("acquire", "status : %d", gpsStatus);

if (gpsStatus < SIM808_GPS_STATUS::FIX) return false; if (gpsStatus < SIM808_GPS_STATUS::FIX) return false;


uint16_t timeToFix = rtc::getTime() - before; uint16_t timeToFix = rtc::getTime() - before;
@@ -98,7 +100,7 @@ namespace positions {
hardware::i2c::powerOn(); hardware::i2c::powerOn();
hardware::i2c::eeprom.writeBlock(entryAddress, entry); 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++; config->lastEntry++;
if (config->lastEntry > details::maxEntryIndex) config->lastEntry = 0; if (config->lastEntry > details::maxEntryIndex) config->lastEntry = 0;


+ 1
- 1
GpsTracker/Rtc.cpp 查看文件

@@ -71,7 +71,7 @@ namespace rtc {
RTC.control(DS3231_A1_INT_ENABLE, DS3231_ON); //Alarm 1 ON RTC.control(DS3231_A1_INT_ENABLE, DS3231_ON); //Alarm 1 ON
RTC.control(DS3231_INT_ENABLE, DS3231_ON); //INTCN 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(); hardware::i2c::powerOff();
} }


Loading…
取消
儲存