Skip to content

Commit

Permalink
nak continued
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Aug 16, 2021
1 parent ab879ec commit 46b4b39
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/tmtccmd/cfdp/lv.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def unpack(cls, raw_bytes: bytearray) -> CfdpLv:
:raise ValueError: Invalid length found
"""
detected_len = raw_bytes[0]
if self.len > 255:
if detected_len > 255:
LOGGER.warning('Length too large for LV field')
raise ValueError
return cls(
Expand Down
20 changes: 8 additions & 12 deletions src/tmtccmd/cfdp/pdu/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,13 @@ def __init__(
self.closure_requested = closure_requested
self.checksum_type = checksum_type
self.file_size = file_size
source_file_name_as_bytes = source_file_name
if serialize:
source_file_name_as_bytes = source_file_name.encode('utf-8')
source_file_name_as_bytes = source_file_name.encode('utf-8')
self.source_file_name_lv = CfdpLv(
serialize=serialize, value=source_file_name_as_bytes
value=source_file_name_as_bytes
)
dest_file_name_as_bytes = dest_file_name
if serialize:
dest_file_name_as_bytes = dest_file_name.encode('utf-8')
dest_file_name_as_bytes = dest_file_name.encode('utf-8')
self.dest_file_name_lv = CfdpLv(
serialize=serialize, value=dest_file_name_as_bytes
value=dest_file_name_as_bytes
)
self.options = options

Expand All @@ -58,8 +54,8 @@ def __empty(cls) -> MetadataPdu:
closure_requested=None,
checksum_type=None,
file_size=None,
source_file_name=None,
dest_file_name=None,
source_file_name="",
dest_file_name="",
direction=None,
trans_mode=None
)
Expand Down Expand Up @@ -87,8 +83,8 @@ def unpack(cls, raw_packet: bytearray) -> MetadataPdu:
# Minimal length: 1 byte + FSS (4 byte) + 2 empty LV (1 byte)
if not check_packet_length(len(raw_packet), metadata_pdu.pdu_file_directive.get_len() + 7):
raise ValueError
self.closure_requested = raw_packet[current_idx] & 0x40
self.checksum_type = raw_packet[current_idx] & 0x0f
metadata_pdu.closure_requested = raw_packet[current_idx] & 0x40
metadata_pdu.checksum_type = raw_packet[current_idx] & 0x0f
current_idx += 1
current_idx, metadata_pdu.file_size = metadata_pdu.pdu_file_directive.parse_fss_field(
raw_packet=raw_packet, current_idx=current_idx
Expand Down
42 changes: 37 additions & 5 deletions src/tmtccmd/cfdp/pdu/nak.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations
import enum
import struct
from typing import List, Tuple

from tmtccmd.cfdp.pdu.file_directive import FileDirectivePduBase, DirectiveCodes, \
ConditionCode
Expand All @@ -10,25 +12,55 @@
class NakPdu():
def __init__(
self,
serialize: bool,
direction: Direction,
trans_mode: TransmissionModes,
start_of_scope: int,
end_of_scope: int,
segment_requests: List[Tuple[int,int]],
crc_flag: CrcFlag = CrcFlag.GLOBAL_CONFIG,
len_entity_id: LenInBytes = LenInBytes.NONE,
len_transaction_seq_num=LenInBytes.NONE,
):
self.pdu_file_directive = FileDirectivePduBase(
serialize=serialize,
directive_code=DirectiveCodes.ACK_PDU,
direction=direction,
trans_mode=trans_mode,
crc_flag=crc_flag,
len_entity_id=len_entity_id,
len_transaction_seq_num=len_transaction_seq_num
)
self.start_of_scope = start_of_scope
self.end_of_scope = end_of_scope
self.segment_requests = segment_requests

@classmethod
def __empty(cls) -> NakPdu:
return cls(
direction=None,
trans_mode=None,
start_of_scope=None,
end_of_scope=None,
segment_requests=None
)

def pack(self) -> bytearray:
pass
nak_pdu = self.pdu_file_directive.pack()
if not self.pdu_file_directive.pdu_header.large_file:
nak_pdu.extend(struct.pack('!I', self.start_of_scope))
nak_pdu.extend(struct.pack('!I', self.end_of_scope))
else:
nak_pdu.extend(struct.pack('!Q', self.start_of_scope))
nak_pdu.extend(struct.pack('!Q', self.end_of_scope))
for segment_request in self.segment_requests:
if not self.pdu_file_directive.pdu_header.large_file:
nak_pdu.extend(struct.pack('!I', segment_request[0]))
nak_pdu.extend(struct.pack('!I', segment_request[1]))
else:
nak_pdu.extend(struct.pack('!Q', segment_request[0]))
nak_pdu.extend(struct.pack('!Q', segment_request[1]))

def unpack(self, raw_packet: bytearray):
pass
@classmethod
def unpack(cls, raw_packet: bytearray) -> NakPdu:
nak_pdu = cls.__empty()
nak_pdu.pdu_file_directive = FileDirectivePduBase.unpack(raw_packet=raw_packet)
current_idx = nak_pdu.pdu_file_directive.get_len()
4 changes: 2 additions & 2 deletions src/tmtccmd/cfdp/tlv.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def unpack(cls, raw_bytes: bytearray) -> CfdpTlv:
LOGGER.warning('Invalid length for TLV field, less than 2')
raise ValueError
try:
self.type = TlvTypes(raw_bytes[0])
type = TlvTypes(raw_bytes[0])
except ValueError:
LOGGER.warning(
f'TLV field invalid, found value {self.type} is not a possible TLV parameter'
f'TLV field invalid, found value {type} is not a possible TLV parameter'
)
raise ValueError
value = bytearray()
Expand Down

0 comments on commit 46b4b39

Please sign in to comment.