mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
new command called 'watch'. telegrams are no longer shown in log debug
This commit is contained in:
@@ -225,9 +225,8 @@ void Console::load_standard_commands(unsigned int context) {
|
|||||||
context,
|
context,
|
||||||
CommandFlags::USER,
|
CommandFlags::USER,
|
||||||
flash_string_vector{F_(log)},
|
flash_string_vector{F_(log)},
|
||||||
flash_string_vector{F_(log_level_optional), F_(trace_format_optional), F_(traceid_optional)},
|
flash_string_vector{F_(log_level_optional)},
|
||||||
[](Shell & shell, const std::vector<std::string> & arguments) {
|
[](Shell & shell, const std::vector<std::string> & arguments) {
|
||||||
uint16_t watch_id;
|
|
||||||
if (!arguments.empty()) {
|
if (!arguments.empty()) {
|
||||||
uuid::log::Level level;
|
uuid::log::Level level;
|
||||||
|
|
||||||
@@ -237,41 +236,10 @@ void Console::load_standard_commands(unsigned int context) {
|
|||||||
shell.printfln(F_(invalid_log_level));
|
shell.printfln(F_(invalid_log_level));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// trace logic
|
|
||||||
if (level == uuid::log::Level::TRACE || level == uuid::log::Level::DEBUG) {
|
|
||||||
watch_id = LOG_TRACE_WATCH_NONE; // no watch ID set
|
|
||||||
if (arguments.size() > 1) {
|
|
||||||
// next argument is raw or full
|
|
||||||
if (arguments[1] == read_flash_string(F_(raw))) {
|
|
||||||
emsesp::EMSESP::trace_raw(true);
|
|
||||||
} else if (arguments[1] == read_flash_string(F_(pretty))) {
|
|
||||||
emsesp::EMSESP::trace_raw(false);
|
|
||||||
} else {
|
|
||||||
emsesp::EMSESP::trace_watch_id(Helpers::hextoint(arguments[1].c_str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the watch_id if its set
|
|
||||||
if (arguments.size() == 3) {
|
|
||||||
emsesp::EMSESP::trace_watch_id(Helpers::hextoint(arguments[2].c_str()));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// it was "log trace" so reset the watch id and switch back to pretty
|
|
||||||
emsesp::EMSESP::trace_raw(false);
|
|
||||||
emsesp::EMSESP::trace_watch_id(LOG_TRACE_WATCH_NONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// print out logging settings
|
// print out logging settings
|
||||||
shell.printfln(F_(log_level_fmt), uuid::log::format_level_uppercase(shell.log_level()));
|
shell.printfln(F_(log_level_fmt), uuid::log::format_level_uppercase(shell.log_level()));
|
||||||
watch_id = emsesp::EMSESP::trace_watch_id();
|
|
||||||
if (watch_id == LOG_TRACE_WATCH_NONE) {
|
|
||||||
shell.printfln(F("Tracing all telegrams"));
|
|
||||||
} else {
|
|
||||||
shell.printfln(F("Tracing only telegrams that match a device ID or telegram type of 0x%02X"), watch_id);
|
|
||||||
}
|
|
||||||
shell.printfln(F_(trace_raw_fmt), emsesp::EMSESP::trace_raw() ? F("as raw bytes") : F("in decoded format"));
|
|
||||||
},
|
},
|
||||||
[](Shell & shell __attribute__((unused)), const std::vector<std::string> & arguments __attribute__((unused))) -> std::vector<std::string> {
|
[](Shell & shell __attribute__((unused)), const std::vector<std::string> & arguments __attribute__((unused))) -> std::vector<std::string> {
|
||||||
return uuid::log::levels_lowercase();
|
return uuid::log::levels_lowercase();
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ using uuid::log::Level;
|
|||||||
// clang-format off
|
// clang-format off
|
||||||
|
|
||||||
#define LOG_DEBUG(...) if (logger_.enabled(Level::DEBUG)) {logger_.debug(__VA_ARGS__);}
|
#define LOG_DEBUG(...) if (logger_.enabled(Level::DEBUG)) {logger_.debug(__VA_ARGS__);}
|
||||||
#define LOG_TRACE(...) if (logger_.enabled(Level::TRACE)) {logger_.trace(__VA_ARGS__);}
|
|
||||||
#define LOG_INFO(...) logger_.info(__VA_ARGS__)
|
#define LOG_INFO(...) logger_.info(__VA_ARGS__)
|
||||||
|
#define LOG_TRACE(...) logger_.trace(__VA_ARGS__)
|
||||||
#define LOG_NOTICE(...) logger_.notice(__VA_ARGS__)
|
#define LOG_NOTICE(...) logger_.notice(__VA_ARGS__)
|
||||||
#define LOG_WARNING(...) logger_.warning(__VA_ARGS__)
|
#define LOG_WARNING(...) logger_.warning(__VA_ARGS__)
|
||||||
#define LOG_ERROR(...) logger_.err(__VA_ARGS__)
|
#define LOG_ERROR(...) logger_.err(__VA_ARGS__)
|
||||||
@@ -90,7 +90,7 @@ MAKE_PSTR_WORD(restart)
|
|||||||
MAKE_PSTR_WORD(reconnect)
|
MAKE_PSTR_WORD(reconnect)
|
||||||
MAKE_PSTR_WORD(format)
|
MAKE_PSTR_WORD(format)
|
||||||
MAKE_PSTR_WORD(raw)
|
MAKE_PSTR_WORD(raw)
|
||||||
MAKE_PSTR_WORD(pretty)
|
MAKE_PSTR_WORD(watch)
|
||||||
|
|
||||||
// context menus
|
// context menus
|
||||||
MAKE_PSTR_WORD(mqtt)
|
MAKE_PSTR_WORD(mqtt)
|
||||||
@@ -102,9 +102,6 @@ MAKE_PSTR(degrees_mandatory, "<degrees>")
|
|||||||
MAKE_PSTR(asterisks, "********")
|
MAKE_PSTR(asterisks, "********")
|
||||||
MAKE_PSTR(n_mandatory, "<n>")
|
MAKE_PSTR(n_mandatory, "<n>")
|
||||||
MAKE_PSTR(n_optional, "[n]")
|
MAKE_PSTR(n_optional, "[n]")
|
||||||
MAKE_PSTR(traceid_optional, "[trace ID]")
|
|
||||||
MAKE_PSTR(trace_raw_fmt, "Displaying telegrams %s")
|
|
||||||
MAKE_PSTR(trace_format_optional, "[pretty | raw]")
|
|
||||||
MAKE_PSTR(bool_mandatory, "<on | off>")
|
MAKE_PSTR(bool_mandatory, "<on | off>")
|
||||||
MAKE_PSTR(typeid_mandatory, "<type ID>")
|
MAKE_PSTR(typeid_mandatory, "<type ID>")
|
||||||
MAKE_PSTR(deviceid_mandatory, "<device ID>")
|
MAKE_PSTR(deviceid_mandatory, "<device ID>")
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ MAKE_PSTR(tx_mode_fmt, "Tx mode = %d")
|
|||||||
MAKE_PSTR(bus_id_fmt, "Bus ID = %02X")
|
MAKE_PSTR(bus_id_fmt, "Bus ID = %02X")
|
||||||
MAKE_PSTR(read_only_fmt, "Read-only mode is %s")
|
MAKE_PSTR(read_only_fmt, "Read-only mode is %s")
|
||||||
|
|
||||||
|
MAKE_PSTR(watchid_optional, "[ID]")
|
||||||
|
MAKE_PSTR(watch_format_mandatory, "<off | on | raw>")
|
||||||
|
MAKE_PSTR(invalid_watch, "Invalid watch type")
|
||||||
|
|
||||||
MAKE_PSTR(logger_name, "emsesp")
|
MAKE_PSTR(logger_name, "emsesp")
|
||||||
|
|
||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
@@ -56,8 +60,8 @@ Shower EMSESP::shower_; // Shower logic
|
|||||||
|
|
||||||
// static/common variables
|
// static/common variables
|
||||||
uint8_t EMSESP::actual_master_thermostat_ = EMSESP_DEFAULT_MASTER_THERMOSTAT; // which thermostat leads when multiple found
|
uint8_t EMSESP::actual_master_thermostat_ = EMSESP_DEFAULT_MASTER_THERMOSTAT; // which thermostat leads when multiple found
|
||||||
uint16_t EMSESP::trace_watch_id_ = LOG_TRACE_WATCH_NONE; // for when log is TRACE. 0 means no trace set
|
uint16_t EMSESP::watch_id_ = WATCH_NONE; // for when log is TRACE. 0 means no trace set
|
||||||
bool EMSESP::trace_raw_ = false; // not showing raw when in trace logging
|
uint8_t EMSESP::watch_ = 0; // trace off
|
||||||
bool EMSESP::tap_water_active_ = false; // for when Boiler states we having running warm water. used in Shower()
|
bool EMSESP::tap_water_active_ = false; // for when Boiler states we having running warm water. used in Shower()
|
||||||
bool EMSESP::ems_read_only_;
|
bool EMSESP::ems_read_only_;
|
||||||
uint32_t EMSESP::last_fetch_ = 0;
|
uint32_t EMSESP::last_fetch_ = 0;
|
||||||
@@ -97,12 +101,12 @@ uint8_t EMSESP::actual_master_thermostat() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// to watch both type IDs and device IDs
|
// to watch both type IDs and device IDs
|
||||||
void EMSESP::trace_watch_id(uint16_t trace_watch_id) {
|
void EMSESP::watch_id(uint16_t watch_id) {
|
||||||
// if it's a device ID, which is a single byte, remove the MSB so to support both Buderus and HT3 protocols
|
// if it's a device ID, which is a single byte, remove the MSB so to support both Buderus and HT3 protocols
|
||||||
if (trace_watch_id <= 0xFF) {
|
if (watch_id <= 0xFF) {
|
||||||
trace_watch_id_ = (trace_watch_id & 0x7F);
|
watch_id_ = (watch_id & 0x7F);
|
||||||
} else {
|
} else {
|
||||||
trace_watch_id_ = trace_watch_id;
|
watch_id_ = watch_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,10 +393,9 @@ void EMSESP::process_version(std::shared_ptr<const Telegram> telegram) {
|
|||||||
// We also check for common telgram types, like the Version(0x02)
|
// We also check for common telgram types, like the Version(0x02)
|
||||||
// returns false if there are none found
|
// returns false if there are none found
|
||||||
bool EMSESP::process_telegram(std::shared_ptr<const Telegram> telegram) {
|
bool EMSESP::process_telegram(std::shared_ptr<const Telegram> telegram) {
|
||||||
if ((logger_.enabled(Level::TRACE)) && !trace_raw()) {
|
if (watch() == 1) {
|
||||||
if ((trace_watch_id_ == LOG_TRACE_WATCH_NONE) || (telegram->src == trace_watch_id_) || (telegram->dest == trace_watch_id_)
|
if ((watch_id_ == WATCH_NONE) || (telegram->src == watch_id_) || (telegram->dest == watch_id_) || (telegram->type_id == watch_id_)) {
|
||||||
|| (telegram->type_id == trace_watch_id_)) {
|
LOG_INFO(pretty_telegram(telegram).c_str());
|
||||||
LOG_TRACE(pretty_telegram(telegram).c_str());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -562,14 +565,14 @@ void EMSESP::send_write_request(const uint16_t type_id,
|
|||||||
// this is main entry point when data is received on the Rx line, via emsuart library
|
// this is main entry point when data is received on the Rx line, via emsuart library
|
||||||
// we check if its a complete telegram or just a single byte (which could be a poll or a return status)
|
// we check if its a complete telegram or just a single byte (which could be a poll or a return status)
|
||||||
void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
|
void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
|
||||||
|
// LOG_DEBUG(F("Rx: %s"), Helpers::data_to_hex(data, length).c_str());
|
||||||
// check first for echo
|
// check first for echo
|
||||||
//LOG_TRACE(F("Rx: %s"), Helpers::data_to_hex(data, length).c_str());
|
|
||||||
uint8_t first_value = data[0];
|
uint8_t first_value = data[0];
|
||||||
if (((first_value & 0x7F) == txservice_.ems_bus_id()) && (length > 1)) {
|
if (((first_value & 0x7F) == txservice_.ems_bus_id()) && (length > 1)) {
|
||||||
// if we ask ourself at roomcontrol for version e.g. 0B 98 02 ...
|
// if we ask ourself at roomcontrol for version e.g. 0B 98 02 00 20
|
||||||
Roomctrl::check((data[1] ^ 0x80 ^ rxservice_.ems_mask()), data);
|
Roomctrl::check((data[1] ^ 0x80 ^ rxservice_.ems_mask()), data);
|
||||||
#ifdef EMSESP_DEBUG
|
#ifdef EMSESP_DEBUG
|
||||||
rxservice_.add(data, length); // just for logging, if compiled with additional debugging
|
LOG_DEBUG(F("[DEBUG] Echo: %s"), Helpers::data_to_hex(data, length).c_str());
|
||||||
#endif
|
#endif
|
||||||
return; // it's an echo
|
return; // it's an echo
|
||||||
}
|
}
|
||||||
@@ -613,7 +616,7 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
|
|||||||
// So re-send the last Tx and increment retry count
|
// So re-send the last Tx and increment retry count
|
||||||
uint8_t retries = txservice_.retry_tx(); // returns 0 if exceeded count
|
uint8_t retries = txservice_.retry_tx(); // returns 0 if exceeded count
|
||||||
#ifdef EMSESP_DEBUG
|
#ifdef EMSESP_DEBUG
|
||||||
LOG_DEBUG(F("Last Tx operation failed. Retry #%d. Sent: %s, received: %s"),
|
LOG_DEBUG(F("[DEBUG] Last Tx operation failed. Retry #%d. Sent: %s, received: %s"),
|
||||||
retries,
|
retries,
|
||||||
txservice_.last_tx_to_string().c_str(),
|
txservice_.last_tx_to_string().c_str(),
|
||||||
Helpers::data_to_hex(data, length).c_str());
|
Helpers::data_to_hex(data, length).c_str());
|
||||||
@@ -823,6 +826,50 @@ void EMSESP::console_commands(Shell & shell, unsigned int context) {
|
|||||||
shell.printfln(F_(read_only_fmt), settings.ems_read_only() ? F_(on) : F_(off));
|
shell.printfln(F_(read_only_fmt), settings.ems_read_only() ? F_(on) : F_(off));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
EMSESPShell::commands->add_command(ShellContext::EMS,
|
||||||
|
CommandFlags::USER,
|
||||||
|
flash_string_vector{F_(watch)},
|
||||||
|
flash_string_vector{F_(watch_format_mandatory), F_(watchid_optional)},
|
||||||
|
[](Shell & shell, const std::vector<std::string> & arguments) {
|
||||||
|
// get raw/pretty
|
||||||
|
if (arguments[0] == read_flash_string(F_(raw))) {
|
||||||
|
emsesp::EMSESP::watch(2); // raw
|
||||||
|
} else if (arguments[0] == read_flash_string(F_(on))) {
|
||||||
|
emsesp::EMSESP::watch(1); // on
|
||||||
|
} else if (arguments[0] == read_flash_string(F_(off))) {
|
||||||
|
emsesp::EMSESP::watch(0); // off
|
||||||
|
} else {
|
||||||
|
shell.printfln(F_(invalid_watch));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t watch_id;
|
||||||
|
if (arguments.size() == 2) {
|
||||||
|
// get the watch_id if its set
|
||||||
|
watch_id = Helpers::hextoint(arguments[1].c_str());
|
||||||
|
} else {
|
||||||
|
watch_id = WATCH_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
emsesp::EMSESP::watch_id(watch_id);
|
||||||
|
|
||||||
|
uint8_t watch = emsesp::EMSESP::watch();
|
||||||
|
if (watch == 0) {
|
||||||
|
shell.printfln(F("Watch is off"));
|
||||||
|
} else if (watch == 1) {
|
||||||
|
shell.printfln(F("Watching incoming telegrams, displayed in decoded format"));
|
||||||
|
} else {
|
||||||
|
shell.printfln(F("Watching incoming telegrams, displayed as raw bytes"));
|
||||||
|
}
|
||||||
|
|
||||||
|
watch_id = emsesp::EMSESP::watch_id();
|
||||||
|
if (watch_id != WATCH_NONE) {
|
||||||
|
shell.printfln(F("Filtering only telegrams that match a device ID or telegram type of 0x%02X"), watch_id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// enter the context
|
// enter the context
|
||||||
Console::enter_custom_context(shell, context);
|
Console::enter_custom_context(shell, context);
|
||||||
}
|
}
|
||||||
@@ -838,7 +885,6 @@ void EMSESP::start() {
|
|||||||
network_.start();
|
network_.start();
|
||||||
console_.start();
|
console_.start();
|
||||||
sensors_.start();
|
sensors_.start();
|
||||||
rxservice_.start();
|
|
||||||
txservice_.start();
|
txservice_.start();
|
||||||
shower_.start();
|
shower_.start();
|
||||||
mqtt_.start();
|
mqtt_.start();
|
||||||
|
|||||||
20
src/emsesp.h
20
src/emsesp.h
@@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
#include "devices/boiler.h"
|
#include "devices/boiler.h"
|
||||||
|
|
||||||
#define LOG_TRACE_WATCH_NONE 0 // no watch id set
|
#define WATCH_NONE 0 // no watch id set
|
||||||
|
|
||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
|
|
||||||
@@ -99,18 +99,18 @@ class EMSESP {
|
|||||||
return sensors_.devices();
|
return sensors_.devices();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void trace_watch_id(uint16_t id);
|
static void watch_id(uint16_t id);
|
||||||
|
|
||||||
static uint16_t trace_watch_id() {
|
static uint16_t watch_id() {
|
||||||
return trace_watch_id_;
|
return watch_id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void trace_raw(bool trace_raw) {
|
static void watch(uint8_t watch) {
|
||||||
trace_raw_ = trace_raw;
|
watch_ = watch; // 0=off, 1=on, 2=raw
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool trace_raw() {
|
static uint8_t watch() {
|
||||||
return trace_raw_;
|
return watch_; // 0=off, 1=on, 2=raw
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool tap_water_active() {
|
static bool tap_water_active() {
|
||||||
@@ -166,8 +166,8 @@ class EMSESP {
|
|||||||
static std::vector<Device_record> device_library_;
|
static std::vector<Device_record> device_library_;
|
||||||
|
|
||||||
static uint8_t actual_master_thermostat_;
|
static uint8_t actual_master_thermostat_;
|
||||||
static uint16_t trace_watch_id_;
|
static uint16_t watch_id_;
|
||||||
static bool trace_raw_;
|
static uint8_t watch_;
|
||||||
static bool tap_water_active_;
|
static bool tap_water_active_;
|
||||||
static bool ems_read_only_;
|
static bool ems_read_only_;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user