wmbusmeters/src/driver_c5isf.cc

292 wiersze
16 KiB
C++
Czysty Zwykły widok Historia

/*
Copyright (C) 2022 Fredrik Öhrström (gpl-3.0-or-later)
2022 Alexander Streit (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"
struct MeterC5isf : public virtual MeterCommonImplementation
{
MeterC5isf(MeterInfo &mi, DriverInfo &di);
private:
// Three types of telegrams (T1A1 T1A2 T1B) they all share total_energy_kwh and total_volume_m3.
// The T1A1 and T1B also contains a status.
// T1A1 and T1A2 also contains the previous month dates.
// We assume that they are identical for both types of telegrams
// so we use the same storage here.
string prev_month_date_[14];
// T1A1 contains 14 back months of energy consumption.
double total_energy_prev_month_kwh_[14] {};
// T1A2 contains 14 back months of volume consumption.
double total_volume_prev_month_m3_[14] {};
// T1B contains:
2022-05-22 19:04:00 +00:00
// due_energy_kwh
2022-05-22 19:55:17 +00:00
// due_date
// volume_flow_m3h
2022-05-22 20:20:55 +00:00
// power_kw
// total_energy_last_month_kwh
string last_month_date_;
double max_power_last_month_kw_ {};
double flow_temperature_c_ {};
2022-05-22 20:20:55 +00:00
// return_temperature_c
};
static bool ok = registerDriver([](DriverInfo&di)
{
di.setName("c5isf");
di.setMeterType(MeterType::HeatMeter);
di.addLinkMode(LinkMode::T1);
di.addDetection(MANUFACTURER_ZRI, 0x0d, 0x88); // Telegram type T1A1
di.addDetection(MANUFACTURER_ZRI, 0x07, 0x88); // Telegram type T1A2
di.addDetection(MANUFACTURER_ZRI, 0x04, 0x88); // Telegram type T1B
di.setConstructor([](MeterInfo& mi, DriverInfo& di){ return shared_ptr<Meter>(new MeterC5isf(mi, di)); });
});
MeterC5isf::MeterC5isf(MeterInfo &mi, DriverInfo &di) : MeterCommonImplementation(mi, di)
{
// Fields common for T1A1, T1A2, T1B...........
2022-04-16 18:23:37 +00:00
addNumericFieldWithExtractor(
"total_energy_consumption",
"The total heat energy consumption recorded by this meter.",
2022-05-22 19:04:00 +00:00
PrintProperty::JSON | PrintProperty::FIELD | PrintProperty::IMPORTANT,
Quantity::Energy,
VifScaling::Auto,
FieldMatcher::build()
.set(MeasurementType::Instantaneous)
.set(VIFRange::EnergyWh)
);
2022-04-16 18:23:37 +00:00
addNumericFieldWithExtractor(
"total_volume",
"The total heating media volume recorded by this meter.",
2022-05-22 19:04:00 +00:00
PrintProperty::JSON | PrintProperty::FIELD | PrintProperty::IMPORTANT,
Quantity::Volume,
VifScaling::Auto,
FieldMatcher::build()
.set(MeasurementType::Instantaneous)
.set(VIFRange::Volume)
);
// Status field common for T1A1 and T1B
addStringFieldWithExtractorAndLookup(
"status",
"Status and error flags.",
2022-05-22 19:04:00 +00:00
PrintProperty::JSON | PrintProperty::FIELD | PrintProperty::IMPORTANT |
PrintProperty::STATUS | PrintProperty::JOIN_TPL_STATUS,
FieldMatcher::build()
.set(VIFRange::ErrorFlags),
{
{
{
"ERROR_FLAGS",
Translate::Type::DecimalsToString,
9999,
"OK",
{
{ 2000, "VERIFICATION_EXPIRED" }, // Status initial verification expired
{ 1000, "BATTERY_EXPIRED" }, // END Status end of the battery
{ 800, "WIRELESS_ERROR" }, // Wireless interface
{ 100, "HARDWARE_ERROR3" }, // Hardware error
{ 50, "VALUE_OVERLOAD" }, // Measured value outside overload range
{ 40, "AIR_INSIDE" }, // Air inside the medium Vent system (**)
{ 30, "REVERSE_FLOW" }, // Reverse water flow detected
{ 20, "DRY" }, // No water in the measuring tube
{ 10, "ERROR_MEASURING" }, // Error in the measuring system
{ 9, "HARDWARE_ERROR2" }, // Hardware error Exchange device
{ 8, "HARDWARE_ERROR1" }, // Hardware error Exchange device
{ 7, "LOW_BATTERY" }, // Battery voltage Exchange device
{ 6, "SUPPLY_SENSOR_INTERRUPTED" }, // Interruption supply sensor Check sensors
{ 5, "SHORT_CIRCUIT_SUPPLY_SENSOR" }, // Short circuit supply sensor Check sensors
{ 4, "RETURN_SENSOR_INTERRUPTED" }, // Interruption return sensor
{ 3, "SHORT_CIRCUIT_RETURN_SENSOR" }, // Short circuit return sensor / Check sensors
{ 2, "TEMP_ABOVE_RANGE" }, // Temperature above of measuring range
{ 1, "TEMP_BELOW_RANGE" }, // Temperature below of measuring range
}
},
},
});
// Dates are common to T1A1 and T1A2 ///////////////////////////////////////////////////////
for (int i=0; i<14; ++i)
{
addStringFieldWithExtractor(
tostrprintf("prev_%d_month", i+1),
Quantity::Text,
2022-04-16 15:47:20 +00:00
FIND_SFIELD_S(MeasurementType::Instantaneous, VIFRange::Date, StorageNr(32+i)),
PrintProperty::JSON,
"The due date.",
SET_STRING_FUNC(prev_month_date_[i]),
GET_STRING_FUNC(prev_month_date_[i]));
}
// Telegram type T1A1 ///////////////////////////////////////////////////////
for (int i=0; i<14; ++i)
{
2022-04-16 18:23:37 +00:00
addNumericFieldWithExtractor(
tostrprintf("prev_%d_month", i+1),
Quantity::Energy,
2022-04-16 15:47:20 +00:00
FIND_FIELD_S(MeasurementType::Instantaneous, VIFRange::EnergyWh, StorageNr(32+i)),
PrintProperty::JSON,
"The total heat energy consumption recorded at end of previous month.",
SET_FUNC(total_energy_prev_month_kwh_[i], Unit::KWH),
GET_FUNC(total_energy_prev_month_kwh_[i], Unit::KWH));
}
// Telegram type T1A2 ///////////////////////////////////////////////////////
for (int i=0; i<14; ++i)
{
2022-04-16 18:23:37 +00:00
addNumericFieldWithExtractor(
tostrprintf("prev_%d_month", i+1),
Quantity::Volume,
2022-04-16 15:47:20 +00:00
FIND_FIELD_S(MeasurementType::Instantaneous, VIFRange::Volume, StorageNr(32+i)),
PrintProperty::JSON,
tostrprintf("Previous month %d last date.", i+1),
SET_FUNC(total_volume_prev_month_m3_[i], Unit::M3),
GET_FUNC(total_volume_prev_month_m3_[i], Unit::M3));
}
// Telegram type T1B ///////////////////////////////////////////////////////
2022-04-16 18:23:37 +00:00
addNumericFieldWithExtractor(
"due_energy_consumption",
"The total heat energy consumption at the due date.",
2022-05-22 19:04:00 +00:00
PrintProperty::JSON | PrintProperty::OPTIONAL,
Quantity::Energy,
VifScaling::Auto,
FieldMatcher::build()
.set(MeasurementType::Instantaneous)
.set(StorageNr(8))
.set(VIFRange::EnergyWh)
);
addStringFieldWithExtractor(
"due_date",
"The due date.",
2022-05-22 19:55:17 +00:00
PrintProperty::JSON | PrintProperty::OPTIONAL,
FieldMatcher::build()
.set(MeasurementType::Instantaneous)
.set(StorageNr(8))
.set(VIFRange::Date)
);
2022-04-16 18:23:37 +00:00
addNumericFieldWithExtractor(
"volume_flow",
"The current heat media volume flow.",
2022-05-22 19:55:17 +00:00
PrintProperty::JSON | PrintProperty::OPTIONAL,
Quantity::Flow,
VifScaling::Auto,
FieldMatcher::build()
.set(MeasurementType::Instantaneous)
.set(VIFRange::VolumeFlow)
);
2022-04-16 18:23:37 +00:00
addNumericFieldWithExtractor(
"power",
"The current power consumption.",
2022-05-22 20:20:55 +00:00
PrintProperty::JSON | PrintProperty::OPTIONAL,
Quantity::Power,
VifScaling::Auto,
FieldMatcher::build()
.set(MeasurementType::Instantaneous)
.set(VIFRange::PowerW)
);
2022-04-16 18:23:37 +00:00
addNumericFieldWithExtractor(
"total_energy_consumption_last_month",
"The total heat energy consumption recorded at end of last month.",
2022-05-22 20:20:55 +00:00
PrintProperty::JSON | PrintProperty::OPTIONAL,
Quantity::Energy,
VifScaling::Auto,
FieldMatcher::build()
.set(MeasurementType::Instantaneous)
.set(StorageNr(32))
.set(VIFRange::EnergyWh)
);
addStringFieldWithExtractor(
"last_month_date",
"The due date.",
2022-05-22 20:20:55 +00:00
PrintProperty::JSON | PrintProperty::OPTIONAL,
FieldMatcher::build()
.set(MeasurementType::Instantaneous)
.set(VIFRange::DateTime)
);
2022-04-16 18:23:37 +00:00
addNumericFieldWithExtractor(
"max_power_last_month",
2022-05-22 20:33:04 +00:00
"Maximum power consumption last month.",
PrintProperty::JSON | PrintProperty::OPTIONAL,
Quantity::Power,
VifScaling::Auto,
2022-05-22 20:33:04 +00:00
FieldMatcher::build()
.set(MeasurementType::Maximum)
.set(StorageNr(32))
.set(VIFRange::PowerW)
.add(VIFCombinable::PerMonth)
);
2022-04-16 18:23:37 +00:00
addNumericFieldWithExtractor(
"flow_temperature",
2022-05-22 20:27:13 +00:00
"The current forward heat media temperature.",
PrintProperty::JSON | PrintProperty::OPTIONAL,
Quantity::Temperature,
VifScaling::Auto,
2022-05-22 20:27:13 +00:00
FieldMatcher::build()
.set(MeasurementType::Instantaneous)
.set(VIFRange::FlowTemperature)
);
2022-04-16 18:23:37 +00:00
addNumericFieldWithExtractor(
"return_temperature",
2022-05-22 20:20:55 +00:00
"The current return heat media temperature.",
PrintProperty::JSON | PrintProperty::OPTIONAL,
Quantity::Temperature,
VifScaling::Auto,
2022-05-22 20:20:55 +00:00
FieldMatcher::build()
.set(MeasurementType::Instantaneous)
.set(VIFRange::ReturnTemperature)
);
}
// Test: Heat c5isf 55445555 NOKEY
// telegram=|E544496A55554455880D7A320200002F2F_04060000000004130000000002FD17240084800106000000008280016C2124C480010600000080C280016CFFFF84810106000000808281016CFFFFC481010600000080C281016CFFFF84820106000000808282016CFFFFC482010600000080C282016CFFFF84830106000000808283016CFFFFC483010600000080C283016CFFFF84840106000000808284016CFFFFC484010600000080C284016CFFFF84850106000000808285016CFFFFC485010600000080C285016CFFFF84860106000000808286016CFFFFC486010600000080C286016CFFFF|
2022-05-22 20:33:04 +00:00
// {"media":"heat/cooling load","meter":"c5isf","name":"Heat","id":"55445555","total_energy_consumption_kwh":0,"total_volume_m3":0,"status":"ERROR REVERSE_FLOW SUPPLY_SENSOR_INTERRUPTED","prev_1_month":"2017-04-01","prev_2_month":"2127-15-31","prev_3_month":"2127-15-31","prev_4_month":"2127-15-31","prev_5_month":"2127-15-31","prev_6_month":"2127-15-31","prev_7_month":"2127-15-31","prev_8_month":"2127-15-31","prev_9_month":"2127-15-31","prev_10_month":"2127-15-31","prev_11_month":"2127-15-31","prev_12_month":"2127-15-31","prev_13_month":"2127-15-31","prev_14_month":"2127-15-31","prev_1_month_kwh":0,"prev_2_month_kwh":2147483648,"prev_3_month_kwh":2147483648,"prev_4_month_kwh":2147483648,"prev_5_month_kwh":2147483648,"prev_6_month_kwh":2147483648,"prev_7_month_kwh":2147483648,"prev_8_month_kwh":2147483648,"prev_9_month_kwh":2147483648,"prev_10_month_kwh":2147483648,"prev_11_month_kwh":2147483648,"prev_12_month_kwh":2147483648,"prev_13_month_kwh":2147483648,"prev_14_month_kwh":2147483648,"prev_1_month_m3":0,"prev_2_month_m3":0,"prev_3_month_m3":0,"prev_4_month_m3":0,"prev_5_month_m3":0,"prev_6_month_m3":0,"prev_7_month_m3":0,"prev_8_month_m3":0,"prev_9_month_m3":0,"prev_10_month_m3":0,"prev_11_month_m3":0,"prev_12_month_m3":0,"prev_13_month_m3":0,"prev_14_month_m3":0,"total_energy_consumption_last_month_kwh":0,"timestamp":"1111-11-11T11:11:11Z"}
2022-05-22 19:04:00 +00:00
// |Heat;55445555;0.000000;0.000000;ERROR REVERSE_FLOW SUPPLY_SENSOR_INTERRUPTED;1111-11-11 11:11.11
// Type T1A2 telegram:
// telegram=|DA44496A5555445588077A320200002F2F_04140000000084800114000000008280016C2124C480011400000080C280016CFFFF84810114000000808281016CFFFFC481011400000080C281016CFFFF84820114000000808282016CFFFFC482011400000080C282016CFFFF84830114000000808283016CFFFFC483011400000080C283016CFFFF84840114000000808284016CFFFFC484011400000080C284016CFFFF84850114000000808285016CFFFFC485011400000080C285016CFFFF84860114000000808286016CFFFFC486011400000080C286016CFFFF|
2022-05-22 20:33:04 +00:00
// {"media":"water","meter":"c5isf","name":"Heat","id":"55445555","total_energy_consumption_kwh":0,"total_volume_m3":0,"status":"ERROR REVERSE_FLOW SUPPLY_SENSOR_INTERRUPTED","prev_1_month":"2017-04-01","prev_2_month":"2127-15-31","prev_3_month":"2127-15-31","prev_4_month":"2127-15-31","prev_5_month":"2127-15-31","prev_6_month":"2127-15-31","prev_7_month":"2127-15-31","prev_8_month":"2127-15-31","prev_9_month":"2127-15-31","prev_10_month":"2127-15-31","prev_11_month":"2127-15-31","prev_12_month":"2127-15-31","prev_13_month":"2127-15-31","prev_14_month":"2127-15-31","prev_1_month_kwh":0,"prev_2_month_kwh":2147483648,"prev_3_month_kwh":2147483648,"prev_4_month_kwh":2147483648,"prev_5_month_kwh":2147483648,"prev_6_month_kwh":2147483648,"prev_7_month_kwh":2147483648,"prev_8_month_kwh":2147483648,"prev_9_month_kwh":2147483648,"prev_10_month_kwh":2147483648,"prev_11_month_kwh":2147483648,"prev_12_month_kwh":2147483648,"prev_13_month_kwh":2147483648,"prev_14_month_kwh":2147483648,"prev_1_month_m3":0,"prev_2_month_m3":21474836.48,"prev_3_month_m3":21474836.48,"prev_4_month_m3":21474836.48,"prev_5_month_m3":21474836.48,"prev_6_month_m3":21474836.48,"prev_7_month_m3":21474836.48,"prev_8_month_m3":21474836.48,"prev_9_month_m3":21474836.48,"prev_10_month_m3":21474836.48,"prev_11_month_m3":21474836.48,"prev_12_month_m3":21474836.48,"prev_13_month_m3":21474836.48,"prev_14_month_m3":21474836.48,"timestamp":"1111-11-11T11:11:11Z"}
2022-05-22 19:04:00 +00:00
// |Heat;55445555;0.000000;0.000000;ERROR REVERSE_FLOW SUPPLY_SENSOR_INTERRUPTED;1111-11-11 11:11.11
// Type T1B telegram:
// telegram=|5E44496A5555445588047A0A0050052F2F_04061A0000000413C20800008404060000000082046CC121043BA4000000042D1900000002591216025DE21002FD17000084800106000000008280016CC121948001AE25000000002F2F2F2F2F2F|
2022-05-22 20:20:55 +00:00
// {"media":"heat","meter":"c5isf","name":"Heat","id":"55445555","total_energy_consumption_kwh":26,"total_volume_m3":2.242,"status":"OK","prev_1_month":"2022-01-01","prev_2_month":"2127-15-31","prev_3_month":"2127-15-31","prev_4_month":"2127-15-31","prev_5_month":"2127-15-31","prev_6_month":"2127-15-31","prev_7_month":"2127-15-31","prev_8_month":"2127-15-31","prev_9_month":"2127-15-31","prev_10_month":"2127-15-31","prev_11_month":"2127-15-31","prev_12_month":"2127-15-31","prev_13_month":"2127-15-31","prev_14_month":"2127-15-31","prev_1_month_kwh":0,"prev_2_month_kwh":2147483648,"prev_3_month_kwh":2147483648,"prev_4_month_kwh":2147483648,"prev_5_month_kwh":2147483648,"prev_6_month_kwh":2147483648,"prev_7_month_kwh":2147483648,"prev_8_month_kwh":2147483648,"prev_9_month_kwh":2147483648,"prev_10_month_kwh":2147483648,"prev_11_month_kwh":2147483648,"prev_12_month_kwh":2147483648,"prev_13_month_kwh":2147483648,"prev_14_month_kwh":2147483648,"prev_1_month_m3":0,"prev_2_month_m3":21474836.48,"prev_3_month_m3":21474836.48,"prev_4_month_m3":21474836.48,"prev_5_month_m3":21474836.48,"prev_6_month_m3":21474836.48,"prev_7_month_m3":21474836.48,"prev_8_month_m3":21474836.48,"prev_9_month_m3":21474836.48,"prev_10_month_m3":21474836.48,"prev_11_month_m3":21474836.48,"prev_12_month_m3":21474836.48,"prev_13_month_m3":21474836.48,"prev_14_month_m3":21474836.48,"due_energy_consumption_kwh":0,"due_date":"2022-01-01","volume_flow_m3h":0.164,"power_kw":2.5,"total_energy_consumption_last_month_kwh":0,"max_power_last_month_kw":0,"flow_temperature_c":56.5,"return_temperature_c":43.22,"timestamp":"1111-11-11T11:11:11Z"}
// |Heat;55445555;26.000000;2.242000;OK;1111-11-11 11:11.11