diff --git a/comIF/obsw_com_config.py b/comIF/obsw_com_config.py index 1b59adb7d32a1cdfd1299bee73e11d416d500254..4810be9050bb7427b8acab9317a407ed71cae56f 100644 --- a/comIF/obsw_com_config.py +++ b/comIF/obsw_com_config.py @@ -2,6 +2,7 @@ Set-up function. Initiates the communication interface. """ import sys +from typing import Union from comIF.obsw_com_interface import CommunicationInterface from comIF.obsw_dummy_com_if import DummyComIF @@ -17,7 +18,7 @@ import config.obsw_config as g LOGGER = get_logger() -def set_communication_interface(tmtc_printer: TmTcPrinter) -> CommunicationInterface: +def set_communication_interface(tmtc_printer: TmTcPrinter) -> Union[CommunicationInterface, None]: """ Return the desired communication interface object :param tmtc_printer: TmTcPrinter object. diff --git a/comIF/obsw_serial_com_if.py b/comIF/obsw_serial_com_if.py index 83c2ca7f44064332e1c07b78b319da5ab1da1fae..ccecaa04ed8f627b5b6f967f839aca637797f0ce 100644 --- a/comIF/obsw_serial_com_if.py +++ b/comIF/obsw_serial_com_if.py @@ -10,6 +10,8 @@ from typing import Tuple from enum import Enum import serial +import serial.tools.list_ports + from comIF.obsw_com_interface import CommunicationInterface from utility.obsw_tmtc_printer import TmTcPrinter from tm.obsw_pus_tm_factory import PusTelemetryFactory, PusTmListT @@ -47,12 +49,15 @@ class SerialComIF(CommunicationInterface): :param ser_com_type: Specify how to handle serial reception """ super().__init__(tmtc_printer) + if com_port is None: + com_port = self.prompt_com_port() + self.valid = False try: self.serial = serial.Serial(port=com_port, baudrate=baud_rate, timeout=serial_timeout) 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: @@ -64,6 +69,17 @@ class SerialComIF(CommunicationInterface): # threads use the deque pass + def prompt_com_port(self): + com_port = input( + "Serial Commuinication specified without COM port. Please enter COM Port" + "(enter h to display list of COM ports): ") + if com_port == 'h': + ports = serial.tools.list_ports.comports() + for port, desc, hwid in sorted(ports): + print("{}: {} [{}]".format(port, desc, hwid)) + com_port = self.prompt_com_port() + return com_port + def close(self): try: self.serial.close() diff --git a/utility/obsw_args_parser.py b/utility/obsw_args_parser.py index 01bc892f2019629c0fa3406a904c5c8a784b7600..67a6fc02ba0eeb5053e73f6426664124436b725e 100644 --- a/utility/obsw_args_parser.py +++ b/utility/obsw_args_parser.py @@ -86,9 +86,6 @@ def handle_unspecified_args(args) -> None: """ if args.com_if == 1 and args.tm_timeout is None: args.tm_timeout = 6.0 - if args.com_if == 1 and args.com_port is None: - args.com_port = input("Serial Commuinication specified without COM port. " - "Please enter COM Port: ") if args.mode is None: print("No mode specified with -m Parameter.") print("Possible Modes: ") diff --git a/utility/obsw_binary_uploader.py b/utility/obsw_binary_uploader.py index 979ee2f6b2dda068d69cb542155fa6c938032726..4b5b55220e8449a6d63981963f79f147c6840a61 100644 --- a/utility/obsw_binary_uploader.py +++ b/utility/obsw_binary_uploader.py @@ -13,6 +13,21 @@ from tkinter import filedialog def perform_binary_upload(): root = tk.Tk() root.withdraw() + root.wm_attributes('-topmost', 1) + print("Please select file to upload") + file_path = filedialog.askopenfilename(parent=root) + print("File select: " + str(file_path)) + calc_hamming_code = input("Calculate and send hamming code? [y/n]") + if calc_hamming_code in ['y', 'yes', 1]: + calc_hamming_code = True + print("Hamming code will be calculated and sent in tail packet") + else: + calc_hamming_code = False + print("Hamming code will not be calculated") + + if calc_hamming_code: + # now we calculate the hamming code + pass + + # We have to split the binary here first - file_path = filedialog.askopenfilename() - print(file_path)