eive-tmtc/pus_tm/factory_hook.py

85 lines
3.1 KiB
Python
Raw Normal View History

2022-04-06 16:41:46 +02:00
"""Core EIVE TM handler module
2020-12-17 17:50:00 +01:00
"""
2021-10-01 10:55:56 +02:00
from spacepackets.ecss.tm import PusTelemetry
2022-04-05 00:51:52 +02:00
from tmtccmd.logging import get_console_logger
2022-04-05 17:05:11 +02:00
from tmtccmd.logging.pus import (
log_raw_pus_tm,
log_raw_unknown_packet,
PacketTypes,
create_tmtc_logger,
)
2020-12-17 17:50:00 +01:00
from tmtccmd.tm.pus_17_test import Service17TMExtended
from tmtccmd.tm.pus_20_fsfw_parameters import Service20FsfwTm
from tmtccmd.tm.pus_200_fsfw_modes import Service200FsfwTm
2022-04-05 17:05:11 +02:00
from tmtccmd.utility.tmtc_printer import PrintFormats, FsfwTmTcPrinter
2021-06-21 17:30:37 +02:00
from config.definitions import PUS_APID
from config.object_ids import get_object_ids
2022-04-06 16:41:46 +02:00
2022-04-05 17:05:11 +02:00
from .event_handler import handle_event_packet
from .verification_handler import handle_service_1_packet
from .hk_handling import handle_hk_packet
2022-04-06 16:41:46 +02:00
from .action_reply_handler import handle_action_reply
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-04-05 17:05:11 +02:00
FSFW_PRINTER = FsfwTmTcPrinter(file_logger=create_tmtc_logger())
def ccsds_tm_handler(apid: int, raw_tm_packet: bytes, _user_args: any) -> None:
2021-06-21 17:30:37 +02:00
if apid == PUS_APID:
2022-04-05 17:05:11 +02:00
pus_factory_hook(raw_tm_packet=raw_tm_packet)
2021-06-21 17:30:37 +02:00
2022-04-05 17:05:11 +02:00
def pus_factory_hook(raw_tm_packet: bytes):
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]
2022-04-05 15:19:46 +02:00
subservice_type = raw_tm_packet[8]
2022-04-05 17:05:11 +02:00
file_logger = FSFW_PRINTER.file_logger
obj_id_dict = get_object_ids()
2022-05-17 17:21:03 +02:00
dedicated_handler = True
2021-12-15 11:19:19 +01:00
try:
2022-05-17 17:21:03 +02:00
tm_packet = None
2021-12-15 11:19:19 +01:00
if service_type == 1:
2022-04-05 17:05:11 +02:00
handle_service_1_packet(printer=FSFW_PRINTER, raw_tm=raw_tm_packet)
elif service_type == 3:
handle_hk_packet(
2022-04-05 19:49:42 +02:00
printer=FSFW_PRINTER, raw_tm=raw_tm_packet, obj_id_dict=obj_id_dict
)
2022-04-05 17:05:11 +02:00
elif service_type == 5:
2022-04-05 19:27:55 +02:00
handle_event_packet(
2022-04-05 19:49:42 +02:00
raw_tm=raw_tm_packet, printer=FSFW_PRINTER, file_logger=file_logger
2022-04-05 19:27:55 +02:00
)
2022-04-05 17:05:11 +02:00
elif service_type == 8:
2022-04-06 16:41:46 +02:00
handle_action_reply(
raw_tm=raw_tm_packet, printer=FSFW_PRINTER, obj_id_dict=obj_id_dict
)
2022-04-05 17:05:11 +02:00
elif service_type == 17:
2021-12-15 11:19:19 +01:00
tm_packet = Service17TMExtended.unpack(raw_telemetry=raw_tm_packet)
2022-05-17 17:21:03 +02:00
dedicated_handler = False
2022-04-05 17:05:11 +02:00
elif service_type == 20:
2022-03-02 10:09:57 +01:00
tm_packet = Service20FsfwTm.unpack(raw_telemetry=raw_tm_packet)
2022-05-17 17:21:03 +02:00
dedicated_handler = False
2022-04-05 17:05:11 +02:00
elif service_type == 200:
tm_packet = Service200FsfwTm.unpack(raw_telemetry=raw_tm_packet)
2022-05-17 17:21:03 +02:00
dedicated_handler = False
2022-04-05 17:05:11 +02:00
else:
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)
2022-05-17 17:21:03 +02:00
dedicated_handler = True
if not dedicated_handler and tm_packet is not None:
FSFW_PRINTER.handle_long_tm_print(packet_if=tm_packet, info_if=tm_packet)
2022-04-05 17:05:11 +02:00
log_raw_pus_tm(
packet=raw_tm_packet, srv_subservice=(service_type, subservice_type)
)
2021-12-15 11:19:19 +01:00
except ValueError:
2022-06-21 16:49:11 +02:00
LOGGER.exception("Invalid packet format detected")
2022-04-05 17:05:11 +02:00
log_raw_unknown_packet(packet=raw_tm_packet, packet_type=PacketTypes.TM)