From cff9d4567cb642bb4dd2d644777bf6f4b4f846ec Mon Sep 17 00:00:00 2001 From: Graham Jones Date: Sun, 24 Mar 2024 22:16:13 +0000 Subject: [PATCH] V4.2.4a - check for null gatt characteristic before writing - should fix #158 --- app/src/main/AndroidManifest.xml | 4 +-- .../openseizuredetector/SdDataSourceBLE.java | 26 +++++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9d91629..5ee9a9f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="138" + android:versionName="4.2.4a"> diff --git a/app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java b/app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java index 634c5a8..093c949 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java @@ -392,18 +392,22 @@ public class SdDataSourceBLE extends SdDataSource { * @param nBytes - number of bytes to send. */ private void executeWriteCharacteristic(BluetoothGattCharacteristic gattCharacteristic, byte[] valBytes) { - gattCharacteristic.setValue(valBytes); - boolean retVal = mBluetoothGatt.writeCharacteristic(gattCharacteristic); - if (retVal) { - Log.d(TAG, "executeWriteCharacteristic - write initiated successfully"); + if (gattCharacteristic != null) { + gattCharacteristic.setValue(valBytes); + boolean retVal = mBluetoothGatt.writeCharacteristic(gattCharacteristic); + if (retVal) { + Log.d(TAG, "executeWriteCharacteristic - write initiated successfully"); + } else { + Log.d(TAG, "executeWriteCharacteristic - write initiation failed - waiting, then re-trying"); + mHandler.postDelayed(new Runnable() { + public void run() { + Log.w(TAG, "Executing delayed write of characteristic"); + executeWriteCharacteristic(gattCharacteristic, valBytes); + } + }, 100); + } } else { - Log.d(TAG, "executeWriteCharacteristic - write initiation failed - waiting, then re-trying"); - mHandler.postDelayed(new Runnable() { - public void run() { - Log.w(TAG, "Executing delayed write of characteristic"); - executeWriteCharacteristic(gattCharacteristic, valBytes); - } - }, 100); + Log.i(TAG,"ExecuteWriteCharacteristic() - gatCharacteristic is null, so not doing anything"); } }