Add manufacture year and serial number for SAP PRIOS devices

pull/249/head
Don-vip 2021-02-13 18:29:58 +01:00
rodzic dd456ea620
commit a9ad2d0256
3 zmienionych plików z 51 dodań i 5 usunięć

Wyświetl plik

@ -1,19 +1,19 @@
# Test IZAR RC 868 I R4 PL water meter telegram
telegram=|1944304C72242421D401A2|013D4013DD8B46A4999C1293E582CC|
{"media":"water","meter":"izar","name":"IzarWater","id":"21242472","total_m3":3.488,"last_month_total_m3":3.486,"last_month_measure_date":"2019-09-30","remaining_battery_life_y":14.5,"current_alarms":"meter_blocked,underflow","previous_alarms":"no_alarm","transmit_period_s":8,"timestamp":"1111-11-11T11:11:11Z"}
{"media":"water","meter":"izar","name":"IzarWater","id":"21242472","prefix":"C19UA","serial_number":"045842","total_m3":3.488,"last_month_total_m3":3.486,"last_month_measure_date":"2019-09-30","remaining_battery_life_y":14.5,"current_alarms":"meter_blocked,underflow","previous_alarms":"no_alarm","transmit_period_s":8,"manufacture_year":"2019","timestamp":"1111-11-11T11:11:11Z"}
# Test new version of IZAR
telegram=|2944A511780729662366A20118001378D3B3DB8CEDD77731F25832AAF3DA8CADF9774EA673172E8C61F2|
{"media":"water","meter":"izar","name":"IzarWater2","id":"66236629","total_m3":16.76,"last_month_total_m3":11.84,"last_month_measure_date":"2019-11-30","remaining_battery_life_y":12,"current_alarms":"no_alarm","previous_alarms":"no_alarm","transmit_period_s":8,"timestamp":"1111-11-11T11:11:11Z"}
{"media":"water","meter":"izar","name":"IzarWater2","id":"66236629","prefix":"","serial_number":"000000","total_m3":16.76,"last_month_total_m3":11.84,"last_month_measure_date":"2019-11-30","remaining_battery_life_y":12,"current_alarms":"no_alarm","previous_alarms":"no_alarm","transmit_period_s":8,"manufacture_year":"0","timestamp":"1111-11-11T11:11:11Z"}
# Yet another version of IZAR
telegram=|1944A511780779194820A1|21170013355F8EDB2D03C6912B1E37
{"media":"water","meter":"izar","name":"IzarWater3","id":"20481979","total_m3":4.366,"last_month_total_m3":0,"last_month_measure_date":"2020-12-31","remaining_battery_life_y":11.5,"current_alarms":"no_alarm","previous_alarms":"no_alarm","transmit_period_s":8,"timestamp":"1111-11-11T11:11:11Z"}
{"media":"water","meter":"izar","name":"IzarWater3","id":"20481979","prefix":"","serial_number":"000000","total_m3":4.366,"last_month_total_m3":0,"last_month_measure_date":"2020-12-31","remaining_battery_life_y":11.5,"current_alarms":"no_alarm","previous_alarms":"no_alarm","transmit_period_s":8,"manufacture_year":"0","timestamp":"1111-11-11T11:11:11Z"}
# And another izar, with a mfct specific tpl ci field a3.
telegram=|1944304c9c5824210c04a363140013716577ec59e8663ab0d31c|
{"media":"water","meter":"izar","name":"IzarWater4","id":"2124589c","total_m3":38.944,"last_month_total_m3":38.691,"last_month_measure_date":"2021-02-01","remaining_battery_life_y":10,"current_alarms":"no_alarm","previous_alarms":"no_alarm","transmit_period_s":32,"timestamp":"1111-11-11T11:11:11Z"}
{"media":"water","meter":"izar","name":"IzarWater4","id":"2124589c","prefix":"H19CA","serial_number":"059196","total_m3":38.944,"last_month_total_m3":38.691,"last_month_measure_date":"2021-02-01","remaining_battery_life_y":10,"current_alarms":"no_alarm","previous_alarms":"no_alarm","transmit_period_s":32,"manufacture_year":"2019","timestamp":"1111-11-11T11:11:11Z"}

Wyświetl plik

