diff options
author | Alex Blasche <alexander.blasche@theqtcompany.com> | 2015-04-09 17:05:27 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@theqtcompany.com> | 2015-04-15 08:30:55 +0000 |
commit | cfdd43d118fbc54a3157eb0c9f7c3ab2bf8cc822 (patch) | |
tree | 5870e84414eb93e99977ecfe1a2dd3749e0f765d /src/bluetooth/qlowenergycontroller_android.cpp | |
parent | 37837004b5d9b551c575c383395579b3d3a38c1c (diff) |
Android: Implement QLEService:readCharacateristic & readDescriptor
In general we extend the concept of the write queue. Not only do we
queue up write requests but also read requests.
The handling of read errors is still missing. Right now the
QLEService::error() signal is not emitted when a readCharacteristic()
and readDescriptor() call fails.
Change-Id: I4b4f086c351c4a29d6e48e8ee9079e9f33f36539
Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com>
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/bluetooth/qlowenergycontroller_android.cpp')
-rw-r--r-- | src/bluetooth/qlowenergycontroller_android.cpp | 63 |
1 files changed, 59 insertions, 4 deletions
diff --git a/src/bluetooth/qlowenergycontroller_android.cpp b/src/bluetooth/qlowenergycontroller_android.cpp index 2794fe17..c1fa0813 100644 --- a/src/bluetooth/qlowenergycontroller_android.cpp +++ b/src/bluetooth/qlowenergycontroller_android.cpp @@ -236,18 +236,57 @@ void QLowEnergyControllerPrivate::writeDescriptor( } void QLowEnergyControllerPrivate::readCharacteristic( - const QSharedPointer<QLowEnergyServicePrivate> /*service*/, - const QLowEnergyHandle /*charHandle*/) + const QSharedPointer<QLowEnergyServicePrivate> service, + const QLowEnergyHandle charHandle) { + Q_ASSERT(!service.isNull()); + + if (!service->characteristicList.contains(charHandle)) + return; + + QAndroidJniEnvironment env; + bool result = false; + if (hub) { + qCDebug(QT_BT_ANDROID) << "Read characteristic with handle" + << charHandle << service->uuid; + result = hub->javaObject().callMethod<jboolean>("readCharacteristic", + "(I)Z", charHandle); + } + if (env->ExceptionOccurred()) { + env->ExceptionDescribe(); + env->ExceptionClear(); + result = false; + } + + if (!result) + service->setError(QLowEnergyService::CharacteristicWriteError); } void QLowEnergyControllerPrivate::readDescriptor( - const QSharedPointer<QLowEnergyServicePrivate> /*service*/, + const QSharedPointer<QLowEnergyServicePrivate> service, const QLowEnergyHandle /*charHandle*/, - const QLowEnergyHandle /*descriptorHandle*/) + const QLowEnergyHandle descriptorHandle) { + Q_ASSERT(!service.isNull()); + + QAndroidJniEnvironment env; + bool result = false; + if (hub) { + qCDebug(QT_BT_ANDROID) << "Read descriptor with handle" + << descriptorHandle << service->uuid; + result = hub->javaObject().callMethod<jboolean>("readDescriptor", + "(I)Z", descriptorHandle); + } + + if (env->ExceptionOccurred()) { + env->ExceptionDescribe(); + env->ExceptionClear(); + result = false; + } + if (!result) + service->setError(QLowEnergyService::DescriptorWriteError); } void QLowEnergyControllerPrivate::connectionUpdated( @@ -390,6 +429,15 @@ void QLowEnergyControllerPrivate::characteristicRead( charDetails.value = data; //value handle always one larger than characteristics value handle charDetails.valueHandle = charHandle + 1; + + if (service->state == QLowEnergyService::ServiceDiscovered) { + QLowEnergyCharacteristic characteristic = characteristicForHandle(charHandle); + if (!characteristic.isValid()) { + qCWarning(QT_BT_ANDROID) << "characteristicRead: Cannot find characteristic"; + return; + } + emit service->characteristicRead(characteristic, data); + } } void QLowEnergyControllerPrivate::descriptorRead( @@ -421,6 +469,13 @@ void QLowEnergyControllerPrivate::descriptorRead( if (!entryUpdated) { qCWarning(QT_BT_ANDROID) << "Cannot find/update descriptor" << descUuid << charUuid << serviceUuid; + } else if (service->state == QLowEnergyService::ServiceDiscovered){ + QLowEnergyDescriptor descriptor = descriptorForHandle(descHandle); + if (!descriptor.isValid()) { + qCWarning(QT_BT_ANDROID) << "descriptorRead: Cannot find descriptor"; + return; + } + emit service->descriptorRead(descriptor, data); } } |