diff --git a/components/dlms_push/__init__.py b/components/dlms_push/__init__.py index e07e924..d3691c9 100644 --- a/components/dlms_push/__init__.py +++ b/components/dlms_push/__init__.py @@ -8,6 +8,7 @@ DEPENDENCIES = ["uart"] CONF_RECEIVE_TIMEOUT = "receive_timeout" CONF_SHOW_LOG = "show_log" +CONF_DUMP_RAW = "dump_raw" CONF_CUSTOM_PATTERN = "custom_pattern" # Define the namespace and the Hub component class @@ -28,6 +29,7 @@ CONFIG_SCHEMA = cv.All( cv.GenerateID(): cv.declare_id(DlmsPushComponent), cv.Optional(CONF_RECEIVE_TIMEOUT, default="50ms"): cv.positive_time_period_milliseconds, cv.Optional(CONF_SHOW_LOG, default=False): cv.boolean, + cv.Optional(CONF_DUMP_RAW, default=False): cv.boolean, cv.Optional(CONF_CUSTOM_PATTERN, default=""): cv.string, } ) diff --git a/components/dlms_push/dlms_push.cpp b/components/dlms_push/dlms_push.cpp index 34d6703..ce48f1d 100644 --- a/components/dlms_push/dlms_push.cpp +++ b/components/dlms_push/dlms_push.cpp @@ -96,6 +96,20 @@ void DlmsPushComponent::process_frame_() { ESP_LOGD(TAG, "PUSH frame size: %zu bytes", this->rx_buffer_len_); } + if (this->dump_raw_) { + ESP_LOGD(TAG, "--- BEGIN RAW DUMP ---"); + for (size_t i = 0; i < this->rx_buffer_len_; i += 32) { + std::string line; + for (size_t j = 0; j < 32 && (i + j) < this->rx_buffer_len_; j++) { + char buf[4]; + snprintf(buf, sizeof(buf), "%02X ", this->rx_buffer_[i + j]); + line += buf; + } + ESP_LOGD(TAG, "%04X: %s", (unsigned int)i, line.c_str()); + } + ESP_LOGD(TAG, "--- END RAW DUMP ---"); + } + auto callback = [this](const char *obis_code, float float_val, const char *str_val, bool is_numeric) { this->on_data_parsed_(obis_code, float_val, str_val, is_numeric); }; diff --git a/components/dlms_push/dlms_push.h b/components/dlms_push/dlms_push.h index aade383..eac2c9f 100644 --- a/components/dlms_push/dlms_push.h +++ b/components/dlms_push/dlms_push.h @@ -54,6 +54,7 @@ class DlmsPushComponent : public Component, public uart::UARTDevice { uint32_t receive_timeout_ms_{50}; bool show_log_{false}; + bool cump_raw_{false}; std::string custom_pattern_{""}; static const size_t MAX_RX_BUFFER_SIZE = 2048;