eive-tmtc/eive_tmtc/pus_tm/devs/rad_sensor.py
2022-11-29 16:53:29 +01:00

25 lines
1020 B
Python

import struct
from eive_tmtc.pus_tm.defs import PrintWrapper
from tmtccmd.util.tmtc_printer import FsfwTmTcPrinter
from eive_tmtc.pus_tc.devs.rad_sensor import SetIds
def handle_rad_sensor_data(printer: FsfwTmTcPrinter, set_id: int, hk_data: bytes):
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]
)
ain_dict = {0: ain0, 1: ain1, 4: ain4, 5: ain5, 6: ain6, 7: ain7}
pw.dlog(f"Temperature: {temp} C")
pw.dlog(f"AIN Channel | Raw Value (hex) | Raw Value (dec)")
for idx, val in ain_dict.items():
pw.dlog(f"{idx} | {val:#06x} | {str(val).ljust(5)}")
current_idx += inc_len
printer.print_validity_buffer(validity_buffer=hk_data[current_idx:], num_vars=7)