39
39
import sys
40
40
import time
41
41
import math
42
+ import os .path
42
43
from sys import exit
43
44
44
45
# ***********************************************************************************
@@ -166,11 +167,11 @@ def phase_setup(ser):
166
167
167
168
baud_detect_byte = b'U'
168
169
169
- verboseprint ('\n phase: \t setup ' )
170
+ verboseprint ('\n Phase: \t Setup ' )
170
171
171
172
# Handle the serial startup blip
172
173
ser .reset_input_buffer ()
173
- verboseprint ('\t cleared startup blip' )
174
+ verboseprint ('\t Cleared startup blip' )
174
175
175
176
ser .write (baud_detect_byte ) # send the baud detection character
176
177
@@ -200,7 +201,7 @@ def phase_bootload(ser):
200
201
resend_max = 4
201
202
resend_count = 0
202
203
203
- verboseprint ('\n phase: \t bootload ' )
204
+ verboseprint ('\n Phase: \t Bootload ' )
204
205
205
206
with open (args .binfile , mode = 'rb' ) as binfile :
206
207
application = binfile .read ()
@@ -223,9 +224,9 @@ def phase_bootload(ser):
223
224
# wait for indication by Artemis
224
225
packet = wait_for_packet (ser )
225
226
if (packet ['timeout' ] or packet ['crc' ]):
226
- print ('\n \t error receiving packet' )
227
- print (packet )
228
- print ('\n ' )
227
+ verboseprint ('\n \t Error receiving packet' )
228
+ verboseprint (packet )
229
+ verboseprint ('\n ' )
229
230
bl_failed = True
230
231
bl_done = True
231
232
@@ -234,21 +235,21 @@ def phase_bootload(ser):
234
235
curr_frame += 1
235
236
resend_count = 0
236
237
elif (packet ['cmd' ] == SVL_CMD_RETRY ):
237
- verboseprint ('\t \t retrying ...' )
238
+ verboseprint ('\t \t Retrying ...' )
238
239
resend_count += 1
239
240
if (resend_count >= resend_max ):
240
241
bl_failed = True
241
242
bl_done = True
242
243
else :
243
- print ('unknown error' )
244
+ print ('Timeout or unknown error' )
244
245
bl_failed = True
245
246
bl_done = True
246
247
247
248
if (curr_frame <= total_frames ):
248
249
frame_data = application [(
249
250
(curr_frame - 1 )* frame_size ):((curr_frame - 1 + 1 )* frame_size )]
250
251
if (args .verbose ):
251
- verboseprint ('\t sending frame #' + str (curr_frame ) +
252
+ verboseprint ('\t Sending frame #' + str (curr_frame ) +
252
253
', length: ' + str (len (frame_data )))
253
254
else :
254
255
percentComplete = curr_frame * 100 / total_frames
@@ -319,6 +320,9 @@ def main():
319
320
num_tries = 3
320
321
321
322
print ('\n \n Artemis SVL Bootloader' )
323
+ if not os .path .exists (args .binfile ):
324
+ print ("Bin file {} does not exits." .format (args .binfile ))
325
+ exit ()
322
326
323
327
for _ in range (num_tries ):
324
328
@@ -335,7 +339,7 @@ def main():
335
339
if (bl_failed == False ):
336
340
break
337
341
338
- except :
342
+ except serial . SerialException :
339
343
phase_serial_port_help ()
340
344
341
345
exit ()
0 commit comments