Fix bug where valid rtlwmbus telegrams were ignored when they came after a crc broken telegram. This bug did not tigger for the normal rtlsdr rtlwmbus usage. It triggered when piping an archive file with collected telegrams into wmbusmeters.

pull/425/head
Fredrik Öhrström 2021-12-29 18:53:54 +01:00
rodzic 6a4266ead6
commit 9d4694d687
4 zmienionych plików z 55 dodań i 10 usunięć

Wyświetl plik

@ -0,0 +1,4 @@
T1;0;0;2021-12-29 13:50:57.000;8;101;91625359;0x294468505953629176f0a0009f29982b00e0982b00802e0601316acd636bcd63008dc3009ed4000fe5ff
T1;0;0;2021-12-29 13:50:57.000;11;108;91625359;0x294468505953629176f0a0009f29982b00e0982b00802e0601316acd636bcd63008dc3009ed4000fe5ff
C1;1;1;2021-12-29 13:50:57.000;94;83;03727567;0x574468506775720394088c0048900f002c25b3290900aa7c765a7dfed6737ab300300710bcabff50afff489e689f834a0bd9578ad52fb85f17854d3d5d522cbec020526a6242e2345a48214088a6a9b8ebfd47f80f15a3b4
C1;1;1;2021-12-29 13:50:57.000;96;87;03727567;0x574468506775720394088c0048900f002c25b3290900aa7c765a7dfed6737ab300300710bcabff50afff489e689f834a0bd9578ad52fb85f17854d3d5d522cbec020526a6242e2345a48214088a6a9b8ebfd47f80f15a3b4

Wyświetl plik

@ -1,5 +1,5 @@
/*
Copyright (C) 2019-2020 Fredrik Öhrström
Copyright (C) 2019-2021 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
@ -248,19 +248,17 @@ void WMBusRTLWMBUS::processSerialData()
{
break;
}
if (status == TextAndNotFrame)
else if (status == TextAndNotFrame)
{
// The buffer has already been printed by serial cmd.
read_buffer_.clear();
break;
read_buffer_.erase(read_buffer_.begin(), read_buffer_.begin()+frame_length);
}
if (status == ErrorInFrame)
else if (status == ErrorInFrame)
{
debug("(rtlwmbus) error in received message.\n");
read_buffer_.clear();
break;
read_buffer_.erase(read_buffer_.begin(), read_buffer_.begin()+frame_length);
}
if (status == FullFrame)
else if (status == FullFrame)
{
vector<uchar> payload;
if (hex_payload_len > 0)
@ -302,6 +300,10 @@ void WMBusRTLWMBUS::processSerialData()
AboutTelegram about(id, rssi, FrameType::WMBUS);
handleTelegram(about, payload);
}
else
{
assert(0);
}
}
}
@ -333,11 +335,13 @@ FrameStatus WMBusRTLWMBUS::checkRTLWMBUSFrame(vector<uchar> &data,
return PartialFrame;
}
// Export how long the current line is, so that it can be removed from the buffer.
*hex_frame_length = eolp+1;
// We got a full line, but if it is too short, then
// there is something wrong. Discard the data.
if (data.size() < 10)
{
debug("(rtlwmbus) too short line\n");
return ErrorInFrame;
}
@ -411,7 +415,6 @@ FrameStatus WMBusRTLWMBUS::checkRTLWMBUSFrame(vector<uchar> &data,
payload_len = eolp-i;
*hex_payload_len_out = payload_len;
*hex_payload_offset = i;
*hex_frame_length = eolp+1;
debug("(rtlwmbus) received full frame\n");
return FullFrame;

Wyświetl plik

@ -120,6 +120,9 @@ if [ "$?" != "0" ]; then RC="1"; fi
./tests/test_broken.sh $PROG
if [ "$?" != "0" ]; then RC="1"; fi
./tests/test_rtlwmbus_crc_errors.sh $PROG
if [ "$?" != "0" ]; then RC="1"; fi
./tests/test_analyze.sh $PROG
if [ "$?" != "0" ]; then RC="1"; fi

Wyświetl plik

@ -0,0 +1,35 @@
#!/bin/sh
PROG="$1"
TEST=testoutput
mkdir -p $TEST
TESTNAME="Test rtlwmbus with crc errors"
TESTRESULT="ERROR"
cat > $TEST/test_expected.txt <<EOF
Started config rtlwmbus on stdin listening on any
No meters configured. Printing id:s of all telegrams heard!
Received telegram from: 03727567
manufacturer: (TCH) Techem Service (0x5068)
type: Heat Cost Allocator (0x08) encrypted
ver: 0x94
device: rtlwmbus[]
rssi: 94 dBm
driver: fhkvdataiv
EOF
cat simulations/simulation_rtlwmbus_errors.txt | $PROG stdin:rtlwmbus > $TEST/test_output.txt 2>&1
if [ "$?" = "0" ]
then
diff $TEST/test_expected.txt $TEST/test_output.txt
if [ "$?" = "0" ]
then
echo OK: $TESTNAME
TESTRESULT="OK"
fi
else
echo "wmbusmeters returned error code: $?"
cat $TEST/test_output.txt
fi