diff options
-rw-r--r-- | src/bluetooth/bluetooth.pro | 5 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycharacteristicinfo.cpp | 5 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycharacteristicinfo.h | 7 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycharacteristicinfo_bluez.cpp | 21 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycharacteristicinfo_p.cpp | 5 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycharacteristicinfo_p.h | 6 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycharacteristicinfo_qnx.cpp | 12 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontroller.cpp | 11 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontroller.h | 2 | ||||
-rw-r--r-- | src/bluetooth/qlowenergydescriptorinfo.cpp | 21 | ||||
-rw-r--r-- | src/bluetooth/qlowenergydescriptorinfo.h | 5 | ||||
-rw-r--r-- | src/bluetooth/qlowenergyprocess_bluez.cpp | 3 | ||||
-rw-r--r-- | src/bluetooth/qlowenergyserviceinfo.cpp | 6 | ||||
-rw-r--r-- | src/bluetooth/qlowenergyserviceinfo.h | 7 | ||||
-rw-r--r-- | src/bluetooth/qlowenergyserviceinfo_p.cpp | 2 | ||||
-rw-r--r-- | src/bluetooth/qlowenergyserviceinfo_p.h | 12 |
16 files changed, 70 insertions, 60 deletions
diff --git a/src/bluetooth/bluetooth.pro b/src/bluetooth/bluetooth.pro index 4e509299..e7cb0356 100644 --- a/src/bluetooth/bluetooth.pro +++ b/src/bluetooth/bluetooth.pro @@ -133,8 +133,3 @@ config_bluez:qtHaveModule(dbus) { OTHER_FILES += HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS - - - - - diff --git a/src/bluetooth/qlowenergycharacteristicinfo.cpp b/src/bluetooth/qlowenergycharacteristicinfo.cpp index 765791ed..b89ca939 100644 --- a/src/bluetooth/qlowenergycharacteristicinfo.cpp +++ b/src/bluetooth/qlowenergycharacteristicinfo.cpp @@ -158,7 +158,7 @@ QString parseUuid(QBluetoothUuid uuid) { QLowEnergyCharacteristicInfo::QLowEnergyCharacteristicInfo(): d_ptr(new QLowEnergyCharacteristicInfoPrivate) { - d_ptr->q_ptr = this; + } /*! @@ -167,7 +167,6 @@ QLowEnergyCharacteristicInfo::QLowEnergyCharacteristicInfo(): QLowEnergyCharacteristicInfo::QLowEnergyCharacteristicInfo(const QBluetoothUuid &uuid): d_ptr(new QLowEnergyCharacteristicInfoPrivate) { - d_ptr->q_ptr = this; d_ptr->uuid = uuid; } @@ -180,7 +179,7 @@ QLowEnergyCharacteristicInfo::QLowEnergyCharacteristicInfo(const QBluetoothUuid QLowEnergyCharacteristicInfo::QLowEnergyCharacteristicInfo(const QLowEnergyCharacteristicInfo &other): d_ptr(other.d_ptr) { - d_ptr->q_ptr = this; + } /*! diff --git a/src/bluetooth/qlowenergycharacteristicinfo.h b/src/bluetooth/qlowenergycharacteristicinfo.h index b7a5b662..77866b71 100644 --- a/src/bluetooth/qlowenergycharacteristicinfo.h +++ b/src/bluetooth/qlowenergycharacteristicinfo.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef QGATTCHARACTERISTICINFO_H -#define QGATTCHARACTERISTICINFO_H +#ifndef QLOWENERGYCHARACTERISTICINFO_H +#define QLOWENERGYCHARACTERISTICINFO_H #include "qbluetoothuuid.h" #include "qlowenergydescriptorinfo.h" #include <QtCore/QSharedPointer> @@ -53,7 +53,6 @@ class QLowEnergyCharacteristicInfoPrivate; class Q_BLUETOOTH_EXPORT QLowEnergyCharacteristicInfo { - Q_DECLARE_PRIVATE(QLowEnergyCharacteristicInfo) friend class QLowEnergyServiceInfo; friend class QLowEnergyServiceInfoPrivate; friend class QLowEnergyController; @@ -108,4 +107,4 @@ protected: QT_END_NAMESPACE -#endif // QGATTCHARACTERISTICINFO_H +#endif // QLOWENERGYCHARACTERISTICINFO_H diff --git a/src/bluetooth/qlowenergycharacteristicinfo_bluez.cpp b/src/bluetooth/qlowenergycharacteristicinfo_bluez.cpp index 49f18610..fa57ffc4 100644 --- a/src/bluetooth/qlowenergycharacteristicinfo_bluez.cpp +++ b/src/bluetooth/qlowenergycharacteristicinfo_bluez.cpp @@ -89,12 +89,11 @@ void QLowEnergyCharacteristicInfoPrivate::replyReceived(const QString &reply) #endif for (int i = 0; i< update.size(); i ++) { if (update.at(i).contains(QStringLiteral("Notification handle"))) { - row = update.at(i).split(QRegularExpression("\\W+"), QString::SkipEmptyParts); + row = update.at(i).split(QRegularExpression(QStringLiteral("\\W+")), QString::SkipEmptyParts); #ifdef QT_LOWENERGYCHARACTERISTIC_DEBUG qDebug() << "Handle : "<< handle << row; #endif if (row.at(2) == handle) { - QString notificationValue = QStringLiteral(""); for (int j = 4 ; j< row.size(); j++) notificationValue += row.at(j); @@ -114,7 +113,7 @@ void QLowEnergyCharacteristicInfoPrivate::replyReceived(const QString &reply) update = reply.split(QStringLiteral("\n")); for (int i = 0; i< update.size(); i ++) { if (update.at(i).contains(QStringLiteral("Characteristic value/descriptor:"))) { - row = update.at(i).split(QRegularExpression("\\W+"), QString::SkipEmptyParts); + row = update.at(i).split(QRegularExpression(QStringLiteral("\\W+")), QString::SkipEmptyParts); QString val = QStringLiteral(""); for ( int j = 3; j<row.size(); j++) val += row.at(j); @@ -138,9 +137,9 @@ void QLowEnergyCharacteristicInfoPrivate::setValue(const QByteArray &wantedValue value = wantedValue; QString command; if (notification == true) - command = QStringLiteral("char-write-req ") + notificationHandle + QStringLiteral(" ") + QString(value.constData()); + command = QStringLiteral("char-write-req ") + notificationHandle + QStringLiteral(" ") + QString::fromLocal8Bit(value.constData()); else - command = QStringLiteral("char-write-req ") + handle + QStringLiteral(" ") + QString(value.constData()); + command = QStringLiteral("char-write-req ") + handle + QStringLiteral(" ") + QString::fromLocal8Bit(value.constData()); #ifdef QT_LOWENERGYCHARACTERISTIC_DEBUG @@ -148,22 +147,30 @@ void QLowEnergyCharacteristicInfoPrivate::setValue(const QByteArray &wantedValue #endif process->executeCommand(command); process->executeCommand(QStringLiteral("\n")); - t++; } -void QLowEnergyCharacteristicInfoPrivate::enableNotification() +bool QLowEnergyCharacteristicInfoPrivate::enableNotification() { + if (!notification) + return false; /* * Wanted value to enable notifications is 0100 */ + if ( (permission & QLowEnergyCharacteristicInfo::Notify) == 0) { +#ifdef QT_LOWENERGYCHARACTERISTIC_DEBUG + qDebug() << "Notification changes not allowed"; +#endif + return false; + } QByteArray val; val.append(48); val.append(49); val.append(48); val.append(48); setValue(val); + return true; } void QLowEnergyCharacteristicInfoPrivate::disableNotification() diff --git a/src/bluetooth/qlowenergycharacteristicinfo_p.cpp b/src/bluetooth/qlowenergycharacteristicinfo_p.cpp index 741aa8e6..e43a0c71 100644 --- a/src/bluetooth/qlowenergycharacteristicinfo_p.cpp +++ b/src/bluetooth/qlowenergycharacteristicinfo_p.cpp @@ -64,9 +64,9 @@ void QLowEnergyCharacteristicInfoPrivate::setValue(const QByteArray &wantedValue Q_UNUSED(wantedValue); } -void QLowEnergyCharacteristicInfoPrivate::enableNotification() +bool QLowEnergyCharacteristicInfoPrivate::enableNotification() { - + return false; } void QLowEnergyCharacteristicInfoPrivate::disableNotification() @@ -88,5 +88,4 @@ bool QLowEnergyCharacteristicInfoPrivate::valid() { return false; } - QT_END_NAMESPACE diff --git a/src/bluetooth/qlowenergycharacteristicinfo_p.h b/src/bluetooth/qlowenergycharacteristicinfo_p.h index 0a0891c1..379ca5d4 100644 --- a/src/bluetooth/qlowenergycharacteristicinfo_p.h +++ b/src/bluetooth/qlowenergycharacteristicinfo_p.h @@ -66,7 +66,6 @@ class QLowEnergyCharacteristicInfo; class QLowEnergyCharacteristicInfoPrivate: public QObject { Q_OBJECT - Q_DECLARE_PUBLIC(QLowEnergyCharacteristicInfo) public: QLowEnergyCharacteristicInfoPrivate(); ~QLowEnergyCharacteristicInfoPrivate(); @@ -74,7 +73,7 @@ public: void setValue(const QByteArray &wantedValue); void readValue(); bool valid(); - void enableNotification(); + bool enableNotification(); void disableNotification(); void readDescriptors(); @@ -113,9 +112,6 @@ private: bool m_signalConnected; #endif - -protected: - QLowEnergyCharacteristicInfo *q_ptr; }; QT_END_NAMESPACE diff --git a/src/bluetooth/qlowenergycharacteristicinfo_qnx.cpp b/src/bluetooth/qlowenergycharacteristicinfo_qnx.cpp index add2f13d..b5d4bf8c 100644 --- a/src/bluetooth/qlowenergycharacteristicinfo_qnx.cpp +++ b/src/bluetooth/qlowenergycharacteristicinfo_qnx.cpp @@ -134,25 +134,27 @@ void QLowEnergyCharacteristicInfoPrivate::serviceNotification(int instance, shor qBBBluetoothDebug() << "Notificiation received and does not belong to this characteristic."; } -void QLowEnergyCharacteristicInfoPrivate::enableNotification() +bool QLowEnergyCharacteristicInfoPrivate::enableNotification() { if (instance == -1) { qBBBluetoothDebug() << " GATT service not connected "; //q_ptr->error(QLowEnergyCharacteristicInfo::NotConnected); - return; + return false; } if ( (permission & QLowEnergyCharacteristicInfo::Notify) == 0) { qBBBluetoothDebug() << "Notification changes not allowed"; - return; + return false; } int rc = bt_gatt_enable_notify(instance, &characteristic, 1); if (rc != 0) { qBBBluetoothDebug() << "bt_gatt_enable_notify errno=" << errno << strerror(errno); //emit q_ptr->error(QLowEnergyCharacteristicInfo::NotificationFail); - return; - } else + return false; + } else { qBBBluetoothDebug() << "bt_gatt_enable_notify was presumably OK"; + return true; + } } void QLowEnergyCharacteristicInfoPrivate::setValue(const QByteArray &wantedValue) diff --git a/src/bluetooth/qlowenergycontroller.cpp b/src/bluetooth/qlowenergycontroller.cpp index abba8edc..00a33325 100644 --- a/src/bluetooth/qlowenergycontroller.cpp +++ b/src/bluetooth/qlowenergycontroller.cpp @@ -246,20 +246,21 @@ void QLowEnergyController::disconnectFromService(const QLowEnergyServiceInfo &le /*! Enables receiving notifications from the given \a characteristic. If the service characteristic - does not belong to one of the services, nothing wil lbe done. - - \sa addLeService + does not belong to one of the services or characteristic permissions do not allow notifications, + the function will return false. */ -void QLowEnergyController::enableNotifications(const QLowEnergyCharacteristicInfo &characteristic) +bool QLowEnergyController::enableNotifications(const QLowEnergyCharacteristicInfo &characteristic) { + bool enable = false; for (int i = 0; i < d_ptr->m_leServices.size(); i++) { for (int j = 0; j < d_ptr->m_leServices.at(i).getCharacteristics().size(); j++) { if (d_ptr->m_leServices.at(i).getCharacteristics().at(j).uuid() == characteristic.uuid()) { connect(d_ptr->m_leServices.at(i).getCharacteristics().at(j).d_ptr.data(), SIGNAL(notifyValue(QBluetoothUuid)), this, SLOT(_q_valueReceived(QBluetoothUuid))); - d_ptr->m_leServices.at(i).getCharacteristics().at(j).d_ptr->enableNotification(); + enable = d_ptr->m_leServices.at(i).getCharacteristics().at(j).d_ptr->enableNotification(); } } } + return enable; } /*! diff --git a/src/bluetooth/qlowenergycontroller.h b/src/bluetooth/qlowenergycontroller.h index bfdfe25c..4f49acb5 100644 --- a/src/bluetooth/qlowenergycontroller.h +++ b/src/bluetooth/qlowenergycontroller.h @@ -63,7 +63,7 @@ public: QList<QLowEnergyServiceInfo> services() const; void connectToService(const QLowEnergyServiceInfo &leService); void disconnectFromService(const QLowEnergyServiceInfo &leService = QLowEnergyServiceInfo()); - void enableNotifications(const QLowEnergyCharacteristicInfo &characteristic); + bool enableNotifications(const QLowEnergyCharacteristicInfo &characteristic); void disableNotifications(const QLowEnergyCharacteristicInfo &characteristic); Q_SIGNALS: diff --git a/src/bluetooth/qlowenergydescriptorinfo.cpp b/src/bluetooth/qlowenergydescriptorinfo.cpp index 763c3aaf..92d376a2 100644 --- a/src/bluetooth/qlowenergydescriptorinfo.cpp +++ b/src/bluetooth/qlowenergydescriptorinfo.cpp @@ -63,7 +63,7 @@ QString parseDescriptorUuid(const QBluetoothUuid &uuid) } QLowEnergyDescriptorInfoPrivate::QLowEnergyDescriptorInfoPrivate(const QBluetoothUuid &uuid, const QString &handle): - m_uuid(uuid), m_handle(handle), m_value(QByteArray()) + m_value(QByteArray()), m_uuid(uuid), m_handle(handle), m_properties(QVariantMap()), m_name(QStringLiteral("")) { } @@ -74,6 +74,15 @@ QLowEnergyDescriptorInfoPrivate::~QLowEnergyDescriptorInfoPrivate() } /*! + Construct a new QLowEnergyCharacteristicInfo with given \a uuid. +*/ +QLowEnergyDescriptorInfo::QLowEnergyDescriptorInfo(const QBluetoothUuid &uuid): + d_ptr(new QLowEnergyDescriptorInfoPrivate(uuid, QStringLiteral("0x0000"))) +{ + +} + +/*! Construct a new QLowEnergyDescriptorInfo with given \a uuid and the \a handle. */ QLowEnergyDescriptorInfo::QLowEnergyDescriptorInfo(const QBluetoothUuid &uuid, const QString &handle): @@ -91,6 +100,16 @@ QLowEnergyDescriptorInfo::~QLowEnergyDescriptorInfo() } /*! + Makes a copy of the \a other and assigns it to this QLowEnergyDescriptorInfo object. + The two copies continue to share the same service and registration details. +*/ +QLowEnergyDescriptorInfo &QLowEnergyDescriptorInfo::operator=(const QLowEnergyDescriptorInfo &other) +{ + d_ptr = other.d_ptr; + return *this; +} + +/*! Returns the UUID of the descriptor. */ QBluetoothUuid QLowEnergyDescriptorInfo::uuid() const diff --git a/src/bluetooth/qlowenergydescriptorinfo.h b/src/bluetooth/qlowenergydescriptorinfo.h index e3ebc294..14f2077c 100644 --- a/src/bluetooth/qlowenergydescriptorinfo.h +++ b/src/bluetooth/qlowenergydescriptorinfo.h @@ -59,8 +59,10 @@ class Q_BLUETOOTH_EXPORT QLowEnergyDescriptorInfo friend class QLowEnergyCharacteristicInfoPrivate; friend class QLowEnergyServiceInfoPrivate; public: - QLowEnergyDescriptorInfo(const QBluetoothUuid &uuid, const QString &handle); + explicit QLowEnergyDescriptorInfo(const QBluetoothUuid &uuid); ~QLowEnergyDescriptorInfo(); + + QLowEnergyDescriptorInfo &operator=(const QLowEnergyDescriptorInfo &other); QByteArray value(); QBluetoothUuid uuid() const; QString handle() const; @@ -69,6 +71,7 @@ public: private: QSharedPointer<QLowEnergyDescriptorInfoPrivate> d_ptr; + QLowEnergyDescriptorInfo(const QBluetoothUuid &uuid, const QString &handle); }; QT_END_NAMESPACE diff --git a/src/bluetooth/qlowenergyprocess_bluez.cpp b/src/bluetooth/qlowenergyprocess_bluez.cpp index 81a34266..736e45ff 100644 --- a/src/bluetooth/qlowenergyprocess_bluez.cpp +++ b/src/bluetooth/qlowenergyprocess_bluez.cpp @@ -1,4 +1,3 @@ - /*************************************************************************** ** ** Copyright (C) 2013 BlackBerry Limited. All rights reserved. @@ -89,7 +88,7 @@ QProcess *QLowEnergyProcess::getProcess() void QLowEnergyProcess::replyRead() { QByteArray result = m_process->readAll(); - QString back = QString(result.data()); + QString back = QString::fromLocal8Bit(result.data()); if (back.size() > 10) emit replySend(back); } diff --git a/src/bluetooth/qlowenergyserviceinfo.cpp b/src/bluetooth/qlowenergyserviceinfo.cpp index 92758da1..137b93f4 100644 --- a/src/bluetooth/qlowenergyserviceinfo.cpp +++ b/src/bluetooth/qlowenergyserviceinfo.cpp @@ -113,7 +113,7 @@ QString parseUuid(const QBluetoothUuid &uuid) QLowEnergyServiceInfo::QLowEnergyServiceInfo(): d_ptr(QSharedPointer<QLowEnergyServiceInfoPrivate>(new QLowEnergyServiceInfoPrivate)) { - d_ptr->q_ptr = this; + } /*! @@ -125,7 +125,6 @@ QLowEnergyServiceInfo::QLowEnergyServiceInfo(const QBluetoothUuid &uuid): d_ptr(QSharedPointer<QLowEnergyServiceInfoPrivate>(new QLowEnergyServiceInfoPrivate)) { d_ptr->uuid = QBluetoothUuid(uuid); - d_ptr->q_ptr = this; d_ptr->serviceName = parseUuid(d_ptr->uuid); } @@ -138,7 +137,7 @@ QLowEnergyServiceInfo::QLowEnergyServiceInfo(const QBluetoothUuid &uuid): QLowEnergyServiceInfo::QLowEnergyServiceInfo(const QLowEnergyServiceInfo &other): d_ptr(other.d_ptr) { - d_ptr->q_ptr = this; + } /*! @@ -198,7 +197,6 @@ QLowEnergyServiceInfo::ServiceType QLowEnergyServiceInfo::getServiceType() const QLowEnergyServiceInfo &QLowEnergyServiceInfo::operator=(const QLowEnergyServiceInfo &other) { d_ptr = other.d_ptr; - d_ptr->q_ptr = this; return *this; } diff --git a/src/bluetooth/qlowenergyserviceinfo.h b/src/bluetooth/qlowenergyserviceinfo.h index deacf050..2412a742 100644 --- a/src/bluetooth/qlowenergyserviceinfo.h +++ b/src/bluetooth/qlowenergyserviceinfo.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef QGATTSERVICEINFO_H -#define QGATTSERVICEINFO_H +#ifndef QLOWENERGYSERVICEINFO_H +#define QLOWENERGYSERVICEINFO_H #include "qbluetoothuuid.h" #include "qlowenergycharacteristicinfo.h" #include "qbluetoothdevicediscoveryagent.h" @@ -56,7 +56,6 @@ class QBluetoothDeviceInfo; class Q_BLUETOOTH_EXPORT QLowEnergyServiceInfo { - Q_DECLARE_PRIVATE(QLowEnergyServiceInfo) friend class QBluetoothServiceDiscoveryAgent; friend class QBluetoothServiceDiscoveryAgentPrivate; friend class QLowEnergyController; @@ -111,4 +110,4 @@ protected: QT_END_NAMESPACE -#endif // QGATTSERVICEINFO_H +#endif // QLOWENERGYSERVICEINFO_H diff --git a/src/bluetooth/qlowenergyserviceinfo_p.cpp b/src/bluetooth/qlowenergyserviceinfo_p.cpp index 4b11c559..0679278b 100644 --- a/src/bluetooth/qlowenergyserviceinfo_p.cpp +++ b/src/bluetooth/qlowenergyserviceinfo_p.cpp @@ -67,6 +67,4 @@ bool QLowEnergyServiceInfoPrivate::valid() { return false; } - - QT_END_NAMESPACE diff --git a/src/bluetooth/qlowenergyserviceinfo_p.h b/src/bluetooth/qlowenergyserviceinfo_p.h index a71e09f2..e91a78bb 100644 --- a/src/bluetooth/qlowenergyserviceinfo_p.h +++ b/src/bluetooth/qlowenergyserviceinfo_p.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef QGATTSERVICEINFO_P_H -#define QGATTSERVICEINFO_P_H +#ifndef QLOWENERGYSERVICEINFO_P_H +#define QLOWENERGYSERVICEINFO_P_H #include "qbluetoothuuid.h" #include "qlowenergyserviceinfo.h" #include "qlowenergycharacteristicinfo.h" @@ -61,7 +61,6 @@ class QLowEnergyProcess; class QLowEnergyServiceInfoPrivate: public QObject { Q_OBJECT - Q_DECLARE_PUBLIC(QLowEnergyServiceInfo) public: QLowEnergyServiceInfoPrivate(); @@ -88,6 +87,7 @@ public: QString endingHandle; QString path; QBluetoothAddress adapterAddress; + bool randomAddress; void connectToTerminal(); void setHandles(); void setCharacteristics(); @@ -120,13 +120,9 @@ private: int m_valueCounter; int m_readCounter; #endif - bool randomAddress; int m_instance; - -protected: - QLowEnergyServiceInfo *q_ptr; }; QT_END_NAMESPACE -#endif // QGATTSERVICEINFO_P_H +#endif // QLOWENERGYSERVICEINFO_P_H |