kopia lustrzana https://github.com/weetmuts/wmbusmeters
Source cleanup.
rodzic
748f03ecfc
commit
69cf31ace0
|
@ -3,4 +3,5 @@ build_debug
|
|||
build_arm/
|
||||
build_arm_debug/
|
||||
archive/
|
||||
testoutput/
|
||||
*~
|
24
Makefile
24
Makefile
|
@ -20,6 +20,8 @@
|
|||
# make DEBUG=true
|
||||
# make DEBUG=true HOST=arm
|
||||
|
||||
VERSION=0.8.4
|
||||
|
||||
ifeq "$(HOST)" "arm"
|
||||
CXX=arm-linux-gnueabihf-g++
|
||||
STRIP=arm-linux-gnueabihf-strip
|
||||
|
@ -44,7 +46,7 @@ endif
|
|||
|
||||
$(shell mkdir -p $(BUILD))
|
||||
|
||||
CXXFLAGS := $(DEBUG_FLAGS) -fPIC -fmessage-length=0 -std=c++11 -Wall -Wno-maybe-uninitialized -Wno-unused-function "-DWMBUSMETERS_VERSION=\"0.8.4\""
|
||||
CXXFLAGS := $(DEBUG_FLAGS) -fPIC -fmessage-length=0 -std=c++11 -Wall -Wno-maybe-uninitialized -Wno-unused-function "-DWMBUSMETERS_VERSION=\"$(VERSION)\""
|
||||
|
||||
$(BUILD)/%.o: src/%.cc $(wildcard src/%.h)
|
||||
$(CXX) $(CXXFLAGS) $< -c -o $@
|
||||
|
@ -73,23 +75,27 @@ METERS_OBJS:=\
|
|||
|
||||
all: $(BUILD)/wmbusmeters $(BUILD)/testinternals
|
||||
@$(STRIP_BINARY)
|
||||
@rm -f $(BUILD)/wmbusmetersd
|
||||
@cp $(BUILD)/wmbusmeters $(BUILD)/wmbusmetersd
|
||||
|
||||
dist: wmbusmeters_0.8.1_$(DEBARCH).deb
|
||||
dist: wmbusmeters_$(VERSION)_$(DEBARCH).deb
|
||||
|
||||
wmbusmeters_0.8.1_$(DEBARCH).deb:
|
||||
install: $(BUILD)/wmbusmeters
|
||||
@./install.sh $(BUILD)/wmbusmeters
|
||||
|
||||
wmbusmeters_$(VERSION)_$(DEBARCH).deb:
|
||||
@rm -rf $(BUILD)/debian/wmbusmeters
|
||||
@mkdir -p $(BUILD)/debian/wmbusmeters/DEBIAN
|
||||
@mkdir -p $(BUILD)/debian/wmbusmeters/usr/local/bin
|
||||
@cp $(BUILD)/wmbusmeters $(BUILD)/debian/wmbusmeters/usr/local/bin
|
||||
@mkdir -p $(BUILD)/debian/wmbusmeters/usr/bin
|
||||
@mkdir -p $(BUILD)/debian/wmbusmeters/usr/sbin
|
||||
@cp $(BUILD)/wmbusmeters $(BUILD)/debian/wmbusmeters/usr/bin/wmbusmeters
|
||||
@ln $(BUILD)/debian/wmbusmeters/usr/bin/wmbusmeters $(BUILD)/debian/wmbusmeters/usr/sbin/wmbusmetersd
|
||||
@rm -f $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
||||
@echo "Package: wmbusmeters" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
||||
@echo "Version: 0.8.1" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
||||
@echo "Version: $(VERSION)" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
||||
@echo "Maintainer: Fredrik Öhrström" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
||||
@echo "Architecture: $(DEBARCH)" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
||||
@echo "Description: A tool to read wireless mbus telegrams from utility meters." >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
||||
@(cd $(BUILD)/debian; dpkg-deb --build wmbusmeters .)
|
||||
@mv $(BUILD)/debian/wmbusmeters_0.8.1_$(DEBARCH).deb .
|
||||
@mv $(BUILD)/debian/wmbusmeters_$(VERSION)_$(DEBARCH).deb .
|
||||
@echo Built package $@
|
||||
|
||||
$(BUILD)/wmbusmeters: $(METERS_OBJS) $(BUILD)/main.o
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ "$1" = "" ]
|
||||
then
|
||||
echo Usage: install.sh build/wmbusmeters
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ ! $(basename "$1") = "wmbusmeters" ]
|
||||
then
|
||||
echo Oups, please only try to install wmbusmeters using this script.
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -x "$1" ]
|
||||
then
|
||||
echo This is not an executable.
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$EUID" -ne 0 ]
|
||||
then echo "Please run as root."
|
||||
exit
|
||||
fi
|
||||
|
||||
rm -f /usr/bin/wmbusmeters /usr/sbin/wmbusmetersd
|
||||
cp "$1" /usr/bin/wmbusmeters
|
||||
ln -s /usr/bin/wmbusmeters /usr/sbin/wmbusmetersd
|
||||
|
||||
echo binaries: installed /usr/bin/wmbusmeters and /usr/sbin/wmbusmetersd
|
||||
|
||||
ID=$(id -u wmbusmeters 2>/dev/null)
|
||||
|
||||
if [ "$ID" == "" ]
|
||||
then
|
||||
# Create the wmbusmeters user
|
||||
adduser --no-create-home --shell /usr/sbin/nologin --disabled-login --gecos "" wmbusmeters
|
||||
echo user: added wmbusmeters
|
||||
else
|
||||
echo user: wmbusmeters unmodified
|
||||
fi
|
||||
|
||||
if [ ! -f /etc/wmbusmeters.conf ]
|
||||
then
|
||||
# Create default configuration
|
||||
cat <<EOF > /etc/wmbusmeters.conf
|
||||
loglevel=normal
|
||||
device=auto
|
||||
logtelegrams=false
|
||||
meterfiles=/tmp/wmbusmeters
|
||||
EOF
|
||||
chown root:root /etc/wmbusmeters.conf
|
||||
chmod 644 /etc/wmbusmeters.d
|
||||
echo conf file: created /etc/wmbusmeters.conf
|
||||
else
|
||||
echo conf file: /etc/wmbusmeters.conf unchanged
|
||||
fi
|
||||
|
||||
if [ ! -d /etc/wmbusmeters.d ]
|
||||
then
|
||||
# Create the configuration directory
|
||||
mkdir -p /etc/wmbusmeters.d
|
||||
chown -R root:root /etc/wmbusmeters.d
|
||||
chmod -R 644 /etc/wmbusmeters.d
|
||||
echo conf dir: created /etc/wmbusmeters.d
|
||||
else
|
||||
echo conf dir: /etc/wmbusmeters.d unchanged
|
||||
fi
|
||||
|
||||
if [ -d /etc/systemd/system ]
|
||||
then
|
||||
if [ ! -f /etc/systemd/system/wmbusmeters.service ]
|
||||
then
|
||||
# Create service file
|
||||
cat <<EOF > /etc/systemd/system/wmbusmeters.service
|
||||
[Unit]
|
||||
Description=wmbusmeters service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
#Restart=always
|
||||
RestartSec=1
|
||||
User=wmbusmeters
|
||||
ExecStart=/usr/sbin/wmbusmetersd
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
echo systemd: installed /etc/systemd/system/wmbusmeters.service
|
||||
else
|
||||
echo systemd: /etc/systemd/system/wmbusmeters.service unchanged
|
||||
fi
|
||||
fi
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 2017-2018 Fredrik Öhrström
|
||||
Copyright (C) 2017-2019 Fredrik Öhrström
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -90,6 +90,13 @@ unique_ptr<CommandLine> parseCommandLine(int argc, char **argv) {
|
|||
}
|
||||
return unique_ptr<CommandLine>(c);
|
||||
}
|
||||
if (!strcmp(argv[i], "--reload")) {
|
||||
c->reload = true;
|
||||
if (i > 1 || argc > 2) {
|
||||
error("Usage error: --reload implies no other arguments on the command line.\n");
|
||||
}
|
||||
return unique_ptr<CommandLine>(c);
|
||||
}
|
||||
if (!strncmp(argv[i], "--robot", 7)) {
|
||||
if (strlen(argv[i]) == 7 ||
|
||||
(strlen(argv[i]) == 12 &&
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 2017-2018 Fredrik Öhrström
|
||||
Copyright (C) 2017-2019 Fredrik Öhrström
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
|
@ -79,6 +79,7 @@ unique_ptr<CommandLine> loadConfiguration()
|
|||
auto i = global_conf.begin();
|
||||
string loglevel;
|
||||
string device;
|
||||
string meterfiles_dir;
|
||||
|
||||
for (;;) {
|
||||
auto p = getNextKeyValue(global_conf, i);
|
||||
|
@ -87,6 +88,7 @@ unique_ptr<CommandLine> loadConfiguration()
|
|||
|
||||
if (p.first == "loglevel") loglevel = p.second;
|
||||
if (p.first == "device") device = p.second;
|
||||
if (p.first == "meterfilesdir") meterfiles_dir = p.second;
|
||||
}
|
||||
|
||||
if (loglevel == "verbose") {
|
||||
|
@ -105,6 +107,11 @@ unique_ptr<CommandLine> loadConfiguration()
|
|||
}
|
||||
// cmdline->logtelegrams
|
||||
|
||||
c->meterfiles_dir = meterfiles_dir;
|
||||
if (!checkIfDirExists(c->meterfiles_dir.c_str())) {
|
||||
warning("Cannot write meter files into dir \"%s\"\n", c->meterfiles_dir.c_str());
|
||||
}
|
||||
|
||||
c->usb_device = device;
|
||||
|
||||
vector<string> meter_files;
|
||||
|
|
|
@ -41,6 +41,7 @@ struct MeterInfo {
|
|||
struct CommandLine {
|
||||
bool daemon {};
|
||||
bool useconfig {};
|
||||
bool reload {};
|
||||
bool need_help {};
|
||||
bool silence {};
|
||||
bool verbose {};
|
||||
|
|
22
src/main.cc
22
src/main.cc
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 2017-2018 Fredrik Öhrström
|
||||
Copyright (C) 2017-2019 Fredrik Öhrström
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -63,30 +63,32 @@ int main(int argc, char **argv)
|
|||
printf(" --exitafter=20h program exits after running for twenty hoursh\n"
|
||||
" or 10m for ten minutes or 5s for five seconds.\n");
|
||||
printf(" --useconfig read from /etc/wmbusmeters.conf and /etc/wmbusmeters.d\n");
|
||||
printf(" check the man page for how to write the config files.\n\n");
|
||||
printf(" check the man page for how to write the config files.\n");
|
||||
printf(" --reload signals a running wmbusmeters daemon to reload the configuration,\n");
|
||||
printf(" when you have modified config files and/or usb dongles.\n\n");
|
||||
|
||||
printf("Specifying auto as the device will automatically look for usb\n");
|
||||
printf("wmbus dongles on /dev/im871a and /dev/amb8465\n\n");
|
||||
printf("The meter types: multical21,flowiq3100,supercom587,iperl (water meters) are supported.\n"
|
||||
"The meter types: multical302 (heat) and omnipower (electricity) qcaloric (heat cost)\n"
|
||||
"are work in progress.\n\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
else
|
||||
if (cmdline->daemon) {
|
||||
startDaemon();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
else
|
||||
if (cmdline->useconfig) {
|
||||
startUsingConfigFiles();
|
||||
exit(0);
|
||||
}
|
||||
else {
|
||||
// We want the data visible in the log file asap!
|
||||
setbuf(stdout, NULL);
|
||||
|
||||
// We want the data visible in the log file asap!
|
||||
setbuf(stdout, NULL);
|
||||
|
||||
startUsingCommandline(cmdline.get());
|
||||
exit(0);
|
||||
startUsingCommandline(cmdline.get());
|
||||
}
|
||||
}
|
||||
|
||||
void startUsingCommandline(CommandLine *cmdline)
|
||||
|
|
77
test.sh
77
test.sh
|
@ -8,76 +8,7 @@ if [ "$?" = "0" ]; then
|
|||
echo Internal test OK
|
||||
fi
|
||||
|
||||
cat simulations/simulation_c1.txt | grep '^{' > test_expected.txt
|
||||
$PROG --robot=json simulations/simulation_c1.txt \
|
||||
MyHeater multical302 12345678 "" \
|
||||
MyTapWater multical21 76348799 "" \
|
||||
Vadden multical21 44556677 "" \
|
||||
MyElectricity omnipower 15947107 "" \
|
||||
> test_output.txt
|
||||
if [ "$?" == "0" ]
|
||||
then
|
||||
cat test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > test_responses.txt
|
||||
diff test_expected.txt test_responses.txt
|
||||
if [ "$?" == "0" ]
|
||||
then
|
||||
echo C1 OK
|
||||
fi
|
||||
else
|
||||
Failure.
|
||||
fi
|
||||
|
||||
cat simulations/simulation_t1.txt | grep '^{' > test_expected.txt
|
||||
$PROG --robot=json simulations/simulation_t1.txt \
|
||||
MyWarmWater supercom587 12345678 "" \
|
||||
MyColdWater supercom587 11111111 "" \
|
||||
MoreWater iperl 12345699 "" \
|
||||
> test_output.txt
|
||||
if [ "$?" == "0" ]
|
||||
then
|
||||
cat test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > test_responses.txt
|
||||
diff test_expected.txt test_responses.txt
|
||||
if [ "$?" == "0" ]
|
||||
then
|
||||
echo T1 OK
|
||||
fi
|
||||
else
|
||||
Failure.
|
||||
fi
|
||||
|
||||
$PROG --shell='echo "$METER_JSON"' simulations/simulation_shell.txt MWW supercom587 12345678 "" > test_output.txt
|
||||
if [ "$?" == "0" ]
|
||||
then
|
||||
cat test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > test_responses.txt
|
||||
echo '{"media":"warm water","meter":"supercom587","name":"MWW","id":"12345678","total_m3":5.548000,"timestamp":"1111-11-11T11:11:11Z"}' > test_expected.txt
|
||||
diff test_expected.txt test_responses.txt
|
||||
if [ "$?" == "0" ]
|
||||
then
|
||||
echo SHELL OK
|
||||
fi
|
||||
else
|
||||
Failure.
|
||||
fi
|
||||
|
||||
rm -f /tmp/MyTapWater
|
||||
cat simulations/simulation_c1.txt | grep '^{' | grep 76348799 | tail -n 1 > test_expected.txt
|
||||
$PROG --meterfiles --robot=json simulations/simulation_c1.txt MyTapWater multical21 76348799 ""
|
||||
cat /tmp/MyTapWater | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > test_response.txt
|
||||
diff test_expected.txt test_response.txt
|
||||
if [ "$?" == "0" ]
|
||||
then
|
||||
echo Meterfiles OK
|
||||
rm /tmp/MyTapWater
|
||||
fi
|
||||
|
||||
rm -rf /tmp/testmeters
|
||||
mkdir /tmp/testmeters
|
||||
cat simulations/simulation_c1.txt | grep '^{' | grep 76348799 | tail -n 1 > test_expected.txt
|
||||
$PROG --meterfiles=/tmp/testmeters --robot=json simulations/simulation_c1.txt MyTapWater multical21 76348799 ""
|
||||
cat /tmp/testmeters/MyTapWater | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > test_response.txt
|
||||
diff test_expected.txt test_response.txt
|
||||
if [ "$?" == "0" ]
|
||||
then
|
||||
echo Meterfiles dir OK
|
||||
rm -rf /tmp/testmeters
|
||||
fi
|
||||
tests/test_c1_meters.sh $PROG
|
||||
tests/test_t1_meters.sh $PROG
|
||||
tests/test_shell.sh $PROG
|
||||
tests/test_meterfiles.sh $PROG
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
#!/bin/bash
|
||||
|
||||
PROG="$1"
|
||||
|
||||
mkdir -p testoutput
|
||||
|
||||
TEST=testoutput
|
||||
|
||||
cat simulations/simulation_c1.txt | grep '^{' > $TEST/test_expected.txt
|
||||
$PROG --robot=json simulations/simulation_c1.txt \
|
||||
MyHeater multical302 12345678 "" \
|
||||
MyTapWater multical21 76348799 "" \
|
||||
Vadden multical21 44556677 "" \
|
||||
MyElectricity omnipower 15947107 "" \
|
||||
> $TEST/test_output.txt
|
||||
if [ "$?" == "0" ]
|
||||
then
|
||||
cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt
|
||||
diff $TEST/test_expected.txt $TEST/test_responses.txt
|
||||
if [ "$?" == "0" ]
|
||||
then
|
||||
echo C1 OK
|
||||
fi
|
||||
else
|
||||
Failure.
|
||||
fi
|
|
@ -0,0 +1,30 @@
|
|||
#!/bin/bash
|
||||
|
||||
PROG="$1"
|
||||
|
||||
mkdir -p testoutput
|
||||
|
||||
TEST=testoutput
|
||||
|
||||
rm -f /tmp/MyTapWater
|
||||
cat simulations/simulation_c1.txt | grep '^{' | grep 76348799 | tail -n 1 > $TEST/test_expected.txt
|
||||
$PROG --meterfiles --robot=json simulations/simulation_c1.txt MyTapWater multical21 76348799 ""
|
||||
cat /tmp/MyTapWater | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_response.txt
|
||||
diff $TEST/test_expected.txt $TEST/test_response.txt
|
||||
if [ "$?" == "0" ]
|
||||
then
|
||||
echo Meterfiles OK
|
||||
rm /tmp/MyTapWater
|
||||
fi
|
||||
|
||||
rm -rf /tmp/testmeters
|
||||
mkdir /tmp/testmeters
|
||||
cat simulations/simulation_c1.txt | grep '^{' | grep 76348799 | tail -n 1 > $TEST/test_expected.txt
|
||||
$PROG --meterfiles=/tmp/testmeters --robot=json simulations/simulation_c1.txt MyTapWater multical21 76348799 ""
|
||||
cat /tmp/testmeters/MyTapWater | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_response.txt
|
||||
diff $TEST/test_expected.txt $TEST/test_response.txt
|
||||
if [ "$?" == "0" ]
|
||||
then
|
||||
echo Meterfiles dir OK
|
||||
rm -rf /tmp/testmeters
|
||||
fi
|
|
@ -0,0 +1,21 @@
|
|||
#!/bin/bash
|
||||
|
||||
PROG="$1"
|
||||
|
||||
mkdir -p testoutput
|
||||
|
||||
TEST=testoutput
|
||||
|
||||
$PROG --shell='echo "$METER_JSON"' simulations/simulation_shell.txt MWW supercom587 12345678 "" > $TEST/test_output.txt
|
||||
if [ "$?" == "0" ]
|
||||
then
|
||||
cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt
|
||||
echo '{"media":"warm water","meter":"supercom587","name":"MWW","id":"12345678","total_m3":5.548000,"timestamp":"1111-11-11T11:11:11Z"}' > $TEST/test_expected.txt
|
||||
diff $TEST/test_expected.txt $TEST/test_responses.txt
|
||||
if [ "$?" == "0" ]
|
||||
then
|
||||
echo SHELL OK
|
||||
fi
|
||||
else
|
||||
Failure.
|
||||
fi
|
|
@ -0,0 +1,25 @@
|
|||
#!/bin/bash
|
||||
|
||||
PROG="$1"
|
||||
|
||||
mkdir -p testoutput
|
||||
|
||||
TEST=testoutput
|
||||
|
||||
cat simulations/simulation_t1.txt | grep '^{' > $TEST/test_expected.txt
|
||||
$PROG --robot=json simulations/simulation_t1.txt \
|
||||
MyWarmWater supercom587 12345678 "" \
|
||||
MyColdWater supercom587 11111111 "" \
|
||||
MoreWater iperl 12345699 "" \
|
||||
> $TEST/test_output.txt
|
||||
if [ "$?" == "0" ]
|
||||
then
|
||||
cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt
|
||||
diff $TEST/test_expected.txt $TEST/test_responses.txt
|
||||
if [ "$?" == "0" ]
|
||||
then
|
||||
echo T1 OK
|
||||
fi
|
||||
else
|
||||
Failure.
|
||||
fi
|
Ładowanie…
Reference in New Issue