From cb1f62856020beef23b41761dbd6cbe46e7c11f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20=C3=96hrstr=C3=B6m?= Date: Fri, 24 Jun 2022 10:10:14 +0200 Subject: [PATCH] Add RemainingBattery vif. --- src/dvparser.h | 1 + src/meters.cc | 7 ++++--- src/meters_common_implementation.h | 5 +++-- src/units.cc | 2 ++ src/wmbus.cc | 8 ++++++++ 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/dvparser.h b/src/dvparser.h index d87dc69..723e56f 100644 --- a/src/dvparser.h +++ b/src/dvparser.h @@ -58,6 +58,7 @@ X(Current,0x7D50,0x7D5F, Quantity::Current, Unit::Ampere) \ X(ResetCounter,0x7D60,0x7D60, Quantity::Counter, Unit::COUNTER) \ X(CumulationCounter,0x7D61,0x7D61, Quantity::Counter, Unit::COUNTER) \ + X(RemainingBattery,0x7D74,0x7D74, Quantity::Time, Unit::Day) \ X(AnyVolumeVIF,0x00,0x00, Quantity::Volume, Unit::Unknown) \ X(AnyEnergyVIF,0x00,0x00, Quantity::Energy, Unit::Unknown) \ X(AnyPowerVIF,0x00,0x00, Quantity::Power, Unit::Unknown) \ diff --git a/src/meters.cc b/src/meters.cc index c16539a..2aefb66 100644 --- a/src/meters.cc +++ b/src/meters.cc @@ -803,7 +803,7 @@ void MeterCommonImplementation::addLinkMode(LinkMode lm) link_modes_.addLinkMode(lm); } -void MeterCommonImplementation::addMfctTPlStatusBits(Translate::Lookup lookup) +void MeterCommonImplementation::addMfctTPLStatusBits(Translate::Lookup lookup) { mfct_tpl_status_bits_ = lookup; } @@ -906,13 +906,14 @@ void MeterCommonImplementation::addNumericFieldWithExtractor(string vname, PrintProperties print_properties, Quantity vquantity, VifScaling vif_scaling, - FieldMatcher matcher) + FieldMatcher matcher, + Unit use_unit) { field_infos_.push_back( FieldInfo(field_infos_.size(), vname, vquantity, - defaultUnitForQuantity(vquantity), + use_unit == Unit::Unknown ? defaultUnitForQuantity(vquantity) : use_unit, vif_scaling, matcher, help, diff --git a/src/meters_common_implementation.h b/src/meters_common_implementation.h index 135e414..4cd1169 100644 --- a/src/meters_common_implementation.h +++ b/src/meters_common_implementation.h @@ -94,7 +94,7 @@ protected: std::vector &meterExtraConstantFields(); void setMeterType(MeterType mt); void addLinkMode(LinkMode lm); - void addMfctTPlStatusBits(Translate::Lookup lookup); + void addMfctTPLStatusBits(Translate::Lookup lookup); // Print with the default unit for this quantity. void addPrint(string vname, Quantity vquantity, @@ -140,7 +140,8 @@ protected: PrintProperties print_properties, // Should this be printed by default in fields,json and hr. Quantity vquantity, // Value belongs to this quantity, this quantity determines the default unit. VifScaling vif_scaling, // How should any Vif value be scaled. - FieldMatcher matcher); + FieldMatcher matcher, + Unit use_unit = Unit::Unknown); // If specified use this unit instead. void addNumericField( string vname, // Name of value without unit, eg total diff --git a/src/units.cc b/src/units.cc index d2c762e..fc861c2 100644 --- a/src/units.cc +++ b/src/units.cc @@ -37,6 +37,8 @@ using namespace std; X(Year, Hour, {vto=vfrom*24.0*365;}) \ X(Hour, Day, {vto=vfrom/24.0;}) \ X(Day, Hour, {vto=vfrom*24.0;}) \ + X(Day, Year, {vto=vfrom/365;}) \ + X(Year, Day, {vto=vfrom*365;}) \ X(KWH, GJ, {vto=vfrom*0.0036;}) \ X(KWH, MJ, {vto=vfrom*0.0036*1000.0;}) \ X(GJ, KWH,{vto=vfrom/0.0036;}) \ diff --git a/src/wmbus.cc b/src/wmbus.cc index a3171ee..011bc41 100644 --- a/src/wmbus.cc +++ b/src/wmbus.cc @@ -2822,6 +2822,9 @@ double vifScale(int vif) case 0x7d5e: case 0x7d5f: { double exp = (vif & 0xf)-12; return pow(10.0, -exp); } + // for remaining battery wmbusmeters returns number of days. + case 0x7d74: { return 1.0; } + /* case 0x78: // Fabrication no case 0x79: // Enhanced identification @@ -3613,6 +3616,11 @@ string vif_7D_SecondExtensionType(uchar dif, uchar vif, uchar vife) if ((vife & 0x7f) >= 0x71) { return "Reserved"; } + + if ((vife & 0x7f) == 0x74) { + return "Remaining battery in days"; + } + return "?"; }