Refactor mkradio4 to new driver format.

pull/687/head
Fredrik Öhrström 2022-11-16 16:24:03 +01:00
rodzic 08fae1b1a6
commit 1ee050534e
5 zmienionych plików z 115 dodań i 135 usunięć

Wyświetl plik

@ -46,12 +46,6 @@ telegram=|2F446850313233347462A2_069F255900B029310000000306060906030609070606050
{"media":"warm water","meter":"mkradio3","name":"Duschen","id":"34333231","total_m3":13.8,"target_m3":8.9,"current_date":"2022-04-27T02:00:00Z","prev_date":"2018-12-31T02:00:00Z","timestamp":"1111-11-11T11:11:11Z"}
|Duschen;34333231;13.800000;8.900000;2022-04-27T02:00:00Z;2018-12-31T02:00:00Z;1111-11-11 11:11.11
# Test MKRadio4 T1 telegrams
telegram=|2F446850200141029562A2_06702901006017030004000300000000000000000000000000000000000000000000000000|
{"media":"warm water","meter":"mkradio4","name":"Duschagain","id":"02410120","total_m3":0.4,"target_m3":0.1,"timestamp":"1111-11-11T11:11:11Z"}
|Duschagain;02410120;0.400000;0.100000;1111-11-11 11:11.11
# Test vario451 T1 telegrams
telegram=|374468506549235827C3A2_129F25383300A8622600008200800A2AF862115175552877A36F26C9AB1CB24400000004000000000004908002|
{"media":"heat","meter":"vario451","name":"HeatMeter","id":"58234965","total_kwh":6371.666667,"current_kwh":2729.444444,"previous_kwh":3642.222222,"timestamp":"1111-11-11T11:11:11Z"}

Wyświetl plik

