Added extra debugging information to log file in the event of an exception during analysis.

This commit is contained in:
Graham Jones
2020-11-06 13:39:44 +00:00
parent 7f368b3655
commit 36285f0d09
5 changed files with 147 additions and 118 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -11,8 +11,8 @@
"type": "SINGLE", "type": "SINGLE",
"filters": [], "filters": [],
"properties": [], "properties": [],
"versionCode": 79, "versionCode": 80,
"versionName": "3.6.1f", "versionName": "3.6.1g",
"enabled": true, "enabled": true,
"outputFile": "app-release.apk" "outputFile": "app-release.apk"
} }

View File

@@ -2,8 +2,8 @@
<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"
package="uk.org.openseizuredetector" package="uk.org.openseizuredetector"
android:versionCode="79" android:versionCode="80"
android:versionName="3.6.1f"> android:versionName="3.6.1g">
<!-- 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

@@ -45,6 +45,7 @@ import java.util.TimerTask;
interface SdDataReceiver { interface SdDataReceiver {
public void onSdDataReceived(SdData sdData); public void onSdDataReceived(SdData sdData);
public void onSdDataFault(SdData sdData); public void onSdDataFault(SdData sdData);
} }
@@ -97,7 +98,6 @@ public abstract class SdDataSource {
private int ACCEL_SCALE_FACTOR = 1000; // Amount by which to reduce analysis results to scale to be comparable to analysis on Pebble. private int ACCEL_SCALE_FACTOR = 1000; // Amount by which to reduce analysis results to scale to be comparable to analysis on Pebble.
private int mAlarmCount; private int mAlarmCount;
protected String mBleDeviceAddr; protected String mBleDeviceAddr;
protected String mBleDeviceName; protected String mBleDeviceName;
@@ -114,6 +114,7 @@ public abstract class SdDataSource {
/** /**
* Returns the SdData object stored by this class. * Returns the SdData object stored by this class.
*
* @return * @return
*/ */
public SdData getSdData() { public SdData getSdData() {
@@ -233,9 +234,13 @@ public abstract class SdDataSource {
} }
} }
public void startPebbleApp() { Log.v(TAG,"startPebbleApp()"); } public void startPebbleApp() {
Log.v(TAG, "startPebbleApp()");
}
public void acceptAlarm() { Log.v(TAG,"acceptAlarm()"); } public void acceptAlarm() {
Log.v(TAG, "acceptAlarm()");
}
// Force the data stored in this datasource to update in line with the JSON string encoded data provided. // Force the data stored in this datasource to update in line with the JSON string encoded data provided.
// Used by webServer to update the GarminDatasource. // Used by webServer to update the GarminDatasource.
@@ -246,6 +251,7 @@ public abstract class SdDataSource {
String watchFwVersion; String watchFwVersion;
String sdVersion; String sdVersion;
String sdName; String sdName;
JSONArray accelVals = null;
Log.v(TAG, "updateFromJSON - " + jsonStr); Log.v(TAG, "updateFromJSON - " + jsonStr);
try { try {
@@ -268,8 +274,12 @@ public abstract class SdDataSource {
// if we get 'null' HR (For example if the heart rate is not working) // if we get 'null' HR (For example if the heart rate is not working)
mMute = 0; mMute = 0;
} }
JSONArray accelVals = dataObject.getJSONArray("data"); accelVals = dataObject.getJSONArray("data");
Log.v(TAG, "Received " + accelVals.length() + " acceleration values"); Log.v(TAG, "Received " + accelVals.length() + " acceleration values, rawData Length is " + mSdData.rawData.length);
if (accelVals.length() > mSdData.rawData.length) {
mUtil.writeToSysLogFile("ERROR: Received " + accelVals.length() + " acceleration values, but rawData storage length is "
+ mSdData.rawData.length);
}
int i; int i;
for (i = 0; i < accelVals.length(); i++) { for (i = 0; i < accelVals.length(); i++) {
mSdData.rawData[i] = accelVals.getInt(i); mSdData.rawData[i] = accelVals.getInt(i);
@@ -318,6 +328,11 @@ public abstract class SdDataSource {
Log.e(TAG, "updateFromJSON - Error Parsing JSON String - " + jsonStr + " - " + e.toString()); Log.e(TAG, "updateFromJSON - Error Parsing JSON String - " + jsonStr + " - " + e.toString());
mUtil.writeToSysLogFile("updateFromJSON - Error Parsing JSON String - " + jsonStr + " - " + e.toString()); mUtil.writeToSysLogFile("updateFromJSON - Error Parsing JSON String - " + jsonStr + " - " + e.toString());
mUtil.writeToSysLogFile("updateFromJSON: Exception at Line Number: " + e.getCause().getStackTrace()[0].getLineNumber() + ", " + e.getCause().getStackTrace()[0].toString()); mUtil.writeToSysLogFile("updateFromJSON: Exception at Line Number: " + e.getCause().getStackTrace()[0].getLineNumber() + ", " + e.getCause().getStackTrace()[0].toString());
if (accelVals == null) {
mUtil.writeToSysLogFile("updateFromJSON: accelVals is null when exception thrown");
} else {
mUtil.writeToSysLogFile("updateFromJSON: Received " + accelVals.length() + " acceleration values");
}
e.printStackTrace(); e.printStackTrace();
retVal = "ERROR"; retVal = "ERROR";
} }
@@ -326,6 +341,7 @@ public abstract class SdDataSource {
/** /**
* Calculate the magnitude of entry i in the fft array fft * Calculate the magnitude of entry i in the fft array fft
*
* @param fft * @param fft
* @param i * @param i
* @return magnitude ( Re*Re + Im*Im ) * @return magnitude ( Re*Re + Im*Im )
@@ -341,21 +357,26 @@ public abstract class SdDataSource {
* and populate the output data structure mSdData * and populate the output data structure mSdData
*/ */
protected void doAnalysis() { protected void doAnalysis() {
int nMin = 0;
int nMax = 0;
int nFreqCutoff = 0;
double[] fft = null;
try {
// FIXME - Use specified sampleFreq, not this hard coded one // FIXME - Use specified sampleFreq, not this hard coded one
mSampleFreq = 25; mSampleFreq = 25;
double freqRes = 1.0 * mSampleFreq / mSdData.mNsamp; double freqRes = 1.0 * mSampleFreq / mSdData.mNsamp;
Log.v(TAG, "doAnalysis(): mSampleFreq=" + mSampleFreq + " mNSamp=" + mSdData.mNsamp + ": freqRes=" + freqRes); Log.v(TAG, "doAnalysis(): mSampleFreq=" + mSampleFreq + " mNSamp=" + mSdData.mNsamp + ": freqRes=" + freqRes);
// Set the frequency bounds for the analysis in fft output bin numbers. // Set the frequency bounds for the analysis in fft output bin numbers.
int nMin = (int)(mAlarmFreqMin/freqRes); nMin = (int) (mAlarmFreqMin / freqRes);
int nMax = (int)(mAlarmFreqMax /freqRes); nMax = (int) (mAlarmFreqMax / freqRes);
Log.v(TAG, "doAnalysis(): mAlarmFreqMin=" + mAlarmFreqMin + ", nMin=" + nMin Log.v(TAG, "doAnalysis(): mAlarmFreqMin=" + mAlarmFreqMin + ", nMin=" + nMin
+ ", mAlarmFreqMax=" + mAlarmFreqMax + ", nMax=" + nMax); + ", mAlarmFreqMax=" + mAlarmFreqMax + ", nMax=" + nMax);
// Calculate the bin number of the cutoff frequency // Calculate the bin number of the cutoff frequency
int nFreqCutoff = (int)(mFreqCutoff /freqRes); nFreqCutoff = (int) (mFreqCutoff / freqRes);
Log.v(TAG, "mFreqCutoff = " + mFreqCutoff + ", nFreqCutoff=" + nFreqCutoff); Log.v(TAG, "mFreqCutoff = " + mFreqCutoff + ", nFreqCutoff=" + nFreqCutoff);
DoubleFFT_1D fftDo = new DoubleFFT_1D(mSdData.mNsamp); DoubleFFT_1D fftDo = new DoubleFFT_1D(mSdData.mNsamp);
double[] fft = new double[mSdData.mNsamp * 2]; fft = new double[mSdData.mNsamp * 2];
///System.arraycopy(mAccData, 0, fft, 0, mNsamp); ///System.arraycopy(mAccData, 0, fft, 0, mNsamp);
System.arraycopy(mSdData.rawData, 0, fft, 0, mSdData.mNsamp); System.arraycopy(mSdData.rawData, 0, fft, 0, mSdData.mNsamp);
fftDo.realForward(fft); fftDo.realForward(fft);
@@ -417,6 +438,17 @@ public abstract class SdDataSource {
// Because we have received data, set flag to show watch app running. // Because we have received data, set flag to show watch app running.
mWatchAppRunningCheck = true; mWatchAppRunningCheck = true;
} catch (Exception e) {
Log.e(TAG, "doAnalysis - Exception during Analysis");
mUtil.writeToSysLogFile("doAnalysis - Exception during analysis - " + e.toString());
mUtil.writeToSysLogFile("doAnalysis: Exception at Line Number: " + e.getCause().getStackTrace()[0].getLineNumber() + ", " + e.getCause().getStackTrace()[0].toString());
mUtil.writeToSysLogFile("doAnalysis: mSdData.mNsamp="+mSdData.mNsamp);
mUtil.writeToSysLogFile("doAnalysis: alarmFreqMin="+mAlarmFreqMin+" nMin="+nMin);
mUtil.writeToSysLogFile("doAnalysis: alarmFreqMax="+mAlarmFreqMax+" nMax="+nMax);
mUtil.writeToSysLogFile("doAnalysis: nFreqCutoff.="+nFreqCutoff);
mUtil.writeToSysLogFile("doAnalysis: fft.length="+fft.length);
mWatchAppRunningCheck = false;
}
// Check this data to see if it represents an alarm state. // Check this data to see if it represents an alarm state.
alarmCheck(); alarmCheck();
@@ -500,13 +532,11 @@ public abstract class SdDataSource {
mSdData.mHRFaultStanding = true; mSdData.mHRFaultStanding = true;
mSdData.mHRAlarmStanding = false; mSdData.mHRAlarmStanding = false;
} }
} } else if ((mSdData.mHR > mSdData.mHRThreshMax) || (mSdData.mHR < mSdData.mHRThreshMin)) {
else if ((mSdData.mHR > mSdData.mHRThreshMax) || (mSdData.mHR < mSdData.mHRThreshMin)) {
Log.i(TAG, "Heart Rate Abnormal - " + mSdData.mHR + " bpm"); Log.i(TAG, "Heart Rate Abnormal - " + mSdData.mHR + " bpm");
mSdData.mHRFaultStanding = false; mSdData.mHRFaultStanding = false;
mSdData.mHRAlarmStanding = true; mSdData.mHRAlarmStanding = true;
} } else {
else {
mSdData.mHRFaultStanding = false; mSdData.mHRFaultStanding = false;
mSdData.mHRAlarmStanding = false; mSdData.mHRAlarmStanding = false;
} }
@@ -770,9 +800,9 @@ public abstract class SdDataSource {
} }
/** /**
* Display a Toast message on screen. * Display a Toast message on screen.
*
* @param msg - message to display. * @param msg - message to display.
*/ */
public void showToast(String msg) { public void showToast(String msg) {
@@ -781,7 +811,6 @@ public abstract class SdDataSource {
} }
public class SdDataBroadcastReceiver extends BroadcastReceiver { public class SdDataBroadcastReceiver extends BroadcastReceiver {
//private String TAG = "SdDataBroadcastReceiver"; //private String TAG = "SdDataBroadcastReceiver";