eive-tmtc/eive_tmtc/cfdp/tm.py

30 lines
1.2 KiB
Python
Raw Normal View History

2023-08-29 21:41:29 +02:00
import logging
2023-11-13 09:05:34 +01:00
from typing import Any
2023-08-29 21:41:29 +02:00
from eive_tmtc.config.definitions import CFDP_APID
from spacepackets.ccsds import SPACE_PACKET_HEADER_SIZE
2023-11-13 09:05:34 +01:00
from spacepackets.cfdp import PduFactory, PduType
2023-08-29 21:41:29 +02:00
from tmtccmd.cfdp.handler import CfdpInCcsdsHandler
2023-11-10 19:23:06 +01:00
from tmtccmd.tmtc import SpecificApidHandlerBase
2023-08-29 21:41:29 +02:00
_LOGGER = logging.getLogger(__name__)
class CfdpInCcsdsWrapper(SpecificApidHandlerBase):
def __init__(self, cfdp_in_ccsds_handler: CfdpInCcsdsHandler):
self.handler = cfdp_in_ccsds_handler
2023-11-13 09:05:34 +01:00
super().__init__(CFDP_APID, None)
2023-08-29 21:41:29 +02:00
2023-11-13 09:05:34 +01:00
def handle_tm(self, packet: bytes, _user_args: Any):
2023-08-29 21:41:29 +02:00
# 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:]
2023-11-13 09:05:34 +01:00
generic_pdu = PduFactory.from_raw(pdu)
assert generic_pdu is not None
if generic_pdu.pdu_type == PduType.FILE_DATA:
2023-09-04 11:17:25 +02:00
_LOGGER.info("Received File Data PDU")
2023-08-29 21:41:29 +02:00
else:
2023-11-13 09:05:34 +01:00
directive_type = PduFactory.pdu_directive_type(pdu)
2023-09-04 11:17:25 +02:00
_LOGGER.info(f"Received File Directive PDU with type {directive_type!r}")
2023-11-13 09:05:34 +01:00
self.handler.insert_pdu_packet(generic_pdu)