kopia lustrzana https://github.com/weetmuts/wmbusmeters
Add field timestamp_ut for printing unix timestamp millis.
rodzic
209ce83c36
commit
2c83c51db1
27
Makefile
27
Makefile
|
@ -330,18 +330,29 @@ update_manufacturers:
|
|||
mv m.h src/manufacturers.h
|
||||
rm *.flags manufacturers.txt
|
||||
|
||||
build_fuzz:
|
||||
@if [ "${AFLHOME}" = "" ]; then echo 'You must supply aflhome "make build_fuzz AFLHOME=/home/afl"'; exit 1; fi
|
||||
$(MAKE) AFL_HARDEN=1 CXX=$(AFLHOME)/afl-g++ $(BUILD)/fuzz
|
||||
$(MAKE) AFL_HARDEN=1 CXX=$(AFLHOME)/afl-g++ $(BUILD)/wmbusmeters
|
||||
|
||||
GCC_MAJOR_VERSION:=$(shell gcc --version | head --lines=1 | sed 's/.* \([0-9]\)\.[0-9]\.[0-9]$$/\1/')
|
||||
AFL_HOME:=AFLplusplus
|
||||
|
||||
$(AFL_HOME)/src/afl-cc.c:
|
||||
mkdir -p AFLplusplus
|
||||
if ! dpkg -s gcc-$(GCC_MAJOR_VERSION)-plugin-dev 2>/dev/null >/dev/null ; then echo "Please run: sudo apt install gcc-$(GCC_MAJOR_VERSION)-plugin-dev"; exit 1; fi
|
||||
git clone https://github.com/AFLplusplus/AFLplusplus.git
|
||||
|
||||
afl_prepared: AFLplusplus/src/afl-cc.c
|
||||
(cd AFLplusplus; make)
|
||||
touch afl_prepared
|
||||
|
||||
build_fuzz: afl_prepared
|
||||
echo GURKA
|
||||
$(MAKE) AFL_HARDEN=1 CXX=$(AFL_HOME)/afl-g++-fast $(BUILD)/fuzz
|
||||
$(MAKE) AFL_HARDEN=1 CXX=$(AFL_HOME)/afl-g++-fast $(BUILD)/wmbusmeters
|
||||
|
||||
run_fuzz_difvifparser:
|
||||
@if [ "${AFLHOME}" = "" ]; then echo 'You must supply aflhome "make run_fuzz AFLHOME=/home/afl"'; exit 1; fi
|
||||
${AFLHOME}/afl-fuzz -i fuzz_testcases/difvifparser -o fuzz_findings/ build/fuzz
|
||||
${AFL_HOME}/afl-fuzz -i fuzz_testcases/difvifparser -o fuzz_findings/ build/fuzz
|
||||
|
||||
run_fuzz_telegrams:
|
||||
@if [ "${AFLHOME}" = "" ]; then echo 'You must supply aflhome "make run_fuzz AFLHOME=/home/afl"'; exit 1; fi
|
||||
${AFLHOME}/afl-fuzz -i fuzz_testcases/telegrams -o fuzz_findings/ build/wmbusmeters --listento=any stdin
|
||||
${AFL_HOME}/afl-fuzz -i fuzz_testcases/telegrams -o fuzz_findings/ build/wmbusmeters --listento=any stdin
|
||||
|
||||
# Include dependency information generated by gcc in a previous compile.
|
||||
include $(wildcard $(patsubst %.o,%.d,$(METER_OBJS)))
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
# Test Aventies Water Meter
|
||||
telegram=76442104710007612507727100076121042507B5006005E2E95A3C2A1279A5415E6732679B43369FD5FDDDD783EEEBB48236D34E7C94AF0A18A5FDA5F7D64111EB42D4D891622139F2952F9D12A20088DFA4CF8123871123EE1F6C1DCEA414879DDB4E05E508F1826D7EFBA6964DF804C9261EA23BBF03
|
||||
|466.472;UT;Votten;61070071
|
|
@ -400,6 +400,14 @@ string MeterCommonImplementation::datetimeOfUpdateRobot()
|
|||
return string(datetime);
|
||||
}
|
||||
|
||||
string MeterCommonImplementation::unixTimestampOfUpdate()
|
||||
{
|
||||
char ut[40];
|
||||
memset(ut, 0, sizeof(ut));
|
||||
sprintf(ut, "%zu", datetime_of_update_);
|
||||
return string(ut);
|
||||
}
|
||||
|
||||
bool needsPolling(MeterDriver d)
|
||||
{
|
||||
#define X(mname,linkmodes,info,driver,cname) if (d == MeterDriver::driver && 0 != ((linkmodes) & MBUS_bit)) return true;
|
||||
|
@ -642,6 +650,11 @@ string concatFields(Meter *m, Telegram *t, char c, vector<Print> &prints, vector
|
|||
s += m->datetimeOfUpdateHumanReadable() + c;
|
||||
continue;
|
||||
}
|
||||
if (field == "timestamp_ut")
|
||||
{
|
||||
s += m->unixTimestampOfUpdate() + c;
|
||||
continue;
|
||||
}
|
||||
if (field == "device")
|
||||
{
|
||||
s += t->about.device + c;
|
||||
|
|
|
@ -219,6 +219,7 @@ struct Meter
|
|||
|
||||
virtual string datetimeOfUpdateHumanReadable() = 0;
|
||||
virtual string datetimeOfUpdateRobot() = 0;
|
||||
virtual string unixTimestampOfUpdate() = 0;
|
||||
|
||||
virtual void onUpdate(std::function<void(Telegram*t,Meter*)> cb) = 0;
|
||||
virtual int numUpdates() = 0;
|
||||
|
|
|
@ -41,6 +41,7 @@ struct MeterCommonImplementation : public virtual Meter
|
|||
|
||||
string datetimeOfUpdateHumanReadable();
|
||||
string datetimeOfUpdateRobot();
|
||||
string unixTimestampOfUpdate();
|
||||
|
||||
void onUpdate(function<void(Telegram*,Meter*)> cb);
|
||||
int numUpdates();
|
||||
|
|
3
test.sh
3
test.sh
|
@ -102,6 +102,9 @@ if [ "$?" != "0" ]; then RC="1"; fi
|
|||
./tests/test_match_dll_and_tpl_id.sh $PROG
|
||||
if [ "$?" != "0" ]; then RC="1"; fi
|
||||
|
||||
./tests/test_unix_timestamp.sh $PROG
|
||||
if [ "$?" != "0" ]; then RC="1"; fi
|
||||
|
||||
./tests/test_log_timestamps.sh $PROG
|
||||
if [ "$?" != "0" ]; then RC="1"; fi
|
||||
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
#!/bin/sh
|
||||
|
||||
PROG="$1"
|
||||
|
||||
mkdir -p testoutput
|
||||
TEST=testoutput
|
||||
|
||||
TESTNAME="Test unix timestamp in fields"
|
||||
TESTRESULT="ERROR"
|
||||
|
||||
METERS="Votten aventieswm 61070071 A004EB23329A477F1DD2D7820B56EB3D"
|
||||
|
||||
cat simulations/simulation_unix_timestamp.txt | grep '^{' > $TEST/test_expected.txt
|
||||
|
||||
NOW=$(date +%s)
|
||||
cat simulations/simulation_unix_timestamp.txt | grep '^|' | sed 's/^|//' | sed "s/UT/${NOW}/" > $TEST/test_expected.txt
|
||||
$PROG --format=fields --selectfields=total_m3,timestamp_ut,name,id simulations/simulation_t1.txt $METERS > $TEST/test_output.txt 2> $TEST/test_stderr.txt
|
||||
if [ "$?" = "0" ]
|
||||
then
|
||||
cat $TEST/test_output.txt | sed 's/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9].[0-9][0-9]$/1111-11-11 11:11.11/' > $TEST/test_responses.txt
|
||||
diff $TEST/test_expected.txt $TEST/test_responses.txt
|
||||
if [ "$?" = "0" ]
|
||||
then
|
||||
echo OK fields: $TESTNAME
|
||||
TESTRESULT="OK"
|
||||
else
|
||||
TESTRESULT="ERROR"
|
||||
fi
|
||||
else
|
||||
echo "wmbusmeters returned error code: $?"
|
||||
cat $TEST/test_output.txt
|
||||
cat $TEST/test_stderr.txt
|
||||
fi
|
||||
|
||||
|
||||
if [ "$TESTRESULT" = "ERROR" ]
|
||||
then
|
||||
echo ERROR: $TESTNAME
|
||||
exit 1
|
||||
fi
|
Ładowanie…
Reference in New Issue