V4.2.4 - fault rather than crash if bluetooth system crashes.

This commit is contained in:
Graham Jones
2024-03-26 21:12:13 +00:00
parent fb59ec6db6
commit ba9b092147
5 changed files with 57 additions and 34 deletions

View File

@@ -1,6 +1,7 @@
OpenSeizureDetector Android App - Change Log OpenSeizureDetector Android App - Change Log
============================================ ============================================
V4.2.4 - Added checks and a FAULT condition for Bluetooth errors in Bluetooth Data Source
V4.2.3 - Uses 3d accelerometer data to calculate magnitude if vector magnitude is not sent from data source. V4.2.3 - Uses 3d accelerometer data to calculate magnitude if vector magnitude is not sent from data source.
- fixed latched alarms (Issue #146) - fixed latched alarms (Issue #146)
- fixed HR alarms selection issue (#153) - fixed HR alarms selection issue (#153)

View File

@@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:versionCode="138" android:versionCode="138"
android:versionName="4.2.4b"> android:versionName="4.2.4">
<!-- android:allowBackup="false" --> <!-- android:allowBackup="false" -->
<uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

View File

@@ -368,21 +368,31 @@ public class SdDataSourceBLE extends SdDataSource {
* @param gattCharacteristic - the characteristic to be read. * @param gattCharacteristic - the characteristic to be read.
*/ */
private void executeReadCharacteristic(BluetoothGattCharacteristic gattCharacteristic) { private void executeReadCharacteristic(BluetoothGattCharacteristic gattCharacteristic) {
if (gattCharacteristic != null) { if (gattCharacteristic == null) {
boolean retVal = mBluetoothGatt.readCharacteristic(gattCharacteristic); Log.i(TAG, "ExecuteReadCharacteristic() - gatCharacteristic is null, so not doing anything");
if (retVal) { mUtil.showToast("ERROR: gatCharacteristic is null - this should not happen");
Log.d(TAG, "executeReadCharacteristic - read initiated successfully"); mSdDataReceiver.onSdDataFault(mSdData);
} else { return;
Log.d(TAG, "executeReadCharacteristic - read initiation failed - waiting, then re-trying"); }
mHandler.postDelayed(new Runnable() { if (mBluetoothGatt == null) {
public void run() { Log.e(TAG, "executeReadCharacteristic() - mBluetoothGatt is null - Characteristic=" + gattCharacteristic.getUuid().toString());
Log.w(TAG, "Executing delayed read of characteristic"); mUtil.showToast("ERROR: mGatCharacteristic is null - this should not happen");
executeReadCharacteristic(gattCharacteristic); mSdDataReceiver.onSdDataFault(mSdData);
} return;
}, 100); }
}
// To get here both gatCharacteristic and mBluetoothGatt must be non-null
boolean retVal = mBluetoothGatt.readCharacteristic(gattCharacteristic);
if (retVal) {
Log.d(TAG, "executeReadCharacteristic - read initiated successfully");
} else { } else {
Log.i(TAG,"ExecuteReadCharacteristic() - gatCharacteristic is null, so not doing anything"); Log.d(TAG, "executeReadCharacteristic - read initiation failed - waiting, then re-trying");
mHandler.postDelayed(new Runnable() {
public void run() {
Log.w(TAG, "Executing delayed read of characteristic");
executeReadCharacteristic(gattCharacteristic);
}
}, 100);
} }
} }
@@ -391,27 +401,38 @@ public class SdDataSourceBLE extends SdDataSource {
* of a given characteristic. * of a given characteristic.
* Because only one BLE operation can be taking place at a time, it may fail, in which case * Because only one BLE operation can be taking place at a time, it may fail, in which case
* the read is re-tried after a 100ms delay. * the read is re-tried after a 100ms delay.
*
* @param gattCharacteristic - the characteristic to be read. * @param gattCharacteristic - the characteristic to be read.
* @param valBytes[] - array of bytes to send * @param valBytes[] - array of bytes to send
* @param nBytes - number of bytes to send. * @param nBytes - number of bytes to send.
*/ */
private void executeWriteCharacteristic(BluetoothGattCharacteristic gattCharacteristic, byte[] valBytes) { private void executeWriteCharacteristic(BluetoothGattCharacteristic gattCharacteristic, byte[] valBytes) {
if (gattCharacteristic != null) { if (gattCharacteristic == null) {
gattCharacteristic.setValue(valBytes); Log.i(TAG, "ExecuteWriteCharacteristic() - gatCharacteristic is null, so not doing anything");
boolean retVal = mBluetoothGatt.writeCharacteristic(gattCharacteristic); mUtil.showToast("ERROR: gatCharacteristic is null - this should not happen");
if (retVal) { mSdDataReceiver.onSdDataFault(mSdData);
Log.d(TAG, "executeWriteCharacteristic - write initiated successfully"); return;
} else { }
Log.d(TAG, "executeWriteCharacteristic - write initiation failed - waiting, then re-trying"); if (mBluetoothGatt == null) {
mHandler.postDelayed(new Runnable() { Log.e(TAG, "executeWriteCharacteristic() - mBluetoothGatt is null - Characteristic=" + gattCharacteristic.getUuid().toString());
public void run() { mUtil.showToast("ERROR: mGatCharacteristic is null - this should not happen");
Log.w(TAG, "Executing delayed write of characteristic"); mSdDataReceiver.onSdDataFault(mSdData);
executeWriteCharacteristic(gattCharacteristic, valBytes); return;
} }
}, 100);
} // To get here both gatCharacteristic and mBluetoothGatt must be non-null
gattCharacteristic.setValue(valBytes);
boolean retVal = mBluetoothGatt.writeCharacteristic(gattCharacteristic);
if (retVal) {
Log.d(TAG, "executeWriteCharacteristic - write initiated successfully");
} else { } else {
Log.i(TAG,"ExecuteWriteCharacteristic() - gatCharacteristic is null, so not doing anything"); 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);
} }
} }

View File

@@ -2,8 +2,9 @@
<resources> <resources>
<string name="app_name">OpenSeizureDetector</string> <string name="app_name">OpenSeizureDetector</string>
<string name="changelog"> <string name="changelog">
"\n "\nV4.2.4 - Fault alarm rather than crash if bluetooth system crashes.
\nV4.2.1 - Added support for PineTime Watches using Bluetooth data source. \nV4.2.3 - Bug Fixes (heart rate alarm and latched alarm issues)
\nV4.2 - Added support for PineTime Watches using Bluetooth data source.
\n - Added new, swipeable user interface to simplify the main screen.. \n - Added new, swipeable user interface to simplify the main screen..
"</string> "</string>
<string name="UpgradeMsg"> <string name="UpgradeMsg">