diff --git a/comIF/obsw_com_config.py b/comIF/obsw_com_config.py index ea5bdcadf5f4435cc48e64807d6ccdc758090042..1b59adb7d32a1cdfd1299bee73e11d416d500254 100644 --- a/comIF/obsw_com_config.py +++ b/comIF/obsw_com_config.py @@ -44,6 +44,9 @@ def set_communication_interface(tmtc_printer: TmTcPrinter) -> CommunicationInter tc_timeout_factor=g.G_TC_SEND_TIMEOUT_FACTOR) else: communication_interface = DummyComIF(tmtc_printer=tmtc_printer) + if not communication_interface.valid: + LOGGER.warning("Invalid communication interface!") + return None return communication_interface except (IOError, OSError): LOGGER.error("Error setting up communication interface") diff --git a/comIF/obsw_com_interface.py b/comIF/obsw_com_interface.py index d2a4090adce1f439aae6f31013b22fce2d7accbf..4567bb2c01e42f24e7da715e7552b6ebff11249e 100644 --- a/comIF/obsw_com_interface.py +++ b/comIF/obsw_com_interface.py @@ -24,6 +24,7 @@ class CommunicationInterface: """ def __init__(self, tmtc_printer: TmTcPrinter): self.tmtc_printer = tmtc_printer + self.valid = False @abstractmethod def close(self) -> None: diff --git a/comIF/obsw_serial_com_if.py b/comIF/obsw_serial_com_if.py index 39751d9b59354b8acb737a904999ac5afb223b0b..83c2ca7f44064332e1c07b78b319da5ab1da1fae 100644 --- a/comIF/obsw_serial_com_if.py +++ b/comIF/obsw_serial_com_if.py @@ -49,8 +49,10 @@ class SerialComIF(CommunicationInterface): super().__init__(tmtc_printer) try: self.serial = serial.Serial(port=com_port, baudrate=baud_rate, timeout=serial_timeout) - except serial.SerialException as error: - LOGGER.exception("Serial Port could not be closed! Traceback: %s", str(error)) + self.valid = True + except serial.SerialException: + LOGGER.error("Serial Port opening failure!") + self.valid = False self.data = bytearray() self.ser_com_type = ser_com_type if self.ser_com_type == SerialCommunicationType.FIXED_FRAME_BASED: diff --git a/obsw_tmtc_client.py b/obsw_tmtc_client.py index b78431fe455510aab06dc5facfe113e4df423562..0faefe606d18573b35e9c5af0b7e05f45912422d 100755 --- a/obsw_tmtc_client.py +++ b/obsw_tmtc_client.py @@ -141,12 +141,21 @@ class TmTcHandler: # This flag could be used later to command the TMTC Client with a front-end self.command_received = True self.tmtc_printer = TmTcPrinter(g.G_DISPLAY_MODE, g.G_PRINT_TO_FILE, True) + self.communication_interface = None + self.tm_listener = None + self.initialize_com_if_and_listener() + atexit.register(keyboard_interrupt_handler, com_interface=self.communication_interface) + + def initialize_com_if_and_listener(self): self.communication_interface = set_communication_interface(self.tmtc_printer) + if self.communication_interface is None: + LOGGER.info("No communication interface set for now") + LOGGER.info("TM listener will not be started") + return self.tm_listener = TmListener( com_interface=self.communication_interface, tm_timeout=g.G_TM_TIMEOUT, tc_timeout_factor=g.G_TC_SEND_TIMEOUT_FACTOR ) - atexit.register(keyboard_interrupt_handler, com_interface=self.communication_interface) self.tm_listener.start() def perform_operation(self): @@ -169,8 +178,7 @@ class TmTcHandler: Command handling. """ if self.mode == g.ModeList.ListenerMode: - if self.tm_listener.event_reply_received: - # TODO: Test this. + if self.tm_listener.event_reply_received.is_set(): LOGGER.info("TmTcHandler: Packets received.") self.tmtc_printer.print_telemetry_queue(self.tm_listener.retrieve_tm_packet_queue()) self.command_received = True @@ -206,6 +214,7 @@ class TmTcHandler: # mode perform_binary_upload() self.command_received = True + self.prompt_mode() elif self.mode == g.ModeList.UnitTest: # Set up test suite and run it with runner. Verbosity specifies detail level @@ -221,6 +230,22 @@ class TmTcHandler: logging.error("Unknown Mode, Configuration error !") sys.exit() + def prompt_mode(self): + next_mode = input("Please enter next mode (enter h for list of modes): ") + if next_mode == 'h': + print("Mode 0: GUI mode") + print("Mode 1: Listener mode") + print("Mode 2: Single Command mode") + print("Mode 3: Service mode") + print("Mode 4: Software mode") + print("Mode 5: Binary upload mode") + print("Mode 5: Module test mode") + self.prompt_mode() + elif next_mode == 1: + self.mode = g.ModeList.ListenerMode + else: + self.mode = g.ModeList.ListenerMode + if __name__ == "__main__": main() diff --git a/obsw_user_code.py b/obsw_user_code.py index c66b02445e5812bf0eb7615f1b152b74e0e46a32..6b6f6639c3e2014a54e00669714820ea2d2b515d 100644 --- a/obsw_user_code.py +++ b/obsw_user_code.py @@ -9,6 +9,7 @@ from enum import Enum # Yeah, I did not have a better idea yet.. # Next step would be a configuration file +# Or extracting the core into a separate repository to decouple the custom code from the core code class Developer(Enum): Robin = 0 diff --git a/utility/obsw_binary_uploader.py b/utility/obsw_binary_uploader.py index d0872b97790882b1f6bd0d8ef052799a1e5ae145..979ee2f6b2dda068d69cb542155fa6c938032726 100644 --- a/utility/obsw_binary_uploader.py +++ b/utility/obsw_binary_uploader.py @@ -6,7 +6,13 @@ This module will be used to upload binaries to the OBC via a communication port, a supplied binary. The binary will be sent via the specified communication interface. It will be possible to encode the data (for example using DLE encoding) """ +import tkinter as tk +from tkinter import filedialog def perform_binary_upload(): - print("Test!") + root = tk.Tk() + root.withdraw() + + file_path = filedialog.askopenfilename() + print(file_path)