Compare commits

...

4 Commits

Author SHA1 Message Date
Tomer27cz 8d5caa54f1 raw dump as cpp array 2026-03-19 18:54:25 +01:00
Tomer27cz 7d8699963c set dump raw 2026-03-19 18:49:42 +01:00
Tomer27cz b4785b77df typo 2026-03-19 18:46:06 +01:00
Tomer27cz 6240f5455f add dump raw option 2026-03-19 18:44:50 +01:00
3 changed files with 23 additions and 0 deletions

View File

@ -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,
}
)
@ -43,4 +45,5 @@ async def to_code(config):
# Apply configuration to the C++ component
cg.add(var.set_receive_timeout(config[CONF_RECEIVE_TIMEOUT]))
cg.add(var.set_show_log(config[CONF_SHOW_LOG]))
cg.add(var.set_dump_raw(config[CONF_DUMP_RAW]))
cg.add(var.set_custom_pattern(config[CONF_CUSTOM_PATTERN]))

View File

@ -96,6 +96,24 @@ void DlmsPushComponent::process_frame_() {
ESP_LOGD(TAG, "PUSH frame size: %zu bytes", this->rx_buffer_len_);
}
if (this->dump_raw_) {
ESP_LOGD(TAG, "--- BEGIN C++ ARRAY DUMP ---");
ESP_LOGD(TAG, "const uint8_t raw_frame[%zu] = {", this->rx_buffer_len_);
// Process 16 bytes per line to safely avoid logger truncation limits
for (size_t i = 0; i < this->rx_buffer_len_; i += 16) {
std::string line = " ";
for (size_t j = 0; j < 16 && (i + j) < this->rx_buffer_len_; j++) {
char buf[8];
snprintf(buf, sizeof(buf), "0x%02X, ", this->rx_buffer_[i + j]);
line += buf;
}
ESP_LOGD(TAG, "%s", line.c_str());
}
ESP_LOGD(TAG, "};");
ESP_LOGD(TAG, "--- END C++ ARRAY 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);
};

View File

@ -34,6 +34,7 @@ class DlmsPushComponent : public Component, public uart::UARTDevice {
void set_receive_timeout(uint32_t timeout_ms) { this->receive_timeout_ms_ = timeout_ms; }
void set_show_log(bool show_log) { this->show_log_ = show_log; }
void set_dump_raw(bool dump_raw) { this->dump_raw_ = dump_raw; }
void set_custom_pattern(const std::string &pattern) { this->custom_pattern_ = pattern; }
#ifdef USE_SENSOR
@ -54,6 +55,7 @@ class DlmsPushComponent : public Component, public uart::UARTDevice {
uint32_t receive_timeout_ms_{50};
bool show_log_{false};
bool dump_raw_{false};
std::string custom_pattern_{""};
static const size_t MAX_RX_BUFFER_SIZE = 2048;