From ad1bfb5410d74c950fe582775c5e3784115be132 Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Sun, 12 Dec 2021 11:15:19 -0500 Subject: [PATCH] Tools/HIL/reboot.py retry every 90 seconds for up to 5 minutes --- Tools/HIL/reboot.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Tools/HIL/reboot.py b/Tools/HIL/reboot.py index fa1eed7da6..d4e8fe7a79 100755 --- a/Tools/HIL/reboot.py +++ b/Tools/HIL/reboot.py @@ -36,26 +36,29 @@ def print_line(line): else: print('{0}'.format(line), end='') -def monitor_firmware_upload(port, baudrate): +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) # clear ser.readlines() + time_start = time.monotonic() ser.write("\nreboot\n".encode("ascii")) ser.flush() + time_reboot_cmd = time_start - timeout_reboot_cmd = 30 + timeout_reboot_cmd = 90 timeout = 300 # 5 minutes - timeout_start = time.monotonic() - timeout_newline = time.monotonic() - time_success = 0 return_code = 0 while True: - if time.monotonic() > timeout_start + timeout_reboot_cmd: + if time.monotonic() > time_reboot_cmd + timeout_reboot_cmd: + time_reboot_cmd = time.monotonic() + print("sending reboot cmd again") ser.write("reboot\n".encode("ascii")) + ser.flush() + time.sleep(0.2) serial_line = ser.readline().decode("ascii", errors='ignore') @@ -66,13 +69,9 @@ def monitor_firmware_upload(port, baudrate): print_line(serial_line) if "NuttShell (NSH)" in serial_line: - time_success = time.monotonic() - - # wait at least 2 seconds after seeing prompt to catch potential errors - if time_success > 0 and time.monotonic() > time_success + 2: sys.exit(return_code) - if time.monotonic() > timeout_start + timeout: + if time.monotonic() > time_start + timeout: print("Error, timeout") sys.exit(-1) @@ -82,7 +81,7 @@ def main(): parser.add_argument("--baudrate", "-b", dest="baudrate", type=int, help="Mavlink port baud rate (default=57600)", default=57600) args = parser.parse_args() - monitor_firmware_upload(args.device, args.baudrate) + reboot(args.device, args.baudrate) if __name__ == "__main__": main()