File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -26,8 +26,28 @@ TEST_CASE("CyphalHeaderCRC")
2626{
2727 using exposed::cyphalHeaderCrcAdd;
2828
29+ // Standard Cyphal header size = 24. The last 2 bytes are for the CRC.
30+
31+ // Standard use case. Header size = 24; CRC is calculated from the first 22 bytes.
32+ // The last two bytes (CRC) are ignored in the calculation.
2933 std::uint16_t crc = 0xFFFFU ;
3034 const uint8_t * header = reinterpret_cast <const uint8_t *>(" \x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x20\x21\x22\x23\x24 " );
3135 crc = cyphalHeaderCrcAdd (crc, 22 , header);
3236 REQUIRE (0xB731 == crc);
37+
38+ // Verify CRC when the size field is equal to the size of the header.
39+ crc = 0xFFFFU ;
40+ header = reinterpret_cast <const uint8_t *>(" \x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x20\x21\x22 " );
41+ crc = cyphalHeaderCrcAdd (crc, 22 , header);
42+ REQUIRE (0xB731 == crc);
43+ crc = 0xFFFFU ;
44+ header = reinterpret_cast <const uint8_t *>(" \x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x20\x21\x22\x23\x24 " );
45+ crc = cyphalHeaderCrcAdd (crc, 24 , header);
46+ REQUIRE (0x96BB == crc);
47+
48+ // Verify CRC when the size field is less than the size of the header. Extra data is ignored.
49+ crc = 0xFFFFU ;
50+ header = reinterpret_cast <const uint8_t *>(" \x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x20\x21\x22\x23\x24 " );
51+ crc = cyphalHeaderCrcAdd (crc, 10 , header);
52+ REQUIRE (0x9F09 == crc);
3353}
You can’t perform that action at this time.
0 commit comments