eive-tmtc/pus_tm/factory_hook.py

65 lines
2.6 KiB
Python
Raw Normal View History

2020-12-17 17:50:00 +01:00
"""
@brief This file transfers control of TM parsing to the user
@details Template configuration file. Copy this folder to the TMTC commander root and adapt
it to your needs.
"""
2022-03-02 10:09:57 +01:00
from tmtccmd.tm.service_8_fsfw_functional_cmd import Service8FsfwTm
2021-10-01 10:55:56 +02:00
from spacepackets.ecss.tm import PusTelemetry
2021-06-28 19:06:09 +02:00
from tmtccmd.utility.logger import get_console_logger
2020-12-17 17:50:00 +01:00
2021-10-04 01:33:03 +02:00
from tmtccmd.pus.service_1_verification import Service1TMExtended
from tmtccmd.pus.service_17_test import Service17TMExtended
2022-03-02 10:09:57 +01:00
from tmtccmd.tm.service_3_fsfw_housekeeping import Service3FsfwTm
from tmtccmd.tm.service_20_fsfw_parameters import Service20FsfwTm
from tmtccmd.tm.service_5_event import Service5Tm
from tmtccmd.tm.service_200_fsfw_mode import Service200FsfwTm
2022-01-18 14:03:56 +01:00
from tmtccmd.utility.tmtc_printer import TmTcPrinter, PrintFormats
2021-06-21 17:30:37 +02:00
from config.definitions import PUS_APID
2020-12-17 17:50:00 +01:00
2021-06-28 19:06:09 +02:00
LOGGER = get_console_logger()
2020-12-17 17:50:00 +01:00
2022-01-18 14:03:56 +01:00
def ccsds_tm_handler(
apid: int, raw_tm_packet: bytearray, tmtc_printer: TmTcPrinter
) -> None:
2021-06-21 17:30:37 +02:00
if apid == PUS_APID:
pus_factory_hook(raw_tm_packet=raw_tm_packet, tmtc_printer=tmtc_printer)
def pus_factory_hook(raw_tm_packet: bytearray, tmtc_printer: TmTcPrinter):
2021-12-16 16:07:59 +01:00
if len(raw_tm_packet) < 8:
LOGGER.warning("Detected packet shorter than 8 bytes!")
return
2020-12-17 17:50:00 +01:00
service_type = raw_tm_packet[7]
2021-06-21 17:30:37 +02:00
tm_packet = None
2021-12-15 11:19:19 +01:00
try:
if service_type == 1:
tm_packet = Service1TMExtended.unpack(raw_telemetry=raw_tm_packet)
if service_type == 3:
2022-03-02 10:09:57 +01:00
tm_packet = Service3FsfwTm.unpack(
2022-01-18 14:03:56 +01:00
raw_telemetry=raw_tm_packet, custom_hk_handling=False
)
2021-12-15 11:19:19 +01:00
if service_type == 5:
2022-03-02 10:09:57 +01:00
tm_packet = Service5Tm.unpack(raw_telemetry=raw_tm_packet)
2021-12-15 11:19:19 +01:00
if service_type == 8:
2022-03-02 10:09:57 +01:00
tm_packet = Service8FsfwTm.unpack(raw_telemetry=raw_tm_packet)
2021-12-15 11:19:19 +01:00
if service_type == 17:
tm_packet = Service17TMExtended.unpack(raw_telemetry=raw_tm_packet)
2022-03-01 19:41:24 +01:00
if service_type == 20:
2022-03-02 10:09:57 +01:00
tm_packet = Service20FsfwTm.unpack(raw_telemetry=raw_tm_packet)
2022-02-25 19:27:39 +01:00
if service_type == 200:
tm_packet = Service200FsfwTm.unpack(raw_telemetry=raw_tm_packet)
2021-12-15 11:19:19 +01:00
if tm_packet is None:
2022-01-18 14:03:56 +01:00
LOGGER.info(
f"The service {service_type} is not implemented in Telemetry Factory"
)
2021-12-15 11:19:19 +01:00
tm_packet = PusTelemetry.unpack(raw_telemetry=raw_tm_packet)
2022-01-18 14:03:56 +01:00
tm_packet.print_source_data(PrintFormats.HEX)
tmtc_printer.print_telemetry(
packet_if=tm_packet, info_if=tm_packet, print_raw_tm=False
)
2021-12-15 11:19:19 +01:00
except ValueError:
# TODO: Log faulty packet
LOGGER.warning("Invalid packet format detected")