diff --git a/.idea/runConfigurations/tmtcclient_Service_8_QEMU__.xml b/.idea/runConfigurations/tmtcclient_Service_8_QEMU__.xml index 5ce38cc5aa79623764dbf567e73c2800f9f80623..c6acd1116ef80ac6a796d560fc2a6c16256a48c9 100644 --- a/.idea/runConfigurations/tmtcclient_Service_8_QEMU__.xml +++ b/.idea/runConfigurations/tmtcclient_Service_8_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 8 -c 2 -t 2.5" /> <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 77109f6396fd0cde8e3c142e801a70d5ecfd5809..1bf776938fee9bcb374914f40faf866c3cb9c579 100644 --- a/core/tmtc_backend.py +++ b/core/tmtc_backend.py @@ -36,7 +36,7 @@ class TmTcHandler: 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 - self.command_received = True + self.one_shot_operation = True self.tmtc_printer: Union[None, TmTcPrinter] = None self.communication_interface: Union[None, CommunicationInterface] = None @@ -73,23 +73,27 @@ class TmTcHandler: """ Periodic operation """ - while True: - try: - if self.command_received: - self.command_received = False - self.handle_action() + try: + self.core_operation(self.one_shot_operation) + except KeyboardInterrupt: + LOGGER.info("Closing TMTC client.") + sys.exit() + except IOError as e: + LOGGER.exception(e) + 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) - except KeyboardInterrupt: - LOGGER.info("Closing TMTC client.") - sys.exit() - except IOError as e: - LOGGER.exception(e) - LOGGER.info("Closing TMTC client.") - sys.exit() + else: + self.handle_action() def handle_action(self): """ @@ -104,7 +108,6 @@ class TmTcHandler: self.tmtc_printer.print_telemetry_queue(self.tm_listener.retrieve_tm_packet_queue()) self.tm_listener.clear_tm_packet_queue() self.tm_listener.clear_reply_event() - self.command_received = True elif self.mode == g.ModeList.SingleCommandMode: if self.single_command_package is None: @@ -117,7 +120,6 @@ class TmTcHandler: tm_listener=self.tm_listener) LOGGER.info("Performing single command operation") sender_and_receiver.send_single_tc_and_receive_tm(pus_packet_tuple=pus_packet_tuple) - self.command_received = True self.mode = g.ModeList.PromptMode elif self.mode == g.ModeList.ServiceTestMode: @@ -133,7 +135,6 @@ class TmTcHandler: com_interface=self.communication_interface, tmtc_printer=self.tmtc_printer, tm_listener=self.tm_listener, tc_queue=service_queue) sender_and_receiver.send_queue_tc_and_receive_tm_sequentially() - self.command_received = True self.mode = g.ModeList.ListenerMode elif self.mode == g.ModeList.SoftwareTestMode: @@ -152,7 +153,6 @@ class TmTcHandler: file_uploader = BinaryFileUploader(self.communication_interface, self.tmtc_printer, self.tm_listener) file_uploader.perform_file_upload() - self.command_received = True self.mode = g.ModeList.ListenerMode elif self.mode == g.ModeList.UnitTest: