kopia lustrzana https://github.com/weetmuts/wmbusmeters
Enable stdin/file/simulation before event loop started, enable other devices after event loop started.
rodzic
1f4083e6d0
commit
a610179331
|
@ -481,10 +481,21 @@ shared_ptr<Configuration> parseCommandLine(int argc, char **argv) {
|
|||
while (argv[i])
|
||||
{
|
||||
bool ok = handleDevice(c, argv[i]);
|
||||
if (!ok) break;
|
||||
if (!ok)
|
||||
{
|
||||
if (!argv[i+1])
|
||||
{
|
||||
// This was the last argument on the commandline.
|
||||
// It should have been a device or a file.
|
||||
error("Not a valid device \"%s\"\n", argv[i]);
|
||||
}
|
||||
// There are more arguments...
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
if (c->supplied_wmbus_devices.size() == 0 &&
|
||||
c->use_auto_device_detect == false &&
|
||||
!c->list_shell_envs &&
|
||||
|
|
|
@ -67,7 +67,16 @@ void parseMeterConfig(Configuration *c, vector<char> &buf, string file)
|
|||
// If the key starts with # then the line is a comment. Ignore it.
|
||||
if (p.first.length() > 0 && p.first[0] == '#') continue;
|
||||
|
||||
if (p.first == "name") name = p.second;
|
||||
if (p.first == "name")
|
||||
{
|
||||
if (name.find(":") != string::npos)
|
||||
{
|
||||
// Oups, names are not allowed to contain the :
|
||||
warning("Found invalid meter name \"%s\" in meter config file, must not contain a ':', skipping meter.\n", name.c_str());
|
||||
return;
|
||||
}
|
||||
name = p.second;
|
||||
}
|
||||
else
|
||||
if (p.first == "type") type = p.second;
|
||||
else
|
||||
|
|
27
src/main.cc
27
src/main.cc
|
@ -49,7 +49,8 @@ void check_for_dead_wmbus_devices(Configuration *config);
|
|||
shared_ptr<Meter> create_meter(Configuration *config, MeterType type, MeterInfo *mi, const char *keymsg);
|
||||
shared_ptr<Printer> create_printer(Configuration *config);
|
||||
shared_ptr<WMBus> create_wmbus_object(Detected *detected, Configuration *config, shared_ptr<SerialCommunicationManager> manager);
|
||||
void detect_and_configure_wmbus_devices(Configuration *config);
|
||||
enum class DetectionType { STDIN_FILE_SIMULATION, ALL };
|
||||
void detect_and_configure_wmbus_devices(Configuration *config, DetectionType dt);
|
||||
SpecifiedDevice *find_specified_device_from_detected(Configuration *c, Detected *d);
|
||||
bool find_specified_device_and_update_detected(Configuration *c, Detected *d);
|
||||
void find_specified_device_and_mark_as_handled(Configuration *c, Detected *d);
|
||||
|
@ -310,7 +311,8 @@ LIST_OF_METERS
|
|||
return newm;
|
||||
}
|
||||
|
||||
shared_ptr<WMBus> create_wmbus_object(Detected *detected, Configuration *config, shared_ptr<SerialCommunicationManager> manager)
|
||||
shared_ptr<WMBus> create_wmbus_object(Detected *detected, Configuration *config,
|
||||
shared_ptr<SerialCommunicationManager> manager)
|
||||
{
|
||||
shared_ptr<WMBus> wmbus;
|
||||
|
||||
|
@ -486,7 +488,7 @@ shared_ptr<Printer> create_printer(Configuration *config)
|
|||
config->meterfiles_timestamp));
|
||||
}
|
||||
|
||||
void detect_and_configure_wmbus_devices(Configuration *config)
|
||||
void detect_and_configure_wmbus_devices(Configuration *config, DetectionType dt)
|
||||
{
|
||||
check_for_dead_wmbus_devices(config);
|
||||
|
||||
|
@ -494,7 +496,7 @@ void detect_and_configure_wmbus_devices(Configuration *config)
|
|||
bool must_auto_find_rtlsdrs = false;
|
||||
|
||||
// The device=auto has been specified....
|
||||
if (config->use_auto_device_detect)
|
||||
if (config->use_auto_device_detect && dt == DetectionType::ALL)
|
||||
{
|
||||
must_auto_find_ttys = true;
|
||||
must_auto_find_rtlsdrs = true;
|
||||
|
@ -503,6 +505,15 @@ void detect_and_configure_wmbus_devices(Configuration *config)
|
|||
for (SpecifiedDevice &specified_device : config->supplied_wmbus_devices)
|
||||
{
|
||||
specified_device.handled = false;
|
||||
if (dt != DetectionType::ALL)
|
||||
{
|
||||
if (!specified_device.is_stdin && !specified_device.is_file && !specified_device.is_simulation)
|
||||
{
|
||||
// The event loop has not yet started and this is not stdin nor a file, nor a simulation file.
|
||||
// Therefore, do not try to detect it yet!
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (specified_device.file == "" && specified_device.command == "")
|
||||
{
|
||||
// File/tty/command not specified, use auto scan later to find actual device file/tty.
|
||||
|
@ -583,7 +594,7 @@ void detect_and_configure_wmbus_devices(Configuration *config)
|
|||
|
||||
for (SpecifiedDevice &specified_device : config->supplied_wmbus_devices)
|
||||
{
|
||||
if (!specified_device.handled)
|
||||
if (dt == DetectionType::ALL && !specified_device.handled)
|
||||
{
|
||||
time_t last_alarm = specified_device.last_alarm;
|
||||
time_t now = time(NULL);
|
||||
|
@ -973,7 +984,7 @@ void regular_checkup(Configuration *config)
|
|||
|
||||
if (serial_manager_ && config)
|
||||
{
|
||||
detect_and_configure_wmbus_devices(config);
|
||||
detect_and_configure_wmbus_devices(config, DetectionType::ALL);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -1124,10 +1135,12 @@ bool start(Configuration *config)
|
|||
// Future changes are triggered through this callback.
|
||||
printed_warning_ = true;
|
||||
|
||||
detect_and_configure_wmbus_devices(config);
|
||||
detect_and_configure_wmbus_devices(config, DetectionType::STDIN_FILE_SIMULATION);
|
||||
|
||||
serial_manager_->startEventLoop();
|
||||
|
||||
detect_and_configure_wmbus_devices(config, DetectionType::ALL);
|
||||
|
||||
if (wmbus_devices_.size() == 0)
|
||||
{
|
||||
notice("No wmbus device detected, waiting for a device to be plugged in.\n");
|
||||
|
|
|
@ -1464,7 +1464,7 @@ void logAlarm(Alarm type, string info)
|
|||
string ts = toString(type);
|
||||
envs.push_back("ALARM_TYPE="+ts);
|
||||
|
||||
string msg = tostrprintf("(alarm %s) %s", ts.c_str(), info.c_str());
|
||||
string msg = tostrprintf("[ALARM %s] %s", ts.c_str(), info.c_str());
|
||||
envs.push_back("ALARM_MESSAGE="+msg);
|
||||
|
||||
warning("%s\n", msg.c_str());
|
||||
|
|
|
@ -25,7 +25,7 @@ cat /tmp/wmbusmeters_alarm_test
|
|||
echo "---------------------------------------"
|
||||
|
||||
cat > $TEST/test_expected.txt <<EOF
|
||||
(alarm DeviceInactivity) 4 seconds of inactivity resetting simulations/simulation_alarm.txt simulation (timeout 4s expected mon-sun(00-23) now 1111-11-11 11:11)
|
||||
[ALARM DeviceInactivity] 4 seconds of inactivity resetting simulations/simulation_alarm.txt simulation (timeout 4s expected mon-sun(00-23) now 1111-11-11 11:11)
|
||||
(wmbus) successfully reset wmbus device
|
||||
EOF
|
||||
|
||||
|
@ -35,7 +35,7 @@ METER =={"media":"cold water","meter":"multical21","name":"Water","id":"76348799
|
|||
EOF
|
||||
|
||||
cat > /tmp/wmbusmeters_alarm_expected <<EOF
|
||||
ALARM_SHELL DeviceInactivity (alarm DeviceInactivity) 4 seconds of inactivity resetting simulations/simulation_alarm.txt simulation (timeout 4s expected mon-sun(00-23) now 1111-11-11 11:11)
|
||||
ALARM_SHELL DeviceInactivity [ALARM DeviceInactivity] 4 seconds of inactivity resetting simulations/simulation_alarm.txt simulation (timeout 4s expected mon-sun(00-23) now 1111-11-11 11:11)
|
||||
EOF
|
||||
|
||||
cat $TEST/test_stderr.txt | sed 's/now ....-..-.. ..:../now 1111-11-11 11:11/' > $TEST/test_responses.txt
|
||||
|
|
|
@ -11,7 +11,7 @@ TESTNAME="Test rtlwmbus starting background script to produce telegrams"
|
|||
TESTRESULT="ERROR"
|
||||
|
||||
cat tests/rtlwmbus_water.sh | grep '^#{' | tr -d '#' > $TEST/test_expected.txt
|
||||
$PROG --format=json "rtlwmbus:CMD(tests/rtlwmbus_water.sh)" \
|
||||
$PROG --silent --format=json "rtlwmbus:CMD(tests/rtlwmbus_water.sh)" \
|
||||
ApWater apator162 88888888 00000000000000000000000000000000 \
|
||||
| grep -v "(rtlwmbus) child process exited! Command was:" \
|
||||
> $TEST/test_output.txt
|
||||
|
|
|
@ -16,7 +16,7 @@ cat > $TEST/test_expected.txt <<EOF
|
|||
EOF
|
||||
|
||||
xxd -r -p simulations/serial_rawtty_ok.hex | \
|
||||
$PROG --format=json --listento=any stdin \
|
||||
$PROG --silent --format=json --listento=any stdin \
|
||||
Rummet1 lansenth 00010203 "" \
|
||||
Rummet2 rfmamb 11772288 "" \
|
||||
| grep Rummet > $TEST/test_output.txt
|
||||
|
@ -43,7 +43,7 @@ cat > $TEST/test_expected.txt <<EOF
|
|||
{"media":"room sensor","meter":"rfmamb","name":"Rummet2","id":"11772288","current_temperature_c":22.08,"average_temperature_1h_c":21.91,"average_temperature_24h_c":22.07,"maximum_temperature_1h_c":22.08,"minimum_temperature_1h_c":21.85,"maximum_temperature_24h_c":23.47,"minimum_temperature_24h_c":21.29,"current_relative_humidity_rh":44.2,"average_relative_humidity_1h_rh":43.2,"average_relative_humidity_24h_rh":44.5,"minimum_relative_humidity_1h_rh":42.2,"maximum_relative_humidity_1h_rh":50.1,"maximum_relative_humidity_24h_rh":0,"minimum_relative_humidity_24h_rh":0,"device_date_time":"2019-10-11 19:59","timestamp":"1111-11-11T11:11:11Z"}
|
||||
EOF
|
||||
|
||||
xxd -r -p simulations/serial_rawtty_bad.hex | $PROG --format=json --listento=any stdin Rummet1 lansenth 00010203 "" Rummet2 rfmamb 11772288 "" | grep Rummet > $TEST/test_output.txt
|
||||
xxd -r -p simulations/serial_rawtty_bad.hex | $PROG --silent --format=json --listento=any stdin Rummet1 lansenth 00010203 "" Rummet2 rfmamb 11772288 "" | grep Rummet > $TEST/test_output.txt
|
||||
|
||||
if [ "$?" = "0" ]
|
||||
then
|
||||
|
|
|
@ -16,7 +16,7 @@ cat > $TEST/test_expected.txt <<EOF
|
|||
EOF
|
||||
|
||||
xxd -r -p simulations/serial_rawtty_ok.hex | \
|
||||
$PROG --format=json --listento=any stdin \
|
||||
$PROG --silent --format=json --listento=any stdin \
|
||||
Rummet1 lansenth 00010203 "" \
|
||||
Rummet2 rfmamb 11772288 "" \
|
||||
| grep Rummet > $TEST/test_output.txt
|
||||
|
@ -46,7 +46,7 @@ cat > $TEST/test_expected.txt <<EOF
|
|||
{"media":"room sensor","meter":"rfmamb","name":"Rummet2","id":"11772288","current_temperature_c":22.08,"average_temperature_1h_c":21.91,"average_temperature_24h_c":22.07,"maximum_temperature_1h_c":22.08,"minimum_temperature_1h_c":21.85,"maximum_temperature_24h_c":23.47,"minimum_temperature_24h_c":21.29,"current_relative_humidity_rh":44.2,"average_relative_humidity_1h_rh":43.2,"average_relative_humidity_24h_rh":44.5,"minimum_relative_humidity_1h_rh":42.2,"maximum_relative_humidity_1h_rh":50.1,"maximum_relative_humidity_24h_rh":0,"minimum_relative_humidity_24h_rh":0,"device_date_time":"2019-10-11 19:59","timestamp":"1111-11-11T11:11:11Z"}
|
||||
EOF
|
||||
|
||||
$PROG --format=json --listento=any $TEST/test_raw \
|
||||
$PROG --silent --format=json --listento=any $TEST/test_raw \
|
||||
Rummet1 lansenth 00010203 "" \
|
||||
Rummet2 rfmamb 11772288 "" \
|
||||
| grep Rummet > $TEST/test_output.txt
|
||||
|
@ -74,7 +74,7 @@ cat > $TEST/test_expected.txt <<EOF
|
|||
EOF
|
||||
|
||||
cat simulations/serial_rtlwmbus_ok.msg | \
|
||||
$PROG --format=json --listento=any stdin:rtlwmbus \
|
||||
$PROG --silent --format=json --listento=any stdin:rtlwmbus \
|
||||
Rummet1 lansenth 00010203 "" \
|
||||
Rummet2 rfmamb 11772288 "" \
|
||||
| grep Rummet > $TEST/test_output.txt
|
||||
|
@ -101,7 +101,7 @@ cat > $TEST/test_expected.txt <<EOF
|
|||
{"media":"room sensor","meter":"rfmamb","name":"Rummet2","id":"11772288","current_temperature_c":22.08,"average_temperature_1h_c":21.91,"average_temperature_24h_c":22.07,"maximum_temperature_1h_c":22.08,"minimum_temperature_1h_c":21.85,"maximum_temperature_24h_c":23.47,"minimum_temperature_24h_c":21.29,"current_relative_humidity_rh":44.2,"average_relative_humidity_1h_rh":43.2,"average_relative_humidity_24h_rh":44.5,"minimum_relative_humidity_1h_rh":42.2,"maximum_relative_humidity_1h_rh":50.1,"maximum_relative_humidity_24h_rh":0,"minimum_relative_humidity_24h_rh":0,"device_date_time":"2019-10-11 19:59","timestamp":"1111-11-11T11:11:11Z","device":"rtlwmbus[]","rssi_dbm":97}
|
||||
EOF
|
||||
|
||||
$PROG --format=json --listento=any simulations/serial_rtlwmbus_ok.msg:rtlwmbus \
|
||||
$PROG --silent --format=json --listento=any simulations/serial_rtlwmbus_ok.msg:rtlwmbus \
|
||||
Rummet1 lansenth 00010203 "" \
|
||||
Rummet2 rfmamb 11772288 "" \
|
||||
| grep Rummet > $TEST/test_output.txt
|
||||
|
@ -127,7 +127,7 @@ cat > $TEST/test_expected.txt <<EOF
|
|||
EOF
|
||||
|
||||
cat simulations/serial_rtl433_ok.msg | \
|
||||
$PROG --format=json --listento=any stdin:rtl433 \
|
||||
$PROG --silent --format=json --listento=any stdin:rtl433 \
|
||||
Rummet1 lansenth 00010203 "" \
|
||||
Rummet2 rfmamb 11772288 "" \
|
||||
| grep Rummet > $TEST/test_output.txt
|
||||
|
@ -154,7 +154,7 @@ cat > $TEST/test_expected.txt <<EOF
|
|||
{"media":"room sensor","meter":"rfmamb","name":"Rummet2","id":"11772288","current_temperature_c":22.08,"average_temperature_1h_c":21.91,"average_temperature_24h_c":22.07,"maximum_temperature_1h_c":22.08,"minimum_temperature_1h_c":21.85,"maximum_temperature_24h_c":23.47,"minimum_temperature_24h_c":21.29,"current_relative_humidity_rh":44.2,"average_relative_humidity_1h_rh":43.2,"average_relative_humidity_24h_rh":44.5,"minimum_relative_humidity_1h_rh":42.2,"maximum_relative_humidity_1h_rh":50.1,"maximum_relative_humidity_24h_rh":0,"minimum_relative_humidity_24h_rh":0,"device_date_time":"2019-10-11 19:59","timestamp":"1111-11-11T11:11:11Z"}
|
||||
EOF
|
||||
|
||||
$PROG --format=json --listento=any simulations/serial_rtl433_ok.msg:rtl433 \
|
||||
$PROG --silent --format=json --listento=any simulations/serial_rtl433_ok.msg:rtl433 \
|
||||
Rummet1 lansenth 00010203 "" \
|
||||
Rummet2 rfmamb 11772288 "" \
|
||||
| grep Rummet > $TEST/test_output.txt
|
||||
|
|
Ładowanie…
Reference in New Issue