forked from Archive/PX4-Autopilot
Cleanup uploader output.
This commit is contained in:
parent
b85f0ab3cd
commit
0a99a26fcc
|
@ -266,18 +266,19 @@ class uploader(object):
|
|||
self.__getSync()
|
||||
return value
|
||||
|
||||
def __drawProgressBar(self, progress, maxVal):
|
||||
def __drawProgressBar(self, label, 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.write("\r%s: [%-20s] %.1f%%" % (label, '='*int(percent/5.0), percent))
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
# send the CHIP_ERASE command and wait for the bootloader to become ready
|
||||
def __erase(self):
|
||||
def __erase(self, label):
|
||||
print("\n", end='')
|
||||
self.__send(uploader.CHIP_ERASE
|
||||
+ uploader.EOC)
|
||||
|
||||
|
@ -288,15 +289,14 @@ class uploader(object):
|
|||
#Draw progress bar (erase usually takes about 9 seconds to complete)
|
||||
estimatedTimeRemaining = deadline-time.time()
|
||||
if estimatedTimeRemaining >= 9.0:
|
||||
self.__drawProgressBar(20.0-estimatedTimeRemaining, 9.0)
|
||||
self.__drawProgressBar(label, 20.0-estimatedTimeRemaining, 9.0)
|
||||
else:
|
||||
self.__drawProgressBar(10.0, 10.0)
|
||||
self.__drawProgressBar(label, 10.0, 10.0)
|
||||
sys.stdout.write(" (timeout: %d seconds) " % int(deadline-time.time()) )
|
||||
sys.stdout.flush()
|
||||
|
||||
if self.__trySync():
|
||||
self.__drawProgressBar(10.0, 10.0)
|
||||
sys.stdout.write("\nerase complete!\n")
|
||||
self.__drawProgressBar(label, 10.0, 10.0)
|
||||
return;
|
||||
|
||||
raise RuntimeError("timed out waiting for erase")
|
||||
|
@ -350,7 +350,8 @@ class uploader(object):
|
|||
return [seq[i:i+length] for i in range(0, len(seq), length)]
|
||||
|
||||
# upload code
|
||||
def __program(self, fw):
|
||||
def __program(self, label, fw):
|
||||
print("\n", end='')
|
||||
code = fw.image
|
||||
groups = self.__split_len(code, uploader.PROG_MULTI_MAX)
|
||||
|
||||
|
@ -361,31 +362,40 @@ class uploader(object):
|
|||
#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!")
|
||||
self.__drawProgressBar(label, uploadProgress, len(groups))
|
||||
self.__drawProgressBar(label, 100, 100)
|
||||
|
||||
# verify code
|
||||
def __verify_v2(self, fw):
|
||||
def __verify_v2(self, label, fw):
|
||||
print("\n", end='')
|
||||
self.__send(uploader.CHIP_VERIFY
|
||||
+ uploader.EOC)
|
||||
self.__getSync()
|
||||
code = fw.image
|
||||
groups = self.__split_len(code, uploader.READ_MULTI_MAX)
|
||||
verifyProgress = 0
|
||||
for bytes in groups:
|
||||
verifyProgress += 1
|
||||
if verifyProgress % 256 == 0:
|
||||
self.__drawProgressBar(label, verifyProgress, len(groups))
|
||||
if (not self.__verify_multi(bytes)):
|
||||
raise RuntimeError("Verification failed")
|
||||
self.__drawProgressBar(label, 100, 100)
|
||||
|
||||
def __verify_v3(self, fw):
|
||||
def __verify_v3(self, label, fw):
|
||||
print("\n", end='')
|
||||
self.__drawProgressBar(label, 1, 100)
|
||||
expect_crc = fw.crc(self.fw_maxsize)
|
||||
self.__send(uploader.GET_CRC
|
||||
+ uploader.EOC)
|
||||
report_crc = self.__recv_int()
|
||||
self.__getSync()
|
||||
verifyProgress = 0
|
||||
if report_crc != expect_crc:
|
||||
print("Expected 0x%x" % expect_crc)
|
||||
print("Got 0x%x" % report_crc)
|
||||
raise RuntimeError("Program CRC failed")
|
||||
self.__drawProgressBar(label, 100, 100)
|
||||
|
||||
# get basic data about the board
|
||||
def identify(self):
|
||||
|
@ -439,19 +449,16 @@ class uploader(object):
|
|||
except Exception:
|
||||
# ignore bad character encodings
|
||||
pass
|
||||
print("erase...")
|
||||
self.__erase()
|
||||
|
||||
print("program...")
|
||||
self.__program(fw)
|
||||
self.__erase("Erase ")
|
||||
self.__program("Program", fw)
|
||||
|
||||
print("verify...")
|
||||
if self.bl_rev == 2:
|
||||
self.__verify_v2(fw)
|
||||
self.__verify_v2("Verify ", fw)
|
||||
else:
|
||||
self.__verify_v3(fw)
|
||||
self.__verify_v3("Verify ", fw)
|
||||
|
||||
print("done, rebooting.")
|
||||
print("\nRebooting.\n")
|
||||
self.__reboot()
|
||||
self.port.close()
|
||||
|
||||
|
|
Loading…
Reference in New Issue