@ -58,6 +58,9 @@ enum class DiehlAddressTransformMethod {
SAP_PRIOS_STANDARD // ?
};
// Diehl: Determines how to interpret frame
DiehlFrameInterpretation detectDiehlFrameInterpretation(const vector<uchar>& frame);
// Diehl: Is "A field" coded differently from standard?
DiehlAddressTransformMethod mustTransformDiehlAddress(const vector<uchar>& frame);

Wyświetl plik

@ -49,6 +49,7 @@ struct MeterIzar : public virtual WaterMeter, public virtual MeterCommonImplemen
double totalWaterConsumption(Unit u);
bool hasTotalWaterConsumption();
string serialNumber();
double lastMonthTotalWaterConsumption(Unit u);
string setH0Date();
string currentAlarmsText();
@ -59,6 +60,8 @@ private:
void processContent(Telegram *t);
vector<uchar> decodePrios(const vector<uchar> &origin, const vector<uchar> &payload, uint32_t key);
string prefix;
uint32_t serial_number {0};
double remaining_battery_life;
uint16_t h0_year;
uint8_t h0_month;
@ -66,6 +69,7 @@ private:
double total_water_consumption_l_ {};
double last_month_total_water_consumption_l_ {};
uint32_t transmit_period_s_ {};
uint16_t manufacture_year {0};
izar_alarms alarms;
vector<uint32_t> keys;
@ -82,6 +86,16 @@ MeterIzar::MeterIzar(MeterInfo &mi) :
initializeDiehlDefaultKeySupport(meterKeys()->confidentiality_key, keys);
addLinkMode(LinkMode::T1);
addPrint("prefix", Quantity::Text,
[&](){ return prefix; },
"The alphanumeric prefix printed before serial number on device.",
true, true);
addPrint("serial_number", Quantity::Text,
[&](){ return serialNumber(); },
"The meter serial number.",
true, true);
addPrint("total", Quantity::Volume,
[&](Unit u){ return totalWaterConsumption(u); },
"The total water consumption recorded by this meter.",
@ -116,6 +130,11 @@ MeterIzar::MeterIzar(MeterInfo &mi) :
[&](Unit u){ return convert(transmit_period_s_, Unit::Second, u); },
"The period at which the meter transmits its data.",
true, true);
addPrint("manufacture_year", Quantity::Text,
[&](){ return to_string(manufacture_year); },
"The year during which the meter was manufactured.",
true, true);
}
double MeterIzar::totalWaterConsumption(Unit u)
@ -142,6 +161,13 @@ string MeterIzar::setH0Date()
return date;
}
string MeterIzar::serialNumber()
{
string result;
strprintf(result, "%06d", serial_number);
return result;
}
string MeterIzar::currentAlarmsText()
{
string s;
@ -202,10 +228,11 @@ void MeterIzar::processContent(Telegram *t)
{
vector<uchar> frame;
t->extractFrame(&frame);
vector<uchar> origin = t->original.empty() ? frame : t->original;
vector<uchar> decoded_content;
for (auto& key : keys) {
decoded_content = decodePrios(t->original.empty() ? frame : t->original, frame, key);
decoded_content = decodePrios(origin, frame, key);
if (!decoded_content.empty())
break;
}
@ -218,6 +245,22 @@ void MeterIzar::processContent(Telegram *t)
return;
}
if (detectDiehlFrameInterpretation(frame) == DiehlFrameInterpretation::SAP_PRIOS)
{
string digits = to_string((origin[7] >> 5) << 24 | origin[6] << 16 | origin[5] << 8 | origin[4]);
// get the manufacture year
uint8_t yy = atoi(digits.substr(0, 2).c_str());
manufacture_year = yy > 70 ? (1900 + yy) : (2000 + yy); // Maybe to adjust in 2070, if this code stills lives :D
// get the serial number
serial_number = atoi(digits.substr(3, digits.size()).c_str());
// get letters
uchar supplier_code = '@' + (((origin[9] & 0x0F) << 1) | (origin[8] >> 7));
uchar meter_type = '@' + ((origin[8] & 0x7C) >> 2);
uchar diameter = '@' + (((origin[8] & 0x03) << 3) | (origin[7] >> 5));
// build the prefix
strprintf(prefix, "%c%02d%c%c", supplier_code, yy, meter_type, diameter);
}
// get the remaining battery life (in year) and transmission period (in seconds)
remaining_battery_life = (frame[12] & 0x1F) / 2.0;
transmit_period_s_ = 1 << ((frame[11] & 0x0F) + 2);