eive-tmtc/eive_tmtc/tmtc/power/power.py
Robin Mueller 1660e27ec1
All checks were successful
EIVE/-/pipeline/pr-main This commit looks good
hopefully soon done
2023-11-29 17:04:30 +01:00

173 lines
6.0 KiB
Python

import enum
import logging
from eive_tmtc.tmtc.power.common_power import (
PowerOpCodes,
PowerInfo,
add_gomspace_cmd_defs,
pack_reset_gnd_wdt_cmd,
)
from eive_tmtc.config.definitions import CustomServiceList
from eive_tmtc.config.object_ids import (
P60_DOCK_HANDLER,
ACU_HANDLER_ID,
PDU_1_HANDLER_ID,
PDU_2_HANDLER_ID,
get_object_ids,
)
from eive_tmtc.tmtc.power.pdu1 import (
add_pdu1_subnodes,
pdu1_req_hk_cmds,
pdu1_switch_cmds,
add_pdu1_common_defs,
add_pdu1_cmds,
)
from eive_tmtc.tmtc.power.pdu2 import (
add_pdu2_subnodes,
pdu2_req_hk_cmds,
add_pdu2_common_defs,
pdu2_switch_cmds,
add_pdu2_cmds,
)
from tmtccmd.config import CmdTreeNode, TmtcDefinitionWrapper, OpCodeEntry
from eive_tmtc.config.object_ids import PCDU_HANDLER_ID
from eive_tmtc.tmtc.power.p60dock import CmdString, CmdInfo, p60_dock_req_hk_cmds
from eive_tmtc.tmtc.power.acu import add_acu_cmds, acu_req_hk_cmds
from tmtccmd.pus.tc.s3_fsfw_hk import (
create_request_one_diag_command,
make_sid,
)
from tmtccmd.config.tmtc import tmtc_definitions_provider
from tmtccmd.tmtc import DefaultPusQueueHelper
class SetId(enum.IntEnum):
SWITCHER_SET = 0
class PcduSetIds(enum.IntEnum):
SWITCHER_SET = 0
class PcduSwitches(enum.IntEnum):
PDU1_CH0_TCS_BOARD_3V3 = 0
PDU1_CH1_SYRLINKS_12V = 1
PDU1_CH2_STAR_TRACKER_5V = 2
PDU1_CH3_MGT_5V = 3
PDU1_CH4_SUS_NOMINAL_3V3 = 4
PDU1_CH5_SOLAR_CELL_EXP_5V = 5
PDU1_CH6_PLOC_12V = 6
PDU1_CH7_ACS_A_SIDE_3V3 = 7
PDU1_CH8_UNOCCUPIED = 8
PDU2_CH0_Q7S = 9
PDU2_CH1_PL_PCDU_BATT_0_14V8 = 10
PDU2_CH2_RW_5V = 11
PDU2_CH3_TCS_BOARD_HEATER_IN_8V = 12
PDU2_CH4_SUS_REDUNDANT_3V3 = 13
PDU2_CH5_DEPLOYMENT_MECHANISM_8V = 14
PDU2_CH6_PL_PCDU_BATT_1_14V8 = 15
PDU2_CH7_ACS_BOARD_SIDE_B_3V3 = 16
PDU2_CH8_PAYLOAD_CAMERA = 17
P60_DOCK_5V_STACK = 18
P60_DOCK_3V3_STACK = 19
def pack_power_commands(q: DefaultPusQueueHelper, cmd_str: str):
pdu1_switch_cmds(q, cmd_str)
pdu2_switch_cmds(q, cmd_str)
if cmd_str in PowerOpCodes.SWITCHER_HK:
q.add_log_cmd("Requesting switcher state HK")
q.add_pus_tc(
create_request_one_diag_command(
make_sid(PCDU_HANDLER_ID, PcduSetIds.SWITCHER_SET)
)
)
if cmd_str in PowerOpCodes.INFO_CORE:
pdu1_req_hk_cmds(q, PowerOpCodes.REQUEST_CORE_HK_ONCE[0])
pdu2_req_hk_cmds(q, PowerOpCodes.REQUEST_CORE_HK_ONCE[0])
p60_dock_req_hk_cmds(q, PowerOpCodes.REQUEST_CORE_HK_ONCE[0])
acu_req_hk_cmds(q, PowerOpCodes.REQUEST_CORE_HK_ONCE[0])
q.add_wait_seconds(8.0)
elif cmd_str in PowerOpCodes.INFO_AUX:
pdu1_req_hk_cmds(q, PowerOpCodes.REQUEST_AUX_HK_ONCE[0])
pdu2_req_hk_cmds(q, PowerOpCodes.REQUEST_AUX_HK_ONCE[0])
p60_dock_req_hk_cmds(q, PowerOpCodes.REQUEST_AUX_HK_ONCE[0])
acu_req_hk_cmds(q, PowerOpCodes.REQUEST_AUX_HK_ONCE[0])
q.add_wait_seconds(8.0)
elif cmd_str in PowerOpCodes.INFO_ALL:
pdu1_req_hk_cmds(q, PowerOpCodes.REQUEST_CORE_HK_ONCE[0])
pdu2_req_hk_cmds(q, PowerOpCodes.REQUEST_CORE_HK_ONCE[0])
pdu1_req_hk_cmds(q, PowerOpCodes.REQUEST_AUX_HK_ONCE[0])
pdu2_req_hk_cmds(q, PowerOpCodes.REQUEST_AUX_HK_ONCE[0])
p60_dock_req_hk_cmds(q, PowerOpCodes.REQUEST_CORE_HK_ONCE[0])
p60_dock_req_hk_cmds(q, PowerOpCodes.REQUEST_AUX_HK_ONCE[0])
acu_req_hk_cmds(q, PowerOpCodes.REQUEST_CORE_HK_ONCE[0])
acu_req_hk_cmds(q, PowerOpCodes.REQUEST_AUX_HK_ONCE[0])
q.add_wait_seconds(8.0)
elif cmd_str in PowerOpCodes.RESET_ALL_GND_WDTS:
oids = get_object_ids()
pack_reset_gnd_wdt_cmd(q, "P60 Dock", oids[P60_DOCK_HANDLER])
pack_reset_gnd_wdt_cmd(q, "ACU", oids[ACU_HANDLER_ID])
pack_reset_gnd_wdt_cmd(q, "PDU1", oids[PDU_1_HANDLER_ID])
pack_reset_gnd_wdt_cmd(q, "PDU2", oids[PDU_2_HANDLER_ID])
q.add_wait_seconds(5.0)
if q.empty():
logging.getLogger(__name__).info(
f"Queue is empty, no stack for op code {cmd_str}"
)
@tmtc_definitions_provider
def add_p60_cmds(defs: TmtcDefinitionWrapper):
oce = OpCodeEntry()
oce.add(keys=CmdString.STACK_3V3_ON, info=CmdInfo.STACK_3V3_ON)
oce.add(keys=CmdString.STACK_3V3_OFF, info=CmdInfo.STACK_3V3_OFF)
oce.add(keys=CmdString.STACK_5V_ON, info=CmdInfo.STACK_5V_ON)
oce.add(keys=CmdString.STACK_5V_OFF, info=CmdInfo.STACK_5V_OFF)
add_gomspace_cmd_defs(oce)
oce.add(keys=CmdString.TEST, info="P60 Tests")
defs.add_service(
name=CustomServiceList.P60DOCK.value, info="P60 Device", op_code_entry=oce
)
def create_power_node() -> CmdTreeNode:
node = CmdTreeNode("power", "Power commands", hide_children_which_are_leaves=True)
add_pdu1_subnodes(node)
add_pdu2_subnodes(node)
node.add_child(CmdTreeNode(PowerOpCodes.SWITCHER_HK[0], PowerInfo.SWITCHER_HK))
node.add_child(CmdTreeNode(PowerOpCodes.INFO_ALL[0], PowerInfo.INFO_ALL))
node.add_child(CmdTreeNode(PowerOpCodes.INFO_CORE[0], PowerInfo.INFO_CORE))
node.add_child(CmdTreeNode(PowerOpCodes.INFO_AUX[0], PowerInfo.INFO_AUX))
node.add_child(
CmdTreeNode(PowerOpCodes.RESET_ALL_GND_WDTS[0], PowerInfo.RESET_ALL_GND_WDTS)
)
return node
@tmtc_definitions_provider
def add_power_cmd_defs(defs: TmtcDefinitionWrapper):
oce = OpCodeEntry()
add_pdu1_common_defs(oce)
add_pdu2_common_defs(oce)
oce.add(keys=PowerOpCodes.SWITCHER_HK, info=PowerInfo.SWITCHER_HK)
oce.add(keys=PowerOpCodes.INFO_ALL, info=PowerInfo.INFO_ALL)
oce.add(keys=PowerOpCodes.INFO_CORE, info=PowerInfo.INFO_CORE)
oce.add(keys=PowerOpCodes.INFO_AUX, info=PowerInfo.INFO_AUX)
oce.add(keys=PowerOpCodes.RESET_ALL_GND_WDTS, info=PowerInfo.RESET_ALL_GND_WDTS)
defs.add_service(
name=CustomServiceList.POWER.value,
info="Power Subsystem",
op_code_entry=oce,
)
def add_pcdu_cmds(defs: TmtcDefinitionWrapper):
add_p60_cmds(defs)
add_pdu1_cmds(defs)
add_pdu2_cmds(defs)
add_acu_cmds(defs)