diff --git a/CHANGELOG.md b/CHANGELOG.md index ddf7a8b..4da1019 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ OpenSeizureDetector Android App - Change Log ============================================ - V3.0.0 - 15feb2019 + V3.0.1 - 21feb201 + - Simplified data log output to CSV format for easier processing, and had it log every update rather than one point per minute. + + V3.0.0 - 15feb2019 - Updated for Android V9 - Added explicity statement of use of SMS permission in notification - Updated to use dynamic permissions diff --git a/app/release/app-release-3.0.1.apk b/app/release/app-release-3.0.1.apk new file mode 100644 index 0000000..a11561c Binary files /dev/null and b/app/release/app-release-3.0.1.apk differ diff --git a/app/release/output.json b/app/release/output.json index d8960b4..d0af5c2 100644 --- a/app/release/output.json +++ b/app/release/output.json @@ -1 +1 @@ -[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":49,"versionName":"3.0.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] \ No newline at end of file +[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":50,"versionName":"3.0.1","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f3b1ca7..dc68e49 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,8 +1,8 @@ diff --git a/app/src/main/java/uk/org/openseizuredetector/SdData.java b/app/src/main/java/uk/org/openseizuredetector/SdData.java index d8a3cbb..1a3b720 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdData.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdData.java @@ -68,7 +68,8 @@ public class SdData implements Parcelable { public boolean mHRAlarmActive = false; public double mHRThreshMin = 40.0; public double mHRTreshMax = 150.0; - public int rawData[]; + public double rawData[]; + int mNsamp = 0; /* Analysis results */ public Time dataTime = null; @@ -90,7 +91,7 @@ public class SdData implements Parcelable { public SdData() { simpleSpec = new int[10]; - rawData = new int[N_RAW_DATA]; + rawData = new double[N_RAW_DATA]; dataTime = new Time(Time.getCurrentTimezone()); } @@ -192,6 +193,30 @@ public class SdData implements Parcelable { return (retval); } + + public String toCSVString(boolean includeRawData) { + String retval; + retval = ""; + if (dataTime != null) { + retval = dataTime.format("%d-%m-%Y %H:%M:%S"); + }else{ + retval = "00-00-00 00:00:00"; + } + for (int i = 0; i < simpleSpec.length; i++) { + retval = retval + ", " + simpleSpec[i]; + } + retval = retval + ", " + specPower; + retval = retval + ", " + roiPower; + retval = retval + ", " + mSampleFreq; + retval = retval + ", " + alarmPhrase; + if (includeRawData) { + for (int i = 0; i< mNsamp;i++) { + retval = retval + ", " + rawData[i]; + } + } + return(retval); + } + public int describeContents() { return 0; } diff --git a/app/src/main/java/uk/org/openseizuredetector/SdDataSourceGarmin.java b/app/src/main/java/uk/org/openseizuredetector/SdDataSourceGarmin.java index 87dc164..7d43df6 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdDataSourceGarmin.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdDataSourceGarmin.java @@ -108,12 +108,6 @@ public class SdDataSourceGarmin extends SdDataSource { private int mAlarmCount; - // raw data storage for SD_MODE_RAW - private int MAX_RAW_DATA = 500; - public double[] mAccData = new double[MAX_RAW_DATA]; - int mNSamp = 0; - - public SdDataSourceGarmin(Context context, Handler handler, SdDataReceiver sdDataReceiver) { super(context, handler, sdDataReceiver); @@ -386,9 +380,10 @@ public class SdDataSourceGarmin extends SdDataSource { Log.v(TAG, "Received " + accelVals.length() + " acceleration values"); int i; for (i = 0; i < accelVals.length(); i++) { - mAccData[i] = accelVals.getInt(i); + mSdData.rawData[i] = accelVals.getInt(i); } - mNSamp = accelVals.length(); + mSdData.mNsamp = accelVals.length(); + //mNSamp = accelVals.length(); mWatchAppRunningCheck = true; doAnalysis(); if (mSdData.haveSettings == false) { @@ -437,8 +432,8 @@ public class SdDataSourceGarmin extends SdDataSource { private void doAnalysis() { // FIXME - Use specified sampleFreq, not this hard coded one mSampleFreq = 25; - double freqRes = 1.0*mSampleFreq/mNSamp; - Log.v(TAG,"doAnalysis(): mSampleFreq="+mSampleFreq+" mNSamp="+mNSamp+": freqRes="+freqRes); + double freqRes = 1.0*mSampleFreq/mSdData.mNsamp; + Log.v(TAG,"doAnalysis(): mSampleFreq="+mSampleFreq+" mNSamp="+mSdData.mNsamp+": freqRes="+freqRes); // Set the frequency bounds for the analysis in fft output bin numbers. int nMin = (int)(mAlarmFreqMin/freqRes); int nMax = (int)(mAlarmFreqMax /freqRes); @@ -448,15 +443,16 @@ public class SdDataSourceGarmin extends SdDataSource { int nFreqCutoff = (int)(mFreqCutoff /freqRes); Log.v(TAG,"mFreqCutoff = "+mFreqCutoff+", nFreqCutoff="+nFreqCutoff); - DoubleFFT_1D fftDo = new DoubleFFT_1D(mNSamp); - double[] fft = new double[mNSamp * 2]; - System.arraycopy(mAccData, 0, fft, 0, mNSamp); + DoubleFFT_1D fftDo = new DoubleFFT_1D(mSdData.mNsamp); + double[] fft = new double[mSdData.mNsamp * 2]; + ///System.arraycopy(mAccData, 0, fft, 0, mNsamp); + System.arraycopy(mSdData.rawData, 0, fft, 0, mSdData.mNsamp); fftDo.realForward(fft); // Calculate the whole spectrum power (well a value equivalent to it that avoids square root calculations // and zero any readings that are above the frequency cutoff. double specPower = 0; - for (int i = 1; i < mNSamp / 2; i++) { + for (int i = 1; i < mSdData.mNsamp / 2; i++) { if (i <= nFreqCutoff) { specPower = specPower + getMagnitude(fft,i); } else { @@ -464,7 +460,7 @@ public class SdDataSourceGarmin extends SdDataSource { fft[2*i+1] = 0.; } } - specPower = specPower/mNSamp/2; + specPower = specPower/mSdData.mNsamp/2; // Calculate the Region of Interest power and power ratio. double roiPower = 0; @@ -622,22 +618,6 @@ public class SdDataSourceGarmin extends SdDataSource { } } - private void makeTestData() { - int sampleFreq = 25; // Hz - int samplePeriod = 5; // sec - int accDataPos = 0; - - double signalFreq = 5; // Hz - double signalAmp = 500; // mG - - for (int i = 0; i < samplePeriod * sampleFreq; i++) { - double t = 1.0*i / sampleFreq; - double r = 2.0*Math.PI*t*signalFreq; - mAccData[accDataPos] = (signalAmp*(Math.sin(r))); - Log.v(TAG, "i=" + i + ", t="+t+", r="+r+", a="+ mAccData[accDataPos]); - accDataPos++; - } - } public class SdDataBroadcastReceiver extends BroadcastReceiver { //private String TAG = "SdDataBroadcastReceiver"; diff --git a/app/src/main/java/uk/org/openseizuredetector/SdServer.java b/app/src/main/java/uk/org/openseizuredetector/SdServer.java index 51d8118..d7948ad 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdServer.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdServer.java @@ -269,13 +269,15 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei if (dataLogTimer == null) { Log.v(TAG, "onStartCommand(): starting dataLog timer"); mUtil.writeToSysLogFile("SdServer.onStartCommand() - starting dataLog timer"); - dataLogTimer = new Timer(); + /*dataLogTimer = new Timer(); dataLogTimer.schedule(new TimerTask() { @Override public void run() { + Log.v(TAG,"dataLogTimer.run()"); logData(); } }, 0, 1000 * 60); + */ } else { Log.v(TAG, "onStartCommand(): dataLog timer already running."); mUtil.writeToSysLogFile("SdServer.onStartCommand() - dataLog timer already running???"); @@ -340,14 +342,14 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei stopLatchTimer(); // Stop the status timer - if (dataLogTimer != null) { + /*if (dataLogTimer != null) { Log.v(TAG, "stop(): cancelling Data logger timer"); mUtil.writeToSysLogFile("onDestroy() - cancelling data log timer"); dataLogTimer.cancel(); dataLogTimer.purge(); dataLogTimer = null; } - + */ try { @@ -489,7 +491,6 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei if (mLogAlarms) { Log.v(TAG, "WARNING - Logging to SD Card"); writeAlarmToSD(); - logData(); } else { Log.v(TAG, "WARNING"); } @@ -503,7 +504,6 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei if (mLogAlarms) { Log.v(TAG, "***ALARM*** - Logging to SD Card"); writeAlarmToSD(); - logData(); } else { Log.v(TAG, "***ALARM***"); } @@ -533,7 +533,6 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei if (mLogAlarms) { Log.v(TAG, "***FALL*** - Logging to SD Card"); writeAlarmToSD(); - logData(); showNotification(2); } else { Log.v(TAG, "***FALL***"); @@ -561,7 +560,6 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei if (mLogAlarms) { Log.v(TAG, "***HEART RATE*** - Logging to SD Card"); writeAlarmToSD(); - logData(); } else { Log.v(TAG, "***HEART RATE***"); } @@ -597,6 +595,8 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei mSdData = sdData; if (webServer != null) webServer.setSdData(mSdData); Log.v(TAG, "onSdDataReceived() - setting mSdData to " + mSdData.toString()); + + logData(); } // Called by SdDataSource when a fault condition is detected. @@ -1096,7 +1096,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei * in which case writes to alarm log file. */ public void writeToSD(boolean alarm) { - Log.v(TAG, "writeToSD(" + alarm + ")"); + //Log.v(TAG, "writeToSD(" + alarm + ")"); Time tnow = new Time(Time.getCurrentTimezone()); tnow.setToNow(); String dateStr = tnow.format("%Y-%m-%d"); @@ -1115,8 +1115,13 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei FileWriter of = new FileWriter(mUtil.getDataStorageDir().toString() + "/" + fname, true); if (mSdData != null) { - Log.v(TAG, "writing mSdData.toString()"); - of.append(mSdData.toString() + "\n"); + if (alarm) { + //Log.v(TAG, "writeToSD() - logging mSdData.toString()"); + of.append(mSdData.toString() + "\n"); + } else { + //Log.v(TAG, "writeToSD() - logging mSdData.toCSVString()"); + of.append(mSdData.toCSVString(true) + "\n"); + } } of.close(); } catch (Exception ex) {