Changeset 5265956 in subsurface


Ignore:
Timestamp:
Jun 27, 2017, 3:14:27 PM (5 months ago)
Author:
Linus Torvalds <torvalds@…>
Branches:
master
Children:
fbdba88
Parents:
d01b7bf
Message:

Use SSRF_CUSTOM_IO v2 to implement device data quirks for BLE GATT

Right now we have a quirk for Shearwater devices to set the random
address flag, but also to handle the differences at read/write time.

With this, I can finally download from both the Suunto EON Steel and the
Shearwater Perdix AI with the same binary.

It's not *pretty*, but it works.

Signed-off-by: Linus Torvalds <torvalds@…>

Location:
core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • core/qt-ble.cpp

    re79bede r5265956  
    8181}
    8282
    83 BLEObject::BLEObject(QLowEnergyController *c)
     83BLEObject::BLEObject(QLowEnergyController *c, dc_user_device_t *d)
    8484{
    8585        controller = c;
     86        device = d;
    8687}
    8788
     
    9192}
    9293
    93 dc_status_t BLEObject::write(const void* data, size_t size, size_t *actual)
     94/* Yeah, I could do the C++ inline member thing */
     95static int device_is_shearwater(dc_user_device_t *device)
     96{
     97        return !strcmp(device->vendor, "Shearwater");
     98}
     99
     100dc_status_t BLEObject::write(const void *data, size_t size, size_t *actual)
    94101{
    95102        QList<QLowEnergyCharacteristic> list = preferredService()->characteristics();
     
    104111                        QLowEnergyService::WriteWithResponse;
    105112
     113                if (device_is_shearwater(device))
     114                        bytes.prepend("\1\0", 2);
     115
    106116                preferredService()->writeCharacteristic(c, bytes, mode);
    107117                return DC_STATUS_SUCCESS;
     
    111121}
    112122
    113 dc_status_t BLEObject::read(void* data, size_t size, size_t *actual)
     123dc_status_t BLEObject::read(void *data, size_t size, size_t *actual)
    114124{
    115125        if (receivedPackets.isEmpty()) {
     
    134144
    135145        QByteArray packet = receivedPackets.takeFirst();
     146
     147        if (device_is_shearwater(device))
     148                packet.remove(0,2);
     149
    136150        if (size > packet.size())
    137151                size = packet.size();
     
    162176        qDebug() << "qt_ble_open(" << devaddr << ")";
    163177
     178        if (device_is_shearwater(io->user_device))
     179                controller->setRemoteAddressType(QLowEnergyController::RandomAddress);
     180
    164181        // Try to connect to the device
    165182        controller->connectToDevice();
     
    185202
    186203        /* We need to discover services etc here! */
    187         BLEObject *ble = new BLEObject(controller);
     204        BLEObject *ble = new BLEObject(controller, io->user_device);
    188205        ble->connect(controller, SIGNAL(serviceDiscovered(QBluetoothUuid)), SLOT(addService(QBluetoothUuid)));
    189206
  • core/qt-ble.h

    r57753321 r5265956  
    1212
    1313public:
    14         BLEObject(QLowEnergyController *c);
     14        BLEObject(QLowEnergyController *c, dc_user_device_t *);
    1515        ~BLEObject();
    1616        dc_status_t write(const void* data, size_t size, size_t *actual);
     
    3333        QList<QByteArray> receivedPackets;
    3434        QEventLoop waitForPacket;
     35        dc_user_device_t *device;
    3536};
    3637
Note: See TracChangeset for help on using the changeset viewer.