Update tests to accomodate new json ordering of keys.

pull/1021/head
Fredrik Öhrström 2023-08-27 21:10:18 +02:00
rodzic 71fe4b4392
commit e577c0b30c
9 zmienionych plików z 100 dodań i 26 usunięć

Wyświetl plik

@ -25,7 +25,6 @@
#include"shell.h"
#include"threads.h"
#include"util.h"
#include"version.h"
#include"wmbus.h"
#include <algorithm>

Wyświetl plik

@ -289,16 +289,15 @@ namespace
// Type T1A2 telegram:
// telegram=|DA44496A5555445588077A320200002F2F_04140000000084800114000000008280016C2124C480011400000080C280016CFFFF84810114000000808281016CFFFFC481011400000080C281016CFFFF84820114000000808282016CFFFFC482011400000080C282016CFFFF84830114000000808283016CFFFFC483011400000080C283016CFFFF84840114000000808284016CFFFFC484011400000080C284016CFFFF84850114000000808285016CFFFFC485011400000080C285016CFFFF84860114000000808286016CFFFFC486011400000080C286016CFFFF|
// {"media":"water","meter":"c5isf","name":"Heat","id":"55445555","total_energy_consumption_kwh":0,"total_volume_m3":0,"status":"ERROR","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_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,"total_energy_consumption_last_month_kwh":0,"timestamp":"1111-11-11T11:11:11Z"}
// {"id": "55445555","media": "water","meter": "c5isf","name": "Heat","prev_10_month": "2127-15-31","prev_10_month_kwh": 2147483648,"prev_10_month_m3": 21474836.48,"prev_11_month": "2127-15-31","prev_11_month_kwh": 2147483648,"prev_11_month_m3": 21474836.48,"prev_12_month": "2127-15-31","prev_12_month_kwh": 2147483648,"prev_12_month_m3": 21474836.48,"prev_13_month": "2127-15-31","prev_13_month_kwh": 2147483648,"prev_13_month_m3": 21474836.48,"prev_14_month": "2127-15-31","prev_14_month_kwh": 2147483648,"prev_14_month_m3": 21474836.48,"prev_1_month": "2017-04-01","prev_1_month_kwh": 0,"prev_1_month_m3": 0,"prev_2_month": "2127-15-31","prev_2_month_kwh": 2147483648,"prev_2_month_m3": 21474836.48,"prev_3_month": "2127-15-31","prev_3_month_kwh": 2147483648,"prev_3_month_m3": 21474836.48,"prev_4_month": "2127-15-31","prev_4_month_kwh": 2147483648,"prev_4_month_m3": 21474836.48,"prev_5_month": "2127-15-31","prev_5_month_kwh": 2147483648,"prev_5_month_m3": 21474836.48,"prev_6_month": "2127-15-31","prev_6_month_kwh": 2147483648,"prev_6_month_m3": 21474836.48,"prev_7_month": "2127-15-31","prev_7_month_kwh": 2147483648,"prev_7_month_m3": 21474836.48,"prev_8_month": "2127-15-31","prev_8_month_kwh": 2147483648,"prev_8_month_m3": 21474836.48,"prev_9_month": "2127-15-31","prev_9_month_kwh": 2147483648,"prev_9_month_m3": 21474836.48,"status": "ERROR","timestamp": "1111-11-11T11:11:11Z","total_energy_consumption_kwh": 0,"total_energy_consumption_last_month_kwh": 0,"total_volume_m3": 0}
// |Heat;55445555;0;0;ERROR;1111-11-11 11:11.11
// Type T1B telegram:
// telegram=|5E44496A5555445588047A0A0050052F2F_04061A0000000413C20800008404060000000082046CC121043BA4000000042D1900000002591216025DE21002FD17000084800106000000008280016CC121948001AE25000000002F2F2F2F2F2F|
// {"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_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"}
// {"due_date": "2022-01-01","due_energy_consumption_kwh": 0,"flow_temperature_c": 56.5,"id": "55445555","max_power_last_month_kw": 0,"media": "heat","meter": "c5isf","name": "Heat","power_kw": 2.5,"prev_10_month": "2127-15-31","prev_10_month_kwh": 2147483648,"prev_10_month_m3": 21474836.48,"prev_11_month": "2127-15-31","prev_11_month_kwh": 2147483648,"prev_11_month_m3": 21474836.48,"prev_12_month": "2127-15-31","prev_12_month_kwh": 2147483648,"prev_12_month_m3": 21474836.48,"prev_13_month": "2127-15-31","prev_13_month_kwh": 2147483648,"prev_13_month_m3": 21474836.48,"prev_14_month": "2127-15-31","prev_14_month_kwh": 2147483648,"prev_14_month_m3": 21474836.48,"prev_1_month": "2022-01-01","prev_1_month_kwh": 0,"prev_1_month_m3": 0,"prev_2_month": "2127-15-31","prev_2_month_kwh": 2147483648,"prev_2_month_m3": 21474836.48,"prev_3_month": "2127-15-31","prev_3_month_kwh": 2147483648,"prev_3_month_m3": 21474836.48,"prev_4_month": "2127-15-31","prev_4_month_kwh": 2147483648,"prev_4_month_m3": 21474836.48,"prev_5_month": "2127-15-31","prev_5_month_kwh": 2147483648,"prev_5_month_m3": 21474836.48,"prev_6_month": "2127-15-31","prev_6_month_kwh": 2147483648,"prev_6_month_m3": 21474836.48,"prev_7_month": "2127-15-31","prev_7_month_kwh": 2147483648,"prev_7_month_m3": 21474836.48,"prev_8_month": "2127-15-31","prev_8_month_kwh": 2147483648,"prev_8_month_m3": 21474836.48,"prev_9_month": "2127-15-31","prev_9_month_kwh": 2147483648,"prev_9_month_m3": 21474836.48,"return_temperature_c": 43.22,"status": "OK","timestamp": "1111-11-11T11:11:11Z","total_energy_consumption_kwh": 26,"total_energy_consumption_last_month_kwh": 0,"total_volume_m3": 2.242,"volume_flow_m3h": 0.164}
// |Heat;55445555;26;2.242;OK;1111-11-11 11:11.11
// Test: Heat c5isf 32002044 NOKEY
// Test telegram with max_power_last_month_kwh which is non-zero
// telegram=|5E44496A4420003288047AFC0050052F2F_0406D00E00000413B28A05008404060000000082046CC121043B00000000042D000000000259E719025D051402FD17000084800106C00C00008280016CC125948001AE25090000002F2F2F2F2F2F|
// {"media":"heat","meter":"c5isf","name":"Heat","id":"32002044","total_energy_consumption_kwh":3792,"total_volume_m3":363.186,"status":"OK","prev_1_month":"2022-05-01","prev_1_month_kwh":3264,"due_energy_consumption_kwh":0,"due_date":"2022-01-01","volume_flow_m3h":0,"power_kw":0,"total_energy_consumption_last_month_kwh":3264,"max_power_last_month_kw":9,"flow_temperature_c":66.31,"return_temperature_c":51.25,"timestamp":"1111-11-11T11:11:11Z"}

