mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
Tools/HIL/reboot.py retry every 90 seconds for up to 5 minutes
This commit is contained in:
parent
63189067f6
commit
ad1bfb5410
@ -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()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user