Updated BLE data source to use neater 128 bit UUIDs (compatible with BangleJS v0.11)
This commit is contained in:
@@ -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="128"
|
android:versionCode="128"
|
||||||
android:versionName="4.2.1b">
|
android:versionName="4.2.1e">
|
||||||
<!-- 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" />
|
||||||
|
|||||||
@@ -83,16 +83,17 @@ public class SdDataSourceBLE extends SdDataSource {
|
|||||||
|
|
||||||
public static String SERV_DEV_INFO = "0000180a-0000-1000-8000-00805f9b34fb";
|
public static String SERV_DEV_INFO = "0000180a-0000-1000-8000-00805f9b34fb";
|
||||||
public static String SERV_HEART_RATE = "0000180d-0000-1000-8000-00805f9b34fb";
|
public static String SERV_HEART_RATE = "0000180d-0000-1000-8000-00805f9b34fb";
|
||||||
public static String SERV_OSD = "000085e9-0000-1000-8000-00805f9b34fb";
|
|
||||||
public static String CHAR_HEART_RATE_MEASUREMENT = "00002a37-0000-1000-8000-00805f9b34fb";
|
public static String CHAR_HEART_RATE_MEASUREMENT = "00002a37-0000-1000-8000-00805f9b34fb";
|
||||||
|
|
||||||
|
public static String SERV_OSD = "000085e9-0000-1000-8000-00805f9b34fb";
|
||||||
|
public static String CHAR_OSD_ACC_DATA = "000085e9-0001-1000-8000-00805f9b34fb";
|
||||||
|
public static String CHAR_OSD_BATT_DATA = "000085e9-0002-1000-8000-00805f9b34fb";
|
||||||
|
public static String CHAR_OSD_WATCH_ID = "000085e9-0003-1000-8000-00805f9b34fb";
|
||||||
|
public static String CHAR_OSD_WATCH_FW = "000085e9-0004-1000-8000-00805f9b34fb";
|
||||||
|
|
||||||
public static String CHAR_MANUF_NAME = "00002a29-0000-1000-8000-00805f9b34fb";
|
public static String CHAR_MANUF_NAME = "00002a29-0000-1000-8000-00805f9b34fb";
|
||||||
public static String CLIENT_CHARACTERISTIC_CONFIG = "00002902-0000-1000-8000-00805f9b34fb";
|
public static String CLIENT_CHARACTERISTIC_CONFIG = "00002902-0000-1000-8000-00805f9b34fb";
|
||||||
public static String CHAR_OSD_ACC_DATA = "000085ea-0000-1000-8000-00805f9b34fb";
|
|
||||||
public static String CHAR_OSD_BATT_DATA = "000085eb-0000-1000-8000-00805f9b34fb";
|
|
||||||
|
|
||||||
public final static UUID UUID_HEART_RATE_MEASUREMENT = UUID.fromString(CHAR_HEART_RATE_MEASUREMENT);
|
|
||||||
private BluetoothGatt mGatt;
|
private BluetoothGatt mGatt;
|
||||||
private BluetoothGattCharacteristic mBattChar;
|
|
||||||
private BluetoothGattCharacteristic mOsdChar;
|
private BluetoothGattCharacteristic mOsdChar;
|
||||||
|
|
||||||
|
|
||||||
@@ -263,10 +264,13 @@ public class SdDataSourceBLE extends SdDataSource {
|
|||||||
setCharacteristicNotification(gattCharacteristic,true);
|
setCharacteristicNotification(gattCharacteristic,true);
|
||||||
}
|
}
|
||||||
else if (charUuidStr.equals(CHAR_OSD_BATT_DATA)) {
|
else if (charUuidStr.equals(CHAR_OSD_BATT_DATA)) {
|
||||||
Log.v(TAG,"Saving battery characteristic for later");
|
|
||||||
Log.v(TAG, "Subscribing to battery change Notifications");
|
Log.v(TAG, "Subscribing to battery change Notifications");
|
||||||
setCharacteristicNotification(gattCharacteristic,true);
|
setCharacteristicNotification(gattCharacteristic,true);
|
||||||
}
|
}
|
||||||
|
//else if (charUuidStr.equals(CHAR_OSD_HR_DATA)) {
|
||||||
|
// Log.v(TAG, "Subscribing to HR change Notifications");
|
||||||
|
// setCharacteristicNotification(gattCharacteristic,true);
|
||||||
|
//.}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -288,34 +292,42 @@ public class SdDataSourceBLE extends SdDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onDataReceived(BluetoothGattCharacteristic characteristic) {
|
public void onDataReceived(BluetoothGattCharacteristic characteristic) {
|
||||||
Log.v(TAG, "onDataReceived uuid" + characteristic.getUuid().toString());
|
/**
|
||||||
|
* onDataReceived - called whenever a BLE characteristic notifies us that its data has changed.
|
||||||
// FIXME - collect data until we have enough to do analysis, then use onDataReceived to process it.
|
* 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.
|
||||||
|
*/
|
||||||
//Log.v(TAG,"onDataReceived: Characteristic="+characteristic.getUuid().toString());
|
//Log.v(TAG,"onDataReceived: Characteristic="+characteristic.getUuid().toString());
|
||||||
if (characteristic.getUuid().toString().equals(CHAR_HEART_RATE_MEASUREMENT)) {
|
if (characteristic.getUuid().toString().equals(CHAR_HEART_RATE_MEASUREMENT)) {
|
||||||
int flag = characteristic.getProperties();
|
int flag = characteristic.getProperties();
|
||||||
|
//Log.d(TAG,"onDataReceived() - flag = "+flag);
|
||||||
int format = -1;
|
int format = -1;
|
||||||
if ((flag & 0x01) != 0) {
|
if ((flag & 0x01) != 0) {
|
||||||
format = BluetoothGattCharacteristic.FORMAT_UINT16;
|
format = BluetoothGattCharacteristic.FORMAT_UINT16;
|
||||||
Log.d(TAG, "Heart rate format UINT16.");
|
//Log.d(TAG, "onDataReceived(): Heart rate format UINT16.");
|
||||||
} else {
|
} else {
|
||||||
format = BluetoothGattCharacteristic.FORMAT_UINT8;
|
format = BluetoothGattCharacteristic.FORMAT_UINT8;
|
||||||
Log.d(TAG, "Heart rate format UINT8.");
|
//Log.d(TAG, "onDataReceived(): Heart rate format UINT8.");
|
||||||
}
|
}
|
||||||
final int heartRate = characteristic.getIntValue(format, 1);
|
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<rawDataBytes.length;i++) {
|
||||||
|
// Log.d(TAG,"onDataReceived - HR["+i+" = "+rawDataBytes[i]);
|
||||||
|
//}
|
||||||
mSdData.mHR = (double) heartRate;
|
mSdData.mHR = (double) heartRate;
|
||||||
Log.d(TAG, String.format("Received heart rate: %d", heartRate));
|
Log.d(TAG, String.format("onDataReceived(): CHAR_HEART_RATE_MEASUREMENT: %d", heartRate));
|
||||||
}
|
}
|
||||||
else if (characteristic.getUuid().toString().equals(CHAR_OSD_ACC_DATA)) {
|
else if (characteristic.getUuid().toString().equals(CHAR_OSD_ACC_DATA)) {
|
||||||
//Log.v(TAG,"Received OSD ACC DATA"+characteristic.getValue());
|
//Log.v(TAG,"Received OSD ACC DATA"+characteristic.getValue());
|
||||||
byte[] rawDataBytes = characteristic.getValue();
|
byte[] rawDataBytes = characteristic.getValue();
|
||||||
Log.v(TAG, "CHAR_OSD_ACC_DATA: numSamples = " + rawDataBytes.length+" nRawData="+nRawData);
|
Log.v(TAG, "onDataReceived(): CHAR_OSD_ACC_DATA: numSamples = " + rawDataBytes.length+" nRawData="+nRawData);
|
||||||
for (int i = 0; i < rawDataBytes.length;i++) {
|
for (int i = 0; i < rawDataBytes.length;i++) {
|
||||||
if (nRawData < MAX_RAW_DATA) {
|
if (nRawData < MAX_RAW_DATA) {
|
||||||
rawData[nRawData] = 1000 * rawDataBytes[i] / 64; // Scale to mg
|
rawData[nRawData] = 1000 * rawDataBytes[i] / 64; // Scale to mg
|
||||||
nRawData++;
|
nRawData++;
|
||||||
} else {
|
} else {
|
||||||
Log.i(TAG, "RawData Buffer Full - processing data");
|
Log.i(TAG, "onDataReceived(): RawData Buffer Full - processing data");
|
||||||
// Re-start collecting raw data.
|
// Re-start collecting raw data.
|
||||||
mSdData.watchAppRunning = true;
|
mSdData.watchAppRunning = true;
|
||||||
for (i = 0; i < rawData.length; i++) {
|
for (i = 0; i < rawData.length; i++) {
|
||||||
@@ -334,7 +346,7 @@ public class SdDataSourceBLE extends SdDataSource {
|
|||||||
else if (characteristic.getUuid().toString().equals(CHAR_OSD_BATT_DATA)) {
|
else if (characteristic.getUuid().toString().equals(CHAR_OSD_BATT_DATA)) {
|
||||||
byte batteryPc = characteristic.getValue()[0];
|
byte batteryPc = characteristic.getValue()[0];
|
||||||
mSdData.batteryPc = batteryPc;
|
mSdData.batteryPc = batteryPc;
|
||||||
Log.v(TAG,"Received Battery Data" + String.format("%d", batteryPc));
|
Log.v(TAG,"onDataReceived(): CHAR_OSD_BATT_DATA: " + String.format("%d", batteryPc));
|
||||||
mSdData.haveSettings = true;
|
mSdData.haveSettings = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -356,7 +368,7 @@ public class SdDataSourceBLE extends SdDataSource {
|
|||||||
@Override
|
@Override
|
||||||
public void onCharacteristicChanged(BluetoothGatt gatt,
|
public void onCharacteristicChanged(BluetoothGatt gatt,
|
||||||
BluetoothGattCharacteristic characteristic) {
|
BluetoothGattCharacteristic characteristic) {
|
||||||
Log.v(TAG,"onCharacteristicChanged(): Characteristic "+characteristic.getUuid()+" changed");
|
//Log.v(TAG,"onCharacteristicChanged(): Characteristic "+characteristic.getUuid()+" changed");
|
||||||
onDataReceived(characteristic);
|
onDataReceived(characteristic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user