From f48b182dfb8344ff9464aa92d86c126057c70785 Mon Sep 17 00:00:00 2001 From: weetmuts Date: Fri, 6 Sep 2019 11:48:52 +0200 Subject: [PATCH] Make safe copy of Telegram for each potential meter listener. --- src/meter_apator162.cc | 10 +++++----- src/wmbus_amb8465.cc | 15 ++++++++++----- src/wmbus_im871a.cc | 8 ++++++-- src/wmbus_rtlwmbus.cc | 12 ++++++++---- src/wmbus_simulator.cc | 8 ++++++-- 5 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/meter_apator162.cc b/src/meter_apator162.cc index 44cbd5d..cf3a9b3 100644 --- a/src/meter_apator162.cc +++ b/src/meter_apator162.cc @@ -94,15 +94,15 @@ void MeterApator162::processContent(Telegram *t) string total; // Current assumption of this proprietary protocol is that byte 13 tells // us where the current total water consumption is located. - if (t->content[13] == 0x83 || t->content[13] == 0x82) { + if ((t->content[13] & 0x80) == 0x80) { strprintf(total, "%02x%02x%02x%02x", t->content[25], t->content[26], t->content[27], t->content[28]); - debug("(apator162) Found 0x83 at offset 13 expect location of current total to be at offset 25: %s\n", total.c_str()); + debug("(apator162) Found 0x80 bit set at offset 13 expect location of current total to be at offset 25: %s\n", total.c_str()); } - else if (t->content[13] == 0x10) { + else if ((t->content[13] & 0x10) == 0x10) { strprintf(total, "%02x%02x%02x%02x", t->content[14], t->content[15], t->content[16], t->content[17]); - debug("(apator162) Found 0x10 at offset 13 expect location of current total to be at offset 14: %s\n", total.c_str()); + debug("(apator162) Found bit 0x10 set at offset 13 expect location of current total to be at offset 14: %s\n", total.c_str()); } else { - warning("(apator162) Unknown value in proprietary(unknown) apator162 protocol. Found 0x%02x expected 0x10 or 0x83\n", t->content[13]); + warning("(apator162) Unknown value in proprietary(unknown) apator162 protocol. Found 0x%02x expected bit 0x10 or 0x80 to be set.\n", t->content[13]); } vendor_values["0413"] = { 25, DVEntry(0x13, 0, 0, 0, total) }; int offset; diff --git a/src/wmbus_amb8465.cc b/src/wmbus_amb8465.cc index debee37..4c5b47c 100644 --- a/src/wmbus_amb8465.cc +++ b/src/wmbus_amb8465.cc @@ -371,11 +371,16 @@ void WMBusAmber::handleMessage(int msgid, vector &frame) { Telegram t; t.parse(frame); - for (auto f : telegram_listeners_) { - if (f) f(&t); - if (isVerboseEnabled() && !t.handled) { - verbose("(amb8465) telegram ignored by all configured meters!\n"); - } + bool handled = false; + for (auto f : telegram_listeners_) + { + Telegram copy = t; + if (f) f(©); + if (copy.handled) handled = true; + } + if (isVerboseEnabled() && !handled) + { + verbose("(amb8465) telegram ignored by all configured meters!\n"); } break; } diff --git a/src/wmbus_im871a.cc b/src/wmbus_im871a.cc index 70ad266..33f3b88 100644 --- a/src/wmbus_im871a.cc +++ b/src/wmbus_im871a.cc @@ -528,11 +528,15 @@ void WMBusIM871A::handleRadioLink(int msgid, vector &payload) { Telegram t; t.parse(payload); + bool handled = false; for (auto f : telegram_listeners_) { - if (f) f(&t); + Telegram copy = t; + if (f) f(©); + if (copy.handled) handled = true; } - if (isVerboseEnabled() && !t.handled) { + if (isVerboseEnabled() && !handled) + { verbose("(im871a) telegram ignored by all configured meters!\n"); } } diff --git a/src/wmbus_rtlwmbus.cc b/src/wmbus_rtlwmbus.cc index e50c26a..1fd2b42 100644 --- a/src/wmbus_rtlwmbus.cc +++ b/src/wmbus_rtlwmbus.cc @@ -176,12 +176,16 @@ void WMBusRTLWMBUS::handleMessage(vector &frame) { Telegram t; t.parse(frame); + bool handled = false; for (auto f : telegram_listeners_) { - if (f) f(&t); - if (isVerboseEnabled() && !t.handled) { - verbose("(rtlwmbus) telegram ignored by all configured meters!\n"); - } + Telegram copy = t; + if (f) f(©); + if (copy.handled) handled = true; + } + if (isVerboseEnabled() && !handled) + { + verbose("(rtlwmbus) telegram ignored by all configured meters!\n"); } } diff --git a/src/wmbus_simulator.cc b/src/wmbus_simulator.cc index 4126c13..7d8a77a 100644 --- a/src/wmbus_simulator.cc +++ b/src/wmbus_simulator.cc @@ -186,10 +186,14 @@ void WMBusSimulator::simulate() Telegram t; t.parse(payload); t.markAsSimulated(); + bool handled = false; for (auto f : telegram_listeners_) { - if (f) f(&t); + Telegram copy = t; + if (f) f(©); + if (copy.handled) handled = true; } - if (isVerboseEnabled() && !t.handled) { + if (isVerboseEnabled() && !handled) + { verbose("(wmbus simulator) telegram ignored by all configured meters!\n"); } }