From 81f1fd448b55ee52bdd479a05eb53fee13bb0271 Mon Sep 17 00:00:00 2001 From: weetmuts Date: Tue, 19 Mar 2019 21:32:28 +0100 Subject: [PATCH] Cleanups. --- src/meter_amiplus.cc | 5 +---- src/meter_apator162.cc | 8 +------- src/meter_iperl.cc | 8 +------- src/meter_multical21.cc | 8 +------- src/meter_omnipower.cc | 5 +---- src/meter_qcaloric.cc | 5 +---- src/meter_supercom587.cc | 8 +------- src/meters.cc | 9 +++++---- src/wmbus.cc | 7 +++++++ src/wmbus.h | 2 ++ 10 files changed, 21 insertions(+), 44 deletions(-) diff --git a/src/meter_amiplus.cc b/src/meter_amiplus.cc index 3c52f10..7a10fab 100644 --- a/src/meter_amiplus.cc +++ b/src/meter_amiplus.cc @@ -78,10 +78,7 @@ void MeterAmiplus::handleTelegram(Telegram *t) { t->a_field_address[0], t->a_field_address[1], t->a_field_address[2], t->a_field_address[3]); - if (t->a_field_version != 0x02) { - warning("(amiplus) expected telegram from APA meter with version 0x01, but got \"%s\" version 0x2x !\n", - manufacturerFlag(t->m_field).c_str(), t->a_field_version); - } + t->expectVersion("amiplus", 0x02); if (t->isEncrypted() && !useAes() && !t->isSimulated()) { warning("(amiplus) warning: telegram is encrypted but no key supplied!\n"); diff --git a/src/meter_apator162.cc b/src/meter_apator162.cc index 09edb85..6540e53 100644 --- a/src/meter_apator162.cc +++ b/src/meter_apator162.cc @@ -99,13 +99,7 @@ void MeterApator162::handleTelegram(Telegram *t) t->a_field_address[0], t->a_field_address[1], t->a_field_address[2], t->a_field_address[3]); - if (t->a_field_version != 0x05) { - warning("(%s) expected telegram from APA meter with version 0x%02x, " - "but got \"%s\" meter with version 0x%02x !\n", "apator162", - 0x05, - manufacturerFlag(t->m_field).c_str(), - t->a_field_version); - } + t->expectVersion("apator162", 0x05); if (t->isEncrypted() && !useAes() && !t->isSimulated()) { warning("(apator162) warning: telegram is encrypted but no key supplied!\n"); diff --git a/src/meter_iperl.cc b/src/meter_iperl.cc index 7bef003..55117b3 100644 --- a/src/meter_iperl.cc +++ b/src/meter_iperl.cc @@ -101,13 +101,7 @@ void MeterIperl::handleTelegram(Telegram *t) t->a_field_address[0], t->a_field_address[1], t->a_field_address[2], t->a_field_address[3]); - if (t->a_field_version != 0x68) { - warning("(%s) expected telegram from SEN meter with version 0x%02x, " - "but got \"%s\" meter with version 0x%02x !\n", "iperl", - 0x68, - manufacturerFlag(t->m_field).c_str(), - t->a_field_version); - } + t->expectVersion("iperl", 0x68); if (t->isEncrypted() && !useAes() && !t->isSimulated()) { warning("(iperl) warning: telegram is encrypted but no key supplied!\n"); diff --git a/src/meter_multical21.cc b/src/meter_multical21.cc index 20984c6..a082ce3 100644 --- a/src/meter_multical21.cc +++ b/src/meter_multical21.cc @@ -202,13 +202,7 @@ void MeterMultical21::handleTelegram(Telegram *t) t->a_field_address[0], t->a_field_address[1], t->a_field_address[2], t->a_field_address[3]); - if (t->a_field_version != expected_version_) { - warning("(%s) expected telegram from KAM meter with version 0x%02x, " - "but got \"%s\" meter with version 0x%02x !\n", meter_name_, - expected_version_, - manufacturerFlag(t->m_field).c_str(), - t->a_field_version); - } + t->expectVersion(name().c_str(), expected_version_); if (useAes()) { vector aeskey = key(); diff --git a/src/meter_omnipower.cc b/src/meter_omnipower.cc index 0ae6bbc..225e14e 100644 --- a/src/meter_omnipower.cc +++ b/src/meter_omnipower.cc @@ -78,10 +78,7 @@ void MeterOmnipower::handleTelegram(Telegram *t) { t->a_field_address[0], t->a_field_address[1], t->a_field_address[2], t->a_field_address[3]); - if (t->a_field_version != 0x01) { - warning("(omnipower) expected telegram from KAM meter with version 0x01, but got \"%s\" version 0x2x !\n", - manufacturerFlag(t->m_field).c_str(), t->a_field_version); - } + t->expectVersion("omnipower", 0x01); if (t->isEncrypted() && !useAes() && !t->isSimulated()) { warning("(omnipower) warning: telegram is encrypted but no key supplied!\n"); diff --git a/src/meter_qcaloric.cc b/src/meter_qcaloric.cc index e7be853..5add64a 100644 --- a/src/meter_qcaloric.cc +++ b/src/meter_qcaloric.cc @@ -93,10 +93,7 @@ void MeterQCaloric::handleTelegram(Telegram *t) { t->a_field_address[0], t->a_field_address[1], t->a_field_address[2], t->a_field_address[3]); - if (t->a_field_version != 0x35) { - warning("(qcaloric) expected telegram from QDS meter with version 0x35, but got \"%s\" version 0x%02x !\n", - manufacturerFlag(t->m_field).c_str(), t->a_field_version); - } + t->expectVersion("qcaloric", 0x35); if (t->isEncrypted() && !useAes() && !t->isSimulated()) { warning("(qcaloric) warning: telegram is encrypted but no key supplied!\n"); diff --git a/src/meter_supercom587.cc b/src/meter_supercom587.cc index 1818253..a80c5fd 100644 --- a/src/meter_supercom587.cc +++ b/src/meter_supercom587.cc @@ -99,13 +99,7 @@ void MeterSupercom587::handleTelegram(Telegram *t) t->a_field_address[0], t->a_field_address[1], t->a_field_address[2], t->a_field_address[3]); - if (t->a_field_version != 0x3c) { - warning("(%s) expected telegram from SON meter with version 0x%02x, " - "but got \"%s\" meter with version 0x%02x !\n", "supercom587", - 0x3c, - manufacturerFlag(t->m_field).c_str(), - t->a_field_version); - } + t->expectVersion("supercom587", 0x3c); if (t->isEncrypted() && !useAes() && !t->isSimulated()) { warning("(supercom587) warning: telegram is encrypted but no key supplied!\n"); diff --git a/src/meters.cc b/src/meters.cc index 4960dce..9552825 100644 --- a/src/meters.cc +++ b/src/meters.cc @@ -150,13 +150,15 @@ bool MeterCommonImplementation::isTelegramForMe(Telegram *t) } if (!id_match) { + // The id must match. debug("(meter) %s: not for me: not my id\n", name_.c_str()); return false; } if (manufacturer_ != 0 && t->m_field != manufacturer_) { - debug("(meter) %s: not for me: manufacturer differs\n", name_.c_str()); - return false; + // We are not that strict for the manufacturer. + // Simply warn. + warning("(meter) %s: probably not for me since manufacturer differs\n", name_.c_str()); } bool media_match = false; @@ -168,8 +170,7 @@ bool MeterCommonImplementation::isTelegramForMe(Telegram *t) } if (!media_match) { - debug("(meter) %s: not for me: no media match\n", name_.c_str()); - return false; + warning("(meter) %s: probably not for me since media does not match\n", name_.c_str()); } debug("(meter) %s: yes for me\n", name_.c_str()); diff --git a/src/wmbus.cc b/src/wmbus.cc index d518c1e..3ec5989 100644 --- a/src/wmbus.cc +++ b/src/wmbus.cc @@ -458,6 +458,13 @@ void Telegram::explainParse(string intro, int from) debug("%s %s\n", intro.c_str(), hex.c_str()); } +void Telegram::expectVersion(const char *info, int v) +{ + if (a_field_version != v) { + warning("(%s) expected telegram with version 0x%02x, but got version 0x%02x !\n", info, v, a_field_version); + } +} + string cType(int c_field) { switch (c_field) { diff --git a/src/wmbus.h b/src/wmbus.h index 42bed51..34a4a5c 100644 --- a/src/wmbus.h +++ b/src/wmbus.h @@ -111,6 +111,8 @@ struct Telegram { void markAsSimulated() { is_simulated_ = true; } + void expectVersion(const char *info, int v); + private: bool is_encrypted_ {};