From 586f7eecba02cf5f375e4757762a7cdf4c8d6223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20=C3=96hrstr=C3=B6m?= Date: Mon, 28 Nov 2022 01:13:44 +0100 Subject: [PATCH] Fix bug when detection amber dongles. No longer analyze telegram twice. --- src/bus.cc | 12 +++++++----- src/bus.h | 2 +- src/main.cc | 4 ++-- src/metermanager.cc | 13 ++++++++++--- src/util.cc | 9 ++++++--- src/util.h | 2 +- src/wmbus_amb8465.cc | 37 ++++++++++++++++++++++--------------- 7 files changed, 49 insertions(+), 30 deletions(-) diff --git a/src/bus.cc b/src/bus.cc index 07cf036..7d438a0 100644 --- a/src/bus.cc +++ b/src/bus.cc @@ -379,7 +379,7 @@ void BusManager::detectAndConfigureWmbusDevices(Configuration *config, Detection bool must_auto_find_rtlsdrs = false; // The device=auto has been specified.... - if (config->use_auto_device_detect && dt == DetectionType::ALL) + if (config->use_auto_device_detect && dt == DetectionType::ALL_BUT_SFS) { must_auto_find_ttys = true; must_auto_find_rtlsdrs = true; @@ -388,7 +388,7 @@ void BusManager::detectAndConfigureWmbusDevices(Configuration *config, Detection for (SpecifiedDevice &specified_device : config->supplied_bus_devices) { specified_device.handled = false; - if (dt != DetectionType::ALL) + if (dt != DetectionType::ALL_BUT_SFS) { if (specified_device.is_tty || (!specified_device.is_stdin && !specified_device.is_file && !specified_device.is_simulation)) { @@ -417,14 +417,16 @@ void BusManager::detectAndConfigureWmbusDevices(Configuration *config, Detection Detected detected = detectBusDeviceWithCommand(specified_device, config->default_device_linkmodes, serial_manager_); specified_device.handled = true; openBusDeviceAndPotentiallySetLinkmodes(config, "config", &detected); + continue; } - if (specified_device.hex != "") + if (specified_device.hex != "" && dt == DetectionType::STDIN_FILE_SIMULATION) { Detected detected = detectBusDeviceWithFileOrHex(specified_device, config->default_device_linkmodes, serial_manager_); openBusDeviceAndPotentiallySetLinkmodes(config, "config", &detected); specified_device.handled = true; + continue; } - if (specified_device.file != "") + if (specified_device.file != "" && dt == DetectionType::STDIN_FILE_SIMULATION) { shared_ptr sd = serial_manager_->lookup(specified_device.file); if (sd != NULL) @@ -510,7 +512,7 @@ void BusManager::detectAndConfigureWmbusDevices(Configuration *config, Detection for (SpecifiedDevice &specified_device : config->supplied_bus_devices) { - if (dt == DetectionType::ALL && !specified_device.handled) + if (dt == DetectionType::ALL_BUT_SFS && !specified_device.handled) { time_t last_alarm = specified_device.last_alarm; time_t now = time(NULL); diff --git a/src/bus.h b/src/bus.h index 5392371..bbe67c5 100644 --- a/src/bus.h +++ b/src/bus.h @@ -28,7 +28,7 @@ #include #include -enum class DetectionType { STDIN_FILE_SIMULATION, ALL }; +enum class DetectionType { STDIN_FILE_SIMULATION, ALL_BUT_SFS }; struct MeterManager; struct Configuration; diff --git a/src/main.cc b/src/main.cc index 9f6eeb3..c8f9dc4 100644 --- a/src/main.cc +++ b/src/main.cc @@ -426,7 +426,7 @@ void regular_checkup(Configuration *config) if (serial_manager_ && config) { - bus_manager_->detectAndConfigureWmbusDevices(config, DetectionType::ALL); + bus_manager_->detectAndConfigureWmbusDevices(config, DetectionType::ALL_BUT_SFS); } bus_manager_->regularCheckup(); @@ -559,7 +559,7 @@ bool start(Configuration *config) serial_manager_->startEventLoop(); - bus_manager_->detectAndConfigureWmbusDevices(config, DetectionType::ALL); + bus_manager_->detectAndConfigureWmbusDevices(config, DetectionType::ALL_BUT_SFS); if (bus_manager_->numBusDevices() == 0) { diff --git a/src/metermanager.cc b/src/metermanager.cc index 9038f0f..72d4149 100644 --- a/src/metermanager.cc +++ b/src/metermanager.cc @@ -384,7 +384,7 @@ public: mi.idsc = t.ids.back(); // This will be the driver that will actually decode and print with. - string using_driver = ""; + string using_driver = "auto"; int using_length = 0; int using_understood = 0; @@ -393,9 +393,14 @@ public: int best_understood = 0; string best_driver = findBestNewStyleDriver(mi, &best_length, &best_understood, t, about, input_frame, simulated, ""); - mi.driver_name = DriverName(""); + mi.driver_name = DriverName(best_driver); - // Use the existing mapping from mfct/media/version to driver. + // Default to best driver.... + using_driver = best_driver; + using_length = best_length; + using_understood = best_understood; + + // Unless the existing mapping from mfct/media/version to driver overrides best. DriverInfo auto_di = pickMeterDriver(&t); string auto_driver = auto_di.name().str(); @@ -422,6 +427,8 @@ public: auto meter = createMeter(&mi); + assert(meter != NULL); + bool match = false; string id; diff --git a/src/util.cc b/src/util.cc index 915a1e5..61b9add 100644 --- a/src/util.cc +++ b/src/util.cc @@ -2150,20 +2150,23 @@ bool isValidBps(const string& b) return false; } -size_t findBytes(vector &v, uchar a, uchar b, uchar c) +bool findBytes(vector &v, uchar a, uchar b, uchar c, size_t *out) { size_t p = 0; + while (p+2 < v.size()) { if (v[p+0] == a && v[p+1] == b && v[p+2] == c) { - return p; + *out = p; + return true; } p++; } - return (size_t)-1; + *out = 999999; + return false; } string reverseBCD(const string& v) diff --git a/src/util.h b/src/util.h index 3615c1c..b140215 100644 --- a/src/util.h +++ b/src/util.h @@ -261,7 +261,7 @@ std::string lookForExecutable(const std::string& prog, std::string bin_dir, std: bool parseExtras(const std::string& s, std::map *extras); void checkIfMultipleWmbusMetersRunning(); -size_t findBytes(std::vector &v, uchar a, uchar b, uchar c); +bool findBytes(std::vector &v, uchar a, uchar b, uchar c, size_t *out); enum class OutputFormat { diff --git a/src/wmbus_amb8465.cc b/src/wmbus_amb8465.cc index 3497b0f..2cc17d8 100644 --- a/src/wmbus_amb8465.cc +++ b/src/wmbus_amb8465.cc @@ -1084,11 +1084,12 @@ AccessCheck detectAMB8465AMB3665(Detected *detected, shared_ptr