Wyświetl plik

@ -118,7 +118,7 @@ namespace
// Test: Tempo piigth 10000284 NOKEY
// telegram=|68383868080072840200102941011B04000000_0265C0094265A509B20165000002FB1A900142FB1A6901B201FB1A00000C788402001002FD0F21000FC016|
// {"media":"room sensor","meter":"piigth","name":"Tempo","id":"10000284","fabrication_no":"10000284","software_version":"0021","status":"OK","temperature_c":24.96,"average_temperature_1h_c":24.69,"average_temperature_24h_c":null,"relative_humidity_rh":40,"relative_humidity_1h_rh":36.1,"relative_humidity_24h_rh":null,"timestamp":"1111-11-11T11:11:11Z"}
// {"media":"room sensor","meter":"piigth","name":"Tempo","id":"10000284","fabrication_no":"10000284","software_version":"0021","status":"OK","temperature_c":24.96,"average_temperature_1h_c":24.69,"relative_humidity_rh":40,"relative_humidity_1h_rh":36.1,"timestamp":"1111-11-11T11:11:11Z"}
// |Tempo;10000284;OK;24.96;40;1111-11-11 11:11.11
// telegram=|68383868080072840200102941011B06000000_02653F0A4265000A820165CA0902FB1A4F0142FB1A53018201FB1A5E010C788402001002FD0F21000F1916|

Wyświetl plik

