From 4446e471d987244b1bd275d40f97d1c86d87ef09 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 13 Nov 2023 09:05:34 +0100 Subject: [PATCH] CFDP fixes --- eive_tmtc/cfdp/tm.py | 16 +++++++++------- eive_tmtc/cfdp/user.py | 13 +++++++++++++ tmtcc.py | 9 ++++++--- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/eive_tmtc/cfdp/tm.py b/eive_tmtc/cfdp/tm.py index 5db88dc..5072553 100644 --- a/eive_tmtc/cfdp/tm.py +++ b/eive_tmtc/cfdp/tm.py @@ -1,8 +1,9 @@ import logging +from typing import Any from eive_tmtc.config.definitions import CFDP_APID from spacepackets.ccsds import SPACE_PACKET_HEADER_SIZE -from spacepackets.cfdp import PduFactory, PduType, DirectiveType +from spacepackets.cfdp import PduFactory, PduType from tmtccmd.cfdp.handler import CfdpInCcsdsHandler from tmtccmd.tmtc import SpecificApidHandlerBase @@ -11,17 +12,18 @@ _LOGGER = logging.getLogger(__name__) class CfdpInCcsdsWrapper(SpecificApidHandlerBase): def __init__(self, cfdp_in_ccsds_handler: CfdpInCcsdsHandler): - super().__init__(CFDP_APID, None) self.handler = cfdp_in_ccsds_handler + super().__init__(CFDP_APID, None) - def handle_tm(self, packet: bytes, _user_args: any): + def handle_tm(self, packet: bytes, _user_args: Any): # Ignore the space packet header. Its only purpose is to use the same protocol and # have a seaprate APID for space packets. If this function is called, the APID is correct. pdu = packet[SPACE_PACKET_HEADER_SIZE:] - pdu_base = PduFactory.from_raw(pdu) - if pdu_base.pdu_type == PduType.FILE_DATA: + generic_pdu = PduFactory.from_raw(pdu) + assert generic_pdu is not None + if generic_pdu.pdu_type == PduType.FILE_DATA: _LOGGER.info("Received File Data PDU") else: - directive_type = DirectiveType(pdu_base.directive_type) + directive_type = PduFactory.pdu_directive_type(pdu) _LOGGER.info(f"Received File Directive PDU with type {directive_type!r}") - self.handler.insert_pdu_packet(pdu_base) + self.handler.insert_pdu_packet(generic_pdu) diff --git a/eive_tmtc/cfdp/user.py b/eive_tmtc/cfdp/user.py index 4a7ced0..9c9cd81 100644 --- a/eive_tmtc/cfdp/user.py +++ b/eive_tmtc/cfdp/user.py @@ -1,7 +1,10 @@ +from datetime import timedelta import logging from spacepackets.cfdp import ConditionCode +from spacepackets.util import UnsignedByteField from tmtccmd.cfdp import CfdpUserBase, TransactionId +from tmtccmd.cfdp.mib import CheckTimerProvider, Countdown, EntityType from tmtccmd.cfdp.user import ( TransactionFinishedParams, MetadataRecvParams, @@ -11,6 +14,16 @@ from tmtccmd.cfdp.user import ( _LOGGER = logging.getLogger(__name__) +class EiveCheckTimerProvider(CheckTimerProvider): + def provide_check_timer( + self, + local_entity_id: UnsignedByteField, + remote_entity_id: UnsignedByteField, + entity_type: EntityType, + ) -> Countdown: + return Countdown(timedelta(seconds=5.0)) + + class EiveCfdpUser(CfdpUserBase): def transaction_indication(self, transaction_id: TransactionId): _LOGGER.info(f"CFDP User: Start of File {transaction_id}") diff --git a/tmtcc.py b/tmtcc.py index fee63b0..0f10f09 100755 --- a/tmtcc.py +++ b/tmtcc.py @@ -14,7 +14,8 @@ from spacepackets.cfdp import ( from spacepackets.ecss import PusVerificator from spacepackets.version import get_version as get_sp_version from tmtccmd import BackendBase -from tmtccmd.cfdp.handler import CfdpInCcsdsHandler +from tmtccmd.cfdp.handler import RemoteEntityCfgTable +from eive_tmtc.cfdp.handler import CfdpInCcsdsHandler from tmtccmd.cfdp.mib import ( IndicationCfg, LocalEntityCfg, @@ -45,7 +46,7 @@ from tmtccmd.util import FileSeqCountProvider, PusFileSeqCountProvider from eive_tmtc import APP_LOGGER from eive_tmtc.cfdp.fault_handler import EiveCfdpFaultHandler from eive_tmtc.cfdp.tm import CfdpInCcsdsWrapper -from eive_tmtc.cfdp.user import EiveCfdpUser +from eive_tmtc.cfdp.user import EiveCfdpUser, EiveCheckTimerProvider from eive_tmtc.config.definitions import ( CFDP_APID, CFDP_LOCAL_ENTITY_ID, @@ -168,6 +169,7 @@ def setup_cfdp_handler() -> CfdpInCcsdsWrapper: crc_type=ChecksumType.CRC_32, default_transmission_mode=TransmissionMode.UNACKNOWLEDGED, ) + check_timer_provider = EiveCheckTimerProvider() cfdp_seq_count_provider = FileSeqCountProvider( max_bit_width=16, file_name=Path("seqcnt_cfdp_transaction.txt") ) @@ -177,7 +179,8 @@ def setup_cfdp_handler() -> CfdpInCcsdsWrapper: cfdp_user = EiveCfdpUser() cfdp_in_ccsds_handler = CfdpInCcsdsHandler( cfg=cfdp_cfg, - remote_cfgs=[remote_cfg, self_as_remote], + check_timer_provider=check_timer_provider, + remote_cfg_table=RemoteEntityCfgTable([remote_cfg, self_as_remote]), ccsds_apid=CFDP_APID, ccsds_seq_cnt_provider=cfdp_ccsds_seq_count_provider, cfdp_seq_cnt_provider=cfdp_seq_count_provider,