From 312fd854696356bf41e4494af03ac89b1464410d Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Mon, 10 May 2021 13:40:11 +0200 Subject: [PATCH] prevent multiple reading of long messages with no offset --- src/emsesp.cpp | 4 +++- src/telegram.cpp | 5 ++++- src/telegram.h | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/emsesp.cpp b/src/emsesp.cpp index 4194d7e04..4525cbeab 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -1061,6 +1061,8 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) { // get_uptime is only updated once per loop, does not give the right time LOG_TRACE(F("[UART_DEBUG] Echo after %d ms: %s"), ::millis() - rx_time_, Helpers::data_to_hex(data, length).c_str()); #endif + // add to RxQueue for log/watch + rxservice_.add(data, length); return; // it's an echo } @@ -1096,7 +1098,7 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) { tx_successful = true; // if telegram is longer read next part with offset + 25 for ems+ if (length == 32) { - if (txservice_.read_next_tx() == read_id_) { + if (txservice_.read_next_tx(data[3]) == read_id_) { read_next_ = true; } } diff --git a/src/telegram.cpp b/src/telegram.cpp index 39588aaa3..1d5893b3a 100644 --- a/src/telegram.cpp +++ b/src/telegram.cpp @@ -590,9 +590,12 @@ void TxService::retry_tx(const uint8_t operation, const uint8_t * data, const ui tx_telegrams_.emplace_front(tx_telegram_id_++, std::move(telegram_last_), true, get_post_send_query()); } -uint16_t TxService::read_next_tx() { +uint16_t TxService::read_next_tx(uint8_t offset) { // add to the top/front of the queue uint8_t message_data[1] = {EMS_MAX_TELEGRAM_LENGTH}; // request all data, 32 bytes + if (telegram_last_->offset != offset) { + return 0; + } add(Telegram::Operation::TX_READ, telegram_last_->dest, telegram_last_->type_id, telegram_last_->offset + 25, message_data, 1, 0, true); return telegram_last_->type_id; } diff --git a/src/telegram.h b/src/telegram.h index 7891a1090..df9401c87 100644 --- a/src/telegram.h +++ b/src/telegram.h @@ -283,7 +283,7 @@ class TxService : public EMSbus { void retry_tx(const uint8_t operation, const uint8_t * data, const uint8_t length); bool is_last_tx(const uint8_t src, const uint8_t dest) const; uint16_t post_send_query(); - uint16_t read_next_tx(); + uint16_t read_next_tx(uint8_t offset); uint8_t retry_count() const { return retry_count_;