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;
// 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<SerialDevice> 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);

Wyświetl plik

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

Wyświetl plik

@ -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)
{

Wyświetl plik

@ -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;

Wyświetl plik

@ -2150,20 +2150,23 @@ bool isValidBps(const string& b)
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;
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)

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);
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
{

Wyświetl plik

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