kopia lustrzana https://github.com/weetmuts/wmbusmeters
Add m3ch unit for power based on m3c.
rodzic
802ed2fe96
commit
b9f756e5e9
|
@ -251,6 +251,17 @@ void MeterCommonImplementation::addExtraCalculatedField(string ecf)
|
||||||
|
|
||||||
Quantity quantity = toQuantity(unit);
|
Quantity quantity = toQuantity(unit);
|
||||||
|
|
||||||
|
FieldInfo *existing = findFieldInfo(vname, quantity);
|
||||||
|
if (existing != NULL)
|
||||||
|
{
|
||||||
|
if (!canConvert(unit, existing->displayUnit()))
|
||||||
|
{
|
||||||
|
warning("Warning! Cannot add the calculated field: %s since it would conflict with the already declared field %s for quantity %s.\n",
|
||||||
|
parts[0].c_str(), vname.c_str(), toString(quantity));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
addNumericFieldWithCalculator(
|
addNumericFieldWithCalculator(
|
||||||
vname,
|
vname,
|
||||||
"Calculated: "+ecf,
|
"Calculated: "+ecf,
|
||||||
|
@ -394,13 +405,13 @@ void MeterCommonImplementation::addNumericFieldWithExtractor(string vname,
|
||||||
Quantity vquantity,
|
Quantity vquantity,
|
||||||
VifScaling vif_scaling,
|
VifScaling vif_scaling,
|
||||||
FieldMatcher matcher,
|
FieldMatcher matcher,
|
||||||
Unit use_unit)
|
Unit display_unit)
|
||||||
{
|
{
|
||||||
field_infos_.emplace_back(
|
field_infos_.emplace_back(
|
||||||
FieldInfo(field_infos_.size(),
|
FieldInfo(field_infos_.size(),
|
||||||
vname,
|
vname,
|
||||||
vquantity,
|
vquantity,
|
||||||
use_unit == Unit::Unknown ? defaultUnitForQuantity(vquantity) : use_unit,
|
display_unit == Unit::Unknown ? defaultUnitForQuantity(vquantity) : display_unit,
|
||||||
vif_scaling,
|
vif_scaling,
|
||||||
matcher,
|
matcher,
|
||||||
help,
|
help,
|
||||||
|
@ -419,7 +430,7 @@ void MeterCommonImplementation::addNumericFieldWithCalculator(string vname,
|
||||||
PrintProperties print_properties,
|
PrintProperties print_properties,
|
||||||
Quantity vquantity,
|
Quantity vquantity,
|
||||||
string formula,
|
string formula,
|
||||||
Unit use_unit)
|
Unit display_unit)
|
||||||
{
|
{
|
||||||
Formula *f = newFormula();
|
Formula *f = newFormula();
|
||||||
bool ok = f->parse(this, formula);
|
bool ok = f->parse(this, formula);
|
||||||
|
@ -438,7 +449,7 @@ void MeterCommonImplementation::addNumericFieldWithCalculator(string vname,
|
||||||
FieldInfo(field_infos_.size(),
|
FieldInfo(field_infos_.size(),
|
||||||
vname,
|
vname,
|
||||||
vquantity,
|
vquantity,
|
||||||
use_unit == Unit::Unknown ? defaultUnitForQuantity(vquantity) : use_unit,
|
display_unit == Unit::Unknown ? defaultUnitForQuantity(vquantity) : display_unit,
|
||||||
VifScaling::Auto,
|
VifScaling::Auto,
|
||||||
FieldMatcher::noMatcher(),
|
FieldMatcher::noMatcher(),
|
||||||
help,
|
help,
|
||||||
|
@ -458,7 +469,7 @@ void MeterCommonImplementation::addNumericFieldWithCalculatorAndMatcher(string v
|
||||||
Quantity vquantity,
|
Quantity vquantity,
|
||||||
string formula,
|
string formula,
|
||||||
FieldMatcher matcher,
|
FieldMatcher matcher,
|
||||||
Unit use_unit)
|
Unit display_unit)
|
||||||
{
|
{
|
||||||
Formula *f = newFormula();
|
Formula *f = newFormula();
|
||||||
bool ok = f->parse(this, formula);
|
bool ok = f->parse(this, formula);
|
||||||
|
@ -477,7 +488,7 @@ void MeterCommonImplementation::addNumericFieldWithCalculatorAndMatcher(string v
|
||||||
FieldInfo(field_infos_.size(),
|
FieldInfo(field_infos_.size(),
|
||||||
vname,
|
vname,
|
||||||
vquantity,
|
vquantity,
|
||||||
use_unit == Unit::Unknown ? defaultUnitForQuantity(vquantity) : use_unit,
|
display_unit == Unit::Unknown ? defaultUnitForQuantity(vquantity) : display_unit,
|
||||||
VifScaling::Auto,
|
VifScaling::Auto,
|
||||||
matcher,
|
matcher,
|
||||||
help,
|
help,
|
||||||
|
@ -522,13 +533,13 @@ void MeterCommonImplementation::addNumericField(
|
||||||
Quantity vquantity,
|
Quantity vquantity,
|
||||||
PrintProperties print_properties,
|
PrintProperties print_properties,
|
||||||
string help,
|
string help,
|
||||||
Unit use_unit)
|
Unit display_unit)
|
||||||
{
|
{
|
||||||
field_infos_.emplace_back(
|
field_infos_.emplace_back(
|
||||||
FieldInfo(field_infos_.size(),
|
FieldInfo(field_infos_.size(),
|
||||||
vname,
|
vname,
|
||||||
vquantity,
|
vquantity,
|
||||||
use_unit == Unit::Unknown ? defaultUnitForQuantity(vquantity) : use_unit,
|
display_unit == Unit::Unknown ? defaultUnitForQuantity(vquantity) : display_unit,
|
||||||
VifScaling::None,
|
VifScaling::None,
|
||||||
FieldMatcher::noMatcher(),
|
FieldMatcher::noMatcher(),
|
||||||
help,
|
help,
|
||||||
|
@ -1169,8 +1180,8 @@ bool checkPrintableField(string *buf, string field, Meter *m, Telegram *t, char
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Doubles have to be converted into the proper unit.
|
// Doubles have to be converted into the proper unit.
|
||||||
string default_unit = unitToStringLowerCase(fi.displayUnit());
|
string display_unit_s = unitToStringLowerCase(fi.displayUnit());
|
||||||
string var = fi.vname()+"_"+default_unit;
|
string var = fi.vname()+"_"+display_unit_s;
|
||||||
if (field == var)
|
if (field == var)
|
||||||
{
|
{
|
||||||
// Default unit.
|
// Default unit.
|
||||||
|
@ -1713,10 +1724,10 @@ string FieldInfo::generateFieldNameWithUnit(DVEntry *dve)
|
||||||
return field_name_->apply(dve);
|
return field_name_->apply(dve);
|
||||||
}
|
}
|
||||||
|
|
||||||
string default_unit = unitToStringLowerCase(displayUnit());
|
string display_unit_s = unitToStringLowerCase(displayUnit());
|
||||||
string var = field_name_->apply(dve);
|
string var = field_name_->apply(dve);
|
||||||
|
|
||||||
return var+"_"+default_unit;
|
return var+"_"+display_unit_s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1724,7 +1735,7 @@ string FieldInfo::renderJson(Meter *m, DVEntry *dve)
|
||||||
{
|
{
|
||||||
string s;
|
string s;
|
||||||
|
|
||||||
string default_unit = unitToStringLowerCase(displayUnit());
|
string display_unit_s = unitToStringLowerCase(displayUnit());
|
||||||
string field_name = generateFieldNameNoUnit(dve);
|
string field_name = generateFieldNameNoUnit(dve);
|
||||||
|
|
||||||
if (xuantity() == Quantity::Text)
|
if (xuantity() == Quantity::Text)
|
||||||
|
@ -1749,16 +1760,16 @@ string FieldInfo::renderJson(Meter *m, DVEntry *dve)
|
||||||
{
|
{
|
||||||
if (displayUnit() == Unit::DateLT)
|
if (displayUnit() == Unit::DateLT)
|
||||||
{
|
{
|
||||||
s += "\""+field_name+"_"+default_unit+"\":\""+strdate(m->getNumericValue(field_name, Unit::DateLT))+"\"";
|
s += "\""+field_name+"_"+display_unit_s+"\":\""+strdate(m->getNumericValue(field_name, Unit::DateLT))+"\"";
|
||||||
}
|
}
|
||||||
else if (displayUnit() == Unit::DateTimeLT)
|
else if (displayUnit() == Unit::DateTimeLT)
|
||||||
{
|
{
|
||||||
s += "\""+field_name+"_"+default_unit+"\":\""+strdatetime(m->getNumericValue(field_name, Unit::DateTimeLT))+"\"";
|
s += "\""+field_name+"_"+display_unit_s+"\":\""+strdatetime(m->getNumericValue(field_name, Unit::DateTimeLT))+"\"";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// All numeric values.
|
// All numeric values.
|
||||||
s += "\""+field_name+"_"+default_unit+"\":"+valueToString(m->getNumericValue(field_name, displayUnit()), displayUnit());
|
s += "\""+field_name+"_"+display_unit_s+"\":"+valueToString(m->getNumericValue(field_name, displayUnit()), displayUnit());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1929,7 +1940,7 @@ void MeterCommonImplementation::printMeter(Telegram *t,
|
||||||
{
|
{
|
||||||
if (fi.printProperties().hasJSON() && !fi.printProperties().hasHIDE())
|
if (fi.printProperties().hasJSON() && !fi.printProperties().hasHIDE())
|
||||||
{
|
{
|
||||||
string default_unit = unitToStringUpperCase(fi.displayUnit());
|
string display_unit_s = unitToStringUpperCase(fi.displayUnit());
|
||||||
string var = fi.vname();
|
string var = fi.vname();
|
||||||
std::transform(var.begin(), var.end(), var.begin(), ::toupper);
|
std::transform(var.begin(), var.end(), var.begin(), ::toupper);
|
||||||
if (fi.xuantity() == Quantity::Text)
|
if (fi.xuantity() == Quantity::Text)
|
||||||
|
@ -1939,7 +1950,7 @@ void MeterCommonImplementation::printMeter(Telegram *t,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string envvar = "METER_"+var+"_"+default_unit+"="+valueToString(getNumericValue(&fi, fi.displayUnit()), fi.displayUnit());
|
string envvar = "METER_"+var+"_"+display_unit_s+"="+valueToString(getNumericValue(&fi, fi.displayUnit()), fi.displayUnit());
|
||||||
envs->push_back(envvar);
|
envs->push_back(envvar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,7 +145,7 @@ protected:
|
||||||
Quantity vquantity, // Value belongs to this quantity, this quantity determines the default unit.
|
Quantity vquantity, // Value belongs to this quantity, this quantity determines the default unit.
|
||||||
VifScaling vif_scaling, // How should any Vif value be scaled.
|
VifScaling vif_scaling, // How should any Vif value be scaled.
|
||||||
FieldMatcher matcher,
|
FieldMatcher matcher,
|
||||||
Unit use_unit = Unit::Unknown); // If specified use this unit for the json field instead instead of the default unit.
|
Unit display_unit = Unit::Unknown); // If specified use this unit for the json field instead instead of the default unit.
|
||||||
|
|
||||||
void addNumericFieldWithCalculator(
|
void addNumericFieldWithCalculator(
|
||||||
string vname, // Name of value without unit, eg "total" "total_month{storagenr}"
|
string vname, // Name of value without unit, eg "total" "total_month{storagenr}"
|
||||||
|
@ -153,7 +153,7 @@ protected:
|
||||||
PrintProperties print_properties, // Should this be printed by default in fields,json and hr.
|
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.
|
Quantity vquantity, // Value belongs to this quantity, this quantity determines the default unit.
|
||||||
string formula, // The formula can reference the other fields and + them together.
|
string formula, // The formula can reference the other fields and + them together.
|
||||||
Unit use_unit = Unit::Unknown); // If specified use this unit for the json field instead instead of the default unit.
|
Unit display_unit = Unit::Unknown); // If specified use this unit for the json field instead instead of the default unit.
|
||||||
|
|
||||||
void addNumericFieldWithCalculatorAndMatcher(
|
void addNumericFieldWithCalculatorAndMatcher(
|
||||||
string vname, // Name of value without unit, eg "total" "total_month{storagenr}"
|
string vname, // Name of value without unit, eg "total" "total_month{storagenr}"
|
||||||
|
@ -162,7 +162,7 @@ protected:
|
||||||
Quantity vquantity, // Value belongs to this quantity, this quantity determines the default unit.
|
Quantity vquantity, // Value belongs to this quantity, this quantity determines the default unit.
|
||||||
string formula, // The formula can reference the other fields and + them together.
|
string formula, // The formula can reference the other fields and + them together.
|
||||||
FieldMatcher matcher, // We can generate a calculated field per match.
|
FieldMatcher matcher, // We can generate a calculated field per match.
|
||||||
Unit use_unit = Unit::Unknown); // If specified use this unit for the json field instead instead of the default unit.
|
Unit display_unit = Unit::Unknown); // If specified use this unit for the json field instead instead of the default unit.
|
||||||
|
|
||||||
void addNumericField(
|
void addNumericField(
|
||||||
string vname, // Name of value without unit, eg total
|
string vname, // Name of value without unit, eg total
|
||||||
|
@ -177,7 +177,7 @@ protected:
|
||||||
Quantity vquantity, // Value belongs to this quantity.
|
Quantity vquantity, // Value belongs to this quantity.
|
||||||
PrintProperties print_properties, // Should this be printed by default in fields,json and hr.
|
PrintProperties print_properties, // Should this be printed by default in fields,json and hr.
|
||||||
string help,
|
string help,
|
||||||
Unit use_unit = Unit::Unknown); // If specified use this unit for the json field instead instead of the default unit.
|
Unit display_unit = Unit::Unknown); // If specified use this unit for the json field instead instead of the default unit.
|
||||||
|
|
||||||
#define SET_STRING_FUNC(varname) {[=](string s){varname = s;}}
|
#define SET_STRING_FUNC(varname) {[=](string s){varname = s;}}
|
||||||
#define GET_STRING_FUNC(varname) {[=](){return varname; }}
|
#define GET_STRING_FUNC(varname) {[=](){return varname; }}
|
||||||
|
|
|
@ -1929,6 +1929,10 @@ LIST_OF_QUANTITIES
|
||||||
fill_with_units_from(Quantity::Power, &to_set);
|
fill_with_units_from(Quantity::Power, &to_set);
|
||||||
|
|
||||||
test_si_convert(1, 1, Unit::KW, "kw", Unit::KW, "kw", Quantity::Power, &from_set, &to_set);
|
test_si_convert(1, 1, Unit::KW, "kw", Unit::KW, "kw", Quantity::Power, &from_set, &to_set);
|
||||||
|
// The power variant is m3ch.
|
||||||
|
test_si_convert(99.0, 99.0, Unit::M3CH, "m3ch", Unit::M3CH, "m3ch", Quantity::Power, &from_set, &to_set);
|
||||||
|
|
||||||
|
test_expected_failed_si_convert(Unit::M3CH, Unit::KW, Quantity::Power);
|
||||||
|
|
||||||
check_units_tested(from_set, to_set, Quantity::Power);
|
check_units_tested(from_set, to_set, Quantity::Power);
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,7 @@ using namespace std;
|
||||||
X(M3C, 1.0, SIExp().m(3).c(1)) \
|
X(M3C, 1.0, SIExp().m(3).c(1)) \
|
||||||
\
|
\
|
||||||
X(KW, 1000.0, SIExp().kg(1).m(2).s(-3)) \
|
X(KW, 1000.0, SIExp().kg(1).m(2).s(-3)) \
|
||||||
|
X(M3CH, 3600.0, SIExp().m(3).c(1).s(-1)) \
|
||||||
\
|
\
|
||||||
X(M3, 1.0, SIExp().m(3)) \
|
X(M3, 1.0, SIExp().m(3)) \
|
||||||
X(L, 1.0/1000.0, SIExp().m(3)) \
|
X(L, 1.0/1000.0, SIExp().m(3)) \
|
||||||
|
|
|
@ -85,6 +85,7 @@ LIST_OF_QUANTITIES
|
||||||
X(M3C,m3c,"m³°C",Energy,"cubic meter celsius") \
|
X(M3C,m3c,"m³°C",Energy,"cubic meter celsius") \
|
||||||
\
|
\
|
||||||
X(KW,kw,"kW",Power,"kilo Watt") \
|
X(KW,kw,"kW",Power,"kilo Watt") \
|
||||||
|
X(M3CH,m3ch,"m³°C/h",Power,"cubic meter celsius per hour") \
|
||||||
\
|
\
|
||||||
X(M3,m3,"m³",Volume,"cubic meter") \
|
X(M3,m3,"m³",Volume,"cubic meter") \
|
||||||
X(L,l,"l",Volume,"litre") \
|
X(L,l,"l",Volume,"litre") \
|
||||||
|
|
3
test.sh
3
test.sh
|
@ -87,6 +87,9 @@ if [ "$?" != "0" ]; then RC="1"; fi
|
||||||
tests/test_conversions.sh $PROG
|
tests/test_conversions.sh $PROG
|
||||||
if [ "$?" != "0" ]; then RC="1"; fi
|
if [ "$?" != "0" ]; then RC="1"; fi
|
||||||
|
|
||||||
|
tests/test_calculate.sh $PROG
|
||||||
|
if [ "$?" != "0" ]; then RC="1"; fi
|
||||||
|
|
||||||
tests/test_formulas.sh $PROG
|
tests/test_formulas.sh $PROG
|
||||||
if [ "$?" != "0" ]; then RC="1"; fi
|
if [ "$?" != "0" ]; then RC="1"; fi
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue