summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/android
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@theqtcompany.com>2014-11-07 12:06:43 +0100
committerAlex Blasche <alexander.blasche@theqtcompany.com>2014-11-10 14:32:51 +0100
commit327b6b7f8ff9acda74f403f2ff286e67f4202dfd (patch)
treea8c5649da588a0d428b4710b6d0080fe2d273da1 /src/bluetooth/android
parente0dc61db4af89cce14ade3582ac92e4b713c7982 (diff)
Propagate Charactereristic data to Qt layer
Although this makes the lowenergyscanner example functionally complete, descriptor data and service meta data are still not accessable via the Qt API. Change-Id: Ifb84010b4fea054357c07424ac30116d1e4f9de0 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/bluetooth/android')
-rw-r--r--src/bluetooth/android/jni_android.cpp2
-rw-r--r--src/bluetooth/android/lowenergynotificationhub.cpp35
-rw-r--r--src/bluetooth/android/lowenergynotificationhub_p.h10
3 files changed, 46 insertions, 1 deletions
diff --git a/src/bluetooth/android/jni_android.cpp b/src/bluetooth/android/jni_android.cpp
index 5ae18161..b75ca2df 100644
--- a/src/bluetooth/android/jni_android.cpp
+++ b/src/bluetooth/android/jni_android.cpp
@@ -205,6 +205,8 @@ static JNINativeMethod methods_le[] = {
(void *) LowEnergyNotificationHub::lowEnergy_servicesDiscovered},
{"leServiceDetailDiscoveryFinished", "(JLjava/lang/String;)V",
(void *) LowEnergyNotificationHub::lowEnergy_serviceDetailsDiscovered},
+ {"leCharacteristicRead", "(JLjava/lang/String;ILjava/lang/String;I[B)V",
+ (void *) LowEnergyNotificationHub::lowEnergy_characteristicRead},
};
static JNINativeMethod methods_server[] = {
diff --git a/src/bluetooth/android/lowenergynotificationhub.cpp b/src/bluetooth/android/lowenergynotificationhub.cpp
index e009e5f7..71aa5a02 100644
--- a/src/bluetooth/android/lowenergynotificationhub.cpp
+++ b/src/bluetooth/android/lowenergynotificationhub.cpp
@@ -137,4 +137,39 @@ void LowEnergyNotificationHub::lowEnergy_serviceDetailsDiscovered(
Q_ARG(QString, serviceUuid));
}
+void LowEnergyNotificationHub::lowEnergy_characteristicRead(
+ JNIEnv *env, jobject, jlong qtObject, jobject sUuid, jint handle,
+ jobject cUuid, jint properties, jbyteArray data)
+{
+ lock.lockForRead();
+ LowEnergyNotificationHub *hub = hubMap()->value(qtObject);
+ lock.unlock();
+ if (!hub)
+ return;
+
+
+ const QBluetoothUuid serviceUuid(QAndroidJniObject(sUuid).toString());
+ if (serviceUuid.isNull())
+ return;
+
+ const QBluetoothUuid charUuid(QAndroidJniObject(cUuid).toString());
+
+ jsize length = env->GetArrayLength(data);
+ jbyte* nativeData = (jbyte*) malloc(length * sizeof(jbyte));
+ if (!nativeData)
+ return;
+
+ env->GetByteArrayRegion(data, 0, length, nativeData);
+ const QByteArray qtArray(reinterpret_cast<const char*>(nativeData),
+ length); //takes ownership of data
+
+ QMetaObject::invokeMethod(hub, "characteristicRead", Qt::QueuedConnection,
+ Q_ARG(QBluetoothUuid, serviceUuid),
+ Q_ARG(int, handle),
+ Q_ARG(QBluetoothUuid, charUuid),
+ Q_ARG(int, properties),
+ Q_ARG(QByteArray, qtArray));
+ free(nativeData);
+}
+
QT_END_NAMESPACE
diff --git a/src/bluetooth/android/lowenergynotificationhub_p.h b/src/bluetooth/android/lowenergynotificationhub_p.h
index 06c7b3ff..7a1e2d79 100644
--- a/src/bluetooth/android/lowenergynotificationhub_p.h
+++ b/src/bluetooth/android/lowenergynotificationhub_p.h
@@ -41,6 +41,7 @@
#include <QtBluetooth/QBluetoothAddress>
#include <jni.h>
+#include <QtBluetooth/QLowEnergyCharacteristic>
#include "qlowenergycontroller_p.h"
QT_BEGIN_NAMESPACE
@@ -59,6 +60,10 @@ public:
jint errorCode, jobject uuidList);
static void lowEnergy_serviceDetailsDiscovered(JNIEnv *, jobject,
jlong qtObject, jobject uuid);
+ static void lowEnergy_characteristicRead(JNIEnv*env, jobject, jlong qtObject,
+ jobject serviceUuid,
+ jint handle, jobject charUuid,
+ jint properties, jbyteArray data);
QAndroidJniObject javaObject()
{
@@ -67,9 +72,12 @@ public:
signals:
void connectionUpdated(QLowEnergyController::ControllerState newState,
- QLowEnergyController::Error errorCode);
+ QLowEnergyController::Error errorCode);
void servicesDiscovered(QLowEnergyController::Error errorCode, const QString &uuids);
void serviceDetailsDiscoveryFinished(const QString& serviceUuid);
+ void characteristicRead(const QBluetoothUuid &serviceUuid,
+ int handle, const QBluetoothUuid &charUuid,
+ int properties, const QByteArray& data);
public slots:
private: