diff --git a/gomspace/gomspace_common.py b/gomspace/gomspace_common.py index e7fa956..c8741c1 100644 --- a/gomspace/gomspace_common.py +++ b/gomspace/gomspace_common.py @@ -37,11 +37,13 @@ class Info: class SetIds: - PDU_1 = 1 - PDU_2 = 2 - P60_CORE = 3 - P60_AUX = 4 - ACU = 5 + PDU_1_CORE = 1 + PDU_1_AUX = 2 + PDU_2_CORE = 3 + PDU_2_AUX = 4 + P60_CORE = 5 + P60_AUX = 6 + ACU = 7 class TableIds: diff --git a/pus_tm/hk_handling.py b/pus_tm/hk_handling.py index 991972c..5d59eda 100644 --- a/pus_tm/hk_handling.py +++ b/pus_tm/hk_handling.py @@ -425,10 +425,79 @@ P60_INDEX_LIST = [ WDT_LIST = ["GND", "I2C", "CAN", "CSP0", "CSP1"] +PDU1_CHANNELS_NAMES = [ + "TCS Board", + "Syrlinks", + "Startracker", + "MGT", + "SUS Nominal", + "SCEX", + "PLOC", + "ACS A Side", + "Unused Channel 8" +] + +PDU2_CHANNELS_NAMES = [ + "Q7S", + "Payload PCDU CH1", + "RW", + "TCS Heater In", + "SUS Redundant", + "Deployment Mechanism", + "Payload PCDU CH6", + "ACS B Side", + "Payload Camera" +] + +PDU_CHANNEL_NAMES = [ + PDU1_CHANNELS_NAMES, + PDU2_CHANNELS_NAMES +] + + +def handle_pdu_data(printer: FsfwTmTcPrinter, pdu_idx: int, set_id: int, hk_data: bytes): + if set_id == SetIds.PDU_1_AUX or set_id == SetIds.PDU_2_AUX: + log_to_both(printer, "PDU AUX HK TODO") + if set_id == SetIds.PDU_1_CORE or set_id == SetIds.PDU_2_CORE: + log_to_both(printer, f"Received PDU HK from PDU {pdu_idx}") + current_list = [] + current_idx = 0 + priv_idx = pdu_idx - 1 + for idx in range(len(PDU1_CHANNELS_NAMES)): + current_list.append( + struct.unpack("!h", hk_data[current_idx: current_idx + 2])[0] + ) + current_idx += 2 + voltage_list = [] + for idx in range(len(PDU1_CHANNELS_NAMES)): + voltage_list.append( + struct.unpack("!H", hk_data[current_idx: current_idx + 2])[0] + ) + current_idx += 2 + output_enb_list = [] + for idx in range(len(PDU1_CHANNELS_NAMES)): + output_enb_list.append(hk_data[current_idx]) + current_idx += 1 + header_str = f"{'Name'.ljust(24)} | OutEnb | U [mV] | I [mA]" + print(header_str) + printer.file_logger.info(header_str) + for idx in range(len(PDU1_CHANNELS_NAMES)): + out_enb = f"{output_enb_list[idx]}".ljust(6) + content_line = ( + f"{PDU_CHANNEL_NAMES[priv_idx][idx].ljust(24)} | {out_enb} | " + f"{voltage_list[idx]:05} | {current_list[idx]:04}" + ) + log_to_both(printer, content_line) + fmt_str = "!IBh" + inc_len = struct.calcsize(fmt_str) + ( + boot_count, + batt_mode, + temperature + ) = struct.unpack(fmt_str, hk_data[current_idx: current_idx + inc_len]) + info = f"Boot Count {boot_count} | Battery Mode {batt_mode} | Temperature {temperature}" + log_to_both(printer, info) -def handle_pdu_data(printer: FsfwTmTcPrinter, pdu_idx: int, hk_data: bytes): - log_to_both(printer, f"Received PDU HK from PDU {pdu_idx}") - def handle_p60_hk_data(printer: FsfwTmTcPrinter, set_id: int, hk_data: bytes): if set_id == SetIds.P60_CORE: