From e27ad147d4a3e8090f5a3efa18c1abbb0912a4b3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 10 Jul 2023 18:29:24 +0200 Subject: [PATCH] done --- eive_tmtc/tmtc/tcs/defs.py | 13 ++++++++ eive_tmtc/tmtc/tcs/heater.py | 13 +------- eive_tmtc/tmtc/tcs/tm.py | 60 ++++++++++++++++++++++++++++++++++-- 3 files changed, 72 insertions(+), 14 deletions(-) diff --git a/eive_tmtc/tmtc/tcs/defs.py b/eive_tmtc/tmtc/tcs/defs.py index 8eb631a..eeaefdb 100644 --- a/eive_tmtc/tmtc/tcs/defs.py +++ b/eive_tmtc/tmtc/tcs/defs.py @@ -12,3 +12,16 @@ class CtrlSetId(enum.IntEnum): class TcsSubmode(enum.IntEnum): DEFAULT = 0 NO_HEATER_CTRL = 1 + + +class Heater(enum.IntEnum): + HEATER_0_PLOC_PROC_BRD = 0 + HEATER_1_PCDU_BRD = 1 + HEATER_2_ACS_BRD = 2 + HEATER_3_OBC_BRD = 3 + HEATER_4_CAMERA = 4 + HEATER_5_STR = 5 + HEATER_6_DRO = 6 + HEATER_7_SYRLINKS = 7 + NUMBER_OF_SWITCHES = 8 + NONE = 0xFF diff --git a/eive_tmtc/tmtc/tcs/heater.py b/eive_tmtc/tmtc/tcs/heater.py index c33ec8c..c6558c0 100644 --- a/eive_tmtc/tmtc/tcs/heater.py +++ b/eive_tmtc/tmtc/tcs/heater.py @@ -7,6 +7,7 @@ import enum from eive_tmtc.config.definitions import CustomServiceList from eive_tmtc.config.object_ids import get_object_ids +from eive_tmtc.tmtc.tcs.defs import Heater from tmtccmd.config import TmtcDefinitionWrapper, OpCodeEntry from tmtccmd.config.tmtc import tmtc_definitions_provider from tmtccmd.tc import DefaultPusQueueHelper @@ -20,18 +21,6 @@ from tmtccmd.pus.s8_fsfw_funccmd import create_action_cmd from spacepackets.ecss.tc import PusTelecommand -class Heater(enum.IntEnum): - HEATER_0_PLOC_PROC_BRD = 0 - HEATER_1_PCDU_BRD = 1 - HEATER_2_ACS_BRD = 2 - HEATER_3_OBC_BRD = 3 - HEATER_4_CAMERA = 4 - HEATER_5_STR = 5 - HEATER_6_DRO = 6 - HEATER_7_SYRLINKS = 7 - NUMBER_OF_SWITCHES = 8 - - HEATER_LOCATION = [ "PLOC Processing Board", "PCDU PDU", diff --git a/eive_tmtc/tmtc/tcs/tm.py b/eive_tmtc/tmtc/tcs/tm.py index 39553ae..985969c 100644 --- a/eive_tmtc/tmtc/tcs/tm.py +++ b/eive_tmtc/tmtc/tcs/tm.py @@ -1,8 +1,11 @@ +import dataclasses +import datetime import enum import logging import struct from eive_tmtc.pus_tm.defs import PrintWrapper +from eive_tmtc.tmtc.tcs.defs import Heater from tmtccmd.fsfw import validity_buffer_list from tmtccmd.util import ObjectIdU32 from .defs import CtrlSetId @@ -40,6 +43,17 @@ class ThermalComponent(enum.IntEnum): NUM_ENTRIES = 24 +@dataclasses.dataclass +class TcsCtrlComponentInfo: + component: ThermalComponent + # Heater on or off? + state: bool + used_sensor_idx: int + used_heater: Heater + start_time: datetime.datetime + end_time: datetime.datetime + + def handle_thermal_controller_hk_data( object_id: ObjectIdU32, pw: PrintWrapper, set_id: int, hk_data: bytes ): @@ -149,7 +163,49 @@ def handle_thermal_controller_hk_data( current_draw = struct.unpack("!H", hk_data[8:10])[0] print(f"Heater Power Channel Current Draw: {current_draw} mA") elif set_id == CtrlSetId.TCS_CTRL_INFO: - pw.dlog("Received TCS CTRL set") - pass + pw.dlog("Received TCS CTRL information set") + current_idx = 0 + heater_states = hk_data[0 : ThermalComponent.NUM_ENTRIES] + current_idx += ThermalComponent.NUM_ENTRIES + used_sensor_idx = hk_data[ + current_idx : current_idx + ThermalComponent.NUM_ENTRIES + ] + current_idx += ThermalComponent.NUM_ENTRIES + used_heater_idx = hk_data[ + current_idx : current_idx + ThermalComponent.NUM_ENTRIES + ] + current_idx += ThermalComponent.NUM_ENTRIES + start_and_end_time_fmt_str = "!IIIIIIIIIIIIIIIIIIIIIIII" + data_len = struct.calcsize(start_and_end_time_fmt_str) + start_times = struct.unpack( + start_and_end_time_fmt_str, hk_data[current_idx : current_idx + data_len] + ) + current_idx += data_len + end_times = struct.unpack( + start_and_end_time_fmt_str, hk_data[current_idx : current_idx + data_len] + ) + current_idx += data_len + component_list = [] + for i in range(ThermalComponent.NUM_ENTRIES): + info = TcsCtrlComponentInfo( + component=ThermalComponent(i), + state=bool(heater_states[i]), + used_sensor_idx=used_sensor_idx[i], + used_heater=Heater(used_heater_idx[i]), + start_time=datetime.datetime.fromtimestamp( + start_times[i], datetime.timezone.utc + ), + end_time=datetime.datetime.fromtimestamp( + end_times[i], datetime.timezone.utc + ), + ) + component_str = f"{info.component!r}".ljust(46) + state_str = "ON" if info.state else "OFF" + pw.dlog( + f"{component_str}: {state_str.ljust(4)} | Sensor Index " + f"{info.used_sensor_idx} | {info.used_heater!r} | Start " + f"{info.start_time} | End {info.end_time}" + ) + component_list.append(info) else: _LOGGER.warning(f"Unimplemented set ID {set_id}")