Fix bug when detection amber dongles. No longer analyze telegram twice.

pull/708/head
Fredrik Öhrström 2022-11-28 01:13:44 +01:00
rodzic 9ce4328d24
commit 586f7eecba
7 zmienionych plików z 49 dodań i 30 usunięć

Wyświetl plik

@ -379,7 +379,7 @@ void BusManager::detectAndConfigureWmbusDevices(Configuration *config, Detection
bool must_auto_find_rtlsdrs = false; bool must_auto_find_rtlsdrs = false;
// The device=auto has been specified.... // 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_ttys = true;
must_auto_find_rtlsdrs = true; must_auto_find_rtlsdrs = true;
@ -388,7 +388,7 @@ void BusManager::detectAndConfigureWmbusDevices(Configuration *config, Detection
for (SpecifiedDevice &specified_device : config->supplied_bus_devices) for (SpecifiedDevice &specified_device : config->supplied_bus_devices)
{ {
specified_device.handled = false; 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)) 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_); Detected detected = detectBusDeviceWithCommand(specified_device, config->default_device_linkmodes, serial_manager_);
specified_device.handled = true; specified_device.handled = true;
openBusDeviceAndPotentiallySetLinkmodes(config, "config", &detected); 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_); Detected detected = detectBusDeviceWithFileOrHex(specified_device, config->default_device_linkmodes, serial_manager_);
openBusDeviceAndPotentiallySetLinkmodes(config, "config", &detected); openBusDeviceAndPotentiallySetLinkmodes(config, "config", &detected);
specified_device.handled = true; specified_device.handled = true;
continue;
} }
if (specified_device.file != "") if (specified_device.file != "" && dt == DetectionType::STDIN_FILE_SIMULATION)
{ {
shared_ptr<SerialDevice> sd = serial_manager_->lookup(specified_device.file); shared_ptr<SerialDevice> sd = serial_manager_->lookup(specified_device.file);
if (sd != NULL) if (sd != NULL)
@ -510,7 +512,7 @@ void BusManager::detectAndConfigureWmbusDevices(Configuration *config, Detection
for (SpecifiedDevice &specified_device : config->supplied_bus_devices) 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 last_alarm = specified_device.last_alarm;
time_t now = time(NULL); time_t now = time(NULL);

Wyświetl plik

@ -28,7 +28,7 @@
#include<set> #include<set>
#include<string> #include<string>
enum class DetectionType { STDIN_FILE_SIMULATION, ALL }; enum class DetectionType { STDIN_FILE_SIMULATION, ALL_BUT_SFS };
struct MeterManager; struct MeterManager;
struct Configuration; struct Configuration;

Wyświetl plik

@ -426,7 +426,7 @@ void regular_checkup(Configuration *config)
if (serial_manager_ && config) if (serial_manager_ && config)
{ {
bus_manager_->detectAndConfigureWmbusDevices(config, DetectionType::ALL); bus_manager_->detectAndConfigureWmbusDevices(config, DetectionType::ALL_BUT_SFS);
} }
bus_manager_->regularCheckup(); bus_manager_->regularCheckup();
@ -559,7 +559,7 @@ bool start(Configuration *config)
serial_manager_->startEventLoop(); serial_manager_->startEventLoop();
bus_manager_->detectAndConfigureWmbusDevices(config, DetectionType::ALL); bus_manager_->detectAndConfigureWmbusDevices(config, DetectionType::ALL_BUT_SFS);
if (bus_manager_->numBusDevices() == 0) if (bus_manager_->numBusDevices() == 0)
{ {

Wyświetl plik

@ -384,7 +384,7 @@ public:
mi.idsc = t.ids.back(); mi.idsc = t.ids.back();
// This will be the driver that will actually decode and print with. // 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_length = 0;
int using_understood = 0; int using_understood = 0;
@ -393,9 +393,14 @@ public:
int best_understood = 0; int best_understood = 0;
string best_driver = findBestNewStyleDriver(mi, &best_length, &best_understood, t, about, input_frame, simulated, ""); 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); DriverInfo auto_di = pickMeterDriver(&t);
string auto_driver = auto_di.name().str(); string auto_driver = auto_di.name().str();
@ -422,6 +427,8 @@ public:
auto meter = createMeter(&mi); auto meter = createMeter(&mi);
assert(meter != NULL);
bool match = false; bool match = false;
string id; string id;

Wyświetl plik

@ -2150,20 +2150,23 @@ bool isValidBps(const string& b)
return false; return false;
} }
size_t findBytes(vector<uchar> &v, uchar a, uchar b, uchar c) bool findBytes(vector<uchar> &v, uchar a, uchar b, uchar c, size_t *out)
{ {
size_t p = 0; size_t p = 0;
while (p+2 < v.size()) while (p+2 < v.size())
{ {
if (v[p+0] == a && if (v[p+0] == a &&
v[p+1] == b && v[p+1] == b &&
v[p+2] == c) v[p+2] == c)
{ {
return p; *out = p;
return true;
} }
p++; p++;
} }
return (size_t)-1; *out = 999999;
return false;
} }
string reverseBCD(const string& v) string reverseBCD(const string& v)

Wyświetl plik

@ -261,7 +261,7 @@ std::string lookForExecutable(const std::string& prog, std::string bin_dir, std:
bool parseExtras(const std::string& s, std::map<std::string,std::string> *extras); bool parseExtras(const std::string& s, std::map<std::string,std::string> *extras);
void checkIfMultipleWmbusMetersRunning(); void checkIfMultipleWmbusMetersRunning();
size_t findBytes(std::vector<uchar> &v, uchar a, uchar b, uchar c); bool findBytes(std::vector<uchar> &v, uchar a, uchar b, uchar c, size_t *out);
enum class OutputFormat enum class OutputFormat
{ {

Wyświetl plik

@ -1084,11 +1084,12 @@ AccessCheck detectAMB8465AMB3665(Detected *detected, shared_ptr<SerialCommunicat
continue; continue;
} }
response.insert(response.end(), data.begin(), data.end()); response.insert(response.end(), data.begin(), data.end());
size_t offset_8465 = findBytes(response, 0xff, 0x8A, 0x7A); size_t offset_8465;
size_t offset_3665 = findBytes(response, 0xff, 0x8A, 0x82); size_t offset_3665;
bool got_8465 = findBytes(response, 0xff, 0x8A, 0x7A, &offset_8465);
bool got_3665 = findBytes(response, 0xff, 0x8A, 0x82, &offset_3665);
if (offset_8465 == ((size_t)-1) && if (!got_8465 && !got_3665)
offset_3665 == ((size_t)-1))
{ {
// No response found yet, lets wait for more bytes. // No response found yet, lets wait for more bytes.
usleep(1000*100); usleep(1000*100);
@ -1096,18 +1097,24 @@ AccessCheck detectAMB8465AMB3665(Detected *detected, shared_ptr<SerialCommunicat
} }
// We have the start of the response, but do we have enough bytes? // We have the start of the response, but do we have enough bytes?
ok_8465 = config.decode8465(response, offset_8465); if (got_8465)
// Yes! {
if (ok_8465) { ok_8465 = config.decode8465(response, offset_8465);
debug("(amb8465) found response at offset %zu\n", offset_8465); // Yes!
break; if (ok_8465) {
debug("(amb8465) found response at offset %zu\n", offset_8465);
break;
}
} }
// We have the start of the response, but do we have enough bytes? if (got_3665)
ok_3665 = config.decode3665(response, offset_3665); {
// Yes! // We have the start of the response, but do we have enough bytes?
if (ok_3665) { ok_3665 = config.decode3665(response, offset_3665);
debug("(amb3665) found response at offset %zu\n", offset_3665); // Yes!
break; if (ok_3665) {
debug("(amb3665) found response at offset %zu\n", offset_3665);
break;
}
} }
// No complete response found yet, lets wait for more bytes. // No complete response found yet, lets wait for more bytes.
usleep(1000*100); usleep(1000*100);