@ -83,11 +83,13 @@ int main(int argc, char **argv)
{
tzset(); // Load the current timezone.
setVersion(VERSION);
auto config = parseCommandLine(argc, argv);
if (config->version)
{
printf("wmbusmeters: " VERSION "\n");
printf("wmbusmeters: %s\n", getVersion());
printf(COMMIT "\n");
exit(0);
}

Wyświetl plik

@ -1101,6 +1101,7 @@ bool MeterCommonImplementation::handleTelegram(AboutTelegram &about, vector<ucha
}
// Invoke any calculators working on the extracted fields.
processFieldCalculators();
// All done....
if (isDebugEnabled())
@ -1239,6 +1240,40 @@ void MeterCommonImplementation::processFieldCalculators()
}
}
string MeterCommonImplementation::getStatusField(FieldInfo *fi)
{
string field_name_no_unit = fi->vname();
if (string_values_.count(field_name_no_unit) == 0)
{
return "null"; // This is translated to a real(non-string) null in the json.
}
StringField &sf = string_values_[field_name_no_unit];
string value = sf.value;
// This is >THE< status field, only one is allowed.
// Look for other fields with the JOIN_INTO_STATUS marker.
// These other fields will not be printed, instead
// joined into this status field.
for (FieldInfo &f : field_infos_)
{
if (f.printProperties().hasINJECTINTOSTATUS())
{
//printf("NOW >%s<\n", value.c_str());
string more = getStringValue(&f);
//printf("MORE >%s<\n", more.c_str());
string joined = joinStatusOKStrings(value, more);
//printf("JOINED >%s<\n", joined.c_str());
value = joined;
}
}
// Sort all found flags and remove any duplicates. A well designed meter decoder
// should not be able to generate duplicates.
value = sortStatusString(value);
// If it is empty, then translate to OK!
if (value == "") value = "OK";
return value;
}
void MeterCommonImplementation::processContent(Telegram *t)
{
}
@ -1617,9 +1652,26 @@ void MeterCommonImplementation::printMeter(Telegram *t,
StringField& sf = p.second;
if (sf.field_info->printProperties().hasHIDE()) continue;
string out = tostrprintf("\"%s\":\"%s\"", vname.c_str(), sf.value.c_str());
s += indent+out+","+newline;
if (sf.field_info->printProperties().hasSTATUS())
{
string in = getStatusField(sf.field_info);
string out = tostrprintf("\"%s\":\"%s\"", vname.c_str(), in.c_str());
s += indent+out+","+newline;
}
else
{
if (sf.value == "null")
{
// The string "null" translates to actual json null.
string out = tostrprintf("\"%s\":null", vname.c_str());
s += indent+out+","+newline;
}
else
{
string out = tostrprintf("\"%s\":\"%s\"", vname.c_str(), sf.value.c_str());
s += indent+out+","+newline;
}
}
}
/*
for (FieldInfo& fi : field_infos_)

Wyświetl plik

@ -180,6 +180,7 @@ protected:
void processFieldExtractors(Telegram *t);
void processFieldCalculators();
string getStatusField(FieldInfo *fi);
virtual void processContent(Telegram *t);

Wyświetl plik

@ -17,7 +17,6 @@
#include"util.h"
#include"shell.h"
#include"version.h"
#include<algorithm>
#include<assert.h>
@ -386,6 +385,18 @@ void enableSyslog() {
syslog_enabled_ = true;
}
const char *version_;
void setVersion(const char *v)
{
version_ = v;
}
const char *getVersion()
{
return version_;
}
bool enableLogfile(const string& logfile, bool daemon)
{
log_file_ = logfile;
@ -397,7 +408,7 @@ bool enableLogfile(const string& logfile, bool daemon)
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", localtime(&now));
int n = 0;
if (daemon) {
n = fprintf(output, "(wmbusmeters) logging started %s using " VERSION "\n", buf);
n = fprintf(output, "(wmbusmeters) logging started %s %s\n", buf, version_);
if (n == 0) {
logfile_enabled_ = false;
return false;
@ -2346,6 +2357,10 @@ string joinStatusEmptyStrings(const string &aa, const string &bb)
return a;
}
if (a != "OK" && b == "OK") return a;
if (a == "OK" && b != "OK") return b;
if (a == "OK" && b == "OK") return a;
return a+" "+b;
}

Wyświetl plik

@ -26,6 +26,9 @@
#include<set>
#include<vector>
void setVersion(const char *v);
const char *getVersion();
void onExit(std::function<void()> cb);
void restoreSignalHandlers();
bool gotHupped();

Wyświetl plik

@ -14,7 +14,10 @@ then
echo "OK: $TESTNAME"
TESTRESULT="OK"
else
echo "ERROR: $TESTNAME $0"
if [ "$USE_MELD" = "true" ]
then
meld $TEST/test_expected.txt $TEST/test_response.txt
fi
fi
else
echo "ERROR: $TESTNAME $0"
@ -142,16 +145,16 @@ Using driver : multical21 00/00
"meter":"multical21",
"name":"",
"id":"76348799",
"status":"DRY",
"total_m3":6.408,
"target_m3":6.408,
"flow_temperature_c":127,
"external_temperature_c":19,
"flow_temperature_c":127,
"target_m3":6.408,
"total_m3":6.408,
"current_status":"DRY",
"time_dry":"22-31 days",
"time_reversed":"",
"time_leaking":"",
"status":"DRY",
"time_bursting":"",
"time_dry":"22-31 days",
"time_leaking":"",
"time_reversed":"",
"timestamp":"1111-11-11T11:11:11Z"
}
EOF
@ -196,16 +199,16 @@ Using driver : multical21 00/00
"meter":"multical21",
"name":"",
"id":"76348799",
"status":"DRY",
"total_m3":6.409,
"target_m3":6.409,
"flow_temperature_c":127,
"external_temperature_c":22,
"flow_temperature_c":127,
"target_m3":6.409,
"total_m3":6.409,
"current_status":"DRY",
"time_dry":"22-31 days",
"time_reversed":"",
"time_leaking":"",
"status":"DRY",
"time_bursting":"",
"time_dry":"22-31 days",
"time_leaking":"",
"time_reversed":"",
"timestamp":"1111-11-11T11:11:11Z"
}
EOF