eive-tmtc/pus_tm/hk_handling_hook.py

80 lines
3.3 KiB
Python
Raw Normal View History

2020-12-17 17:50:00 +01:00
"""
@brief This file transfers control of housekeeping handling (PUS service 3) to the
developer
@details Template configuration file. Copy this folder to the TMTC commander root and adapt
it to your needs.
"""
2021-02-27 13:09:55 +01:00
import struct
2020-12-17 17:50:00 +01:00
from typing import Tuple
2021-05-17 18:08:43 +02:00
from tmtccmd.pus_tm.service_3_housekeeping import Service3Base
from tmtccmd.utility.logger import get_logger
from pus_tc.syrlinks_hk_handler import SetIds
from config.object_ids import SYRLINKS_HANDLER
2020-12-17 17:50:00 +01:00
LOGGER = get_logger()
2021-05-17 18:08:43 +02:00
def handle_user_hk_packet(object_id: bytes, set_id: int, hk_data: bytearray,
2021-02-27 13:13:12 +01:00
service3_packet: Service3Base) -> Tuple[list, list, bytearray, int]:
2020-12-17 17:50:00 +01:00
"""
This function is called when a Service 3 Housekeeping packet is received.
2021-02-27 13:13:12 +01:00
Please note that the object IDs should be compared by value because direct comparison of
enumerations does not work in Python. For example use:
if object_id.value == ObjectIds.TEST_OBJECT.value
to test equality based on the object ID list.
2020-12-17 17:50:00 +01:00
@param object_id:
2021-02-27 13:13:12 +01:00
@param set_id:
2020-12-17 17:50:00 +01:00
@param hk_data:
@param service3_packet:
2021-02-27 13:13:12 +01:00
@return: Expects a tuple, consisting of two lists, a bytearray and an integer
The first list contains the header columns, the second list the list with
the corresponding values. The bytearray is the validity buffer, which is usually appended
at the end of the housekeeping packet. The last value is the number of parameters.
2020-12-17 17:50:00 +01:00
"""
2021-05-17 18:08:43 +02:00
if object_id == SYRLINKS_HANDLER:
2021-03-01 12:14:04 +01:00
if set_id == SetIds.RX_REGISTERS_DATASET:
return handle_syrlinks_rx_registers_dataset(hk_data)
elif set_id == SetIds.TX_REGISTERS_DATASET:
return handle_syrlinks_tx_registers_dataset(hk_data)
else:
LOGGER.info("Serive 3 TM: Syrlinks handler reply with unknown set id")
return [], [], bytearray(), 0
2021-02-27 13:09:55 +01:00
else:
LOGGER.info("Service 3 TM: Parsing for this SID has not been implemented.")
return [], [], bytearray(), 0
2021-02-27 13:42:41 +01:00
def handle_syrlinks_rx_registers_dataset(hk_data: bytearray) -> Tuple[list, list, bytearray, int]:
2021-02-27 13:09:55 +01:00
hk_header = []
hk_content = []
validity_buffer = bytearray()
hk_header = ["RX Status", "RX Sensitivity", "RX Frequency Shift", "RX IQ Power", "RX AGC Value", "RX Demod Eb",
"RX Demod N0", "RX Datarate"]
rx_status = hk_data[0]
rx_sensitivity = struct.unpack('!I', hk_data[1:5])
rx_frequency_shift = struct.unpack('!I', hk_data[5:9])
2021-03-01 12:14:04 +01:00
rx_iq_power = struct.unpack('!H', hk_data[9:11])
rx_agc_value = struct.unpack('!H', hk_data[11:13])
rx_demod_eb = struct.unpack('!I', hk_data[13:17])
rx_demod_n0 = struct.unpack('!I', hk_data[17:21])
rx_data_rate = hk_data[21]
2021-02-27 13:09:55 +01:00
hk_content = [rx_status, rx_sensitivity, rx_frequency_shift, rx_iq_power, rx_agc_value, rx_demod_eb, rx_demod_n0,
rx_data_rate]
return hk_header, hk_content, validity_buffer, 8
2021-03-01 12:14:04 +01:00
def handle_syrlinks_tx_registers_dataset(hk_data: bytearray) -> Tuple[list, list, bytearray, int]:
hk_header = []
hk_content = []
validity_buffer = bytearray()
hk_header = ["TX Status", "TX Waveform", "TX AGC value"]
tx_status = hk_data[0]
tx_waveform = hk_data[1]
tx_agc_value = struct.unpack('!H', hk_data[2:4])
hk_content = [tx_status, tx_waveform, tx_agc_value]
return hk_header, hk_content, validity_buffer, 3