diff --git a/obsw_tmtc_client.py b/obsw_tmtc_client.py index d4c97f195a27b7f2634072a8afabf04d1b643f22..23ff7ac84d152fddbc64f7d4f68aecd8b550acfb 100644 --- a/obsw_tmtc_client.py +++ b/obsw_tmtc_client.py @@ -118,11 +118,15 @@ class TmTcHandler: def perform_operation(self): while True: - if self.command_received: - self.handle_action() - self.command_received = False - logger.info("TMTC Client in idle mode") - time.sleep(5) + try: + if self.command_received: + self.handle_action() + self.command_received = False + logger.info("TMTC Client in idle mode") + time.sleep(5) + except (IOError, KeyboardInterrupt): + logger.info("Closing TMTC client.") + def handle_action(self): tmtc_printer = TmTcPrinter(g.G_DISPLAY_MODE, g.G_PRINT_TO_FILE, True) @@ -137,7 +141,7 @@ class TmTcHandler: sys.exit() else: communication_interface = set_communication_interface(tmtc_printer) - atexit.register(keyboard_interrupt_handler, comInterface=communication_interface) + atexit.register(keyboard_interrupt_handler, com_interface=communication_interface) tm_listener = TmListener( com_interface=communication_interface, tm_timeout=g.G_TM_TIMEOUT, tc_timeout_factor=g.G_TC_SEND_TIMEOUT_FACTOR) diff --git a/sendreceive/obsw_multiple_commands_sender_receiver.py b/sendreceive/obsw_multiple_commands_sender_receiver.py index aee4dab16051df50fa82b82714e87801e3d87f9f..8e7f67dd5979544eec9e91d9d981a16c8d699b9d 100644 --- a/sendreceive/obsw_multiple_commands_sender_receiver.py +++ b/sendreceive/obsw_multiple_commands_sender_receiver.py @@ -15,7 +15,9 @@ from comIF.obsw_com_interface import CommunicationInterface from utility.obsw_tmtc_printer import TmTcPrinter from sendreceive.obsw_tm_listener import TmListenerT import config.obsw_config as g +from utility.obsw_tmtc_printer import get_logger +logger = get_logger() class MultipleCommandSenderReceiver(SequentialCommandSenderReceiver): """ @@ -61,7 +63,7 @@ class MultipleCommandSenderReceiver(SequentialCommandSenderReceiver): if g.G_PRINT_TO_FILE: self._tmtc_printer.print_to_file() except (KeyboardInterrupt, SystemExit): - print("Keyboard Interrupt or System Exit detected") + logger.info("Closing TMTC Client") exit() return self.tcInfoQueue, self.tmTupleQueue diff --git a/sendreceive/obsw_sequential_sender_receiver.py b/sendreceive/obsw_sequential_sender_receiver.py index 0bce546b78728cea594a073af899f03adbc4eb1f..83ba8d49b0007463dbbf1780cc1bf869a2e9cb9a 100644 --- a/sendreceive/obsw_sequential_sender_receiver.py +++ b/sendreceive/obsw_sequential_sender_receiver.py @@ -50,9 +50,8 @@ class SequentialCommandSenderReceiver(CommandSenderReceiver): try: self.__handle_tc_sending() except (KeyboardInterrupt, SystemExit): - print("Keyboard Interrupt or System Exit detected") + logger.info("Closing TMTC Client") sys.exit() - # self.handleInterrupt(receiverThread) def __handle_tc_sending(self): while not self.__all_replies_received: diff --git a/utility/obsw_exit_handler.py b/utility/obsw_exit_handler.py index 38232e919b3a20fe9a78e0003246a1ffef0b17a7..ff9990b6f4693ee2ca6a72fd62bb9d729d1e71a2 100644 --- a/utility/obsw_exit_handler.py +++ b/utility/obsw_exit_handler.py @@ -1,6 +1,8 @@ import signal from comIF.obsw_com_interface import CommunicationInterface +from utility.obsw_logger import get_logger +logger = get_logger() class GracefulKiller: kill_now = False @@ -14,9 +16,9 @@ class GracefulKiller: print("I was killed") -def keyboard_interrupt_handler(comInterface: CommunicationInterface): - print("Disconnect registered") +def keyboard_interrupt_handler(com_interface: CommunicationInterface): + logger.info("Disconnect registered") # Unit Test closes Serial Port at the end # We could do some optional stuff here - if comInterface is not None: - comInterface.send_telecommand(bytearray([0, 0, 0, 0, 0])) + if com_interface is not None: + com_interface.send_telecommand(bytearray([0, 0, 0, 0, 0]))