eive-tmtc/eive_tmtc/pus_tm/devs/plpcdu.py

53 lines
1.5 KiB
Python
Raw Normal View History

2022-05-24 02:16:54 +02:00
import struct
2022-11-29 16:53:29 +01:00
from eive_tmtc.pus_tm.defs import PrintWrapper
2022-07-08 16:25:46 +02:00
from tmtccmd.util.tmtc_printer import FsfwTmTcPrinter
2023-01-16 14:13:06 +01:00
from eive_tmtc.pus_tc.devs.plpcdu import SetId
2022-05-24 02:16:54 +02:00
ADC_CHANNELS_NAMED = [
"U BAT DIV 6",
"U NEG V FB",
"I HPA",
"U HPA DIV 6",
"I MPA",
"U MPA DIV 6",
"I TX",
"U TX DIV 6",
"I X8",
"U X8 DIV 6",
"I DRO",
"U DRO DIV 6",
]
def handle_plpcdu_hk(printer: FsfwTmTcPrinter, set_id: int, hk_data: bytes):
2023-01-16 14:13:06 +01:00
if set_id == SetId.ADC:
2022-05-24 02:16:54 +02:00
pw = PrintWrapper(printer)
current_idx = 0
pw.dlog("Received PL PCDU ADC HK data")
channels = []
ch_print = "Channels Raw (hex): ["
for i in range(12):
channels.append(
struct.unpack("!H", hk_data[current_idx : current_idx + 2])[0]
)
if i < 11:
ch_print += f"{channels[i]:06x},"
else:
ch_print += f"{channels[i]:06x}]"
current_idx += 2
processed_vals = []
for i in range(12):
processed_vals.append(
struct.unpack("!f", hk_data[current_idx : current_idx + 4])[0]
)
current_idx += 4
temp = struct.unpack("!f", hk_data[current_idx : current_idx + 4])[0]
current_idx += 4
pw.dlog(f"Temperature: {temp} C")
pw.dlog(ch_print)
for i in range(12):
pw.dlog(f"{ADC_CHANNELS_NAMED[i].ljust(24)} | {processed_vals[i]}")
printer.print_validity_buffer(validity_buffer=hk_data[current_idx:], num_vars=3)