summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNedim Hadzic <nhadzic@blackberry.com>2014-03-07 18:19:02 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-11 11:02:05 +0100
commit2f133076fb91ecadadef4a8e28cd6c5d9b431f71 (patch)
treed809f5ca15a4c5bc06964c008d58ab4ab2bdd1b6
parent10126f30e5f5dec0c13ed11ae302a76bc5fa6da0 (diff)
BLE communication moved to controller class
BLE communication code was implemented in QLowEnergyServiceInfo class. It is moved now to the QLowEnergyController class. Needed adjustments are done in order to make this work. Change-Id: I9206d2324ad59f79f4e035509e23f5c7f7cfb328 Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
-rw-r--r--src/bluetooth/bluetooth.pro9
-rw-r--r--src/bluetooth/qlowenergycontroller.cpp123
-rw-r--r--src/bluetooth/qlowenergycontroller.h4
-rw-r--r--src/bluetooth/qlowenergycontroller_bluez.cpp405
-rw-r--r--src/bluetooth/qlowenergycontroller_p.cpp97
-rw-r--r--src/bluetooth/qlowenergycontroller_p.h19
-rw-r--r--src/bluetooth/qlowenergydescriptorinfo.h1
-rw-r--r--src/bluetooth/qlowenergyprocess_bluez.cpp3
-rw-r--r--src/bluetooth/qlowenergyserviceinfo.cpp10
-rw-r--r--src/bluetooth/qlowenergyserviceinfo.h2
-rw-r--r--src/bluetooth/qlowenergyserviceinfo_bluez.cpp302
-rw-r--r--src/bluetooth/qlowenergyserviceinfo_p.h11
12 files changed, 544 insertions, 442 deletions
diff --git a/src/bluetooth/bluetooth.pro b/src/bluetooth/bluetooth.pro
index 1d376b7a..bb4e6266 100644
--- a/src/bluetooth/bluetooth.pro
+++ b/src/bluetooth/bluetooth.pro
@@ -87,7 +87,8 @@ config_bluez:qtHaveModule(dbus) {
qbluetoothtransferreply_bluez.cpp \
qlowenergyprocess_bluez.cpp \
qlowenergyserviceinfo_bluez.cpp \
- qlowenergycharacteristicinfo_bluez.cpp
+ qlowenergycharacteristicinfo_bluez.cpp \
+ qlowenergycontroller_bluez.cpp
} else:CONFIG(blackberry) {
DEFINES += QT_QNX_BLUETOOTH
@@ -136,7 +137,8 @@ config_bluez:qtHaveModule(dbus) {
qbluetoothserver_android.cpp \
qlowenergyserviceinfo_p.cpp \
qlowenergycharacteristicinfo_p.cpp \
- qlowenergyprocess_p.cpp
+ qlowenergyprocess_p.cpp \
+ qlowenergycontroller_p.cpp
} else {
message("Unsupported bluetooth platform, will not build a working QBluetooth library")
@@ -150,7 +152,8 @@ config_bluez:qtHaveModule(dbus) {
qbluetoothserver_p.cpp \
qlowenergyserviceinfo_p.cpp \
qlowenergycharacteristicinfo_p.cpp \
- qlowenergyprocess_p.cpp
+ qlowenergyprocess_p.cpp \
+ qlowenergycontroller_p.cpp
}
OTHER_FILES +=
diff --git a/src/bluetooth/qlowenergycontroller.cpp b/src/bluetooth/qlowenergycontroller.cpp
index e2ca99cc..21daa650 100644
--- a/src/bluetooth/qlowenergycontroller.cpp
+++ b/src/bluetooth/qlowenergycontroller.cpp
@@ -43,7 +43,6 @@
#include "qlowenergycontroller_p.h"
#include "qlowenergyserviceinfo_p.h"
#include "qlowenergycharacteristicinfo_p.h"
-#include "moc_qlowenergycontroller.cpp"
QT_BEGIN_NAMESPACE
/*!
@@ -110,118 +109,6 @@ QT_BEGIN_NAMESPACE
\sa enableNotifications(const QLowEnergyCharacteristicInfo &characteristic)
*/
-QLowEnergyControllerPrivate::QLowEnergyControllerPrivate()
-{
-
-}
-
-QLowEnergyControllerPrivate::~QLowEnergyControllerPrivate()
-{
-
-}
-
-void QLowEnergyControllerPrivate::_q_serviceConnected(const QBluetoothUuid &uuid)
-{
- for (int i = 0; i < m_leServices.size(); i++) {
- if (((QLowEnergyServiceInfo)m_leServices.at(i)).serviceUuid() == uuid)
- emit q_ptr->connected((QLowEnergyServiceInfo)m_leServices.at(i));
-
- }
-}
-
-void QLowEnergyControllerPrivate::_q_serviceError(const QBluetoothUuid &uuid)
-{
- for (int i = 0; i < m_leServices.size(); i++) {
- if (((QLowEnergyServiceInfo)m_leServices.at(i)).serviceUuid() == uuid) {
- QLowEnergyServiceInfo service((QLowEnergyServiceInfo)m_leServices.at(i));
- errorString = service.d_ptr->errorString;
- emit q_ptr->error(service);
- }
- }
-}
-
-void QLowEnergyControllerPrivate::_q_characteristicError(const QBluetoothUuid &uuid)
-{
- for (int i = 0; i < m_leServices.size(); i++) {
- QList<QLowEnergyCharacteristicInfo> characteristics = m_leServices.at(i).characteristics();
- for (int j = 0; j < characteristics.size(); j++) {
- if (characteristics.at(j).uuid() == uuid) {
- errorString = characteristics.at(j).d_ptr->errorString;
- emit q_ptr->error(characteristics.at(j));
- }
- }
- }
-}
-
-
-void QLowEnergyControllerPrivate::_q_valueReceived(const QBluetoothUuid &uuid)
-{
- for (int i = 0; i < m_leServices.size(); i++) {
- QList<QLowEnergyCharacteristicInfo> characteristics = m_leServices.at(i).characteristics();
- for (int j = 0; j < characteristics.size(); j++) {
- if (characteristics.at(j).uuid() == uuid)
- emit q_ptr->valueChanged(characteristics.at(j));
- }
- }
-}
-
-
-
-void QLowEnergyControllerPrivate::_q_serviceDisconnected(const QBluetoothUuid &uuid)
-{
- for (int i = 0; i < m_leServices.size(); i++) {
- if (((QLowEnergyServiceInfo)m_leServices.at(i)).serviceUuid() == uuid) {
- QObject::disconnect(((QLowEnergyServiceInfo)m_leServices.at(i)).d_ptr.data(), SIGNAL(connectedToService(QBluetoothUuid)), q_ptr, SLOT(_q_serviceConnected(QBluetoothUuid)));
- QObject::disconnect(((QLowEnergyServiceInfo)m_leServices.at(i)).d_ptr.data(), SIGNAL(error(QBluetoothUuid)), q_ptr, SLOT(_q_serviceError(QBluetoothUuid)));
- QObject::disconnect(((QLowEnergyServiceInfo)m_leServices.at(i)).d_ptr.data(), SIGNAL(disconnectedFromService(QBluetoothUuid)), q_ptr, SLOT(_q_serviceDisconnected(QBluetoothUuid)));
- emit q_ptr->disconnected((QLowEnergyServiceInfo)m_leServices.at(i));
- }
- }
-}
-
-void QLowEnergyControllerPrivate::connectService(const QLowEnergyServiceInfo &service)
-{
- bool in = false;
- if (service.isValid()) {
- for (int i = 0; i < m_leServices.size(); i++) {
- if (((QLowEnergyServiceInfo)m_leServices.at(i)).serviceUuid() == service.serviceUuid() && !((QLowEnergyServiceInfo)m_leServices.at(i)).isConnected()) {
- in = true;
- QObject::connect(m_leServices.at(i).d_ptr.data(), SIGNAL(connectedToService(QBluetoothUuid)), q_ptr, SLOT(_q_serviceConnected(QBluetoothUuid)));
- QObject::connect(((QLowEnergyServiceInfo)m_leServices.at(i)).d_ptr.data(), SIGNAL(error(QBluetoothUuid)), q_ptr, SLOT(_q_serviceError(QBluetoothUuid)));
- QObject::connect(((QLowEnergyServiceInfo)m_leServices.at(i)).d_ptr.data(), SIGNAL(disconnectedFromService(QBluetoothUuid)), q_ptr, SLOT(_q_serviceDisconnected(QBluetoothUuid)));
- ((QLowEnergyServiceInfo)m_leServices.at(i)).d_ptr->registerServiceWatcher();
- break;
- }
- }
- if (!in) {
- m_leServices.append(service);
- QObject::connect(((QLowEnergyServiceInfo)m_leServices.last()).d_ptr.data(), SIGNAL(connectedToService(QBluetoothUuid)), q_ptr, SLOT(_q_serviceConnected(QBluetoothUuid)));
- QObject::connect(((QLowEnergyServiceInfo)m_leServices.last()).d_ptr.data(), SIGNAL(error(QBluetoothUuid)), q_ptr, SLOT(_q_serviceError(QBluetoothUuid)));
- QObject::connect(((QLowEnergyServiceInfo)m_leServices.last()).d_ptr.data(), SIGNAL(disconnectedFromService(QBluetoothUuid)), q_ptr, SLOT(_q_serviceDisconnected(QBluetoothUuid)));
- ((QLowEnergyServiceInfo)m_leServices.last()).d_ptr->registerServiceWatcher();
- }
- }
-}
-
-void QLowEnergyControllerPrivate::disconnectService(const QLowEnergyServiceInfo &service)
-{
- if (service.isValid()) {
- for (int i = 0; i < m_leServices.size(); i++) {
- if (((QLowEnergyServiceInfo)m_leServices.at(i)).serviceUuid() == service.serviceUuid() && service.isConnected()) {
- ((QLowEnergyServiceInfo)m_leServices.at(i)).d_ptr->unregisterServiceWatcher();
- break;
- }
- }
- }
- else {
- for (int i = 0; i < m_leServices.size(); i++) {
- if (((QLowEnergyServiceInfo)m_leServices.at(i)).isConnected()) {
- ((QLowEnergyServiceInfo)m_leServices.at(i)).d_ptr->unregisterServiceWatcher();
- break;
- }
- }
- }
-}
/*!
Construct a new QLowEnergyInfo object with the \a parent.
@@ -316,4 +203,14 @@ QString QLowEnergyController::errorString() const
{
return d_ptr->errorString;
}
+
+/*!
+ This method is called for the Linux platform if a device has a random device address that
+ is used for connecting.
+ */
+void QLowEnergyController::setRandomAddress()
+{
+ d_ptr->m_randomAddress = true;
+}
+
QT_END_NAMESPACE
diff --git a/src/bluetooth/qlowenergycontroller.h b/src/bluetooth/qlowenergycontroller.h
index 842a2e7e..5b2ae1a6 100644
--- a/src/bluetooth/qlowenergycontroller.h
+++ b/src/bluetooth/qlowenergycontroller.h
@@ -65,6 +65,7 @@ public:
bool enableNotifications(const QLowEnergyCharacteristicInfo &characteristic);
void disableNotifications(const QLowEnergyCharacteristicInfo &characteristic);
QString errorString() const;
+ void setRandomAddress();
Q_SIGNALS:
void connected(const QLowEnergyServiceInfo &);
@@ -83,6 +84,9 @@ private:
Q_PRIVATE_SLOT(d_func(), void _q_characteristicError(const QBluetoothUuid &uuid))
Q_PRIVATE_SLOT(d_func(), void _q_valueReceived(const QBluetoothUuid &uuid))
Q_PRIVATE_SLOT(d_func(), void _q_serviceDisconnected(const QBluetoothUuid &uuid))
+#ifdef QT_BLUEZ_BLUETOOTH
+ Q_PRIVATE_SLOT(d_func(), void _q_replyReceived(const QString &reply))
+#endif
};
QT_END_NAMESPACE
diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp
new file mode 100644
index 00000000..7a6aeece
--- /dev/null
+++ b/src/bluetooth/qlowenergycontroller_bluez.cpp
@@ -0,0 +1,405 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited all rights reserved
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlowenergycontroller.h"
+#include "qlowenergycontroller_p.h"
+#include "qlowenergyserviceinfo_p.h"
+#include "qlowenergycharacteristicinfo_p.h"
+#include "qlowenergyprocess_p.h"
+#include "qlowenergydescriptorinfo.h"
+#include "qlowenergydescriptorinfo_p.h"
+#include "moc_qlowenergycontroller.cpp"
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(QT_BT_BLUEZ)
+
+QLowEnergyControllerPrivate::QLowEnergyControllerPrivate():
+ m_randomAddress(false), m_step(0), m_commandStarted(false)
+{
+
+}
+
+QLowEnergyControllerPrivate::~QLowEnergyControllerPrivate()
+{
+
+}
+
+void QLowEnergyControllerPrivate::_q_serviceConnected(const QBluetoothUuid &uuid)
+{
+ for (int i = 0; i < m_leServices.size(); i++) {
+ if (((QLowEnergyServiceInfo)m_leServices.at(i)).serviceUuid() == uuid)
+ emit q_ptr->connected((QLowEnergyServiceInfo)m_leServices.at(i));
+
+ }
+}
+
+void QLowEnergyControllerPrivate::_q_serviceError(const QBluetoothUuid &uuid)
+{
+ for (int i = 0; i < m_leServices.size(); i++) {
+ if (((QLowEnergyServiceInfo)m_leServices.at(i)).serviceUuid() == uuid) {
+ QLowEnergyServiceInfo service((QLowEnergyServiceInfo)m_leServices.at(i));
+ //errorString = service.d_ptr->errorString;
+ emit q_ptr->error(service);
+ }
+ }
+}
+
+void QLowEnergyControllerPrivate::_q_characteristicError(const QBluetoothUuid &uuid)
+{
+ for (int i = 0; i < m_leServices.size(); i++) {
+ QList<QLowEnergyCharacteristicInfo> characteristics = m_leServices.at(i).characteristics();
+ for (int j = 0; j < characteristics.size(); j++) {
+ if (characteristics.at(j).uuid() == uuid) {
+ errorString = characteristics.at(j).d_ptr->errorString;
+ emit q_ptr->error(characteristics.at(j));
+ }
+ }
+ }
+}
+
+
+void QLowEnergyControllerPrivate::_q_valueReceived(const QBluetoothUuid &uuid)
+{
+ for (int i = 0; i < m_leServices.size(); i++) {
+ QList<QLowEnergyCharacteristicInfo> characteristics = m_leServices.at(i).characteristics();
+ for (int j = 0; j < characteristics.size(); j++) {
+ if (characteristics.at(j).uuid() == uuid)
+ emit q_ptr->valueChanged(characteristics.at(j));
+ }
+ }
+}
+
+void QLowEnergyControllerPrivate::_q_serviceDisconnected(const QBluetoothUuid &uuid)
+{
+ for (int i = 0; i < m_leServices.size(); i++) {
+ if (((QLowEnergyServiceInfo)m_leServices.at(i)).serviceUuid() == uuid) {
+ QObject::disconnect(((QLowEnergyServiceInfo)m_leServices.at(i)).d_ptr.data(), SIGNAL(connectedToService(QBluetoothUuid)), q_ptr, SLOT(_q_serviceConnected(QBluetoothUuid)));
+ QObject::disconnect(((QLowEnergyServiceInfo)m_leServices.at(i)).d_ptr.data(), SIGNAL(error(QBluetoothUuid)), q_ptr, SLOT(_q_serviceError(QBluetoothUuid)));
+ QObject::disconnect(((QLowEnergyServiceInfo)m_leServices.at(i)).d_ptr.data(), SIGNAL(disconnectedFromService(QBluetoothUuid)), q_ptr, SLOT(_q_serviceDisconnected(QBluetoothUuid)));
+ emit q_ptr->disconnected((QLowEnergyServiceInfo)m_leServices.at(i));
+ }
+ }
+}
+
+void QLowEnergyControllerPrivate::connectService(const QLowEnergyServiceInfo &service)
+{
+ errorString = QString();
+ service.d_ptr->characteristicList.clear();
+ bool add = true;
+ for (int i = 0; i < m_leServices.size(); i++) {
+ if (m_leServices.at(i).serviceUuid() == service.serviceUuid()) {
+ m_leServices.replace(i, service);
+ add = false;
+ break;
+ }
+ }
+ if (add)
+ m_leServices.append(service);
+ process = process->instance();
+ if (!process->isConnected()) {
+ if (m_commandStarted)
+ connectToTerminal();
+ else {
+ QObject::connect(process, SIGNAL(replySend(const QString &)), q_ptr, SLOT(_q_replyReceived(const QString &)));
+ QString command = QStringLiteral("gatttool -i ") + service.d_ptr->adapterAddress.toString() + QStringLiteral(" -b ") + service.d_ptr->deviceInfo.address().toString() + QStringLiteral(" -I");
+ if (m_randomAddress)
+ command += QStringLiteral(" -t random");
+ qCDebug(QT_BT_BLUEZ) << "[REGISTER] uuid inside: " << service.d_ptr->uuid << command;
+ process->startCommand(command);
+ m_commandStarted = true;
+ }
+ process->addConnection();
+ }
+ else
+ service.d_ptr->m_step = 1;
+}
+
+void QLowEnergyControllerPrivate::disconnectService(const QLowEnergyServiceInfo &service)
+{
+ if (service.isValid()) {
+ for (int i = 0; i < m_leServices.size(); i++) {
+ if (m_leServices.at(i).serviceUuid() == service.serviceUuid() && service.isConnected()) {
+ process = process->instance();
+ process->endProcess();
+ m_leServices.at(i).d_ptr->connected = false;
+ m_leServices.at(i).d_ptr->m_step = 0;
+ m_leServices.at(i).d_ptr->m_valueCounter = 0;
+ m_leServices.removeAt(i);
+ emit q_ptr->disconnected(service);
+ break;
+ }
+ }
+ }
+ else
+ disconnectAllServices();
+}
+
+void QLowEnergyControllerPrivate::_q_replyReceived(const QString &reply)
+{
+ qCDebug(QT_BT_BLUEZ) << "reply: " << reply;
+ // STEP 0
+ if (m_step == 0)
+ connectToTerminal();
+ if (reply.contains(QStringLiteral("Connection refused (111)"))) {
+ errorString = QStringLiteral("Connection refused (111)");
+ disconnectAllServices();
+ }
+ else if (reply.contains(QStringLiteral("Device busy"))) {
+ errorString = QStringLiteral("Connection refused (111)");
+ disconnectAllServices();
+ }
+ else if (reply.contains(QStringLiteral("disconnected"))) {
+ errorString = QStringLiteral("Trying to execute command on disconnected service");
+ disconnectAllServices();
+ }
+ else {
+ // STEP 1
+ if (reply.contains(QStringLiteral("[CON]"))) {
+ for (int i = 0; i < m_leServices.size(); i++) {
+ if (m_leServices.at(i).d_ptr->m_step == 1) {
+ setHandles();
+ m_leServices.at(i).d_ptr->m_step++;
+ }
+ }
+ }
+
+ // STEP 2
+ if (reply.contains(QStringLiteral("attr")) && reply.contains(QStringLiteral("uuid"))){
+ const QStringList handles = reply.split(QStringLiteral("\n"));
+ foreach (const QString &handle, handles) {
+ if (handle.contains(QStringLiteral("attr")) && handle.contains(QStringLiteral("uuid"))) {
+ const QStringList handleDetails = handle.split(QRegularExpression(QStringLiteral("[\\s+|,]")),
+ QString::SkipEmptyParts);
+ Q_ASSERT(handleDetails.count() == 9);
+ const QBluetoothUuid foundUuid(handleDetails.at(8));
+ for (int i = 0; i < m_leServices.size(); i++) {
+ if (foundUuid == m_leServices.at(i).serviceUuid() && m_leServices.at(i).d_ptr->m_step == 2) {
+ m_leServices.at(i).d_ptr->startingHandle = handleDetails.at(2);
+ m_leServices.at(i).d_ptr->endingHandle = handleDetails.at(6);
+ setCharacteristics(i);
+ }
+ }
+ }
+ }
+ }
+
+ // STEP 3
+ if (reply.contains(QStringLiteral("char")) && reply.contains(QStringLiteral("uuid")) && reply.contains(QStringLiteral("properties"))) {
+ const QStringList handles = reply.split(QStringLiteral("\n"));
+ int stepSet = -1;
+ foreach (const QString& handle, handles) {
+ if (handle.contains(QStringLiteral("char")) && handle.contains(QStringLiteral("uuid"))) {
+ const QStringList handleDetails = handle.split(QRegularExpression(QStringLiteral("[\\s+|,]")),
+ QString::SkipEmptyParts);
+ Q_ASSERT(handleDetails.count() == 11);
+ const QString charHandle = handleDetails.at(8);
+ ushort charHandleId = charHandle.toUShort(0, 0);
+ for (int i = 0; i < m_leServices.size(); i++) {
+ if ( charHandleId >= m_leServices.at(i).d_ptr->startingHandle.toUShort(0,0) &&
+ charHandleId <= m_leServices.at(i).d_ptr->endingHandle.toUShort(0,0))
+ {
+ const QBluetoothUuid charUuid(handleDetails.at(10));
+ QVariantMap map;
+
+ QLowEnergyCharacteristicInfo charInfo(charUuid);
+ charInfo.d_ptr->handle = charHandle;
+ charInfo.d_ptr->startingHandle = handleDetails.at(1);
+ charInfo.d_ptr->permission = handleDetails.at(4).toUShort(0,0);
+ map[QStringLiteral("uuid")] = charUuid.toString();
+ map[QStringLiteral("handle")] = charHandle;
+ map[QStringLiteral("permission")] = charInfo.d_ptr->permission;
+ charInfo.d_ptr->properties = map;
+ if (!(charInfo.d_ptr->permission & QLowEnergyCharacteristicInfo::Read))
+ qCDebug(QT_BT_BLUEZ) << "GATT characteristic: Read not permitted: " << charInfo.d_ptr->uuid;
+ else
+ m_leServices.at(i).d_ptr->m_readCounter++;
+ m_leServices.at(i).d_ptr->characteristicList.append(charInfo);
+ stepSet = i;
+ break;
+ }
+ }
+ }
+ }
+ if ( stepSet != -1)
+ readCharacteristicValue(stepSet);
+ }
+
+ // STEP 4 and STEP 5
+ // This part is for reading characteristic values and setting the notifications
+ if (reply.contains(QStringLiteral("handle")) && reply.contains(QStringLiteral("value")) && !reply.contains(QStringLiteral("char"))) {
+ int index = -1; // setting characteristics values
+ int index1 = -1; // setting notifications and descriptors
+ for (int i = 0; i < m_leServices.size(); i++) {
+ if (m_leServices.at(i).d_ptr->m_step == 4)
+ index = i;
+ if (m_leServices.at(i).d_ptr->m_step == 5)
+ index1 = i;
+ }
+ const QStringList handles = reply.split(QStringLiteral("\n"));
+ bool lastStep = false;
+ foreach (const QString &handle, handles) {
+ if (handle.contains(QStringLiteral("handle")) &&
+ handle.contains(QStringLiteral("value")))
+ {
+ const QStringList handleDetails = handle.split(QRegularExpression(QStringLiteral("\\W+")), QString::SkipEmptyParts);
+ if (index != -1) {
+ if (!m_leServices.at(index).d_ptr->characteristicList.isEmpty()) {
+ for (int j = 0; j < m_leServices.at(index).d_ptr->characteristicList.size(); j++) {
+ const QLowEnergyCharacteristicInfo chars = m_leServices.at(index).d_ptr->characteristicList.at(j);
+ const QString handleId = handleDetails.at(1);
+ qCDebug(QT_BT_BLUEZ) << handleId << handleId.toUShort(0,0) << chars.handle() << chars.handle().toUShort(0,0);
+ if (handleId.toUShort(0,0) == chars.handle().toUShort(0,0)) {
+ QString value;
+ for ( int k = 3; k < handleDetails.size(); k++)
+ value = value + handleDetails.at(k);
+ m_leServices.at(index).d_ptr->characteristicList[j].d_ptr->value = value.toUtf8();
+ qCDebug(QT_BT_BLUEZ) << "Characteristic value set." << m_leServices.at(index).d_ptr->characteristicList[j].uuid() << chars.d_ptr->handle << value;
+ m_leServices.at(index).d_ptr->m_valueCounter++;
+ }
+ }
+ }
+ if (m_leServices.at(index).d_ptr->m_valueCounter == m_leServices.at(index).d_ptr->m_readCounter) {
+ setNotifications();
+ m_leServices.at(index).d_ptr->m_step++;
+ }
+ }
+ 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);
+ 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);
+
+ 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);
+ 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;
+ }
+ }
+ 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));
+ }
+ lastStep = true;
+ }
+ }
+ }
+ }
+ }
+}
+
+void QLowEnergyControllerPrivate::disconnectAllServices()
+{
+ for (int i = 0; i < m_leServices.size(); i++) {
+ process = process->instance();
+ process->endProcess();
+ m_leServices.at(i).d_ptr->m_step = 0;
+ m_leServices.at(i).d_ptr->m_valueCounter = 0;
+ if (m_leServices.at(i).isConnected()) {
+ m_leServices.at(i).d_ptr->connected = false;
+ emit q_ptr->disconnected(m_leServices.at(i));
+ }
+ if (errorString != QString())
+ emit q_ptr->error(m_leServices.at(i));
+ m_step = 0;
+ }
+ m_leServices.clear();
+}
+
+void QLowEnergyControllerPrivate::connectToTerminal()
+{
+ process->executeCommand(QStringLiteral("connect"));
+ process->executeCommand(QStringLiteral("\n"));
+ for (int i = 0; i < m_leServices.size(); i++)
+ m_leServices.at(i).d_ptr->m_step = 1;
+ m_step++;
+}
+
+void QLowEnergyControllerPrivate::setHandles()
+{
+ process->executeCommand(QStringLiteral("primary"));
+ process->executeCommand(QStringLiteral("\n"));
+ m_step++;
+}
+
+void QLowEnergyControllerPrivate::setCharacteristics(int a)
+{
+ const QString command = QStringLiteral("characteristics ") + m_leServices.at(a).d_ptr->startingHandle + QStringLiteral(" ") + m_leServices.at(a).d_ptr->endingHandle;
+ process->executeCommand(command);
+ process->executeCommand(QStringLiteral("\n"));
+ m_leServices.at(a).d_ptr->m_step++;
+}
+
+void QLowEnergyControllerPrivate::setNotifications()
+{
+ process->executeCommand(QStringLiteral("char-read-uuid 2902"));
+ process->executeCommand(QStringLiteral("\n"));
+}
+
+void QLowEnergyControllerPrivate::readCharacteristicValue(int index)
+{
+ for (int i = 0; i < m_leServices.at(index).d_ptr->characteristicList.size(); i++) {
+ if ((m_leServices.at(index).d_ptr->characteristicList.at(i).d_ptr->permission & QLowEnergyCharacteristicInfo::Read)) {
+ const QString uuidHandle = m_leServices.at(index).d_ptr->characteristicList.at(i).uuid().toString().remove(QLatin1Char('{')).remove(QLatin1Char('}'));
+ const QString command = QStringLiteral("char-read-uuid ") + uuidHandle;
+ process->executeCommand(command);
+ process->executeCommand(QStringLiteral("\n"));
+ }
+ }
+ m_leServices.at(index).d_ptr->m_step++;
+}
+
+QT_END_NAMESPACE
diff --git a/src/bluetooth/qlowenergycontroller_p.cpp b/src/bluetooth/qlowenergycontroller_p.cpp
new file mode 100644
index 00000000..0595a059
--- /dev/null
+++ b/src/bluetooth/qlowenergycontroller_p.cpp
@@ -0,0 +1,97 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited all rights reserved
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlowenergycontroller_p.h"
+#include "moc_qlowenergycontroller.cpp"
+
+QT_BEGIN_NAMESPACE
+
+QLowEnergyControllerPrivate::QLowEnergyControllerPrivate()
+{
+
+}
+
+QLowEnergyControllerPrivate::~QLowEnergyControllerPrivate()
+{
+
+}
+
+void QLowEnergyControllerPrivate::connectService(const QLowEnergyServiceInfo &service)
+{
+ Q_UNUSED(service);
+}
+
+void QLowEnergyControllerPrivate::disconnectService(const QLowEnergyServiceInfo &leService)
+{
+ Q_UNUSED(leService);
+}
+
+void QLowEnergyControllerPrivate::disconnectAllServices()
+{
+
+}
+
+void QLowEnergyControllerPrivate::_q_characteristicError(const QBluetoothUuid &uuid)
+{
+ Q_UNUSED(uuid);
+}
+
+void QLowEnergyControllerPrivate::_q_serviceConnected(const QBluetoothUuid &uuid)
+{
+ Q_UNUSED(uuid);
+}
+
+void QLowEnergyControllerPrivate::_q_serviceDisconnected(const QBluetoothUuid &uuid)
+{
+ Q_UNUSED(uuid);
+}
+
+void QLowEnergyControllerPrivate::_q_serviceError(const QBluetoothUuid &uuid)
+{
+ Q_UNUSED(uuid);
+}
+
+void QLowEnergyControllerPrivate::_q_valueReceived(const QBluetoothUuid &uuid)
+{
+ Q_UNUSED(uuid);
+}
+
+QT_END_NAMESPACE
diff --git a/src/bluetooth/qlowenergycontroller_p.h b/src/bluetooth/qlowenergycontroller_p.h
index 1d68f4b7..b0e07587 100644
--- a/src/bluetooth/qlowenergycontroller_p.h
+++ b/src/bluetooth/qlowenergycontroller_p.h
@@ -41,9 +41,11 @@
#ifndef QLOWENERGYCONTROLLER_P_H
#define QLOWENERGYCONTROLLER_P_H
#include "qlowenergycontroller.h"
+
QT_BEGIN_NAMESPACE
class QLowEnergyController;
+class QLowEnergyProcess;
class QLowEnergyControllerPrivate
{
@@ -59,11 +61,28 @@ public:
void _q_characteristicError(const QBluetoothUuid &uuid);
void _q_valueReceived(const QBluetoothUuid &uuid);
void _q_serviceDisconnected(const QBluetoothUuid &uuid);
+ void disconnectAllServices();
QList<QLowEnergyServiceInfo> m_leServices;
QString errorString;
+#ifdef QT_BLUEZ_BLUETOOTH
+ void connectToTerminal();
+ void setHandles();
+ void setCharacteristics(int);
+ void setNotifications();
+ void readCharacteristicValue(int);
+public slots:
+ void _q_replyReceived(const QString &reply);
+#endif
private:
+ bool m_randomAddress;
+#ifdef QT_BLUEZ_BLUETOOTH
+ QLowEnergyProcess *process;
+ int m_step;
+ bool m_deviceConnected;
+ bool m_commandStarted;
+#endif
QLowEnergyController *q_ptr;
};
QT_END_NAMESPACE
diff --git a/src/bluetooth/qlowenergydescriptorinfo.h b/src/bluetooth/qlowenergydescriptorinfo.h
index c02cb5a8..4ee6c983 100644
--- a/src/bluetooth/qlowenergydescriptorinfo.h
+++ b/src/bluetooth/qlowenergydescriptorinfo.h
@@ -56,6 +56,7 @@ class Q_BLUETOOTH_EXPORT QLowEnergyDescriptorInfo
friend class QLowEnergyCharacteristicInfo;
friend class QLowEnergyCharacteristicInfoPrivate;
friend class QLowEnergyServiceInfoPrivate;
+ friend class QLowEnergyControllerPrivate;
public:
explicit QLowEnergyDescriptorInfo(const QBluetoothUuid &uuid);
~QLowEnergyDescriptorInfo();
diff --git a/src/bluetooth/qlowenergyprocess_bluez.cpp b/src/bluetooth/qlowenergyprocess_bluez.cpp
index df8320a0..26013273 100644
--- a/src/bluetooth/qlowenergyprocess_bluez.cpp
+++ b/src/bluetooth/qlowenergyprocess_bluez.cpp
@@ -62,6 +62,7 @@ QLowEnergyProcess::QLowEnergyProcess()
*/
QLowEnergyProcess::~QLowEnergyProcess()
{
+ m_process->kill();
delete m_process;
}
@@ -79,7 +80,6 @@ QLowEnergyProcess *QLowEnergyProcess::instance()
*/
QProcess *QLowEnergyProcess::getProcess()
{
-
return m_process;
}
@@ -128,7 +128,6 @@ void QLowEnergyProcess::endProcess()
executeCommand(QStringLiteral("disconnect"));
executeCommand(QStringLiteral("\n"));
connected = false;
- m_process->terminate();
}
}
diff --git a/src/bluetooth/qlowenergyserviceinfo.cpp b/src/bluetooth/qlowenergyserviceinfo.cpp
index 857cdc25..23ead34e 100644
--- a/src/bluetooth/qlowenergyserviceinfo.cpp
+++ b/src/bluetooth/qlowenergyserviceinfo.cpp
@@ -208,16 +208,6 @@ bool QLowEnergyServiceInfo::isConnected() const
}
/*!
- This method is called if a device has a random device address that is used for connecting.
- It should be called before connecting to a service; otherwise connecting will not be
- successful and ConnectionRefused error will be emitted.
- */
-void QLowEnergyServiceInfo::setRandomAddress()
-{
- d_ptr->randomAddress = true;
-}
-
-/*!
Returns the address of the Bluetooth device that provides this service.
*/
QBluetoothDeviceInfo QLowEnergyServiceInfo::device() const
diff --git a/src/bluetooth/qlowenergyserviceinfo.h b/src/bluetooth/qlowenergyserviceinfo.h
index 2f21ec49..6fb2316a 100644
--- a/src/bluetooth/qlowenergyserviceinfo.h
+++ b/src/bluetooth/qlowenergyserviceinfo.h
@@ -84,8 +84,6 @@ public:
void setServiceType(QLowEnergyServiceInfo::ServiceType type);
QLowEnergyServiceInfo::ServiceType serviceType() const;
- void setRandomAddress();
-
bool isConnected() const;
bool isValid() const;
diff --git a/src/bluetooth/qlowenergyserviceinfo_bluez.cpp b/src/bluetooth/qlowenergyserviceinfo_bluez.cpp
index 85a8c2b2..9e34fee4 100644
--- a/src/bluetooth/qlowenergyserviceinfo_bluez.cpp
+++ b/src/bluetooth/qlowenergyserviceinfo_bluez.cpp
@@ -61,7 +61,6 @@ QLowEnergyServiceInfoPrivate::QLowEnergyServiceInfoPrivate():
serviceType(QLowEnergyServiceInfo::PrimaryService), connected(false), characteristic(0), m_valueCounter(0), m_readCounter(0)
{
m_step = 0;
- randomAddress = false;
QBluetoothLocalDevice localDevice;
adapterAddress = localDevice.address();
}
@@ -70,7 +69,6 @@ QLowEnergyServiceInfoPrivate::QLowEnergyServiceInfoPrivate(const QString &servic
serviceType(QLowEnergyServiceInfo::PrimaryService), connected(false), path(servicePath), characteristic(0)
{
m_step = 0;
- randomAddress = false;
}
QLowEnergyServiceInfoPrivate::~QLowEnergyServiceInfoPrivate()
@@ -78,306 +76,6 @@ QLowEnergyServiceInfoPrivate::~QLowEnergyServiceInfoPrivate()
delete characteristic;
}
-void QLowEnergyServiceInfoPrivate::registerServiceWatcher()
-{
- characteristicList.clear();
- process = process->instance();
- if (!process->isConnected()) {
- connect(process, SIGNAL(replySend(const QString &)), this, SLOT(replyReceived(const QString &)));
- QString command = QStringLiteral("gatttool -i ") + adapterAddress.toString() + QStringLiteral(" -b ") + deviceInfo.address().toString() + QStringLiteral(" -I");
- if (randomAddress)
- command += QStringLiteral(" -t random");
-
-#ifdef QT_LOWENERGYSERVICE_DEBUG
- qDebug() << "[REGISTER] uuid inside: " << uuid << command;
-#endif
- process->startCommand(command);
- process->addConnection();
- }
- else {
- m_step++;
- connect(process, SIGNAL(replySend(const QString &)), this, SLOT(replyReceived(const QString &)));
- }
-}
-
-void QLowEnergyServiceInfoPrivate::unregisterServiceWatcher()
-{
- if (connected) {
- process = process->instance();
- process->endProcess();
- connected = false;
- m_step = 0;
- m_valueCounter = 0;
- disconnect(process, SIGNAL(replySend(const QString &)), this, SLOT(replyReceived(const QString &)));
- emit disconnectedFromService(uuid);
- }
-}
-
-void QLowEnergyServiceInfoPrivate::replyReceived(const QString &reply)
-{
-#ifdef QT_LOWENERGYSERVICE_DEBUG
- qDebug() << uuid << "m step: " << m_step << reply;
-#endif
- bool stepSet = false;
- switch (m_step) {
- case 0:
- connectToTerminal();
- break;
- case 1:
- if (reply.contains(QStringLiteral("[CON]"))) {
- connected = true;
- setHandles();
- }
- else {
- connected = false;
- if (reply.contains(QStringLiteral("Connection refused (111)"))) {
-#ifdef QT_LOWENERGYSERVICE_DEBUG
- qDebug() << "Connection refused (111)";
-#endif
- errorString = QStringLiteral("Connection refused (111)");
- emit error(uuid);
- }
- else if (reply.contains(QStringLiteral("Device busy"))) {
-#ifdef QT_LOWENERGYSERVICE_DEBUG
- qDebug() << "Device busy";
-#endif
- errorString = QStringLiteral("Connection refused (111)");
- emit error(uuid);
- }
- }
- break;
- case 2:
- if (reply.contains(QStringLiteral("attr")) && reply.contains(QStringLiteral("uuid"))){
- const QStringList handles = reply.split(QStringLiteral("\n"));
- foreach (const QString &handle, handles) {
- if (handle.contains(QStringLiteral("attr")) && handle.contains(QStringLiteral("uuid"))) {
- const QStringList handleDetails = handle.split(QRegularExpression(QStringLiteral("[\\s+|,]")),
- QString::SkipEmptyParts);
- Q_ASSERT(handleDetails.count() == 9);
- const QBluetoothUuid foundUuid(handleDetails.at(8));
- if (foundUuid == uuid) {
- startingHandle = handleDetails.at(2);
- endingHandle = handleDetails.at(6);
- stepSet = true;
- }
- }
- }
- if (stepSet)
- setCharacteristics();
- }
- break;
- case 3:
- if (reply.contains(QStringLiteral("char")) && reply.contains(QStringLiteral("uuid"))) {
- const QStringList handles = reply.split(QStringLiteral("\n"));
- foreach (const QString& handle, handles) {
- if (handle.contains(QStringLiteral("char")) && handle.contains(QStringLiteral("uuid"))) {
- const QStringList handleDetails = handle.split(QRegularExpression(QStringLiteral("[\\s+|,]")),
- QString::SkipEmptyParts);
-#ifdef QT_LOWENERGYSERVICE_DEBUG
- qDebug() << handleDetails;
-#endif
- Q_ASSERT(handleDetails.count() == 11);
- const QString charHandle = handleDetails.at(8);
- ushort charHandleId = charHandle.toUShort(0, 0);
- if ( charHandleId >= startingHandle.toUShort(0,0) &&
- charHandleId <= endingHandle.toUShort(0,0))
- {
- const QBluetoothUuid charUuid(handleDetails.at(10));
- QVariantMap map;
-
- QLowEnergyCharacteristicInfo charInfo(charUuid);
- charInfo.d_ptr->handle = charHandle;
- charInfo.d_ptr->startingHandle = handleDetails.at(1);
- charInfo.d_ptr->permission = handleDetails.at(4).toUShort(0,0);
- map[QStringLiteral("uuid")] = charUuid.toString();
- map[QStringLiteral("handle")] = charHandle;
- map[QStringLiteral("permission")] = charInfo.d_ptr->permission;
- charInfo.d_ptr->properties = map;
- if (!(charInfo.d_ptr->permission & QLowEnergyCharacteristicInfo::Read)) {
-#ifdef QT_LOWENERGYSERVICE_DEBUG
- qDebug() << "GATT characteristic: Read not permitted: " << charInfo.d_ptr->uuid;
-#endif
- } else {
- m_readCounter++;
- }
- characteristicList.append(charInfo);
- stepSet = true;
- }
- }
- }
-#ifdef QT_LOWENERGYSERVICE_DEBUG
- qDebug() << "COUNTER : " << m_readCounter;
-#endif
- if ( stepSet )
- setNotifications();
- }
- break;
- case 4:
- if (reply.contains(QStringLiteral("handle")) && reply.contains(QStringLiteral("value"))) {
- const QStringList handles = reply.split(QStringLiteral("\n"));
- foreach (const QString handle, handles) {
- if (handle.contains(QStringLiteral("handle")) && handle.contains(QStringLiteral("value"))) {
- const QStringList handleDetails = handle.split(QRegularExpression(QStringLiteral("\\W+")), QString::SkipEmptyParts);
- if (!characteristicList.isEmpty()) {
- for (int j = 0; j < (characteristicList.size()-1); j++) {
- QLowEnergyCharacteristicInfo chars = characteristicList.at(j);
- QLowEnergyCharacteristicInfo charsNext = characteristicList.at(j+1);
- const QString handleId = handleDetails.at(1);
- ushort h = handleId.toUShort(0, 0);
-#ifdef QT_LOWENERGYSERVICE_DEBUG
- qDebug() << handleId << h << chars.handle() << chars.handle().toUShort(0,0);
-#endif
- 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);
- 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();
- characteristicList[j].d_ptr->descriptorsList.append(descriptor);
-#ifdef QT_LOWENERGYSERVICE_DEBUG
- qDebug() << "Notification characteristic set." << chars.d_ptr->handle << chars.d_ptr->notificationHandle;
-#endif
- }
- }
- }
- }
- }
-#ifdef QT_LOWENERGYSERVICE_DEBUG
- qDebug() << "COUNTER : " << m_readCounter;
-#endif
- if (m_readCounter > 0)
- readCharacteristicValue();
- else {
-#ifdef QT_LOWENERGYSERVICE_DEBUG
- qDebug() << "Ready to emit connected signal" << uuid;
-#endif
- m_step = 6;
- connected = true;
- emit connectedToService(uuid);
- }
- }
- break;
- case 5:
- // This part is for reading characteristic values
- if (reply.contains(QStringLiteral("handle")) && reply.contains(QStringLiteral("value"))) {
- const QStringList handles = reply.split(QStringLiteral("\n"));
- foreach (const QString &handle, handles) {
- if (handle.contains(QStringLiteral("handle")) &&
- handle.contains(QStringLiteral("value")))
- {
- const QStringList handleDetails = handle.split(QRegularExpression(QStringLiteral("\\W+")), QString::SkipEmptyParts);
- if (!characteristicList.isEmpty()) {
- for (int j = 0; j < characteristicList.size(); j++) {
- const QLowEnergyCharacteristicInfo chars = characteristicList.at(j);
- const QString handleId = handleDetails.at(1);
-#ifdef QT_LOWENERGYSERVICE_DEBUG
- qDebug() << handleId << handleId.toUShort(0,0) << chars.handle() << chars.handle().toUShort(0,0);
-#endif
- if (handleId.toUShort(0,0) == chars.handle().toUShort(0,0)) {
- QString value;
- for ( int k = 3; k < handleDetails.size(); k++)
- value = value + handleDetails.at(k);
- characteristicList[j].d_ptr->value = value.toUtf8();
-#ifdef QT_LOWENERGYSERVICE_DEBUG
- qDebug() << "Characteristic value set." << chars.d_ptr->handle << value;
-#endif
- m_valueCounter++;
- }
- }
- }
- }
- }
- if (m_valueCounter == m_readCounter) {
- m_step++;
-#ifdef QT_LOWENERGYSERVICE_DEBUG
- qDebug() << "Ready to emit connected signal" << uuid;
-#endif
- connected = true;
- emit connectedToService(uuid);
- }
- }
- break;
- default:
- break;
-
- }
-
-}
-
-void QLowEnergyServiceInfoPrivate::connectToTerminal()
-{
-#ifdef QT_LOWENERGYSERVICE_DEBUG
- qDebug() << "[CONNECT TO TERMINAL] uuid inside: " << uuid;
-#endif
- process->executeCommand(QStringLiteral("connect"));
- process->executeCommand(QStringLiteral("\n"));
- m_step++;
-}
-
-void QLowEnergyServiceInfoPrivate::setHandles()
-{
-#ifdef QT_LOWENERGYSERVICE_DEBUG
- qDebug() << "Setting handles: primary";
-#endif
- process->executeCommand(QStringLiteral("primary"));
- process->executeCommand(QStringLiteral("\n"));
- m_step++;
-}
-
-void QLowEnergyServiceInfoPrivate::setCharacteristics()
-{
- const QString command = QStringLiteral("characteristics ") + startingHandle + QStringLiteral(" ") + endingHandle;
-#ifdef QT_LOWENERGYSERVICE_DEBUG
- qDebug() << "Setting characteristics: " << command;
-#endif
- process->executeCommand(command);
- process->executeCommand(QStringLiteral("\n"));
- m_step++;
-}
-
-void QLowEnergyServiceInfoPrivate::setNotifications()
-{
-#ifdef QT_LOWENERGYSERVICE_DEBUG
- qDebug() << "Setting notifications: char-read-uuid 2902";
-#endif
- process->executeCommand(QStringLiteral("char-read-uuid 2902"));
- process->executeCommand(QStringLiteral("\n"));
- m_step++;
-}
-
-void QLowEnergyServiceInfoPrivate::readCharacteristicValue()
-{
- for (int i = 0; i < characteristicList.size(); i++) {
- if ((characteristicList.at(i).d_ptr->permission & QLowEnergyCharacteristicInfo::Read)) {
- const QString uuidHandle = characteristicList.at(i).uuid().toString().remove(QLatin1Char('{')).remove(QLatin1Char('}'));
-#ifdef QT_LOWENERGYSERVICE_DEBUG
- qDebug() << "FFFFFF Setting notifications: char-read-uuid " << uuidHandle ;
-#endif
- const QString command = QStringLiteral("char-read-uuid ") + uuidHandle;
- process->executeCommand(command);
- process->executeCommand(QStringLiteral("\n"));
- }
- }
- m_step++;
-}
-
-void QLowEnergyServiceInfoPrivate::readDescriptors()
-{
- const QString command = QStringLiteral("char-desc ") + startingHandle + QStringLiteral(" ") + endingHandle;
- process->executeCommand(command);
- process->executeCommand(QStringLiteral("\n"));
-
- m_step++;
-}
-
bool QLowEnergyServiceInfoPrivate::valid()
{
if (adapterAddress == QBluetoothAddress())
diff --git a/src/bluetooth/qlowenergyserviceinfo_p.h b/src/bluetooth/qlowenergyserviceinfo_p.h
index aa7b0675..d033a613 100644
--- a/src/bluetooth/qlowenergyserviceinfo_p.h
+++ b/src/bluetooth/qlowenergyserviceinfo_p.h
@@ -60,6 +60,7 @@ class QLowEnergyProcess;
class QLowEnergyServiceInfoPrivate: public QObject
{
Q_OBJECT
+ friend class QLowEnergyControllerPrivate;
public:
QLowEnergyServiceInfoPrivate();
@@ -80,21 +81,11 @@ public:
QLowEnergyServiceInfo::ServiceType serviceType;
bool connected;
QBluetoothDeviceInfo deviceInfo;
- QString errorString;
- bool randomAddress;
#ifdef QT_BLUEZ_BLUETOOTH
QString startingHandle;
QString endingHandle;
QString path;
QBluetoothAddress adapterAddress;
- void connectToTerminal();
- void setHandles();
- void setCharacteristics();
- void setNotifications();
- void readCharacteristicValue();
- void readDescriptors();
-public slots:
- void replyReceived(const QString &reply);
#endif
#ifdef QT_QNX_BLUETOOTH