eive-tmtc/pus_tc/plpcdu.py

84 lines
2.7 KiB
Python
Raw Normal View History

2022-02-25 19:21:32 +01:00
import enum
2022-03-01 18:00:39 +01:00
from typing import Optional
2022-02-25 19:21:32 +01:00
from tmtccmd.config import QueueCommands
from tmtccmd.tc.definitions import TcQueueT
from tmtccmd.tc.service_200_mode import pack_mode_data, Modes, Subservices
2022-03-01 17:31:36 +01:00
from tmtccmd.tc.service_20_parameter import (
pack_scalar_double_param_app_data,
2022-03-01 18:12:31 +01:00
pack_fsfw_load_param_cmd,
2022-03-01 17:31:36 +01:00
)
from tmtccmd.utility.logger import get_console_logger
2022-02-25 19:21:32 +01:00
from spacepackets.ecss.tc import PusTelecommand
from config.object_ids import PL_PCDU_ID
2022-03-01 17:31:36 +01:00
LOGGER = get_console_logger()
2022-02-25 19:21:32 +01:00
2022-03-01 18:00:39 +01:00
2022-02-25 19:21:32 +01:00
class OpCodes:
SWITCH_ADC_ON = ["0", "switch-adc-on"]
SWITCH_ALL_ON = ["1", "switch-all-on"]
2022-03-01 17:25:50 +01:00
UPDATE_DRO_TO_X8_WAIT = ["2", "dro-to-x8-wait"]
2022-02-25 19:21:32 +01:00
class Submodes(enum.IntEnum):
ADC_ON = 0
ALL_ON = 1
2022-03-01 17:31:36 +01:00
class ParamIds(enum.IntEnum):
2022-03-01 19:41:24 +01:00
SSR_TO_DRO_WAIT_TIME = 17
DRO_TO_X8_WAIT_TIME = 18
2022-03-01 17:31:36 +01:00
2022-02-25 19:21:32 +01:00
def pack_pl_pcdu_commands(tc_queue: TcQueueT, op_code: str):
if op_code in OpCodes.SWITCH_ADC_ON:
tc_queue.appendleft((QueueCommands.PRINT, "Switching PL PCDU ADC module on"))
mode_data = pack_mode_data(
object_id=PL_PCDU_ID, mode=Modes.NORMAL, submode=Submodes.ADC_ON
)
mode_cmd = PusTelecommand(
service=200, subservice=Subservices.SWITCH_MODE, app_data=mode_data
)
tc_queue.appendleft(mode_cmd.pack_command_tuple())
if op_code in OpCodes.SWITCH_ALL_ON:
tc_queue.appendleft((QueueCommands.PRINT, "Switching all PL PCDU modules on"))
mode_data = pack_mode_data(
object_id=PL_PCDU_ID, mode=Modes.NORMAL, submode=Submodes.ALL_ON
)
mode_cmd = PusTelecommand(
service=200, subservice=Subservices.SWITCH_MODE, app_data=mode_data
)
tc_queue.appendleft(mode_cmd.pack_command_tuple())
2022-03-01 17:25:50 +01:00
if op_code in OpCodes.UPDATE_DRO_TO_X8_WAIT:
2022-03-01 18:00:39 +01:00
wait_time = request_wait_time()
2022-03-01 19:41:24 +01:00
tc_queue.appendleft(
(QueueCommands.PRINT, f"Updating DRO to X8 wait time to {wait_time}")
)
2022-03-01 18:00:39 +01:00
if wait_time is None:
return
2022-03-01 17:31:36 +01:00
param_data = pack_scalar_double_param_app_data(
object_id=PL_PCDU_ID,
domain_id=0,
unique_id=ParamIds.DRO_TO_X8_WAIT_TIME,
2022-03-01 18:12:31 +01:00
parameter=wait_time,
2022-03-01 17:31:36 +01:00
)
cmd = pack_fsfw_load_param_cmd(ssc=0, app_data=param_data)
tc_queue.appendleft(cmd.pack_command_tuple())
2022-03-01 18:00:39 +01:00
def request_wait_time() -> Optional[float]:
while True:
2022-03-01 19:41:24 +01:00
wait_time = input("Please enter DRO to X8 wait time in seconds, x to cancel: ")
2022-03-01 18:00:39 +01:00
if wait_time.lower() == "x":
return None
2022-03-01 19:41:24 +01:00
try:
wait_time = float(wait_time)
except ValueError:
2022-03-01 18:00:39 +01:00
LOGGER.warning("Invalid input")
continue
if wait_time <= 0:
LOGGER.warning("Invalid input")
else:
return wait_time