From a017003f64ce961ba2846daa7b55fb69c3202e11 Mon Sep 17 00:00:00 2001 From: Francois Beaufort Date: Mon, 24 Apr 2017 08:54:14 +0200 Subject: [PATCH] Fix long GATT read operations --- .../bletestperipheral/Peripheral.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/github/webbluetoothcg/bletestperipheral/Peripheral.java b/app/src/main/java/io/github/webbluetoothcg/bletestperipheral/Peripheral.java index ecf1a6d..68294e8 100644 --- a/app/src/main/java/io/github/webbluetoothcg/bletestperipheral/Peripheral.java +++ b/app/src/main/java/io/github/webbluetoothcg/bletestperipheral/Peripheral.java @@ -142,15 +142,15 @@ public void run() { public void onCharacteristicReadRequest(BluetoothDevice device, int requestId, int offset, BluetoothGattCharacteristic characteristic) { super.onCharacteristicReadRequest(device, requestId, offset, characteristic); + byte [] value = characteristictem.getValue(); Log.d(TAG, "Device tried to read characteristic: " + characteristic.getUuid()); - Log.d(TAG, "Value: " + Arrays.toString(characteristic.getValue())); + Log.d(TAG, "Value: " + Arrays.toString(value)); if (offset != 0) { - mGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_INVALID_OFFSET, offset, - /* value (optional) */ null); + mGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, offset, + Arrays.copyOfRange(value, offset, value.length)); return; } - mGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, - offset, characteristic.getValue()); + mGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, offset, value); } @Override @@ -178,15 +178,15 @@ public void onCharacteristicWriteRequest(BluetoothDevice device, int requestId, public void onDescriptorReadRequest(BluetoothDevice device, int requestId, int offset, BluetoothGattDescriptor descriptor) { super.onDescriptorReadRequest(device, requestId, offset, descriptor); + byte [] value = descriptor.getValue(); Log.d(TAG, "Device tried to read descriptor: " + descriptor.getUuid()); - Log.d(TAG, "Value: " + Arrays.toString(descriptor.getValue())); + Log.d(TAG, "Value: " + Arrays.toString(value)); if (offset != 0) { - mGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_INVALID_OFFSET, offset, - /* value (optional) */ null); + mGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, offset, + Arrays.copyOfRange(value, offset, value.length)); return; } - mGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, offset, - descriptor.getValue()); + mGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, offset, value); } @Override