diff options
author | Fredrik Thulin <fredrik@thulin.net> | 2016-05-17 09:50:38 +0200 |
---|---|---|
committer | Fredrik Thulin <fredrik@thulin.net> | 2016-05-18 14:12:03 +0200 |
commit | 18b11939bf24b2f75ea54eb93d7d29273262c476 (patch) | |
tree | ce6d47c7e8e2320efab3862aee22e8b5d363e73e | |
parent | 3b044e50d3295c04863bdb0587a6eef157e654b8 (diff) |
Write in 4k-chunks, with acks for flow control.
-rw-r--r-- | projects/cli-test/cli-test.c | 8 | ||||
-rwxr-xr-x | projects/cli-test/filetransfer | 8 |
2 files changed, 12 insertions, 4 deletions
diff --git a/projects/cli-test/cli-test.c b/projects/cli-test/cli-test.c index 0b54e7e..5d33b27 100644 --- a/projects/cli-test/cli-test.c +++ b/projects/cli-test/cli-test.c @@ -49,10 +49,10 @@ extern uint32_t update_crc(uint32_t crc, uint8_t *buf, int len); int cmd_filetransfer(struct cli_def *cli, const char *command, char *argv[], int argc) { - uint32_t filesize = 0, crc = 0, my_crc = 0, n = 4; - uint8_t buf[4]; + uint32_t filesize = 0, crc = 0, my_crc = 0, n = 4096, counter = 0; + uint8_t buf[4096]; - cli_print(cli, "OK, write file size (4 bytes), data, CRC-32 (4 bytes)"); + cli_print(cli, "OK, write file size (4 bytes), data in 4096 byte chunks, CRC-32 (4 bytes)"); uart_receive_bytes(STM_UART_MGMT, (void *) &filesize, 4, 1000); cli_print(cli, "Filesize %li", filesize); @@ -65,6 +65,8 @@ int cmd_filetransfer(struct cli_def *cli, const char *command, char *argv[], int uart_receive_bytes(STM_UART_MGMT, (void *) &buf, n, 1000); filesize -= n; my_crc = update_crc(my_crc, buf, n); + counter++; + uart_send_bytes(STM_UART_MGMT, (void *) &counter, 4); } uart_receive_bytes(STM_UART_MGMT, (void *) &crc, 4, 1000); diff --git a/projects/cli-test/filetransfer b/projects/cli-test/filetransfer index 451a1d9..3e8e043 100755 --- a/projects/cli-test/filetransfer +++ b/projects/cli-test/filetransfer @@ -64,13 +64,19 @@ def send_file(filename, device='/dev/ttyUSB0', initiate=True): _read(dst) # 2. Write file contents while calculating CRC-32 crc = 0 + counter = 0 while True: - data = src.read(1024) + data = src.read(4096) if not data: break dst.write(data) print("Wrote {!s} bytes".format(len(data))) crc = crc32(data, crc) & 0xffffffff + new_counter = struct.unpack('<I', dst.read(4))[0] + if new_counter != counter + 1: + print('ERROR: Did not receive the expected counter as ACK (got {!r}, not {!r})'.format(new_counter, counter)) + return False + counter += 1 # 3. Write CRC-32 (4 bytes) _write(dst, struct.pack('<I', crc)) _read(dst) |