Refactor lse_07_17 driver.

pull/473/head
Fredrik Öhrström 2022-02-06 21:12:05 +01:00
rodzic 6823279b05
commit da943d3573
6 zmienionych plików z 212 dodań i 235 usunięć

Wyświetl plik

@ -203,6 +203,9 @@ As <options> you can use:
--alarmshell=<cmdline> invokes cmdline when an alarm triggers
--alarmtimeout=<time> Expect a telegram to arrive within <time> seconds, eg 60s, 60m, 24h during expected activity.
--analyze Analyze a telegram to find the best driver.
--analyze=<key> Analyze a telegram to find the best driver use the provided decryption key.
--analyze=<driver> Analyze a telegram and use only this driver.
--analyze=<driver>:<key> Analyze a telegram and use only this driver with this key.
--debug for a lot of information
--device=<device> override device in config files. Use only in combination with --useconfig= option
--donotprobe=<tty> do not auto-probe this tty. Use multiple times for several ttys or specify "all" for all ttys.

Wyświetl plik

@ -0,0 +1,205 @@
/*
Copyright (C) 2021-2022 Fredrik Öhrström
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include"meters_common_implementation.h"
using namespace std;
struct MeterLSE_07_17 : public virtual MeterCommonImplementation
{
MeterLSE_07_17(MeterInfo &mi, DriverInfo &di);
double total_water_consumption_m3_ {};
double due_date_water_consumption_m3_ {};
string due_date_ {};
string error_code_ {};
string error_date_ {};
string device_date_time_ {};
};
static bool ok = registerDriver([](DriverInfo&di)
{
di.setName("lse_07_17");
di.setMeterType(MeterType::WaterMeter);
di.setExpectedTPLSecurityMode(TPLSecurityMode::AES_CBC_IV);
di.addLinkMode(LinkMode::S1);
di.addDetection(MANUFACTURER_LSE, 0x06, 0x18);
di.addDetection(MANUFACTURER_LSE, 0x07, 0x18);
di.addDetection(MANUFACTURER_LSE, 0x07, 0x16);
di.addDetection(MANUFACTURER_LSE, 0x07, 0x17);
di.addDetection(MANUFACTURER_QDS, 0x37, 0x33);
di.setConstructor([](MeterInfo& mi, DriverInfo& di){ return shared_ptr<Meter>(new MeterLSE_07_17(mi, di)); });
});
MeterLSE_07_17::MeterLSE_07_17(MeterInfo &mi, DriverInfo &di) :
MeterCommonImplementation(mi, di)
{
addFieldWithExtractor(
"total",
Quantity::Volume,
NoDifVifKey,
VifScaling::Auto,
MeasurementType::Instantaneous,
ValueInformation::Volume,
StorageNr(0),
TariffNr(0),
IndexNr(1),
PrintProperty::JSON | PrintProperty::FIELD | PrintProperty::IMPORTANT,
"The total water consumption recorded by this meter.",
SET_FUNC(total_water_consumption_m3_, Unit::M3),
GET_FUNC(total_water_consumption_m3_, Unit::M3));
addFieldWithExtractor(
"due_date",
Quantity::Volume,
NoDifVifKey,
VifScaling::Auto,
MeasurementType::Instantaneous,
ValueInformation::Volume,
StorageNr(1),
TariffNr(0),
IndexNr(1),
PrintProperty::JSON | PrintProperty::FIELD | PrintProperty::IMPORTANT,
"The water consumption at the due date.",
SET_FUNC(due_date_water_consumption_m3_, Unit::M3),
GET_FUNC(due_date_water_consumption_m3_, Unit::M3));
addStringFieldWithExtractor(
"due_date",
Quantity::Text,
NoDifVifKey,
MeasurementType::Instantaneous,
ValueInformation::Date,
StorageNr(1),
TariffNr(0),
IndexNr(1),
PrintProperty::JSON | PrintProperty::FIELD,
"The due date configured on the meter.",
SET_STRING_FUNC(due_date_),
GET_STRING_FUNC(due_date_));
addStringFieldWithExtractorAndLookup(
"error_code",
Quantity::Text,
DifVifKey("02BB56"),
MeasurementType::Unknown,
ValueInformation::Any,
AnyStorageNr,
AnyTariffNr,
IndexNr(1),
PrintProperty::JSON | PrintProperty::FIELD,
"Error code of the Meter, 0 means no error.",
SET_STRING_FUNC(error_code_),
GET_STRING_FUNC(error_code_),
{
{
{
"ERROR_FLAGS",
Translate::Type::BitToString,
0xffff,
"OK",
{
{ 0x01, "?" },
}
},
},
});
addStringFieldWithExtractor(
"error_date",
Quantity::Text,
NoDifVifKey,
MeasurementType::AtError,
ValueInformation::Date,
StorageNr(0),
TariffNr(0),
IndexNr(1),
PrintProperty::JSON | PrintProperty::FIELD,
"The date the error occured at. If no error, reads 2127-15-31 (FFFF).",
SET_STRING_FUNC(error_date_),
GET_STRING_FUNC(error_date_));
addStringFieldWithExtractor(
"device_date_time",
Quantity::Text,
NoDifVifKey,
MeasurementType::Instantaneous,
ValueInformation::DateTime,
StorageNr(0),
TariffNr(0),
IndexNr(1),
PrintProperty::JSON | PrintProperty::FIELD,
"Date when measurement was recorded.",
SET_STRING_FUNC(device_date_time_),
GET_STRING_FUNC(device_date_time_));
}
/*
The following telegram corresponds to the Qundis QWater5.5 cold water meters I have here.
From the device display it states that it is set to S-mode operation, sending a telegram
every 4 h.
Another option of this device is the C mode operation, sending telegrams every
7.5 s.
Even though my meters are definitely Qundis QWater5.5, the meters do not identify with
manufacturer code QDS but with LSE.
(lse_07_17) 0f: 0C dif (8 digit BCD Instantaneous value)
(lse_07_17) 10: 13 vif (Volume l)
(lse_07_17) 11: * 04400100 total consumption (14.004000 m3)
(lse_07_17) 15: 4C dif (8 digit BCD Instantaneous value storagenr=1)
(lse_07_17) 16: 13 vif (Volume l)
(lse_07_17) 17: * 40620000 due date consumption (6.240000 m3)
(lse_07_17) 1b: 42 dif (16 Bit Integer/Binary Instantaneous value storagenr=1)
(lse_07_17) 1c: 6C vif (Date type G)
(lse_07_17) 1d: * 9F2C due date (2020-12-31)
(lse_07_17) 1f: 02 dif (16 Bit Integer/Binary Instantaneous value)
(lse_07_17) 20: BB vif (Volume flow l/h)
(lse_07_17) 21: 56 vife (duration of limit exceed last lower is 2)
(lse_07_17) 22: * 0000 error code (0)
(lse_07_17) 24: 32 dif (16 Bit Integer/Binary Value during error state)
(lse_07_17) 25: 6C vif (Date type G)
(lse_07_17) 26: * FFFF error date (2127-15-31)
(lse_07_17) 28: 04 dif (32 Bit Integer/Binary Instantaneous value)
(lse_07_17) 29: 6D vif (Date and time type)
(lse_07_17) 2a: * 180DA924 device datetime (2021-04-09 13:24)
if (findKey(MeasurementType::Instantaneous, ValueInformation::DateTime, 0, 0, &key, &t->values)) {
struct tm datetime;
extractDVdate(&t->values, key, &offset, &datetime);
device_date_time_ = strdatetime(&datetime);
t->addMoreExplanation(offset, " device datetime (%s)", device_date_time_.c_str());
}
// How do the following error codes on the display map to the code in the telegram?
// According to the datasheet, these errors can appear on the display:
// LEAC Leak in the system (no associated error code)
// 0 Negative direction of flow.
// 2 Operating hours expired.
// 3 Hardware error.
// 4 Permanently stored error.
// b Communication via OPTO too often per month.
// c Communication via M-Bus too often per month.
// d Flow too high.
// f Device was without voltage supply briefly. All parameter settings are lost.
*/

