From aabfcf83ac6fc35c65d63bb334f5fc0a73bbb6e6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 17 Feb 2023 18:43:20 +0100 Subject: [PATCH] that should be the basic delete impl --- eive_tmtc/tmtc/tm_store.py | 42 +++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/eive_tmtc/tmtc/tm_store.py b/eive_tmtc/tmtc/tm_store.py index 62a714b..8a64f76 100644 --- a/eive_tmtc/tmtc/tm_store.py +++ b/eive_tmtc/tmtc/tm_store.py @@ -1,4 +1,6 @@ +import datetime import logging +import math import struct from eive_tmtc.config.object_ids import ( @@ -40,19 +42,14 @@ def pack_tm_store_commands(p: ServiceProviderParams): q = p.queue_helper o = p.op_code if o == OpCode.DELETE: - q.add_log_cmd(Info.DELETE) - delete_up_to_time = parse( - input( - "Please enter delete end time in any format supported by dateutil.parser.parse\n" - "Recommended format: UTC ISO format YYYY-MM-DDThh:mm:ssZ: " - ) - ) - print(f"Parsed timestamp: {delete_up_to_time}") - end_stamp = delete_up_to_time.timestamp() - obj_id = store_select_prompt() + obj_id, store_string = store_select_prompt() app_data = bytearray(obj_id.as_bytes) + delete_up_to_time = time_prompt() + end_stamp = int(math.floor(delete_up_to_time.timestamp())) app_data.extend(struct.pack("!I", end_stamp)) - # q.add_pus_tc( + q.add_log_cmd(Info.DELETE) + q.add_log_cmd(f"Selected Store: {obj_id}") + q.add_log_cmd(f"Deletion up to time {delete_up_to_time}") print( PusTelecommand( service=15, subservice=Subservice.DELETE_UP_TO, app_data=app_data @@ -83,20 +80,33 @@ STORE_DICT = { } -def store_select_prompt() -> ObjectIdU32: +def time_prompt() -> datetime.datetime: + # TODO: Add support for offset from now in seconds + delete_up_to_time = parse( + input( + "Please enter delete end time in any format supported by dateutil.parser.parse\n" + "Recommended format: UTC ISO format YYYY-MM-DDThh:mm:ssZ: " + ) + ) + print(f"Parsed timestamp: {delete_up_to_time}") + return delete_up_to_time + + +def store_select_prompt() -> (ObjectIdU32, str): obj_id_dict = get_object_ids() print("Available TM stores:") idx_to_obj_id = dict() for idx, (k, v) in enumerate(STORE_DICT.items()): - idx_to_obj_id.update({idx: k}) + idx_to_obj_id.update({idx: (k, v)}) print(f"{idx}: {v}") while True: target_index = int( input("Please enter the target store for the TM store transaction: ") ) - obj_id_raw = idx_to_obj_id.get(target_index) - if obj_id_raw is None: + obj_id_and_store_str = idx_to_obj_id.get(target_index) + if obj_id_and_store_str is None: _LOGGER.warning("Invalid index. Try again") continue break - return obj_id_dict.get(obj_id_raw) + obj_id_raw = obj_id_and_store_str[0] + return obj_id_dict.get(obj_id_raw), obj_id_and_store_str[1]