Skip to content

Commit f34cbe7

Browse files
Simplify the reassembler further
1 parent 698e5b5 commit f34cbe7

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

libcanard/canard.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,14 @@ CANARD_PRIVATE int8_t rxSessionUpdate(CanardInstance* const ins,
825825
CANARD_ASSERT(frame->transfer_id <= CANARD_TRANSFER_ID_MAX);
826826

827827
// The transfer ID timeout is measured relative to the timestamp of the last start-of-transfer frame.
828+
// Triggering a TID timeout when the TID is the same is undesirable because it may cause the reassembler to
829+
// switch to another interface if the start-of-transfer frame of the current transfer is duplicated
830+
// on the other interface more than (transfer-ID timeout) units of time after the start of
831+
// the transfer while the reassembly of this transfer is still in progress.
832+
// While this behavior is not visible to the application because the transfer will still be reassembled,
833+
// it may delay the delivery of the transfer.
828834
const bool tid_timed_out = (frame->timestamp_usec > rxs->transfer_timestamp_usec) &&
835+
(frame->transfer_id != rxs->transfer_id) &&
829836
((frame->timestamp_usec - rxs->transfer_timestamp_usec) > transfer_id_timeout_usec);
830837
// Examples: rxComputeTransferIDDifference(2, 3)==31
831838
// rxComputeTransferIDDifference(2, 2)==0
@@ -836,12 +843,6 @@ CANARD_PRIVATE int8_t rxSessionUpdate(CanardInstance* const ins,
836843
const bool need_restart =
837844
frame->start_of_transfer &&
838845
(tid_timed_out || ((rxs->redundant_transport_index == redundant_transport_index) && not_previous_tid));
839-
// One interesting trait of this implementation is that if the start-of-transfer frame of the current
840-
// transfer is duplicated on another interface more than (transfer-ID timeout) units of time after the start of
841-
// the transfer while the reassembly of this transfer is still in progress,
842-
// the reassembler will switch to the other interface and restart the transfer reassembly from scratch.
843-
// This effect is not visible to the application because the outcome is the same as if the transfer was
844-
// received on the original interface.
845846
if (need_restart)
846847
{
847848
CANARD_ASSERT(frame->start_of_transfer);

tests/test_public_rx.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -518,17 +518,17 @@ TEST_CASE("Issue212")
518518
0,
519519
0b001'00'0'11'0110011001100'0'0100111,
520520
{1, 2, 3, 4, 5, 6, 7, 0b101'00011}));
521-
REQUIRE(0 == accept(112'000'001, // second frame, transport #0
522-
0,
521+
REQUIRE(0 == accept(112'000'001, // second frame, transport #1
522+
1,
523523
0b001'00'0'11'0110011001100'0'0100111,
524524
{8, 9, 10, 11, 12, 13, 14, 0b000'00011}));
525-
REQUIRE(1 == accept(113'000'002, // third and last frame, transport #0
526-
0,
525+
REQUIRE(1 == accept(113'000'002, // third and last frame, transport #1
526+
1,
527527
0b001'00'0'11'0110011001100'0'0100111,
528528
{0x32, 0xF8, 0b011'00011}));
529529
REQUIRE(subscription != nullptr); // Subscription exists.
530530
REQUIRE(subscription->port_id == 0b0110011001100);
531-
REQUIRE(transfer.timestamp_usec == 111'000'001);
531+
REQUIRE(transfer.timestamp_usec == 110'000'001);
532532
REQUIRE(transfer.metadata.priority == CanardPriorityImmediate);
533533
REQUIRE(transfer.metadata.transfer_kind == CanardTransferKindMessage);
534534
REQUIRE(transfer.metadata.port_id == 0b0110011001100);

0 commit comments

Comments
 (0)