summaryrefslogtreecommitdiffstats
path: root/src/android/bluetooth
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@theqtcompany.com>2014-11-12 10:39:04 +0100
committerAlex Blasche <alexander.blasche@theqtcompany.com>2014-11-14 08:46:04 +0100
commit26b5e44ffc7c33b258e6c3eb6bce340d51a4a377 (patch)
tree757fbd89fad2fc363ef3f4c991e4b00c10d07a08 /src/android/bluetooth
parentcc94fad463e50f0f4ec110bacc098f4c4d4818d8 (diff)
Support for QLEService::writeDescriptor() on Android
Change-Id: I1c7f0491506c6f0512d097a419660c5f5e7fb144 Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/android/bluetooth')
-rw-r--r--src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java53
1 files changed, 50 insertions, 3 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 c5198dbd..45120081 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
@@ -258,7 +258,6 @@ public class QtBluetoothLE {
errorCode = 0; break; // NoError
default:
errorCode = 2; break; // CharacteristicWriteError
-
}
leCharacteristicWritten(qtObject, handle+1, characteristic.getValue(), errorCode);
@@ -342,7 +341,21 @@ public class QtBluetoothLE {
android.bluetooth.BluetoothGattDescriptor descriptor,
int status)
{
- System.out.println("onDescriptorWrite");
+ if (status != BluetoothGatt.GATT_SUCCESS)
+ Log.w(TAG, "onDescriptorWrite: error " + status);
+
+ int handle = handleForDescriptor(descriptor);
+
+ int errorCode = 0;
+ //This must be in sync with QLowEnergyService::ServiceError
+ switch (status) {
+ case BluetoothGatt.GATT_SUCCESS:
+ errorCode = 0; break; // NoError
+ default:
+ errorCode = 3; break; // DescriptorWriteError
+ }
+
+ leDescriptorWritten(qtObject, handle+1, descriptor.getValue(), errorCode);
}
//TODO Requires Android API 21 which is not available on CI yet.
// public void onReliableWriteCompleted(android.bluetooth.BluetoothGatt gatt,
@@ -725,10 +738,42 @@ public class QtBluetoothLE {
return false;
}
- entry.characteristic.setValue(newValue);
+ boolean result = entry.characteristic.setValue(newValue);
+ if (!result) {
+ Log.w(TAG, "BluetoothGattCharacteristic.setValue failed");
+ return false;
+ }
+
return mBluetoothGatt.writeCharacteristic(entry.characteristic);
}
+ /*************************************************************/
+ /* Write Descriptors */
+ /*************************************************************/
+
+ public boolean writeDescriptor(int descHandle, byte[] newValue)
+ {
+ if (mBluetoothGatt == null)
+ return false;
+
+ GattEntry entry = null;
+ try {
+ entry = entries.get(descHandle-1); //Qt always uses handles+1
+ } catch (IndexOutOfBoundsException ex) {
+ ex.printStackTrace();
+ return false;
+ }
+
+ boolean result = entry.descriptor.setValue(newValue);
+ if (!result) {
+ Log.w(TAG, "BluetoothGattDescriptor.setValue failed");
+ return false;
+ }
+
+ return mBluetoothGatt.writeDescriptor(entry.descriptor);
+ }
+
+
public native void leConnectionStateChange(long qtObject, int wasErrorTransition, int newState);
public native void leServicesDiscovered(long qtObject, int errorCode, String uuidList);
public native void leServiceDetailDiscoveryFinished(long qtObject, final String serviceUuid,
@@ -740,6 +785,8 @@ public class QtBluetoothLE {
int descHandle, String descUuid, byte[] data);
public native void leCharacteristicWritten(long qtObject, int charHandle, byte[] newData,
int errorCode);
+ public native void leDescriptorWritten(long qtObject, int charHandle, byte[] newData,
+ int errorCode);
}