added store enum

This commit is contained in:
Robin Müller 2023-02-17 19:22:56 +01:00
parent ab9f2ca05d
commit 676f851659
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC

View File

@ -1,4 +1,5 @@
import datetime import datetime
import enum
import logging import logging
import math import math
import struct 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 = { STORE_DICT = {
OK_TM_STORE: "OK Store (Verification)", TmStoreSelect.OK_TM_STORE: (OK_TM_STORE, "OK Store (Verification)"),
NOT_OK_TM_STORE: "NOT OK Store (Events, Verification Failures..)", TmStoreSelect.NOT_OK_TM_STORE: (NOT_OK_TM_STORE, "NOT OK Store (Events, Verification Failures..)"),
MISC_TM_STORE: "Miscellaneous Store", TmStoreSelect.MISC_TM_STORE: (MISC_TM_STORE, "Miscellaneous Store"),
HK_TM_STORE: "HK TM Store", TmStoreSelect.HK_TM_STORE: (HK_TM_STORE, "HK TM Store"),
CFDP_TM_STORE: "CFDP 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() obj_id_dict = get_object_ids()
print("Available TM stores:") print("Available TM stores:")
idx_to_obj_id = dict() idx_to_obj_id = dict()
for idx, (k, v) in enumerate(STORE_DICT.items()): for k, v in STORE_DICT.items():
idx_to_obj_id.update({idx: (k, v)}) print(f" {k}: {v[1]}")
print(f" {idx}: {v}")
while True: while True:
target_index = int( target_index = int(
input("Please enter the target store for the TM store transaction: ") input("Please enter the target store for the TM store transaction: ")
) )
obj_id_and_store_str = idx_to_obj_id.get(target_index) desc_and_obj_id = STORE_DICT.get(TmStoreSelect(target_index))
if obj_id_and_store_str is None: if desc_and_obj_id is None:
_LOGGER.warning("Invalid index. Try again") _LOGGER.warning("Invalid index. Try again")
continue continue
break break
obj_id_raw = obj_id_and_store_str[0] obj_id_raw = desc_and_obj_id[0]
return obj_id_dict.get(obj_id_raw), obj_id_and_store_str[1] 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]