From 676f85165912daf78da7f673e3d5ee17116b12bf Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 17 Feb 2023 19:22:56 +0100 Subject: [PATCH] added store enum --- eive_tmtc/tmtc/tm_store.py | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/eive_tmtc/tmtc/tm_store.py b/eive_tmtc/tmtc/tm_store.py index a5094da..f6d7214 100644 --- a/eive_tmtc/tmtc/tm_store.py +++ b/eive_tmtc/tmtc/tm_store.py @@ -1,4 +1,5 @@ import datetime +import enum import logging import math import struct @@ -73,12 +74,20 @@ def add_persistent_tm_store_cmd_defs(defs: TmtcDefinitionWrapper): ) +class TmStoreSelect(enum.IntEnum): + OK_TM_STORE = 0 + NOT_OK_TM_STORE = 1 + MISC_TM_STORE = 2 + HK_TM_STORE = 3 + CFDP_TM_STORE = 4 + + STORE_DICT = { - OK_TM_STORE: "OK Store (Verification)", - NOT_OK_TM_STORE: "NOT OK Store (Events, Verification Failures..)", - MISC_TM_STORE: "Miscellaneous Store", - HK_TM_STORE: "HK TM Store", - CFDP_TM_STORE: "CFDP TM Store", + TmStoreSelect.OK_TM_STORE: (OK_TM_STORE, "OK Store (Verification)"), + TmStoreSelect.NOT_OK_TM_STORE: (NOT_OK_TM_STORE, "NOT OK Store (Events, Verification Failures..)"), + TmStoreSelect.MISC_TM_STORE: (MISC_TM_STORE, "Miscellaneous Store"), + TmStoreSelect.HK_TM_STORE: (HK_TM_STORE, "HK TM Store"), + TmStoreSelect.CFDP_TM_STORE: (CFDP_TM_STORE, "CFDP TM Store"), } @@ -135,17 +144,18 @@ 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, v)}) - print(f" {idx}: {v}") + for k, v in STORE_DICT.items(): + print(f" {k}: {v[1]}") while True: target_index = int( input("Please enter the target store for the TM store transaction: ") ) - obj_id_and_store_str = idx_to_obj_id.get(target_index) - if obj_id_and_store_str is None: + desc_and_obj_id = STORE_DICT.get(TmStoreSelect(target_index)) + if desc_and_obj_id is None: _LOGGER.warning("Invalid index. Try again") continue break - obj_id_raw = obj_id_and_store_str[0] - return obj_id_dict.get(obj_id_raw), obj_id_and_store_str[1] + obj_id_raw = desc_and_obj_id[0] + obj_id = obj_id_dict.get(obj_id_raw) + print(f"Selected store: {obj_id} ({desc_and_obj_id[1]})") + return obj_id_dict.get(obj_id_raw), desc_and_obj_id[1]