diff --git a/app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java b/app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java index be2f2a8..02d59ca 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java @@ -47,7 +47,10 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.UUID; @@ -68,6 +71,7 @@ public class SdDataSourceBLE extends SdDataSource { private int nRawData = 0; private double[] rawData = new double[MAX_RAW_DATA]; + private double[] rawData3d = new double[MAX_RAW_DATA * 3]; private int mAccFmt = 0; private boolean waitForDescriptorWrite = false; @@ -75,6 +79,7 @@ public class SdDataSourceBLE extends SdDataSource { private static final int STATE_CONNECTING = 1; private static final int STATE_CONNECTED = 2; + /* public final static String ACTION_GATT_CONNECTED = "com.example.bluetooth.le.ACTION_GATT_CONNECTED"; public final static String ACTION_GATT_DISCONNECTED = @@ -85,7 +90,7 @@ public class SdDataSourceBLE extends SdDataSource { "com.example.bluetooth.le.ACTION_DATA_AVAILABLE"; public final static String EXTRA_DATA = "com.example.bluetooth.le.EXTRA_DATA"; - + */ public static String SERV_DEV_INFO = "0000180a-0000-1000-8000-00805f9b34fb"; public static String SERV_HEART_RATE = "0000180d-0000-1000-8000-00805f9b34fb"; @@ -99,8 +104,12 @@ public class SdDataSourceBLE extends SdDataSource { public static String CHAR_OSD_ACC_FMT= "000085e9-0005-1000-8000-00805f9b34fb"; // Valid values are 0: 8 bit vector magnitude scaled so 1g=44 - public static String CHAR_MANUF_NAME = "00002a29-0000-1000-8000-00805f9b34fb"; - public static String CLIENT_CHARACTERISTIC_CONFIG = "00002902-0000-1000-8000-00805f9b34fb"; + public final static int ACC_FMT_8BIT = 0; + public final static int ACC_FMT_16BIT = 1; + public final static int ACC_FMT_3D = 3; + + // public static String CHAR_MANUF_NAME = "00002a29-0000-1000-8000-00805f9b34fb"; + // public static String CLIENT_CHARACTERISTIC_CONFIG = "00002902-0000-1000-8000-00805f9b34fb"; private BluetoothGatt mGatt; private BluetoothGattCharacteristic mOsdChar; @@ -305,7 +314,7 @@ public class SdDataSourceBLE extends SdDataSource { /** - * executeReadCharacteristic runs teh bluetoothGatt readCharacteristic command to read the value + * executeReadCharacteristic runs the bluetoothGatt readCharacteristic command to read the value * of a given characteristic. * 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. @@ -344,7 +353,7 @@ public class SdDataSourceBLE extends SdDataSource { } public void onDataReceived(BluetoothGattCharacteristic characteristic) { - /** + /* * onDataReceived - called whenever a BLE characteristic notifies us that its data has changed. * If the data is acceleration data, we add it to a buffer - it is analysed once the buffer is full. * Heart rate data is written directly to sdData to be used in future analysis. @@ -362,35 +371,64 @@ public class SdDataSourceBLE extends SdDataSource { //Log.d(TAG, "onDataReceived(): Heart rate format UINT8."); } final int heartRate = characteristic.getIntValue(format, 1); // heart rate is second byte - //byte[] rawDataBytes = characteristic.getValue(); - //Log.d(TAG,"onDataReceived - len(rawDataBytes)="+rawDataBytes.length); - //for (int i=0;i