aboutsummaryrefslogtreecommitdiff
path: root/projects
diff options
context:
space:
mode:
Diffstat (limited to 'projects')
-rw-r--r--projects/cli-test/cli-test.c8
-rwxr-xr-xprojects/cli-test/filetransfer21
2 files changed, 23 insertions, 6 deletions
diff --git a/projects/cli-test/cli-test.c b/projects/cli-test/cli-test.c
index 86e11ce..6102d32 100644
--- a/projects/cli-test/cli-test.c
+++ b/projects/cli-test/cli-test.c
@@ -62,20 +62,24 @@ int cmd_filetransfer(struct cli_def *cli, const char *command, char *argv[], int
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);
+ cli_print(cli, "File size %li", filesize);
while (filesize) {
if (filesize < n) {
n = filesize;
}
- uart_receive_bytes(STM_UART_MGMT, (void *) &buf, n, 1000);
+ if (uart_receive_bytes(STM_UART_MGMT, (void *) &buf, n, 1000) != HAL_OK) {
+ cli_print(cli, "Receive timed out");
+ return CLI_ERROR;
+ }
filesize -= n;
my_crc = update_crc(my_crc, buf, n);
counter++;
uart_send_bytes(STM_UART_MGMT, (void *) &counter, 4);
}
+ cli_print(cli, "Send CRC-32");
uart_receive_bytes(STM_UART_MGMT, (void *) &crc, 4, 1000);
cli_print(cli, "CRC-32 %li", crc);
if (crc == my_crc) {
diff --git a/projects/cli-test/filetransfer b/projects/cli-test/filetransfer
index 3e8e043..674a7f1 100755
--- a/projects/cli-test/filetransfer
+++ b/projects/cli-test/filetransfer
@@ -51,7 +51,7 @@ def send_file(filename, device='/dev/ttyUSB0', initiate=True):
size = s.st_size
src = open(filename, 'rb')
- dst = serial.Serial(device, 921600, timeout=1)
+ dst = serial.Serial(device, 921600, timeout=0.1)
if initiate:
response = _execute(dst, 'filetransfer')
@@ -71,12 +71,25 @@ def send_file(filename, device='/dev/ttyUSB0', initiate=True):
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]
+ # read ACK (a counter of number of 4k chunks received)
+ while True:
+ ack = dst.read(4)
+ if len(ack) == 4:
+ break
+ print('ERROR: Did not receive an ACK, got {!r}'.format(ack))
+ dst.write('\r')
+ new_counter = struct.unpack('<I', ack)[0]
if new_counter != counter + 1:
- print('ERROR: Did not receive the expected counter as ACK (got {!r}, not {!r})'.format(new_counter, counter))
+ print('ERROR: Did not receive the expected counter as ACK (got {!r}/{!r}, not {!r})'.format(new_counter, ack, counter))
+ flush = dst.read(100)
+ print('FLUSH data: {!r}'.format(flush))
return False
counter += 1
+
+ crc = crc32(data, crc) & 0xffffffff
+
+ _read(dst)
+
# 3. Write CRC-32 (4 bytes)
_write(dst, struct.pack('<I', crc))
_read(dst)