From d00738a155dfc824d3a897ac56ec195b02762d0f Mon Sep 17 00:00:00 2001
From: "Robin.Mueller" <robin.mueller.m@gmail.com>
Date: Sat, 31 Oct 2020 01:15:45 +0100
Subject: [PATCH] refactoring continued

---
 .../tmtcclient_Service_17_QEMU.xml            |  2 +-
 .../tmtcclient_Service_2_QEMU.xml             |  2 +-
 .../tmtcclient_Service_3_QEMU_.xml            |  2 +-
 .../tmtcclient_Service_5_QEMU_.xml            |  2 +-
 .../tmtcclient_Service_Dummy_QEMU.xml         |  2 +-
 .../tmtcclient_Service_GPS0_QEMU__.xml        |  2 +-
 .../tmtcclient_Service_GPS1_QEMU___.xml       |  2 +-
 core/tmtc_backend.py                          |  3 ++
 core/tmtc_client_core.py                      | 35 +++++++++----------
 core/tmtc_frontend.py                         | 14 ++++----
 10 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/.idea/runConfigurations/tmtcclient_Service_17_QEMU.xml b/.idea/runConfigurations/tmtcclient_Service_17_QEMU.xml
index 95d5fd3..7ea51c0 100644
--- a/.idea/runConfigurations/tmtcclient_Service_17_QEMU.xml
+++ b/.idea/runConfigurations/tmtcclient_Service_17_QEMU.xml
@@ -12,7 +12,7 @@
     <option name="ADD_CONTENT_ROOTS" value="true" />
     <option name="ADD_SOURCE_ROOTS" value="true" />
     <EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
-    <option name="SCRIPT_NAME" value="$PROJECT_DIR$/core/tmtc_client_core.py" />
+    <option name="SCRIPT_NAME" value="$PROJECT_DIR$/tmtc_client_cli.py" />
     <option name="PARAMETERS" value="-m 3 -s 17 -c 2 -t 2" />
     <option name="SHOW_COMMAND_LINE" value="false" />
     <option name="EMULATE_TERMINAL" value="false" />
diff --git a/.idea/runConfigurations/tmtcclient_Service_2_QEMU.xml b/.idea/runConfigurations/tmtcclient_Service_2_QEMU.xml
index 30390e9..dd37495 100644
--- a/.idea/runConfigurations/tmtcclient_Service_2_QEMU.xml
+++ b/.idea/runConfigurations/tmtcclient_Service_2_QEMU.xml
@@ -12,7 +12,7 @@
     <option name="ADD_CONTENT_ROOTS" value="true" />
     <option name="ADD_SOURCE_ROOTS" value="true" />
     <EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
-    <option name="SCRIPT_NAME" value="$PROJECT_DIR$/core/tmtc_client_core.py" />
+    <option name="SCRIPT_NAME" value="$PROJECT_DIR$/tmtc_client_cli.py" />
     <option name="PARAMETERS" value="-m 3 -s 2 -c 2 -t 2.5" />
     <option name="SHOW_COMMAND_LINE" value="false" />
     <option name="EMULATE_TERMINAL" value="true" />
diff --git a/.idea/runConfigurations/tmtcclient_Service_3_QEMU_.xml b/.idea/runConfigurations/tmtcclient_Service_3_QEMU_.xml
index 9d4be2a..621b333 100644
--- a/.idea/runConfigurations/tmtcclient_Service_3_QEMU_.xml
+++ b/.idea/runConfigurations/tmtcclient_Service_3_QEMU_.xml
@@ -12,7 +12,7 @@
     <option name="ADD_CONTENT_ROOTS" value="true" />
     <option name="ADD_SOURCE_ROOTS" value="true" />
     <EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
-    <option name="SCRIPT_NAME" value="$PROJECT_DIR$/core/tmtc_client_core.py" />
+    <option name="SCRIPT_NAME" value="$PROJECT_DIR$/tmtc_client_cli.py" />
     <option name="PARAMETERS" value="-m 3 -s 3 -c 2 -t 2 --hk" />
     <option name="SHOW_COMMAND_LINE" value="false" />
     <option name="EMULATE_TERMINAL" value="true" />
