eive-tmtc/eive_tmtc/tmtc/time.py
2023-11-22 10:51:26 +01:00

55 lines
1.6 KiB
Python

import enum
import logging
from datetime import datetime
from spacepackets.ecss import PusTelecommand, PusService
from tmtccmd.tmtc import DefaultPusQueueHelper
from tmtccmd.config import CmdTreeNode
class Subservice(enum.IntEnum):
SET_TIME = 128
DUMP_TIME = 129
class CmdStr:
SET_CURRENT_TIME = "set_curr_time"
DUMP_TIME = "dump_time"
class Info:
SET_CURRENT_TIME = "Setting current time in ASCII format"
DUMP_TIME = "Dump system time as event"
def pack_time_management_cmd(q: DefaultPusQueueHelper, cmd_str: str):
if cmd_str == CmdStr.SET_CURRENT_TIME:
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,
)
)
elif cmd_str == CmdStr.DUMP_TIME:
q.add_log_cmd(Info.DUMP_TIME)
q.add_pus_tc(
PusTelecommand(
service=PusService.S9_TIME_MGMT, subservice=Subservice.DUMP_TIME
)
)
def create_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