diff --git a/src/telegram.cpp b/src/telegram.cpp index 46d510567..29d078af1 100644 --- a/src/telegram.cpp +++ b/src/telegram.cpp @@ -148,7 +148,7 @@ void RxService::add(uint8_t * data, uint8_t length) { // validate the CRC. if it fails then increment the number of corrupt/incomplete telegrams and only report to console/syslog uint8_t crc = calculate_crc(data, length - 1); if (data[length - 1] != crc) { - if ((data[0] & 0x7F) != ems_bus_id()) { // do not count echos as errors + if (data[0] != EMSuart::last_tx_src()) { // do not count echos as errors telegram_error_count_++; LOG_WARNING("Incomplete Rx: %s", Helpers::data_to_hex(data, length).c_str()); // include CRC } else { diff --git a/src/uart/emsuart_esp32.cpp b/src/uart/emsuart_esp32.cpp index 89b55de45..0b9f2fccc 100644 --- a/src/uart/emsuart_esp32.cpp +++ b/src/uart/emsuart_esp32.cpp @@ -31,6 +31,7 @@ #include "emsesp.h" namespace emsesp { +uint8_t EMSuart::last_tx_src_ = 0; static QueueHandle_t uart_queue; uint8_t tx_mode_ = 0xFF; @@ -144,6 +145,8 @@ uint16_t EMSuart::transmit(const uint8_t * buf, const uint8_t len) { return EMS_TX_STATUS_OK; } + last_tx_src_ = len < 4 ? 0 : buf[0]; + if (tx_mode_ == EMS_TXMODE_HW) { // hardware controlled mode uart_write_bytes_with_break(EMSUART_NUM, buf, len, 10); return EMS_TX_STATUS_OK; diff --git a/src/uart/emsuart_esp32.h b/src/uart/emsuart_esp32.h index dcb31c49e..e2b5cd643 100644 --- a/src/uart/emsuart_esp32.h +++ b/src/uart/emsuart_esp32.h @@ -65,10 +65,14 @@ class EMSuart { static void send_poll(const uint8_t data); static void stop(); static uint16_t transmit(const uint8_t * buf, const uint8_t len); + static uint8_t last_tx_src() { + return last_tx_src_; + } private: static void IRAM_ATTR uart_gen_break(uint32_t length_us); static void uart_event_task(void * pvParameters); + static uint8_t last_tx_src_; }; } // namespace emsesp