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
|
|
|
|
|
|
|
|
from config.definitions import CustomServiceList
|
|
|
|
from tmtccmd.config.definitions import QueueCommands, ServiceOpCodeDictT
|
|
|
|
from tmtccmd.tc.service_8_functional_cmd import generate_action_command
|
|
|
|
from tmtccmd.config.globals import add_service_op_code_entry, add_op_code_entry
|
2021-07-24 14:58:47 +02:00
|
|
|
from tmtccmd.tc.packer import TcQueueT
|
2021-10-01 10:55:56 +02:00
|
|
|
from spacepackets.ecss.tc import PusTelecommand
|
2021-02-06 16:35:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
class SwitchNumbers:
|
2022-05-03 19:03:10 +02:00
|
|
|
HEATER_0_OBC_BRD = 0
|
|
|
|
HEATER_1_PLOC_PROC_BRD = 1
|
|
|
|
HEATER_2_ACS_BRD = 2
|
|
|
|
HEATER_3_PCDU_PDU = 3
|
|
|
|
HEATER_4_CAMERA = 4
|
|
|
|
HEATER_5_STR = 5
|
|
|
|
HEATER_6_DRO = 6
|
|
|
|
HEATER_7_HPA = 7
|
2021-02-14 09:37:28 +01:00
|
|
|
NUMBER_OF_SWITCHES = 8
|
2021-02-06 16:35:53 +01:00
|
|
|
|
|
|
|
|
2022-05-03 19:01:38 +02:00
|
|
|
class OpCodes:
|
2022-05-04 08:48:43 +02:00
|
|
|
HEATER_CMD = ["0", "switch-cmd"]
|
|
|
|
HEATER_EXT_CTRL = ["1", "heater-ext-ctrl"]
|
|
|
|
HEATER_FAULTY_CMD = ["2", "set-faulty"]
|
2022-05-03 19:01:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Info:
|
|
|
|
HEATER_CMD = "Heater Switch Command"
|
|
|
|
|
|
|
|
|
|
|
|
class ActionIds(enum.IntEnum):
|
|
|
|
SWITCH_HEATER = 0
|
|
|
|
|
2021-02-06 16:35:53 +01:00
|
|
|
|
2022-05-03 19:01:38 +02:00
|
|
|
def add_heater_cmds(cmd_dict: ServiceOpCodeDictT):
|
|
|
|
op_code_dict = dict()
|
|
|
|
add_op_code_entry(
|
|
|
|
op_code_dict=op_code_dict, keys=OpCodes.HEATER_CMD, info=Info.HEATER_CMD
|
|
|
|
)
|
|
|
|
add_service_op_code_entry(
|
|
|
|
srv_op_code_dict=cmd_dict,
|
|
|
|
name=CustomServiceList.HEATER.value,
|
|
|
|
info="Heater Device",
|
|
|
|
op_code_entry=op_code_dict,
|
|
|
|
)
|
2021-02-06 16:35:53 +01:00
|
|
|
|
|
|
|
|
2022-05-04 08:48:43 +02:00
|
|
|
def pack_heater_cmds(object_id: bytearray, op_code: str, tc_queue: TcQueueT):
|
|
|
|
if op_code in OpCodes.HEATER_CMD:
|
|
|
|
tc_queue.appendleft((QueueCommands.PRINT, "Heater Switching"))
|
|
|
|
while True:
|
|
|
|
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)
|
|
|
|
if heater_number >= SwitchNumbers.NUMBER_OF_SWITCHES or heater_number < 0:
|
|
|
|
print("Invalid heater switch number")
|
|
|
|
continue
|
|
|
|
break
|
|
|
|
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}"
|
|
|
|
tc_queue.appendleft((QueueCommands.PRINT, debug_string))
|
|
|
|
command = pack_switch_heater_command(object_id, heater_number, action)
|
|
|
|
tc_queue.appendleft(command.pack_command_tuple())
|
|
|
|
if op_code in OpCodes.HEATER_EXT_CTRL:
|
|
|
|
pass
|
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)
|
2022-05-03 19:01:38 +02:00
|
|
|
return generate_action_command(
|
|
|
|
object_id=object_id, action_id=ActionIds.SWITCH_HEATER, app_data=command
|
|
|
|
)
|