update logger calls

pull/83/head
Peter Buchegger 2023-01-21 13:47:05 +01:00
rodzic 4aa7d93b34
commit 8202f72016
3 zmienionych plików z 35 dodań i 30 usunięć

Wyświetl plik

@ -15,6 +15,8 @@
#define VERSION "22.19.0" #define VERSION "22.19.0"
logging::Logger logger;
Configuration Config; Configuration Config;
BeaconManager BeaconMan; BeaconManager BeaconMan;
@ -65,9 +67,9 @@ void setup() {
#ifdef TTGO_T_Beam_V1_0 #ifdef TTGO_T_Beam_V1_0
Wire.begin(SDA, SCL); Wire.begin(SDA, SCL);
if (!powerManagement.begin(Wire)) { if (!powerManagement.begin(Wire)) {
logPrintlnI("AXP192 init done!"); logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "AXP192", "init done!");
} else { } else {
logPrintlnE("AXP192 init failed!"); logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "AXP192", "init failed!");
} }
powerManagement.activateLoRa(); powerManagement.activateLoRa();
powerManagement.activateOLED(); powerManagement.activateOLED();
@ -76,8 +78,8 @@ void setup() {
#endif #endif
delay(500); delay(500);
logPrintlnI("LoRa APRS Tracker by OE5BPA (Peter Buchegger)"); logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "LoRa APRS Tracker by OE5BPA (Peter Buchegger)");
logPrintlnI("Version: " VERSION); logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "Version: " VERSION);
setup_display(); setup_display();
show_display("OE5BPA", "LoRa APRS Tracker", "by Peter Buchegger", "Version: " VERSION, 2000); show_display("OE5BPA", "LoRa APRS Tracker", "by Peter Buchegger", "Version: " VERSION, 2000);
@ -105,9 +107,9 @@ void setup() {
} }
userButton.attachDoubleClick(toggle_display); userButton.attachDoubleClick(toggle_display);
logPrintlnI("Smart Beacon is " + getSmartBeaconState()); logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "Smart Beacon is: %s", getSmartBeaconState());
show_display("INFO", "Smart Beacon is " + getSmartBeaconState(), 1000); show_display("INFO", "Smart Beacon is " + getSmartBeaconState(), 1000);
logPrintlnI("setup done..."); logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "setup done...");
delay(500); delay(500);
} }
@ -137,10 +139,11 @@ void loop() {
if (gps_loc_update != gps_loc_update_valid) { if (gps_loc_update != gps_loc_update_valid) {
gps_loc_update_valid = gps_loc_update; gps_loc_update_valid = gps_loc_update;
if (gps_loc_update) if (gps_loc_update) {
logPrintlnI("GPS fix state went to VALID"); logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Loop", "GPS fix state went to VALID");
else } else {
logPrintlnI("GPS fix state went to INVALID"); logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Loop", "GPS fix state went to INVALID");
}
} }
static double currentHeading = 0; static double currentHeading = 0;
@ -292,7 +295,7 @@ void loop() {
msg.getBody()->setData(aprsmsg); msg.getBody()->setData(aprsmsg);
String data = msg.encode(); String data = msg.encode();
logPrintlnD(data); logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "Loop", "%s", data);
show_display("<< TX >>", data); show_display("<< TX >>", data);
if (Config.ptt.active) { if (Config.ptt.active) {
@ -351,8 +354,9 @@ void loop() {
} }
if ((Config.debug == false) && (millis() > 5000 && gps.charsProcessed() < 10)) { if ((Config.debug == false) && (millis() > 5000 && gps.charsProcessed() < 10)) {
logPrintlnE("No GPS frames detected! Try to reset the GPS Chip with this " logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "GPS",
"firmware: https://github.com/lora-aprs/TTGO-T-Beam_GPS-reset"); "No GPS frames detected! Try to reset the GPS Chip with this "
"firmware: https://github.com/lora-aprs/TTGO-T-Beam_GPS-reset");
show_display("No GPS frames detected!", "Try to reset the GPS Chip", "https://github.com/lora-aprs/TTGO-T-Beam_GPS-reset", 2000); show_display("No GPS frames detected!", "Try to reset the GPS Chip", "https://github.com/lora-aprs/TTGO-T-Beam_GPS-reset", 2000);
} }
} }
@ -362,8 +366,9 @@ void load_config() {
Config = confmg.readConfiguration(); Config = confmg.readConfiguration();
BeaconMan.loadConfig(Config.beacons); BeaconMan.loadConfig(Config.beacons);
if (BeaconMan.getCurrentBeaconConfig()->callsign == "NOCALL-10") { if (BeaconMan.getCurrentBeaconConfig()->callsign == "NOCALL-10") {
logPrintlnE("You have to change your settings in 'data/tracker.json' and " logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "Config",
"upload it via \"Upload File System image\"!"); "You have to change your settings in 'data/tracker.json' and "
"upload it via \"Upload File System image\"!");
show_display("ERROR", "You have to change your settings in 'data/tracker.json' and " show_display("ERROR", "You have to change your settings in 'data/tracker.json' and "
"upload it via \"Upload File System image\"!"); "upload it via \"Upload File System image\"!");
while (true) { while (true) {
@ -372,16 +377,15 @@ void load_config() {
} }
void setup_lora() { void setup_lora() {
logPrintlnI("Set SPI pins!"); logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "LoRa", "Set SPI pins!");
SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS); SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS);
logPrintlnI("Set LoRa pins!"); logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "LoRa", "Set LoRa pins!");
LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ); LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ);
long freq = Config.lora.frequencyTx; long freq = Config.lora.frequencyTx;
logPrintI("frequency: "); logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "LoRa", "frequency: %d", freq);
logPrintlnI(String(freq));
if (!LoRa.begin(freq)) { if (!LoRa.begin(freq)) {
logPrintlnE("Starting LoRa failed!"); logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "LoRa", "Starting LoRa failed!");
show_display("ERROR", "Starting LoRa failed!"); show_display("ERROR", "Starting LoRa failed!");
while (true) { while (true) {
} }
@ -392,7 +396,7 @@ void setup_lora() {
LoRa.enableCrc(); LoRa.enableCrc();
LoRa.setTxPower(Config.lora.power); LoRa.setTxPower(Config.lora.power);
logPrintlnI("LoRa init done!"); logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "LoRa", "LoRa init done!");
show_display("INFO", "LoRa init done!", 2000); show_display("INFO", "LoRa init done!", 2000);
} }

