Skip to content

Commit

Permalink
examples: exit on end of fw update
Browse files Browse the repository at this point in the history
and print update time
  • Loading branch information
tridge committed Dec 28, 2023
1 parent 0f67d51 commit a95f003
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions examples/firmware_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
parser.add_argument("--bitrate", default=1000000, type=int, help="CAN bit rate")
parser.add_argument("--node-id", default=100, type=int, help="CAN node ID")
parser.add_argument("--target-node-id", default=-1, type=int, help="Target CAN node ID (-1 for auto)")
parser.add_argument("--dna", action='store_true', default=True, help="run dynamic node allocation server")
parser.add_argument("--dna", action='store_true', default=False, help="run dynamic node allocation server")
parser.add_argument("--port", default='/dev/ttyACM0', type=str, help="serial port")
parser.add_argument("--fw", default='', required=True, type=str, help="app firmware path")

Expand Down Expand Up @@ -70,20 +70,24 @@

update_started = False
update_complete = False
start_time = None

def on_node_status(e):
global update_started
global update_complete
global start_time

if e.transfer.source_node_id == target_node_id:
if e.message.mode == e.message.MODE_SOFTWARE_UPDATE:
if not update_started:
print('Performing update')
update_started = True;
start_time = time.time()
#request_update()
else:
if update_started:
print('Update complete')
elapsed = time.time() - start_time
print('Update complete in %.2f seconds' % elapsed)
update_complete = True;


Expand Down Expand Up @@ -118,3 +122,5 @@ def request_update():
sys.exit(0)
except dronecan.transport.TransferError:
pass

node.close()

0 comments on commit a95f003

Please sign in to comment.