kopia lustrzana https://github.com/weetmuts/wmbusmeters
Improve manual
rodzic
cabcf04d20
commit
08cdf9825e
|
@ -81,6 +81,31 @@ void parseMeterConfig(Configuration *c, vector<char> &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<Configuration>(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<Configuration>(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
error("You must supply a directory to --useconfig=dir\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void handleLoglevel(Configuration *c, string loglevel)
|
||||
{
|
||||
if (loglevel == "verbose") { c->verbose = true; }
|
||||
|
|
|
@ -79,4 +79,8 @@ struct Configuration {
|
|||
|
||||
unique_ptr<Configuration> loadConfiguration(string root);
|
||||
|
||||
|
||||
bool parseUseConfig(string arg, Configuration *config);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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<uchar> *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<uchar> *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;
|
||||
|
|
|
@ -88,7 +88,7 @@ void invokeShell(string program, vector<string> args, vector<string> envs)
|
|||
delete[] p;
|
||||
}
|
||||
|
||||
bool invokeBackgroundShell(string program, vector<string> args, vector<string> envs, int *out, int *err, int *pid)
|
||||
bool invokeBackgroundShell(string program, vector<string> args, vector<string> envs, int *out, int *pid)
|
||||
{
|
||||
int link[2];
|
||||
vector<const char*> argv(args.size()+2);
|
||||
|
|
|
@ -21,5 +21,5 @@
|
|||
using namespace std;
|
||||
|
||||
void invokeShell(string program, vector<string> args, vector<string> envs);
|
||||
bool invokeBackgroundShell(string program, vector<string> args, vector<string> envs, int *out, int *err, int *pid);
|
||||
bool invokeBackgroundShell(string program, vector<string> args, vector<string> envs, int *out, int *pid);
|
||||
void stopBackgroundShell(int pid);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<time>] exit program after time, eg 20h, 10m 5s
|
||||
\fB\--exitafter=\fR<time> exit program after time, eg 20h, 10m 5s
|
||||
|
||||
[\fB\--format=\fR(hr|json|fields)] for human readable, json or semicolon separated fields
|
||||
\fB\--format=\fR(hr|json|fields) for human readable, json or semicolon separated fields
|
||||
|
||||
[\fB\--logfile=\fR<dir>] use this file instead of stdout
|
||||
\fB\--logfile=\fR<dir> use this file instead of stdout
|
||||
|
||||
[\fB\--logtelegrams\fR] log the contents of the telegrams for easy replay
|
||||
\fB\--logtelegrams\fR log the contents of the telegrams for easy replay
|
||||
|
||||
[\fB\--meterfiles=\fR<dir>] store meter readings in dir
|
||||
\fB\--meterfiles=\fR<dir> store meter readings in dir
|
||||
|
||||
[\fB\--meterfilesaction=\fR(overwrite|append)] overwrite or append to the meter readings file
|
||||
\fB\--meterfilesaction=\fR(overwrite|append) overwrite or append to the meter readings file
|
||||
|
||||
[\fB\--oneshot\fR] wait for an update from each meter, then quit
|
||||
\fB\--oneshot\fR wait for an update from each meter, then quit
|
||||
|
||||
[\fB\--separator=\fR<c>] change field separator to c
|
||||
\fB\--separator=\fR<c> change field separator to c
|
||||
|
||||
[\fB\--shell=\fR<cmdline>] invokes cmdline with env variables containing the latest reading
|
||||
\fB\--shell=\fR<cmdline> invokes cmdline with env variables containing the latest reading
|
||||
|
||||
[\fB\--shellenvs\fR] list the env variables available for the meter
|
||||
\fB\--shellenvs\fR list the env variables available for the meter
|
||||
|
||||
[\fB\--t1\fR] listen to T1 messages when no meters are supplied
|
||||
\fB\--t1\fR listen to T1 messages when no meters are supplied
|
||||
|
||||
[\fB\--useconfig=\fR<dir>] load config files from dir/etc
|
||||
\fB\--useconfig=\fR<dir> load config files from dir/etc
|
||||
|
||||
[\fB\--verbose\fR] for more information
|
||||
\fB\--verbose\fR for more information
|
||||
|
||||
.SH DEVICES
|
||||
.TP
|
||||
[\fB/dev/ttyUSB0\fR] to which an im871a or amb8456 dongle is attached
|
||||
\fB/dev/ttyUSB0\fR to which an im871a or amb8456 dongle is attached
|
||||
|
||||
.TP
|
||||
[\fBauto\fR] look for /dev/im871a or /dev/amb8465
|
||||
\fBauto\fR look for /dev/im871a or /dev/amb8465
|
||||
|
||||
.TP
|
||||
[\fBrtlwmbus:<freq>\fR] use software defined radio rtl_sdr|rtl_wmbus to received wmbus telegrams
|
||||
\fBrtlwmbus:<freq>\fR use software defined radio rtl_sdr|rtl_wmbus to receive wmbus telegrams
|
||||
|
||||
.TP
|
||||
[\fBsimulation.txt\fR] read telegrams from file to replay telegram feed (use --logtelegrams to acquire feed for replay)
|
||||
\fBsimulation_xxx.txt\fR read telegrams from file to replay telegram feed (use --logtelegrams to acquire feed for replay)
|
||||
|
||||
.SH METER QUADRUPLES
|
||||
.TP
|
||||
[\fBmeter_name\fR] a mnemonic for your utility meter
|
||||
\fBmeter_name\fR a mnemonic for your utility meter
|
||||
.TP
|
||||
[\fBmeter_type\fR] multical21/flowiq3100/supercom587/iperl/multical302/omnipower/qcaloric
|
||||
\fBmeter_type\fR multical21/flowiq3100/supercom587/iperl/multical302/omnipower/qcaloric
|
||||
.TP
|
||||
[\fBmeter_id\fR] an 8 digit number, usually printed on the meter
|
||||
\fBmeter_id\fR an 8 digit number, usually printed on the meter
|
||||
.TP
|
||||
[\fBmeter_key\fR] a unique key for the meter, if meter telegrams are not encrypted, you must supply an empty key: ""
|
||||
\fBmeter_key\fR a unique key for the meter, if meter telegrams are not encrypted, you must supply an empty key: ""
|
||||
|
||||
.SH EXAMPLES
|
||||
.TP
|
||||
|
@ -97,7 +97,7 @@ Execute using config file /home/me/etc/wmbusmeters.conf and meter config files i
|
|||
.TP
|
||||
Start a daemon using config file /etc/wmbusmeters.conf and meter config files in /etc/wmbusmeters.d
|
||||
|
||||
% wmbusmetersd --useconfig=/
|
||||
% wmbusmetersd --useconfig=/ /var/run/wmbusmeters/wmbusmeters.pid
|
||||
|
||||
.TP
|
||||
An example wmbusmeters.conf:
|
||||
|
|
Ładowanie…
Reference in New Issue