From 85786cbe8c354fdb364be853603d19196017b653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20=C3=96hrstr=C3=B6m?= Date: Wed, 11 Nov 2020 17:08:24 +0100 Subject: [PATCH] Fix bug that caused auto even though only a single device expected, like: rtlwmbus[1234] --- src/config.cc | 5 +++++ src/main.cc | 16 ++++++++++++---- src/wmbus.cc | 8 ++++++++ src/wmbus.h | 1 + 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/config.cc b/src/config.cc index a635851..d14398e 100644 --- a/src/config.cc +++ b/src/config.cc @@ -224,6 +224,11 @@ bool handleDevice(Configuration *c, string devicefile) { SpecifiedDevice specified_device; bool ok = specified_device.parse(devicefile); + if (!ok && SpecifiedDevice::isLikelyDevice(devicefile)) + { + error("Not a valid device \"%s\"\n", devicefile.c_str()); + } + if (ok) { // Number the devices diff --git a/src/main.cc b/src/main.cc index 6afd31a..6a50abe 100644 --- a/src/main.cc +++ b/src/main.cc @@ -889,8 +889,12 @@ void perform_auto_scan_of_serial_devices(Configuration *config) { // See if we had a specified device without a file, // that matches this detected device. - find_specified_device_and_update_detected(config, &detected); - open_wmbus_device_and_set_linkmodes(config, "auto", &detected); + bool found = find_specified_device_and_update_detected(config, &detected); + if (config->use_auto_device_detect || found) + { + // Open the device, only if auto is enabled, or if the device was specified. + open_wmbus_device_and_set_linkmodes(config, found?"config":"auto", &detected); + } } else { @@ -937,8 +941,12 @@ void perform_auto_scan_of_swradio_devices(Configuration *config) { // Use the serialnr as the id. detected.found_device_id = serialnr; - find_specified_device_and_update_detected(config, &detected); - open_wmbus_device_and_set_linkmodes(config, "auto", &detected); + bool found = find_specified_device_and_update_detected(config, &detected); + if (config->use_auto_device_detect || found) + { + // Open the device, only if auto is enabled, or if the device was specified. + open_wmbus_device_and_set_linkmodes(config, found?"config":"auto", &detected); + } } } } diff --git a/src/wmbus.cc b/src/wmbus.cc index 10a9dfe..9bf9959 100644 --- a/src/wmbus.cc +++ b/src/wmbus.cc @@ -4105,6 +4105,14 @@ string SpecifiedDevice::str() return r; } +bool SpecifiedDevice::isLikelyDevice(string &arg) +{ + // Only devices are allowed to contain colons. + // Devices usually contain a colon! + if (arg.find(":") != string::npos) return true; + return false; +} + bool SpecifiedDevice::parse(string &arg) { clear(); diff --git a/src/wmbus.h b/src/wmbus.h index 04d3684..9e9f832 100644 --- a/src/wmbus.h +++ b/src/wmbus.h @@ -164,6 +164,7 @@ struct SpecifiedDevice void clear(); string str(); bool parse(string &s); + static bool isLikelyDevice(string &s); }; struct Detected