Changeset 709c1df in subsurface


Ignore:
Timestamp:
Jul 4, 2017, 7:46:07 AM (4 months ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
3cde4f5
Parents:
d6b17fe
git-author:
Jan Mulder <jlmulder@…> (07/04/17 00:03:30)
git-committer:
Dirk Hohndel <dirk@…> (07/04/17 07:46:07)
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/qt-ble.cpp

    rd6b17fe r709c1df  
    147147        Q_UNUSED(actual) // that seems like it might cause problems
    148148
     149        if (!receivedPackets.isEmpty()) {
     150                qDebug() << ".. write HIT with still incoming packets in queue";
     151        }
     152
    149153        QList<QLowEnergyCharacteristic> list = preferredService()->characteristics();
    150154        QByteArray bytes((const char *)data, (int) size);
     
    170174dc_status_t BLEObject::read(void *data, size_t size, size_t *actual)
    171175{
     176        *actual = 0;
    172177        if (receivedPackets.isEmpty()) {
    173178                QList<QLowEnergyCharacteristic> list = preferredService()->characteristics();
     
    186191                return DC_STATUS_IO;
    187192
    188         QByteArray packet = receivedPackets.takeFirst();
    189 
    190         if (device_is_shearwater(device))
    191                 packet.remove(0,2);
    192 
    193         if (size > (size_t)packet.size())
    194                 size = packet.size();
    195         memcpy(data, packet.data(), size);
    196         *actual = size;
     193        int offset = 0;
     194        while (!receivedPackets.isEmpty()) {
     195                while (!receivedPackets.isEmpty()) {
     196                        QByteArray packet = receivedPackets.takeFirst();
     197
     198                        if (device_is_shearwater(device))
     199                                packet.remove(0,2);
     200
     201                        //qDebug() << ".. read (packet.length, contents, size)" << packet.size() << packet.toHex() << size;
     202
     203                        if ((offset + packet.size()) > size) {
     204                                qDebug() << "BLE read trouble, receive buffer too small";
     205                                return DC_STATUS_NOMEMORY;
     206                        }
     207
     208                        memcpy((char *)data + offset, packet.data(), packet.size());
     209                        offset += packet.size();
     210                        *actual += packet.size();
     211                }
     212                waitFor(50); // and process some Qt events to see if there is more data coming in.
     213        }
    197214        return DC_STATUS_SUCCESS;
    198215}
Note: See TracChangeset for help on using the changeset viewer.