mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-29 22:33:33 +08:00
Tools/HIL: default to USB UART if available
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user