From fc547cad2fffcaa354b170694796beddf37dd4a1 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 7 Jul 2013 01:48:13 +0000 Subject: added length field for messages git-svn-id: https://svn.spreadspace.org/pic/trunk@46 a09c6847-51d9-44de-8ef2-e725cf50f3c7 --- downloader/downloader.py | 53 ++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 24 deletions(-) (limited to 'downloader/downloader.py') diff --git a/downloader/downloader.py b/downloader/downloader.py index 9efb30e..f90eced 100755 --- a/downloader/downloader.py +++ b/downloader/downloader.py @@ -100,7 +100,7 @@ def calc_csum(str): cs ^= c return cs -def exec_command(dev, cmd, answer): +def exec_command(dev, cmd, param, answer): import struct return_codes = { 0: "OK", 1: "invalid command", 2: "bad checksum", @@ -108,21 +108,22 @@ def exec_command(dev, cmd, answer): 5: "address invalid", 6: "address prohibited", 7: "value out of bounds" } - cstr = bytearray(cmd) + cstr = bytearray(struct.pack(' 0: tmp = bytearray() tmp += dev.read(answer_len) if len(tmp) < answer_len: - print "ERROR: timeout while reading response" + print "ERROR: timeout while reading response (expected %d bytes, got %d)" % (answer_len, len(tmp)) sys.exit(4) astr += tmp @@ -146,12 +151,12 @@ def exec_command(dev, cmd, answer): print "ERROR: checksum error" sys.exit(4) - return struct.unpack_from(answer, astr, 2) + return struct.unpack_from(answer, astr, 3) ### Commands def identify(dev): - data = exec_command(dev, struct.pack('