import enum from typing import Tuple, Dict from spacepackets.ecss import PusTelecommand from eive_tmtc.tmtc.common import pack_mode_cmd_with_info from eive_tmtc.config.object_ids import ACS_SUBSYSTEM_ID from eive_tmtc.config.definitions import CustomServiceList from tmtccmd.config.tmtc import ( tmtc_definitions_provider, TmtcDefinitionWrapper, OpCodeEntry, ) from tmtccmd.tc.pus_200_fsfw_mode import Subservice as ModeSubservices from tmtccmd.tc import service_provider from tmtccmd.tc.decorator import ServiceProviderParams class OpCode(str, enum.Enum): OFF = "off" SAFE = "safe" DETUMBLE = "detumble" IDLE = "idle" PTG_TARGET = "ptg_target" PTG_TARGET_NADIR = "ptg_nadir" PTG_TARGET_GS = "ptg_target_gs" PTG_TARGET_INERTIAL = "ptg_inertial" REPORT_ALL_MODES = "all_modes" class AcsMode(enum.IntEnum): OFF = 0 SAFE = 10 DETUMBLE = 11 IDLE = 12 PTG_TARGET_NADIR = 13 PTG_TARGET = 14 PTG_TARGET_GS = 15 PTG_TARGET_INERTIAL = 16 class Info(str, enum.Enum): OFF = "Off Command" SAFE = "Safe Mode Command" DETUMBLE = "Detumble Mode Command" IDLE = "Idle Mode Command" PTG_TARGET_NADIR = "Target Pointing Nadir" PTG_TARGET = "Target Pointing" PTG_TARGET_GS = "Target Pointing Ground Station" PTG_TARGET_INERTIAL = "Target Pointing Inertial" REPORT_ALL_MODES = "Report All Modes Recursively" HANDLER_LIST: Dict[str, Tuple[int, str]] = { OpCode.OFF: (AcsMode.OFF, Info.OFF), OpCode.SAFE: (AcsMode.SAFE, Info.SAFE), OpCode.DETUMBLE: (AcsMode.DETUMBLE, Info.DETUMBLE), OpCode.IDLE: (AcsMode.IDLE, Info.IDLE), OpCode.PTG_TARGET: (AcsMode.PTG_TARGET, Info.PTG_TARGET), OpCode.PTG_TARGET_GS: (AcsMode.PTG_TARGET_GS, Info.PTG_TARGET_GS), OpCode.PTG_TARGET_NADIR: (AcsMode.PTG_TARGET_NADIR, Info.PTG_TARGET_NADIR), OpCode.PTG_TARGET_INERTIAL: (AcsMode.PTG_TARGET_INERTIAL, Info.PTG_TARGET_INERTIAL), } @service_provider(CustomServiceList.ACS_SS.value) def build_acs_subsystem_cmd(p: ServiceProviderParams): op_code = p.op_code q = p.queue_helper info_prefix = "ACS Subsystem" if op_code in OpCode.REPORT_ALL_MODES: q.add_log_cmd(f"{info_prefix}: {Info.REPORT_ALL_MODES}") q.add_pus_tc( PusTelecommand( service=200, subservice=ModeSubservices.TC_MODE_ANNOUNCE_RECURSIVE, app_data=ACS_SUBSYSTEM_ID, ) ) mode_info_tup = HANDLER_LIST.get(op_code) if mode_info_tup is None: return pack_mode_cmd_with_info( object_id=ACS_SUBSYSTEM_ID, info=f"{info_prefix}: {mode_info_tup[1]}", submode=0, mode=mode_info_tup[0], q=q, ) @tmtc_definitions_provider def add_acs_subsystem_cmds(defs: TmtcDefinitionWrapper): oce = OpCodeEntry() for op_code, (_, info) in HANDLER_LIST.items(): oce.add(op_code, info) oce.add(OpCode.REPORT_ALL_MODES, Info.REPORT_ALL_MODES) defs.add_service(CustomServiceList.ACS_SS, "ACS Subsystem", oce)