some architectural improvements

This commit is contained in:
Robin Müller 2022-09-09 14:58:34 +02:00
parent 64ade84d51
commit 4f9e246ecd
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814

View File

@ -19,6 +19,7 @@ from tmtccmd.cfdp import (
CfdpUserBase,
)
from spacepackets.util import UnsignedByteField
from tmtccmd.cfdp.defs import CfdpRequestType
from tmtccmd.cfdp.handler import SourceHandler, DestHandler
from tmtccmd.cfdp.request import PutRequest, PutRequestCfg
from tmtccmd.logging import get_current_time_string
@ -50,7 +51,7 @@ from common_tmtc.pus_tc.service_20_parameters import pack_service20_commands_int
from common_tmtc.pus_tc.service_2_raw_cmd import pack_service_2_commands_into
from common_tmtc.pus_tc.service_3_housekeeping import pack_service_3_commands_into
from common_tmtc.pus_tc.service_8_func_cmd import pack_service_8_commands_into
from examples.tmtcc import EXAMPLE_APID
from examples.tmtcc import EXAMPLE_PUS_APID, EXAMPLE_CFDP_APID
from tmtccmd import TcHandlerBase, get_console_logger, TmTcCfgHookBase, BackendBase
from tmtccmd.pus import VerificationWrapper
from tmtccmd.tc import (
@ -70,7 +71,8 @@ from common_tmtc.pus_tm.factory_hook import pus_factory_hook
LOGGER = get_console_logger()
class CfdpCcsdsWrapper:
class CfdpCcsdsWrapper(SpecificApidHandlerBase):
def __init__(
self,
cfg: LocalEntityCfg,
@ -80,6 +82,7 @@ class CfdpCcsdsWrapper:
ccsds_seq_cnt_provider: ProvidesSeqCount,
ccsds_apid: int,
):
super().__init__(EXAMPLE_CFDP_APID, None)
self.handler = CfdpHandler(cfg, user, cfdp_seq_cnt_provider, remote_cfg)
self.ccsds_seq_cnt_provider = ccsds_seq_cnt_provider
self.ccsds_apid = ccsds_apid
@ -100,12 +103,19 @@ class CfdpCcsdsWrapper:
def confirm_dest_packet_sent(self):
self.handler.confirm_dest_packet_sent()
def pass_packet(self, packet: SpacePacket):
def pass_packet(self, space_packet: SpacePacket):
# Unwrap the user data and pass it to the handler
pdu_raw = packet.user_data
pdu_raw = space_packet.user_data
pdu_base = PduFactory.from_raw(pdu_raw)
self.handler.pass_packet(pdu_base)
def handle_tm(self, packet: bytes, _user_args: any):
ccsds_header_raw = packet[0:6]
sp_header = SpacePacketHeader.unpack(ccsds_header_raw)
pdu = packet[6:]
sp = SpacePacket(sp_header, sec_header=None, user_data=pdu)
self.pass_packet(sp)
class CfdpHandler:
def __init__(
@ -115,7 +125,7 @@ class CfdpHandler:
seq_cnt_provider: ProvidesSeqCount,
remote_cfg: Sequence[RemoteEntityCfg],
):
self.dest_id = UnsignedByteField(EXAMPLE_APID, 2)
self.dest_id = UnsignedByteField(EXAMPLE_PUS_APID, 2)
self.remote_cfg_table = RemoteEntityCfgTable()
self.remote_cfg_table.add_remote_entities(remote_cfg)
self.dest_handler = DestHandler(cfg, user, self.remote_cfg_table)
@ -194,7 +204,7 @@ class PusHandler(SpecificApidHandlerBase):
printer: FsfwTmTcPrinter,
raw_logger: RawTmtcTimedLogWrapper,
):
super().__init__(EXAMPLE_APID, None)
super().__init__(EXAMPLE_PUS_APID, None)
self.printer = printer
self.verif_wrapper = wrapper
self.raw_logger = raw_logger
@ -211,7 +221,6 @@ class PusHandler(SpecificApidHandlerBase):
class TcHandler(TcHandlerBase):
def __init__(
self,
pus_apid: int,
seq_count_provider: FileSeqCountProvider,
cfdp_handler: CfdpCcsdsWrapper,
pus_verificator: PusVerificator,
@ -225,7 +234,7 @@ class TcHandler(TcHandlerBase):
self.raw_logger = raw_logger
self.queue_helper = DefaultPusQueueHelper(
queue_wrapper=None,
pus_apid=pus_apid,
pus_apid=EXAMPLE_PUS_APID,
seq_cnt_provider=seq_count_provider,
pus_verificator=pus_verificator,
)
@ -261,7 +270,11 @@ class TcHandler(TcHandlerBase):
LOGGER.warning("Invalid Service !")
def handle_cfdp_procedure(self, info: ProcedureHelper):
info.to_def_procedure()
cfdp_procedure = info.to_cfdp_procedure()
if cfdp_procedure.cfdp_request_type == CfdpRequestType.PUT:
# TODO: Start put request if there isn't one pending yet
# self.cfdp_handler.handler.put_request_file(...)
pass
pass
def send_cb(self, params: SendCbParams):
@ -309,7 +322,7 @@ def setup_params(hook_obj: TmTcCfgHookBase) -> SetupWrapper:
parser_wrapper.parse()
tmtccmd.init_printout(parser_wrapper.use_gui)
parser_wrapper.set_params(params)
params.apid = EXAMPLE_APID
params.apid = EXAMPLE_PUS_APID
setup_wrapper = SetupWrapper(hook_obj=hook_obj, setup_params=params)
return setup_wrapper
@ -317,20 +330,21 @@ def setup_params(hook_obj: TmTcCfgHookBase) -> SetupWrapper:
def setup_tmtc_handlers(
verif_wrapper: VerificationWrapper,
printer: FsfwTmTcPrinter,
cfdp_handler: CfdpCcsdsWrapper,
raw_logger: RawTmtcTimedLogWrapper,
) -> (CcsdsTmHandler, TcHandler):
pus_handler = PusHandler(
printer=printer, raw_logger=raw_logger, wrapper=verif_wrapper
printer=printer, raw_logger=raw_logger, wrapper=verif_wrapper, cfdp_handler=cfdp_handler
)
ccsds_handler = CcsdsTmHandler(None)
ccsds_handler.add_apid_handler(pus_handler)
tc_handler = TcHandler(
pus_apid=EXAMPLE_APID,
file_logger=printer.file_logger,
raw_logger=raw_logger,
pus_verificator=verif_wrapper.pus_verificator,
seq_count_provider=PusFileSeqCountProvider(),
cfdp_handler=cfdp_handler
)
return ccsds_handler, tc_handler