Skip to content

Commit

Permalink
fix emsesp#282, check received status before toggling fetch-flag on e…
Browse files Browse the repository at this point in the history
…mpty telegrams.
  • Loading branch information
MichaelDvP committed Jan 10, 2022
1 parent ff6738e commit b4f9302
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/emsdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1339,17 +1339,17 @@ const std::string EMSdevice::telegram_type_name(std::shared_ptr<const Telegram>
// take a telegram_type_id and call the matching handler
// return true if match found
bool EMSdevice::handle_telegram(std::shared_ptr<const Telegram> 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);
}

Expand Down
4 changes: 3 additions & 1 deletion src/emsdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
};
Expand Down

0 comments on commit b4f9302

Please sign in to comment.