From 18b11939bf24b2f75ea54eb93d7d29273262c476 Mon Sep 17 00:00:00 2001 From: Fredrik Thulin Date: Tue, 17 May 2016 09:50:38 +0200 Subject: Write in 4k-chunks, with acks for flow control. --- projects/cli-test/cli-test.c | 8 +++++--- 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('