mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
BLE: read until no more data in coming in
The current BLE read reads just one 20 bype packet. That packet size is set in ble_serial_ops, so, without being able to test on anything other than a OSTC3, I assume that this holds for other BLE DCs too. So, I think is is weird that those interfaces work with the current read() of just one packet at the time. As we need a blocking read (at least for the OSTC parser), just read all data that is available on the input. And when we think we are done, give the QtEventloop control to see if there is more, and process that incoming data as well. All this basically implements a blocking read. CAVEAT 1: This might break the reading from the currently working BLE devices. CAVEAT 2: With this, I still cannot read the OSTC3 completely. For developers familiar with the HW transfer protocol: it just stops while reading the first full dive (header + profile) command 0x66, despite correctly reading about 5Kb of data before. For some reason, I do not believe that this is related to this commit. CAVEAT 3: All above tested on Linux Desktop with bluez stack, and confirmed NOT to work on Android 7.1.2, build with Qt 5.9.0, And yes, I know 5.9.1 recommended. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
This commit is contained in:
parent
d6b17fef08
commit
709c1df2af
1 changed files with 24 additions and 7 deletions
|
@ -146,6 +146,10 @@ dc_status_t BLEObject::write(const void *data, size_t size, size_t *actual)
|
|||
{
|
||||
Q_UNUSED(actual) // that seems like it might cause problems
|
||||
|
||||
if (!receivedPackets.isEmpty()) {
|
||||
qDebug() << ".. write HIT with still incoming packets in queue";
|
||||
}
|
||||
|
||||
QList<QLowEnergyCharacteristic> list = preferredService()->characteristics();
|
||||
QByteArray bytes((const char *)data, (int) size);
|
||||
|
||||
|
@ -169,6 +173,7 @@ dc_status_t BLEObject::write(const void *data, size_t size, size_t *actual)
|
|||
|
||||
dc_status_t BLEObject::read(void *data, size_t size, size_t *actual)
|
||||
{
|
||||
*actual = 0;
|
||||
if (receivedPackets.isEmpty()) {
|
||||
QList<QLowEnergyCharacteristic> list = preferredService()->characteristics();
|
||||
if (list.isEmpty())
|
||||
|
@ -185,15 +190,27 @@ dc_status_t BLEObject::read(void *data, size_t size, size_t *actual)
|
|||
if (receivedPackets.isEmpty())
|
||||
return DC_STATUS_IO;
|
||||
|
||||
QByteArray packet = receivedPackets.takeFirst();
|
||||
int offset = 0;
|
||||
while (!receivedPackets.isEmpty()) {
|
||||
while (!receivedPackets.isEmpty()) {
|
||||
QByteArray packet = receivedPackets.takeFirst();
|
||||
|
||||
if (device_is_shearwater(device))
|
||||
packet.remove(0,2);
|
||||
if (device_is_shearwater(device))
|
||||
packet.remove(0,2);
|
||||
|
||||
if (size > (size_t)packet.size())
|
||||
size = packet.size();
|
||||
memcpy(data, packet.data(), size);
|
||||
*actual = size;
|
||||
//qDebug() << ".. read (packet.length, contents, size)" << packet.size() << packet.toHex() << size;
|
||||
|
||||
if ((offset + packet.size()) > size) {
|
||||
qDebug() << "BLE read trouble, receive buffer too small";
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
memcpy((char *)data + offset, packet.data(), packet.size());
|
||||
offset += packet.size();
|
||||
*actual += packet.size();
|
||||
}
|
||||
waitFor(50); // and process some Qt events to see if there is more data coming in.
|
||||
}
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue