From 247b975675a23655dc8e9a2655a1795d47c0337b Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Fri, 31 Dec 2021 18:55:59 -0500 Subject: [PATCH] Tools/HIL: disable XON/XOFF, consistent timeouts, proper input buffer clear --- Tools/HIL/monitor_firmware_upload.py | 2 +- Tools/HIL/nsh_param_set.py | 4 ++-- Tools/HIL/reboot.py | 11 +++++------ Tools/HIL/run_nsh_cmd.py | 5 ++--- Tools/HIL/run_tests.py | 5 ++--- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Tools/HIL/monitor_firmware_upload.py b/Tools/HIL/monitor_firmware_upload.py index b58f25bcdc..9388e0fea0 100755 --- a/Tools/HIL/monitor_firmware_upload.py +++ b/Tools/HIL/monitor_firmware_upload.py @@ -37,7 +37,7 @@ def print_line(line): 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=True, rtscts=False, dsrdtr=False) + ser = serial.Serial(port, baudrate, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False) timeout = 180 # 3 minutes timeout_start = time.monotonic() diff --git a/Tools/HIL/nsh_param_set.py b/Tools/HIL/nsh_param_set.py index 74539bf123..115e29fcbb 100755 --- a/Tools/HIL/nsh_param_set.py +++ b/Tools/HIL/nsh_param_set.py @@ -32,7 +32,7 @@ def print_line(line): print(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=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=1, xonxoff=False, rtscts=False, dsrdtr=False) timeout_start = time.monotonic() timeout = 30 # 30 seconds @@ -55,7 +55,7 @@ def do_param_set_cmd(port, baudrate, param_name, param_value): sys.exit(1) # clear - ser.readlines() + ser.reset_input_buffer() # run command timeout_start = time.monotonic() diff --git a/Tools/HIL/reboot.py b/Tools/HIL/reboot.py index d4e8fe7a79..3af5b8106a 100755 --- a/Tools/HIL/reboot.py +++ b/Tools/HIL/reboot.py @@ -37,14 +37,14 @@ def print_line(line): 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=True, rtscts=False, dsrdtr=False) + ser = serial.Serial(port, baudrate, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False) # clear - ser.readlines() + ser.reset_input_buffer() time_start = time.monotonic() - ser.write("\nreboot\n".encode("ascii")) - ser.flush() + ser.write("\n".encode("ascii")) + ser.write("reboot\n".encode("ascii")) time_reboot_cmd = time_start timeout_reboot_cmd = 90 @@ -57,8 +57,7 @@ def reboot(port, baudrate): time_reboot_cmd = time.monotonic() print("sending reboot cmd again") ser.write("reboot\n".encode("ascii")) - ser.flush() - time.sleep(0.2) + time.sleep(0.5) serial_line = ser.readline().decode("ascii", errors='ignore') diff --git a/Tools/HIL/run_nsh_cmd.py b/Tools/HIL/run_nsh_cmd.py index 96324c9a67..8ede7b2286 100755 --- a/Tools/HIL/run_nsh_cmd.py +++ b/Tools/HIL/run_nsh_cmd.py @@ -38,7 +38,7 @@ def print_line(line): 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.2, 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=False, rtscts=False, dsrdtr=False) timeout_start = time.monotonic() timeout = 30 # 30 seconds @@ -46,7 +46,6 @@ 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') @@ -61,7 +60,7 @@ def do_nsh_cmd(port, baudrate, cmd): sys.exit(1) # clear - ser.readlines() + ser.reset_input_buffer() # run command timeout_start = time.monotonic() diff --git a/Tools/HIL/run_tests.py b/Tools/HIL/run_tests.py index 1c6e2de160..0291169494 100755 --- a/Tools/HIL/run_tests.py +++ b/Tools/HIL/run_tests.py @@ -39,7 +39,7 @@ def print_line(line): 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=0.2, 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=False, rtscts=False, dsrdtr=False) timeout_start = time.monotonic() timeout = 30 # 30 seconds @@ -47,7 +47,6 @@ 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') @@ -62,7 +61,7 @@ def do_test(port, baudrate, test_name): return False # clear - ser.readlines() + ser.reset_input_buffer() success = False