From b4f9302d4c87836ce19ca659dd9ee7ba8b37a93b Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Mon, 10 Jan 2022 08:48:50 +0100 Subject: [PATCH] fix #282, check received status before toggling fetch-flag on empty telegrams. --- src/emsdevice.cpp | 14 +++++++------- src/emsdevice.h | 4 +++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index 55d8698bb..d288c3fc4 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -452,7 +452,7 @@ void EMSdevice::show_mqtt_handlers(uuid::console::Shell & shell) { // register a callback function for a specific telegram type void EMSdevice::register_telegram_type(const uint16_t telegram_type_id, const __FlashStringHelper * telegram_type_name, bool fetch, const process_function_p f) { - telegram_functions_.emplace_back(telegram_type_id, telegram_type_name, fetch, f); + telegram_functions_.emplace_back(telegram_type_id, telegram_type_name, fetch, false, f); } // add to device value library, also know now as a "device entity" @@ -1339,17 +1339,17 @@ const std::string EMSdevice::telegram_type_name(std::shared_ptr // take a telegram_type_id and call the matching handler // return true if match found bool EMSdevice::handle_telegram(std::shared_ptr telegram) { - for (const auto & tf : telegram_functions_) { + for (auto & tf : telegram_functions_) { if (tf.telegram_type_id_ == telegram->type_id) { - // if the data block is empty, assume that this telegram is not recognized by the bus master - // so remove it from the automatic fetch list - if (telegram->message_length == 0 && telegram->offset == 0) { + // if the data block is empty and we have not received data before, assume that this telegram + // is not recognized by the bus master. So remove it from the automatic fetch list + if (telegram->message_length == 0 && telegram->offset == 0 && !tf.received_) { EMSESP::logger().debug(F("This telegram (%s) is not recognized by the EMS bus"), read_flash_string(tf.telegram_type_name_).c_str()); - toggle_fetch(tf.telegram_type_id_, false); + tf.fetch_ = false; return false; } - if (telegram->message_length > 0) { + tf.received_ = true; tf.process_function_(telegram); } diff --git a/src/emsdevice.h b/src/emsdevice.h index b96d81d6b..5326efa0b 100644 --- a/src/emsdevice.h +++ b/src/emsdevice.h @@ -379,12 +379,14 @@ class EMSdevice { uint16_t telegram_type_id_; // it's type_id const __FlashStringHelper * telegram_type_name_; // e.g. RC20Message bool fetch_; // if this type_id be queried automatically + bool received_; process_function_p process_function_; - TelegramFunction(uint16_t telegram_type_id, const __FlashStringHelper * telegram_type_name, bool fetch, const process_function_p process_function) + TelegramFunction(uint16_t telegram_type_id, const __FlashStringHelper * telegram_type_name, bool fetch, bool received, const process_function_p process_function) : telegram_type_id_(telegram_type_id) , telegram_type_name_(telegram_type_name) , fetch_(fetch) + , received_(received) , process_function_(process_function) { } };