2018-08-04 17:48:47 -03:00
|
|
|
#! /usr/bin/python
|
|
|
|
|
|
|
|
import serial, time
|
|
|
|
import subprocess
|
|
|
|
from subprocess import call, Popen
|
|
|
|
from argparse import ArgumentParser
|
|
|
|
import re
|
|
|
|
|
2019-06-15 13:03:37 -03:00
|
|
|
def monitor_firmware_upload(port, baudrate):
|
2018-08-04 17:48:47 -03:00
|
|
|
databits = serial.EIGHTBITS
|
|
|
|
stopbits = serial.STOPBITS_ONE
|
|
|
|
parity = serial.PARITY_NONE
|
2019-06-15 13:03:37 -03:00
|
|
|
ser = serial.Serial(port, baudrate, databits, parity, stopbits, timeout=10)
|
2018-08-04 17:48:47 -03:00
|
|
|
|
|
|
|
finished = 0
|
|
|
|
|
2019-06-15 17:13:05 -03:00
|
|
|
timeout = 300 # 5 minutes
|
2019-06-15 13:03:37 -03:00
|
|
|
timeout_start = time.time()
|
|
|
|
timeout_newline = time.time()
|
|
|
|
|
2018-08-04 17:48:47 -03:00
|
|
|
while finished == 0:
|
|
|
|
serial_line = ser.readline()
|
2019-06-15 13:03:37 -03:00
|
|
|
print(serial_line.replace('\n',''))
|
2018-08-04 17:48:47 -03:00
|
|
|
|
|
|
|
if "NuttShell (NSH)" in serial_line:
|
|
|
|
finished = 1
|
2019-06-15 13:03:37 -03:00
|
|
|
break
|
|
|
|
|
|
|
|
if time.time() > timeout_start + timeout:
|
|
|
|
print("Error, timeout")
|
|
|
|
finished = 1
|
|
|
|
break
|
|
|
|
|
|
|
|
# newline every 30 seconds if still running
|
|
|
|
if time.time() - timeout_newline > 30:
|
|
|
|
ser.write('\n')
|
|
|
|
timeout_newline = time.time()
|
|
|
|
|
2018-08-04 17:48:47 -03:00
|
|
|
ser.close()
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = ArgumentParser(description=__doc__)
|
|
|
|
parser.add_argument('--device', "-d", nargs='?', default = None, help='')
|
|
|
|
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)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|