@ -0,0 +1,115 @@
/*
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);
void processContent(Telegram *t);
private:
double totalWaterConsumption(Unit u);
double targetWaterConsumption(Unit u);
double total_water_consumption_m3_ {};
double target_water_consumption_m3_ {};
};
static bool ok = registerDriver([](DriverInfo&di)
{
di.setName("mkradio4");
di.setMeterType(MeterType::WaterMeter);
di.addLinkMode(LinkMode::T1);
di.addDetection(MANUFACTURER_TCH, 0x62, 0x95);
di.addDetection(MANUFACTURER_TCH, 0x62, 0x70);
di.addDetection(MANUFACTURER_TCH, 0x72, 0x95);
di.addDetection(MANUFACTURER_TCH, 0x72, 0x70);
di.setConstructor([](MeterInfo& mi, DriverInfo& di){ return shared_ptr<Meter>(new Driver(mi, di)); });
});
Driver::Driver(MeterInfo &mi, DriverInfo &di) : MeterCommonImplementation(mi, di)
{
addPrint("total", Quantity::Volume,
[&](Unit u){ return totalWaterConsumption(u); },
"The total water consumption recorded by this meter.",
PrintProperty::FIELD | PrintProperty::JSON);
addPrint("target", Quantity::Volume,
[&](Unit u){ return targetWaterConsumption(u); },
"The total water consumption recorded at the beginning of this month.",
PrintProperty::FIELD | PrintProperty::JSON);
}
void Driver::processContent(Telegram *t)
{
// Unfortunately, the MK Radio 4 is mostly a proprieatary protocol
// simple wrapped inside a wmbus telegram since the ci-field is 0xa2.
// Which means that the entire payload is manufacturer specific.
map<string,pair<int,DVEntry>> vendor_values;
vector<uchar> content;
t->extractPayload(&content);
uchar prev_lo = content[3];
uchar prev_hi = content[4];
double prev = (256.0*prev_hi+prev_lo)/10.0;
string prevs;
strprintf(&prevs, "%02x%02x", prev_lo, prev_hi);
int offset = t->parsed.size()+3;
vendor_values["0215"] = { offset, DVEntry(offset, DifVifKey("0215"), MeasurementType::Instantaneous, 0x15, {}, 0, 0, 0, prevs) };
t->explanations.push_back(Explanation(offset, 2, prevs, KindOfData::CONTENT, Understanding::FULL));
t->addMoreExplanation(offset, " prev consumption (%f m3)", prev);
uchar curr_lo = content[7];
uchar curr_hi = content[8];
double curr = (256.0*curr_hi+curr_lo)/10.0;
string currs;
strprintf(&currs, "%02x%02x", curr_lo, curr_hi);
offset = t->parsed.size()+7;
vendor_values["0215"] = { offset, DVEntry(offset, DifVifKey("0215"), MeasurementType::Instantaneous, 0x15, {}, 0, 0, 0, currs) };
t->explanations.push_back(Explanation(offset, 2, currs, KindOfData::CONTENT, Understanding::FULL));
t->addMoreExplanation(offset, " curr consumption (%f m3)", curr);
total_water_consumption_m3_ = prev+curr;
target_water_consumption_m3_ = prev;
}
double Driver::totalWaterConsumption(Unit u)
{
assertQuantity(u, Quantity::Volume);
return convert(total_water_consumption_m3_, Unit::M3, u);
}
double Driver::targetWaterConsumption(Unit u)
{
return target_water_consumption_m3_;
}
}
// Test: Duschagain mkradio4 02410120 NOKEY
// telegram=|2F446850200141029562A2_06702901006017030004000300000000000000000000000000000000000000000000000000|
// {"media":"warm water","meter":"mkradio4","name":"Duschagain","id":"02410120","total_m3":0.4,"target_m3":0.1,"timestamp":"1111-11-11T11:11:11Z"}
// |Duschagain;02410120;0.400000;0.100000;1111-11-11 11:11.11

Wyświetl plik

@ -39,10 +39,6 @@
X(HYDRODIGIT,MANUFACTURER_BMT, 0x07, 0x13) \
X(HYDRODIGIT,MANUFACTURER_BMT, 0x07, 0x15) \
X(LSE_08, MANUFACTURER_LSE, 0x08, 0x01) \
X(MKRADIO4, MANUFACTURER_TCH, 0x62, 0x95) \
X(MKRADIO4, MANUFACTURER_TCH, 0x62, 0x70) \
X(MKRADIO4, MANUFACTURER_TCH, 0x72, 0x95) \
X(MKRADIO4, MANUFACTURER_TCH, 0x72, 0x70) \
X(MULTICAL302,MANUFACTURER_KAM, 0x04, 0x30) \
X(MULTICAL302,MANUFACTURER_KAM, 0x0d, 0x30) \
X(MULTICAL302,MANUFACTURER_KAM, 0x0c, 0x30) \

Wyświetl plik

@ -1,124 +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"
#include"util.h"
using namespace std;
struct MKRadio4 : public virtual MeterCommonImplementation
{
MKRadio4(MeterInfo &mi);
double totalWaterConsumption(Unit u);
bool hasTotalWaterConsumption();
double targetWaterConsumption(Unit u);
bool hasTargetWaterConsumption();
private:
void processContent(Telegram *t);
double total_water_consumption_m3_ {};
double target_water_consumption_m3_ {};
};
MKRadio4::MKRadio4(MeterInfo &mi) :
MeterCommonImplementation(mi, "mkradio4")
{
setMeterType(MeterType::WaterMeter);
setExpectedTPLSecurityMode(TPLSecurityMode::AES_CBC_IV);
addLinkMode(LinkMode::T1);
addPrint("total", Quantity::Volume,
[&](Unit u){ return totalWaterConsumption(u); },
"The total water consumption recorded by this meter.",
PrintProperty::FIELD | PrintProperty::JSON);
addPrint("target", Quantity::Volume,
[&](Unit u){ return targetWaterConsumption(u); },
"The total water consumption recorded at the beginning of this month.",
PrintProperty::FIELD | PrintProperty::JSON);
}
shared_ptr<Meter> createMKRadio4(MeterInfo &mi)
{
return shared_ptr<Meter>(new MKRadio4(mi));
}
void MKRadio4::processContent(Telegram *t)
{
// Unfortunately, the MK Radio 4 is mostly a proprieatary protocol
// simple wrapped inside a wmbus telegram since the ci-field is 0xa2.
// Which means that the entire payload is manufacturer specific.
map<string,pair<int,DVEntry>> vendor_values;
vector<uchar> content;
t->extractPayload(&content);
uchar prev_lo = content[3];
uchar prev_hi = content[4];
double prev = (256.0*prev_hi+prev_lo)/10.0;
string prevs;
strprintf(&prevs, "%02x%02x", prev_lo, prev_hi);
int offset = t->parsed.size()+3;
vendor_values["0215"] = { offset, DVEntry(offset, DifVifKey("0215"), MeasurementType::Instantaneous, 0x15, {}, 0, 0, 0, prevs) };
t->explanations.push_back(Explanation(offset, 2, prevs, KindOfData::CONTENT, Understanding::FULL));
t->addMoreExplanation(offset, " prev consumption (%f m3)", prev);
uchar curr_lo = content[7];
uchar curr_hi = content[8];
double curr = (256.0*curr_hi+curr_lo)/10.0;
string currs;
strprintf(&currs, "%02x%02x", curr_lo, curr_hi);
offset = t->parsed.size()+7;
vendor_values["0215"] = { offset, DVEntry(offset, DifVifKey("0215"), MeasurementType::Instantaneous, 0x15, {}, 0, 0, 0, currs) };
t->explanations.push_back(Explanation(offset, 2, currs, KindOfData::CONTENT, Understanding::FULL));
t->addMoreExplanation(offset, " curr consumption (%f m3)", curr);
total_water_consumption_m3_ = prev+curr;
target_water_consumption_m3_ = prev;
}
double MKRadio4::totalWaterConsumption(Unit u)
{
assertQuantity(u, Quantity::Volume);
return convert(total_water_consumption_m3_, Unit::M3, u);
}
bool MKRadio4::hasTotalWaterConsumption()
{
return true;
}
double MKRadio4::targetWaterConsumption(Unit u)
{
return target_water_consumption_m3_;
}
bool MKRadio4::hasTargetWaterConsumption()
{
return true;
}

Wyświetl plik

@ -68,7 +68,6 @@ LIST_OF_METER_TYPES
X(gransystems,T1_bit, ElectricityMeter, CCx01, CCx01) \
X(hydrocalm3, T1_bit, HeatMeter, HYDROCALM3, HydrocalM3) \
X(hydrodigit, T1_bit, WaterMeter, HYDRODIGIT, Hydrodigit) \
X(mkradio4, T1_bit, WaterMeter, MKRADIO4, MKRadio4) \
X(multical302,C1_bit|T1_bit, HeatMeter, MULTICAL302, Multical302) \
X(multical403,C1_bit, HeatMeter, MULTICAL403, Multical403) \
X(multical602,C1_bit, HeatMeter, MULTICAL602, Multical602) \