From 2c58a77338d76530989b80e6f5a8aebe5306ec8e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 5 Apr 2022 17:39:51 +0200 Subject: [PATCH] continuing printout handling refactoring --- pus_tm/factory_hook.py | 12 +++++++- pus_tm/hk_handling.py | 62 ++++++++++++++++++++++++++---------------- tmtccmd | 2 +- 3 files changed, 51 insertions(+), 25 deletions(-) diff --git a/pus_tm/factory_hook.py b/pus_tm/factory_hook.py index fd80f2f..5899960 100644 --- a/pus_tm/factory_hook.py +++ b/pus_tm/factory_hook.py @@ -21,6 +21,7 @@ from tmtccmd.tm.service_200_fsfw_mode import Service200FsfwTm from tmtccmd.utility.tmtc_printer import PrintFormats, FsfwTmTcPrinter from config.definitions import PUS_APID +from config.object_ids import get_object_ids from .event_handler import handle_event_packet from .verification_handler import handle_service_1_packet from .hk_handling import handle_hk_packet @@ -44,6 +45,7 @@ def pus_factory_hook(raw_tm_packet: bytes): subservice_type = raw_tm_packet[8] tm_packet = None file_logger = FSFW_PRINTER.file_logger + obj_id_dict = get_object_ids() try: if service_type == 1: handle_service_1_packet(printer=FSFW_PRINTER, raw_tm=raw_tm_packet) @@ -51,7 +53,15 @@ def pus_factory_hook(raw_tm_packet: bytes): tm_packet = Service3FsfwTm.unpack( raw_telemetry=raw_tm_packet, custom_hk_handling=False ) - handle_hk_packet(hk_packet=tm_packet, packet_if=tm_packet) + named_obj_id = obj_id_dict.get(tm_packet.object_id.as_bytes) + if named_obj_id is None: + named_obj_id = tm_packet.object_id + handle_hk_packet( + printer=FSFW_PRINTER, + object_id=named_obj_id, + hk_packet=tm_packet, + packet_if=tm_packet + ) elif service_type == 5: tm_packet = Service5Tm.unpack(raw_telemetry=raw_tm_packet) handle_event_packet(file_logger=file_logger, tm=tm_packet) diff --git a/pus_tm/hk_handling.py b/pus_tm/hk_handling.py index d7c2659..36beb45 100644 --- a/pus_tm/hk_handling.py +++ b/pus_tm/hk_handling.py @@ -3,9 +3,10 @@ import struct import os import datetime +from tmtccmd.utility.tmtc_printer import FsfwTmTcPrinter from tmtccmd.config.definitions import HkReplyUnpacked from tmtccmd.tm.base import PusTmInterface -from tmtccmd.tm.service_3_fsfw_housekeeping import Service3Base +from tmtccmd.tm.service_3_fsfw_housekeeping import Service3Base, HkContentType from tmtccmd.logging import get_console_logger from pus_tc.devs.bpx_batt import BpxSetIds from pus_tc.devs.syrlinks_hk_handler import SetIds @@ -24,19 +25,32 @@ from config.object_ids import ( LOGGER = get_console_logger() -def handle_hk_packet(hk_packet: Service3Base, packet_if: PusTmInterface): +def handle_hk_packet( + printer: FsfwTmTcPrinter, + object_id: ObjectId, + hk_packet: Service3Base, + packet_if: PusTmInterface +): if packet_if.subservice == 25 or packet_if.subservice == 26: + hk_data = packet_if.tm_data[8:] + printer.generic_hk_print( + content_type=HkContentType.HK, + object_id=object_id, + set_id=hk_packet.set_id, + hk_data=hk_data + ) handle_regular_hk_print( - object_id=hk_packet.object_id, + printer=printer, + object_id=object_id, hk_packet=hk_packet, - hk_data=packet_if.tm_data[8:], + hk_data=hk_data, ) if packet_if.subservice == 10 or packet_if.subservice == 12: LOGGER.warning("HK definitions printout not implemented yet") def handle_regular_hk_print( - object_id: ObjectId, hk_packet: Service3Base, hk_data: bytes + printer: FsfwTmTcPrinter, object_id: ObjectId, hk_packet: Service3Base, hk_data: bytes ): object_id = object_id.as_bytes set_id = hk_packet.set_id @@ -62,7 +76,7 @@ def handle_regular_hk_print( elif object_id == CORE_CONTROLLER_ID: return handle_core_hk_data(hk_data=hk_data, set_id=set_id) elif object_id == P60_DOCK_HANDLER: - return handle_p60_hk_data(hk_data=hk_data) + return handle_p60_hk_data(printer=printer, hk_data=hk_data) else: LOGGER.info("Service 3 TM: Parsing for this SID has not been implemented.") return HkReplyUnpacked() @@ -392,32 +406,34 @@ P60_INDEX_LIST = [ ] -def handle_p60_hk_data(hk_data: bytes) -> HkReplyUnpacked: +def handle_p60_hk_data(printer: FsfwTmTcPrinter, hk_data: bytes) -> HkReplyUnpacked: reply = HkReplyUnpacked() current_idx = 0 + current_list = [] for idx in range(0, 13): - if idx == 0: - reply.header_list.append(f"I [mA] {P60_INDEX_LIST[idx]}") - - else: - reply.header_list.append(f"I {P60_INDEX_LIST[idx]}") - reply.content_list.append( - struct.unpack("!h", hk_data[current_idx : current_idx + 2])[0] + current_list.append( + struct.unpack('!h', hk_data[current_idx : current_idx + 2])[0] ) current_idx += 2 - for idx in range(0, 13): - if idx == 0: - reply.header_list.append(f"U [mV] {P60_INDEX_LIST[idx]}") - else: - reply.header_list.append(f"U {P60_INDEX_LIST[idx]}") - reply.content_list.append( + voltage_list = [] + for idx in range(13): + voltage_list.append( struct.unpack("!H", hk_data[current_idx : current_idx + 2])[0] ) current_idx += 2 - for idx in range(0, 13): - reply.header_list.append(f"OutEnb {P60_INDEX_LIST[idx]}") - reply.content_list.append(hk_data[current_idx]) + out_enb_list = [] + for idx in range(13): + out_enb_list.append(hk_data[current_idx]) current_idx += 1 + header_str = f"{'Name'.ljust(24)} | OutEnb | U [mV] | I [mA]" + print(header_str) + printer.file_logger.info(header_str) + for idx in range(13): + out_enb = f"{out_enb_list[idx]}".ljust(6) + content_line = f"{P60_INDEX_LIST[idx].ljust(24)} | {out_enb} | " \ + f"{voltage_list[idx]:05} | {current_list[idx]:04}" + print(content_line) + printer.file_logger.info(content_line) reply.header_list.append("Temp 0 [C]") reply.content_list.append( struct.unpack("!h", hk_data[current_idx : current_idx + 2])[0] diff --git a/tmtccmd b/tmtccmd index 36f3453..dfeaec0 160000 --- a/tmtccmd +++ b/tmtccmd @@ -1 +1 @@ -Subproject commit 36f3453c274a5cdc4505b4e8cc22cd2827b7fc16 +Subproject commit dfeaec0f452c32f2e3fa7eadaf91e3297fb8124e