diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c3e3c4..0c44882 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ list yields a list of all related PRs for each release. # [unreleased] +## Added + +- Add time dump command + # [v2.8.0] 2023-01-01 - Move all device modules inside `pus_tc` and `pus_tm` to `tmtc` module and respective diff --git a/eive_tmtc/pus_tc/cmd_definitions.py b/eive_tmtc/pus_tc/cmd_definitions.py index fb5baa1..a42d18a 100644 --- a/eive_tmtc/pus_tc/cmd_definitions.py +++ b/eive_tmtc/pus_tc/cmd_definitions.py @@ -104,22 +104,6 @@ def add_str_cmds(defs: TmtcDefinitionWrapper): defs.add_service(CustomServiceList.STAR_TRACKER.value, "Star Tracker", oce) -@tmtc_definitions_provider -def add_time_cmds(defs: TmtcDefinitionWrapper): - from eive_tmtc.pus_tc.system.time import OpCode, Info - - oce = OpCodeEntry() - oce.add( - keys=OpCode.SET_CURRENT_TIME, - info=Info.SET_CURRENT_TIME, - ) - defs.add_service( - name=CustomServiceList.TIME.value, - info="Time Service", - op_code_entry=oce, - ) - - @tmtc_definitions_provider def add_system_cmds(defs: TmtcDefinitionWrapper): import eive_tmtc.pus_tc.system.controllers as controllers diff --git a/eive_tmtc/pus_tc/system/time.py b/eive_tmtc/pus_tc/system/time.py deleted file mode 100644 index f00739d..0000000 --- a/eive_tmtc/pus_tc/system/time.py +++ /dev/null @@ -1,28 +0,0 @@ -import logging -from datetime import datetime - -from eive_tmtc.config.definitions import CustomServiceList -from spacepackets.ecss import PusTelecommand - -from tmtccmd.tc import service_provider -from tmtccmd.tc.decorator import ServiceProviderParams - - -class OpCode: - SET_CURRENT_TIME = ["0", "set-curr-time"] - - -class Info: - SET_CURRENT_TIME = "Setting current time in ASCII format" - - -@service_provider(CustomServiceList.TIME.value) -def pack_set_current_time_ascii_command(p: ServiceProviderParams): - q = p.queue_helper - time_test_current_time = datetime.utcnow().isoformat() + "Z" + "\0" - current_time_ascii = time_test_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=9, subservice=128, app_data=current_time_ascii)) diff --git a/eive_tmtc/tmtc/time.py b/eive_tmtc/tmtc/time.py new file mode 100644 index 0000000..da7fc6d --- /dev/null +++ b/eive_tmtc/tmtc/time.py @@ -0,0 +1,70 @@ +import enum +import logging +from datetime import datetime + +from eive_tmtc.config.definitions import CustomServiceList +from spacepackets.ecss import PusTelecommand, PusService +from tmtccmd.config.tmtc import ( + tmtc_definitions_provider, + TmtcDefinitionWrapper, + OpCodeEntry, +) + +from tmtccmd.tc import service_provider +from tmtccmd.tc.decorator import ServiceProviderParams + + +class Subservice(enum.IntEnum): + SET_TIME = 128 + DUMP_TIME = 129 + + +class OpCode: + 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" + + +@service_provider(CustomServiceList.TIME.value) +def pack_set_current_time_ascii_command(p: ServiceProviderParams): + q = p.queue_helper + o = p.op_code + if o == OpCode.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 o == OpCode.DUMP_TIME: + q.add_log_cmd(Info.DUMP_TIME) + q.add_pus_tc( + PusTelecommand( + service=PusService.S9_TIME_MGMT, subservice=Subservice.DUMP_TIME + ) + ) + + +@tmtc_definitions_provider +def add_time_cmds(defs: TmtcDefinitionWrapper): + oce = OpCodeEntry() + oce.add( + keys=OpCode.SET_CURRENT_TIME, + info=Info.SET_CURRENT_TIME, + ) + defs.add_service( + name=CustomServiceList.TIME.value, + info="Time Service", + op_code_entry=oce, + )