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

69 lines
2.0 KiB
Python

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 EPS_SUBSYSTEM_ID
from eive_tmtc.config.definitions import CustomServiceList
from tmtccmd.config.tmtc import (
tmtc_definitions_provider,
TmtcDefinitionWrapper,
OpCodeEntry,
)
from tmtccmd.pus.s200_fsfw_mode import Subservice as ModeSubservices, Mode
from tmtccmd.tmtc import service_provider
from tmtccmd.tmtc.decorator import ServiceProviderParams
class OpCode(str, enum.Enum):
OFF = "off"
NML = "normal"
REPORT_ALL_MODES = "all_modes"
class Info(str, enum.Enum):
OFF = "Off Mode Command"
NML = "Normal Mode Command"
REPORT_ALL_MODES = "Report All Modes Recursively"
HANDLER_LIST: Dict[str, Tuple[int, int, str]] = {
OpCode.OFF: (Mode.OFF, 0, Info.OFF),
OpCode.NML: (Mode.NORMAL, 0, Info.NML),
}
@service_provider(CustomServiceList.EPS_SS.value)
def build_eps_subsystem_cmd(p: ServiceProviderParams):
op_code = p.op_code
q = p.queue_helper
info_prefix = "EPS 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=EPS_SUBSYSTEM_ID,
)
)
mode_info_tup = HANDLER_LIST.get(op_code)
if mode_info_tup is None:
return
pack_mode_cmd_with_info(
object_id=EPS_SUBSYSTEM_ID,
info=f"{info_prefix}: {mode_info_tup[2]}",
mode=mode_info_tup[0],
submode=mode_info_tup[1],
q=q,
)
@tmtc_definitions_provider
def add_eps_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.EPS_SS, "EPS Subsystem", oce)