diff --git a/src/emsesp.cpp b/src/emsesp.cpp index 4152eaf71..dee34067a 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -120,19 +120,20 @@ void EMSESP::show_emsbus(uuid::console::Shell & shell) { } shell.printfln(F("EMS Bus info:")); + shell.printfln(F(" Tx mode: %d"), Settings().ems_tx_mode()); shell.printfln(F(" Bus protocol: %s"), EMSbus::is_ht3() ? F("HT3") : F("Buderus")); shell.printfln(F(" #telegrams received: %d"), rxservice_.telegram_count()); shell.printfln(F(" #read requests sent: %d"), txservice_.telegram_read_count()); shell.printfln(F(" #write requests sent: %d"), txservice_.telegram_write_count()); - shell.printfln(F(" #incomplete telegrams: %d (%d%%)"), rxservice_.telegram_error_count(), success_rate); - shell.printfln(F(" #tx fails (after 3 retries): %d"), txservice_.telegram_fail_count()); + shell.printfln(F(" #corrupted telegrams: %d (%d%%)"), rxservice_.telegram_error_count(), success_rate); + shell.printfln(F(" #tx fails (after %d retries): %d"), TxService::MAXIMUM_TX_RETRIES, txservice_.telegram_fail_count()); } else { - shell.printfln(F("EMS Bus is disconnected")); + shell.printfln(F("EMS Bus is disconnected.")); } shell.println(); - // Rx + // Rx queue auto rx_telegrams = rxservice_.queue(); if (rx_telegrams.empty()) { shell.printfln(F("Rx Queue is empty")); @@ -145,7 +146,7 @@ void EMSESP::show_emsbus(uuid::console::Shell & shell) { shell.println(); - // Tx + // Tx queue auto tx_telegrams = txservice_.queue(); if (tx_telegrams.empty()) { shell.printfln(F("Tx Queue is empty")); @@ -393,9 +394,11 @@ void EMSESP::process_version(std::shared_ptr telegram) { // We also check for common telgram types, like the Version(0x02) // returns false if there are none found bool EMSESP::process_telegram(std::shared_ptr telegram) { + + // if watching... if (watch() == 1) { if ((watch_id_ == WATCH_NONE) || (telegram->src == watch_id_) || (telegram->dest == watch_id_) || (telegram->type_id == watch_id_)) { - LOG_INFO(pretty_telegram(telegram).c_str()); + LOG_NOTICE(pretty_telegram(telegram).c_str()); } } @@ -722,28 +725,24 @@ void EMSESP::console_commands(Shell & shell, unsigned int context) { }; }); - EMSESPShell::commands->add_command( - ShellContext::EMS, - CommandFlags::ADMIN, - flash_string_vector{F_(set), F_(tx_mode)}, - flash_string_vector{F_(n_mandatory)}, - [](Shell & shell, const std::vector & arguments) { - uint8_t tx_mode = std::strtol(arguments[0].c_str(), nullptr, 10); - if ((tx_mode > 0) && (tx_mode <= 30)) { - Settings settings; - settings.ems_tx_mode(tx_mode); - settings.commit(); - shell.printfln(F_(tx_mode_fmt), settings.ems_tx_mode()); - // reset the UART - EMSuart::stop(); - EMSuart::start(tx_mode); - } else { - shell.println(F("Must be 1 for EMS generic, 2 for EMS+, 3 for HT3, 4 for experimental")); - } - }, - [](Shell & shell __attribute__((unused)), const std::vector & arguments __attribute__((unused))) -> const std::vector { - return std::vector{read_flash_string(F("1")), read_flash_string(F("2")), read_flash_string(F("3")), read_flash_string(F("4"))}; - }); + EMSESPShell::commands->add_command(ShellContext::EMS, + CommandFlags::ADMIN, + flash_string_vector{F_(set), F_(tx_mode)}, + flash_string_vector{F_(n_mandatory)}, + [](Shell & shell, const std::vector & arguments) { + uint8_t tx_mode = std::strtol(arguments[0].c_str(), nullptr, 10); + if ((tx_mode > 0) && (tx_mode <= 30)) { + Settings settings; + settings.ems_tx_mode(tx_mode); + settings.commit(); + shell.printfln(F_(tx_mode_fmt), settings.ems_tx_mode()); + // reset the UART + EMSuart::stop(); + EMSuart::start(tx_mode); + } else { + shell.println(F("Must be 1 for EMS generic, 2 for EMS+, 3 for HT3, 4 for experimental")); + } + }); EMSESPShell::commands->add_command( ShellContext::EMS, @@ -858,7 +857,15 @@ void EMSESP::console_commands(Shell & shell, unsigned int context) { uint8_t watch = emsesp::EMSESP::watch(); if (watch == 0) { shell.printfln(F("Watch is off")); - } else if (watch == 1) { + return; + } + + // if logging is off, the watch won't show anything, show force it back to INFO + if (!logger_.enabled(Level::NOTICE)) { + shell.log_level(Level::NOTICE); + } + + if (watch == 1) { shell.printfln(F("Watching incoming telegrams, displayed in decoded format")); } else { shell.printfln(F("Watching incoming telegrams, displayed as raw bytes")); diff --git a/src/system.cpp b/src/system.cpp index f21d7a668..27d0bc1f3 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -72,8 +72,7 @@ void System::mqtt_commands(const char * message) { if (doc["send"] != nullptr) { const char * data = doc["send"]; EMSESP::send_raw_telegram(data); - LOG_INFO(F("Sending raw: %s"),data); - + LOG_INFO(F("Sending raw: %s"), data); } #if defined(ESP8266) @@ -87,39 +86,60 @@ void System::mqtt_commands(const char * message) { const uint8_t d2_ = 21; const uint8_t d3_ = 17; #endif - if(doc["D0"] != nullptr) { + +#ifndef EMSESP_STANDALONE + + if (doc["D0"] != nullptr) { const int8_t set = doc["D0"]; pinMode(d0_, OUTPUT); - if (set == 1) digitalWrite(d0_, HIGH); - else if (set == 0) digitalWrite(d0_, LOW); - LOG_INFO(F("Port D0 set to %d"),set); + if (set == 1) { + digitalWrite(d0_, HIGH); + } else if (set == 0) { + digitalWrite(d0_, LOW); + } + LOG_INFO(F("Port D0 set to %d"), set); } - if(doc["D1"] != nullptr) { + + if (doc["D1"] != nullptr) { const int8_t set = doc["D1"]; pinMode(d1_, OUTPUT); - if (set == 1) digitalWrite(d1_, HIGH); - else if (set == 0) digitalWrite(d1_, LOW); - LOG_INFO(F("Port D1 set to %d"),set); + if (set == 1) { + digitalWrite(d1_, HIGH); + } else if (set == 0) { + digitalWrite(d1_, LOW); + } + LOG_INFO(F("Port D1 set to %d"), set); } - if(doc["D2"] != nullptr) { + + if (doc["D2"] != nullptr) { const int8_t set = doc["D2"]; pinMode(d2_, OUTPUT); - if (set == 1) digitalWrite(d2_, HIGH); - else if (set == 0) digitalWrite(d2_, LOW); - LOG_INFO(F("Port D2 set to %d"),set); + if (set == 1) { + digitalWrite(d2_, HIGH); + } else if (set == 0) { + digitalWrite(d2_, LOW); + } + LOG_INFO(F("Port D2 set to %d"), set); } - if(doc["D3"] != nullptr) { + + if (doc["D3"] != nullptr) { const int8_t set = doc["D3"]; pinMode(d3_, OUTPUT); - if (set == 1) digitalWrite(d3_, HIGH); - else if (set == 0) digitalWrite(d3_, LOW); - LOG_INFO(F("Port D3 set to %d"),set); + if (set == 1) { + digitalWrite(d3_, HIGH); + } else if (set == 0) { + digitalWrite(d3_, LOW); + } + LOG_INFO(F("Port D3 set to %d"), set); } +#endif + const char * command = doc["cmd"]; if (command == nullptr) { return; } + // send raw command if (strcmp(command, "send") == 0) { const char * data = doc["data"]; @@ -127,7 +147,7 @@ void System::mqtt_commands(const char * message) { return; } EMSESP::send_raw_telegram(data); - LOG_INFO(F("Sending raw: %s"),data); + LOG_INFO(F("Sending raw: %s"), data); return; } } diff --git a/src/telegram.cpp b/src/telegram.cpp index a393093bc..16e40b98d 100644 --- a/src/telegram.cpp +++ b/src/telegram.cpp @@ -304,11 +304,11 @@ void RxService::add(uint8_t * data, uint8_t length) { return; } - // if we're in "trace" and "raw" print out actual telegram as bytes to the console + // if we're watching and "raw" print out actual telegram as bytes to the console if (EMSESP::watch() == 2) { uint16_t trace_watch_id = EMSESP::watch_id(); if ((trace_watch_id == WATCH_NONE) || (src == trace_watch_id) || (dest == trace_watch_id) || (type_id == trace_watch_id)) { - LOG_INFO(F("Rx: %s"), Helpers::data_to_hex(data, length).c_str()); + LOG_NOTICE(F("Rx: %s"), Helpers::data_to_hex(data, length).c_str()); } } @@ -471,7 +471,7 @@ void TxService::send_telegram(const QueuedTxTelegram & tx_telegram) { #ifdef EMSESP_DEBUG // if watching in 'raw' mode if (EMSESP::watch() == 2) { - LOG_INFO(F("[DEBUG] Tx: %s"), Helpers::data_to_hex(telegram_raw, length).c_str()); + LOG_NOTICE(F("[DEBUG] Tx: %s"), Helpers::data_to_hex(telegram_raw, length).c_str()); } #endif