Skip to content
25 changes: 15 additions & 10 deletions oresat_c3/protocols/uslp.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def unpack_frame(raw: bytes) -> TransferFrame:

vcid = ((raw[2] & 0b111) << 3) | ((raw[3] >> 5) & 0b111)

sdls_header_len = get_sdls_header_len(vcid)
is_command = bool(raw[6] & 0x40)
sdls_header_len = 0 if is_command else get_sdls_header_len(vcid)

frame_props = VarFrameProperties(
has_insert_zone=sdls_header_len != 0,
Expand All @@ -92,6 +93,7 @@ def make_frame(
control_word: Optional[bytes] = None,
sequence_number: int = 0,
bypass: bool = False,
command: bool = False,
) -> TransferFrame:
"""Create and pack a USLP

Expand All @@ -113,6 +115,8 @@ def make_frame(
The anti-replay sequence number for SDLS.
bypass
Specify if this frame is bypass (Type-BD) frame.
command
Specify if this frame is for protocol command.

Returns
-------
Expand All @@ -127,29 +131,29 @@ def make_frame(
tfdz=payload,
)

# USLP transfer frame total length - 1
frame_len = len(payload) + PRIMARY_HEADER_LEN + DFH_LEN + FECF_LEN - 1
vcf_count_len = 1 if vcf_count is not None else 0

has_clcw = control_word is not None
if has_clcw:
frame_len += len(control_word)

# USLP transfer frame total length - 1
frame_len = len(payload) + PRIMARY_HEADER_LEN + DFH_LEN + FECF_LEN - 1
frame_len = len(payload) + PRIMARY_HEADER_LEN + vcf_count_len + DFH_LEN + FECF_LEN - 1
if has_clcw:
frame_len += len(control_word)
frame_len += get_sdls_len(vcid)
if not command:
frame_len += get_sdls_len(vcid)

frame_header = PrimaryHeader(
scid=SPACECRAFT_ID,
map_id=0,
vcid=vcid,
src_dest=src_dest,
frame_len=frame_len,
vcf_count_len=bool(vcf_count),
vcf_count_len=vcf_count_len,
vcf_count=vcf_count,
op_ctrl_flag=has_clcw,
prot_ctrl_cmd_flag=ProtocolCommandFlag.USER_DATA,
prot_ctrl_cmd_flag=(
ProtocolCommandFlag.PROTOCOL_INFORMATION if command else ProtocolCommandFlag.USER_DATA
),
bypass_seq_ctrl_flag=(
BypassSequenceControlFlag.EXPEDITED_QOS
if bypass
Expand All @@ -159,6 +163,7 @@ def make_frame(

frame = TransferFrame(header=frame_header, tfdf=tfdf, op_ctrl_field=control_word)

apply_sdls(frame, sequence_number, hmac_key)
if not command:
apply_sdls(frame, sequence_number, hmac_key)

return frame
2 changes: 1 addition & 1 deletion oresat_c3/services/cop_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _process_farm_higher(self) -> None:
def create_farm_service(self, vcid: EdlVcid) -> SimpleQueue[TransferFrame]:
logger.info(f"Creating FARM-1 Service for VCID {vcid}")
q: SimpleQueue[TransferFrame] = SimpleQueue()
self._farms[vcid] = (Farm1(w=20, vcf_count_length=2), q)
self._farms[vcid] = (Farm1(w=20, vcf_count_length=1), q)
return q

def get_service(self, vcid: EdlVcid) -> Optional[CopService]:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies = [
"skyfield>=1.54",
"smbus2",
"spacepackets>=0.30.1",
"ccsds-cop>=0.0.0",
"ccsds-cop>=0.1.1",
"typing-extensions>=4.13.0"
]

Expand Down
Loading