summaryrefslogtreecommitdiffstats
path: root/src/bluetooth
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@theqtcompany.com>2014-11-18 08:50:54 +0100
committerAlex Blasche <alexander.blasche@theqtcompany.com>2014-11-24 15:08:57 +0100
commit6ed49688149fd43b3d4c5aa0415191a8c1cdc1a5 (patch)
treeae2a3ef1c4d5c5bcb5f6912ed874bcebf8977eed /src/bluetooth
parent5de53cc79ecb83e3bce97567b1462ce432cc5759 (diff)
Android: characteristic changed notification support
Change-Id: I4c50df7d758390989c2e2127f7646e5d2dc34712 Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/bluetooth')
-rw-r--r--src/bluetooth/android/jni_android.cpp2
-rw-r--r--src/bluetooth/android/lowenergynotificationhub.cpp21
-rw-r--r--src/bluetooth/android/lowenergynotificationhub_p.h3
-rw-r--r--src/bluetooth/qlowenergycontroller_android.cpp22
-rw-r--r--src/bluetooth/qlowenergycontroller_p.h1
5 files changed, 49 insertions, 0 deletions
diff --git a/src/bluetooth/android/jni_android.cpp b/src/bluetooth/android/jni_android.cpp
index 7eacd3bc..a877b6bf 100644
--- a/src/bluetooth/android/jni_android.cpp
+++ b/src/bluetooth/android/jni_android.cpp
@@ -213,6 +213,8 @@ static JNINativeMethod methods_le[] = {
(void *) LowEnergyNotificationHub::lowEnergy_characteristicWritten},
{"leDescriptorWritten", "(JI[BI)V",
(void *) LowEnergyNotificationHub::lowEnergy_descriptorWritten},
+ {"leCharacteristicChanged", "(JI[B)V",
+ (void *) LowEnergyNotificationHub::lowEnergy_characteristicChanged},
};
static JNINativeMethod methods_server[] = {
diff --git a/src/bluetooth/android/lowenergynotificationhub.cpp b/src/bluetooth/android/lowenergynotificationhub.cpp
index 00ef4ff0..a0dbe565 100644
--- a/src/bluetooth/android/lowenergynotificationhub.cpp
+++ b/src/bluetooth/android/lowenergynotificationhub.cpp
@@ -260,4 +260,25 @@ void LowEnergyNotificationHub::lowEnergy_descriptorWritten(
(QLowEnergyService::ServiceError)errorCode));
}
+void LowEnergyNotificationHub::lowEnergy_characteristicChanged(
+ JNIEnv *env, jobject, jlong qtObject, jint charHandle, jbyteArray data)
+{
+ lock.lockForRead();
+ LowEnergyNotificationHub *hub = hubMap()->value(qtObject);
+ lock.unlock();
+ if (!hub)
+ return;
+
+ QByteArray payload;
+ if (data) { //empty Java byte array is 0x0
+ jsize length = env->GetArrayLength(data);
+ payload.resize(length);
+ env->GetByteArrayRegion(data, 0, length,
+ reinterpret_cast<signed char*>(payload.data()));
+ }
+
+ QMetaObject::invokeMethod(hub, "characteristicChanged", Qt::QueuedConnection,
+ Q_ARG(int, charHandle), Q_ARG(QByteArray, payload));
+}
+
QT_END_NAMESPACE
diff --git a/src/bluetooth/android/lowenergynotificationhub_p.h b/src/bluetooth/android/lowenergynotificationhub_p.h
index b3399a8d..286c8120 100644
--- a/src/bluetooth/android/lowenergynotificationhub_p.h
+++ b/src/bluetooth/android/lowenergynotificationhub_p.h
@@ -74,6 +74,8 @@ public:
static void lowEnergy_descriptorWritten(JNIEnv *, jobject, jlong qtObject,
jint descHandle, jbyteArray data,
jint errorCode);
+ static void lowEnergy_characteristicChanged(JNIEnv *, jobject, jlong qtObject,
+ jint charHandle, jbyteArray data);
QAndroidJniObject javaObject()
{
@@ -95,6 +97,7 @@ signals:
QLowEnergyService::ServiceError errorCode);
void descriptorWritten(int descHandle, const QByteArray &data,
QLowEnergyService::ServiceError errorCode);
+ void characteristicChanged(int charHandle, const QByteArray &data);
public slots:
private:
diff --git a/src/bluetooth/qlowenergycontroller_android.cpp b/src/bluetooth/qlowenergycontroller_android.cpp
index a28feaf6..e2624a56 100644
--- a/src/bluetooth/qlowenergycontroller_android.cpp
+++ b/src/bluetooth/qlowenergycontroller_android.cpp
@@ -78,6 +78,8 @@ void QLowEnergyControllerPrivate::connectToDevice()
this, &QLowEnergyControllerPrivate::characteristicWritten);
connect(hub, &LowEnergyNotificationHub::descriptorWritten,
this, &QLowEnergyControllerPrivate::descriptorWritten);
+ connect(hub, &LowEnergyNotificationHub::characteristicChanged,
+ this, &QLowEnergyControllerPrivate::characteristicChanged);
}
if (!hub->javaObject().isValid()) {
@@ -432,4 +434,24 @@ void QLowEnergyControllerPrivate::descriptorWritten(
emit service->descriptorWritten(descriptor, data);
}
+void QLowEnergyControllerPrivate::characteristicChanged(
+ int charHandle, const QByteArray &data)
+{
+ QSharedPointer<QLowEnergyServicePrivate> service =
+ serviceForHandle(charHandle);
+ if (service.isNull())
+ return;
+
+ qCDebug(QT_BT_ANDROID) << "Characteristic change notification" << service->uuid
+ << charHandle << data.toHex();
+
+ QLowEnergyCharacteristic characteristic = characteristicForHandle(charHandle);
+ if (!characteristic.isValid()) {
+ qCWarning(QT_BT_ANDROID) << "characteristicChanged: Cannot find characteristic";
+ return;
+ }
+
+ emit service->characteristicChanged(characteristic, data);
+}
+
QT_END_NAMESPACE
diff --git a/src/bluetooth/qlowenergycontroller_p.h b/src/bluetooth/qlowenergycontroller_p.h
index 17c28cd6..add92b43 100644
--- a/src/bluetooth/qlowenergycontroller_p.h
+++ b/src/bluetooth/qlowenergycontroller_p.h
@@ -208,6 +208,7 @@ private slots:
QLowEnergyService::ServiceError errorCode);
void descriptorWritten(int descHandle, const QByteArray &data,
QLowEnergyService::ServiceError errorCode);
+ void characteristicChanged(int charHandle, const QByteArray &data);
#endif
private:
QLowEnergyController *q_ptr;