diff --git a/core/tmtc_backend.py b/core/tmtc_backend.py index 322e7a125a578197eeaf279b18cf28d942b74188..1f80b5242576a130491c9d08e55a7af86d089d47 100644 --- a/core/tmtc_backend.py +++ b/core/tmtc_backend.py @@ -2,7 +2,7 @@ import atexit import time import logging import sys -from multiprocessing import Process +from multiprocessing import Process, Value from collections import deque from config import obsw_config as g from config.obsw_definitions import ModeList @@ -50,8 +50,21 @@ class TmTcHandler: LOGGER.info("TM listener will not be started") atexit.register(keyboard_interrupt_handler, com_interface=self.communication_interface) - def prepare_start(self) -> Process: - return Process(target=self.perform_operation) + @staticmethod + def prepare_tmtc_handler_start_in_process(init_mode: ModeList): + tmtc_handler_task = Process(target=TmTcHandler.start_tmtc_handler, args=(init_mode, )) + return tmtc_handler_task + + @staticmethod + def start_tmtc_handler(handler_args: any): + tmtc_handler = TmTcHandler(handler_args) + tmtc_handler.perform_operation() + + @staticmethod + def prepare_tmtc_handler_start(init_mode: ModeList = g.ModeList.ListenerMode): + tmtc_handler = TmTcHandler(init_mode) + tmtc_task = Process(target=start_tmtc_handler, args=(tmtc_handler, )) + return tmtc_handler, tmtc_task def perform_operation(self): """ @@ -96,7 +109,6 @@ class TmTcHandler: else: LOGGER.info("send package from gui") pus_packet_tuple = self.single_command_package - sender_and_receiver = SingleCommandSenderReceiver( com_interface=self.communication_interface, tmtc_printer=self.tmtc_printer, tm_listener=self.tm_listener) @@ -174,4 +186,7 @@ def command_preparation() -> Tuple[bytearray, Union[None, PusTcInfo]]: Prepare command for single command testing :return: """ - return command_preparation_hook() \ No newline at end of file + return command_preparation_hook() + +def start_tmtc_handler(executing_task: TmTcHandler): + executing_task.perform_operation() \ No newline at end of file diff --git a/core/tmtc_client_core.py b/core/tmtc_client_core.py index 70dcffea83af12974dfa9e1d912a31420cc81e4f..634c82f6384670a71bef7701c5e319e9707b9105 100755 --- a/core/tmtc_client_core.py +++ b/core/tmtc_client_core.py @@ -51,22 +51,31 @@ def run_tmtc_client(use_gui: bool): set_globals(args) LOGGER.info("Starting TMTC Handler") - if use_gui: - tmtc_handler = TmTcHandler() + + # Experimental. Right now, creating the class outside of the process leads to issues.. + create_task_in_process = False + + tmtc_handler = TmTcHandler + tmtc_frontend_task = Process + + if create_task_in_process: + # Currently does not work, problems with QEMU / Asyncio + if not use_gui: + tmtc_handler, tmtc_handler_task = TmTcHandler.prepare_tmtc_handler_start(g.G_MODE_ID) + else: + tmtc_handler, tmtc_handler_task = TmTcHandler.prepare_tmtc_handler_start() else: - tmtc_handler = TmTcHandler(g.G_MODE_ID) + tmtc_handler_task = TmTcHandler.prepare_tmtc_handler_start_in_process(g.G_MODE_ID) - # tmtc_handler_task = tmtc_handler.prepare_start() - tmtc_frontend_task = Process() - if use_gui: - tmtc_frontend = TmTcFrontend(tmtc_handler) - tmtc_frontend_task = tmtc_frontend.prepare_start() - tmtc_frontend_task.start() - # tmtc_handler_task.start() - tmtc_handler.perform_operation() + if create_task_in_process: + if use_gui: + tmtc_frontend = TmTcFrontend(tmtc_handler) + tmtc_frontend_task = tmtc_frontend.prepare_start(tmtc_frontend) + tmtc_frontend_task.start() + tmtc_handler_task.start() - # tmtc_handler_task.join() + tmtc_handler_task.join() if use_gui: tmtc_frontend_task.join() diff --git a/core/tmtc_frontend.py b/core/tmtc_frontend.py index c84073128ff638e321eac0277261a2f8fe853c94..2f5fba95ecd69128427531f58f62b322e147eb2a 100644 --- a/core/tmtc_frontend.py +++ b/core/tmtc_frontend.py @@ -44,7 +44,7 @@ class TmTcFrontend: obsw_config.G_SERVICE = 17 obsw_config.G_COM_IF = obsw_config.ComInterfaces.QEMU - def prepare_start(self) -> Process: + def prepare_start(self, args: any) -> Process: return Process(target=self.start_ui) def service_index_changed(self, index: int):