3939import sys
4040import time
4141import math
42+ import os .path
4243from sys import exit
4344
4445# ***********************************************************************************
@@ -166,11 +167,11 @@ def phase_setup(ser):
166167
167168 baud_detect_byte = b'U'
168169
169- verboseprint ('\n phase: \t setup ' )
170+ verboseprint ('\n Phase: \t Setup ' )
170171
171172 # Handle the serial startup blip
172173 ser .reset_input_buffer ()
173- verboseprint ('\t cleared startup blip' )
174+ verboseprint ('\t Cleared startup blip' )
174175
175176 ser .write (baud_detect_byte ) # send the baud detection character
176177
@@ -200,7 +201,7 @@ def phase_bootload(ser):
200201 resend_max = 4
201202 resend_count = 0
202203
203- verboseprint ('\n phase: \t bootload ' )
204+ verboseprint ('\n Phase: \t Bootload ' )
204205
205206 with open (args .binfile , mode = 'rb' ) as binfile :
206207 application = binfile .read ()
@@ -223,9 +224,9 @@ def phase_bootload(ser):
223224 # wait for indication by Artemis
224225 packet = wait_for_packet (ser )
225226 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 ' )
229230 bl_failed = True
230231 bl_done = True
231232
@@ -234,21 +235,21 @@ def phase_bootload(ser):
234235 curr_frame += 1
235236 resend_count = 0
236237 elif (packet ['cmd' ] == SVL_CMD_RETRY ):
237- verboseprint ('\t \t retrying ...' )
238+ verboseprint ('\t \t Retrying ...' )
238239 resend_count += 1
239240 if (resend_count >= resend_max ):
240241 bl_failed = True
241242 bl_done = True
242243 else :
243- print ('unknown error' )
244+ print ('Timeout or unknown error' )
244245 bl_failed = True
245246 bl_done = True
246247
247248 if (curr_frame <= total_frames ):
248249 frame_data = application [(
249250 (curr_frame - 1 )* frame_size ):((curr_frame - 1 + 1 )* frame_size )]
250251 if (args .verbose ):
251- verboseprint ('\t sending frame #' + str (curr_frame ) +
252+ verboseprint ('\t Sending frame #' + str (curr_frame ) +
252253 ', length: ' + str (len (frame_data )))
253254 else :
254255 percentComplete = curr_frame * 100 / total_frames
@@ -319,6 +320,9 @@ def main():
319320 num_tries = 3
320321
321322 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 ()
322326
323327 for _ in range (num_tries ):
324328
@@ -335,7 +339,7 @@ def main():
335339 if (bl_failed == False ):
336340 break
337341
338- except :
342+ except serial . SerialException :
339343 phase_serial_port_help ()
340344
341345 exit ()
0 commit comments