diff --git a/.idea/runConfigurations/tmtcclient_Service_5_QEMU_.xml b/.idea/runConfigurations/tmtcclient_Service_5_QEMU_.xml
index 2458e89..9d97d32 100644
--- a/.idea/runConfigurations/tmtcclient_Service_5_QEMU_.xml
+++ b/.idea/runConfigurations/tmtcclient_Service_5_QEMU_.xml
@@ -12,7 +12,7 @@
     <option name="ADD_CONTENT_ROOTS" value="true" />
     <option name="ADD_SOURCE_ROOTS" value="true" />
     <EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
-    <option name="SCRIPT_NAME" value="$PROJECT_DIR$/core/tmtc_client_core.py" />
+    <option name="SCRIPT_NAME" value="$PROJECT_DIR$/tmtc_client_cli.py" />
     <option name="PARAMETERS" value="-m 3 -s 5 -c 2 -t 2" />
     <option name="SHOW_COMMAND_LINE" value="false" />
     <option name="EMULATE_TERMINAL" value="true" />
diff --git a/.idea/runConfigurations/tmtcclient_Service_Dummy_QEMU.xml b/.idea/runConfigurations/tmtcclient_Service_Dummy_QEMU.xml
index 1ca4f2f..f7d6fee 100644
--- a/.idea/runConfigurations/tmtcclient_Service_Dummy_QEMU.xml
+++ b/.idea/runConfigurations/tmtcclient_Service_Dummy_QEMU.xml
@@ -12,7 +12,7 @@
     <option name="ADD_CONTENT_ROOTS" value="true" />
     <option name="ADD_SOURCE_ROOTS" value="true" />
     <EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
-    <option name="SCRIPT_NAME" value="$PROJECT_DIR$/core/tmtc_client_core.py" />
+    <option name="SCRIPT_NAME" value="$PROJECT_DIR$/tmtc_client_cli.py" />
     <option name="PARAMETERS" value="-m 3 -s Dummy -c 2 -t 2" />
     <option name="SHOW_COMMAND_LINE" value="false" />
     <option name="EMULATE_TERMINAL" value="true" />
diff --git a/.idea/runConfigurations/tmtcclient_Service_GPS0_QEMU__.xml b/.idea/runConfigurations/tmtcclient_Service_GPS0_QEMU__.xml
index 33ec970..a1e01a6 100644
--- a/.idea/runConfigurations/tmtcclient_Service_GPS0_QEMU__.xml
+++ b/.idea/runConfigurations/tmtcclient_Service_GPS0_QEMU__.xml
@@ -12,7 +12,7 @@
     <option name="ADD_CONTENT_ROOTS" value="true" />
     <option name="ADD_SOURCE_ROOTS" value="true" />
     <EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
-    <option name="SCRIPT_NAME" value="$PROJECT_DIR$/core/tmtc_client_core.py" />
+    <option name="SCRIPT_NAME" value="$PROJECT_DIR$/tmtc_client_cli.py" />
     <option name="PARAMETERS" value="-m 3 -s GPS0 -c 2 -t 2.5 --hk" />
     <option name="SHOW_COMMAND_LINE" value="false" />
     <option name="EMULATE_TERMINAL" value="true" />
diff --git a/.idea/runConfigurations/tmtcclient_Service_GPS1_QEMU___.xml b/.idea/runConfigurations/tmtcclient_Service_GPS1_QEMU___.xml
index 8e8b943..74f6c14 100644
--- a/.idea/runConfigurations/tmtcclient_Service_GPS1_QEMU___.xml
+++ b/.idea/runConfigurations/tmtcclient_Service_GPS1_QEMU___.xml
@@ -12,7 +12,7 @@
     <option name="ADD_CONTENT_ROOTS" value="true" />
     <option name="ADD_SOURCE_ROOTS" value="true" />
     <EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
-    <option name="SCRIPT_NAME" value="$PROJECT_DIR$/core/tmtc_client_core.py" />
+    <option name="SCRIPT_NAME" value="$PROJECT_DIR$/tmtc_client_cli.py" />
     <option name="PARAMETERS" value="-m 3 -s GPS1 -c 2 -t 2.5 --hk" />
     <option name="SHOW_COMMAND_LINE" value="false" />
     <option name="EMULATE_TERMINAL" value="true" />
diff --git a/core/tmtc_backend.py b/core/tmtc_backend.py
index 1fb0c8f..22aed03 100644
--- a/core/tmtc_backend.py
+++ b/core/tmtc_backend.py
@@ -48,6 +48,9 @@ class TmTcHandler:
             LOGGER.info("TM listener will not be started")
         atexit.register(keyboard_interrupt_handler, com_interface=self.communication_interface)
 
