eive-tmtc/eive_tmtc/tmtc/health.py

69 lines
2.2 KiB
Python
Raw Normal View History

2023-02-01 20:11:47 +01:00
from spacepackets.ecss import PusTelecommand
from tmtccmd.config.tmtc import (
2023-11-22 13:51:33 +01:00
CmdTreeNode,
2023-02-01 20:11:47 +01:00
)
2023-11-22 13:51:33 +01:00
from tmtccmd.pus.s201_fsfw_health import FsfwHealth, Subservice
from tmtccmd.tmtc import DefaultPusQueueHelper
from eive_tmtc.config.definitions import CustomServiceList
from eive_tmtc.tmtc.obj_prompt import prompt_object
2023-02-01 20:11:47 +01:00
class OpCode:
2023-03-06 12:03:51 +01:00
SET_HEALTH = "set_health"
2023-02-01 20:11:47 +01:00
ANNOUNCE_HEALTH_ALL = "read_health_all"
ANNOUNCE_HEALTH = "read_health"
class Info:
2023-03-06 12:03:51 +01:00
SET_HEALTH = "Set health of specific object"
2023-02-01 20:11:47 +01:00
ANNOUNCE_HEALTH_ALL = "Read all health states"
ANNOUNCE_HEALTH = "Read health state of one object"
def prompt_health() -> FsfwHealth:
for item in FsfwHealth:
print(f"{item}: {item.name}")
2023-03-06 13:58:52 +01:00
health_idx = int(input("Please enter health by index: "))
return FsfwHealth(health_idx)
2023-11-22 19:42:26 +01:00
def build_health_cmds(q: DefaultPusQueueHelper, cmd_str: str):
2023-11-22 13:51:33 +01:00
if cmd_str == OpCode.SET_HEALTH:
app_data = bytearray(prompt_object())
health = prompt_health()
2023-03-06 13:58:52 +01:00
app_data.append(health)
q.add_log_cmd(Info.SET_HEALTH)
q.add_pus_tc(
PusTelecommand(
service=201, subservice=Subservice.TC_SET_HEALTH, app_data=app_data
)
)
2023-11-22 13:51:33 +01:00
elif cmd_str == OpCode.ANNOUNCE_HEALTH:
app_data = bytearray(prompt_object())
q.add_log_cmd(Info.ANNOUNCE_HEALTH)
q.add_pus_tc(
PusTelecommand(
service=201, subservice=Subservice.TC_ANNOUNCE_HEALTH, app_data=app_data
)
)
2023-11-22 13:51:33 +01:00
elif cmd_str == OpCode.ANNOUNCE_HEALTH_ALL:
2023-02-01 20:11:47 +01:00
q.add_log_cmd(Info.ANNOUNCE_HEALTH_ALL)
q.add_pus_tc(
PusTelecommand(service=201, subservice=Subservice.TC_ANNOUNCE_HEALTH_ALL)
)
2023-03-06 13:58:52 +01:00
else:
2023-11-22 13:51:33 +01:00
raise ValueError(
f"unknown command string {cmd_str} for service {CustomServiceList.HEALTH}"
)
2023-02-01 20:11:47 +01:00
2023-11-22 13:51:33 +01:00
def create_global_health_node() -> CmdTreeNode:
health_node = CmdTreeNode("health", "Health Commands")
health_node.add_child(
CmdTreeNode(OpCode.ANNOUNCE_HEALTH_ALL, Info.ANNOUNCE_HEALTH_ALL)
)
health_node.add_child(CmdTreeNode(OpCode.ANNOUNCE_HEALTH, Info.ANNOUNCE_HEALTH))
health_node.add_child(CmdTreeNode(OpCode.SET_HEALTH, Info.SET_HEALTH))
return health_node