eive-tmtc/pus_tm/devs/rad_sensor.py

25 lines
1003 B
Python
Raw Normal View History

2022-05-23 15:49:21 +02:00
import struct
from pus_tm.defs import PrintWrapper
2022-05-23 15:38:05 +02:00
from tmtccmd.utility.tmtc_printer import FsfwTmTcPrinter
2022-05-23 15:49:21 +02:00
from pus_tc.devs.rad_sensor import SetIds
2022-05-23 15:38:05 +02:00
def handle_rad_sensor_data(printer: FsfwTmTcPrinter, set_id: int, hk_data: bytes):
2022-05-23 15:49:21 +02:00
if set_id == SetIds.HK:
pw = PrintWrapper(printer)
current_idx = 0
pw.dlog("Received Radiation Sensor HK data")
fmt_str = "!fHHHHHH"
inc_len = struct.calcsize(fmt_str)
(temp, ain0, ain1, ain4, ain5, ain6, ain7) = struct.unpack(
fmt_str, hk_data[current_idx : current_idx + inc_len]
)
2022-05-23 18:25:25 +02:00
ain_dict = {0: ain0, 1: ain1, 4: ain4, 5: ain5, 6: ain6, 7: ain7}
2022-05-23 15:49:21 +02:00
pw.dlog(f"Temperature: {temp} C")
pw.dlog(f"AIN Channel | Raw Value (hex) | Raw Value (dec)")
2022-05-23 18:25:25 +02:00
for idx, val in ain_dict.items():
pw.dlog(f"{idx} | {val:#06x} | {str(val).ljust(5)}")
2022-05-23 15:49:21 +02:00
current_idx += inc_len
printer.print_validity_buffer(validity_buffer=hk_data[current_idx:], num_vars=7)