Skip to content
Snippets Groups Projects
Commit 540ed898 authored by Robin.Mueller's avatar Robin.Mueller
Browse files

backend improved a bit

parent 4d2b3a3e
Branches
No related tags found
No related merge requests found
...@@ -32,7 +32,7 @@ class TmTcHandler: ...@@ -32,7 +32,7 @@ class TmTcHandler:
This is the primary class which handles TMTC reception. This can be seen as the backend 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. 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.mode = init_mode
self.com_if = g.G_COM_IF self.com_if = g.G_COM_IF
# This flag could be used later to command the TMTC Client with a front-end # This flag could be used later to command the TMTC Client with a front-end
...@@ -44,6 +44,19 @@ class TmTcHandler: ...@@ -44,6 +44,19 @@ class TmTcHandler:
self.single_command_package: Tuple[bytearray, Union[None, PusTcInfo]] = bytearray(), None 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 @staticmethod
def prepare_tmtc_handler_start(init_mode: ModeList = g.ModeList.ListenerMode): def prepare_tmtc_handler_start(init_mode: ModeList = g.ModeList.ListenerMode):
tmtc_handler = TmTcHandler(init_mode) tmtc_handler = TmTcHandler(init_mode)
...@@ -56,6 +69,10 @@ class TmTcHandler: ...@@ -56,6 +69,10 @@ class TmTcHandler:
executed_handler.perform_operation() executed_handler.perform_operation()
def initialize(self): 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.tmtc_printer = TmTcPrinter(g.G_DISPLAY_MODE, g.G_PRINT_TO_FILE, True)
self.communication_interface = set_communication_interface(self.tmtc_printer) self.communication_interface = set_communication_interface(self.tmtc_printer)
self.tm_listener = TmListener( self.tm_listener = TmListener(
...@@ -74,7 +91,7 @@ class TmTcHandler: ...@@ -74,7 +91,7 @@ class TmTcHandler:
Periodic operation Periodic operation
""" """
try: try:
self.core_operation(self.one_shot_operation) self.__core_operation(self.one_shot_operation)
except KeyboardInterrupt: except KeyboardInterrupt:
LOGGER.info("Closing TMTC client.") LOGGER.info("Closing TMTC client.")
sys.exit() sys.exit()
...@@ -83,19 +100,7 @@ class TmTcHandler: ...@@ -83,19 +100,7 @@ class TmTcHandler:
LOGGER.info("Closing TMTC client.") LOGGER.info("Closing TMTC client.")
sys.exit() sys.exit()
def core_operation(self, one_shot): def __handle_action(self):
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):
""" """
Command handling. Command handling.
""" """
...@@ -167,6 +172,19 @@ class TmTcHandler: ...@@ -167,6 +172,19 @@ class TmTcHandler:
logging.error("Unknown Mode, Configuration error !") logging.error("Unknown Mode, Configuration error !")
sys.exit() 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): def prompt_mode(self):
next_mode = input("Please enter next mode (enter h for list of modes): ") next_mode = input("Please enter next mode (enter h for list of modes): ")
if next_mode == 'h': if next_mode == 'h':
......
...@@ -99,7 +99,7 @@ class TmTcFrontend: ...@@ -99,7 +99,7 @@ class TmTcFrontend:
LOGGER.info("start tmtc_handler.handle_action") LOGGER.info("start tmtc_handler.handle_action")
self.is_busy = True self.is_busy = True
self.set_send_buttons(False) self.set_send_buttons(False)
self.tmtc_handler.handle_action() self.tmtc_handler.__handle_action()
self.is_busy = False self.is_busy = False
self.set_send_buttons(True) self.set_send_buttons(True)
LOGGER.info("finished tmtc_handler.handle_action") LOGGER.info("finished tmtc_handler.handle_action")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment