diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-09-26 11:23:57 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-09-26 12:13:20 -0700 |
commit | 890d4c3d649dd55817d4bb85d62ad433a61cebe4 (patch) | |
tree | b67cab20df81c1b4b0a4fa7b670f5c1bec49123f | |
parent | 8426024b76ebc6e3aa3def24aa077a5b7442347c (diff) | |
download | subsurface-890d4c3d649dd55817d4bb85d62ad433a61cebe4.tar.gz |
qt-ble: allow reading of partial packet data
The existing BLE dive computers treat BLE as the packetized protocol it
is, and read whole packets at a time.
However, the Mares BlueLink backend treats it as just a basic "serial
over BLE" transport, and for historical reasons reads the reply packets
in smaller chunks.
This allows that kind of IO behavior, where if the divecomputer backend
reads just a part of a packet, we'll split the packet, return the part
the user asked for, and push back the leftover packet onto the received
packet queue.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | core/qt-ble.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/core/qt-ble.cpp b/core/qt-ble.cpp index 8d4003d0f..ece3bc6cf 100644 --- a/core/qt-ble.cpp +++ b/core/qt-ble.cpp @@ -191,8 +191,15 @@ dc_status_t BLEObject::read(void *data, size_t size, size_t *actual) QByteArray packet = receivedPackets.takeFirst(); - if ((size_t)packet.size() > size) - return DC_STATUS_NOMEMORY; + // Did we get more than asked for? + // + // Put back the left-over at the beginning of the + // received packet list, and truncate the packet + // we got to just the part asked for. + if ((size_t)packet.size() > size) { + receivedPackets.prepend(packet.mid(size)); + packet.truncate(size); + } memcpy((char *)data, packet.data(), packet.size()); if (actual) |