+    def start(self):
+        self.perform_operation()
+
     def perform_operation(self):
         """
         Periodic operation
diff --git a/core/tmtc_client_core.py b/core/tmtc_client_core.py
index 346e1ab..296ab08 100755
--- a/core/tmtc_client_core.py
+++ b/core/tmtc_client_core.py
@@ -26,12 +26,13 @@ limitations under the License.
 @manual
 Run this file with the -h flag to display options.
 """
-import time
+from multiprocessing import Process
 
 from tmtc_core.utility.obsw_logger import set_tmtc_logger, get_logger
 
 from config.obsw_config import set_globals
 from core.tmtc_backend import TmTcHandler
+from core.tmtc_frontend import TmTcFrontend
 from utility.obsw_args_parser import parse_input_arguments
 
 LOGGER = get_logger()
@@ -43,19 +44,25 @@ def run_tmtc_client(use_gui: bool):
     set_tmtc_logger()
     LOGGER.info("Starting TMTC Client")
 
-    if use_gui:
-        run_with_gui()
-
-    LOGGER.info("Parsing input arguments")
-    args = parse_input_arguments()
+    if not use_gui:
+        LOGGER.info("Parsing input arguments")
+        args = parse_input_arguments()
 
-    LOGGER.info("Setting global variables")
-    set_globals(args)
+        LOGGER.info("Setting global variables")
+        set_globals(args)
 
     LOGGER.info("Starting TMTC Handler")
-
     tmtc_handler = TmTcHandler()
-    tmtc_handler.perform_operation()
+
+
+    if use_gui:
+        LOGGER.info("Starting TMTC GUI")
+        tmtc_frontend = TmTcFrontend(tmtc_handler)
+        frontend_process = Process(target=tmtc_frontend.init_ui())
+        frontend_process.start()
+        tmtc_handler.start()
+    else:
+        tmtc_handler.start()
 
     # At some later point, the program will run permanently and be able to take commands.
     # For now we put a permanent loop here so the program
@@ -64,13 +71,5 @@ def run_tmtc_client(use_gui: bool):
         pass
 
 
-def run_with_gui():
-    while True:
-        print("GUI net fertig")
-        time.sleep(2)
-    # tmtcGui = gui.obsw_tmtc_gui.TmTcGUI()
-    # tmtcGui.run()
-    # sys.exit()
-
 
 
diff --git a/core/tmtc_frontend.py b/core/tmtc_frontend.py
index 3ed6d80..ca4d2fd 100644
--- a/core/tmtc_frontend.py
+++ b/core/tmtc_frontend.py
@@ -33,11 +33,6 @@ LOGGER = get_logger()
 # Step 1: Huge Mission Badge in Tkinter window because that is cool.
 # Step 2: Simple buttons to run servce tests around the badge.
 
-def initialize_frontend(tmtc_backend: TmTcHandler):
-    tmtc_frontend = TmTcFrontend(tmtc_backend)
-    frontend_process = Process(target=tmtc_frontend.init_ui())
-    frontend_process.start()
-
 class SingleCommandTable(QTableWidget):
     def __init__(self):
         super().__init__()
@@ -67,13 +62,16 @@ class TmTcFrontend:
     single_command_ssc: int = 20
     single_command_data: bytearray = bytearray([])
 
-    isBusy: bool
+    is_busy: bool
 
     def __init__(self, tmtc_handler: TmTcHandler):
         self.tmtc_handler = tmtc_handler
         obsw_config.G_SERVICE = 17
         obsw_config.G_COM_IF = obsw_config.ComIF.QEMU
 
+    def start(self):
+        self.init_ui()
+
     def service_index_changed(self, index: int):
         obsw_config.G_SERVICE = self.serviceList[index]
         LOGGER.info("service_test_mode_selection updated: " + str(self.serviceList[index]))
@@ -124,10 +122,10 @@ class TmTcFrontend:
 
     def handle_tm_tc_action(self):
         LOGGER.info("start tmtc_handler.handle_action")
-        self.isBusy = True
+        self.is_busy = True
         self.set_send_buttons(False)
         self.tmtc_handler.handle_action()
-        self.isBusy = False
+        self.is_busy = False
         self.set_send_buttons(True)
         LOGGER.info("finished tmtc_handler.handle_action")
 
-- 
GitLab