summaryrefslogtreecommitdiffstats
path: root/core/qtserialbluetooth.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2017-07-11 20:31:40 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-07-11 20:32:48 -0700
commitb9f691a70093f1174d07a28a8d05b436e46478b2 (patch)
tree160907bd555a9b19d6924892f551d2a61438084f /core/qtserialbluetooth.cpp
parent45f36e251bb780b6276fcbe78e6ea849ec3ecc2b (diff)
parentfbaaa64a4a3cf3266b8afe62af578105ec32a374 (diff)
downloadsubsurface-b9f691a70093f1174d07a28a8d05b436e46478b2.tar.gz
Merge branch 'hw-o-ble-2' of https://github.com/janmulder/subsurface
Doing a manual merge from the command line in order to retain Jan's SHAs so that the commit message makes sense... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/qtserialbluetooth.cpp')
-rw-r--r--core/qtserialbluetooth.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/core/qtserialbluetooth.cpp b/core/qtserialbluetooth.cpp
index 8b5779ce5..3a031e1ae 100644
--- a/core/qtserialbluetooth.cpp
+++ b/core/qtserialbluetooth.cpp
@@ -126,19 +126,34 @@ static dc_status_t ble_serial_read(dc_custom_io_t *io, void* data, size_t size,
{
Q_UNUSED(io)
size_t len;
+ size_t received = 0;
if (buffer.in_pos >= buffer.in_bytes) {
+ ble_serial_flush_write();
+ }
+
+ /* There is still unused/unread data in the input steam.
+ * So preseve it at the start of a new read.
+ */
+ if (buffer.in_pos > 0) {
+ len = buffer.in_bytes - buffer.in_pos;
+ memcpy(buffer.in, buffer.in + buffer.in_pos, len);
+ buffer.in_pos = 0;
+ buffer.in_bytes = len;
+ }
+
+ /* Read a long as requested in the size parameter */
+ while ((buffer.in_bytes - buffer.in_pos) < size) {
dc_status_t rc;
- size_t received;
- ble_serial_flush_write();
- rc = ble_serial_ops.packet_read(&ble_serial_ops, buffer.in, sizeof(buffer.in), &received);
+ rc = ble_serial_ops.packet_read(&ble_serial_ops, buffer.in + buffer.in_bytes,
+ sizeof(buffer.in) - buffer.in_bytes, &received);
if (rc != DC_STATUS_SUCCESS)
return rc;
if (!received)
return DC_STATUS_IO;
- buffer.in_pos = 0;
- buffer.in_bytes = received;
+
+ buffer.in_bytes += received;
}
len = buffer.in_bytes - buffer.in_pos;