From 19768cb1b125568734e77432cc2c636637e4894d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 9 Apr 2022 18:44:04 +0200 Subject: [PATCH] added new time commands --- config/definitions.py | 1 + config/hook_implementations.py | 9 +++------ pus_tc/cmd_definitions.py | 17 +++++++++++++++++ pus_tc/devs/star_tracker.py | 4 +--- pus_tc/system/time.py | 28 ++++++++++++++++++++++++++++ pus_tc/tc_packer_hook.py | 3 +++ 6 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 pus_tc/system/time.py diff --git a/config/definitions.py b/config/definitions.py index 476e8e4..80a7ddb 100644 --- a/config/definitions.py +++ b/config/definitions.py @@ -45,3 +45,4 @@ class CustomServiceList(enum.Enum): ACS_ASS = "acs-ass" SUS_ASS = "sus-ass" TCS_ASS = "tcs-ass" + TIME = "time" diff --git a/config/hook_implementations.py b/config/hook_implementations.py index aa7bdf8..63a99d3 100644 --- a/config/hook_implementations.py +++ b/config/hook_implementations.py @@ -1,19 +1,14 @@ -import argparse -from typing import Union, Dict +from typing import Union from tmtccmd.config.definitions import ( ServiceOpCodeDictT, - HkReplyUnpacked, - DataReplyUnpacked, ) -from tmtccmd.tm.service_3_base import Service3Base from tmtccmd.tc.definitions import TcQueueT from tmtccmd.utility.retval import RetvalDictT from tmtccmd.pus.obj_id import ObjectIdDictT from tmtccmd.com_if.com_interface_base import CommunicationInterface from tmtccmd.core.backend import TmTcHandler from tmtccmd.config.hook import TmTcHookBase -from tmtccmd.utility.tmtc_printer import FsfwTmTcPrinter from tmtccmd.config.globals import OpCodeDictKeys from config.definitions import CustomServiceList @@ -75,6 +70,7 @@ def get_eive_service_op_code_dict(service_op_code_dict: ServiceOpCodeDictT): add_ploc_mpsoc_cmds, add_ploc_supv_cmds, add_system_cmds, + add_time_cmds, ) from pus_tc.devs.gps import GpsOpCodes @@ -88,6 +84,7 @@ def get_eive_service_op_code_dict(service_op_code_dict: ServiceOpCodeDictT): add_ploc_mpsoc_cmds(cmd_dict=service_op_code_dict) add_ploc_supv_cmds(cmd_dict=service_op_code_dict) add_system_cmds(cmd_dict=service_op_code_dict) + add_time_cmds(cmd_dict=service_op_code_dict) op_code_dict = { GpsOpCodes.RESET_GNSS.value: ("Reset GPS", {OpCodeDictKeys.TIMEOUT: 2.0}) diff --git a/pus_tc/cmd_definitions.py b/pus_tc/cmd_definitions.py index c5646c9..26691ca 100644 --- a/pus_tc/cmd_definitions.py +++ b/pus_tc/cmd_definitions.py @@ -179,6 +179,23 @@ def add_pl_pcdu_cmds(cmd_dict: ServiceOpCodeDictT): ) +def add_time_cmds(cmd_dict: ServiceOpCodeDictT): + from pus_tc.system.time import OpCodes, Info + + op_code_dict = dict() + add_op_code_entry( + op_code_dict=op_code_dict, + keys=OpCodes.SET_CURRENT_TIME, + info=Info.SET_CURRENT_TIME, + ) + add_service_op_code_entry( + srv_op_code_dict=cmd_dict, + name=CustomServiceList.TIME.value, + info="Time Service", + op_code_entry=op_code_dict, + ) + + def add_pcdu_cmds(cmd_dict: ServiceOpCodeDictT): from pus_tc.devs.p60dock import P60OpCodes, GomspaceOpCodes, Info from pus_tc.devs.pdu1 import Pdu1OpCodes diff --git a/pus_tc/devs/star_tracker.py b/pus_tc/devs/star_tracker.py index 47a06b0..f8df76d 100644 --- a/pus_tc/devs/star_tracker.py +++ b/pus_tc/devs/star_tracker.py @@ -146,9 +146,7 @@ class Submode: FIRMWARE = 2 -def pack_star_tracker_commands( - object_id: bytearray, tc_queue: TcQueueT, op_code: str -) -> TcQueueT: +def pack_star_tracker_commands(object_id: bytearray, tc_queue: TcQueueT, op_code: str): tc_queue.appendleft( ( QueueCommands.PRINT, diff --git a/pus_tc/system/time.py b/pus_tc/system/time.py new file mode 100644 index 0000000..c66bc17 --- /dev/null +++ b/pus_tc/system/time.py @@ -0,0 +1,28 @@ +from datetime import datetime + +from spacepackets.ecss import PusTelecommand +from tmtccmd.config import QueueCommands +from tmtccmd.tc.definitions import TcQueueT + +from tmtccmd.logging import get_console_logger + +LOGGER = get_console_logger() + + +class OpCodes: + SET_CURRENT_TIME = ["0", "set-curr-time"] + + +class Info: + SET_CURRENT_TIME = "Setting current time in ASCII format" + + +def pack_set_current_time_ascii_command(tc_queue: TcQueueT, ssc: int): + time_test_current_time = datetime.utcnow().isoformat() + "Z" + "\0" + current_time_ascii = time_test_current_time.encode("ascii") + LOGGER.info(f"Current time in ASCII format: {current_time_ascii}") + tc_queue.appendleft((QueueCommands.PRINT, Info.SET_CURRENT_TIME)) + command = PusTelecommand( + service=9, subservice=128, ssc=ssc, app_data=current_time_ascii + ) + tc_queue.appendleft(command.pack_command_tuple()) diff --git a/pus_tc/tc_packer_hook.py b/pus_tc/tc_packer_hook.py index 50bb8c6..420a768 100644 --- a/pus_tc/tc_packer_hook.py +++ b/pus_tc/tc_packer_hook.py @@ -36,6 +36,7 @@ from pus_tc.system.core import pack_core_commands from pus_tc.devs.star_tracker import pack_star_tracker_commands from pus_tc.devs.syrlinks_hk_handler import pack_syrlinks_command from pus_tc.devs.gps import pack_gps_command +from pus_tc.system.time import pack_set_current_time_ascii_command from pus_tc.system.acs import pack_acs_command, pack_sus_cmds from pus_tc.devs.plpcdu import pack_pl_pcdu_commands from pus_tc.devs.str_img_helper import pack_str_img_helper_command @@ -230,6 +231,8 @@ def pack_service_queue_user( return pack_acs_command(tc_queue=service_queue, op_code=op_code) if service == CustomServiceList.TCS_ASS.value: return pack_tcs_sys_commands(tc_queue=service_queue, op_code=op_code) + if service == CustomServiceList.TIME.value: + return pack_set_current_time_ascii_command(tc_queue=service_queue, ssc=0) LOGGER.warning("Invalid Service !")