Skip to content

Commit 13fddde

Browse files
author
Nathan Seidle
committed
Bringing back serial exception handling. See issue 119.
Fixed small capitalization nits. Change error packet printing to verbose.
1 parent cb1b3cf commit 13fddde

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

tools/artemis/artemis_svl.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import sys
4040
import time
4141
import math
42+
import os.path
4243
from sys import exit
4344

4445
# ***********************************************************************************
@@ -166,11 +167,11 @@ def phase_setup(ser):
166167

167168
baud_detect_byte = b'U'
168169

169-
verboseprint('\nphase:\tsetup')
170+
verboseprint('\nPhase:\tSetup')
170171

171172
# Handle the serial startup blip
172173
ser.reset_input_buffer()
173-
verboseprint('\tcleared startup blip')
174+
verboseprint('\tCleared 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('\nphase:\tbootload')
204+
verboseprint('\nPhase:\tBootload')
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\terror receiving packet')
227-
print(packet)
228-
print('\n')
227+
verboseprint('\n\tError 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\tretrying...')
238+
verboseprint('\t\tRetrying...')
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('\tsending frame #'+str(curr_frame) +
252+
verboseprint('\tSending 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\nArtemis 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

Comments
 (0)