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 ++++++++++++++++++++++++++---------------------- downloader/proto.txt | 52 ++++++++++++++++++++++++----------------------- 2 files changed, 56 insertions(+), 49 deletions(-) (limited to 'downloader') 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(' (in this case will always be 1) + 1 | len=3 | answer: - 1 | | version | name | devid | fss | mess | supported | + 1 | len=22 | | version | name | devid | fss | mess | supported | version: 2bytes, protocol version @@ -64,7 +66,7 @@ identify: operation first. mess: - 2bytes, maximum eeprom segment size + 1byte, maximum eeprom segment size This represents the maximum number of eeprom bytes which may be written or read at once. Unlike value it is ok to write or read less than bytes. @@ -89,10 +91,10 @@ boot: ~~~~~ command: - 2 | (in this case will always be 2) + 2 | len=3 | answer: - 2 | | + 2 | len=4 | | This instucts the bootloader to boot to the user application directly (no reset) @@ -101,10 +103,10 @@ reset: ~~~~~~ command: - 3 | (in this case will always be 3) + 3 | len=3 | answer: - 3 | | + 3 | len=4 | | The device performs a reboot. If the boot condition (i.e.: port pin) is not met this instructs the device to boot to the user application. @@ -114,10 +116,10 @@ read flash: ~~~~~~~~~~~ command: - 4 | addr | + 4 | len=5 | addr | answer: - 4 | | data | + 4 | len=4+2* | | data | The bootloader reads words from flash address and returns it as . @@ -127,10 +129,10 @@ write flash: ~~~~~~~~~~~~ command: - 5 | addr | data | + 5 | len=5+2* | addr | data | answer: - 5 | | + 5 | len=4 | | The bootloader writes (which has to contain exactly words) to address inside the flash. The start address has to be aligned to boundaries. @@ -142,36 +144,36 @@ read eeprom: ~~~~~~~~~~~~ command: - 6 | addr | len | + 6 | len=5 | addr | len | answer: - 6 | | data | + 6 | len=4+ | | data | The bootloader reads bytes from eeprom at address and returns it as - . len is 2bytes long. + . len is 1byte long. write eeprom: ~~~~~~~~~~~~~ command: - 7 | addr | len | data | + 7 | len=4+2 answer: - 7 | | + 7 | len=4 | | The bootloader writes (which has to contain exactly bytes) to address - inside the eeprom. len is 2bytes long and the value must not exceed bytes. + inside the eeprom. len is 1byte long and the value must not exceed bytes. read config: ~~~~~~~~~~~~ command: - 8 | nr | + 8 | len=3 | nr | answer: - 8 | | word | + 8 | len=6 | | word | The bootloader reads and returns the configuration word number . is one byte long. @@ -181,10 +183,10 @@ write config: ~~~~~~~~~~~~~ command: - 9 | nr | word | + 9 | len=5 | nr | word | answer: - 9 | | + 9 | len=4 | | The bootloader writes onto configuration word number . is one byte long. -- cgit v1.2.3