mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
Tools/HIL: console print timestamps
This commit is contained in:
parent
847b3b5b64
commit
209fde9ff3
@ -6,6 +6,7 @@ from subprocess import call, Popen
|
|||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
import datetime
|
||||||
|
|
||||||
COLOR_RED = "\x1b[31m"
|
COLOR_RED = "\x1b[31m"
|
||||||
COLOR_GREEN = "\x1b[32m"
|
COLOR_GREEN = "\x1b[32m"
|
||||||
@ -29,7 +30,8 @@ def print_line(line):
|
|||||||
if "FAILED" in line:
|
if "FAILED" in line:
|
||||||
line = line.replace("FAILED", f"{COLOR_RED}FAILED{COLOR_RESET}", 1)
|
line = line.replace("FAILED", f"{COLOR_RED}FAILED{COLOR_RESET}", 1)
|
||||||
|
|
||||||
print(line, end='')
|
current_time = datetime.datetime.now()
|
||||||
|
print('[{0}] {1}'.format(current_time.isoformat(timespec='milliseconds'), line), end='')
|
||||||
|
|
||||||
def monitor_firmware_upload(port, baudrate):
|
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=True, rtscts=False, dsrdtr=False)
|
ser = serial.Serial(port, baudrate, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1, xonxoff=True, rtscts=False, dsrdtr=False)
|
||||||
@ -41,13 +43,13 @@ def monitor_firmware_upload(port, baudrate):
|
|||||||
while True:
|
while True:
|
||||||
serial_line = ser.readline().decode("ascii", errors='ignore')
|
serial_line = ser.readline().decode("ascii", errors='ignore')
|
||||||
|
|
||||||
|
if len(serial_line) > 0:
|
||||||
|
print_line(serial_line)
|
||||||
|
|
||||||
if "NuttShell (NSH)" in serial_line:
|
if "NuttShell (NSH)" in serial_line:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
elif "nsh>" in serial_line:
|
elif "nsh>" in serial_line:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
else:
|
|
||||||
if len(serial_line) > 0:
|
|
||||||
print_line(serial_line)
|
|
||||||
|
|
||||||
if time.time() > timeout_start + timeout:
|
if time.time() > timeout_start + timeout:
|
||||||
print("Error, timeout")
|
print("Error, timeout")
|
||||||
|
|||||||
@ -6,6 +6,7 @@ from subprocess import call, Popen
|
|||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
import datetime
|
||||||
|
|
||||||
COLOR_RED = "\x1b[31m"
|
COLOR_RED = "\x1b[31m"
|
||||||
COLOR_GREEN = "\x1b[32m"
|
COLOR_GREEN = "\x1b[32m"
|
||||||
@ -29,7 +30,8 @@ def print_line(line):
|
|||||||
if "FAILED" in line:
|
if "FAILED" in line:
|
||||||
line = line.replace("FAILED", f"{COLOR_RED}FAILED{COLOR_RESET}", 1)
|
line = line.replace("FAILED", f"{COLOR_RED}FAILED{COLOR_RESET}", 1)
|
||||||
|
|
||||||
print(line, end='')
|
current_time = datetime.datetime.now()
|
||||||
|
print('[{0}] {1}'.format(current_time.isoformat(timespec='milliseconds'), line), end='')
|
||||||
|
|
||||||
def do_nsh_cmd(port, baudrate, cmd):
|
def do_nsh_cmd(port, baudrate, cmd):
|
||||||
ser = serial.Serial(port, baudrate, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=0.1, xonxoff=True, rtscts=False, dsrdtr=False)
|
ser = serial.Serial(port, baudrate, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=0.1, xonxoff=True, rtscts=False, dsrdtr=False)
|
||||||
@ -59,7 +61,7 @@ def do_nsh_cmd(port, baudrate, cmd):
|
|||||||
|
|
||||||
# run command
|
# run command
|
||||||
timeout_start = time.time()
|
timeout_start = time.time()
|
||||||
timeout = 10 # 10 seconds
|
timeout = 2 # 2 seconds
|
||||||
|
|
||||||
success_cmd = "cmd succeeded!"
|
success_cmd = "cmd succeeded!"
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import re
|
|||||||
import unittest
|
import unittest
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import datetime
|
||||||
|
|
||||||
COLOR_RED = "\x1b[31m"
|
COLOR_RED = "\x1b[31m"
|
||||||
COLOR_GREEN = "\x1b[32m"
|
COLOR_GREEN = "\x1b[32m"
|
||||||
@ -31,10 +32,11 @@ def print_line(line):
|
|||||||
if "FAILED" in line:
|
if "FAILED" in line:
|
||||||
line = line.replace("FAILED", f"{COLOR_RED}FAILED{COLOR_RESET}", 1)
|
line = line.replace("FAILED", f"{COLOR_RED}FAILED{COLOR_RESET}", 1)
|
||||||
|
|
||||||
print(line, end='')
|
current_time = datetime.datetime.now()
|
||||||
|
print('[{0}] {1}'.format(current_time.isoformat(timespec='milliseconds'), line), end='')
|
||||||
|
|
||||||
def do_test(port, baudrate, test_name):
|
def do_test(port, baudrate, test_name):
|
||||||
ser = serial.Serial(port, baudrate, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=0.1, xonxoff=True, rtscts=False, dsrdtr=False)
|
ser = serial.Serial(port, baudrate, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=0.2, xonxoff=True, rtscts=False, dsrdtr=False)
|
||||||
|
|
||||||
timeout_start = time.time()
|
timeout_start = time.time()
|
||||||
timeout = 10 # 10 seconds
|
timeout = 10 # 10 seconds
|
||||||
@ -68,7 +70,7 @@ def do_test(port, baudrate, test_name):
|
|||||||
print('|======================================================================')
|
print('|======================================================================')
|
||||||
|
|
||||||
timeout_start = time.time()
|
timeout_start = time.time()
|
||||||
timeout = 10 # 10 seconds
|
timeout = 2 # 2 seconds
|
||||||
|
|
||||||
# wait for command echo
|
# wait for command echo
|
||||||
serial_cmd = '{0}\n'.format(cmd)
|
serial_cmd = '{0}\n'.format(cmd)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user