From 540ed898103d9fc663e8e44d9f482ee06b5f6fc3 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" <robin.mueller.m@gmail.com> Date: Sat, 31 Oct 2020 16:51:11 +0100 Subject: [PATCH] backend improved a bit --- core/tmtc_backend.py | 48 +++++++++++++++++++++++++++++-------------- core/tmtc_frontend.py | 2 +- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/core/tmtc_backend.py b/core/tmtc_backend.py index 1bf7769..3936828 100644 --- a/core/tmtc_backend.py +++ b/core/tmtc_backend.py @@ -32,7 +32,7 @@ class TmTcHandler: This is the primary class which handles TMTC reception. This can be seen as the backend in case a GUI or front-end is implemented. """ - def __init__(self, init_mode: ModeList = g.ModeList.ListenerMode): + def __init__(self, init_mode: ModeList = ModeList.ListenerMode): self.mode = init_mode self.com_if = g.G_COM_IF # This flag could be used later to command the TMTC Client with a front-end @@ -44,6 +44,19 @@ class TmTcHandler: self.single_command_package: Tuple[bytearray, Union[None, PusTcInfo]] = bytearray(), None + def set_one_shot_or_loop_handling(self, enable: bool): + """ + Specify whether the perform_operation() call will only handle one action depending + on the mode or keep listening for replies after handling an operation. + """ + self.one_shot_operation = enable + + def set_mode(self, mode: ModeList): + """ + Set the mode which will determine what perform_operation does. + """ + self.mode = mode + @staticmethod def prepare_tmtc_handler_start(init_mode: ModeList = g.ModeList.ListenerMode): tmtc_handler = TmTcHandler(init_mode) @@ -56,6 +69,10 @@ class TmTcHandler: executed_handler.perform_operation() def initialize(self): + """ + Perform initialization steps which might be necessary after class construction. + This has to be called at some point before using the class! + """ self.tmtc_printer = TmTcPrinter(g.G_DISPLAY_MODE, g.G_PRINT_TO_FILE, True) self.communication_interface = set_communication_interface(self.tmtc_printer) self.tm_listener = TmListener( @@ -74,7 +91,7 @@ class TmTcHandler: Periodic operation """ try: - self.core_operation(self.one_shot_operation) + self.__core_operation(self.one_shot_operation) except KeyboardInterrupt: LOGGER.info("Closing TMTC client.") sys.exit() @@ -83,19 +100,7 @@ class TmTcHandler: LOGGER.info("Closing TMTC client.") sys.exit() - def core_operation(self, one_shot): - if not one_shot: - while True: - self.handle_action() - if self.mode == g.ModeList.Idle: - LOGGER.info("TMTC Client in idle mode") - time.sleep(5) - elif self.mode == g.ModeList.ListenerMode: - time.sleep(1) - else: - self.handle_action() - - def handle_action(self): + def __handle_action(self): """ Command handling. """ @@ -167,6 +172,19 @@ class TmTcHandler: logging.error("Unknown Mode, Configuration error !") sys.exit() + + def __core_operation(self, one_shot): + if not one_shot: + while True: + self.__handle_action() + if self.mode == g.ModeList.Idle: + LOGGER.info("TMTC Client in idle mode") + time.sleep(5) + elif self.mode == g.ModeList.ListenerMode: + time.sleep(1) + else: + self.__handle_action() + def prompt_mode(self): next_mode = input("Please enter next mode (enter h for list of modes): ") if next_mode == 'h': diff --git a/core/tmtc_frontend.py b/core/tmtc_frontend.py index 61a16e8..77cf71f 100644 --- a/core/tmtc_frontend.py +++ b/core/tmtc_frontend.py @@ -99,7 +99,7 @@ class TmTcFrontend: LOGGER.info("start tmtc_handler.handle_action") self.is_busy = True self.set_send_buttons(False) - self.tmtc_handler.handle_action() + self.tmtc_handler.__handle_action() self.is_busy = False self.set_send_buttons(True) LOGGER.info("finished tmtc_handler.handle_action") -- GitLab