Compare commits
4 Commits
c9bbbd574c
...
8d5caa54f1
| Author | SHA1 | Date |
|---|---|---|
|
|
8d5caa54f1 | |
|
|
7d8699963c | |
|
|
b4785b77df | |
|
|
6240f5455f |
|
|
@ -8,6 +8,7 @@ DEPENDENCIES = ["uart"]
|
||||||
|
|
||||||
CONF_RECEIVE_TIMEOUT = "receive_timeout"
|
CONF_RECEIVE_TIMEOUT = "receive_timeout"
|
||||||
CONF_SHOW_LOG = "show_log"
|
CONF_SHOW_LOG = "show_log"
|
||||||
|
CONF_DUMP_RAW = "dump_raw"
|
||||||
CONF_CUSTOM_PATTERN = "custom_pattern"
|
CONF_CUSTOM_PATTERN = "custom_pattern"
|
||||||
|
|
||||||
# Define the namespace and the Hub component class
|
# Define the namespace and the Hub component class
|
||||||
|
|
@ -28,6 +29,7 @@ CONFIG_SCHEMA = cv.All(
|
||||||
cv.GenerateID(): cv.declare_id(DlmsPushComponent),
|
cv.GenerateID(): cv.declare_id(DlmsPushComponent),
|
||||||
cv.Optional(CONF_RECEIVE_TIMEOUT, default="50ms"): cv.positive_time_period_milliseconds,
|
cv.Optional(CONF_RECEIVE_TIMEOUT, default="50ms"): cv.positive_time_period_milliseconds,
|
||||||
cv.Optional(CONF_SHOW_LOG, default=False): cv.boolean,
|
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,
|
cv.Optional(CONF_CUSTOM_PATTERN, default=""): cv.string,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
@ -43,4 +45,5 @@ async def to_code(config):
|
||||||
# Apply configuration to the C++ component
|
# Apply configuration to the C++ component
|
||||||
cg.add(var.set_receive_timeout(config[CONF_RECEIVE_TIMEOUT]))
|
cg.add(var.set_receive_timeout(config[CONF_RECEIVE_TIMEOUT]))
|
||||||
cg.add(var.set_show_log(config[CONF_SHOW_LOG]))
|
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]))
|
cg.add(var.set_custom_pattern(config[CONF_CUSTOM_PATTERN]))
|
||||||
|
|
@ -96,6 +96,24 @@ void DlmsPushComponent::process_frame_() {
|
||||||
ESP_LOGD(TAG, "PUSH frame size: %zu bytes", this->rx_buffer_len_);
|
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) {
|
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);
|
this->on_data_parsed_(obis_code, float_val, str_val, is_numeric);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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_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_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; }
|
void set_custom_pattern(const std::string &pattern) { this->custom_pattern_ = pattern; }
|
||||||
|
|
||||||
#ifdef USE_SENSOR
|
#ifdef USE_SENSOR
|
||||||
|
|
@ -54,6 +55,7 @@ class DlmsPushComponent : public Component, public uart::UARTDevice {
|
||||||
|
|
||||||
uint32_t receive_timeout_ms_{50};
|
uint32_t receive_timeout_ms_{50};
|
||||||
bool show_log_{false};
|
bool show_log_{false};
|
||||||
|
bool dump_raw_{false};
|
||||||
std::string custom_pattern_{""};
|
std::string custom_pattern_{""};
|
||||||
|
|
||||||
static const size_t MAX_RX_BUFFER_SIZE = 2048;
|
static const size_t MAX_RX_BUFFER_SIZE = 2048;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue