Refactor sontex868 driver to new format.

pull/687/head
Fredrik Öhrström 2022-11-16 17:34:29 +01:00
rodzic 1ee050534e
commit f33ca02fa5
9 zmienionych plików z 156 dodań i 294 usunięć

Wyświetl plik

@ -12,7 +12,7 @@ telegram=|A244EE4D111111113C077AAC000000_0C1389490000426CE1F14C130000000082046C2
telegram=|AF46EE4D2827282716087A80000000_046D040A9F2A036E000000426CE1F7436E000000525900008288016C61258388016E0000008D8801EE1E3533FE00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005FF2D0000803F8520FF2D0000803F0259AD0A0265D8041259AD0A8310FD3100000082106C01018110FD610082206C9F2A0BFD0F01030102FF2C000002FD66AC08|
{"media":"heat cost allocation","meter":"sontex868","name":"MyHeatCoster","id":"27282728","current_consumption_hca":0,"set_date":"2127-07-01","consumption_at_set_date_hca":0,"current_temp_c":27.33,"current_room_temp_c":12.4,"max_temp_c":27.33,"max_temp_previous_period_c":0,"device_date_time":"2020-10-31 10:04","timestamp":"1111-11-11T11:11:11Z"}
|MyHeatCoster;27282728;0.000000;2127-07-01;0.000000;1111-11-11 11:11.11
|MyHeatCoster;27282728;0;2127-07-01;0;1111-11-11 11:11.11
# Test iPerl T1 telegram, after decryption, its got 2f2f markers.

Wyświetl plik

@ -69,7 +69,7 @@ namespace
addNumericFieldWithExtractor(
"current_consumption",
"The current temperature.",
"The current heat cost allocation.",
PrintProperty::JSON | PrintProperty::FIELD,
Quantity::HCA,
VifScaling::Auto,

Wyświetl plik

@ -0,0 +1,134 @@
/*
Copyright (C) 2020-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("sontex868");
di.setDefaultFields("name,id,current_consumption_hca,set_date,consumption_at_set_date_hca,timestamp");
di.setMeterType(MeterType::HeatCostAllocationMeter);
di.addLinkMode(LinkMode::T1);
di.addDetection(MANUFACTURER_SON, 0x08, 0x16);
di.setConstructor([](MeterInfo& mi, DriverInfo& di){ return shared_ptr<Meter>(new Driver(mi, di)); });
});
Driver::Driver(MeterInfo &mi, DriverInfo &di) : MeterCommonImplementation(mi, di)
{
addNumericFieldWithExtractor(
"current_consumption",
"The current heat cost allocation for this meter.",
PrintProperty::JSON | PrintProperty::FIELD,
Quantity::HCA,
VifScaling::Auto,
FieldMatcher::build()
.set(MeasurementType::Instantaneous)
.set(VIFRange::HeatCostAllocation)
);
addStringFieldWithExtractor(
"set_date",
"The most recent billing period date.",
PrintProperty::JSON | PrintProperty::FIELD | PrintProperty::OPTIONAL,
FieldMatcher::build()
.set(MeasurementType::Instantaneous)
.set(VIFRange::Date)
.set(StorageNr(1))
);
addNumericFieldWithExtractor(
"consumption_at_set_date",
"Heat cost allocation at the most recent billing period date.",
PrintProperty::JSON | PrintProperty::FIELD,
Quantity::HCA,
VifScaling::Auto,
FieldMatcher::build()
.set(MeasurementType::Instantaneous)
.set(VIFRange::HeatCostAllocation)
.set(StorageNr(1))
);
addNumericFieldWithExtractor(
"current_temp",
"The current temperature of the heating element.",
PrintProperty::JSON | PrintProperty::FIELD | PrintProperty::OPTIONAL,
Quantity::Temperature,
VifScaling::Auto,
FieldMatcher::build()
.set(MeasurementType::Instantaneous)
.set(VIFRange::FlowTemperature)
);
addNumericFieldWithExtractor(
"current_room_temp",
"The current room temperature.",
PrintProperty::JSON | PrintProperty::FIELD | PrintProperty::OPTIONAL,
Quantity::Temperature,
VifScaling::Auto,
FieldMatcher::build()
.set(MeasurementType::Instantaneous)
.set(VIFRange::ExternalTemperature)
);
addNumericFieldWithExtractor(
"max_temp",
"The maximum temperature so far during this billing period.",
PrintProperty::JSON | PrintProperty::FIELD | PrintProperty::OPTIONAL,
Quantity::Temperature,
VifScaling::Auto,
FieldMatcher::build()
.set(MeasurementType::Maximum)
.set(VIFRange::FlowTemperature)
);
addNumericFieldWithExtractor(
"max_temp_previous_period",
"The maximum temperature during the previous billing period.",
PrintProperty::JSON | PrintProperty::FIELD | PrintProperty::OPTIONAL,
Quantity::Temperature,
VifScaling::Auto,
FieldMatcher::build()
.set(MeasurementType::Maximum)
.set(VIFRange::FlowTemperature)
.set(StorageNr(1))
);
addStringFieldWithExtractor(
"device_date_time",
"Date and time when the meter sent the telegram.",
PrintProperty::JSON | PrintProperty::OPTIONAL,
FieldMatcher::build()
.set(MeasurementType::Instantaneous)
.set(VIFRange::DateTime)
);
}
}
// Test: MyHeatCoster sontex868 27282728 NOKEY
// telegram=|AF46EE4D2827282716087A80000000_046D040A9F2A036E770000426CE1F7436E660000525900008288016C61258388016E0000008D8801EE1E3533FE00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005FF2D0000803F8520FF2D0000803F0259AD0A0265D8041259AD0A8310FD3100000082106C01018110FD610082206C9F2A0BFD0F01030102FF2C000002FD66AC08|
// {"media":"heat cost allocation","meter":"sontex868","name":"MyHeatCoster","id":"27282728","current_consumption_hca":119,"set_date":"2127-07-01","consumption_at_set_date_hca":102,"current_temp_c":27.33,"current_room_temp_c":12.4,"max_temp_c":27.33,"max_temp_previous_period_c":0,"device_date_time":"2020-10-31 10:04","timestamp":"1111-11-11T11:11:11Z"}
// |MyHeatCoster;27282728;119;2127-07-01;102;1111-11-11 11:11.11

Wyświetl plik

@ -50,7 +50,6 @@
X(MULTICAL803,MANUFACTURER_KAM, 0x04, 0x39) \
X(RFMAMB, MANUFACTURER_BMT, 0x1b, 0x10) \
X(RFMTX1, MANUFACTURER_BMT, 0x07, 0x05) \
X(SONTEX868, MANUFACTURER_SON, 0x08, 0x16) \

Wyświetl plik

@ -1,289 +0,0 @@
/*
Copyright (C) 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 MeterSontex868 : public virtual MeterCommonImplementation {
MeterSontex868(MeterInfo &mi);
double currentConsumption(Unit u);
string setDate();
double consumptionAtSetDate(Unit u);
double currentTemp(Unit u);
double currentRoomTemp(Unit u);
double maxTemp(Unit u);
double maxTempPreviousPeriod(Unit u);
private:
void processContent(Telegram *t);
// Telegram type 1
double current_consumption_hca_ {};
string set_date_;
double consumption_at_set_date_hca_ {};
string set_date_17_;
double curr_temp_c_ {};
double curr_room_temp_c_ {};
double max_temp_c_ {};
double max_temp_previous_period_c_ {};
string device_date_time_;
};
MeterSontex868::MeterSontex868(MeterInfo &mi) :
MeterCommonImplementation(mi, "sontex868")
{
setMeterType(MeterType::HeatCostAllocationMeter);
setExpectedTPLSecurityMode(TPLSecurityMode::AES_CBC_IV);
addLinkMode(LinkMode::C1);
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 consumptionAtSetDate(u); },
"Heat cost allocation at the most recent billing period date.",
PrintProperty::FIELD | PrintProperty::JSON);
addPrint("current_temp", Quantity::Temperature,
[&](Unit u){ return currentTemp(u); },
"The current temperature of the heating element.",
PrintProperty::JSON);
addPrint("current_room_temp", Quantity::Temperature,
[&](Unit u){ return currentRoomTemp(u); },
"The current room temperature.",
PrintProperty::JSON);
addPrint("max_temp", Quantity::Temperature,
[&](Unit u){ return maxTemp(u); },
"The maximum temperature so far during this billing period.",
PrintProperty::JSON);
addPrint("max_temp_previous_period", Quantity::Temperature,
[&](Unit u){ return maxTempPreviousPeriod(u); },
"The maximum temperature during the previous billing period.",
PrintProperty::JSON);
addPrint("device_date_time", Quantity::Text,
[&](){ return device_date_time_; },
"Device date time.",
PrintProperty::JSON);
}
shared_ptr<Meter> createSontex868(MeterInfo &mi)
{
return shared_ptr<Meter>(new MeterSontex868(mi));
}
double MeterSontex868::currentConsumption(Unit u)
{
return current_consumption_hca_;
}
string MeterSontex868::setDate()
{
return set_date_;
}
double MeterSontex868::consumptionAtSetDate(Unit u)
{
return consumption_at_set_date_hca_;
}
double MeterSontex868::currentTemp(Unit u)
{
assertQuantity(u, Quantity::Temperature);
return convert(curr_temp_c_, Unit::C, u);
}
double MeterSontex868::currentRoomTemp(Unit u)
{
assertQuantity(u, Quantity::Temperature);
return convert(curr_room_temp_c_, Unit::C, u);
}
double MeterSontex868::maxTemp(Unit u)
{
assertQuantity(u, Quantity::Temperature);
return convert(max_temp_c_, Unit::C, u);
}
double MeterSontex868::maxTempPreviousPeriod(Unit u)
{
assertQuantity(u, Quantity::Temperature);
return convert(max_temp_previous_period_c_, Unit::C, u);
}
void MeterSontex868::processContent(Telegram *t)
{
/*
(sontex868) 0f: 04 dif (32 Bit Integer/Binary Instantaneous value)
(sontex868) 10: 6D vif (Date and time type)
(sontex868) 11: * 040A9F2A device datetime (2020-10-31 10:04)
(sontex868) 15: 03 dif (24 Bit Integer/Binary Instantaneous value)
(sontex868) 16: 6E vif (Units for H.C.A.)
(sontex868) 17: * 000000 current consumption (0.000000 hca)
(sontex868) 1a: 42 dif (16 Bit Integer/Binary Instantaneous value storagenr=1)
(sontex868) 1b: 6C vif (Date type G)
(sontex868) 1c: * E1F7 set date (2127-07-01)
(sontex868) 1e: 43 dif (24 Bit Integer/Binary Instantaneous value storagenr=1)
(sontex868) 1f: 6E vif (Units for H.C.A.)
(sontex868) 20: * 000000 consumption at set date (0.000000 hca)
(sontex868) 23: 52 dif (16 Bit Integer/Binary Maximum value storagenr=1)
(sontex868) 24: 59 vif (Flow temperature 10² °C)
(sontex868) 25: * 0000 max temperature previous period (0.000000 °C)
(sontex868) 27: 82 dif (16 Bit Integer/Binary Instantaneous value)
(sontex868) 28: 88 dife (subunit=0 tariff=0 storagenr=16)
(sontex868) 29: 01 dife (subunit=0 tariff=0 storagenr=48)
(sontex868) 2a: 6C vif (Date type G)
(sontex868) 2b: 6125
(sontex868) 2d: 83 dif (24 Bit Integer/Binary Instantaneous value)
(sontex868) 2e: 88 dife (subunit=0 tariff=0 storagenr=16)
(sontex868) 2f: 01 dife (subunit=0 tariff=0 storagenr=48)
(sontex868) 30: 6E vif (Units for H.C.A.)
(sontex868) 31: 000000
(sontex868) 34: 8D dif (variable length Instantaneous value)
(sontex868) 35: 88 dife (subunit=0 tariff=0 storagenr=16)
(sontex868) 36: 01 dife (subunit=0 tariff=0 storagenr=48)
(sontex868) 37: EE vif (Units for H.C.A.)
(sontex868) 38: 1E vife (Compact profile with register)
(sontex868) 39: 35 varlen=53
(sontex868) 3a: 33FE000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
(sontex868) 6f: 05 dif (32 Bit Real Instantaneous value)
(sontex868) 70: FF vif (Vendor extension)
(sontex868) 71: 2D vife (per m3)
(sontex868) 72: 0000803F
(sontex868) 76: 85 dif (32 Bit Real Instantaneous value)
(sontex868) 77: 20 dife (subunit=0 tariff=2 storagenr=0)
(sontex868) 78: FF vif (Vendor extension)
(sontex868) 79: 2D vife (per m3)
(sontex868) 7a: 0000803F
(sontex868) 7e: 02 dif (16 Bit Integer/Binary Instantaneous value)
(sontex868) 7f: 59 vif (Flow temperature 10² °C)
(sontex868) 80: * AD0A current temperature (27.330000 °C)
(sontex868) 82: 02 dif (16 Bit Integer/Binary Instantaneous value)
(sontex868) 83: 65 vif (External temperature 10² °C)
(sontex868) 84: * D804 current room temperature (12.400000 °C)
(sontex868) 86: 12 dif (16 Bit Integer/Binary Maximum value)
(sontex868) 87: 59 vif (Flow temperature 10² °C)
(sontex868) 88: * AD0A max temperature current period (27.330000 °C)
(sontex868) 8a: 83 dif (24 Bit Integer/Binary Instantaneous value)
(sontex868) 8b: 10 dife (subunit=0 tariff=1 storagenr=0)
(sontex868) 8c: FD vif (Second extension of VIF-codes)
(sontex868) 8d: 31 vife (Duration of tariff [minute(s)])
(sontex868) 8e: 000000
(sontex868) 91: 82 dif (16 Bit Integer/Binary Instantaneous value)
(sontex868) 92: 10 dife (subunit=0 tariff=1 storagenr=0)
(sontex868) 93: 6C vif (Date type G)
(sontex868) 94: 0101
(sontex868) 96: 81 dif (8 Bit Integer/Binary Instantaneous value)
(sontex868) 97: 10 dife (subunit=0 tariff=1 storagenr=0)
(sontex868) 98: FD vif (Second extension of VIF-codes)
(sontex868) 99: 61 vife (Cumulation counter)
(sontex868) 9a: 00
(sontex868) 9b: 82 dif (16 Bit Integer/Binary Instantaneous value)
(sontex868) 9c: 20 dife (subunit=0 tariff=2 storagenr=0)
(sontex868) 9d: 6C vif (Date type G)
(sontex868) 9e: 9F2A
(sontex868) a0: 0B dif (6 digit BCD Instantaneous value)
(sontex868) a1: FD vif (Second extension of VIF-codes)
(sontex868) a2: 0F vife (Software version #)
(sontex868) a3: 010301
(sontex868) a6: 02 dif (16 Bit Integer/Binary Instantaneous value)
(sontex868) a7: FF vif (Vendor extension)
(sontex868) a8: 2C vife (per litre)
(sontex868) a9: 0000
(sontex868) ab: 02 dif (16 Bit Integer/Binary Instantaneous value)
(sontex868) ac: FD vif (Second extension of VIF-codes)
(sontex868) ad: 66 vife (State of parameter activation)
(sontex868) ae: AC08
*/
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());
}
if (findKey(MeasurementType::Instantaneous, VIFRange::HeatCostAllocation, 1, 0, &key, &t->dv_entries)) {
extractDVdouble(&t->dv_entries, key, &offset, &consumption_at_set_date_hca_);
t->addMoreExplanation(offset, " consumption at set date (%f hca)", consumption_at_set_date_hca_);
}
if(findKey(MeasurementType::Instantaneous, VIFRange::FlowTemperature, 0, 0, &key, &t->dv_entries)) {
extractDVdouble(&t->dv_entries, key, &offset, &curr_temp_c_);
t->addMoreExplanation(offset, " current temperature (%f °C)", curr_temp_c_);
}
if(findKey(MeasurementType::Instantaneous, VIFRange::ExternalTemperature, 0, 0, &key, &t->dv_entries)) {
extractDVdouble(&t->dv_entries, key, &offset, &curr_room_temp_c_);
t->addMoreExplanation(offset, " current room temperature (%f °C)", curr_room_temp_c_);
}
if(findKey(MeasurementType::Maximum, VIFRange::FlowTemperature, 0, 0, &key, &t->dv_entries)) {
extractDVdouble(&t->dv_entries, key, &offset, &max_temp_c_);
t->addMoreExplanation(offset, " max temperature current period (%f °C)", max_temp_c_);
}
if(findKey(MeasurementType::Maximum, VIFRange::FlowTemperature, 1, 0, &key, &t->dv_entries)) {
extractDVdouble(&t->dv_entries, key, &offset, &max_temp_previous_period_c_);
t->addMoreExplanation(offset, " max temperature previous period (%f °C)", max_temp_previous_period_c_);
}
if (findKey(MeasurementType::Instantaneous, VIFRange::DateTime, 0, 0, &key, &t->dv_entries)) {
struct tm datetime;
extractDVdate(&t->dv_entries, key, &offset, &datetime);
device_date_time_ = strdatetime(&datetime);
t->addMoreExplanation(offset, " device datetime (%s)", device_date_time_.c_str());
}
key = "0DFF5F";
if (hasKey(&t->dv_entries, key)) {
string hex;
extractDVHexString(&t->dv_entries, key, &offset, &hex);
t->addMoreExplanation(offset, " vendor extension data");
// This is not stored anywhere yet, we need to understand it, if necessary.
}
}

Wyświetl plik

@ -3369,6 +3369,24 @@ void MeterCommonImplementation::addOptionalFlowRelatedFields(string field_names)
}
}
void MeterCommonImplementation::addHCARelatedFields(string field_names)
{
set<string> fields = splitStringIntoSet(field_names, ',');
if (checkIf(fields,"consumption_hca"))
{
addNumericFieldWithExtractor(
"consumption",
"The current heat cost allocation for this meter.",
PrintProperty::JSON | PrintProperty::FIELD,
Quantity::HCA,
VifScaling::Auto,
FieldMatcher::build()
.set(MeasurementType::Instantaneous)
.set(VIFRange::HeatCostAllocation)
);
}
}
const char *toString(VifScaling s)
{

Wyświetl plik

@ -74,7 +74,6 @@ LIST_OF_METER_TYPES
X(multical803,C1_bit, HeatMeter, MULTICAL803, Multical803) \
X(rfmamb, T1_bit, TempHygroMeter, RFMAMB, RfmAmb) \
X(rfmtx1, T1_bit, WaterMeter, RFMTX1, RfmTX1) \
X(sontex868, T1_bit, HeatCostAllocationMeter, SONTEX868, Sontex868) \
X(lse_08, S1_bit|C1_bit, HeatCostAllocationMeter, LSE_08, LSE_08) \

Wyświetl plik

@ -258,6 +258,7 @@ protected:
void addOptionalCommonFields(string fields);
void addOptionalFlowRelatedFields(string fields);
void addHCARelatedFields(string fields);
vector<string> &selectedFields() { return selected_fields_; }
void setSelectedFields(vector<string> &f) { selected_fields_ = f; }

Wyświetl plik

@ -372,7 +372,7 @@ if [ ! -z "$RES" ]
then
echo ERROR: $TESTNAME
echo -----------------
diff $LOGFILE $LOGFILE_EXPECTED
meld $LOGFILE $LOGFILE_EXPECTED
echo -----------------
exit 1
else