eive-tmtc/eive_tmtc/pus_tc/devs/rtd.py

111 lines
3.3 KiB
Python
Raw Normal View History

2022-05-23 17:50:08 +02:00
from typing import Optional
2022-11-29 16:53:29 +01:00
from eive_tmtc.config.definitions import CustomServiceList
2023-01-16 14:13:06 +01:00
from eive_tmtc.pus_tc.devs.pdec_handler import CommandId
2022-05-23 17:50:08 +02:00
from spacepackets.ecss import PusTelecommand
from tmtccmd.config import TmtcDefinitionWrapper, OpCodeEntry
from tmtccmd.config.tmtc import tmtc_definitions_provider
2022-07-04 15:22:53 +02:00
2022-08-08 16:32:18 +02:00
from tmtccmd.tc import DefaultPusQueueHelper
2022-07-08 16:25:46 +02:00
from tmtccmd.util import ObjectIdU32
2023-01-17 18:37:16 +01:00
from tmtccmd.tc.pus_200_fsfw_modes 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
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-01-16 14:13:06 +01:00
class OpCode:
2022-05-23 17:50:08 +02:00
ON = ["0", "on"]
OFF = ["1", "off"]
NORMAL = ["2", "normal"]
2022-06-07 17:49:16 +02:00
CONFIG_CMD = ["3", "Write config"]
2022-05-23 17:50:08 +02:00
class Info:
ON = "Switch handler on"
OFF = "Switch handler off"
NORMAL = "Switch handler normal"
2022-06-07 17:49:16 +02:00
WIRTE_CONFIG = "Write config"
2022-05-23 17:50:08 +02:00
@tmtc_definitions_provider
def specify_rtd_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.ON, info=Info.ON)
oce.add(keys=OpCode.NORMAL, info=Info.NORMAL)
oce.add(keys=OpCode.OFF, info=Info.OFF)
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(
op_code: str, object_id: Optional[ObjectIdU32], q: DefaultPusQueueHelper
):
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-01-16 14:13:06 +01:00
if op_code in OpCode.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-01-16 14:13:06 +01:00
if op_code in OpCode.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-01-16 14:13:06 +01:00
if op_code in OpCode.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-01-16 14:13:06 +01:00
if op_code in OpCode.CONFIG_CMD:
command = object_id.as_bytes + CommandId.PRINT_CLCW
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
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