Skip to content

Commit ba9b092

Browse files
committed
V4.2.4 - fault rather than crash if bluetooth system crashes.
1 parent fb59ec6 commit ba9b092

5 files changed

Lines changed: 57 additions & 34 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
OpenSeizureDetector Android App - Change Log
22
============================================
33

4+
V4.2.4 - Added checks and a FAULT condition for Bluetooth errors in Bluetooth Data Source
45
V4.2.3 - Uses 3d accelerometer data to calculate magnitude if vector magnitude is not sent from data source.
56
- fixed latched alarms (Issue #146)
67
- fixed HR alarms selection issue (#153)

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
44
android:versionCode="138"
5-
android:versionName="4.2.4b">
5+
android:versionName="4.2.4">
66
<!-- android:allowBackup="false" -->
77
<uses-permission android:name="android.permission.BLUETOOTH" />
88
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java

Lines changed: 52 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -368,21 +368,31 @@ public void run() {
368368
* @param gattCharacteristic - the characteristic to be read.
369369
*/
370370
private void executeReadCharacteristic(BluetoothGattCharacteristic gattCharacteristic) {
371-
if (gattCharacteristic != null) {
372-
boolean retVal = mBluetoothGatt.readCharacteristic(gattCharacteristic);
373-
if (retVal) {
374-
Log.d(TAG, "executeReadCharacteristic - read initiated successfully");
375-
} else {
376-
Log.d(TAG, "executeReadCharacteristic - read initiation failed - waiting, then re-trying");
377-
mHandler.postDelayed(new Runnable() {
378-
public void run() {
379-
Log.w(TAG, "Executing delayed read of characteristic");
380-
executeReadCharacteristic(gattCharacteristic);
381-
}
382-
}, 100);
383-
}
371+
if (gattCharacteristic == null) {
372+
Log.i(TAG, "ExecuteReadCharacteristic() - gatCharacteristic is null, so not doing anything");
373+
mUtil.showToast("ERROR: gatCharacteristic is null - this should not happen");
374+
mSdDataReceiver.onSdDataFault(mSdData);
375+
return;
376+
}
377+
if (mBluetoothGatt == null) {
378+
Log.e(TAG, "executeReadCharacteristic() - mBluetoothGatt is null - Characteristic=" + gattCharacteristic.getUuid().toString());
379+
mUtil.showToast("ERROR: mGatCharacteristic is null - this should not happen");
380+
mSdDataReceiver.onSdDataFault(mSdData);
381+
return;
382+
}
383+
384+
// To get here both gatCharacteristic and mBluetoothGatt must be non-null
385+
boolean retVal = mBluetoothGatt.readCharacteristic(gattCharacteristic);
386+
if (retVal) {
387+
Log.d(TAG, "executeReadCharacteristic - read initiated successfully");
384388
} else {
385-
Log.i(TAG,"ExecuteReadCharacteristic() - gatCharacteristic is null, so not doing anything");
389+
Log.d(TAG, "executeReadCharacteristic - read initiation failed - waiting, then re-trying");
390+
mHandler.postDelayed(new Runnable() {
391+
public void run() {
392+
Log.w(TAG, "Executing delayed read of characteristic");
393+
executeReadCharacteristic(gattCharacteristic);
394+
}
395+
}, 100);
386396
}
387397
}
388398

@@ -391,27 +401,38 @@ public void run() {
391401
* of a given characteristic.
392402
* Because only one BLE operation can be taking place at a time, it may fail, in which case
393403
* the read is re-tried after a 100ms delay.
404+
*
394405
* @param gattCharacteristic - the characteristic to be read.
395-
* @param valBytes[] - array of bytes to send
396-
* @param nBytes - number of bytes to send.
406+
* @param valBytes[] - array of bytes to send
407+
* @param nBytes - number of bytes to send.
397408
*/
398409
private void executeWriteCharacteristic(BluetoothGattCharacteristic gattCharacteristic, byte[] valBytes) {
399-
if (gattCharacteristic != null) {
400-
gattCharacteristic.setValue(valBytes);
401-
boolean retVal = mBluetoothGatt.writeCharacteristic(gattCharacteristic);
402-
if (retVal) {
403-
Log.d(TAG, "executeWriteCharacteristic - write initiated successfully");
404-
} else {
405-
Log.d(TAG, "executeWriteCharacteristic - write initiation failed - waiting, then re-trying");
406-
mHandler.postDelayed(new Runnable() {
407-
public void run() {
408-
Log.w(TAG, "Executing delayed write of characteristic");
409-
executeWriteCharacteristic(gattCharacteristic, valBytes);
410-
}
411-
}, 100);
412-
}
410+
if (gattCharacteristic == null) {
411+
Log.i(TAG, "ExecuteWriteCharacteristic() - gatCharacteristic is null, so not doing anything");
412+
mUtil.showToast("ERROR: gatCharacteristic is null - this should not happen");
413+
mSdDataReceiver.onSdDataFault(mSdData);
414+
return;
415+
}
416+
if (mBluetoothGatt == null) {
417+
Log.e(TAG, "executeWriteCharacteristic() - mBluetoothGatt is null - Characteristic=" + gattCharacteristic.getUuid().toString());
418+
mUtil.showToast("ERROR: mGatCharacteristic is null - this should not happen");
419+
mSdDataReceiver.onSdDataFault(mSdData);
420+
return;
421+
}
422+
423+
// To get here both gatCharacteristic and mBluetoothGatt must be non-null
424+
gattCharacteristic.setValue(valBytes);
425+
boolean retVal = mBluetoothGatt.writeCharacteristic(gattCharacteristic);
426+
if (retVal) {
427+
Log.d(TAG, "executeWriteCharacteristic - write initiated successfully");
413428
} else {
414-
Log.i(TAG,"ExecuteWriteCharacteristic() - gatCharacteristic is null, so not doing anything");
429+
Log.d(TAG, "executeWriteCharacteristic - write initiation failed - waiting, then re-trying");
430+
mHandler.postDelayed(new Runnable() {
431+
public void run() {
432+
Log.w(TAG, "Executing delayed write of characteristic");
433+
executeWriteCharacteristic(gattCharacteristic, valBytes);
434+
}
435+
}, 100);
415436
}
416437
}
417438

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
<resources>
33
<string name="app_name">OpenSeizureDetector</string>
44
<string name="changelog">
5-
"\n
6-
\nV4.2.1 - Added support for PineTime Watches using Bluetooth data source.
5+
"\nV4.2.4 - Fault alarm rather than crash if bluetooth system crashes.
6+
\nV4.2.3 - Bug Fixes (heart rate alarm and latched alarm issues)
7+
\nV4.2 - Added support for PineTime Watches using Bluetooth data source.
78
\n - Added new, swipeable user interface to simplify the main screen..
89
"</string>
910
<string name="UpgradeMsg">

0 commit comments

Comments
 (0)