diff options
author | Timur Pocheptsov <Timur.Pocheptsov@digia.com> | 2014-11-28 13:42:18 +0100 |
---|---|---|
committer | Timur Pocheptsov <Timur.Pocheptsov@digia.com> | 2014-12-01 11:08:23 +0100 |
commit | 68332a47fbcc124efedf73b106b7e06bfacd65fd (patch) | |
tree | aa245330d234ae5539a0479388116e6c773eeef6 /src/bluetooth/qlowenergycontroller_osx.mm | |
parent | 0e3046f29b0e86affeb33c8f6687618cfd1dfae2 (diff) |
Bluetooth LE - handles/chars/descriptors/services (OS X and iOS)
In Qt we work with handles (real for Bluez, emulated for Android/iOS/OS X).
Core Bluetooth has its own (quite primitive and inconvenient) data structures
(arrays of objects, containing nested arrays).
To make things not so ugly I'm adding several
maps to be able to find a characteristic/descriptor/service using a
handle from Qt's layer.
Also modify writeCharacteristic to use this new 'addressing scheme'.
Change-Id: Ic822c9aa82a4df1e9c4cf4c673451cac8006b9ba
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/bluetooth/qlowenergycontroller_osx.mm')
-rw-r--r-- | src/bluetooth/qlowenergycontroller_osx.mm | 67 |
1 files changed, 19 insertions, 48 deletions
diff --git a/src/bluetooth/qlowenergycontroller_osx.mm b/src/bluetooth/qlowenergycontroller_osx.mm index f41423d8..88ec6421 100644 --- a/src/bluetooth/qlowenergycontroller_osx.mm +++ b/src/bluetooth/qlowenergycontroller_osx.mm @@ -43,6 +43,7 @@ #include <QtCore/qloggingcategory.h> #include <QtCore/qsharedpointer.h> +#include <QtCore/qbytearray.h> #include <QtCore/qglobal.h> #include <QtCore/qstring.h> #include <QtCore/qlist.h> @@ -319,59 +320,23 @@ void QLowEnergyControllerPrivateOSX::serviceDiscoveryFinished(LEServices service void QLowEnergyControllerPrivateOSX::serviceDetailsDiscoveryFinished(LEService service) { - if (!service) { - qCDebug(QT_BT_OSX) << "QLowEnergyControllerPrivateOSX::serviceDetailsDiscoveryFinished(), " - "invalid service (nil)"; - return; - } + Q_ASSERT_X(!service.isNull(), "serviceDetailsDiscoveryFinished", + "invalid service (null)"); QT_BT_MAC_AUTORELEASEPOOL; - const QBluetoothUuid qtUuid(OSXBluetooth::qt_uuid(service.data().UUID)); - if (!discoveredServices.contains(qtUuid)) { + if (!discoveredServices.contains(service->uuid)) { qCDebug(QT_BT_OSX) << "QLowEnergyControllerPrivateOSX::serviceDetailsDiscoveryFinished(), " - "unknown service uuid: " << qtUuid; + "unknown service uuid: " << service->uuid; return; } - ServicePrivate qtService(discoveredServices.value(qtUuid)); - qtService->startHandle = ++lastValidHandle; - // Now we iterate on characteristics and descriptors (if any). - NSArray *const cs = service.data().characteristics; - if (cs && cs.count) { - QHash<QLowEnergyHandle, QLowEnergyServicePrivate::CharData> charList; - // That's not a real handle - just a key into a hash map. - for (CBCharacteristic *c in cs) { - QLowEnergyServicePrivate::CharData newChar = {}; - newChar.uuid = OSXBluetooth::qt_uuid(c.UUID); - // CBCharacteristicProperty enum has the same values as Qt + - // a couple of values above 'extended' we do not support yet - mask them out. - // All other possible enumerators are the same: - const int cbProps = c.properties & 0xff; - newChar.properties = static_cast<QLowEnergyCharacteristic::PropertyTypes>(cbProps); - newChar.value = OSXBluetooth::qt_bytearray(c.value); - newChar.valueHandle = ++lastValidHandle; - - NSArray *const ds = c.descriptors; - if (ds && ds.count) { - QHash<QLowEnergyHandle, QLowEnergyServicePrivate::DescData> descList; - for (CBDescriptor *d in ds) { - QLowEnergyServicePrivate::DescData newDesc = {}; - newDesc.uuid = OSXBluetooth::qt_uuid(d.UUID); - newDesc.value = OSXBluetooth::qt_bytearray(d.value); - descList[++lastValidHandle] = newDesc; - } - - newChar.descriptorList = descList; - } - - charList[newChar.valueHandle] = newChar; - } + ServicePrivate qtService(discoveredServices.value(service->uuid)); + // Assert on handles? + qtService->startHandle = service->startHandle; + qtService->endHandle = service->endHandle; + qtService->characteristicList = service->characteristicList; - qtService->characteristicList = charList; - } - - qtService->endHandle = lastValidHandle; qtService->stateChanged(QLowEnergyService::ServiceDiscovered); } @@ -557,6 +522,14 @@ void QLowEnergyControllerPrivateOSX::discoverServiceDetails(const QBluetoothUuid } } +void QLowEnergyControllerPrivateOSX::setNotifyValue(QSharedPointer<QLowEnergyServicePrivate> service, + QLowEnergyHandle charHandle, const QByteArray &newValue) +{ + Q_UNUSED(service) + Q_UNUSED(charHandle) + Q_UNUSED(newValue) +} + void QLowEnergyControllerPrivateOSX::writeCharacteristic(QSharedPointer<QLowEnergyServicePrivate> service, QLowEnergyHandle charHandle, const QByteArray &newValue, bool writeWithResponse) @@ -585,9 +558,7 @@ void QLowEnergyControllerPrivateOSX::writeCharacteristic(QSharedPointer<QLowEner } const bool result = [centralManager write:newValue - characteristic:charHandle - serviceUuid:service->uuid - serviceHandle:service->startHandle + charHandle:charHandle withResponse:writeWithResponse]; if (!result) service->setError(QLowEnergyService::CharacteristicWriteError); |