aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2015-01-08 17:53:11 +0100
committerLorenz Meier <lm@inf.ethz.ch>2015-01-08 17:53:11 +0100
commit0f70b4b8465277e2c9c8762f27a4ad83257e9456 (patch)
tree3cf0e795a575462b6903edf20e53541e8b7f556a
parentaa2a00b56a0be0e20abfa54c311575f9e055f212 (diff)
parent1eda1f816bdd4877fee79abb4f0edb13bbc02a91 (diff)
downloadpx4-firmware-0f70b4b8465277e2c9c8762f27a4ad83257e9456.tar.gz
px4-firmware-0f70b4b8465277e2c9c8762f27a4ad83257e9456.tar.bz2
px4-firmware-0f70b4b8465277e2c9c8762f27a4ad83257e9456.zip
Merge branch 'px_uploader_improvements' of github.com:Zefz/Firmware
-rwxr-xr-xTools/px_uploader.py75
1 files changed, 54 insertions, 21 deletions
diff --git a/Tools/px_uploader.py b/Tools/px_uploader.py
index 3a4540ac0..272080619 100755
--- a/Tools/px_uploader.py
+++ b/Tools/px_uploader.py
@@ -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