Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDU CRC length not included in the data length field #7

Closed
avan989 opened this issue Nov 14, 2023 · 2 comments
Closed

PDU CRC length not included in the data length field #7

avan989 opened this issue Nov 14, 2023 · 2 comments

Comments

@avan989
Copy link

avan989 commented Nov 14, 2023

According to the blue book 727.0-B-5 section 4.1.3.2, the CRC is supposed to be included in the data length field. It looks like the CFDP engine is not taking into account the CRC length (if calculated).

4.1.3.2 The CRC value shall be placed in the final octets of the PDU data field, and its
length shall be included in the PDU data field length. The CRC algorithm shall be applied
from the first octet of the PDU header to the last octet of the PDU data field prior to the CRC
value. 

Example:

pdu = build_initial_pdu(type: "FILE_DATA", destination_entity: destination_entity, file_size: file_size, segmentation_control: segmentation_control, transmission_mode: transmission_mode)
pdu_header_part_1_length = pdu.length # Measured here before writing variable data
pdu_header = pdu.build_variable_header(source_entity_id: source_entity['id'], transaction_seq_num: transaction_seq_num, destination_entity_id: destination_entity['id'])
pdu_header_part_2_length = pdu_header.length
pdu_contents = pdu.build_file_data_pdu_contents(offset: offset, file_data: file_data, record_continuation_state: record_continuation_state, segment_metadata: segment_metadata)
pdu.write("VARIABLE_DATA", pdu_header + pdu_contents)
pdu.write("PDU_DATA_LENGTH", pdu.length - pdu_header_part_1_length - pdu_header_part_2_length)
if destination_entity['crcs_required']
crc16 = OpenC3::Crc16.new
pdu.write("CRC", crc16.calc(pdu.buffer(false)[0..-3]))
end
return pdu.buffer(false)

@ryanmelt
Copy link
Member

The early pdu.length does include the two bytes for the CRC, so those two bytes should not be subtracted out of PDU_DATA_LENGTH.

@ryanmelt
Copy link
Member

closed by #6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants