continuing printout handling refactoring

This commit is contained in:
Robin Müller 2022-04-05 17:39:51 +02:00
parent 5896ecad07
commit 2c58a77338
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
3 changed files with 51 additions and 25 deletions

View File

@ -21,6 +21,7 @@ from tmtccmd.tm.service_200_fsfw_mode import Service200FsfwTm
from tmtccmd.utility.tmtc_printer import PrintFormats, FsfwTmTcPrinter from tmtccmd.utility.tmtc_printer import PrintFormats, FsfwTmTcPrinter
from config.definitions import PUS_APID from config.definitions import PUS_APID
from config.object_ids import get_object_ids
from .event_handler import handle_event_packet from .event_handler import handle_event_packet
from .verification_handler import handle_service_1_packet from .verification_handler import handle_service_1_packet
from .hk_handling import handle_hk_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] subservice_type = raw_tm_packet[8]
tm_packet = None tm_packet = None
file_logger = FSFW_PRINTER.file_logger file_logger = FSFW_PRINTER.file_logger
obj_id_dict = get_object_ids()
try: try:
if service_type == 1: if service_type == 1:
handle_service_1_packet(printer=FSFW_PRINTER, raw_tm=raw_tm_packet) 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( tm_packet = Service3FsfwTm.unpack(
raw_telemetry=raw_tm_packet, custom_hk_handling=False 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: elif service_type == 5:
tm_packet = Service5Tm.unpack(raw_telemetry=raw_tm_packet) tm_packet = Service5Tm.unpack(raw_telemetry=raw_tm_packet)
handle_event_packet(file_logger=file_logger, tm=tm_packet) handle_event_packet(file_logger=file_logger, tm=tm_packet)

View File

@ -3,9 +3,10 @@ import struct
import os import os
import datetime import datetime
from tmtccmd.utility.tmtc_printer import FsfwTmTcPrinter
from tmtccmd.config.definitions import HkReplyUnpacked from tmtccmd.config.definitions import HkReplyUnpacked
from tmtccmd.tm.base import PusTmInterface 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 tmtccmd.logging import get_console_logger
from pus_tc.devs.bpx_batt import BpxSetIds from pus_tc.devs.bpx_batt import BpxSetIds
from pus_tc.devs.syrlinks_hk_handler import SetIds from pus_tc.devs.syrlinks_hk_handler import SetIds
@ -24,19 +25,32 @@ from config.object_ids import (
LOGGER = get_console_logger() 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: 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( handle_regular_hk_print(
object_id=hk_packet.object_id, printer=printer,
object_id=object_id,
hk_packet=hk_packet, 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: if packet_if.subservice == 10 or packet_if.subservice == 12:
LOGGER.warning("HK definitions printout not implemented yet") LOGGER.warning("HK definitions printout not implemented yet")
def handle_regular_hk_print( 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 object_id = object_id.as_bytes
set_id = hk_packet.set_id set_id = hk_packet.set_id
@ -62,7 +76,7 @@ def handle_regular_hk_print(
elif object_id == CORE_CONTROLLER_ID: elif object_id == CORE_CONTROLLER_ID:
return handle_core_hk_data(hk_data=hk_data, set_id=set_id) return handle_core_hk_data(hk_data=hk_data, set_id=set_id)
elif object_id == P60_DOCK_HANDLER: 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: else:
LOGGER.info("Service 3 TM: Parsing for this SID has not been implemented.") LOGGER.info("Service 3 TM: Parsing for this SID has not been implemented.")
return HkReplyUnpacked() 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() reply = HkReplyUnpacked()
current_idx = 0 current_idx = 0
current_list = []
for idx in range(0, 13): for idx in range(0, 13):
if idx == 0: current_list.append(
reply.header_list.append(f"I [mA] {P60_INDEX_LIST[idx]}") struct.unpack('!h', hk_data[current_idx : current_idx + 2])[0]
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_idx += 2 current_idx += 2
for idx in range(0, 13): voltage_list = []
if idx == 0: for idx in range(13):
reply.header_list.append(f"U [mV] {P60_INDEX_LIST[idx]}") voltage_list.append(
else:
reply.header_list.append(f"U {P60_INDEX_LIST[idx]}")
reply.content_list.append(
struct.unpack("!H", hk_data[current_idx : current_idx + 2])[0] struct.unpack("!H", hk_data[current_idx : current_idx + 2])[0]
) )
current_idx += 2 current_idx += 2
for idx in range(0, 13): out_enb_list = []
reply.header_list.append(f"OutEnb {P60_INDEX_LIST[idx]}") for idx in range(13):
reply.content_list.append(hk_data[current_idx]) out_enb_list.append(hk_data[current_idx])
current_idx += 1 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.header_list.append("Temp 0 [C]")
reply.content_list.append( reply.content_list.append(
struct.unpack("!h", hk_data[current_idx : current_idx + 2])[0] struct.unpack("!h", hk_data[current_idx : current_idx + 2])[0]

@ -1 +1 @@
Subproject commit 36f3453c274a5cdc4505b4e8cc22cd2827b7fc16 Subproject commit dfeaec0f452c32f2e3fa7eadaf91e3297fb8124e