This commit is contained in:
parent
33cf7b1613
commit
492d364246
@ -1,6 +1,7 @@
|
||||
import enum
|
||||
import struct
|
||||
import logging
|
||||
from datetime import datetime
|
||||
import datetime
|
||||
|
||||
from spacepackets.ecss import PusTelecommand, PusService
|
||||
|
||||
@ -8,26 +9,31 @@ from tmtccmd.tmtc import DefaultPusQueueHelper
|
||||
from tmtccmd.config import CmdTreeNode
|
||||
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
class Subservice(enum.IntEnum):
|
||||
SET_TIME = 128
|
||||
DUMP_TIME = 129
|
||||
RELATIVE_TIMESHIFT = 130
|
||||
|
||||
|
||||
class CmdStr:
|
||||
SET_CURRENT_TIME = "set_curr_time"
|
||||
RELATIVE_TIMESHIFT = "relative_timeshift"
|
||||
DUMP_TIME = "dump_time"
|
||||
|
||||
|
||||
class Info:
|
||||
SET_CURRENT_TIME = "Setting current time in ASCII format"
|
||||
RELATIVE_TIMESHIFT = "Shift time with a relative offset"
|
||||
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 = datetime.datetime.now(datetime.UTC).isoformat() + "Z" + "\0"
|
||||
current_time_ascii = current_time.encode("ascii")
|
||||
logging.getLogger(__name__).info(
|
||||
_LOGGER.info(
|
||||
f"Current time in ASCII format: {current_time_ascii}"
|
||||
)
|
||||
q.add_log_cmd(Info.SET_CURRENT_TIME)
|
||||
@ -38,6 +44,17 @@ def pack_time_management_cmd(q: DefaultPusQueueHelper, cmd_str: str):
|
||||
app_data=current_time_ascii,
|
||||
)
|
||||
)
|
||||
elif cmd_str == CmdStr.RELATIVE_TIMESHIFT:
|
||||
nanos = input("Specify relative timeshift in nanoseconds")
|
||||
nanos_packed = struct.pack("!Q", nanos)
|
||||
q.add_log_cmd(Info.RELATIVE_TIMESHIFT)
|
||||
q.add_pus_tc(
|
||||
PusTelecommand(
|
||||
service=PusService.S9_TIME_MGMT,
|
||||
subservice=Subservice.RELATIVE_TIMESHIFT,
|
||||
app_data=nanos_packed
|
||||
)
|
||||
)
|
||||
elif cmd_str == CmdStr.DUMP_TIME:
|
||||
q.add_log_cmd(Info.DUMP_TIME)
|
||||
q.add_pus_tc(
|
||||
@ -51,4 +68,5 @@ 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"))
|
||||
time_node.add_child(CmdTreeNode(CmdStr.RELATIVE_TIMESHIFT,Info.RELATIVE_TIMESHIFT))
|
||||
return time_node
|
||||
|
Loading…
Reference in New Issue
Block a user