summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Jan Mulder <jlmulder@xs4all.nl>2017-09-22 10:03:42 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-09-22 02:30:58 -0700
commitf442031fdd43c4ffc9cc2c10fe2c8efd604b1a53 (patch)
tree134604a4604d63f672b22475aa76d0019d5beb1c /core
parentbb1df1218d83aaa2bcb503e53246e19ab2e29c62 (diff)
downloadsubsurface-f442031fdd43c4ffc9cc2c10fe2c8efd604b1a53.tar.gz
BLE: big writes to connected DC (OSTC firmware)
Most writes to a connected DC are small, typically some command bytes to get DC in download mode, or to set some parameter. All this just worked over BLE, however, sending a full firmware update (on an OSTC device) failed, as the underlying BLE interface can only handle small 20 byte BLE packets at once. So, send max ble->packet_size chuncks at once. Tested for the following cases (linux desktop with OSTC3 over BLE): 1) normal download of dive data. 2) read and write settings from configure UI 3) update firmware (from 2.15 to 2.15) And to my surprise, no flow control credit administration is required here. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
Diffstat (limited to 'core')
-rw-r--r--core/qtserialbluetooth.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/core/qtserialbluetooth.cpp b/core/qtserialbluetooth.cpp
index ca721d78c..8e5fac499 100644
--- a/core/qtserialbluetooth.cpp
+++ b/core/qtserialbluetooth.cpp
@@ -169,15 +169,26 @@ static dc_status_t ble_serial_write(dc_custom_io_t *io, const void* data, size_t
size_t transferred = 0;
ble_serial_flush_read();
+
+ /*
+ * Most writes to a connected DC are small, typically some command bytes to get
+ * DC in download mode, or to set some parameter. All this just worked over BLE,
+ * however, sending a full firmware update (on an OSTC device) failed, as the
+ * underlying BLE interface can only handle small 20 byte BLE packets at once.
+ *
+ * So, send max ble->packet_size chuncks at once.
+ */
while (size) {
- size_t len = sizeof(buffer.out) - buffer.out_bytes;
+ size_t len = sizeof(buffer.out) - transferred;
+ if (len > io->packet_size)
+ len = io->packet_size;
if (len > size)
len = size;
memcpy(buffer.out + buffer.out_bytes, data, len);
buffer.out_bytes += len;
- if (buffer.out_bytes == sizeof(buffer.out)) {
+ if (buffer.out_bytes <= io->packet_size || buffer.out_bytes == size) {
rc = ble_serial_flush_write();
if (rc != DC_STATUS_SUCCESS)
break;