Wyświetl plik

@ -7,12 +7,14 @@
#include "configuration.h" #include "configuration.h"
extern logging::Logger logger;
ConfigurationManagement::ConfigurationManagement(String FilePath) : mFilePath(FilePath) { ConfigurationManagement::ConfigurationManagement(String FilePath) : mFilePath(FilePath) {
if (!SPIFFS.begin(true)) { if (!SPIFFS.begin(true)) {
logPrintlnE("Mounting SPIFFS was not possible. Trying to format SPIFFS..."); logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "Configuration", "Mounting SPIFFS was not possible. Trying to format SPIFFS...");
SPIFFS.format(); SPIFFS.format();
if (!SPIFFS.begin()) { if (!SPIFFS.begin()) {
logPrintlnE("Formating SPIFFS was not okay!"); logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "Configuration", "Formatting SPIFFS was not okay!");
} }
} }
} }
@ -21,14 +23,14 @@ ConfigurationManagement::ConfigurationManagement(String FilePath) : mFilePath(Fi
Configuration ConfigurationManagement::readConfiguration() { Configuration ConfigurationManagement::readConfiguration() {
File file = SPIFFS.open(mFilePath); File file = SPIFFS.open(mFilePath);
if (!file) { if (!file) {
logPrintlnE("Failed to open file for reading..."); logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "Configuration", "Failed to open file for reading...");
return Configuration(); return Configuration();
} }
DynamicJsonDocument data(2048); DynamicJsonDocument data(2048);
DeserializationError error = deserializeJson(data, file); DeserializationError error = deserializeJson(data, file);
if (error) { if (error) {
logPrintlnE("Failed to read file, using default configuration."); logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "Configuration", "Failed to read file, using default configuration.");
} }
file.close(); file.close();
@ -89,7 +91,7 @@ Configuration ConfigurationManagement::readConfiguration() {
void ConfigurationManagement::writeConfiguration(Configuration conf) { void ConfigurationManagement::writeConfiguration(Configuration conf) {
File file = SPIFFS.open(mFilePath, "w"); File file = SPIFFS.open(mFilePath, "w");
if (!file) { if (!file) {
logPrintlnE("Failed to open file for writing..."); logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "Configuration", "Failed to open file for writing...");
return; return;
} }
DynamicJsonDocument data(2048); DynamicJsonDocument data(2048);

Wyświetl plik

@ -7,6 +7,8 @@
#include "display.h" #include "display.h"
#include "pins.h" #include "pins.h"
extern logging::Logger logger;
Adafruit_SSD1306 display(128, 64, &Wire, OLED_RST); Adafruit_SSD1306 display(128, 64, &Wire, OLED_RST);
// cppcheck-suppress unusedFunction // cppcheck-suppress unusedFunction
@ -18,7 +20,7 @@ void setup_display() {
Wire.begin(OLED_SDA, OLED_SCL); Wire.begin(OLED_SDA, OLED_SCL);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) { if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) {
logPrintlnE("SSD1306 allocation failed"); logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "SSD1306", "allocation failed!");
while (true) { while (true) {
} }
} }
@ -35,12 +37,9 @@ void setup_display() {
// cppcheck-suppress unusedFunction // cppcheck-suppress unusedFunction
void display_toggle(bool toggle) { void display_toggle(bool toggle) {
logPrintI("Toggling display: ");
if (toggle) { if (toggle) {
logPrintlnI("On");
display.ssd1306_command(SSD1306_DISPLAYON); display.ssd1306_command(SSD1306_DISPLAYON);
} else { } else {
logPrintlnI("Off");
display.ssd1306_command(SSD1306_DISPLAYOFF); display.ssd1306_command(SSD1306_DISPLAYOFF);
} }
} }