diff --git a/firmware/console/binary/serial_can.cpp b/firmware/console/binary/serial_can.cpp index c7364f5c61..3f2360d927 100644 --- a/firmware/console/binary/serial_can.cpp +++ b/firmware/console/binary/serial_can.cpp @@ -141,8 +141,8 @@ int CanStreamerState::receiveFrame(CANRxFrame *rxmsg, uint8_t *buf, int num, can memcpy(buf, srcBuf, numBytesToCopy); } srcBuf += numBytesToCopy; + waitingForNumBytes -= numBytesAvailable; numBytesAvailable -= numBytesToCopy; - waitingForNumBytes -= numBytesToCopy; // if there are some more bytes left, we save them for the next time for (int i = 0; i < numBytesAvailable; i++) { rxFifoBuf.put(srcBuf[i]); diff --git a/unit_tests/tests/test_can_serial.cpp b/unit_tests/tests/test_can_serial.cpp index 52431df204..6a591be2b7 100644 --- a/unit_tests/tests/test_can_serial.cpp +++ b/unit_tests/tests/test_can_serial.cpp @@ -110,13 +110,15 @@ public: for (size_t i = 0; i < totalSize; i++) { EXPECT_EQ(totalData[i], totalReceivedData[i]) << "Rcv. byte #" << i << " differs!"; } + // check the FIFO buf size + EXPECT_EQ(0, rxFifoBuf.getCount()); + } protected: TestCanStreamer streamer; }; - TEST(testCanSerial, test1Frame) { { @@ -146,6 +148,10 @@ TEST(testCanSerial, test2Frames) { TestCanStreamerState state; state.test({ "01234567" }, { "\x10"s "\x08"s "012345"s, "\x21"s "67\0\0\0\0\0"s }, 8, { 8 }); // 8 bytes -> 2 8-byte frames, 8 bytes in FIFO } + { + TestCanStreamerState state; + state.test({ "0123456789A" }, { "\x10"s "\x0B"s "012345"s, "\x21"s "6789A\0\0"s }, 11, { 2, 5, 4 }); // 11 bytes -> 2 8-byte frames + } /* { TestCanStreamerState state;