diff --git a/Tools/HIL/monitor_firmware_upload.py b/Tools/HIL/monitor_firmware_upload.py index 9388e0fea0..27309b8639 100755 --- a/Tools/HIL/monitor_firmware_upload.py +++ b/Tools/HIL/monitor_firmware_upload.py @@ -7,6 +7,7 @@ from argparse import ArgumentParser import re import sys import datetime +import serial.tools.list_ports as list_ports COLOR_RED = "\x1b[31m" COLOR_GREEN = "\x1b[32m" @@ -36,6 +37,7 @@ def print_line(line): else: print('{0}'.format(line), end='') + def monitor_firmware_upload(port, baudrate): ser = serial.Serial(port, baudrate, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False) @@ -70,8 +72,30 @@ def monitor_firmware_upload(port, baudrate): ser.flush() def main(): + + default_device = None + device_required = True + + # select USB UART as default if there's only 1 + ports = list(serial.tools.list_ports.grep('USB UART')) + + if (len(ports) == 1): + default_device = ports[0].device + device_required = False + + print("Default USB UART port: {0}".format(ports[0].name)) + print(" device: {0}".format(ports[0].device)) + print(" description: \"{0}\" ".format(ports[0].description)) + print(" hwid: {0}".format(ports[0].hwid)) + #print(" vid: {0}, pid: {1}".format(ports[0].vid, ports[0].pid)) + #print(" serial_number: {0}".format(ports[0].serial_number)) + #print(" location: {0}".format(ports[0].location)) + print(" manufacturer: {0}".format(ports[0].manufacturer)) + #print(" product: {0}".format(ports[0].product)) + #print(" interface: {0}".format(ports[0].interface)) + parser = ArgumentParser(description=__doc__) - parser.add_argument('--device', "-d", nargs='?', default=None, help='', required=True) + parser.add_argument('--device', "-d", nargs='?', default=default_device, help='', required=device_required) parser.add_argument("--baudrate", "-b", dest="baudrate", type=int, help="Mavlink port baud rate (default=57600)", default=57600) args = parser.parse_args() diff --git a/Tools/HIL/nsh_param_set.py b/Tools/HIL/nsh_param_set.py index 115e29fcbb..1500ac0eab 100755 --- a/Tools/HIL/nsh_param_set.py +++ b/Tools/HIL/nsh_param_set.py @@ -6,6 +6,8 @@ from subprocess import call, Popen from argparse import ArgumentParser import re import sys +import datetime +import serial.tools.list_ports as list_ports COLOR_RED = "\x1b[31m" COLOR_GREEN = "\x1b[32m" @@ -29,7 +31,12 @@ def print_line(line): if "FAILED" in line: line = line.replace("FAILED", f"{COLOR_RED}FAILED{COLOR_RESET}", 1) - print(line, end='') + if "\n" in line: + current_time = datetime.datetime.now() + print('[{0}] {1}'.format(current_time.isoformat(timespec='milliseconds'), line), end='') + else: + print('{0}'.format(line), end='') + def do_param_set_cmd(port, baudrate, param_name, param_value): ser = serial.Serial(port, baudrate, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False) @@ -126,8 +133,30 @@ def do_param_set_cmd(port, baudrate, param_name, param_value): ser.close() def main(): + + default_device = None + device_required = True + + # select USB UART as default if there's only 1 + ports = list(serial.tools.list_ports.grep('USB UART')) + + if (len(ports) == 1): + default_device = ports[0].device + device_required = False + + print("Default USB UART port: {0}".format(ports[0].name)) + print(" device: {0}".format(ports[0].device)) + print(" description: \"{0}\" ".format(ports[0].description)) + print(" hwid: {0}".format(ports[0].hwid)) + #print(" vid: {0}, pid: {1}".format(ports[0].vid, ports[0].pid)) + #print(" serial_number: {0}".format(ports[0].serial_number)) + #print(" location: {0}".format(ports[0].location)) + print(" manufacturer: {0}".format(ports[0].manufacturer)) + #print(" product: {0}".format(ports[0].product)) + #print(" interface: {0}".format(ports[0].interface)) + parser = ArgumentParser(description=__doc__) - parser.add_argument('--device', "-d", nargs='?', default=None, help='', required=True) + parser.add_argument('--device', "-d", nargs='?', default=default_device, help='', required=device_required) parser.add_argument("--baudrate", "-b", dest="baudrate", type=int, help="Mavlink port baud rate (default=57600)", default=57600) parser.add_argument("--name", "-p", dest="param_name", help="Parameter name") parser.add_argument("--value", "-v", dest="param_value", help="Parameter value") diff --git a/Tools/HIL/reboot.py b/Tools/HIL/reboot.py index 3af5b8106a..892e538a47 100755 --- a/Tools/HIL/reboot.py +++ b/Tools/HIL/reboot.py @@ -7,6 +7,7 @@ from argparse import ArgumentParser import re import sys import datetime +import serial.tools.list_ports as list_ports COLOR_RED = "\x1b[31m" COLOR_GREEN = "\x1b[32m" @@ -36,6 +37,7 @@ def print_line(line): else: print('{0}'.format(line), end='') + def reboot(port, baudrate): ser = serial.Serial(port, baudrate, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False) @@ -75,8 +77,30 @@ def reboot(port, baudrate): sys.exit(-1) def main(): + + default_device = None + device_required = True + + # select USB UART as default if there's only 1 + ports = list(serial.tools.list_ports.grep('USB UART')) + + if (len(ports) == 1): + default_device = ports[0].device + device_required = False + + print("Default USB UART port: {0}".format(ports[0].name)) + print(" device: {0}".format(ports[0].device)) + print(" description: \"{0}\" ".format(ports[0].description)) + print(" hwid: {0}".format(ports[0].hwid)) + #print(" vid: {0}, pid: {1}".format(ports[0].vid, ports[0].pid)) + #print(" serial_number: {0}".format(ports[0].serial_number)) + #print(" location: {0}".format(ports[0].location)) + print(" manufacturer: {0}".format(ports[0].manufacturer)) + #print(" product: {0}".format(ports[0].product)) + #print(" interface: {0}".format(ports[0].interface)) + parser = ArgumentParser(description=__doc__) - parser.add_argument('--device', "-d", nargs='?', default=None, help='', required=True) + parser.add_argument('--device', "-d", nargs='?', default=default_device, help='', required=device_required) parser.add_argument("--baudrate", "-b", dest="baudrate", type=int, help="Mavlink port baud rate (default=57600)", default=57600) args = parser.parse_args() diff --git a/Tools/HIL/run_nsh_cmd.py b/Tools/HIL/run_nsh_cmd.py index 8ede7b2286..33a67121c6 100755 --- a/Tools/HIL/run_nsh_cmd.py +++ b/Tools/HIL/run_nsh_cmd.py @@ -7,6 +7,7 @@ from argparse import ArgumentParser import re import sys import datetime +import serial.tools.list_ports as list_ports COLOR_RED = "\x1b[31m" COLOR_GREEN = "\x1b[32m" @@ -46,6 +47,7 @@ def do_nsh_cmd(port, baudrate, cmd): # wait for nsh prompt while True: ser.write("\n".encode("ascii")) + ser.flush() serial_line = ser.readline().decode("ascii", errors='ignore') @@ -126,8 +128,30 @@ def do_nsh_cmd(port, baudrate, cmd): ser.close() def main(): + + default_device = None + device_required = True + + # select USB UART as default if there's only 1 + ports = list(serial.tools.list_ports.grep('USB UART')) + + if (len(ports) == 1): + default_device = ports[0].device + device_required = False + + print("Default USB UART port: {0}".format(ports[0].name)) + print(" device: {0}".format(ports[0].device)) + print(" description: \"{0}\" ".format(ports[0].description)) + print(" hwid: {0}".format(ports[0].hwid)) + #print(" vid: {0}, pid: {1}".format(ports[0].vid, ports[0].pid)) + #print(" serial_number: {0}".format(ports[0].serial_number)) + #print(" location: {0}".format(ports[0].location)) + print(" manufacturer: {0}".format(ports[0].manufacturer)) + #print(" product: {0}".format(ports[0].product)) + #print(" interface: {0}".format(ports[0].interface)) + parser = ArgumentParser(description=__doc__) - parser.add_argument('--device', "-d", nargs='?', default=None, help='', required=True) + parser.add_argument('--device', "-d", nargs='?', default=default_device, help='', required=device_required) parser.add_argument("--baudrate", "-b", dest="baudrate", type=int, help="Mavlink port baud rate (default=57600)", default=57600) parser.add_argument("--cmd", "-c", dest="cmd", help="Command to run") args = parser.parse_args() diff --git a/Tools/HIL/run_tests.py b/Tools/HIL/run_tests.py index 0291169494..b47035c25b 100755 --- a/Tools/HIL/run_tests.py +++ b/Tools/HIL/run_tests.py @@ -9,6 +9,7 @@ import unittest import os import sys import datetime +import serial.tools.list_ports as list_ports COLOR_RED = "\x1b[31m" COLOR_GREEN = "\x1b[32m" @@ -38,6 +39,7 @@ def print_line(line): else: print('{0}'.format(line), end='') + def do_test(port, baudrate, test_name): ser = serial.Serial(port, baudrate, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False) @@ -47,6 +49,7 @@ def do_test(port, baudrate, test_name): # wait for nsh prompt while True: ser.write("\n".encode("ascii")) + ser.flush() serial_line = ser.readline().decode("ascii", errors='ignore') @@ -206,8 +209,30 @@ class TestHardwareMethods(unittest.TestCase): self.assertTrue(do_test(self.TEST_DEVICE, self.TEST_BAUDRATE, "versioning")) def main(): + + default_device = None + device_required = True + + # select USB UART as default if there's only 1 + ports = list(serial.tools.list_ports.grep('USB UART')) + + if (len(ports) == 1): + default_device = ports[0].device + device_required = False + + print("Default USB UART port: {0}".format(ports[0].name)) + print(" device: {0}".format(ports[0].device)) + print(" description: \"{0}\" ".format(ports[0].description)) + print(" hwid: {0}".format(ports[0].hwid)) + #print(" vid: {0}, pid: {1}".format(ports[0].vid, ports[0].pid)) + #print(" serial_number: {0}".format(ports[0].serial_number)) + #print(" location: {0}".format(ports[0].location)) + print(" manufacturer: {0}".format(ports[0].manufacturer)) + #print(" product: {0}".format(ports[0].product)) + #print(" interface: {0}".format(ports[0].interface)) + parser = ArgumentParser(description=__doc__) - parser.add_argument('--device', "-d", nargs='?', default=None, help='', required=True) + parser.add_argument('--device', "-d", nargs='?', default=default_device, help='', required=device_required) parser.add_argument("--baudrate", "-b", dest="baudrate", type=int, help="Mavlink port baud rate (default=57600)", default=57600) args = parser.parse_args()