diff --git a/src/config.cc b/src/config.cc index 49bc868..bf493d8 100644 --- a/src/config.cc +++ b/src/config.cc @@ -81,6 +81,31 @@ void parseMeterConfig(Configuration *c, vector &buf, string file) } +bool parseUseConfig(string arg, Configuration *config) +{ + if (arg.substr(0, 2) == "--") { + } + if (arg.substr(0,11) == "--useconfig") { + if (strlen(argv[i]) == 11) + { + c->useconfig = true; + c->config_root = ""; + return unique_ptr(c); + } + else if (strlen(argv[i]) > 12 && argv[i][11] == '=') + { + size_t len = strlen(argv[i]) - 12; + c->useconfig = true; + c->config_root = string(argv[i]+12, len); + return unique_ptr(c); + } + else + { + error("You must supply a directory to --useconfig=dir\n"); + } + +} + void handleLoglevel(Configuration *c, string loglevel) { if (loglevel == "verbose") { c->verbose = true; } diff --git a/src/config.h b/src/config.h index 22ccd67..fccd845 100644 --- a/src/config.h +++ b/src/config.h @@ -79,4 +79,8 @@ struct Configuration { unique_ptr loadConfiguration(string root); + +bool parseUseConfig(string arg, Configuration *config); + + #endif diff --git a/src/serial.cc b/src/serial.cc index 9c53f80..31154b8 100644 --- a/src/serial.cc +++ b/src/serial.cc @@ -238,7 +238,7 @@ SerialDeviceCommand::~SerialDeviceCommand() bool SerialDeviceCommand::open(bool fail_if_not_ok) { - bool ok = invokeBackgroundShell("/bin/sh", args_, envs_, &fd_, 0, &pid_); + bool ok = invokeBackgroundShell("/bin/sh", args_, envs_, &fd_, &pid_); if (!ok) return false; manager_->opened(this); verbose("(serialcmd) opened %s\n", command_.c_str()); @@ -289,13 +289,16 @@ int SerialDeviceCommand::receive(vector *data) pthread_mutex_lock(&read_lock_); data->clear(); + int total = 0; int available = 0; int num_read = 0; ioctl(fd_, FIONREAD, &available); if (!available) goto end; - data->resize(available); + again: + total += available; + data->resize(total); while (true) { int nr = read(fd_, &((*data)[num_read]), available-num_read); @@ -311,6 +314,10 @@ int SerialDeviceCommand::receive(vector *data) string msg = bin2hex(*data); debug("(serialcmd) received \"%s\"\n", msg.c_str()); } + + ioctl(fd_, FIONREAD, &available); + if (available) goto again; + end: pthread_mutex_unlock(&read_lock_); return num_read; diff --git a/src/shell.cc b/src/shell.cc index c9d5bae..00e31d1 100644 --- a/src/shell.cc +++ b/src/shell.cc @@ -88,7 +88,7 @@ void invokeShell(string program, vector args, vector envs) delete[] p; } -bool invokeBackgroundShell(string program, vector args, vector envs, int *out, int *err, int *pid) +bool invokeBackgroundShell(string program, vector args, vector envs, int *out, int *pid) { int link[2]; vector argv(args.size()+2); diff --git a/src/shell.h b/src/shell.h index 427d268..4dcf9a4 100644 --- a/src/shell.h +++ b/src/shell.h @@ -21,5 +21,5 @@ using namespace std; void invokeShell(string program, vector args, vector envs); -bool invokeBackgroundShell(string program, vector args, vector envs, int *out, int *err, int *pid); +bool invokeBackgroundShell(string program, vector args, vector envs, int *out, int *pid); void stopBackgroundShell(int pid); diff --git a/tests/test_logfile.sh b/tests/test_logfile.sh index fd82af0..134db21 100755 --- a/tests/test_logfile.sh +++ b/tests/test_logfile.sh @@ -6,10 +6,19 @@ rm -f $TEST/thelog2.txt rm -rf $TEST/meter_readings2 mkdir -p $TEST/meter_readings2 -$PROG --useconfig=tests/config2 - ERRORS=false +RES=$($PROG --useconfig=tests/config2 2>&1) + +if [ ! "$RES" = "" ] +then + ERRORS=true + echo Expected no output on stdout and stderr + echo but got------------------ + echo $RES + echo --------------------- +fi + cat simulations/simulation_t1.txt | grep '^{' | grep 12345699 | tail -n 1 > $TEST/test_expected.txt cat $TEST/meter_readings2/MoreWater | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_response.txt diff $TEST/test_expected.txt $TEST/test_response.txt @@ -34,7 +43,7 @@ then ERRORS=true fi -RES=$(cat $TEST/thelog2.txt | grep -v "logging started" | grep -v "waiting for telegrams" | grep -v "shutting down") +RES=$(cat $TEST/thelog2.txt) if [ ! "$RES" = "" ] then diff --git a/wmbusmeters.1 b/wmbusmeters.1 index f44f854..93ec969 100644 --- a/wmbusmeters.1 +++ b/wmbusmeters.1 @@ -18,58 +18,58 @@ The shell commands can for example relay the telegram using MQTT (eg mqtt_publis or store it in a database (eg psql). .SH OPTIONS -[\fB\--c1\fR] listen to C1 messages when no meters are supplied +\fB\--c1\fR listen to C1 messages when no meters are supplied -[\fB\--debug\fR] for a lot of information +\fB\--debug\fR for a lot of information -[\fB\--exitafter=\fR