diff --git a/core/tmtc_backend.py b/core/tmtc_backend.py index 1f80b5242576a130491c9d08e55a7af86d089d47..77109f6396fd0cde8e3c142e801a70d5ecfd5809 100644 --- a/core/tmtc_backend.py +++ b/core/tmtc_backend.py @@ -2,27 +2,28 @@ import atexit import time import logging import sys -from multiprocessing import Process, Value +from multiprocessing import Process from collections import deque +from typing import Tuple, Union + from config import obsw_config as g from config.obsw_definitions import ModeList -from typing import Tuple, Union +from config.obsw_user_code import command_preparation_hook -from tc.obsw_pus_tc_packer import ServiceQueuePacker, create_total_tc_queue -from test.obsw_pus_service_test import run_selected_pus_tests from tmtc_core.utility.obsw_logger import get_logger from tmtc_core.tc.obsw_pus_tc_base import PusTcInfo from tmtc_core.sendreceive.obsw_single_command_sender_receiver import SingleCommandSenderReceiver from tmtc_core.sendreceive.obsw_sequential_sender_receiver import SequentialCommandSenderReceiver from tmtc_core.sendreceive.obsw_tm_listener import TmListener +from tmtc_core.comIF.obsw_com_interface import CommunicationInterface from tmtc_core.utility.obsw_tmtc_printer import TmTcPrinter from tmtc_core.utility.obsw_exit_handler import keyboard_interrupt_handler -from config.obsw_com_config import set_communication_interface +from tc.obsw_pus_tc_packer import ServiceQueuePacker, create_total_tc_queue +from test.obsw_pus_service_test import run_selected_pus_tests +from config.obsw_com_config import set_communication_interface from utility.obsw_binary_uploader import BinaryFileUploader -from config.obsw_user_code import command_preparation_hook - LOGGER = get_logger() @@ -36,13 +37,31 @@ class TmTcHandler: self.com_if = g.G_COM_IF # This flag could be used later to command the TMTC Client with a front-end self.command_received = True + + self.tmtc_printer: Union[None, TmTcPrinter] = None + self.communication_interface: Union[None, CommunicationInterface] = None + self.tm_listener: Union[None, TmListener] = None + + self.single_command_package: Tuple[bytearray, Union[None, PusTcInfo]] = bytearray(), None + + @staticmethod + def prepare_tmtc_handler_start(init_mode: ModeList = g.ModeList.ListenerMode): + tmtc_handler = TmTcHandler(init_mode) + tmtc_task = Process(target=TmTcHandler.start_handler, args=(tmtc_handler, )) + return tmtc_task + + @staticmethod + def start_handler(executed_handler): + executed_handler.initialize() + executed_handler.perform_operation() + + def initialize(self): 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( com_interface=self.communication_interface, tm_timeout=g.G_TM_TIMEOUT, tc_timeout_factor=g.G_TC_SEND_TIMEOUT_FACTOR ) - self.single_command_package: Tuple[bytearray, Union[None, PusTcInfo]] = bytearray(), None if self.communication_interface.valid: self.tm_listener.start() else: @@ -50,22 +69,6 @@ class TmTcHandler: LOGGER.info("TM listener will not be started") atexit.register(keyboard_interrupt_handler, com_interface=self.communication_interface) - @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): """ Periodic operation @@ -180,6 +183,18 @@ class TmTcHandler: else: self.mode = g.ModeList.ListenerMode + # These two will not be used for now. + @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.initialize() + tmtc_handler.perform_operation() + def command_preparation() -> Tuple[bytearray, Union[None, PusTcInfo]]: """ @@ -187,6 +202,3 @@ def command_preparation() -> Tuple[bytearray, Union[None, PusTcInfo]]: :return: """ 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 634c82f6384670a71bef7701c5e319e9707b9105..01ed6fd9b4ff7f8a13b656aa6275fd1ae5b21f92 100755 --- a/core/tmtc_client_core.py +++ b/core/tmtc_client_core.py @@ -52,27 +52,18 @@ def run_tmtc_client(use_gui: bool): LOGGER.info("Starting TMTC Handler") - # 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() + # Currently does not work, problems with QEMU / Asyncio + if not use_gui: + tmtc_handler_task = TmTcHandler.prepare_tmtc_handler_start(g.G_MODE_ID) else: - tmtc_handler_task = TmTcHandler.prepare_tmtc_handler_start_in_process(g.G_MODE_ID) + tmtc_handler_task = TmTcHandler.prepare_tmtc_handler_start() - - 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() + if use_gui: + tmtc_frontend = TmTcFrontend() + tmtc_frontend_task = tmtc_frontend.prepare_start(tmtc_frontend) + tmtc_frontend_task.start() tmtc_handler_task.start() tmtc_handler_task.join() diff --git a/core/tmtc_frontend.py b/core/tmtc_frontend.py index 2f5fba95ecd69128427531f58f62b322e147eb2a..61a16e8f4205afa24c2d4654843e2ccf627f2c5d 100644 --- a/core/tmtc_frontend.py +++ b/core/tmtc_frontend.py @@ -39,8 +39,8 @@ class TmTcFrontend: is_busy: bool - def __init__(self, tmtc_handler: TmTcHandler): - self.tmtc_handler = tmtc_handler + def __init__(self): + # self.tmtc_handler = tmtc_handler obsw_config.G_SERVICE = 17 obsw_config.G_COM_IF = obsw_config.ComInterfaces.QEMU @@ -63,7 +63,7 @@ class TmTcFrontend: def start_service_test_clicked(self): LOGGER.info("start service test button pressed") LOGGER.info("start testing service: " + str(obsw_config.G_SERVICE)) - self.tmtc_handler.mode = obsw_config.ModeList.ServiceTestMode + # self.tmtc_handler.mode = obsw_config.ModeList.ServiceTestMode # start the action in a new process p = threading.Thread(target=self.handle_tm_tc_action) p.start() @@ -88,9 +88,9 @@ class TmTcFrontend: command = PusTelecommand( service=self.single_command_service, subservice=self.single_command_sub_service, ssc=self.single_command_ssc) - self.tmtc_handler.single_command_package = command.pack_command_tuple() + # self.tmtc_handler.single_command_package = command.pack_command_tuple() - self.tmtc_handler.mode = obsw_config.ModeList.SingleCommandMode + # self.tmtc_handler.mode = obsw_config.ModeList.SingleCommandMode # start the action in a new process p = threading.Thread(target=self.handle_tm_tc_action) p.start() diff --git a/tmtc_core b/tmtc_core index 228d57103721942918f38b54e0b5e84f3acae427..bef5d1f8e52aff053a953e91bc287e7772ff3148 160000 --- a/tmtc_core +++ b/tmtc_core @@ -1 +1 @@ -Subproject commit 228d57103721942918f38b54e0b5e84f3acae427 +Subproject commit bef5d1f8e52aff053a953e91bc287e7772ff3148