eive-tmtc/eive_tmtc/tmtc/acs/subsystem.py

88 lines
2.9 KiB
Python
Raw Normal View History

2022-10-04 14:12:33 +02:00
import enum
2022-10-04 14:46:00 +02:00
from typing import Tuple, Dict
2022-10-04 14:12:33 +02:00
2023-03-10 13:37:17 +01:00
from eive_tmtc.tmtc.acs.defs import AcsMode, SafeSubmode
2022-10-10 10:44:45 +02:00
from spacepackets.ecss import PusTelecommand
2022-11-29 16:53:29 +01:00
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
2022-10-04 14:12:33 +02:00
from tmtccmd.config.tmtc import (
tmtc_definitions_provider,
TmtcDefinitionWrapper,
OpCodeEntry,
)
2023-01-31 12:56:13 +01:00
from tmtccmd.tc.pus_200_fsfw_mode import Subservice as ModeSubservices
2022-10-04 14:12:33 +02:00
from tmtccmd.tc import service_provider
from tmtccmd.tc.decorator import ServiceProviderParams
2023-01-16 14:13:06 +01:00
class OpCode(str, enum.Enum):
2022-10-04 14:12:33 +02:00
OFF = "off"
SAFE = "safe"
2022-10-04 14:46:00 +02:00
DETUMBLE = "detumble"
2022-10-04 14:12:33 +02:00
IDLE = "idle"
2023-02-03 10:47:18 +01:00
PTG_TARGET = "ptg_target"
PTG_TARGET_NADIR = "ptg_nadir"
PTG_TARGET_GS = "ptg_target_gs"
PTG_TARGET_INERTIAL = "ptg_inertial"
2022-10-10 10:44:45 +02:00
REPORT_ALL_MODES = "all_modes"
2022-10-04 14:46:00 +02:00
2022-10-04 14:12:33 +02:00
class Info(str, enum.Enum):
OFF = "Off Command"
SAFE = "Safe Mode Command"
2022-10-04 14:46:00 +02:00
DETUMBLE = "Detumble Mode Command"
2022-10-04 14:12:33 +02:00
IDLE = "Idle Mode Command"
2023-02-03 10:47:18 +01:00
PTG_TARGET_NADIR = "Target Pointing Nadir"
PTG_TARGET = "Target Pointing"
PTG_TARGET_GS = "Target Pointing Ground Station"
PTG_TARGET_INERTIAL = "Target Pointing Inertial"
2022-10-10 10:44:45 +02:00
REPORT_ALL_MODES = "Report All Modes Recursively"
2022-10-04 14:46:00 +02:00
2023-03-10 13:37:17 +01:00
HANDLER_LIST: Dict[str, Tuple[int, int, str]] = {
OpCode.OFF: (AcsMode.OFF, 0, Info.OFF),
OpCode.SAFE: (AcsMode.SAFE, SafeSubmode.DEFAULT, Info.SAFE),
OpCode.DETUMBLE: (AcsMode.SAFE, SafeSubmode.DETUMBLE, Info.DETUMBLE),
OpCode.IDLE: (AcsMode.IDLE, 0, Info.IDLE),
OpCode.PTG_TARGET: (AcsMode.PTG_TARGET, 0, Info.PTG_TARGET),
OpCode.PTG_TARGET_GS: (AcsMode.PTG_TARGET_GS, 0, Info.PTG_TARGET_GS),
OpCode.PTG_TARGET_NADIR: (AcsMode.PTG_NADIR, 0, Info.PTG_TARGET_NADIR),
OpCode.PTG_TARGET_INERTIAL: (AcsMode.PTG_INERTIAL, 0, Info.PTG_TARGET_INERTIAL),
2022-10-04 14:46:00 +02:00
}
2022-10-04 14:12:33 +02:00
@service_provider(CustomServiceList.ACS_SS.value)
def build_acs_subsystem_cmd(p: ServiceProviderParams):
op_code = p.op_code
2022-10-04 14:46:00 +02:00
q = p.queue_helper
info_prefix = "ACS Subsystem"
2023-01-16 14:13:06 +01:00
if op_code in OpCode.REPORT_ALL_MODES:
2022-10-10 10:44:45 +02:00
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,
)
)
2022-10-10 11:09:17 +02:00
mode_info_tup = HANDLER_LIST.get(op_code)
2022-10-04 14:46:00 +02:00
if mode_info_tup is None:
return
pack_mode_cmd_with_info(
object_id=ACS_SUBSYSTEM_ID,
2023-03-10 13:37:17 +01:00
info=f"{info_prefix}: {mode_info_tup[2]}",
2022-10-04 14:46:00 +02:00
mode=mode_info_tup[0],
2023-03-10 13:37:17 +01:00
submode=mode_info_tup[1],
2022-10-04 14:46:00 +02:00
q=q,
)
2022-10-04 14:12:33 +02:00
@tmtc_definitions_provider
def add_acs_subsystem_cmds(defs: TmtcDefinitionWrapper):
oce = OpCodeEntry()
2023-03-10 14:08:31 +01:00
for op_code, (_, _, info) in HANDLER_LIST.items():
2023-02-03 10:47:18 +01:00
oce.add(op_code, info)
2023-01-16 14:13:06 +01:00
oce.add(OpCode.REPORT_ALL_MODES, Info.REPORT_ALL_MODES)
2022-10-04 14:12:33 +02:00
defs.add_service(CustomServiceList.ACS_SS, "ACS Subsystem", oce)