Skip to content
Snippets Groups Projects
Commit 70a4e4e3 authored by Robin Mueller's avatar Robin Mueller
Browse files

some more refactoring

parent 28af57e3
No related branches found
No related tags found
No related merge requests found
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<option name="ADD_CONTENT_ROOTS" value="true" /> <option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" /> <option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" /> <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="PARAMETERS" value="-m 3 -s 8 -c 2 -t 2.5" />
<option name="SHOW_COMMAND_LINE" value="false" /> <option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="true" /> <option name="EMULATE_TERMINAL" value="true" />
......
...@@ -36,7 +36,7 @@ class TmTcHandler: ...@@ -36,7 +36,7 @@ class TmTcHandler:
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
self.command_received = True self.one_shot_operation = True
self.tmtc_printer: Union[None, TmTcPrinter] = None self.tmtc_printer: Union[None, TmTcPrinter] = None
self.communication_interface: Union[None, CommunicationInterface] = None self.communication_interface: Union[None, CommunicationInterface] = None
...@@ -73,23 +73,27 @@ class TmTcHandler: ...@@ -73,23 +73,27 @@ class TmTcHandler:
""" """
Periodic operation Periodic operation
""" """
while True: try:
try: self.core_operation(self.one_shot_operation)
if self.command_received: except KeyboardInterrupt:
self.command_received = False LOGGER.info("Closing TMTC client.")
self.handle_action() 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: if self.mode == g.ModeList.Idle:
LOGGER.info("TMTC Client in idle mode") LOGGER.info("TMTC Client in idle mode")
time.sleep(5) time.sleep(5)
elif self.mode == g.ModeList.ListenerMode: elif self.mode == g.ModeList.ListenerMode:
time.sleep(1) time.sleep(1)
except KeyboardInterrupt: else:
LOGGER.info("Closing TMTC client.") self.handle_action()
sys.exit()
except IOError as e:
LOGGER.exception(e)
LOGGER.info("Closing TMTC client.")
sys.exit()
def handle_action(self): def handle_action(self):
""" """
...@@ -104,7 +108,6 @@ class TmTcHandler: ...@@ -104,7 +108,6 @@ class TmTcHandler:
self.tmtc_printer.print_telemetry_queue(self.tm_listener.retrieve_tm_packet_queue()) self.tmtc_printer.print_telemetry_queue(self.tm_listener.retrieve_tm_packet_queue())
self.tm_listener.clear_tm_packet_queue() self.tm_listener.clear_tm_packet_queue()
self.tm_listener.clear_reply_event() self.tm_listener.clear_reply_event()
self.command_received = True
elif self.mode == g.ModeList.SingleCommandMode: elif self.mode == g.ModeList.SingleCommandMode:
if self.single_command_package is None: if self.single_command_package is None:
...@@ -117,7 +120,6 @@ class TmTcHandler: ...@@ -117,7 +120,6 @@ class TmTcHandler:
tm_listener=self.tm_listener) tm_listener=self.tm_listener)
LOGGER.info("Performing single command operation") LOGGER.info("Performing single command operation")
sender_and_receiver.send_single_tc_and_receive_tm(pus_packet_tuple=pus_packet_tuple) sender_and_receiver.send_single_tc_and_receive_tm(pus_packet_tuple=pus_packet_tuple)
self.command_received = True
self.mode = g.ModeList.PromptMode self.mode = g.ModeList.PromptMode
elif self.mode == g.ModeList.ServiceTestMode: elif self.mode == g.ModeList.ServiceTestMode:
...@@ -133,7 +135,6 @@ class TmTcHandler: ...@@ -133,7 +135,6 @@ class TmTcHandler:
com_interface=self.communication_interface, tmtc_printer=self.tmtc_printer, com_interface=self.communication_interface, tmtc_printer=self.tmtc_printer,
tm_listener=self.tm_listener, tc_queue=service_queue) tm_listener=self.tm_listener, tc_queue=service_queue)
sender_and_receiver.send_queue_tc_and_receive_tm_sequentially() sender_and_receiver.send_queue_tc_and_receive_tm_sequentially()
self.command_received = True
self.mode = g.ModeList.ListenerMode self.mode = g.ModeList.ListenerMode
elif self.mode == g.ModeList.SoftwareTestMode: elif self.mode == g.ModeList.SoftwareTestMode:
...@@ -152,7 +153,6 @@ class TmTcHandler: ...@@ -152,7 +153,6 @@ class TmTcHandler:
file_uploader = BinaryFileUploader(self.communication_interface, self.tmtc_printer, file_uploader = BinaryFileUploader(self.communication_interface, self.tmtc_printer,
self.tm_listener) self.tm_listener)
file_uploader.perform_file_upload() file_uploader.perform_file_upload()
self.command_received = True
self.mode = g.ModeList.ListenerMode self.mode = g.ModeList.ListenerMode
elif self.mode == g.ModeList.UnitTest: elif self.mode == g.ModeList.UnitTest:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment