Changeset 57753321 in subsurface


Ignore:
Timestamp:
Jun 27, 2017, 11:03:19 AM (5 months ago)
Author:
Linus Torvalds <torvalds@…>
Branches:
master
Children:
e79bede
Parents:
81dabe5
git-author:
Alex Blasche <alexander.blasche@…> (06/27/17 05:56:30)
git-committer:
Linus Torvalds <torvalds@…> (06/27/17 11:03:19)
Message:

Ensure all found BLE services are tracked

If a device has more than one service the order of service discovery
determined the selection of the service that we intend to interact
with. This assumption is not accurate and is even platform dependent.

Thinking ahead, it is likely that some devices may require us to keep
track and interact with multiple services at the time.

The new logic still suffers from the fact that there is no way
to select the correct service for interaction. This will require
higher level stack changes.

Signed-off-by: Alex Blasche <alexander.blasche@…>
Signed-off-by: Linus Torvalds <torvalds@…>

Location:
core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • core/qt-ble.cpp

    r81dabe5 r57753321  
    2323        QList<QLowEnergyCharacteristic> list;
    2424
    25         list = service->characteristics();
     25        auto service = qobject_cast<QLowEnergyService*>(sender());
     26        if (service)
     27                list = service->characteristics();
    2628
    2729        Q_FOREACH(QLowEnergyCharacteristic c, list) {
     
    5153        }
    5254
    53         service = controller->createServiceObject(newService, this);
     55        auto service = controller->createServiceObject(newService, this);
    5456        qDebug() << " .. created service object" << service;
    5557        if (service) {
     58                services.append(service);
    5659                connect(service, &QLowEnergyService::stateChanged, this, &BLEObject::serviceStateChanged);
    5760                connect(service, &QLowEnergyService::characteristicChanged, this, &BLEObject::characteristcStateChanged);
     
    7376dc_status_t BLEObject::write(const void* data, size_t size, size_t *actual)
    7477{
    75         QList<QLowEnergyCharacteristic> list = service->characteristics();
     78        QList<QLowEnergyCharacteristic> list = preferredService()->characteristics();
    7679        QByteArray bytes((const char *)data, (int) size);
    7780
     
    8487                        QLowEnergyService::WriteWithResponse;
    8588
    86                 service->writeCharacteristic(c, bytes, mode);
     89                preferredService()->writeCharacteristic(c, bytes, mode);
    8790                return DC_STATUS_SUCCESS;
    8891        }
     
    9497{
    9598        if (receivedPackets.isEmpty()) {
    96                 QList<QLowEnergyCharacteristic> list = service->characteristics();
     99                QList<QLowEnergyCharacteristic> list = preferredService()->characteristics();
    97100                if (list.isEmpty())
    98101                        return DC_STATUS_IO;
     
    189192
    190193        qDebug() << " .. done waiting";
     194        if (ble->preferredService() == nullptr) {
     195                qDebug() << "failed to find suitable service on" << devaddr;
     196                report_error("Failed to find suitable service on '%s'", devaddr);
     197                controller->disconnectFromDevice();
     198                delete controller;
     199                return DC_STATUS_IO;
     200        }
     201
    191202
    192203        qDebug() << " .. enabling notifications";
    193204
    194205        /* Enable notifications */
    195         QList<QLowEnergyCharacteristic> list = ble->service->characteristics();
     206        QList<QLowEnergyCharacteristic> list = ble->preferredService()->characteristics();
    196207
    197208        if (!list.isEmpty()) {
     
    210221                        qDebug() << "now writing \"0x0100\" to the first descriptor";
    211222
    212                         ble->service->writeDescriptor(d, QByteArray::fromHex("0100"));
     223                        ble->preferredService()->writeDescriptor(d, QByteArray::fromHex("0100"));
    213224                }
    214225        }
  • core/qt-ble.h

    r63fc06e r57753321  
    33#define QT_BLE_H
    44
     5#include <QVector>
    56#include <QLowEnergyController>
    67#include <QEventLoop>
     
    1516        dc_status_t write(const void* data, size_t size, size_t *actual);
    1617        dc_status_t read(void* data, size_t size, size_t *actual);
    17         QLowEnergyService *service;
     18
     19        //TODO: need better mode of selecting the desired service than below
     20        inline QLowEnergyService *preferredService()
     21                                { return services.isEmpty() ? nullptr : services[0]; }
    1822
    1923public slots:
     
    2428
    2529private:
    26         QLowEnergyController *controller;
     30        QVector<QLowEnergyService *> services;
     31
     32        QLowEnergyController *controller = nullptr;
    2733        QList<QByteArray> receivedPackets;
    2834        QEventLoop waitForPacket;
Note: See TracChangeset for help on using the changeset viewer.