diff --git a/simulations/simulation_rtlwmbus_errors.txt b/simulations/simulation_rtlwmbus_errors.txt new file mode 100644 index 0000000..9830af5 --- /dev/null +++ b/simulations/simulation_rtlwmbus_errors.txt @@ -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 diff --git a/src/wmbus_rtlwmbus.cc b/src/wmbus_rtlwmbus.cc index 171b61f..86d6cf6 100644 --- a/src/wmbus_rtlwmbus.cc +++ b/src/wmbus_rtlwmbus.cc @@ -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 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 &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 &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; diff --git a/test.sh b/test.sh index f2c5993..e789a8a 100755 --- a/test.sh +++ b/test.sh @@ -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 diff --git a/tests/test_rtlwmbus_crc_errors.sh b/tests/test_rtlwmbus_crc_errors.sh new file mode 100755 index 0000000..5ddac88 --- /dev/null +++ b/tests/test_rtlwmbus_crc_errors.sh @@ -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 < $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