88#include < cstring>
99
1010static const uint32_t CRC_INITIAL = 0xFFFFFFFFU ;
11+ static const uint32_t UDPARD_MAX_FRAME_INDEX = 0x7FFFFFFFU ;
1112
1213TEST_CASE (" rxTryParseFrame" )
1314{
@@ -36,7 +37,7 @@ TEST_CASE("rxTryParseFrame")
3637 header.destination_node_id = 0xFFFF ;
3738 header.data_specifier = 0x0000 ;
3839 header.transfer_id = 0x0000000000000001 ;
39- header.frame_index_eot = ( 1U << 31U ) + 1U ;
40+ header.frame_index_eot = 1U << 31U ;
4041 header._opaque = 0x0000 ;
4142 header.cyphal_header_checksum = 0x0000 ;
4243
@@ -48,7 +49,7 @@ TEST_CASE("rxTryParseFrame")
4849 0xFF , 0xFF , // Destination Node ID
4950 0x00 , 0x00 , // Data Specifier
5051 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , // Transfer ID
51- 0x01 , 0x00 , 0x00 , 0x80 , // Frame EOT
52+ 0x00 , 0x00 , 0x00 , 0x80 , // Frame EOT
5253 0x00 , 0x00 , // Opaque Data
5354 0x00 , 0x00 , // Transfer CRC
5455 };
@@ -70,7 +71,7 @@ TEST_CASE("rxTryParseFrame")
7071 0xFF , 0xFF , // Destination Node ID
7172 0x00 , 0x00 , // Data Specifier
7273 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , // Transfer ID
73- 0x01 , 0x00 , 0x00 , 0x80 , // Frame EOT
74+ 0x00 , 0x00 , 0x00 , 0x80 , // Frame EOT
7475 0x00 , 0x00 , // Opaque Data
7576 0x00 , 0x00 , // Transfer CRC
7677 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 // Payload
@@ -82,7 +83,7 @@ TEST_CASE("rxTryParseFrame")
8283 REQUIRE (model.source_node_id == 0U );
8384 REQUIRE (model.destination_node_id == UDPARD_NODE_ID_UNSET);
8485 REQUIRE (model.transfer_id == 1U );
85- // REQUIRE(model.frame_index == 1U );
86+ REQUIRE (( model.frame_index & UDPARD_MAX_FRAME_INDEX) == 0U );
8687 REQUIRE (model.start_of_transfer );
8788 REQUIRE (model.end_of_transfer );
8889 REQUIRE (model.payload_size == 8 );
@@ -105,7 +106,7 @@ TEST_CASE("rxTryParseFrame")
105106 0xFF , 0xFF , // Destination Node ID
106107 0x00 , 0x00 , // Data Specifier
107108 0x07 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , // Transfer ID
108- 0x00 , 0x00 , 0x00 , 0x80 , // Frame EOT
109+ 0x02 , 0x00 , 0x00 , 0x80 , // Frame EOT
109110 0x00 , 0x00 , // Opaque Data
110111 0x00 , 0x00 , // Transfer CRC
111112 })); // MFT FRAMES REQUIRE PAYLOAD
@@ -120,7 +121,7 @@ TEST_CASE("rxTryParseFrame")
120121 0xFF , 0xFF , // Destination Node ID
121122 0xCC , 0x0C , // Data Specifier
122123 0x17 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , // Transfer ID
123- 0x01 , 0x00 , 0x00 , 0x00 , // Frame EOT
124+ 0x00 , 0x00 , 0x00 , 0x00 , // Frame EOT
124125 0x00 , 0x00 , // Opaque Data
125126 0x00 , 0x00 , // Transfer CRC
126127 0 , 1 , 2 , 3 , 4 , 5 , 6 // Payload
@@ -132,6 +133,7 @@ TEST_CASE("rxTryParseFrame")
132133 REQUIRE (model.source_node_id == 0b0100111U );
133134 REQUIRE (model.destination_node_id == UDPARD_NODE_ID_UNSET);
134135 REQUIRE (model.transfer_id == 23U );
136+ REQUIRE ((model.frame_index & UDPARD_MAX_FRAME_INDEX) == 0U );
135137 REQUIRE (model.start_of_transfer );
136138 REQUIRE (!model.end_of_transfer );
137139 REQUIRE (model.payload_size == 7 );
@@ -172,7 +174,7 @@ TEST_CASE("rxTryParseFrame")
172174 0xFF , 0xFF , // Destination Node ID
173175 0xCD , 0x0C , // Data Specifier
174176 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , // Transfer ID
175- 0x01 , 0x00 , 0x00 , 0x80 , // Frame EOT
177+ 0x00 , 0x00 , 0x00 , 0x80 , // Frame EOT
176178 0x00 , 0x00 , // Opaque Data
177179 0x00 , 0x00 , // Transfer CRC
178180 }));
@@ -183,6 +185,7 @@ TEST_CASE("rxTryParseFrame")
183185 REQUIRE (model.source_node_id == UDPARD_NODE_ID_UNSET);
184186 REQUIRE (model.destination_node_id == UDPARD_NODE_ID_UNSET);
185187 REQUIRE (model.transfer_id == 0U );
188+ REQUIRE ((model.frame_index & UDPARD_MAX_FRAME_INDEX) == 0U );
186189 REQUIRE (model.start_of_transfer );
187190 REQUIRE (model.end_of_transfer );
188191 REQUIRE (model.payload_size == 0 );
@@ -563,7 +566,7 @@ TEST_CASE("rxSessionUpdate")
563566 frame.transfer_id = 13 ;
564567 frame.end_of_transfer = false ;
565568 frame.payload_size = 7 ;
566- frame.frame_index = 1 ;
569+ frame.frame_index = 0 ;
567570 frame.payload = reinterpret_cast <const uint8_t *>(" \x06\x06\x06\x06\x06\x06\x06 " );
568571 REQUIRE (0 == update (0 , 1'000'000 , 16 ));
569572
@@ -591,7 +594,7 @@ TEST_CASE("rxSessionUpdate")
591594 frame.timestamp_usec = 20'000'200 ;
592595 frame.start_of_transfer = false ;
593596 frame.end_of_transfer = false ;
594- frame.frame_index = 3 + static_cast <uint32_t >(1U << static_cast <uint32_t >(31U ));
597+ frame.frame_index = 2 + static_cast <uint32_t >(1U << static_cast <uint32_t >(31U ));
595598 frame.payload_size = 2 ;
596599 frame.payload = reinterpret_cast <const uint8_t *>(" \x09\x09 " );
597600 REQUIRE (-UDPARD_ERROR_OUT_OF_ORDER == update (0 , 1'000'000 , 16 ));
@@ -618,7 +621,7 @@ TEST_CASE("rxSessionUpdate")
618621 frame.start_of_transfer = true ;
619622 frame.end_of_transfer = false ;
620623 frame.payload_size = 7 ;
621- frame.frame_index = 1 ;
624+ frame.frame_index = 0 ;
622625 frame.payload = reinterpret_cast <const uint8_t *>(" \x06\x06\x06\x06\x06\x06\x06 " );
623626 REQUIRE (0 == update (0 , 1'000'000 , 16 ));
624627
@@ -645,7 +648,7 @@ TEST_CASE("rxSessionUpdate")
645648 // Multi-frame, middle.
646649 frame.start_of_transfer = false ;
647650 frame.end_of_transfer = false ;
648- frame.frame_index = 2 ;
651+ frame.frame_index = 1 ;
649652 frame.payload_size = 7 ;
650653 frame.payload = reinterpret_cast <const uint8_t *>(" \x07\x07\x07\x07\x07\x07\x07 " );
651654 REQUIRE (0 == update (0 , 1'000'000 , 16 ));
@@ -672,7 +675,7 @@ TEST_CASE("rxSessionUpdate")
672675 // Multi-frame, last.
673676 frame.start_of_transfer = false ;
674677 frame.end_of_transfer = true ;
675- frame.frame_index = 3 + static_cast <uint32_t >(1U << static_cast <uint32_t >(31U ));
678+ frame.frame_index = 2 + static_cast <uint32_t >(1U << static_cast <uint32_t >(31U ));
676679 frame.payload_size = 8 ; // The payload is IMPLICITLY TRUNCATED, and the CRC IS STILL VALIDATED.
677680 frame.payload = reinterpret_cast <const uint8_t *>(" \x09\x09\x09\x09\x32\x98\x04\x7B " );
678681 REQUIRE (1 == update (0 , 1'000'000 , 16 ));
0 commit comments