Wyświetl plik

@ -66,12 +66,7 @@
X(LANSENTH, MANUFACTURER_LAS, 0x1b, 0x07) \
X(LANSENPU, MANUFACTURER_LAS, 0x00, 0x14) \
X(LANSENPU, MANUFACTURER_LAS, 0x00, 0x0b) \
X(LSE_07_17, MANUFACTURER_LSE, 0x06, 0x18) \
X(LSE_07_17, MANUFACTURER_LSE, 0x07, 0x18) \
X(LSE_07_17, MANUFACTURER_LSE, 0x07, 0x16) \
X(LSE_07_17, MANUFACTURER_LSE, 0x07, 0x17) \
X(QCALORIC, MANUFACTURER_LSE, 0x08, 0x35) \
X(LSE_07_17, MANUFACTURER_QDS, 0x37, 0x33) \
X(LSE_08, MANUFACTURER_LSE, 0x08, 0x01) \
X(MKRADIO3, MANUFACTURER_TCH, 0x62, 0x74) \
X(MKRADIO3, MANUFACTURER_TCH, 0x72, 0x74) \

Wyświetl plik

@ -1,227 +0,0 @@
/*
Copyright (C) 2021 Fredrik Öhrström
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include"dvparser.h"
#include"meters.h"
#include"meters_common_implementation.h"
#include"wmbus.h"
#include"wmbus_utils.h"
#include"util.h"
using namespace std;
struct MeterLSE_07_17 : public virtual MeterCommonImplementation {
MeterLSE_07_17(MeterInfo &mi);
// Total water counted through the meter
double totalWaterConsumption(Unit u);
bool hasTotalWaterConsumption();
// Water conumption at due date
double dueDateWaterConsumption(Unit u);
// The configured due date
string dueDate();
// Not shure about this one, should be error codes and 0 otherwise
string errorCode();
// Date of the error, if no error occured it is 2127-15-31 (FFFF)
string errorDate();
// Date and time of the device, presumably in UTC
string deviceDateTime();
private:
void processContent(Telegram *t);
double total_water_consumption_m3_ {};
double due_date_water_consumption_m3_ {};
string due_date_ {};
ushort error_code_ {};
string error_date_ {};
string device_date_time_ {};
};
shared_ptr<Meter> createLSE_07_17(MeterInfo &mi)
{
return shared_ptr<Meter>(new MeterLSE_07_17(mi));
}
MeterLSE_07_17::MeterLSE_07_17(MeterInfo &mi) :
MeterCommonImplementation(mi, "lse_07_17")
{
setMeterType(MeterType::WaterMeter);
setExpectedTPLSecurityMode(TPLSecurityMode::AES_CBC_IV);
addLinkMode(LinkMode::S1);
addPrint("total", Quantity::Volume,
[&](Unit u){ return totalWaterConsumption(u); },
"The total water consumption recorded by this meter.",
true, true);
addPrint("due_date", Quantity::Volume,
[&](Unit u){ return dueDateWaterConsumption(u); },
"The water consumption at the due date.",
true, true);
addPrint("due_date", Quantity::Text,
[&](){ return dueDate(); },
"The due date configured on the meter.",
true, true);
addPrint("error_code", Quantity::Text,
[&](){ return errorCode(); },
"Error code of the Meter, 0 means no error.",
true, true);
addPrint("error_date", Quantity::Text,
[&](){ return errorDate(); },
"The date the error occured at. If no error, reads 2127-15-31 (FFFF).",
true, true);
addPrint("device_date_time", Quantity::Text,
[&](){ return deviceDateTime(); },
"Error code of the Meter, 0 means no error.",
true, true);
}
void MeterLSE_07_17::processContent(Telegram *t)
{
/*
The following telegram corresponds to the Qundis QWater5.5 cold water meters I have here.
From the device display it states that it is set to S-mode operation, sending a telegram
every 4 h.
Another option of this device is the C mode operation, sending telegrams every
7.5 s.
Even though my meters are definitely Qundis QWater5.5, the meters do not identify with
manufacturer code QDS but with LSE.
(lse_07_17) 0f: 0C dif (8 digit BCD Instantaneous value)
(lse_07_17) 10: 13 vif (Volume l)
(lse_07_17) 11: * 04400100 total consumption (14.004000 m3)
(lse_07_17) 15: 4C dif (8 digit BCD Instantaneous value storagenr=1)
(lse_07_17) 16: 13 vif (Volume l)
(lse_07_17) 17: * 40620000 due date consumption (6.240000 m3)
(lse_07_17) 1b: 42 dif (16 Bit Integer/Binary Instantaneous value storagenr=1)
(lse_07_17) 1c: 6C vif (Date type G)
(lse_07_17) 1d: * 9F2C due date (2020-12-31)
(lse_07_17) 1f: 02 dif (16 Bit Integer/Binary Instantaneous value)
(lse_07_17) 20: BB vif (Volume flow l/h)
(lse_07_17) 21: 56 vife (duration of limit exceed last lower is 2)
(lse_07_17) 22: * 0000 error code (0)
(lse_07_17) 24: 32 dif (16 Bit Integer/Binary Value during error state)
(lse_07_17) 25: 6C vif (Date type G)
(lse_07_17) 26: * FFFF error date (2127-15-31)
(lse_07_17) 28: 04 dif (32 Bit Integer/Binary Instantaneous value)
(lse_07_17) 29: 6D vif (Date and time type)
(lse_07_17) 2a: * 180DA924 device datetime (2021-04-09 13:24)
*/
int offset;
string key;
if (findKey(MeasurementType::Instantaneous, ValueInformation::Volume, 0, 0, &key, &t->values)) {
extractDVdouble(&t->values, key, &offset, &total_water_consumption_m3_);
t->addMoreExplanation(offset, " total consumption (%f m3)", total_water_consumption_m3_);
}
if (findKey(MeasurementType::Instantaneous, ValueInformation::Volume, 1, 0, &key, &t->values)) {
extractDVdouble(&t->values, key, &offset, &due_date_water_consumption_m3_);
t->addMoreExplanation(offset, " due date consumption (%f m3)", due_date_water_consumption_m3_);
}
if (findKey(MeasurementType::Instantaneous, ValueInformation::Date, 1, 0, &key, &t->values)) {
struct tm date;
extractDVdate(&t->values, key, &offset, &date);
due_date_ = strdate(&date);
t->addMoreExplanation(offset, " due date (%s)", due_date_.c_str());
}
key = "02BB56";
if (hasKey(&t->values, key)) {
extractDVuint16(&t->values, key, &offset, &error_code_);
// Not sure about this one, is it error codes or sth else?
t->addMoreExplanation(offset, " error code (%s)", errorCode().c_str());
}
if (findKey(MeasurementType::AtError, ValueInformation::Date, 0, 0, &key, &t->values)) {
struct tm date;
extractDVdate(&t->values, key, &offset, &date);
error_date_ = strdate(&date);
t->addMoreExplanation(offset, " error date (%s)", error_date_.c_str());
}
if (findKey(MeasurementType::Instantaneous, ValueInformation::DateTime, 0, 0, &key, &t->values)) {
struct tm datetime;
extractDVdate(&t->values, key, &offset, &datetime);
device_date_time_ = strdatetime(&datetime);
t->addMoreExplanation(offset, " device datetime (%s)", device_date_time_.c_str());
}
}
double MeterLSE_07_17::totalWaterConsumption(Unit u)
{
assertQuantity(u, Quantity::Volume);
return convert(total_water_consumption_m3_, Unit::M3, u);
}
bool MeterLSE_07_17::hasTotalWaterConsumption()
{
return true;
}
double MeterLSE_07_17::dueDateWaterConsumption(Unit u)
{
assertQuantity(u, Quantity::Volume);
return convert(due_date_water_consumption_m3_, Unit::M3, u);
}
string MeterLSE_07_17::dueDate()
{
return due_date_;
}
string MeterLSE_07_17::errorCode()
{
if (error_code_ == 0) return "OK";
// How do the following error codes on the display map to the code in the telegram?
// According to the datasheet, these errors can appear on the display:
// LEAC Leak in the system (no associated error code)
// 0 Negative direction of flow.
// 2 Operating hours expired.
// 3 Hardware error.
// 4 Permanently stored error.
// b Communication via OPTO too often per month.
// c Communication via M-Bus too often per month.
// d Flow too high.
// f Device was without voltage supply briefly. All parameter settings are lost.
//
return tostrprintf("ERR %04x", error_code_);
}
string MeterLSE_07_17::errorDate()
{
return error_date_;
}
string MeterLSE_07_17::deviceDateTime()
{
return device_date_time_;
}

Wyświetl plik

@ -77,7 +77,6 @@ LIST_OF_METER_TYPES
X(lansensm, T1_bit, SmokeDetector, LANSENSM, LansenSM) \
X(lansenth, T1_bit, TempHygroMeter, LANSENTH, LansenTH) \
X(lansenpu, T1_bit, PulseCounter, LANSENPU, LansenPU) \
X(lse_07_17, S1_bit, WaterMeter, LSE_07_17, LSE_07_17) \
X(mkradio3, T1_bit, WaterMeter, MKRADIO3, MKRadio3) \
X(mkradio4, T1_bit, WaterMeter, MKRADIO4, MKRadio4) \
X(multical21, C1_bit|T1_bit, WaterMeter, MULTICAL21, Multical21) \

Wyświetl plik

@ -1349,8 +1349,10 @@ int days_in_months[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int get_days_in_month(int year, int month)
{
assert(month >= 0);
assert(month < 12);
if (month < 0 || month >= 12)
{
month = 0;
}
int days = days_in_months[month];