2022-04-06 16:41:46 +02:00
|
|
|
"""Core EIVE TM handler module
|
2020-12-17 17:50:00 +01:00
|
|
|
"""
|
2022-11-29 16:53:29 +01:00
|
|
|
from eive_tmtc.config.object_ids import get_object_ids
|
2022-07-04 15:22:53 +02:00
|
|
|
from spacepackets.ecss import PusTelemetry
|
2022-08-19 12:42:27 +02:00
|
|
|
from spacepackets.ecss.pus_17_test import Service17Tm
|
2022-07-04 15:22:53 +02:00
|
|
|
from spacepackets.util import PrintFormats
|
2023-01-16 17:45:46 +01:00
|
|
|
from spacepackets.ccsds.time import CdsShortTimestamp
|
2022-07-04 15:22:53 +02:00
|
|
|
from tmtccmd import get_console_logger
|
|
|
|
from tmtccmd.logging.pus import RawTmtcTimedLogWrapper
|
|
|
|
from tmtccmd.pus import VerificationWrapper
|
|
|
|
from tmtccmd.tm import Service20FsfwTm, Service200FsfwTm
|
2023-01-31 12:56:13 +01:00
|
|
|
from tmtccmd.tm.pus_20_fsfw_param import Service20ParamDumpWrapper
|
|
|
|
from tmtccmd.pus.s20_fsfw_param_defs import CustomSubservice as ParamSubservice
|
|
|
|
from tmtccmd.tm.pus_200_fsfw_mode import Subservice as ModeSubservice
|
2022-07-08 16:25:46 +02:00
|
|
|
from tmtccmd.util.tmtc_printer import FsfwTmTcPrinter
|
2022-10-11 15:08:00 +02:00
|
|
|
from .defs import PrintWrapper
|
2022-04-06 16:41:46 +02:00
|
|
|
|
2022-04-05 17:05:11 +02:00
|
|
|
from .event_handler import handle_event_packet
|
2022-10-11 15:08:00 +02:00
|
|
|
from .verification_handler import handle_service_1_fsfw_packet, generic_retval_printout
|
2022-05-18 16:02:23 +02:00
|
|
|
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-07-04 15:22:53 +02:00
|
|
|
def pus_factory_hook(
|
|
|
|
packet: bytes,
|
|
|
|
verif_wrapper: VerificationWrapper,
|
|
|
|
printer: FsfwTmTcPrinter,
|
|
|
|
raw_logger: RawTmtcTimedLogWrapper,
|
|
|
|
):
|
|
|
|
if len(packet) < 8:
|
2021-12-16 16:07:59 +01:00
|
|
|
LOGGER.warning("Detected packet shorter than 8 bytes!")
|
|
|
|
return
|
2021-12-15 11:19:19 +01:00
|
|
|
try:
|
2023-01-16 17:45:46 +01:00
|
|
|
tm_packet = PusTelemetry.unpack(packet, CdsShortTimestamp.empty())
|
2021-12-15 11:19:19 +01:00
|
|
|
except ValueError:
|
2022-07-04 15:22:53 +02:00
|
|
|
LOGGER.warning("Could not generate PUS TM object from raw data")
|
|
|
|
LOGGER.warning(f"Raw Packet: [{packet.hex(sep=',')}], REPR: {packet!r}")
|
|
|
|
return
|
|
|
|
service = tm_packet.service
|
|
|
|
obj_id_dict = get_object_ids()
|
2022-10-11 15:08:00 +02:00
|
|
|
pw = PrintWrapper(printer)
|
2022-07-04 15:22:53 +02:00
|
|
|
dedicated_handler = True
|
|
|
|
if service == 1:
|
2022-08-18 16:19:09 +02:00
|
|
|
handle_service_1_fsfw_packet(wrapper=verif_wrapper, raw_tm=packet)
|
2022-07-04 15:22:53 +02:00
|
|
|
elif service == 3:
|
|
|
|
handle_hk_packet(printer=printer, raw_tm=packet, obj_id_dict=obj_id_dict)
|
|
|
|
elif service == 5:
|
2022-08-22 10:47:10 +02:00
|
|
|
handle_event_packet(raw_tm=packet, printer=printer)
|
2022-07-04 15:22:53 +02:00
|
|
|
elif service == 8:
|
|
|
|
handle_action_reply(raw_tm=packet, printer=printer, obj_id_dict=obj_id_dict)
|
|
|
|
elif service == 17:
|
2023-01-16 17:45:46 +01:00
|
|
|
tm_packet = Service17Tm.unpack(
|
|
|
|
raw_telemetry=packet, time_reader=CdsShortTimestamp.empty()
|
|
|
|
)
|
2022-08-19 12:42:27 +02:00
|
|
|
if tm_packet.subservice == 2:
|
|
|
|
verif_wrapper.dlog("Received Ping Reply TM[17,2]")
|
|
|
|
dedicated_handler = True
|
2022-07-04 15:22:53 +02:00
|
|
|
elif service == 20:
|
2023-01-28 14:48:36 +01:00
|
|
|
param_packet = Service20FsfwTm.unpack(
|
2023-01-16 17:45:46 +01:00
|
|
|
raw_telemetry=packet, time_reader=CdsShortTimestamp.empty()
|
|
|
|
)
|
2023-01-28 14:36:21 +01:00
|
|
|
if tm_packet.subservice == ParamSubservice.TM_DUMP_REPLY:
|
2023-01-28 14:48:36 +01:00
|
|
|
param_wrapper = Service20ParamDumpWrapper(param_tm=param_packet)
|
2023-01-28 14:36:21 +01:00
|
|
|
try:
|
|
|
|
param = param_wrapper.get_param()
|
2023-01-28 14:48:36 +01:00
|
|
|
obj = obj_id_dict.get(param_wrapper.param_tm.object_id)
|
|
|
|
pw.dlog(f"Received parameter dump TM from {obj}")
|
|
|
|
pw.dlog(f"Parameter: {param}")
|
|
|
|
if param.row == 1 and param.column == 1:
|
|
|
|
try:
|
|
|
|
scalar_param = param.parse_scalar_param()
|
|
|
|
if isinstance(scalar_param, int):
|
|
|
|
pw.dlog(f"Scalar integer parameter: {scalar_param}")
|
|
|
|
elif isinstance(scalar_param, float):
|
|
|
|
pw.dlog(f"Scalar floating point parameter: {scalar_param}")
|
|
|
|
except ValueError as e:
|
|
|
|
pw.dlog("received {e} trying to parse scalar parameter")
|
|
|
|
else:
|
|
|
|
# TODO: Could improve display further by actually displaying a matrix as a
|
|
|
|
# matrix using row and column information
|
|
|
|
pw.dlog(
|
|
|
|
f"Received vector or matrix data: {param.param_data.hex(sep=',')}"
|
|
|
|
)
|
2023-01-28 14:36:21 +01:00
|
|
|
except ValueError as e:
|
|
|
|
pw.dlog(f"received {e} when trying to parse parameters")
|
|
|
|
except NotImplementedError as e:
|
|
|
|
pw.dlog(f"received {e} when trying to parse parameters")
|
|
|
|
else:
|
|
|
|
pw.dlog(f"unknown subservice {tm_packet.subservice} for parameter service")
|
2022-07-04 15:22:53 +02:00
|
|
|
elif service == 200:
|
2023-01-16 17:45:46 +01:00
|
|
|
tm_packet = Service200FsfwTm.unpack(
|
|
|
|
raw_telemetry=packet, time_reader=CdsShortTimestamp.empty()
|
|
|
|
)
|
2023-01-28 14:36:21 +01:00
|
|
|
if tm_packet.subservice == ModeSubservice.TM_CANT_REACH_MODE:
|
2022-10-11 15:08:00 +02:00
|
|
|
obj_id = tm_packet.object_id
|
|
|
|
obj_id_obj = obj_id_dict.get(obj_id)
|
|
|
|
retval = tm_packet.return_value
|
|
|
|
string_list = generic_retval_printout(retval)
|
|
|
|
pw.dlog(f"Received Mode Reply from {obj_id_obj}: Can't reach mode.")
|
|
|
|
for string in string_list:
|
|
|
|
pw.dlog(f"Reason: {string}")
|
|
|
|
dedicated_handler = True
|
|
|
|
else:
|
|
|
|
dedicated_handler = False
|
2022-07-04 15:22:53 +02:00
|
|
|
else:
|
|
|
|
LOGGER.info(f"The service {service} is not implemented in Telemetry Factory")
|
|
|
|
tm_packet.print_source_data(PrintFormats.HEX)
|
|
|
|
dedicated_handler = True
|
|
|
|
if not dedicated_handler and tm_packet is not None:
|
|
|
|
printer.handle_long_tm_print(packet_if=tm_packet, info_if=tm_packet)
|
|
|
|
raw_logger.log_tm(tm_packet)
|