Refactor eurisii driver to new format.

pull/708/head
Fredrik Öhrström 2022-11-26 17:58:14 +01:00
rodzic 9670d33263
commit 614e47de0b
5 zmienionych plików z 139 dodań i 246 usunięć

Wyświetl plik

@ -79,8 +79,8 @@ telegram=|4E4468507620541494087AAD004005089D86B62A329B3439873999738F82461ABDE3C7
# Test EurisII T1 telegrams
telegram=|7644C52501880188550872_01880188C5255508010000002F2F0B6E332211426E110182016E1102C2016E110382026E1104C2026E110582036E1106C2036E110782046E1108C2046E110982056E1110C2056E111182066E1112C2066E111382076E1114C2076E111582086E1116C2086E111702FD172100|
{"media":"heat cost allocation","meter":"eurisii","name":"HeatMeter","id":"88018801","current_consumption_hca":112233,"set_date":"","consumption_at_set_date_hca":273,"consumption_at_set_date_1_hca":273,"consumption_at_set_date_2_hca":529,"consumption_at_set_date_3_hca":785,"consumption_at_set_date_4_hca":1041,"consumption_at_set_date_5_hca":1297,"consumption_at_set_date_6_hca":1553,"consumption_at_set_date_7_hca":1809,"consumption_at_set_date_8_hca":2065,"consumption_at_set_date_9_hca":2321,"consumption_at_set_date_10_hca":4113,"consumption_at_set_date_11_hca":4369,"consumption_at_set_date_12_hca":4625,"consumption_at_set_date_13_hca":4881,"consumption_at_set_date_14_hca":5137,"consumption_at_set_date_15_hca":5393,"consumption_at_set_date_16_hca":5649,"consumption_at_set_date_17_hca":5905,"error_flags":"MEASUREMENT RESET","timestamp":"1111-11-11T11:11:11Z"}
|HeatMeter;88018801;112233.000000;;MEASUREMENT RESET;1111-11-11 11:11.11
{"media":"heat cost allocation","meter":"eurisii","name":"HeatMeter","id":"88018801","status":"MEASUREMENT RESET","current_consumption_hca":112233,"consumption_at_set_date_hca":273,"consumption_at_set_date_1_hca":273,"consumption_at_set_date_2_hca":529,"consumption_at_set_date_3_hca":785,"consumption_at_set_date_4_hca":1041,"consumption_at_set_date_5_hca":1297,"consumption_at_set_date_6_hca":1553,"consumption_at_set_date_7_hca":1809,"consumption_at_set_date_8_hca":2065,"consumption_at_set_date_9_hca":2321,"consumption_at_set_date_10_hca":4113,"consumption_at_set_date_11_hca":4369,"consumption_at_set_date_12_hca":4625,"consumption_at_set_date_13_hca":4881,"consumption_at_set_date_14_hca":5137,"consumption_at_set_date_15_hca":5393,"consumption_at_set_date_16_hca":5649,"consumption_at_set_date_17_hca":5905,"error_flags":"MEASUREMENT RESET","timestamp":"1111-11-11T11:11:11Z"}
|HeatMeter;88018801;112233;MEASUREMENT RESET;1111-11-11 11:11.11
# Test Lansen smoke detector telegram

Wyświetl plik

@ -0,0 +1,137 @@
/*
Copyright (C) 2019-2022 Fredrik Öhrström (gpl-3.0-or-later)
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"
namespace
{
struct Driver : public virtual MeterCommonImplementation
{
Driver(MeterInfo &mi, DriverInfo &di);
};
static bool ok = registerDriver([](DriverInfo&di)
{
di.setName("eurisii");
di.setDefaultFields("name,id,current_consumption_hca,status,timestamp");
di.setMeterType(MeterType::HeatCostAllocationMeter);
di.addLinkMode(LinkMode::T1);
di.addDetection(MANUFACTURER_INE, 0x08, 0x55);
di.setConstructor([](MeterInfo& mi, DriverInfo& di){ return shared_ptr<Meter>(new Driver(mi, di)); });
});
Driver::Driver(MeterInfo &mi, DriverInfo &di) : MeterCommonImplementation(mi, di)
{
addStringFieldWithExtractorAndLookup(
"status",
"Meter status from error flags and tpl status field.",
PrintProperty::JSON | PrintProperty::IMPORTANT |
PrintProperty::STATUS | PrintProperty::JOIN_TPL_STATUS,
FieldMatcher::build()
.set(MeasurementType::Instantaneous)
.set(VIFRange::ErrorFlags),
Translate::Lookup(
{
{
{
"ERROR_FLAGS",
Translate::Type::BitToString,
0xffff,
"OK",
{
{ 0x0001, "MEASUREMENT" },
{ 0x0002, "SABOTAGE" },
{ 0x0004, "BATTERY" },
{ 0x0008, "CS" },
{ 0x0010, "HF" },
{ 0x0020, "RESET" }
}
},
},
}));
addStringFieldWithExtractorAndLookup(
"error_flags",
"Deprecated field! Use status instead.",
PrintProperty::JSON | PrintProperty::DEPRECATED |
PrintProperty::STATUS | PrintProperty::JOIN_TPL_STATUS,
FieldMatcher::build()
.set(MeasurementType::Instantaneous)
.set(VIFRange::ErrorFlags),
Translate::Lookup(
{
{
{
"ERROR_FLAGS",
Translate::Type::BitToString,
0xffff,
"OK",
{
{ 0x0001, "MEASUREMENT" },
{ 0x0002, "SABOTAGE" },
{ 0x0004, "BATTERY" },
{ 0x0008, "CS" },
{ 0x0010, "HF" },
{ 0x0020, "RESET" }
}
},
},
}));
addNumericFieldWithExtractor(
"current_consumption",
"The current heat cost allocation.",
PrintProperty::JSON,
Quantity::HCA,
VifScaling::Auto,
FieldMatcher::build()
.set(MeasurementType::Instantaneous)
.set(VIFRange::HeatCostAllocation)
);
addNumericFieldWithExtractor(
"consumption_at_set_date_{storage_counter}",
"The heat cost allocation at set date #.",
PrintProperty::JSON,
Quantity::HCA,
VifScaling::Auto,
FieldMatcher::build()
.set(MeasurementType::Instantaneous)
.set(VIFRange::HeatCostAllocation)
.set(StorageNr(1),StorageNr(17))
);
addNumericFieldWithExtractor(
"consumption_at_set_date",
"Deprecated field.",
PrintProperty::JSON,
Quantity::HCA,
VifScaling::Auto,
FieldMatcher::build()
.set(MeasurementType::Instantaneous)
.set(VIFRange::HeatCostAllocation)
.set(StorageNr(1))
);
}
}
// Test: HeatMeter eurisii 88018801 NOKEY
// telegram=|7644C52501880188550872_01880188C5255508010000002F2F0B6E332211426E110182016E1102C2016E110382026E1104C2026E110582036E1106C2036E110782046E1108C2046E110982056E1110C2056E111182066E1112C2066E111382076E1114C2076E111582086E1116C2086E111702FD172100|
// {"media":"heat cost allocation","meter":"eurisii","name":"HeatMeter","id":"88018801","status":"MEASUREMENT RESET","current_consumption_hca":112233,"consumption_at_set_date_hca":273,"consumption_at_set_date_1_hca":273,"consumption_at_set_date_2_hca":529,"consumption_at_set_date_3_hca":785,"consumption_at_set_date_4_hca":1041,"consumption_at_set_date_5_hca":1297,"consumption_at_set_date_6_hca":1553,"consumption_at_set_date_7_hca":1809,"consumption_at_set_date_8_hca":2065,"consumption_at_set_date_9_hca":2321,"consumption_at_set_date_10_hca":4113,"consumption_at_set_date_11_hca":4369,"consumption_at_set_date_12_hca":4625,"consumption_at_set_date_13_hca":4881,"consumption_at_set_date_14_hca":5137,"consumption_at_set_date_15_hca":5393,"consumption_at_set_date_16_hca":5649,"consumption_at_set_date_17_hca":5905,"error_flags":"MEASUREMENT RESET","timestamp":"1111-11-11T11:11:11Z"}
// |HeatMeter;88018801;112233;MEASUREMENT RESET;1111-11-11 11:11.11

Wyświetl plik

@ -28,7 +28,6 @@
//
#define METER_DETECTION \
X(CCx01, MANUFACTURER_GSS, 0x02, 0x01) \
X(EURISII, MANUFACTURER_INE, 0x08, 0x55) \
X(HYDROCALM3,MANUFACTURER_BMT, 0x0d, 0x0b) \
X(HYDRODIGIT,MANUFACTURER_BMT, 0x06, 0x13) \
X(HYDRODIGIT,MANUFACTURER_BMT, 0x07, 0x13) \

Wyświetl plik

@ -1,242 +0,0 @@
/*
Copyright (C) 2019-2020 Fredrik Öhrström (gpl-3.0-or-later)
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"
struct MeterEurisII : public virtual MeterCommonImplementation {
MeterEurisII(MeterInfo &mi);
double currentConsumption(Unit u);
string setDate();
double consumptionAtSetDate(Unit u);
private:
void processContent(Telegram *t);
string errorFlagsHumanReadable();
double current_consumption_hca_ {};
string set_date_; // The set date for index 0 below, is only sent for short telegrams.
// Ie for long telegrams with 17 values, then the set_date_ is empty.
double consumption_at_set_date_hca_[17]; // 1 to 17 store in index 0 to 16
uint16_t error_flags_;
};
MeterEurisII::MeterEurisII(MeterInfo &mi) :
MeterCommonImplementation(mi, "eurisii")
{
setMeterType(MeterType::HeatCostAllocationMeter);
setExpectedTPLSecurityMode(TPLSecurityMode::AES_CBC_IV);
addLinkMode(LinkMode::T1);
addPrint("current_consumption", Quantity::HCA,
[&](Unit u){ return currentConsumption(u); },
"The current heat cost allocation.",
PrintProperty::FIELD | PrintProperty::JSON);
addPrint("set_date", Quantity::Text,
[&](){ return setDate(); },
"The most recent billing period date.",
PrintProperty::FIELD | PrintProperty::JSON);
addPrint("consumption_at_set_date", Quantity::HCA,
[&](Unit u){ return consumption_at_set_date_hca_[0]; },
"Heat cost allocation at the most recent billing period date.",
PrintProperty::JSON);
for (int i=1; i<=17; ++i)
{
string msg, info;
strprintf(&msg, "consumption_at_set_date_%d", i);
strprintf(&info, "Heat cost allocation at the %d billing period date.", i);
addPrint(msg, Quantity::HCA,
[this,i](Unit u){ return consumption_at_set_date_hca_[i-1]; },
info,
PrintProperty::JSON);
}
addPrint("error_flags", Quantity::Text,
[&](){ return errorFlagsHumanReadable(); },
"Error flags.",
PrintProperty::FIELD | PrintProperty::JSON);
}
shared_ptr<Meter> createEurisII(MeterInfo &mi)
{
return shared_ptr<Meter>(new MeterEurisII(mi));
}
double MeterEurisII::currentConsumption(Unit u)
{
return current_consumption_hca_;
}
string MeterEurisII::setDate()
{
return set_date_;
}
double MeterEurisII::consumptionAtSetDate(Unit u)
{
return consumption_at_set_date_hca_[0];
}
string MeterEurisII::errorFlagsHumanReadable()
{
string s;
if (error_flags_ & 0x01) s += "MEASUREMENT ";
if (error_flags_ & 0x02) s += "SABOTAGE ";
if (error_flags_ & 0x04) s += "BATTERY ";
if (error_flags_ & 0x08) s += "CS ";
if (error_flags_ & 0x10) s += "HF ";
if (error_flags_ & 0x20) s += "RESET ";
if (s.length() > 0) {
s.pop_back();
return s;
}
if (error_flags_ != 0 && s.length() == 0) {
// Some higher bits are set that we do not know about! Fall back to printing the number!
strprintf(&s, "0x%04X", error_flags_);
}
return s;
}
void MeterEurisII::processContent(Telegram *t)
{
// These meters can be configured to send long telegrams 18 measurement values, no date.
// or short telegrams 2 measurement values, with a date.
// Here is a long telegram:
// (eurisii) 0f: 2F skip
// (eurisii) 10: 2F skip
// (eurisii) 11: 0B dif (6 digit BCD Instantaneous value)
// (eurisii) 12: 6E vif (Units for H.C.A.)
// (eurisii) 13: * 112233 current consumption (332211.000000 hca)
// (eurisii) 16: 42 dif (16 Bit Integer/Binary Instantaneous value storagenr=1)
// (eurisii) 17: 6E vif (Units for H.C.A.)
// (eurisii) 18: * 0000 consumption at set date 1 (0.000000 hca)
// (eurisii) 1a: 82 dif (16 Bit Integer/Binary Instantaneous value)
// (eurisii) 1b: 01 dife (subunit=0 tariff=0 storagenr=2)
// (eurisii) 1c: 6E vif (Units for H.C.A.)
// (eurisii) 1d: * 0000 consumption at set date 2 (0.000000 hca)
// (eurisii) 1f: C2 dif (16 Bit Integer/Binary Instantaneous value storagenr=1)
// (eurisii) 20: 01 dife (subunit=0 tariff=0 storagenr=3)
// (eurisii) 21: 6E vif (Units for H.C.A.)
// (eurisii) 22: * 0000 consumption at set date 3 (0.000000 hca)
// (eurisii) 24: 82 dif (16 Bit Integer/Binary Instantaneous value)
// (eurisii) 25: 02 dife (subunit=0 tariff=0 storagenr=4)
// (eurisii) 26: 6E vif (Units for H.C.A.)
// (eurisii) 27: * 0000 consumption at set date 4 (0.000000 hca)
// (eurisii) 29: C2 dif (16 Bit Integer/Binary Instantaneous value storagenr=1)
// (eurisii) 2a: 02 dife (subunit=0 tariff=0 storagenr=5)
// (eurisii) 2b: 6E vif (Units for H.C.A.)
// (eurisii) 2c: * 0000 consumption at set date 5 (0.000000 hca)
// (eurisii) 2e: 82 dif (16 Bit Integer/Binary Instantaneous value)
// (eurisii) 2f: 03 dife (subunit=0 tariff=0 storagenr=6)
// (eurisii) 30: 6E vif (Units for H.C.A.)
// (eurisii) 31: * 0000 consumption at set date 6 (0.000000 hca)
// (eurisii) 33: C2 dif (16 Bit Integer/Binary Instantaneous value storagenr=1)
// (eurisii) 34: 03 dife (subunit=0 tariff=0 storagenr=7)
// (eurisii) 35: 6E vif (Units for H.C.A.)
// (eurisii) 36: * 0000 consumption at set date 7 (0.000000 hca)
// (eurisii) 38: 82 dif (16 Bit Integer/Binary Instantaneous value)
// (eurisii) 39: 04 dife (subunit=0 tariff=0 storagenr=8)
// (eurisii) 3a: 6E vif (Units for H.C.A.)
// (eurisii) 3b: * 0000 consumption at set date 8 (0.000000 hca)
// (eurisii) 3d: C2 dif (16 Bit Integer/Binary Instantaneous value storagenr=1)
// (eurisii) 3e: 04 dife (subunit=0 tariff=0 storagenr=9)
// (eurisii) 3f: 6E vif (Units for H.C.A.)
// (eurisii) 40: * 0000 consumption at set date 9 (0.000000 hca)
// (eurisii) 42: 82 dif (16 Bit Integer/Binary Instantaneous value)
// (eurisii) 43: 05 dife (subunit=0 tariff=0 storagenr=10)
// (eurisii) 44: 6E vif (Units for H.C.A.)
// (eurisii) 45: * 0000 consumption at set date 10 (0.000000 hca)
// (eurisii) 47: C2 dif (16 Bit Integer/Binary Instantaneous value storagenr=1)
// (eurisii) 48: 05 dife (subunit=0 tariff=0 storagenr=11)
// (eurisii) 49: 6E vif (Units for H.C.A.)
// (eurisii) 4a: * 0000 consumption at set date 11 (0.000000 hca)
// (eurisii) 4c: 82 dif (16 Bit Integer/Binary Instantaneous value)
// (eurisii) 4d: 06 dife (subunit=0 tariff=0 storagenr=12)
// (eurisii) 4e: 6E vif (Units for H.C.A.)
// (eurisii) 4f: * 0000 consumption at set date 12 (0.000000 hca)
// (eurisii) 51: C2 dif (16 Bit Integer/Binary Instantaneous value storagenr=1)
// (eurisii) 52: 06 dife (subunit=0 tariff=0 storagenr=13)
// (eurisii) 53: 6E vif (Units for H.C.A.)
// (eurisii) 54: * 0000 consumption at set date 13 (0.000000 hca)
// (eurisii) 56: 82 dif (16 Bit Integer/Binary Instantaneous value)
// (eurisii) 57: 07 dife (subunit=0 tariff=0 storagenr=14)
// (eurisii) 58: 6E vif (Units for H.C.A.)
// (eurisii) 59: * 0000 consumption at set date 14 (0.000000 hca)
// (eurisii) 5b: C2 dif (16 Bit Integer/Binary Instantaneous value storagenr=1)
// (eurisii) 5c: 07 dife (subunit=0 tariff=0 storagenr=15)
// (eurisii) 5d: 6E vif (Units for H.C.A.)
// (eurisii) 5e: * 0000 consumption at set date 15 (0.000000 hca)
// (eurisii) 60: 82 dif (16 Bit Integer/Binary Instantaneous value)
// (eurisii) 61: 08 dife (subunit=0 tariff=0 storagenr=16)
// (eurisii) 62: 6E vif (Units for H.C.A.)
// (eurisii) 63: * 0000 consumption at set date 16 (0.000000 hca)
// (eurisii) 65: C2 dif (16 Bit Integer/Binary Instantaneous value storagenr=1)
// (eurisii) 66: 08 dife (subunit=0 tariff=0 storagenr=17)
// (eurisii) 67: 6E vif (Units for H.C.A.)
// (eurisii) 68: * 0000 consumption at set date 17 (0.000000 hca)
// (eurisii) 6a: 02 dif (16 Bit Integer/Binary Instantaneous value)
// (eurisii) 6b: FD vif (Second extension of VIF-codes)
// (eurisii) 6c: 17 vife (Error flags (binary))
// (eurisii) 6d: * 0000 error flags (0000)
int offset;
string key;
if (findKey(MeasurementType::Instantaneous, VIFRange::HeatCostAllocation, 0, 0, &key, &t->dv_entries))
{
extractDVdouble(&t->dv_entries, key, &offset, &current_consumption_hca_);
t->addMoreExplanation(offset, " current consumption (%f hca)", current_consumption_hca_);
}
if (findKey(MeasurementType::Instantaneous, VIFRange::Date, 1, 0, &key, &t->dv_entries)) {
struct tm date;
extractDVdate(&t->dv_entries, key, &offset, &date);
set_date_ = strdate(&date);
t->addMoreExplanation(offset, " set date (%s)", set_date_.c_str());
}
for (int i=1; i<=17; ++i)
{
if (findKey(MeasurementType::Instantaneous, VIFRange::HeatCostAllocation, i, 0, &key, &t->dv_entries))
{
string info;
strprintf(&info, " consumption at set date %d (%%f hca)", i);
extractDVdouble(&t->dv_entries, key, &offset, &consumption_at_set_date_hca_[i-1]);
t->addMoreExplanation(offset, info.c_str(), consumption_at_set_date_hca_[i-1]);
}
}
key = "02FD17";
if (hasKey(&t->dv_entries, key)) {
extractDVuint16(&t->dv_entries, "02FD17", &offset, &error_flags_);
t->addMoreExplanation(offset, " error flags (%04X)", error_flags_);
}
}

Wyświetl plik

@ -61,7 +61,6 @@ LIST_OF_METER_TYPES
#define LIST_OF_METERS \
X(auto, 0, AutoMeter, AUTO, Auto) \
X(unknown, 0, UnknownMeter, UNKNOWN, Unknown) \
X(eurisii, T1_bit, HeatCostAllocationMeter, EURISII, EurisII) \
X(gransystems,T1_bit, ElectricityMeter, CCx01, CCx01) \
X(hydrocalm3, T1_bit, HeatMeter, HYDROCALM3, HydrocalM3) \
X(hydrodigit, T1_bit, WaterMeter, HYDRODIGIT, Hydrodigit) \