2022-04-05 17:05:11 +02:00
|
|
|
from datetime import datetime
|
2022-12-01 11:14:28 +01:00
|
|
|
|
|
|
|
from eive_tmtc.config.events import get_event_dict
|
2022-11-29 16:53:29 +01:00
|
|
|
from eive_tmtc.config.object_ids import get_object_ids
|
|
|
|
from eive_tmtc.pus_tm.defs import PrintWrapper
|
|
|
|
from eive_tmtc.pus_tm.verification_handler import generic_retval_printout
|
2023-01-16 14:13:06 +01:00
|
|
|
from eive_tmtc.tmtc.acs.acs_subsystem import AcsMode
|
2023-01-16 15:05:33 +01:00
|
|
|
from tmtccmd.tc.pus_200_fsfw_modes import Mode
|
2022-04-05 00:55:17 +02:00
|
|
|
|
2022-04-05 17:05:11 +02:00
|
|
|
from tmtccmd.tm import Service5Tm
|
2022-04-05 00:51:52 +02:00
|
|
|
from tmtccmd.logging import get_console_logger
|
2022-07-08 16:25:46 +02:00
|
|
|
from tmtccmd.util.tmtc_printer import FsfwTmTcPrinter
|
2022-12-01 11:14:28 +01:00
|
|
|
from tmtccmd.fsfw import EventInfo
|
2023-01-16 17:45:46 +01:00
|
|
|
from spacepackets.ccsds.time import CdsShortTimestamp
|
2022-03-03 19:57:22 +01:00
|
|
|
|
2022-03-04 11:56:42 +01:00
|
|
|
LOGGER = get_console_logger()
|
2022-03-04 11:02:10 +01:00
|
|
|
|
2022-03-03 19:57:22 +01:00
|
|
|
|
2022-08-22 10:47:10 +02:00
|
|
|
def handle_event_packet(raw_tm: bytes, printer: FsfwTmTcPrinter):
|
|
|
|
pw = PrintWrapper(printer)
|
2023-01-16 17:45:46 +01:00
|
|
|
tm = Service5Tm.unpack(raw_telemetry=raw_tm, time_reader=CdsShortTimestamp.empty())
|
2022-03-04 14:27:19 +01:00
|
|
|
event_dict = get_event_dict()
|
2022-04-05 17:05:11 +02:00
|
|
|
info = event_dict.get(tm.event_id)
|
2022-03-07 11:26:44 +01:00
|
|
|
if info is None:
|
2022-04-05 17:05:11 +02:00
|
|
|
LOGGER.warning(f"Event ID {tm.event_id} has no information")
|
2022-03-07 11:26:44 +01:00
|
|
|
info = EventInfo()
|
|
|
|
info.name = "Unknown event"
|
2022-03-04 14:27:19 +01:00
|
|
|
obj_ids = get_object_ids()
|
2022-04-05 17:05:11 +02:00
|
|
|
obj_id_obj = obj_ids.get(tm.reporter_id.as_bytes)
|
2022-03-04 14:27:19 +01:00
|
|
|
if obj_id_obj is None:
|
2022-07-04 15:22:53 +02:00
|
|
|
LOGGER.warning(f"Object ID 0x{tm.reporter_id.as_hex_string} has no name")
|
|
|
|
obj_name = tm.reporter_id.as_hex_string
|
2022-03-04 14:27:19 +01:00
|
|
|
else:
|
|
|
|
obj_name = obj_id_obj.name
|
2022-04-05 17:05:11 +02:00
|
|
|
generic_event_string = (
|
|
|
|
f"Object {obj_name} generated Event {tm.event_id} | {info.name}"
|
|
|
|
)
|
2022-08-22 14:02:07 +02:00
|
|
|
pw.printer.file_logger.info(
|
|
|
|
f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}: {generic_event_string}"
|
|
|
|
)
|
|
|
|
LOGGER.info(generic_event_string)
|
|
|
|
specific_handler = True
|
2022-10-11 15:38:31 +02:00
|
|
|
if info.name == "MODE_TRANSITION_FAILED":
|
|
|
|
reason = generic_retval_printout(tm.param_1)
|
|
|
|
for string in reason:
|
|
|
|
pw.dlog(f"Reason from event parameter 1: {string}")
|
2022-10-11 22:42:10 +02:00
|
|
|
pw.dlog(f"Mode, sequence or table: {tm.param_2:#08x}")
|
2022-08-22 11:47:12 +02:00
|
|
|
if info.name == "SUPV_UPDATE_PROGRESS" or info.name == "WRITE_MEMORY_FAILED":
|
2022-08-22 10:47:10 +02:00
|
|
|
additional_event_info = f"Additional info: {info.info}"
|
2022-08-22 11:47:12 +02:00
|
|
|
context = (
|
|
|
|
f"Progress Percent: {tm.param_1 >> 24 & 0xff} | Sequence Count: {tm.param_1 & 0xffff} "
|
|
|
|
f"| Bytes Written: {tm.param_2}"
|
|
|
|
)
|
2022-08-22 10:47:10 +02:00
|
|
|
pw.dlog(additional_event_info)
|
|
|
|
pw.dlog(context)
|
2022-10-10 11:20:57 +02:00
|
|
|
if info.name == "MODE_INFO":
|
2022-10-10 17:32:05 +02:00
|
|
|
mode_name = "Unknown"
|
2022-10-11 14:24:13 +02:00
|
|
|
if obj_name == "ACS_SUBSYSTEM":
|
2023-01-16 15:05:33 +01:00
|
|
|
if tm.param_1 == Mode.OFF:
|
2022-10-11 14:24:13 +02:00
|
|
|
mode_name = "Off"
|
2023-01-16 14:13:06 +01:00
|
|
|
elif tm.param_1 == AcsMode.IDLE:
|
2022-10-11 14:24:13 +02:00
|
|
|
mode_name = "Idle"
|
2023-01-16 14:13:06 +01:00
|
|
|
elif tm.param_1 == AcsMode.DETUMBLE:
|
2022-10-11 14:24:13 +02:00
|
|
|
mode_name = "Detumble"
|
2023-01-16 14:13:06 +01:00
|
|
|
elif tm.param_1 == AcsMode.SAFE:
|
2022-10-11 14:24:13 +02:00
|
|
|
mode_name = "Safe"
|
2023-01-16 14:13:06 +01:00
|
|
|
elif tm.param_1 == AcsMode.TARGET_PT:
|
2022-10-11 14:24:13 +02:00
|
|
|
mode_name = "Target Pointing"
|
|
|
|
else:
|
2023-01-16 15:05:33 +01:00
|
|
|
if tm.param_1 == Mode.OFF:
|
2022-10-11 14:24:13 +02:00
|
|
|
mode_name = "Off"
|
2023-01-16 15:05:33 +01:00
|
|
|
elif tm.param_1 == Mode.ON:
|
2022-10-11 14:24:13 +02:00
|
|
|
mode_name = "On"
|
2023-01-16 15:05:33 +01:00
|
|
|
elif tm.param_1 == Mode.NORMAL:
|
2022-10-11 14:24:13 +02:00
|
|
|
mode_name = "Normal"
|
2023-01-16 15:05:33 +01:00
|
|
|
elif tm.param_1 == Mode.RAW:
|
2022-10-11 14:24:13 +02:00
|
|
|
mode_name = "Raw"
|
|
|
|
pw.dlog(f"Mode Number {tm.param_1}, Mode Name {mode_name}")
|
|
|
|
pw.dlog(f"Submode: {tm.param_2}")
|
2022-08-22 10:42:51 +02:00
|
|
|
else:
|
2022-08-22 14:02:07 +02:00
|
|
|
specific_handler = False
|
2022-08-22 10:42:51 +02:00
|
|
|
if info.info != "":
|
|
|
|
additional_event_info = (
|
|
|
|
f"Additional info: {info.info} | P1: {tm.param_1} | P2: {tm.param_2}"
|
|
|
|
)
|
2022-08-22 10:47:10 +02:00
|
|
|
pw.dlog(additional_event_info)
|
2022-08-22 14:02:07 +02:00
|
|
|
if not specific_handler:
|
|
|
|
printer.handle_long_tm_print(packet_if=tm, info_if=tm)
|