eive-tmtc/eive_tmtc/tmtc/tcs/rtd.py

187 lines
5.6 KiB
Python
Raw Normal View History

2023-03-13 10:31:27 +01:00
import enum
2022-05-23 17:50:08 +02:00
from typing import Optional
2023-01-19 13:21:12 +01:00
import struct
2022-05-23 17:50:08 +02:00
2022-11-29 16:53:29 +01:00
from eive_tmtc.config.definitions import CustomServiceList
2023-03-14 10:11:01 +01:00
from eive_tmtc.pus_tm.defs import PrintWrapper
2022-05-23 17:50:08 +02:00
from spacepackets.ecss import PusTelecommand
2023-11-28 17:41:46 +01:00
from tmtccmd.config import CmdTreeNode, TmtcDefinitionWrapper, OpCodeEntry
from tmtccmd.config.tmtc import tmtc_definitions_provider
2022-07-04 15:22:53 +02:00
2023-11-10 19:23:06 +01:00
from tmtccmd.tmtc import DefaultPusQueueHelper
2022-07-08 16:25:46 +02:00
from tmtccmd.util import ObjectIdU32
2023-11-10 19:23:06 +01:00
from tmtccmd.pus.s200_fsfw_mode import Mode, pack_mode_data, Subservice
2022-11-29 16:53:29 +01:00
import eive_tmtc.config.object_ids as oids
from eive_tmtc.config.object_ids import get_object_ids
2024-05-08 10:49:20 +02:00
from tmtccmd.fsfw.tmtc_printer import get_validity_buffer_str
2022-05-23 17:50:08 +02:00
RTD_IDS = [
oids.RTD_0_PLOC_HSPD,
oids.RTD_1_PLOC_MISSIONBRD,
oids.RTD_2_4K_CAM,
oids.RTD_3_DAC_HSPD,
oids.RTD_4_STR,
oids.RTD_5_RW1_MX_MY,
oids.RTD_6_DRO,
oids.RTD_7_SCEX,
oids.RTD_8_X8,
oids.RTD_9_HPA,
oids.RTD_10_PL_TX,
oids.RTD_11_MPA,
oids.RTD_12_ACU,
oids.RTD_13_PLPCDU_HSPD,
oids.RTD_14_TCS_BRD,
2022-05-23 18:34:28 +02:00
oids.RTD_15_IMTQ,
2022-05-23 17:50:08 +02:00
]
2023-03-14 10:11:01 +01:00
RTD_NAMES = {
oids.RTD_0_PLOC_HSPD: "RTD 0 PLOC Heatspreader",
oids.RTD_1_PLOC_MISSIONBRD: "RTD 1 PLOC Missionboard",
oids.RTD_2_4K_CAM: "RTD 2 4K Camera",
oids.RTD_3_DAC_HSPD: "RTD 3 DAC HSPC",
oids.RTD_4_STR: "RTD 4 Startracker",
oids.RTD_5_RW1_MX_MY: "RTD 5 RW1 MX MY",
oids.RTD_6_DRO: "RTD 6 DRO",
oids.RTD_7_SCEX: "RTD 7 SCEX",
oids.RTD_8_X8: "RTD 8 X8",
oids.RTD_9_HPA: "RTD 9 HPA",
oids.RTD_10_PL_TX: "RTD 10 PL TX",
oids.RTD_11_MPA: "RTD 11 MPA",
oids.RTD_12_ACU: "RTD 12 ACU",
oids.RTD_13_PLPCDU_HSPD: "RTD 13 PL PCDU Heatspreader",
oids.RTD_14_TCS_BRD: "RTD 14 TCS Board",
oids.RTD_15_IMTQ: "RTD 15 iMTQ",
}
2022-05-23 17:50:08 +02:00
2023-01-19 13:21:12 +01:00
class CommandId:
WRITE_CONFIG = 6
2023-03-13 10:35:33 +01:00
class RtdId(enum.IntEnum):
RTD_0_PLOC_HSPC = 0
RTD_1_PLOC_MISSIONBRD = 1
RTD_2_4K_CAM = 2
RTD_3_DAC_HSPD = 3
RTD_4_STR = 4
RTD_5_RW1_MX_MY = 5
RTD_6_DRO = 6
RTD_7_SCEX = 7
RTD_8_X8 = 8
RTD_9_HPA = 9
RTD_10_PL_TX = 10
RTD_11_MPA = 11
RTD_12_ACU = 12
RTD_13_PLPCDU_HSPD = 13
RTD_14_TCS_BRD = 14
RTD_15_IMTQ = 15
2023-03-13 10:31:27 +01:00
class SetId(enum.IntEnum):
TEMPERATURE = 1
2023-11-22 10:17:05 +01:00
class CmdStr:
ON = "on"
OFF = "off"
NORMAL = "normal"
WRITE_CONFIG = "write_cfg"
2022-05-23 17:50:08 +02:00
2023-11-22 10:17:05 +01:00
class CmdInfo:
2022-05-23 17:50:08 +02:00
ON = "Switch handler on"
OFF = "Switch handler off"
NORMAL = "Switch handler normal"
2023-01-19 13:21:12 +01:00
WRITE_CONFIG = "Write config"
2022-05-23 17:50:08 +02:00
2023-11-28 17:41:46 +01:00
def create_rtd_node() -> CmdTreeNode:
node = CmdTreeNode("rtd", "RTD commands", hide_children_which_are_leaves=True)
node.add_child(CmdTreeNode(CmdStr.ON, CmdInfo.ON))
node.add_child(CmdTreeNode(CmdStr.NORMAL, CmdInfo.NORMAL))
node.add_child(CmdTreeNode(CmdStr.OFF, CmdInfo.OFF))
node.add_child(CmdTreeNode(CmdStr.WRITE_CONFIG, CmdInfo.WRITE_CONFIG))
return node
@tmtc_definitions_provider
def specify_rtd_cmds(defs: TmtcDefinitionWrapper):
2022-07-05 02:12:54 +02:00
oce = OpCodeEntry()
2023-11-22 10:17:05 +01:00
oce.add(keys=CmdStr.ON, info=CmdInfo.ON)
oce.add(keys=CmdStr.NORMAL, info=CmdInfo.NORMAL)
oce.add(keys=CmdStr.OFF, info=CmdInfo.OFF)
oce.add(keys=CmdStr.WRITE_CONFIG, info=CmdInfo.WRITE_CONFIG)
2022-07-05 02:12:54 +02:00
defs.add_service(
name=CustomServiceList.RTD.value, info="RTD commands", op_code_entry=oce
2022-05-23 17:50:08 +02:00
)
2022-08-08 16:32:18 +02:00
def pack_rtd_commands(
2023-11-22 10:17:05 +01:00
cmd_str: str, object_id: Optional[ObjectIdU32], q: DefaultPusQueueHelper
2022-08-08 16:32:18 +02:00
):
2022-05-23 17:50:08 +02:00
if object_id is not None and object_id not in RTD_IDS:
print("Specified object ID not a valid RTD ID")
object_id = None
if object_id is None:
tgt_rtd_idx = prompt_rtd_idx()
object_id_dict = get_object_ids()
object_id = object_id_dict.get(RTD_IDS[tgt_rtd_idx])
2023-11-22 10:17:05 +01:00
if cmd_str == CmdStr.ON:
2023-01-16 15:05:33 +01:00
app_data = pack_mode_data(object_id=object_id.as_bytes, mode=Mode.ON, submode=0)
2022-07-04 15:22:53 +02:00
q.add_pus_tc(
PusTelecommand(
2023-01-17 18:37:16 +01:00
service=200, subservice=Subservice.TC_MODE_COMMAND, app_data=app_data
2022-07-04 15:22:53 +02:00
)
2022-05-23 17:50:08 +02:00
)
2023-11-22 10:17:05 +01:00
if cmd_str == CmdStr.NORMAL:
2022-05-23 18:34:28 +02:00
app_data = pack_mode_data(
2023-01-16 15:05:33 +01:00
object_id=object_id.as_bytes, mode=Mode.NORMAL, submode=0
2022-05-23 18:34:28 +02:00
)
2022-07-04 15:22:53 +02:00
q.add_pus_tc(
PusTelecommand(
2023-01-17 18:37:16 +01:00
service=200, subservice=Subservice.TC_MODE_COMMAND, app_data=app_data
2022-07-04 15:22:53 +02:00
)
2022-05-23 17:50:08 +02:00
)
2023-11-22 10:17:05 +01:00
if cmd_str == CmdStr.OFF:
2022-05-23 18:34:28 +02:00
app_data = pack_mode_data(
2023-01-16 15:05:33 +01:00
object_id=object_id.as_bytes, mode=Mode.OFF, submode=0
2022-05-23 18:34:28 +02:00
)
2022-07-04 15:22:53 +02:00
q.add_pus_tc(
PusTelecommand(
2023-01-17 18:37:16 +01:00
service=200, subservice=Subservice.TC_MODE_COMMAND, app_data=app_data
2022-07-04 15:22:53 +02:00
)
2022-05-23 17:50:08 +02:00
)
2023-11-22 10:17:05 +01:00
if cmd_str in CmdStr.WRITE_CONFIG:
2023-01-20 10:35:30 +01:00
command = object_id.as_bytes + struct.pack("!I", CommandId.WRITE_CONFIG)
2022-07-04 15:22:53 +02:00
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2022-05-23 17:50:08 +02:00
2023-05-24 13:44:45 +02:00
def handle_rtd_hk(object_id: bytes, hk_data: bytes, pw: PrintWrapper):
2023-03-14 10:11:01 +01:00
rtd_name = RTD_NAMES.get(object_id)
if rtd_name is None:
rtd_name = "unknown RTD device"
pw.dlog(f"Received RTD HK for RTD {rtd_name} with object ID {object_id}")
fmt_str = "!ffBB"
fmt_len = struct.calcsize(fmt_str)
(rtd_val, temp_celcius, last_err_byte, error_byte) = struct.unpack(
fmt_str, hk_data[0 : 0 + fmt_len]
)
pw.dlog(f"Temperature Celcius: {temp_celcius}")
pw.dlog(f"RTD Value: {rtd_val}")
pw.dlog(f"Error Byte: {error_byte}")
pw.dlog(f"Last Error Byte: {last_err_byte}")
2024-05-08 10:49:20 +02:00
pw.dlog(get_validity_buffer_str(hk_data[fmt_len:], 4))
2023-03-14 10:11:01 +01:00
2022-05-23 17:50:08 +02:00
def prompt_rtd_idx():
while True:
rtd_idx = input("Please specify RTD index [0-15]: ")
if not rtd_idx.isdigit():
print("Invalid input")
continue
rtd_idx = int(rtd_idx)
if rtd_idx < 0 or rtd_idx > 15:
print("Invalid device index")
continue
return rtd_idx