fsfw-example-tmtc-common/pus_tm/hk_handling.py

82 lines
2.8 KiB
Python
Raw Normal View History

2021-08-04 17:09:45 +02:00
"""This file transfers control of housekeeping handling (PUS service 3) to the developer
2021-07-14 00:28:33 +02:00
"""
import struct
from typing import Tuple
2022-05-18 23:40:13 +02:00
from tmtccmd.tm import Service3FsfwTm
from tmtccmd.tm.pus_3_hk_base import HkContentType, Service3Base
from tmtccmd.utility.obj_id import ObjectIdDictT, ObjectId
from tmtccmd.utility.tmtc_printer import FsfwTmTcPrinter
from tmtccmd.logging import get_console_logger
2021-07-14 00:28:33 +02:00
from common_tmtc.config.object_ids import TEST_DEVICE_0_ID, TEST_DEVICE_1_ID
2021-12-14 15:46:00 +01:00
2021-07-14 00:28:33 +02:00
LOGGER = get_console_logger()
2022-05-18 23:40:13 +02:00
def handle_hk_packet(
raw_tm: bytes,
obj_id_dict: ObjectIdDictT,
printer: FsfwTmTcPrinter,
):
tm_packet = Service3FsfwTm.unpack(raw_telemetry=raw_tm, custom_hk_handling=False)
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
if tm_packet.subservice == 25 or tm_packet.subservice == 26:
hk_data = tm_packet.tm_data[8:]
printer.generic_hk_tm_print(
content_type=HkContentType.HK,
object_id=named_obj_id,
set_id=tm_packet.set_id,
hk_data=hk_data,
)
handle_regular_hk_print(
printer=printer,
object_id=named_obj_id,
hk_packet=tm_packet,
hk_data=hk_data,
)
if tm_packet.subservice == 10 or tm_packet.subservice == 12:
LOGGER.warning("HK definitions printout not implemented yet")
def handle_regular_hk_print(
printer: FsfwTmTcPrinter,
object_id: ObjectId,
hk_packet: Service3Base,
hk_data: bytes,
):
2021-07-14 00:28:33 +02:00
if object_id == TEST_DEVICE_0_ID or object_id == TEST_DEVICE_1_ID:
2022-05-18 23:40:13 +02:00
handle_test_set_deserialization(hk_data=hk_data)
2021-07-14 00:28:33 +02:00
2021-12-14 15:46:00 +01:00
def handle_test_set_deserialization(
2022-05-18 23:40:13 +02:00
hk_data: bytes,
2021-12-14 15:46:00 +01:00
) -> Tuple[list, list, bytearray, int]:
2021-07-14 00:28:33 +02:00
header_list = []
content_list = []
validity_buffer = bytearray()
# uint8 (1) + uint32_t (4) + float vector with 3 entries (12) + validity buffer (1)
if len(hk_data) < 18:
LOGGER.warning("Invalid HK data format for test set reply!")
return header_list, content_list, validity_buffer, 0
2021-12-14 15:46:00 +01:00
uint8_value = struct.unpack("!B", hk_data[0:1])[0]
uint32_value = struct.unpack("!I", hk_data[1:5])[0]
float_value_1 = struct.unpack("!f", hk_data[5:9])[0]
float_value_2 = struct.unpack("!f", hk_data[9:13])[0]
float_value_3 = struct.unpack("!f", hk_data[13:17])[0]
2021-07-14 00:28:33 +02:00
validity_buffer.append(hk_data[17])
header_list.append("uint8 value")
header_list.append("uint32 value")
header_list.append("float vec value 1")
header_list.append("float vec value 2")
header_list.append("float vec value 3")
content_list.append(uint8_value)
content_list.append(uint32_value)
content_list.append(float_value_1)
content_list.append(float_value_2)
content_list.append(float_value_3)
return header_list, content_list, validity_buffer, 3