diff --git a/canard.c b/canard.c index a475c199..3e30aad4 100644 --- a/canard.c +++ b/canard.c @@ -319,11 +319,12 @@ int16_t canardHandleRxFrame(CanardInstance* ins, const CanardCANFrame* frame, ui const bool first_frame = IS_START_OF_TRANSFER(tail_byte); const bool not_previous_tid = computeTransferIDForwardDistance((uint8_t) rx_state->transfer_id, TRANSFER_ID_FROM_TAIL_BYTE(tail_byte)) > 1; + const bool incomplete_frame = rx_state->buffer_blocks != NULL; const bool need_restart = (not_initialized) || (tid_timed_out) || - (first_frame && not_previous_tid); + (first_frame && (not_previous_tid || incomplete_frame)); if (need_restart) { diff --git a/tests/test_rxerr.cpp b/tests/test_rxerr.cpp index 9822c29d..a5dd88bb 100644 --- a/tests/test_rxerr.cpp +++ b/tests/test_rxerr.cpp @@ -372,3 +372,37 @@ TEST_CASE("canardHandleRxFrame OOM handling, Correctness") err = canardHandleRxFrame(&canard, &frame, 1); REQUIRE(-CANARD_ERROR_OUT_OF_MEMORY == err); } + +TEST_CASE("canardHandleRxFrame unusual single frame, Correctness") +{ + uint8_t canard_memory_pool[1024]; + CanardInstance canard; + CanardCANFrame frame; + int16_t err; + + g_should_accept = true; + + //Open canard to accept all transfers with a node ID of 20 + canardInit(&canard, canard_memory_pool, sizeof(canard_memory_pool), + onTransferReceived, shouldAcceptTransfer, &canard); + canardSetLocalNodeID(&canard, 20); + + frame.data[7] = CONSTRUCT_TAIL_BYTE(1, 0, 0, 1); + frame.id = CONSTRUCT_SVC_ID(0, 0, 1, 20, 0); + frame.data_len = 8; //Data length MUST be full packet + err = canardHandleRxFrame(&canard, &frame, 1); + REQUIRE(CANARD_OK == err); + + + frame.data[7] = CONSTRUCT_TAIL_BYTE(0, 0, 1, 1); + frame.id = CONSTRUCT_SVC_ID(0, 0, 1, 20, 0); + frame.data_len = 8; //Data length MUST be full packet + err = canardHandleRxFrame(&canard, &frame, 1); + REQUIRE(CANARD_OK == err); + + frame.data[1] = CONSTRUCT_TAIL_BYTE(1, 1, 1, 1); + frame.id = CONSTRUCT_SVC_ID(0, 0, 1, 20, 0); + frame.data_len = 2; //Data length MUST be full packet + err = canardHandleRxFrame(&canard, &frame, 1); + REQUIRE(CANARD_OK == err); +}