summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2013-07-06 22:49:22 +0000
committerChristian Pointner <equinox@spreadspace.org>2013-07-06 22:49:22 +0000
commit2c63756b9244efe191d2038a7ec65261f04718f9 (patch)
treefc6e64bb8dd9bfbb139a4733eabea5d27a69b001
parentshorter version of command code check (diff)
read_flash_segment works now
added timeout for responses from bootloader git-svn-id: https://svn.spreadspace.org/pic/trunk@43 a09c6847-51d9-44de-8ef2-e725cf50f3c7
-rwxr-xr-xdownloader/downloader.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/downloader/downloader.py b/downloader/downloader.py
index 8da13cf..9efb30e 100755
--- a/downloader/downloader.py
+++ b/downloader/downloader.py
@@ -85,7 +85,7 @@ def open_serial(device, baud):
print "opening %s (%s Baud)" % (device, baud)
try:
- dev = serial.Serial(port=device, baudrate=baud)
+ dev = serial.Serial(port=device, baudrate=baud, timeout=3)
dev.flushInput()
dev.flushOutput()
return dev
@@ -114,6 +114,9 @@ def exec_command(dev, cmd, answer):
astr = bytearray()
astr += dev.read(3)
+ if len(astr) < 3:
+ print "ERROR: timeout while reading response header"
+ sys.exit(4)
if astr[0] != cstr[0]:
print "ERROR: bootloader returned wrong command code"
@@ -130,7 +133,14 @@ def exec_command(dev, cmd, answer):
sys.exit(4)
answer_len = struct.calcsize(answer)
- astr += dev.read(answer_len)
+ if answer_len > 0:
+ tmp = bytearray()
+ tmp += dev.read(answer_len)
+ if len(tmp) < answer_len:
+ print "ERROR: timeout while reading response"
+ sys.exit(4)
+
+ astr += tmp
if 0 != calc_csum(astr):
print "ERROR: checksum error"