aboutsummaryrefslogtreecommitdiff
path: root/projects/cli-test/filetransfer
diff options
context:
space:
mode:
authorFredrik Thulin <fredrik@thulin.net>2016-05-17 09:50:38 +0200
committerFredrik Thulin <fredrik@thulin.net>2016-05-18 14:12:03 +0200
commit18b11939bf24b2f75ea54eb93d7d29273262c476 (patch)
treece6d47c7e8e2320efab3862aee22e8b5d363e73e /projects/cli-test/filetransfer
parent3b044e50d3295c04863bdb0587a6eef157e654b8 (diff)
Write in 4k-chunks, with acks for flow control.
Diffstat (limited to 'projects/cli-test/filetransfer')
-rwxr-xr-xprojects/cli-test/filetransfer8
1 files changed, 7 insertions, 1 deletions
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)