瀏覽代碼

Improved logs

tags/v1.2.0
Bertrand Lemasle 7 年之前
父節點
當前提交
3c9a53a6c0
共有 6 個檔案被更改,包括 40 行新增24 行删除
  1. +2
    -2
      GpsTracker/Core.cpp
  2. +25
    -14
      GpsTracker/Debug.cpp
  3. +1
    -1
      GpsTracker/Debug.h
  4. +2
    -2
      GpsTracker/Flash.h
  5. +4
    -3
      GpsTracker/MainUnit.cpp
  6. +6
    -2
      GpsTracker/Rtc.cpp

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

@@ -35,9 +35,9 @@ namespace core {
}

void setSleepTime(uint8_t velocity) {
for (uint8_t i = 0; i < flash::getFlashArraySize(config::defaultSleepTimings); i++) {
for (uint8_t i = 0; i < flash::getArraySize(config::defaultSleepTimings); i++) {
sleepTimings_t timing;
flash::readFromFlash(&config::defaultSleepTimings[i], timing);
flash::read(&config::defaultSleepTimings[i], timing);

if (velocity > timing.speed) continue;



+ 25
- 14
GpsTracker/Debug.cpp 查看文件

@@ -9,7 +9,7 @@ MENU_ENTRY(SEPARATOR, "----");

MENU_ENTRY(RUN, "[0] Run");
MENU_ENTRY(RUN_ONCE, "[1] Run once");
MENU_ENTRY(RAM, "[2] Read battery");
MENU_ENTRY(RAM, "[2] Free RAM");
MENU_ENTRY(READ_BATTERY, "[3] Read battery");
MENU_ENTRY(GPS_ON, "[4] GPS On");
MENU_ENTRY(GPS_OFF, "[5] GPS Off");
@@ -18,7 +18,7 @@ MENU_ENTRY(RTC_ON, "[7] RTC On");
MENU_ENTRY(RTC_OFF, "[8] RTC Off");
MENU_ENTRY(RTC_SET, "[9] Get RTC time");
MENU_ENTRY(RTC_GET, "[10] Set RTC time");
MENU_ENTRY(SD_WRITE_TEST "[11] Write to test file");
MENU_ENTRY(SD_WRITE_TEST, "[11] Write to test file");
MENU_ENTRY(EEPROM_GET_CONFIG, "[16] Get EEPROM config");
MENU_ENTRY(EEPROM_GET_ENTRIES, "[17] Get EEPROM entries");
MENU_ENTRY(QUESTION, "?");
@@ -46,9 +46,16 @@ const char * const MENU_ENTRIES[] PROGMEM = {
MENU_RTC_SET,
MENU_RTC_GET,

MENU_QUESTION
MENU_SEPARATOR,

MENU_SD_WRITE_TEST,

MENU_SEPARATOR,

MENU_EEPROM_GET_CONFIG,
MENU_EEPROM_GET_ENTRIES,

MENU_QUESTION
};

int freeRam2() { // dirty hack because putting it in namespace doesn't compile
@@ -61,7 +68,7 @@ namespace debug {

void waitForSerial() {
while (!Serial);
Serial.begin(DEBUG_SERIAL_SPEED);
Serial.println("Starting !");
}

int freeRam() {
@@ -72,15 +79,17 @@ namespace debug {
if (!Serial) return GPSTRACKER_DEBUG_COMMAND::NONE;

uint8_t command;

while (command > static_cast<uint8_t>(GPSTRACKER_DEBUG_COMMAND::RTC_SET)) {
for (uint8_t i = 0; i < flash::getFlashArraySize(MENU_ENTRIES); i++) {
Serial.println(reinterpret_cast<const __FlashStringHelper *>(pgm_read_word(MENU_ENTRIES[i])));
size_t menuSize = flash::getArraySize(MENU_ENTRIES);
do {
for (uint8_t i = 0; i < menuSize; i++) {
Serial.println(reinterpret_cast<const __FlashStringHelper *>(pgm_read_word(&MENU_ENTRIES[i])));
}

while (!Serial.available());
command = static_cast<uint8_t>(Serial.parseInt());
}
while (Serial.available()) Serial.read();
} while (command > static_cast<uint8_t>(GPSTRACKER_DEBUG_COMMAND::EEPROM_GET_ENTRIES));
return static_cast<GPSTRACKER_DEBUG_COMMAND>(command);
}
@@ -88,20 +97,22 @@ namespace debug {
void getAndDisplayGpsPosition() {
SIM808_GPS_STATUS gpsStatus = gps::acquireCurrentPosition(GPS_DEFAULT_TOTAL_TIMEOUT_MS);

Log.notice(F("%d %s"), gpsStatus, gps::lastPosition);
Log.notice(F("%d %s\n"), gpsStatus, gps::lastPosition);
}

void getAndDisplayBattery() {
hardware::sim808::powerOn();
SIM808ChargingStatus status = hardware::sim808::device.getChargingState();
hardware::sim808::powerOff();

Log.notice(F("%d %d%% %dmV"), status.state, status.level, status.voltage);
Log.notice(F("%d %d%% %dmV\n"), status.state, status.level, status.voltage);
}

void getAndDisplayRtcTime() {
tmElements_t time;
rtc::getTime(time);

Log.notice(F("%d/%d/%d %d:%d:%d"), time.Year, time.Month, time.Day, time.Hour, time.Minute, time.Second);
Log.notice(F("%d/%d/%d %d:%d:%d\n"), tmYearToCalendar(time.Year), time.Month, time.Day, time.Hour, time.Minute, time.Second);
}

void getAndDisplayEepromConfig() {
@@ -109,7 +120,7 @@ namespace debug {
config::read();
hardware::i2c::eepromPowerOff();
Log.notice(F("%s, %s, %d, %d"), config::value.seed, config::value.version, config::value.firstEntry, config::value.lastEntry);
Log.notice(F("%s, %s, %d, %d\n"), config::value.seed, config::value.version, config::value.firstEntry, config::value.lastEntry);
}

void getAndDisplayEepromPositions() {
@@ -119,7 +130,7 @@ namespace debug {

do {
positions::get(currentEntryIndex, currentEntry);
Log.notice(F("%d%%, %dmV, %d, %s"), currentEntry.battery.level, currentEntry.battery.voltage, currentEntry.status, currentEntry.position);
Log.notice(F("%d%%, %dmV, %d, %s\n"), currentEntry.battery.level, currentEntry.battery.voltage, currentEntry.status, currentEntry.position);

} while (currentEntryIndex != config::value.lastEntry);


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

@@ -24,7 +24,7 @@

#endif

#define DEBUG_SERIAL_SPEED 9600
#define DEBUG_SERIAL_SPEED 115200

namespace debug {



+ 2
- 2
GpsTracker/Flash.h 查看文件

@@ -4,8 +4,8 @@

namespace flash {

template<typename T, size_t N> size_t getFlashArraySize(T(&)[N]) { return N; }
template<typename T> void readFromFlash(const T *source, T &dest) {
template<typename T, size_t N> size_t getArraySize(T(&)[N]) { return N; }
template<typename T> void read(const T *source, T &dest) {
memcpy_P(&dest, source, sizeof(T));
}
}

+ 4
- 3
GpsTracker/MainUnit.cpp 查看文件

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

void sleep(period_t period) {
Log.verbose(F("Sleeping for period : %d"), period);
Log.notice(F("Sleeping for period : %d"), period);
LowPower.powerDown(period, ADC_OFF, BOD_OFF);
@@ -30,11 +30,12 @@ namespace mainunit {
}

void deepSleep(uint16_t seconds) {
Log.verbose(F("Deep sleeping for %d seconds"), seconds);
Log.notice(F("Deep sleeping for %d seconds"), seconds);

interruptIn(seconds);
Log.verbose("interruptIn done !");
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
Log.verbose("hola");
Log.verbose(reinterpret_cast<const __FlashStringHelper *>(pgm_read_word(WOKE_UP)));
}
}

+ 6
- 2
GpsTracker/Rtc.cpp 查看文件

@@ -48,10 +48,14 @@ namespace rtc {
}

void setAlarm(tmElements_t &time) {
tmElements_t currentTime;
getTime(currentTime);
Log.verbose(F("Current time : %d/%d/%d %d:%d:%d\n"), tmYearToCalendar(currentTime.Year), currentTime.Month, currentTime.Day, currentTime.Hour, currentTime.Minute, currentTime.Second);
Log.notice(F("Set alarm to : %d/%d/%d %d:%d:%d\n"), tmYearToCalendar(time.Year), time.Month, time.Day, time.Hour, time.Minute, time.Second);
details::writeTimeToRegisters(time);
RTC.writeAlarm1(DS3231_ALM_S);
RTC.writeAlarm1(DS3231_ALM_DTHMS);

RTC.control(DS3231_A1_FLAG, DS3231_OFF);
RTC.control(DS3231_A1_FLAG, DS3231_OFF); //reset Alarm 1 flag
RTC.control(DS3231_A1_INT_ENABLE, DS3231_ON); //Alarm 1 ON
RTC.control(DS3231_INT_ENABLE, DS3231_ON); //INTCN ON
}


Loading…
取消
儲存