mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-25 00:31:36 +08:00
Merge branch 'px_uploader_improvements' of github.com:Zefz/Firmware
This commit is contained in:
+54
-21
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
############################################################################
|
||||
#
|
||||
# Copyright (C) 2012, 2013 PX4 Development Team. All rights reserved.
|
||||
# Copyright (C) 2012-2015 PX4 Development Team. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
@@ -227,16 +227,21 @@ class uploader(object):
|
||||
+ uploader.EOC)
|
||||
self.__getSync()
|
||||
|
||||
# def __trySync(self):
|
||||
# c = self.__recv()
|
||||
# if (c != self.INSYNC):
|
||||
# #print("unexpected 0x%x instead of INSYNC" % ord(c))
|
||||
# return False;
|
||||
# c = self.__recv()
|
||||
# if (c != self.OK):
|
||||
# #print("unexpected 0x%x instead of OK" % ord(c))
|
||||
# return False
|
||||
# return True
|
||||
def __trySync(self):
|
||||
try:
|
||||
self.port.flush()
|
||||
if (self.__recv() != self.INSYNC):
|
||||
#print("unexpected 0x%x instead of INSYNC" % ord(c))
|
||||
return False;
|
||||
|
||||
if (self.__recv() != self.OK):
|
||||
#print("unexpected 0x%x instead of OK" % ord(c))
|
||||
return False
|
||||
return True
|
||||
|
||||
except RuntimeError:
|
||||
#timeout, no response yet
|
||||
return False
|
||||
|
||||
# send the GET_DEVICE command and wait for an info parameter
|
||||
def __getInfo(self, param):
|
||||
@@ -261,19 +266,37 @@ class uploader(object):
|
||||
self.__getSync()
|
||||
return value
|
||||
|
||||
def __drawProgressBar(self, progress, maxVal):
|
||||
if maxVal < progress:
|
||||
progress = maxVal
|
||||
|
||||
percent = (float(progress) / float(maxVal)) * 100.0
|
||||
|
||||
sys.stdout.write("\rprogress:[%-20s] %.2f%%" % ('='*int(percent/5.0), percent))
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
# send the CHIP_ERASE command and wait for the bootloader to become ready
|
||||
def __erase(self):
|
||||
self.__send(uploader.CHIP_ERASE
|
||||
+ uploader.EOC)
|
||||
|
||||
# erase is very slow, give it 20s
|
||||
deadline = time.time() + 20
|
||||
deadline = time.time() + 20.0
|
||||
while time.time() < deadline:
|
||||
try:
|
||||
self.__getSync()
|
||||
return
|
||||
except RuntimeError:
|
||||
# we timed out, that's OK
|
||||
continue
|
||||
|
||||
#Draw progress bar (erase usually takes about 9 seconds to complete)
|
||||
estimatedTimeRemaining = deadline-time.time()
|
||||
if estimatedTimeRemaining > 0:
|
||||
self.__drawProgressBar(20.0-estimatedTimeRemaining, 9.0)
|
||||
else:
|
||||
self.__drawProgressBar(10.0, 10.0)
|
||||
sys.stdout.write(" (timeout: %d seconds) " % int(time.time()-deadline) )
|
||||
|
||||
if self.__trySync():
|
||||
self.__drawProgressBar(10.0, 10.0)
|
||||
sys.stdout.write("\nerase complete!\n")
|
||||
return;
|
||||
|
||||
raise RuntimeError("timed out waiting for erase")
|
||||
|
||||
@@ -329,9 +352,18 @@ class uploader(object):
|
||||
def __program(self, fw):
|
||||
code = fw.image
|
||||
groups = self.__split_len(code, uploader.PROG_MULTI_MAX)
|
||||
|
||||
uploadProgress = 0
|
||||
for bytes in groups:
|
||||
self.__program_multi(bytes)
|
||||
|
||||
#Print upload progress (throttled, so it does not delay upload progress)
|
||||
uploadProgress += 1
|
||||
if uploadProgress % 256 == 0:
|
||||
self.__drawProgressBar(uploadProgress, len(groups))
|
||||
self.__drawProgressBar(100, 100)
|
||||
print("\nprogram complete!")
|
||||
|
||||
# verify code
|
||||
def __verify_v2(self, fw):
|
||||
self.__send(uploader.CHIP_VERIFY
|
||||
@@ -434,8 +466,7 @@ class uploader(object):
|
||||
self.__send(uploader.MAVLINK_REBOOT_ID0)
|
||||
except:
|
||||
return
|
||||
|
||||
|
||||
|
||||
|
||||
# Detect python version
|
||||
if sys.version_info[0] < 3:
|
||||
@@ -511,8 +542,10 @@ while True:
|
||||
print("attempting reboot on %s..." % port)
|
||||
print("if the board does not respond, unplug and re-plug the USB connector.")
|
||||
up.send_reboot()
|
||||
|
||||
# wait for the reboot, without we might run into Serial I/O Error 5
|
||||
time.sleep(0.5)
|
||||
|
||||
# always close the port
|
||||
up.close()
|
||||
continue
|
||||
@@ -524,7 +557,7 @@ while True:
|
||||
except RuntimeError as ex:
|
||||
|
||||
# print the error
|
||||
print("ERROR: %s" % ex.args)
|
||||
print("\nERROR: %s" % ex.args)
|
||||
|
||||
finally:
|
||||
# always close the port
|
||||
|
||||
Reference in New Issue
Block a user