kopia lustrzana https://github.com/weetmuts/wmbusmeters
Fix listenvs/listfields for new driver format.
rodzic
1450c2d86a
commit
70b7e51231
35
src/main.cc
35
src/main.cc
|
@ -187,8 +187,24 @@ void list_shell_envs(Configuration *config, string meter_driver)
|
|||
Telegram t;
|
||||
t.about.device = "?";
|
||||
MeterInfo mi;
|
||||
shared_ptr<Meter> meter;
|
||||
DriverInfo di;
|
||||
|
||||
mi.driver = toMeterDriver(meter_driver);
|
||||
shared_ptr<Meter> meter = createMeter(&mi);
|
||||
if (mi.driver != MeterDriver::UNKNOWN)
|
||||
{
|
||||
meter = createMeter(&mi);
|
||||
}
|
||||
else
|
||||
{
|
||||
mi.driver_name = meter_driver;
|
||||
if (!lookupDriverInfo(meter_driver, &di))
|
||||
{
|
||||
error("No such driver %s\n", meter_driver.c_str());
|
||||
}
|
||||
meter = di.construct(mi);
|
||||
}
|
||||
|
||||
meter->printMeter(&t,
|
||||
&ignore1,
|
||||
&ignore2, config->separator,
|
||||
|
@ -209,8 +225,23 @@ void list_shell_envs(Configuration *config, string meter_driver)
|
|||
void list_fields(Configuration *config, string meter_driver)
|
||||
{
|
||||
MeterInfo mi;
|
||||
shared_ptr<Meter> meter;
|
||||
DriverInfo di;
|
||||
|
||||
mi.driver = toMeterDriver(meter_driver);
|
||||
shared_ptr<Meter> meter = createMeter(&mi);
|
||||
if (mi.driver != MeterDriver::UNKNOWN)
|
||||
{
|
||||
meter = createMeter(&mi);
|
||||
}
|
||||
else
|
||||
{
|
||||
mi.driver_name = meter_driver;
|
||||
if (!lookupDriverInfo(meter_driver, &di))
|
||||
{
|
||||
error("No such driver %s\n", meter_driver.c_str());
|
||||
}
|
||||
meter = di.construct(mi);
|
||||
}
|
||||
|
||||
int width = 13; // Width of timestamp_utc
|
||||
for (auto &p : meter->prints())
|
||||
|
|
3
test.sh
3
test.sh
|
@ -30,6 +30,9 @@ if [ "$?" != "0" ]; then RC="1"; fi
|
|||
tests/test_anyid.sh $PROG
|
||||
if [ "$?" != "0" ]; then RC="1"; fi
|
||||
|
||||
./tests/test_list_envs.sh $PROG
|
||||
if [ "$?" != "0" ]; then RC="1"; fi
|
||||
|
||||
#tests/test_unknown.sh $PROG
|
||||
#if [ "$?" != "0" ]; then RC="1"; fi
|
||||
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
#!/bin/sh
|
||||
|
||||
PROG="$1"
|
||||
|
||||
mkdir -p testoutput
|
||||
TEST=testoutput
|
||||
|
||||
TESTNAME="Test list-envs and list-fields"
|
||||
TESTRESULT="ERROR"
|
||||
|
||||
$PROG --listenvs=amiplus > $TEST/test_output.txt 2>&1
|
||||
|
||||
cat <<EOF > $TEST/test_expected.txt
|
||||
METER_JSON
|
||||
METER_ID
|
||||
METER_NAME
|
||||
METER_MEDIA
|
||||
METER_TYPE
|
||||
METER_TIMESTAMP
|
||||
METER_TIMESTAMP_UTC
|
||||
METER_TIMESTAMP_UT
|
||||
METER_TIMESTAMP_LT
|
||||
METER_DEVICE
|
||||
METER_RSSI_DBM
|
||||
METER_TOTAL_ENERGY_CONSUMPTION_KWH
|
||||
METER_CURRENT_POWER_CONSUMPTION_KW
|
||||
METER_TOTAL_ENERGY_PRODUCTION_KWH
|
||||
METER_CURRENT_POWER_PRODUCTION_KW
|
||||
METER_VOLTAGE_AT_PHASE_1_Volt
|
||||
METER_VOLTAGE_AT_PHASE_2_Volt
|
||||
METER_VOLTAGE_AT_PHASE_3_Volt
|
||||
METER_DEVICE_DATE_TIME
|
||||
EOF
|
||||
|
||||
if [ "$?" = "0" ]
|
||||
then
|
||||
diff $TEST/test_expected.txt $TEST/test_output.txt
|
||||
if [ "$?" = "0" ]
|
||||
then
|
||||
echo OK: $TESTNAME
|
||||
TESTRESULT="OK"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$TESTRESULT" = "ERROR" ]
|
||||
then
|
||||
echo ERROR: $TESTNAME
|
||||
exit 1
|
||||
fi
|
||||
|
||||
$PROG --listfields=amiplus > $TEST/test_output.txt 2>&1
|
||||
|
||||
cat <<EOF > $TEST/test_expected.txt
|
||||
id The meter id number.
|
||||
name Your name for the meter.
|
||||
media What does the meter measure?
|
||||
meter Meter driver.
|
||||
timestamp Timestamp when wmbusmeters received the telegram. Local time for hr/fields UTC for json.
|
||||
timestamp_ut Unix timestamp when wmbusmeters received the telegram.
|
||||
timestamp_lt Local time when wmbusmeters received the telegram.
|
||||
timestamp_utc UTC time when wmbusmeters received the telegram.
|
||||
device The wmbus device that received the telegram.
|
||||
rssi_dbm The rssi for the received telegram as reported by the device.
|
||||
total_energy_consumption_kwh The total energy consumption recorded by this meter.
|
||||
current_power_consumption_kw Current power consumption.
|
||||
total_energy_production_kwh The total energy production recorded by this meter.
|
||||
current_power_production_kw Current power production.
|
||||
voltage_at_phase_1_v Voltage at phase L1.
|
||||
voltage_at_phase_2_v Voltage at phase L2.
|
||||
voltage_at_phase_3_v Voltage at phase L3.
|
||||
device_date_time_txt Device date time.
|
||||
EOF
|
||||
|
||||
if [ "$?" = "0" ]
|
||||
then
|
||||
diff $TEST/test_expected.txt $TEST/test_output.txt
|
||||
if [ "$?" = "0" ]
|
||||
then
|
||||
echo OK: $TESTNAME
|
||||
TESTRESULT="OK"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$TESTRESULT" = "ERROR" ]
|
||||
then
|
||||
echo ERROR: $TESTNAME
|
||||
exit 1
|
||||
fi
|
Ładowanie…
Reference in New Issue