Skip to content

Commit 89f87ab

Browse files
Remove single frame transfer CRC on receive (#17)
Remove single frame transfer CRC on receive so that is not exposed to the user
1 parent 1f5eca7 commit 89f87ab

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

libudpard/udpard.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -888,8 +888,6 @@ UDPARD_PRIVATE int8_t rxSessionAcceptFrame(UdpardInstance* const ins,
888888
rxs->transfer_timestamp_usec = frame->timestamp_usec;
889889
}
890890

891-
const bool single_frame = frame->start_of_transfer && frame->end_of_transfer;
892-
893891
rxs->calculated_crc = crcAdd(rxs->calculated_crc, frame->payload_size, frame->payload);
894892

895893
int8_t out = rxSessionWritePayload(ins, rxs, extent, frame->payload_size, frame->payload);
@@ -912,8 +910,9 @@ UDPARD_PRIVATE int8_t rxSessionAcceptFrame(UdpardInstance* const ins,
912910

913911
// Cut off the CRC from the payload if it's there -- we don't want to expose it to the user.
914912
UDPARD_ASSERT(rxs->total_payload_size >= rxs->payload_size);
913+
// For single frame transfers, the truncated amount will be 0 (total_payload_size == payload_size)
915914
const size_t truncated_amount = rxs->total_payload_size - rxs->payload_size;
916-
if ((!single_frame) && (CRC_SIZE_BYTES > truncated_amount)) // Single-frame transfers don't have CRC.
915+
if (CRC_SIZE_BYTES > truncated_amount)
917916
{
918917
UDPARD_ASSERT(out_transfer->payload_size >= (CRC_SIZE_BYTES - truncated_amount));
919918
out_transfer->payload_size -= CRC_SIZE_BYTES - truncated_amount;

tests/test_private_rx.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ TEST_CASE("rxSessionUpdate")
481481
REQUIRE(transfer.metadata.port_id == 2'222);
482482
REQUIRE(transfer.metadata.remote_node_id == 55);
483483
REQUIRE(transfer.metadata.transfer_id == 11);
484-
REQUIRE(transfer.payload_size == 7);
484+
REQUIRE(transfer.payload_size == 3); // Payload size should not include the CRC (3 byte payload + 4 byte CRC)
485485
REQUIRE(0 == std::memcmp(transfer.payload, "\x01\x01\x01", 3));
486486
REQUIRE(ins.getAllocator().getNumAllocatedFragments() == 1);
487487
REQUIRE(ins.getAllocator().getTotalAllocatedAmount() == 16);
@@ -515,7 +515,7 @@ TEST_CASE("rxSessionUpdate")
515515
REQUIRE(transfer.metadata.port_id == 2'222);
516516
REQUIRE(transfer.metadata.remote_node_id == 55);
517517
REQUIRE(transfer.metadata.transfer_id == 12);
518-
REQUIRE(transfer.payload_size == 7);
518+
REQUIRE(transfer.payload_size == 3); // Payload size should not include the CRC (3 byte payload + 4 byte CRC)
519519
REQUIRE(0 == std::memcmp(transfer.payload, "\x03\x03\x03", 3));
520520
REQUIRE(ins.getAllocator().getNumAllocatedFragments() == 1);
521521
REQUIRE(ins.getAllocator().getTotalAllocatedAmount() == 16);
@@ -550,7 +550,7 @@ TEST_CASE("rxSessionUpdate")
550550
REQUIRE(transfer.metadata.port_id == 2'222);
551551
REQUIRE(transfer.metadata.remote_node_id == 55);
552552
REQUIRE(transfer.metadata.transfer_id == 12);
553-
REQUIRE(transfer.payload_size == 7);
553+
REQUIRE(transfer.payload_size == 3); // Payload size should not include the CRC (3 byte payload + 4 byte CRC)
554554
REQUIRE(0 == std::memcmp(transfer.payload, "\x05\x05\x05", 3));
555555
REQUIRE(ins.getAllocator().getNumAllocatedFragments() == 1);
556556
REQUIRE(ins.getAllocator().getTotalAllocatedAmount() == 16);

tests/test_public_rx.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,11 @@ TEST_CASE("RxBasic0")
122122
header.frame_index_eot = (1U << 31U) + 1U;
123123
header.priority = 0b001;
124124
header.transfer_id = 0;
125-
header.data_specifier = 0b0000110011001100;
125+
header.data_specifier = 0b0000110011001100; // Subject ID = 3276
126126
specifier.data_specifier = UDPARD_UDP_PORT;
127127
specifier.destination_route_specifier = 0b11101111'00'01000'0'0'000110011001100;
128128
specifier.source_route_specifier = 0b11000000'10101000'00000000'00100111;
129+
// This is an empty payload, the last four bytes are CRC.
129130
REQUIRE(1 == accept(0, 100'000'001, header, specifier, {0, 0, 0, 0}));
130131
REQUIRE(subscription != nullptr);
131132
REQUIRE(subscription->port_id == 0b0110011001100);
@@ -135,7 +136,7 @@ TEST_CASE("RxBasic0")
135136
REQUIRE(transfer.metadata.port_id == 0b0110011001100);
136137
REQUIRE(transfer.metadata.remote_node_id == 0b0100111);
137138
REQUIRE(transfer.metadata.transfer_id == 0);
138-
REQUIRE(transfer.payload_size == 4);
139+
REQUIRE(transfer.payload_size == 0); // Payload size should not include the CRC (0 byte payload + 4 byte CRC)
139140
REQUIRE(0 == std::memcmp(transfer.payload, "", 0));
140141
REQUIRE(ins.getAllocator().getNumAllocatedFragments() == 2); // The SESSION and the PAYLOAD BUFFER.
141142
REQUIRE(ins.getAllocator().getTotalAllocatedAmount() == (sizeof(RxSession) + 16));
@@ -156,7 +157,6 @@ TEST_CASE("RxBasic0")
156157
specifier.data_specifier = UDPARD_UDP_PORT;
157158
specifier.destination_route_specifier = 0b11101111'00'01000'1'00000000'00011010;
158159
specifier.source_route_specifier = 0b11000000'10101000'00000000'00100111;
159-
160160
REQUIRE(0 == accept(0, 100'000'002, header, specifier, {0, 0, 0, 0}));
161161
REQUIRE(subscription == nullptr);
162162

@@ -193,7 +193,7 @@ TEST_CASE("RxBasic0")
193193
REQUIRE(transfer.metadata.port_id == 0b0000110011);
194194
REQUIRE(transfer.metadata.remote_node_id == 0b0100101);
195195
REQUIRE(transfer.metadata.transfer_id == 4);
196-
REQUIRE(transfer.payload_size == 7);
196+
REQUIRE(transfer.payload_size == 3); // Payload size should not include the CRC (3 byte payload + 4 byte CRC)
197197
REQUIRE(0 == std::memcmp(transfer.payload, "\x01\x02\x03\x1E\xF2\x30\xF1", 7));
198198
REQUIRE(ins.getAllocator().getNumAllocatedFragments() == 4); // Two SESSIONS and two PAYLOAD BUFFERS.
199199
REQUIRE(ins.getAllocator().getTotalAllocatedAmount() == (2 * sizeof(RxSession) + 16 + 20));
@@ -276,7 +276,7 @@ TEST_CASE("RxBasic0")
276276
REQUIRE(transfer.metadata.port_id == 0b0000111100);
277277
REQUIRE(transfer.metadata.remote_node_id == 0b0011011);
278278
REQUIRE(transfer.metadata.transfer_id == 5);
279-
REQUIRE(transfer.payload_size == 5);
279+
REQUIRE(transfer.payload_size == 1); // Payload size should not include the CRC (1 byte payload + 4 byte CRC)
280280
REQUIRE(0 == std::memcmp(transfer.payload, "\x05\x4D\x47\x8C\x67", 5));
281281
REQUIRE(ins.getAllocator().getNumAllocatedFragments() == 4);
282282
REQUIRE(ins.getAllocator().getTotalAllocatedAmount() == (2 * sizeof(RxSession) + 10 + 20));

0 commit comments

Comments
 (0)