diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2014-05-28 16:22:19 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-06-04 13:41:18 +0200 |
commit | 622288ecb7d194b8c3ca08effc3315e1734c251e (patch) | |
tree | 54d278ec6c788bf7617008ceb9db3f43798dcd5a /src/bluetooth | |
parent | 96f46e71d0d76f4d5063c95bbe50165391a20a4f (diff) |
Streamline some of the QLowEnergyDescriptorInfo related code
1. QLowEnergyDescriptorInfo::type() added
2. QLowEnergyDescriptorInfo ctor signature modified
3. QBluetoothUuid::DescriptorId enum renamed
4. QLowEnergyDescriptorInfo::uuid() changed its meaning
5. QBluetoothUuid(CharacteristicDescriptor) ctor added
Starting from this change QNX is going to be broken. In particular
point 2 cause breaks or bug. The focus is on santizing the API at
this point in time.
Change-Id: I7838f550410b6a0f94026b68ecf0751533eba3cb
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src/bluetooth')
-rw-r--r-- | src/bluetooth/qbluetoothuuid.cpp | 21 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothuuid.h | 7 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycharacteristicinfo.h | 6 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontroller_bluez.cpp | 32 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontroller_qnx.cpp | 1 | ||||
-rw-r--r-- | src/bluetooth/qlowenergydescriptorinfo.cpp | 24 | ||||
-rw-r--r-- | src/bluetooth/qlowenergydescriptorinfo.h | 7 | ||||
-rw-r--r-- | src/bluetooth/qlowenergydescriptorinfo_p.h | 4 | ||||
-rw-r--r-- | src/bluetooth/qlowenergyprocess_bluez.cpp | 2 |
9 files changed, 75 insertions, 29 deletions
diff --git a/src/bluetooth/qbluetoothuuid.cpp b/src/bluetooth/qbluetoothuuid.cpp index 730a58e3..89f14440 100644 --- a/src/bluetooth/qbluetoothuuid.cpp +++ b/src/bluetooth/qbluetoothuuid.cpp @@ -375,9 +375,11 @@ Q_GLOBAL_STATIC_WITH_ARGS(QUuid, baseUuid, ("{00000000-0000-1000-8000-00805F9B34 */ /*! - \enum QBluetoothUuid::DescriptorID + \enum QBluetoothUuid::CharacteristicDescriptor - This enum is a convienience type for Bluetooth low energy service descriptor class UUIDs. Values of this type + Descriptors are attributes that describe Bluetooth Low Energy characteristic values. + + This enum is a convienience type for descriptor class UUIDs. Values of this type will be implicitly converted into a QBluetoothUuid when necessary. \value CharacteristicExtendedProperties Descriptor defines additional Characteristic Properties. @@ -426,9 +428,9 @@ QBluetoothUuid::QBluetoothUuid(ServiceClassUuid uuid) } /*! - Constructs a new Bluetooth UUID from the characteristic id \a uuid. + Constructs a new Bluetooth UUID from the characteristic type \a uuid. */ -QBluetoothUuid::QBluetoothUuid(CharacteristicId uuid) +QBluetoothUuid::QBluetoothUuid(CharacteristicType uuid) : QUuid(uuid, baseUuid()->data2, baseUuid()->data3, baseUuid()->data4[0], baseUuid()->data4[1], baseUuid()->data4[2], baseUuid()->data4[3], baseUuid()->data4[4], baseUuid()->data4[5], baseUuid()->data4[6], baseUuid()->data4[7]) @@ -436,6 +438,17 @@ QBluetoothUuid::QBluetoothUuid(CharacteristicId uuid) } /*! + Constructs a new Bluetooth UUID from the descriptor type \a uuid. +*/ +QBluetoothUuid::QBluetoothUuid(QBluetoothUuid::CharacteristicDescriptor uuid) + : QUuid(uuid, baseUuid()->data2, baseUuid()->data3, baseUuid()->data4[0], baseUuid()->data4[1], + baseUuid()->data4[2], baseUuid()->data4[3], baseUuid()->data4[4], baseUuid()->data4[5], + baseUuid()->data4[6], baseUuid()->data4[7]) +{ + +} + +/*! Constructs a new Bluetooth UUID from the 16 bit \a uuid. */ QBluetoothUuid::QBluetoothUuid(quint16 uuid) diff --git a/src/bluetooth/qbluetoothuuid.h b/src/bluetooth/qbluetoothuuid.h index ee3477ac..e98bb5a5 100644 --- a/src/bluetooth/qbluetoothuuid.h +++ b/src/bluetooth/qbluetoothuuid.h @@ -176,7 +176,7 @@ public: LocationAndNavigation = 0x1819, }; - enum CharacteristicId { + enum CharacteristicType { AlertCategoryID = 0x2a43, AlertCategoryIDBitMask = 0x2a42, AlertLevel = 0x2a06, @@ -260,7 +260,7 @@ public: UnreadAlertStatus = 0x2a45 }; - enum DescriptorID { + enum CharacteristicDescriptor { CharacteristicExtendedProperties = 0x2900, CharacteristicUserDescription = 0x2901, ClientCharacteristicConfiguration = 0x2902, @@ -275,7 +275,8 @@ public: QBluetoothUuid(); QBluetoothUuid(ProtocolUuid uuid); QBluetoothUuid(ServiceClassUuid uuid); - QBluetoothUuid(CharacteristicId uuid); + QBluetoothUuid(CharacteristicType uuid); + QBluetoothUuid(CharacteristicDescriptor uuid); explicit QBluetoothUuid(quint16 uuid); explicit QBluetoothUuid(quint32 uuid); explicit QBluetoothUuid(quint128 uuid); diff --git a/src/bluetooth/qlowenergycharacteristicinfo.h b/src/bluetooth/qlowenergycharacteristicinfo.h index e8746b04..ea6750cb 100644 --- a/src/bluetooth/qlowenergycharacteristicinfo.h +++ b/src/bluetooth/qlowenergycharacteristicinfo.h @@ -1,5 +1,6 @@ /*************************************************************************** ** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Copyright (C) 2013 BlackBerry Limited all rights reserved ** Contact: http://www.qt-project.org/legal ** @@ -57,6 +58,7 @@ class Q_BLUETOOTH_EXPORT QLowEnergyCharacteristicInfo friend class QLowEnergyControllerPrivate; public: + //TODO rename enum name enum Property { Broadcasting = 0x01, Read = 0x02, @@ -82,9 +84,9 @@ public: void setValue(const QByteArray &value); QByteArray value() const; - int permissions() const; + int permissions() const; //TODO should be of Type QLowEnergyCharacteristicInfo::Property QVariantMap properties() const; - QString handle() const; + QString handle() const; //TODO should be int bool isNotificationCharacteristic() const; diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp index 42ae9101..bebce1cf 100644 --- a/src/bluetooth/qlowenergycontroller_bluez.cpp +++ b/src/bluetooth/qlowenergycontroller_bluez.cpp @@ -1,5 +1,6 @@ /*************************************************************************** ** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Copyright (C) 2013 BlackBerry Limited all rights reserved ** Contact: http://www.qt-project.org/legal ** @@ -257,9 +258,10 @@ void QLowEnergyControllerPrivate::_q_replyReceived(const QString &reply) } } if (index1 != -1) { - for (int j = 0; j < (m_leServices.at(index1).d_ptr->characteristicList.size()-1); j++) { - QLowEnergyCharacteristicInfo chars = m_leServices.at(index1).d_ptr->characteristicList.at(j); - QLowEnergyCharacteristicInfo charsNext = m_leServices.at(index1).d_ptr->characteristicList.at(j+1); + QLowEnergyServiceInfo service = m_leServices.at(index1); + for (int j = 0; j < service.d_ptr->characteristicList.size()-1; j++) { + QLowEnergyCharacteristicInfo chars = service.d_ptr->characteristicList.at(j); + QLowEnergyCharacteristicInfo charsNext = service.d_ptr->characteristicList.at(j+1); const QString handleId = handleDetails.at(1); ushort h = handleId.toUShort(0, 0); qCDebug(QT_BT_BLUEZ) << handleId << h << chars.handle() << chars.handle().toUShort(0,0); @@ -267,25 +269,25 @@ void QLowEnergyControllerPrivate::_q_replyReceived(const QString &reply) if (h > chars.handle().toUShort(0,0) && h < charsNext.handle().toUShort(0,0)) { chars.d_ptr->notificationHandle = handleId; chars.d_ptr->notification = true; - QBluetoothUuid descUuid((ushort)0x2902); - QLowEnergyDescriptorInfo descriptor(descUuid, handleId); + QLowEnergyDescriptorInfo descriptor( + service.d_ptr->characteristicList[j].uuid(), + QBluetoothUuid::ClientCharacteristicConfiguration, + handleId); QString val; //TODO why do we start parsing value from k = 0? Shouldn't it be k = 2 for (int k = 3; k < handleDetails.size(); k++) val = val + handleDetails.at(k); descriptor.d_ptr->m_value = val.toUtf8(); - QVariantMap map; - map[QStringLiteral("uuid")] = descUuid.toString(); - map[QStringLiteral("handle")] = handleId; - map[QStringLiteral("value")] = val.toUtf8(); - m_leServices.at(index1).d_ptr->characteristicList[j].d_ptr->descriptorsList.append(descriptor); - qCDebug(QT_BT_BLUEZ) << "Notification characteristic set." << chars.d_ptr->handle << chars.d_ptr->notificationHandle; + service.d_ptr->characteristicList[j].d_ptr->descriptorsList.append(descriptor); + qCDebug(QT_BT_BLUEZ) << "Notification characteristic set." + << chars.d_ptr->handle + << chars.d_ptr->notificationHandle; } } if (!lastStep) { - m_leServices.at(index1).d_ptr->m_step++; - m_leServices.at(index1).d_ptr->connected = true; - emit q_ptr->connected(m_leServices.at(index1)); + service.d_ptr->m_step++; + service.d_ptr->connected = true; + emit q_ptr->connected(service); } lastStep = true; } @@ -362,6 +364,8 @@ void QLowEnergyControllerPrivate::setCharacteristics(int a) void QLowEnergyControllerPrivate::setNotifications() { + // TODO at the moment we only search for 2902 descriptors + // it doesn't show all 2902's and we leave a lot of other descriptors out process->executeCommand(QStringLiteral("char-read-uuid 2902")); } diff --git a/src/bluetooth/qlowenergycontroller_qnx.cpp b/src/bluetooth/qlowenergycontroller_qnx.cpp index ac8bb551..8fd687bb 100644 --- a/src/bluetooth/qlowenergycontroller_qnx.cpp +++ b/src/bluetooth/qlowenergycontroller_qnx.cpp @@ -620,6 +620,7 @@ void QLowEnergyControllerPrivate::readDescriptors(QLowEnergyCharacteristicInfo & descriptor.d_ptr->instance = characteristic.d_ptr->instance; map[QStringLiteral("value")] = descriptor.d_ptr->m_value; descriptor.d_ptr->m_properties = map; + //TODO what are these properties? Bluez doesn't have these atm characteristic.d_ptr->descriptorsList.append(descriptor); } diff --git a/src/bluetooth/qlowenergydescriptorinfo.cpp b/src/bluetooth/qlowenergydescriptorinfo.cpp index c72ee946..05f66a15 100644 --- a/src/bluetooth/qlowenergydescriptorinfo.cpp +++ b/src/bluetooth/qlowenergydescriptorinfo.cpp @@ -1,5 +1,6 @@ /*************************************************************************** ** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Copyright (C) 2013 BlackBerry Limited. All rights reserved. ** Contact: http://www.qt-project.org/legal ** @@ -97,12 +98,17 @@ QLowEnergyDescriptorInfo::QLowEnergyDescriptorInfo(const QBluetoothUuid &uuid): } /*! - Construct a new QLowEnergyDescriptorInfo with given \a uuid and the \a handle. + \internal + Construct a new QLowEnergyDescriptorInfo with given parent + characteristic \a uuid, descriptor \a type and \a handle. */ -QLowEnergyDescriptorInfo::QLowEnergyDescriptorInfo(const QBluetoothUuid &uuid, const QString &handle): +QLowEnergyDescriptorInfo::QLowEnergyDescriptorInfo(const QBluetoothUuid &uuid, + QBluetoothUuid::CharacteristicDescriptor type, + const QString &handle): d_ptr(new QLowEnergyDescriptorInfoPrivate(uuid, handle)) { - d_ptr->m_name = parseDescriptorUuid(uuid); + d_ptr->m_type = type; + d_ptr->m_name = parseDescriptorUuid(uuid); } /*! @@ -124,8 +130,10 @@ QLowEnergyDescriptorInfo &QLowEnergyDescriptorInfo::operator=(const QLowEnergyDe } /*! - Returns the UUID of the descriptor. + Returns the UUID of the characteristic that this descriptor belongs to. */ + +//TODO should this return the characteristic uuid or indeed 0x2902? QBluetoothUuid QLowEnergyDescriptorInfo::uuid() const { return d_ptr->m_uuid; @@ -164,6 +172,14 @@ QString QLowEnergyDescriptorInfo::name() const } /*! + Returns the type of descriptor. + */ +QBluetoothUuid::CharacteristicDescriptor QLowEnergyDescriptorInfo::type() const +{ + return d_ptr->m_type; +} + +/*! Sets the value \a value of the descriptor. This only caches the value. To write a value directly to the device QLowEnergyController class must be used. diff --git a/src/bluetooth/qlowenergydescriptorinfo.h b/src/bluetooth/qlowenergydescriptorinfo.h index 272922b9..de33ffac 100644 --- a/src/bluetooth/qlowenergydescriptorinfo.h +++ b/src/bluetooth/qlowenergydescriptorinfo.h @@ -1,5 +1,6 @@ /*************************************************************************** ** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Copyright (C) 2013 BlackBerry Limited. All rights reserved. ** Contact: http://www.qt-project.org/legal ** @@ -68,9 +69,13 @@ public: QVariantMap properties() const; QString name() const; + QBluetoothUuid::CharacteristicDescriptor type() const; + private: QSharedPointer<QLowEnergyDescriptorInfoPrivate> d_ptr; - QLowEnergyDescriptorInfo(const QBluetoothUuid &uuid, const QString &handle); + QLowEnergyDescriptorInfo(const QBluetoothUuid &uuid, + QBluetoothUuid::CharacteristicDescriptor desc, + const QString &handle); }; QT_END_NAMESPACE diff --git a/src/bluetooth/qlowenergydescriptorinfo_p.h b/src/bluetooth/qlowenergydescriptorinfo_p.h index 2cf8b36e..ff3b0f53 100644 --- a/src/bluetooth/qlowenergydescriptorinfo_p.h +++ b/src/bluetooth/qlowenergydescriptorinfo_p.h @@ -1,5 +1,6 @@ /*************************************************************************** ** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Copyright (C) 2013 BlackBerry Limited all rights reserved ** Contact: http://www.qt-project.org/legal ** @@ -42,6 +43,8 @@ #ifndef QLOWENERGYDESCRIPTORINFO_P_H #define QLOWENERGYDESCRIPTORINFO_P_H +#include <QtBluetooth/QBluetoothUuid> + QT_BEGIN_NAMESPACE class QLowEnergyDescriptorInfoPrivate @@ -54,6 +57,7 @@ public: QString m_handle; QVariantMap m_properties; QString m_name; + QBluetoothUuid::CharacteristicDescriptor m_type; #ifdef QT_QNX_BLUETOOTH int instance; #endif diff --git a/src/bluetooth/qlowenergyprocess_bluez.cpp b/src/bluetooth/qlowenergyprocess_bluez.cpp index 614679dd..72cb0c46 100644 --- a/src/bluetooth/qlowenergyprocess_bluez.cpp +++ b/src/bluetooth/qlowenergyprocess_bluez.cpp @@ -70,7 +70,7 @@ QLowEnergyProcess::~QLowEnergyProcess() } /*! - Returns the instance of this clas. This class is a singleton class. + Returns the instance of this class. This class is a singleton class. */ QLowEnergyProcess *QLowEnergyProcess::instance() |