Skip to content

Commit

Permalink
Simplify output messages (and fix to 80 column terminal)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-thompson committed May 3, 2020
1 parent 9cc61db commit 3d6fd30
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
4 changes: 2 additions & 2 deletions ble_legacy_dfu_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def start(self, verbose=False):
# last_send_time = time.time()

if (segment_count == segment_total):
print_progress(self.image_size, self.image_size, prefix = 'Progress:', suffix = 'Complete', barLength = 50)
print_progress(self.image_size, self.image_size, barLength = 50)

duration = time.time() - time_start
print("\nUpload complete in {} minutes and {} seconds".format(int(duration / 60), int(duration % 60)))
Expand All @@ -164,7 +164,7 @@ def start(self, verbose=False):
if res != Responses.SUCCESS:
raise Exception("bad notification status: {}".format(Responses.to_string(res)))

print_progress(pkts, self.image_size, prefix = 'Progress:', suffix = 'Complete', barLength = 50)
print_progress(pkts, self.image_size, barLength = 50)

# Send Validate Command
self._dfu_send_command(Procedures.VALIDATE_FIRMWARE)
Expand Down
4 changes: 2 additions & 2 deletions ble_secure_dfu_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def _dfu_send_image(self):
obj_offset += self._dfu_send_object(obj_offset, max_size)

# Image uploaded successfully, update the progress bar
print_progress(self.image_size, self.image_size, prefix = 'Progress:', suffix = 'Complete', barLength = 50)
print_progress(self.image_size, self.image_size, barLength = 50)

duration = time.time() - time_start
print("\nUpload complete in {} minutes and {} seconds".format(int(duration / 60), int(duration % 60)))
Expand Down Expand Up @@ -306,7 +306,7 @@ def _dfu_send_object(self, offset, obj_max_size):
# Something went wrong, need to re-transmit this object
return 0

print_progress(offset, self.image_size, prefix = 'Progress:', suffix = 'Complete', barLength = 50)
print_progress(offset, self.image_size, barLength = 50)

# Calculate CRC
self._dfu_send_command(Procedures.CALC_CHECKSUM)
Expand Down
32 changes: 20 additions & 12 deletions dfu.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,6 @@

def main():

init_msg = """
================================
== ==
== DFU Server ==
== ==
================================
"""

# print "DFU Server start"
print(init_msg)

try:
parser = optparse.OptionParser(usage='%prog -f <hex_file> -a <dfu_target_address>\n\nExample:\n\tdfu.py -f application.hex -d application.dat -a cd:e3:4a:47:1c:e4',
version='0.5')
Expand Down Expand Up @@ -79,6 +68,11 @@ def main():
help='Use secure bootloader (Nordic SDK < 12)'
)

parser.add_option('-v', '--verbose',
action='store_true',
dest='verbose',
help='Enable verbose mode'
)
options, args = parser.parse_args()

except Exception as e:
Expand Down Expand Up @@ -132,6 +126,19 @@ def main():

''' Start of Device Firmware Update processing '''

if options.verbose:
init_msg = \
"""
================================
== ==
== DFU Server ==
== ==
================================
"""
# print "DFU Server start"
print(init_msg)


if options.secure_dfu:
ble_dfu = BleDfuControllerSecure(options.address.upper(), hexfile, datfile)
else:
Expand Down Expand Up @@ -173,7 +180,8 @@ def main():
if unpacker != None:
unpacker.delete()

print("DFU Server done")
if options.verbose:
print("DFU Server done")

"""
------------------------------------------------------------------------------
Expand Down
6 changes: 4 additions & 2 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ def print_progress(iteration, total, prefix = '', suffix = '', decimals = 1, bar
formatStr = "{0:." + str(decimals) + "f}"
percents = formatStr.format(100 * (iteration / float(total)))
filledLength = int(round(barLength * iteration / float(total)))
bar = 'x' * filledLength + '-' * (barLength - filledLength)
sys.stdout.write('\r%s |%s| %s%s %s (%d of %d bytes)' % (prefix, bar, percents, '%', suffix, iteration, total)),
bar = '#' * filledLength + '.' * (barLength - filledLength)
if len(prefix):
prefix = prefix + ' '
sys.stdout.write('\r%s[%s] %s%s %s (%d of %d kb)' % (prefix, bar, percents, '%', suffix, iteration/1024, total/1024)),
if iteration == total:
sys.stdout.write('\n')
sys.stdout.flush()

0 comments on commit 3d6fd30

Please sign in to comment.