2023-02-01 19:13:59 +01:00
|
|
|
import enum
|
|
|
|
import logging
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
from spacepackets.ecss import PusTelecommand, PusService
|
|
|
|
|
2023-11-22 10:17:05 +01:00
|
|
|
from tmtccmd.tmtc import DefaultPusQueueHelper
|
|
|
|
from tmtccmd.config import CmdTreeNode
|
2023-02-01 19:13:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Subservice(enum.IntEnum):
|
|
|
|
SET_TIME = 128
|
|
|
|
DUMP_TIME = 129
|
|
|
|
|
|
|
|
|
2023-11-22 10:17:05 +01:00
|
|
|
class CmdStr:
|
|
|
|
SET_CURRENT_TIME = "set_curr_time"
|
|
|
|
DUMP_TIME = "dump_time"
|
2023-02-01 19:13:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Info:
|
|
|
|
SET_CURRENT_TIME = "Setting current time in ASCII format"
|
|
|
|
DUMP_TIME = "Dump system time as event"
|
|
|
|
|
|
|
|
|
2023-11-22 10:17:05 +01:00
|
|
|
def pack_time_management_cmd(q: DefaultPusQueueHelper, cmd_str: str):
|
|
|
|
if cmd_str == CmdStr.SET_CURRENT_TIME:
|
2023-02-01 19:13:59 +01:00
|
|
|
current_time = datetime.utcnow().isoformat() + "Z" + "\0"
|
|
|
|
current_time_ascii = current_time.encode("ascii")
|
|
|
|
logging.getLogger(__name__).info(
|
|
|
|
f"Current time in ASCII format: {current_time_ascii}"
|
|
|
|
)
|
|
|
|
q.add_log_cmd(Info.SET_CURRENT_TIME)
|
|
|
|
q.add_pus_tc(
|
|
|
|
PusTelecommand(
|
|
|
|
service=PusService.S9_TIME_MGMT,
|
|
|
|
subservice=Subservice.SET_TIME,
|
|
|
|
app_data=current_time_ascii,
|
|
|
|
)
|
|
|
|
)
|
2023-11-22 10:17:05 +01:00
|
|
|
elif cmd_str == CmdStr.DUMP_TIME:
|
2023-02-01 19:13:59 +01:00
|
|
|
q.add_log_cmd(Info.DUMP_TIME)
|
|
|
|
q.add_pus_tc(
|
|
|
|
PusTelecommand(
|
|
|
|
service=PusService.S9_TIME_MGMT, subservice=Subservice.DUMP_TIME
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-11-22 10:17:05 +01:00
|
|
|
def return_time_node() -> CmdTreeNode:
|
|
|
|
time_node = CmdTreeNode("time", "Time Management")
|
|
|
|
time_node.add_child(CmdTreeNode(CmdStr.SET_CURRENT_TIME, "Set current time"))
|
|
|
|
time_node.add_child(CmdTreeNode(CmdStr.DUMP_TIME, "Dumpy current time"))
|
|
|
|
return time_node
|