Improve analyze so that it tests more relevant drivers.

pull/455/head
Fredrik Öhrström 2022-01-25 21:21:17 +01:00
rodzic c22e58f595
commit 349524d547
2 zmienionych plików z 38 dodań i 0 usunięć

Wyświetl plik

@ -43,6 +43,15 @@ bool DriverInfo::detect(uint16_t mfct, uchar type, uchar version)
return false;
}
bool DriverInfo::isValidMedia(uchar type)
{
for (auto &dd : detect_)
{
if (dd.type == type) return true;
}
return false;
}
void DriverInfo::setExpectedELLSecurityMode(ELLSecurityMode dsm)
{
// TODO should check that the telegram is encrypted using the same mode.
@ -389,6 +398,13 @@ LIST_OF_METERS
{
if (dr == MeterDriver::AUTO) continue;
if (dr == MeterDriver::UNKNOWN) continue;
if (!isMeterDriverReasonableForMedia(dr, "", t.dll_type) &&
!isMeterDriverReasonableForMedia(dr, "", t.tpl_type))
{
// Skip this driver since it is not relevant for this media.
continue;
}
string driver_name = toString(dr);
debug("Testing driver %s...\n", driver_name.c_str());
mi.driver = dr;
@ -1707,6 +1723,24 @@ METER_DETECTION
return false;
}
bool isMeterDriverReasonableForMedia(MeterDriver type, string driver_name, int media)
{
if (media == 0x37) return false; // Skip converter meter side since they do not give any useful information.
#define X(TY,MA,ME,VE) { if (type == MeterDriver::TY && media == ME) { return true; }}
METER_DETECTION
#undef X
for (auto &p : all_registered_drivers_)
{
if (p.first == "driver_name" && p.second.isValidMedia(media))
{
return true;
}
}
return false;
}
vector<DriverInfo>& allRegisteredDrivers()
{
return all_registered_drivers_list_;

Wyświetl plik

@ -144,6 +144,9 @@ void detectMeterDrivers(int manufacturer, int media, int version, std::vector<st
// When entering the driver, check that the telegram is indeed known to be
// compatible with the driver(type), if not then print a warning.
bool isMeterDriverValid(MeterDriver type, int manufacturer, int media, int version);
// For an unknown telegram, when analyzing check if the media type is reasonable in relation to the driver.
// Ie. do not try to decode a door sensor telegram with a water meter driver.
bool isMeterDriverReasonableForMedia(MeterDriver type, string driver_name, int media);
bool isValidKey(string& key, MeterDriver mt);
@ -256,6 +259,7 @@ public:
LinkModeSet linkModes() { return linkmodes_; }
shared_ptr<Meter> construct(MeterInfo& mi) { return constructor_(mi, *this); }
bool detect(uint16_t mfct, uchar type, uchar version);
bool isValidMedia(uchar type);
};
bool registerDriver(function<void(DriverInfo&di)> setup);