Skip to content

Commit

Permalink
improvements for EOF PDU
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Nov 3, 2021
1 parent 7b12d49 commit 3265d5b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 5 additions & 4 deletions spacepackets/cfdp/pdu/eof.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class EofPdu:

def __init__(
self,
condition_code: ConditionCode,
checksum_u32: int,
file_size: int,
pdu_conf: PduConfig,
fault_location: Optional[EntityIdTlv] = None,
condition_code: ConditionCode = ConditionCode.NO_ERROR,
fault_location: Optional[EntityIdTlv] = None
):
"""Constructor for an EOF PDU
Expand Down Expand Up @@ -67,6 +67,7 @@ def _calculate_directive_param_field_len(self):
def __empty(cls) -> EofPdu:
empty_conf = PduConfig.empty()
return cls(
condition_code=ConditionCode.NO_ERROR,
checksum_u32=0,
file_size=0,
pdu_conf=empty_conf
Expand All @@ -80,7 +81,7 @@ def pack(self) -> bytearray:
eof_pdu.extend(struct.pack('!Q', self.file_size))
else:
eof_pdu.extend(struct.pack('!I', self.file_size))
if self.fault_location is not None:
if self.fault_location is not None and self.condition_code is not ConditionCode.NO_ERROR:
eof_pdu.extend(self.fault_location.pack())
return eof_pdu

Expand All @@ -105,6 +106,6 @@ def unpack(cls, raw_packet: bytearray) -> EofPdu:
current_idx, eof_pdu.file_size = eof_pdu.pdu_file_directive._parse_fss_field(
raw_packet=raw_packet, current_idx=current_idx
)
if len(raw_packet) > current_idx:
if len(raw_packet) > current_idx and eof_pdu.condition_code != ConditionCode.NO_ERROR:
eof_pdu.fault_location = EntityIdTlv.unpack(raw_bytes=raw_packet[current_idx:])
return eof_pdu
4 changes: 4 additions & 0 deletions tests/test_cfdp_pdus.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ def test_eof_pdu(self):
pdu_conf = PduConfig.empty()
zero_checksum = 0
eof_pdu = EofPdu(
condition_code=ConditionCode.NO_ERROR,
checksum_u32=zero_checksum,
file_size=0,
pdu_conf=pdu_conf
Expand Down Expand Up @@ -546,6 +547,7 @@ def test_eof_pdu(self):
)
self.assertEqual(fault_loc_tlv.packet_len, 4)
eof_pdu.fault_location = fault_loc_tlv
eof_pdu.condition_code = ConditionCode.POSITIVE_ACK_LIMIT_REACHED
self.assertEqual(eof_pdu.packet_len, expected_packet_len + 4)
eof_pdu_with_fault_loc = eof_pdu
eof_pdu_with_fault_loc_raw = eof_pdu_with_fault_loc.pack()
Expand All @@ -557,13 +559,15 @@ def test_eof_pdu(self):

with self.assertRaises(ValueError):
EofPdu(
condition_code=ConditionCode.NO_ERROR,
checksum_u32=pow(2, 64),
file_size=0,
pdu_conf=pdu_conf
)

pdu_conf.file_size = FileSize.LARGE
eof_pdu_large_file = EofPdu(
condition_code=ConditionCode.NO_ERROR,
checksum_u32=zero_checksum,
file_size=0,
pdu_conf=pdu_conf
Expand Down

0 comments on commit 3265d5b

Please sign in to comment.