eive-tmtc/eive_tmtc/tmtc/system.py
Robin Mueller d640d547bd
All checks were successful
EIVE/-/pipeline/head This commit looks good
OOF3
2023-11-22 13:51:33 +01:00

119 lines
4.4 KiB
Python

import enum
from eive_tmtc.config.definitions import CustomServiceList
from eive_tmtc.tmtc.acs.subsystem import AcsMode
from tmtccmd.config.tmtc import (
CmdTreeNode,
tmtc_definitions_provider,
TmtcDefinitionWrapper,
OpCodeEntry,
)
from tmtccmd.tmtc import DefaultPusQueueHelper
from eive_tmtc.config.object_ids import EIVE_SYSTEM_ID
from tmtccmd.pus.s200_fsfw_mode import (
create_mode_command,
create_announce_mode_recursive_command,
)
from tmtccmd.pus.s8_fsfw_action import create_action_cmd
class SystemMode:
BOOT = 5
SAFE = AcsMode.SAFE
IDLE = AcsMode.IDLE
PTG_NADIR = AcsMode.PTG_NADIR
PTG_TARGET = AcsMode.PTG_TARGET
PTG_TARGET_GS = AcsMode.PTG_TARGET_GS
PTG_INERTIAL = AcsMode.PTG_INERTIAL
class ActionId(enum.IntEnum):
EXECUTE_I2C_REBOOT = 10
class OpCode:
BOOT_MODE = "boot"
SAFE_MODE = "safe"
IDLE_MODE = "idle"
NADIR_MODE = "nadir"
TARGET_MODE = "ptg_target"
TARGET_GS_MODE = "ptg_target_gs"
INERTIAL_MODE = "ptg_inertial"
ANNOUNCE_MODES = "announce_modes"
REBOOT_I2C = "reboot_i2c"
class Info:
BOOT_MODE = "Command System into Boot Mode"
SAFE_MODE = "Command System into Safe Mode"
IDLE_MODE = "Command System into Idle Pointing Mode"
NADIR_MODE = "Command System into Nadir Pointing Mode"
TARGET_MODE = "Command System into Target Pointing Mode"
TARGET_GS_MODE = "Command System into Target Groundstation Pointing Mode"
INERTIAL_MODE = "Command System into Inertial Pointing Mode"
ANNOUNCE_MODES = "Announce mode recursively"
REBOOT_I2C = "Reboot I2C bus"
def build_system_cmds(q: DefaultPusQueueHelper, cmd_str: str):
prefix = "EIVE System"
if cmd_str == OpCode.SAFE_MODE:
q.add_log_cmd(f"{prefix}: {Info.SAFE_MODE}")
q.add_pus_tc(create_mode_command(EIVE_SYSTEM_ID, SystemMode.SAFE, 0))
elif cmd_str == OpCode.IDLE_MODE:
q.add_log_cmd(f"{prefix}: {Info.IDLE_MODE}")
q.add_pus_tc(create_mode_command(EIVE_SYSTEM_ID, SystemMode.IDLE, 0))
elif cmd_str == OpCode.NADIR_MODE:
q.add_log_cmd(f"{prefix}: {Info.NADIR_MODE}")
q.add_pus_tc(create_mode_command(EIVE_SYSTEM_ID, SystemMode.PTG_NADIR, 0))
elif cmd_str == OpCode.TARGET_MODE:
q.add_log_cmd(f"{prefix}: {Info.TARGET_MODE}")
q.add_pus_tc(create_mode_command(EIVE_SYSTEM_ID, SystemMode.PTG_TARGET, 0))
elif cmd_str == OpCode.TARGET_GS_MODE:
q.add_log_cmd(f"{prefix}: {Info.TARGET_GS_MODE}")
q.add_pus_tc(create_mode_command(EIVE_SYSTEM_ID, SystemMode.PTG_TARGET_GS, 0))
elif cmd_str == OpCode.INERTIAL_MODE:
q.add_log_cmd(f"{prefix}: {Info.INERTIAL_MODE}")
q.add_pus_tc(create_mode_command(EIVE_SYSTEM_ID, SystemMode.PTG_INERTIAL, 0))
elif cmd_str == OpCode.ANNOUNCE_MODES:
q.add_log_cmd(f"{prefix}: {Info.ANNOUNCE_MODES}")
q.add_pus_tc(create_announce_mode_recursive_command(EIVE_SYSTEM_ID))
elif cmd_str == OpCode.BOOT_MODE:
q.add_log_cmd(f"{prefix}: {Info.BOOT_MODE}")
q.add_pus_tc(create_mode_command(EIVE_SYSTEM_ID, SystemMode.BOOT, 0))
elif cmd_str == OpCode.REBOOT_I2C:
q.add_log_cmd(f"{prefix}: {Info.REBOOT_I2C}")
q.add_pus_tc(create_action_cmd(EIVE_SYSTEM_ID, ActionId.EXECUTE_I2C_REBOOT))
def create_system_node() -> CmdTreeNode:
op_code_strs = [
getattr(OpCode, key) for key in dir(OpCode) if not key.startswith("__")
]
info_strs = [getattr(Info, key) for key in dir(OpCode) if not key.startswith("__")]
combined_dict = dict(zip(op_code_strs, info_strs))
node = CmdTreeNode("system", "EIVE System")
for op_code, info in combined_dict.items():
node.add_child(CmdTreeNode(op_code, info))
return node
@tmtc_definitions_provider
def add_system_cmd_defs(defs: TmtcDefinitionWrapper):
oce = OpCodeEntry()
oce.add(keys=OpCode.BOOT_MODE, info=Info.BOOT_MODE)
oce.add(keys=OpCode.SAFE_MODE, info=Info.SAFE_MODE)
oce.add(keys=OpCode.IDLE_MODE, info=Info.IDLE_MODE)
oce.add(keys=OpCode.NADIR_MODE, info=Info.NADIR_MODE)
oce.add(keys=OpCode.TARGET_MODE, info=Info.TARGET_MODE)
oce.add(keys=OpCode.TARGET_GS_MODE, info=Info.TARGET_GS_MODE)
oce.add(keys=OpCode.INERTIAL_MODE, info=Info.INERTIAL_MODE)
oce.add(keys=OpCode.ANNOUNCE_MODES, info=Info.ANNOUNCE_MODES)
oce.add(keys=OpCode.REBOOT_I2C, info=Info.REBOOT_I2C)
defs.add_service(
name=CustomServiceList.SYSTEM.value,
info="EIVE system commands",
op_code_entry=oce,
)
pass