summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/osx
diff options
context:
space:
mode:
authorTimur Pocheptsov <timur.pocheptsov@qt.io>2016-11-10 17:49:17 +0100
committerTimur Pocheptsov <timur.pocheptsov@qt.io>2016-11-11 08:50:06 +0000
commit72fbcaf6f50eda25aace772d49a575ddaae852c3 (patch)
tree368ce2633b6673680386796595fb04cafb45c520 /src/bluetooth/osx
parent8c2f88f2294ea871e374ef1a13ea4793854bd214 (diff)
LE peripheral - fix a characteristic's length
With Qt's Bluetooth API it's possible to write values with different lengths into the same characteristic. Imagine this scenario: service->writeCharacteristic(handle, QByteArray("abcd")); and then service->writeCharacteristic(handle, QByteArray(2, 0)); If we read from the characteristic later, we get: 00cd. A write request in CoreBluetooth is presented as an array of CBATTRequest, each of them has its offset and value with length. After processing these requests we truncate a characteristic's length if needed. Task-number: QTBUG-56898 Change-Id: I674637eb78c806364d1a89a1db8ab3f31a8800ce Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/bluetooth/osx')
-rw-r--r--src/bluetooth/osx/osxbtperipheralmanager.mm17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/bluetooth/osx/osxbtperipheralmanager.mm b/src/bluetooth/osx/osxbtperipheralmanager.mm
index 1a461be9..03b95667 100644
--- a/src/bluetooth/osx/osxbtperipheralmanager.mm
+++ b/src/bluetooth/osx/osxbtperipheralmanager.mm
@@ -51,7 +51,6 @@
#include <algorithm>
#include <limits>
-#include <set>
namespace
{
@@ -584,20 +583,24 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
}
}
- std::set<QLowEnergyHandle> updated;
+ std::map<QLowEnergyHandle, NSUInteger> updated;
for (CBATTRequest *request in requests) {
// Transition to 'connected' if needed.
[self addConnectedCentral:request.central];
-
const auto charHandle = charMap.key(request.characteristic);
- updated.insert(charHandle);
+ const auto prevLen = updated[charHandle];
+ updated[charHandle] = std::max(request.offset + request.value.length,
+ prevLen);
[self writeValueForCharacteristic:charHandle withWriteRequest:request];
}
- for (const auto handle : updated) {
- emit notifier->characteristicUpdated(handle, qt_bytearray(charValues[handle]));
- const ObjCStrongReference<NSData> copy([NSData dataWithData:charValues[handle]],
+ for (const auto pair : updated) {
+ const auto handle = pair.first;
+ NSMutableData *value = charValues[handle];
+ value.length = pair.second;
+ emit notifier->characteristicUpdated(handle, qt_bytearray(value));
+ const ObjCStrongReference<NSData> copy([NSData dataWithData:value],
true);
updateQueue.push_back(UpdateRequest{handle, copy});
}