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>
This commit is contained in:
Linus Torvalds 2018-09-26 11:23:57 -07:00 committed by Dirk Hohndel
parent 8426024b76
commit 890d4c3d64

View file

@ -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)