From f442031fdd43c4ffc9cc2c10fe2c8efd604b1a53 Mon Sep 17 00:00:00 2001 From: Jan Mulder Date: Fri, 22 Sep 2017 10:03:42 +0200 Subject: 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 --- core/qtserialbluetooth.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'core') 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; -- cgit v1.2.3-70-g09d2