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

219 lines
6.6 KiB
Python
Raw Normal View History

2021-02-06 16:35:53 +01:00
# -*- coding: utf-8 -*-
2022-05-03 19:01:38 +02:00
"""Command sequence to test the HeaterHandler
2021-02-06 16:35:53 +01:00
@author J. Meier
@date 30.01.2021
"""
2022-05-03 19:01:38 +02:00
import enum
2023-11-28 17:24:25 +01:00
from spacepackets.ecss.tc import PusTelecommand
from tmtccmd.config import CmdTreeNode, OpCodeEntry, TmtcDefinitionWrapper
from tmtccmd.config.tmtc import tmtc_definitions_provider
2023-11-28 17:24:25 +01:00
from tmtccmd.pus.s8_fsfw_action import create_action_cmd
from tmtccmd.pus.s201_fsfw_health import (
FsfwHealth,
2023-01-17 18:37:16 +01:00
Subservice,
2023-11-28 17:24:25 +01:00
pack_set_health_cmd_data,
)
2023-11-28 17:24:25 +01:00
from tmtccmd.tmtc import DefaultPusQueueHelper
from tmtccmd.util.obj_id import ObjectIdU32
2021-02-06 16:35:53 +01:00
2023-11-28 17:24:25 +01:00
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
2021-02-06 16:35:53 +01:00
2023-02-21 02:28:32 +01:00
HEATER_LOCATION = [
"PLOC Processing Board",
"PCDU PDU",
"ACS Board",
"OBC Board",
2023-02-21 02:28:32 +01:00
"Camera",
"Startracker",
"DRO",
"Syrlinks",
2023-02-21 02:28:32 +01:00
]
2023-01-16 14:13:06 +01:00
class OpCode:
2023-11-28 17:24:25 +01:00
HEATER_CMD = "switch_cmd"
HEATER_EXT_CTRL = "set_ext_ctrl"
HEATER_FAULTY_CMD = "set_faulty"
HEATER_HEALTHY_CMD = "set_healthy"
2022-05-03 19:01:38 +02:00
class Info:
HEATER_CMD = "Heater Switch Command"
2022-05-05 14:30:28 +02:00
HEATER_EXT_CTRL = "Set to external control"
HEATER_FAULTY_CMD = "Set to faulty"
HEATER_HEALTHY_CMD = "Set to healthy"
2022-05-03 19:01:38 +02:00
# Needed in OBSW to differentiate between external and internal heater commands
COMMAND_SOURCE_PARAM_EXTERNAL = 1
2022-05-03 19:01:38 +02:00
class ActionIds(enum.IntEnum):
SWITCH_HEATER = 0
2021-02-06 16:35:53 +01:00
2023-11-28 17:24:25 +01:00
CTN = CmdTreeNode
def create_heater_node() -> CmdTreeNode:
node = CmdTreeNode("heater", "Heater Device", hide_children_which_are_leaves=True)
node.add_child(CTN(OpCode.HEATER_CMD, Info.HEATER_CMD))
node.add_child(CTN(OpCode.HEATER_HEALTHY_CMD, Info.HEATER_HEALTHY_CMD))
node.add_child(CTN(OpCode.HEATER_EXT_CTRL, Info.HEATER_EXT_CTRL))
node.add_child(CTN(OpCode.HEATER_FAULTY_CMD, Info.HEATER_FAULTY_CMD))
return node
@tmtc_definitions_provider
def add_heater_cmds(defs: TmtcDefinitionWrapper):
2022-07-05 02:12:54 +02:00
oce = OpCodeEntry()
2023-01-16 14:13:06 +01:00
oce.add(keys=OpCode.HEATER_CMD, info=Info.HEATER_CMD)
oce.add(keys=OpCode.HEATER_HEALTHY_CMD, info=Info.HEATER_HEALTHY_CMD)
oce.add(keys=OpCode.HEATER_EXT_CTRL, info=Info.HEATER_EXT_CTRL)
oce.add(keys=OpCode.HEATER_FAULTY_CMD, info=Info.HEATER_FAULTY_CMD)
2022-07-05 02:12:54 +02:00
defs.add_service(
2022-05-03 19:01:38 +02:00
name=CustomServiceList.HEATER.value,
info="Heater Device",
2022-07-05 02:12:54 +02:00
op_code_entry=oce,
2022-05-03 19:01:38 +02:00
)
2021-02-06 16:35:53 +01:00
2023-11-22 10:17:05 +01:00
def pack_heater_cmds(object_id: bytes, cmd_str: str, q: DefaultPusQueueHelper):
2023-11-28 17:24:25 +01:00
if cmd_str == OpCode.HEATER_CMD:
2022-07-04 15:22:53 +02:00
q.add_log_cmd("Heater Switching")
2022-05-05 14:30:28 +02:00
heater_number = prompt_heater()
2022-05-04 08:48:43 +02:00
while True:
action = input("Turn switch on or off? (0 - off, 1 - on): ")
if not action.isdigit():
print("Switch action not valid")
continue
action = int(action)
if action != 0 and action != 1:
print("Invalid action defined. Must be 0 (off) or 1 (on")
continue
break
if action == 1:
act_str = "on"
else:
act_str = "off"
debug_string = f"Switching heater {heater_number} {act_str}"
2022-07-04 15:22:53 +02:00
q.add_log_cmd(debug_string)
q.add_pus_tc(pack_switch_heater_command(object_id, heater_number, action))
2023-11-28 17:24:25 +01:00
if cmd_str == OpCode.HEATER_EXT_CTRL:
2022-05-05 14:30:28 +02:00
heater_number = prompt_heater()
obj_id = heater_idx_to_obj(heater_number)
health_cmd(
2022-07-04 15:22:53 +02:00
q=q,
2022-05-05 14:30:28 +02:00
object_id=obj_id,
health=FsfwHealth.EXTERNAL_CTRL,
health_str="External Control",
heater_idx=heater_number,
)
2023-11-28 17:24:25 +01:00
if cmd_str == OpCode.HEATER_FAULTY_CMD:
2022-05-05 14:30:28 +02:00
heater_number = prompt_heater()
obj_id = heater_idx_to_obj(heater_number)
health_cmd(
2022-07-04 15:22:53 +02:00
q=q,
2022-05-05 14:30:28 +02:00
object_id=obj_id,
health=FsfwHealth.FAULTY,
health_str="Faulty",
heater_idx=heater_number,
)
2023-11-28 17:24:25 +01:00
if cmd_str == OpCode.HEATER_HEALTHY_CMD:
2022-05-05 14:30:28 +02:00
heater_number = prompt_heater()
obj_id = heater_idx_to_obj(heater_number)
health_cmd(
2022-07-04 15:22:53 +02:00
q=q,
2022-05-05 14:30:28 +02:00
object_id=obj_id,
health=FsfwHealth.HEALTHY,
health_str="Healthy",
heater_idx=heater_number,
)
2022-07-05 02:12:54 +02:00
def heater_idx_to_obj(heater: int) -> ObjectIdU32:
2022-11-29 16:53:29 +01:00
from eive_tmtc.config.object_ids import (
HEATER_0_PLOC_PROC_BRD,
HEATER_1_PCDU_BRD,
2022-05-05 14:30:28 +02:00
HEATER_2_ACS_BRD,
HEATER_3_OBC_BRD,
2022-05-05 14:30:28 +02:00
HEATER_4_CAMERA,
HEATER_5_STR,
HEATER_6_DRO,
HEATER_7_SYRLINKS,
2022-05-05 14:30:28 +02:00
)
obj_id_array = [
HEATER_0_PLOC_PROC_BRD,
HEATER_1_PCDU_BRD,
2022-05-05 14:30:28 +02:00
HEATER_2_ACS_BRD,
HEATER_3_OBC_BRD,
2022-05-05 14:30:28 +02:00
HEATER_4_CAMERA,
HEATER_5_STR,
HEATER_6_DRO,
HEATER_7_SYRLINKS,
2022-05-05 14:30:28 +02:00
]
obj_dict = get_object_ids()
obj_id_obj = obj_dict.get(obj_id_array[heater])
if obj_id_obj is None:
2022-07-05 02:12:54 +02:00
return ObjectIdU32.from_bytes(obj_id_array[heater])
2022-05-05 14:30:28 +02:00
return obj_id_obj
def prompt_heater() -> int:
while True:
2022-05-09 16:12:58 +02:00
print("HEATER 0 | PLOC PROC Board")
print("HEATER 1 | PCDU Board")
print("HEATER 2 | ACS Board")
print("HEATER 3 | OBC Board")
print("HEATER 4 | CAMERA")
print("HEATER 5 | STR")
print("HEATER 6 | DRO")
2023-03-11 15:15:00 +01:00
print("HEATER 7 | Syrlinks")
2022-05-05 14:30:28 +02:00
heater_number = input("Type number of heater to switch [0-7]: ")
if not heater_number.isdigit():
print("Heater number not a digit")
continue
heater_number = int(heater_number)
2023-01-31 15:48:43 +01:00
if heater_number >= Heater.NUMBER_OF_SWITCHES or heater_number < 0:
2022-05-05 14:30:28 +02:00
print("Invalid heater switch number")
continue
break
return heater_number
def health_cmd(
2022-08-08 16:32:18 +02:00
q: DefaultPusQueueHelper,
2022-05-05 14:30:28 +02:00
heater_idx: int,
2022-07-05 02:12:54 +02:00
object_id: ObjectIdU32,
2022-05-05 14:30:28 +02:00
health: FsfwHealth,
health_str: str,
):
2022-07-04 15:22:53 +02:00
q.add_log_cmd(f"Setting Heater {heater_idx} {object_id} to {health_str}")
2022-05-05 14:30:28 +02:00
app_data = pack_set_health_cmd_data(object_id=object_id.as_bytes, health=health)
2022-07-04 15:22:53 +02:00
q.add_pus_tc(
PusTelecommand(
2023-01-17 18:37:16 +01:00
service=201, subservice=Subservice.TC_SET_HEALTH, app_data=app_data
2022-07-04 15:22:53 +02:00
)
2022-05-05 14:30:28 +02:00
)
2021-02-06 16:35:53 +01:00
2022-01-18 14:03:56 +01:00
def pack_switch_heater_command(
2022-05-03 19:01:38 +02:00
object_id: bytes, switch_nr: int, switch_action: int
) -> PusTelecommand:
2022-05-04 08:48:43 +02:00
"""Function to generate a heater switch command.
:param object_id: The object id of the HeaterHandler object.
:param switch_nr: The switch number identifying the heater to switch
:param switch_action: Action to perform. 0 - Sets switch off, 1 - Sets switch on.
2021-02-06 16:35:53 +01:00
"""
2022-03-16 18:44:28 +01:00
command = bytearray()
2021-02-06 16:35:53 +01:00
command.append(switch_nr)
command.append(switch_action)
command.append(COMMAND_SOURCE_PARAM_EXTERNAL)
return create_action_cmd(
2022-08-22 11:47:12 +02:00
object_id=object_id, action_id=ActionIds.SWITCH_HEATER, user_data=command
2022-05-03 19:01:38 +02:00
)