diff options
author | Alex Blasche <alexander.blasche@theqtcompany.com> | 2014-12-03 14:19:48 +0100 |
---|---|---|
committer | Alex Blasche <alexander.blasche@theqtcompany.com> | 2014-12-04 09:35:31 +0100 |
commit | 90491cb94b5aaad8c9aded106fea0aba09ac4be9 (patch) | |
tree | be2e5bc76035a99932caf011e407813ab33ce31b /src | |
parent | 01ea948742b649ad482c2e3e6d914fc1ac5f4917 (diff) |
Don't update cached char value when property is not readable
In addition we update the documentation to reflect the slightly changed
API behavior.
Change-Id: Ieddee750aa35a32d3c01213dfbf678ee2a1d88d7
Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com>
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src')
4 files changed, 23 insertions, 6 deletions
diff --git a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java index 748d709e..b9f7e184 100644 --- a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java +++ b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java @@ -919,7 +919,7 @@ public class QtBluetoothLE { into two operations. BluetoothGatt.enableCharacteristicNotification ensures the local Blueooth stack forwards the notifications. In addition, BluetoothGattDescriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE) - must be written to the peripheral + must be written to the peripheral. */ diff --git a/src/bluetooth/qlowenergycharacteristic.cpp b/src/bluetooth/qlowenergycharacteristic.cpp index 2f8bd6fa..91e9d94d 100644 --- a/src/bluetooth/qlowenergycharacteristic.cpp +++ b/src/bluetooth/qlowenergycharacteristic.cpp @@ -195,9 +195,11 @@ QLowEnergyCharacteristic::PropertyTypes QLowEnergyCharacteristic::properties() c \l {QLowEnergyService::writeCharacteristic()}{write operation} or when an update notification is received. - The returned \l QByteArray is empty if the characteristic does not have the - \l {QLowEnergyCharacteristic::Read}{read permission}. However, a non-readable - characteristic may obtain a non-empty value via a related notification or write operation. + The returned \l QByteArray always remains empty if the characteristic does not + have the \l {QLowEnergyCharacteristic::Read}{read permission}. In such cases only + the \l QLowEnergyService::characteristicChanged() or + \l QLowEnergyService::characteristicWritten() may provice information about the + value of this characteristic. */ QByteArray QLowEnergyCharacteristic::value() const { diff --git a/src/bluetooth/qlowenergycontroller_android.cpp b/src/bluetooth/qlowenergycontroller_android.cpp index 9be5cff0..e1b668ca 100644 --- a/src/bluetooth/qlowenergycontroller_android.cpp +++ b/src/bluetooth/qlowenergycontroller_android.cpp @@ -431,7 +431,10 @@ void QLowEnergyControllerPrivate::characteristicWritten( return; } - updateValueOfCharacteristic(charHandle, data, false); + // only update cache when property is readable. Otherwise it remains + // empty. + if (characteristic.properties() & QLowEnergyCharacteristic::Read) + updateValueOfCharacteristic(charHandle, data, false); emit service->characteristicWritten(characteristic, data); } @@ -479,7 +482,10 @@ void QLowEnergyControllerPrivate::characteristicChanged( return; } - updateValueOfCharacteristic(characteristic.attributeHandle(), + // only update cache when property is readable. Otherwise it remains + // empty. + if (characteristic.properties() & QLowEnergyCharacteristic::Read) + updateValueOfCharacteristic(characteristic.attributeHandle(), data, false); emit service->characteristicChanged(characteristic, data); } diff --git a/src/bluetooth/qlowenergyservice.cpp b/src/bluetooth/qlowenergyservice.cpp index 10307332..96c3bbeb 100644 --- a/src/bluetooth/qlowenergyservice.cpp +++ b/src/bluetooth/qlowenergyservice.cpp @@ -242,6 +242,15 @@ QT_BEGIN_NAMESPACE by calling \l writeCharacteristic(). If the write operation is not successful, the \l error() signal is emitted using the \l CharacteristicWriteError flag. + Since this signal is an indication of a successful write operation \a newValue + generally matches the value that was passed to the associated + \l writeCharacteristic() call. However, it may happen that the two values differ + from each other. This can occur in cases when the written value is + used by the remote device to trigger an operation and it returns some other value via + the written and/or change notification. Such cases are very specific to the + target device. In any case, the reception of the written signal can still be considered + as a sign that the target device received the to-be-written value. + \note If \l writeCharacteristic() is called using the \l WriteWithoutResponse mode, this signal and the \l error() are never emitted. |