From 54b29534cdc95ac0b2d81e4140d91a75bb1aa916 Mon Sep 17 00:00:00 2001 From: Aleksander Nowakowski Date: Tue, 19 Jun 2018 16:43:21 +0200 Subject: [PATCH 1/4] #51 fixed --- .../android/nrftoolbox/cgms/CGMSManager.java | 88 +++++----- .../nrftoolbox/gls/GlucoseManager.java | 156 +++++++++--------- .../proximity/ProximityManager.java | 5 +- 3 files changed, 128 insertions(+), 121 deletions(-) diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/cgms/CGMSManager.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/cgms/CGMSManager.java index 3a740fe9..6667763e 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/cgms/CGMSManager.java +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/cgms/CGMSManager.java @@ -71,13 +71,15 @@ public class CGMSManager extends BleManager { private final static int OPERATOR_LAST_RECORD = 6; /** - * The filter type is used for range operators ({@link #OPERATOR_LESS_THEN_OR_EQUAL}, {@link #OPERATOR_GREATER_THEN_OR_EQUAL}, {@link #OPERATOR_WITHING_RANGE}.
+ * The filter type is used for range operators ({@link #OPERATOR_LESS_THEN_OR_EQUAL}, + * {@link #OPERATOR_GREATER_THEN_OR_EQUAL}, {@link #OPERATOR_WITHING_RANGE}.
* The syntax of the operand is: [Filter Type][Minimum][Maximum].
* This filter selects the records by the sequence number. */ private final static int FILTER_TYPE_SEQUENCE_NUMBER = 1; /** - * The filter type is used for range operators ({@link #OPERATOR_LESS_THEN_OR_EQUAL}, {@link #OPERATOR_GREATER_THEN_OR_EQUAL}, {@link #OPERATOR_WITHING_RANGE}.
+ * The filter type is used for range operators ({@link #OPERATOR_LESS_THEN_OR_EQUAL}, + * {@link #OPERATOR_GREATER_THEN_OR_EQUAL}, {@link #OPERATOR_WITHING_RANGE}.
* The syntax of the operand is: [Filter Type][Minimum][Maximum].
* This filter selects the records by the user facing time (base time + offset time). */ @@ -219,8 +221,7 @@ public class CGMSManager extends BleManager { // Request the records if (number > 0) { final BluetoothGattCharacteristic racpCharacteristic = mRecordAccessControlPointCharacteristic; - setOpCode(racpCharacteristic, OP_CODE_REPORT_STORED_RECORDS, OPERATOR_ALL_RECORDS); - writeCharacteristic(racpCharacteristic); + writeCharacteristic(racpCharacteristic, getOpCode(OP_CODE_REPORT_STORED_RECORDS, OPERATOR_ALL_RECORDS)); } else { mCallbacks.onOperationCompleted(gatt.getDevice()); } @@ -259,35 +260,34 @@ public class CGMSManager extends BleManager { /** * Writes given operation parameters to the characteristic * - * @param characteristic the characteristic to write. This must be the Record Access Control Point characteristic - * @param opCode the operation code - * @param operator the operator (see {@link #OPERATOR_NULL} and others - * @param params optional parameters (one for >=, <=, two for the range, none for other operators) + * @param opCode the operation code + * @param operator the operator (see {@link #OPERATOR_NULL} and others + * @param params optional parameters (one for >=, <=, two for the range, none for other operators) */ - private void setOpCode(final BluetoothGattCharacteristic characteristic, final int opCode, final int operator, final Integer... params) { - final int size = 2 + ((params.length > 0) ? 1 : 0) + params.length * 2; // 1 byte for opCode, 1 for operator, 1 for filter type (if parameters exists) and 2 for each parameter - characteristic.setValue(new byte[size]); + private byte[] getOpCode(final int opCode, final int operator, final Integer... params) { + // 1 byte for opCode, 1 for operator, 1 for filter type (if parameters exists) and 2 for each parameter + final int size = 2 + ((params.length > 0) ? 1 : 0) + params.length * 2; + final byte[] data = new byte[size]; - // write the operation code + // Write the operation code int offset = 0; - characteristic.setValue(opCode, BluetoothGattCharacteristic.FORMAT_UINT8, offset); - offset += 1; + data[offset++] = (byte) opCode; - // write the operator. This is always present but may be equal to OPERATOR_NULL - characteristic.setValue(operator, BluetoothGattCharacteristic.FORMAT_UINT8, offset); - offset += 1; + // Write the operator. This is always present but may be equal to OPERATOR_NULL + data[offset++] = (byte) operator; - // if parameters exists, append them. Parameters should be sorted from minimum to maximum. Currently only one or two params are allowed + // If parameters exists, append them. Parameters should be sorted from minimum to maximum. + // Currently only one or two params are allowed if (params.length > 0) { - // our implementation use only sequence number as a filer type - characteristic.setValue(FILTER_TYPE_SEQUENCE_NUMBER, BluetoothGattCharacteristic.FORMAT_UINT8, offset); - offset += 1; + // Our implementation use only sequence number as a filer type + data[offset++] = FILTER_TYPE_SEQUENCE_NUMBER; for (final Integer i : params) { - characteristic.setValue(i, BluetoothGattCharacteristic.FORMAT_UINT16, offset); - offset += 2; + data[offset++] = (byte) (i & 0xFF); + data[offset++] = (byte) ((i >> 8) & 0xFF); } } + return data; } /** @@ -306,7 +306,8 @@ public class CGMSManager extends BleManager { } /** - * Sends the request to obtain the last (most recent) record from glucose device. The data will be returned to Glucose Measurement characteristic as a notification followed by Record Access + * Sends the request to obtain the last (most recent) record from glucose device. The data will + * be returned to Glucose Measurement characteristic as a notification followed by Record Access * Control Point indication with status code ({@link #RESPONSE_SUCCESS} or other in case of error. */ public void getLastRecord() { @@ -317,13 +318,13 @@ public class CGMSManager extends BleManager { mCallbacks.onOperationStarted(mBluetoothDevice); final BluetoothGattCharacteristic characteristic = mRecordAccessControlPointCharacteristic; - setOpCode(characteristic, OP_CODE_REPORT_STORED_RECORDS, OPERATOR_LAST_RECORD); - writeCharacteristic(characteristic); + writeCharacteristic(characteristic, getOpCode(OP_CODE_REPORT_STORED_RECORDS, OPERATOR_LAST_RECORD)); } /** - * Sends the request to obtain the first (oldest) record from glucose device. The data will be returned to Glucose Measurement characteristic as a notification followed by Record Access Control - * Point indication with status code ({@link #RESPONSE_SUCCESS} or other in case of error. + * Sends the request to obtain the first (oldest) record from glucose device. The data will be + * returned to Glucose Measurement characteristic as a notification followed by Record Access + * Control Point indication with status code ({@link #RESPONSE_SUCCESS} or other in case of error. */ public void getFirstRecord() { if (mRecordAccessControlPointCharacteristic == null) @@ -333,8 +334,7 @@ public class CGMSManager extends BleManager { mCallbacks.onOperationStarted(mBluetoothDevice); final BluetoothGattCharacteristic characteristic = mRecordAccessControlPointCharacteristic; - setOpCode(characteristic, OP_CODE_REPORT_STORED_RECORDS, OPERATOR_FIRST_RECORD); - writeCharacteristic(characteristic); + writeCharacteristic(characteristic, getOpCode(OP_CODE_REPORT_STORED_RECORDS, OPERATOR_FIRST_RECORD)); } /** @@ -346,14 +346,15 @@ public class CGMSManager extends BleManager { mAbort = true; final BluetoothGattCharacteristic characteristic = mRecordAccessControlPointCharacteristic; - setOpCode(characteristic, OP_CODE_ABORT_OPERATION, OPERATOR_NULL); - writeCharacteristic(characteristic); + writeCharacteristic(characteristic, getOpCode(OP_CODE_ABORT_OPERATION, OPERATOR_NULL)); } /** - * Sends the request to obtain all records from glucose device. Initially we want to notify him/her about the number of the records so the {@link #OP_CODE_REPORT_NUMBER_OF_RECORDS} is send. The - * data will be returned to Glucose Measurement characteristic as a notification followed by Record Access Control Point indication with status code ({@link #RESPONSE_SUCCESS} or other in case of - * error. + * Sends the request to obtain all records from glucose device. Initially we want to notify + * him/her about the number of the records so the {@link #OP_CODE_REPORT_NUMBER_OF_RECORDS} + * is send. The data will be returned to Glucose Measurement characteristic as a notification + * followed by Record Access Control Point indication with status code ({@link #RESPONSE_SUCCESS} + * or other in case of error. */ public void getAllRecords() { if (mRecordAccessControlPointCharacteristic == null) @@ -363,14 +364,15 @@ public class CGMSManager extends BleManager { mCallbacks.onOperationStarted(mBluetoothDevice); final BluetoothGattCharacteristic characteristic = mRecordAccessControlPointCharacteristic; - setOpCode(characteristic, OP_CODE_REPORT_NUMBER_OF_RECORDS, OPERATOR_ALL_RECORDS); - writeCharacteristic(characteristic); + writeCharacteristic(characteristic, getOpCode(OP_CODE_REPORT_NUMBER_OF_RECORDS, OPERATOR_ALL_RECORDS)); } /** - * Sends the request to obtain all records from glucose device. Initially we want to notify him/her about the number of the records so the {@link #OP_CODE_REPORT_NUMBER_OF_RECORDS} is send. The - * data will be returned to Glucose Measurement characteristic as a notification followed by Record Access Control Point indication with status code ({@link #RESPONSE_SUCCESS} or other in case of - * error. + * Sends the request to obtain all records from glucose device. Initially we want to notify + * him/her about the number of the records so the {@link #OP_CODE_REPORT_NUMBER_OF_RECORDS} + * is send. The data will be returned to Glucose Measurement characteristic as a notification + * followed by Record Access Control Point indication with status code ({@link #RESPONSE_SUCCESS} + * or other in case of error. */ public void refreshRecords() { if (mRecordAccessControlPointCharacteristic == null) @@ -385,8 +387,7 @@ public class CGMSManager extends BleManager { final int sequenceNumber = mRecords.keyAt(mRecords.size() - 1) + 1; final BluetoothGattCharacteristic characteristic = mRecordAccessControlPointCharacteristic; - setOpCode(characteristic, OP_CODE_REPORT_STORED_RECORDS, OPERATOR_GREATER_THEN_OR_EQUAL, sequenceNumber); - writeCharacteristic(characteristic); + writeCharacteristic(characteristic, getOpCode(OP_CODE_REPORT_STORED_RECORDS, OPERATOR_GREATER_THEN_OR_EQUAL, sequenceNumber)); // Info: // Operators OPERATOR_GREATER_THEN_OR_EQUAL, OPERATOR_LESS_THEN_OR_EQUAL and OPERATOR_RANGE are not supported by the CGMS sample from SDK // The "Operation not supported" response will be received @@ -401,8 +402,7 @@ public class CGMSManager extends BleManager { mCallbacks.onOperationStarted(mBluetoothDevice); final BluetoothGattCharacteristic characteristic = mRecordAccessControlPointCharacteristic; - setOpCode(characteristic, OP_CODE_DELETE_STORED_RECORDS, OPERATOR_ALL_RECORDS); - writeCharacteristic(characteristic); + writeCharacteristic(characteristic, getOpCode(OP_CODE_DELETE_STORED_RECORDS, OPERATOR_ALL_RECORDS)); } } diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/gls/GlucoseManager.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/gls/GlucoseManager.java index 1c573fd7..20ab6a7c 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/gls/GlucoseManager.java +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/gls/GlucoseManager.java @@ -45,15 +45,25 @@ import no.nordicsemi.android.nrftoolbox.utility.DebugLogger; public class GlucoseManager extends BleManager { private static final String TAG = "GlucoseManager"; - /** Glucose service UUID */ + /** + * Glucose service UUID + */ public final static UUID GLS_SERVICE_UUID = UUID.fromString("00001808-0000-1000-8000-00805f9b34fb"); - /** Glucose Measurement characteristic UUID */ + /** + * Glucose Measurement characteristic UUID + */ private final static UUID GM_CHARACTERISTIC = UUID.fromString("00002A18-0000-1000-8000-00805f9b34fb"); - /** Glucose Measurement Context characteristic UUID */ + /** + * Glucose Measurement Context characteristic UUID + */ private final static UUID GM_CONTEXT_CHARACTERISTIC = UUID.fromString("00002A34-0000-1000-8000-00805f9b34fb"); - /** Glucose Feature characteristic UUID */ + /** + * Glucose Feature characteristic UUID + */ private final static UUID GF_CHARACTERISTIC = UUID.fromString("00002A51-0000-1000-8000-00805f9b34fb"); - /** Record Access Control Point characteristic UUID */ + /** + * Record Access Control Point characteristic UUID + */ private final static UUID RACP_CHARACTERISTIC = UUID.fromString("00002A52-0000-1000-8000-00805f9b34fb"); private final static int OP_CODE_REPORT_STORED_RECORDS = 1; @@ -72,13 +82,15 @@ public class GlucoseManager extends BleManager { private final static int OPERATOR_LAST_RECORD = 6; /** - * The filter type is used for range operators ({@link #OPERATOR_LESS_THEN_OR_EQUAL}, {@link #OPERATOR_GREATER_THEN_OR_EQUAL}, {@link #OPERATOR_WITHING_RANGE}.
+ * The filter type is used for range operators ({@link #OPERATOR_LESS_THEN_OR_EQUAL}, + * {@link #OPERATOR_GREATER_THEN_OR_EQUAL}, {@link #OPERATOR_WITHING_RANGE}.
* The syntax of the operand is: [Filter Type][Minimum][Maximum].
* This filter selects the records by the sequence number. */ private final static int FILTER_TYPE_SEQUENCE_NUMBER = 1; /** - * The filter type is used for range operators ({@link #OPERATOR_LESS_THEN_OR_EQUAL}, {@link #OPERATOR_GREATER_THEN_OR_EQUAL}, {@link #OPERATOR_WITHING_RANGE}.
+ * The filter type is used for range operators ({@link #OPERATOR_LESS_THEN_OR_EQUAL}, + * {@link #OPERATOR_GREATER_THEN_OR_EQUAL}, {@link #OPERATOR_WITHING_RANGE}.
* The syntax of the operand is: [Filter Type][Minimum][Maximum].
* This filter selects the records by the user facing time (base time + offset time). */ @@ -346,8 +358,7 @@ public class GlucoseManager extends BleManager { // Request the records if (number > 0) { final BluetoothGattCharacteristic racpCharacteristic = mRecordAccessControlPointCharacteristic; - setOpCode(racpCharacteristic, OP_CODE_REPORT_STORED_RECORDS, OPERATOR_ALL_RECORDS); - writeCharacteristic(racpCharacteristic); + writeCharacteristic(racpCharacteristic, getOpCode(OP_CODE_REPORT_STORED_RECORDS, OPERATOR_ALL_RECORDS)); } else { mCallbacks.onOperationCompleted(gatt.getDevice()); } @@ -357,23 +368,23 @@ public class GlucoseManager extends BleManager { DebugLogger.d(TAG, "Response result for: " + requestedOpCode + " is: " + responseCode); switch (responseCode) { - case RESPONSE_SUCCESS: - if (!mAbort) + case RESPONSE_SUCCESS: + if (!mAbort) + mCallbacks.onOperationCompleted(gatt.getDevice()); + else + mCallbacks.onOperationAborted(gatt.getDevice()); + break; + case RESPONSE_NO_RECORDS_FOUND: mCallbacks.onOperationCompleted(gatt.getDevice()); - else - mCallbacks.onOperationAborted(gatt.getDevice()); - break; - case RESPONSE_NO_RECORDS_FOUND: - mCallbacks.onOperationCompleted(gatt.getDevice()); - break; - case RESPONSE_OP_CODE_NOT_SUPPORTED: - mCallbacks.onOperationNotSupported(gatt.getDevice()); - break; - case RESPONSE_PROCEDURE_NOT_COMPLETED: - case RESPONSE_ABORT_UNSUCCESSFUL: - default: - mCallbacks.onOperationFailed(gatt.getDevice()); - break; + break; + case RESPONSE_OP_CODE_NOT_SUPPORTED: + mCallbacks.onOperationNotSupported(gatt.getDevice()); + break; + case RESPONSE_PROCEDURE_NOT_COMPLETED: + case RESPONSE_ABORT_UNSUCCESSFUL: + default: + mCallbacks.onOperationFailed(gatt.getDevice()); + break; } mAbort = false; } @@ -382,41 +393,37 @@ public class GlucoseManager extends BleManager { /** * Writes given operation parameters to the characteristic - * - * @param characteristic - * the characteristic to write. This must be the Record Access Control Point characteristic - * @param opCode - * the operation code - * @param operator - * the operator (see {@link #OPERATOR_NULL} and others - * @param params - * optional parameters (one for >=, <=, two for the range, none for other operators) + * + * @param opCode the operation code + * @param operator the operator (see {@link #OPERATOR_NULL} and others + * @param params optional parameters (one for >=, <=, two for the range, none for other operators) */ - private void setOpCode(final BluetoothGattCharacteristic characteristic, final int opCode, final int operator, final Integer... params) { - final int size = 2 + ((params.length > 0) ? 1 : 0) + params.length * 2; // 1 byte for opCode, 1 for operator, 1 for filter type (if parameters exists) and 2 for each parameter - characteristic.setValue(new byte[size]); + private byte[] getOpCode(final int opCode, final int operator, final Integer... params) { + // 1 byte for opCode, 1 for operator, 1 for filter type (if parameters exists) and 2 for each parameter + final int size = 2 + ((params.length > 0) ? 1 : 0) + params.length * 2; + final byte[] data = new byte[size]; - // write the operation code + // Write the operation code int offset = 0; - characteristic.setValue(opCode, BluetoothGattCharacteristic.FORMAT_UINT8, offset); - offset += 1; + data[offset++] = (byte) opCode; - // write the operator. This is always present but may be equal to OPERATOR_NULL - characteristic.setValue(operator, BluetoothGattCharacteristic.FORMAT_UINT8, offset); - offset += 1; + // Write the operator. This is always present but may be equal to OPERATOR_NULL + data[offset++] = (byte) operator; - // if parameters exists, append them. Parameters should be sorted from minimum to maximum. Currently only one or two params are allowed + // If parameters exists, append them. Parameters should be sorted from minimum to maximum. + // Currently only one or two params are allowed if (params.length > 0) { - // our implementation use only sequence number as a filer type - characteristic.setValue(FILTER_TYPE_SEQUENCE_NUMBER, BluetoothGattCharacteristic.FORMAT_UINT8, offset); - offset += 1; + // Our implementation use only sequence number as a filer type + data[offset++] = FILTER_TYPE_SEQUENCE_NUMBER; for (final Integer i : params) { - characteristic.setValue(i, BluetoothGattCharacteristic.FORMAT_UINT16, offset); - offset += 2; + data[offset++] = (byte) (i & 0xFF); + data[offset++] = (byte) ((i >> 8) & 0xFF); } } + return data; } + /** * Returns all records as a sparse array where sequence number is the key. * @@ -435,7 +442,8 @@ public class GlucoseManager extends BleManager { } /** - * Sends the request to obtain the last (most recent) record from glucose device. The data will be returned to Glucose Measurement characteristic as a notification followed by Record Access + * Sends the request to obtain the last (most recent) record from glucose device. The data will + * be returned to Glucose Measurement characteristic as a notification followed by Record Access * Control Point indication with status code ({@link #RESPONSE_SUCCESS} or other in case of error. */ public void getLastRecord() { @@ -446,13 +454,13 @@ public class GlucoseManager extends BleManager { mCallbacks.onOperationStarted(mBluetoothDevice); final BluetoothGattCharacteristic characteristic = mRecordAccessControlPointCharacteristic; - setOpCode(characteristic, OP_CODE_REPORT_STORED_RECORDS, OPERATOR_LAST_RECORD); - writeCharacteristic(characteristic); + writeCharacteristic(characteristic, getOpCode(OP_CODE_REPORT_STORED_RECORDS, OPERATOR_LAST_RECORD)); } /** - * Sends the request to obtain the first (oldest) record from glucose device. The data will be returned to Glucose Measurement characteristic as a notification followed by Record Access Control - * Point indication with status code ({@link #RESPONSE_SUCCESS} or other in case of error. + * Sends the request to obtain the first (oldest) record from glucose device. The data will be + * returned to Glucose Measurement characteristic as a notification followed by Record Access + * Control Point indication with status code ({@link #RESPONSE_SUCCESS} or other in case of error. */ public void getFirstRecord() { if (mRecordAccessControlPointCharacteristic == null) @@ -462,14 +470,15 @@ public class GlucoseManager extends BleManager { mCallbacks.onOperationStarted(mBluetoothDevice); final BluetoothGattCharacteristic characteristic = mRecordAccessControlPointCharacteristic; - setOpCode(characteristic, OP_CODE_REPORT_STORED_RECORDS, OPERATOR_FIRST_RECORD); - writeCharacteristic(characteristic); + writeCharacteristic(characteristic, getOpCode(OP_CODE_REPORT_STORED_RECORDS, OPERATOR_FIRST_RECORD)); } /** - * Sends the request to obtain all records from glucose device. Initially we want to notify him/her about the number of the records so the {@link #OP_CODE_REPORT_NUMBER_OF_RECORDS} is send. The - * data will be returned to Glucose Measurement characteristic as a notification followed by Record Access Control Point indication with status code ({@link #RESPONSE_SUCCESS} or other in case of - * error. + * Sends the request to obtain all records from glucose device. Initially we want to notify + * him/her about the number of the records so the {@link #OP_CODE_REPORT_NUMBER_OF_RECORDS} + * is send. The data will be returned to Glucose Measurement characteristic as a notification + * followed by Record Access Control Point indication with status code ({@link #RESPONSE_SUCCESS} + * or other in case of error. */ public void getAllRecords() { if (mRecordAccessControlPointCharacteristic == null) @@ -479,17 +488,18 @@ public class GlucoseManager extends BleManager { mCallbacks.onOperationStarted(mBluetoothDevice); final BluetoothGattCharacteristic characteristic = mRecordAccessControlPointCharacteristic; - setOpCode(characteristic, OP_CODE_REPORT_NUMBER_OF_RECORDS, OPERATOR_ALL_RECORDS); - writeCharacteristic(characteristic); + writeCharacteristic(characteristic, getOpCode(OP_CODE_REPORT_NUMBER_OF_RECORDS, OPERATOR_ALL_RECORDS)); } /** - * Sends the request to obtain from the glucose device all records newer than the newest one from local storage. The data will be returned to Glucose Measurement characteristic as a notification - * followed by Record Access Control Point indication with status code ({@link #RESPONSE_SUCCESS} or other in case of error. + * Sends the request to obtain from the glucose device all records newer than the newest one + * from local storage. The data will be returned to Glucose Measurement characteristic as a + * notification followed by Record Access Control Point indication with status code + * ({@link #RESPONSE_SUCCESS} or other in case of error. *

- * Refresh button will not download records older than the oldest in the local memory. F.e. if you have pressed Last and then Refresh, than it will try to get only newer records. However if there - * are no records, it will download all existing (using {@link #getAllRecords()}). - *

+ * Refresh button will not download records older than the oldest in the local memory. + * E.g. if you have pressed Last and then Refresh, than it will try to get only newer records. + * However, if there are no records, it will download all existing (using {@link #getAllRecords()}). */ public void refreshRecords() { if (mRecordAccessControlPointCharacteristic == null) @@ -504,8 +514,7 @@ public class GlucoseManager extends BleManager { final int sequenceNumber = mRecords.keyAt(mRecords.size() - 1) + 1; final BluetoothGattCharacteristic characteristic = mRecordAccessControlPointCharacteristic; - setOpCode(characteristic, OP_CODE_REPORT_STORED_RECORDS, OPERATOR_GREATER_THEN_OR_EQUAL, sequenceNumber); - writeCharacteristic(characteristic); + writeCharacteristic(characteristic, getOpCode(OP_CODE_REPORT_STORED_RECORDS, OPERATOR_GREATER_THEN_OR_EQUAL, sequenceNumber)); // Info: // Operators OPERATOR_LESS_THEN_OR_EQUAL and OPERATOR_RANGE are not supported by Nordic Semiconductor Glucose Service in SDK 4.4.2. } @@ -520,13 +529,13 @@ public class GlucoseManager extends BleManager { mAbort = true; final BluetoothGattCharacteristic characteristic = mRecordAccessControlPointCharacteristic; - setOpCode(characteristic, OP_CODE_ABORT_OPERATION, OPERATOR_NULL); - writeCharacteristic(characteristic); + writeCharacteristic(characteristic, getOpCode(OP_CODE_ABORT_OPERATION, OPERATOR_NULL)); } /** - * Sends the request to delete all data from the device. A Record Access Control Point indication with status code ({@link #RESPONSE_SUCCESS} (or other in case of error) will be send. - * + * Sends the request to delete all data from the device. A Record Access Control Point indication + * with status code ({@link #RESPONSE_SUCCESS} (or other in case of error) will be send. + *

* FIXME This method is not supported by Nordic Semiconductor Glucose Service in SDK 4.4.2. */ public void deleteAllRecords() { @@ -537,7 +546,6 @@ public class GlucoseManager extends BleManager { mCallbacks.onOperationStarted(mBluetoothDevice); final BluetoothGattCharacteristic characteristic = mRecordAccessControlPointCharacteristic; - setOpCode(characteristic, OP_CODE_DELETE_STORED_RECORDS, OPERATOR_ALL_RECORDS); - writeCharacteristic(characteristic); + writeCharacteristic(characteristic, getOpCode(OP_CODE_DELETE_STORED_RECORDS, OPERATOR_ALL_RECORDS)); } } diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/proximity/ProximityManager.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/proximity/ProximityManager.java index 2cd6bb8d..b6a6a842 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/proximity/ProximityManager.java +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/proximity/ProximityManager.java @@ -41,7 +41,7 @@ public class ProximityManager extends BleManager { /** Immediate Alert service UUID */ public final static UUID IMMEDIATE_ALERT_SERVICE_UUID = UUID.fromString("00001802-0000-1000-8000-00805f9b34fb"); - /** Linkloss service UUID */ + /** Link Loss service UUID */ public final static UUID LINKLOSS_SERVICE_UUID = UUID.fromString("00001803-0000-1000-8000-00805f9b34fb"); /** Alert Level characteristic UUID */ private static final UUID ALERT_LEVEL_CHARACTERISTIC_UUID = UUID.fromString("00002A06-0000-1000-8000-00805f9b34fb"); @@ -129,8 +129,7 @@ public class ProximityManager extends BleManager { return; if (mAlertLevelCharacteristic != null) { - mAlertLevelCharacteristic.setValue(on ? HIGH_ALERT : NO_ALERT); - writeCharacteristic(mAlertLevelCharacteristic); + writeCharacteristic(mAlertLevelCharacteristic, on ? HIGH_ALERT : NO_ALERT); mAlertOn = on; } else { DebugLogger.w(TAG, "Immediate Alert Level Characteristic is not found"); From 4b1dd1b11eec29cd1951a0c0d99e512ee771ae53 Mon Sep 17 00:00:00 2001 From: Aleksander Nowakowski Date: Tue, 19 Jun 2018 16:43:52 +0200 Subject: [PATCH 2/4] Android Studio 3.1.3 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 2ddc5a88..5975f391 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.1' + classpath 'com.android.tools.build:gradle:3.1.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files From 721fabbce3138178fb158aaf281549162403b1c1 Mon Sep 17 00:00:00 2001 From: Aleksander Nowakowski Date: Tue, 19 Jun 2018 16:44:08 +0200 Subject: [PATCH 3/4] BLE Library imported from jcenter --- app/build.gradle | 8 ++++++-- settings.gradle | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index cdb93136..f6befe0f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -46,7 +46,7 @@ dependencies { implementation 'com.android.support:design:27.1.1' implementation 'no.nordicsemi.android:log:2.1.1' - implementation 'no.nordicsemi.android.support.v18:scanner:1.0.0' + implementation 'no.nordicsemi.android.support.v18:scanner:1.1.0' // The DFU Library is imported automatically from jcenter: implementation 'no.nordicsemi.android:dfu:1.6.1' @@ -55,7 +55,11 @@ dependencies { // implementation project(':dfu') // Import the BLE Library - implementation project(':ble') + implementation 'no.nordicsemi.android:ble:1.2.0' + // The BLE Library may be included from jcenter. If you want to modify the code, + // clone the project from GitHub and replace the line above with the following + // (and also the according lines in the settings.gradle): + // implementation project(':ble') implementation('org.simpleframework:simple-xml:2.7.1') { exclude group: 'stax', module: 'stax-api' diff --git a/settings.gradle b/settings.gradle index 08573a8f..809803aa 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,7 +1,8 @@ include ':app', ':wear', ':common' -include ':ble' -project(':ble').projectDir = file('../Android-BLE-Library/ble') +// Uncomment these lines if you want to import the BLE Library as a project, not from jcenter +// include ':ble' +// project(':ble').projectDir = file('../Android-BLE-Library/ble') // Uncomment these lines if you want to import the DFULibrary as a project, not from jcenter // include ':dfu' From 4e08e8204e6a3c745b46d9ca274a4e012d348333 Mon Sep 17 00:00:00 2001 From: Aleksander Nowakowski Date: Tue, 26 Jun 2018 16:50:51 +0200 Subject: [PATCH 4/4] Readme updated --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a0e299ae..86797ac7 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,11 @@ Since version 1.10.0 the *nRF Toolbox* also supports the **Nordic UART Service** ### How to import to Android Studio -nRF Toolbox depends on [Android BLE Library](https://github.com/NordicSemiconductor/Android-BLE-Library/) which has to be cloned into the same root folder as this app. +The production version of nRF Toolbox depends on [Android BLE Library](https://github.com/NordicSemiconductor/Android-BLE-Library/) version 1.2.0, which is available on jcenter. + +**Note:** It is recommended to use the *develop* branch of this project. The new version will soon replace the current one. It is using the BLE Library v2 which is now in alpha version. Its API and stability has been improved. + +You may also include the BLE Library as a module. Clone the library project to the same root folder. If you are having issue like [#40](https://github.com/NordicSemiconductor/Android-nRF-Toolbox/issues/40) or [#41](https://github.com/NordicSemiconductor/Android-nRF-Toolbox/issues/41), the correct folders structure should look like this: @@ -26,12 +30,16 @@ If you are having issue like [#40](https://github.com/NordicSemiconductor/Androi If you prefer a different name for BLE library, update the [*settings.gradle*](https://github.com/NordicSemiconductor/Android-nRF-Toolbox/blob/master/settings.gradle) file. +**Note:** The nRF Toolbox app on *develop* branch depends on [Android BLE Common Library](https://github.com/NordicSemiconductor/Android-BLE-Common-Library/), which depends on the BLE Library v2. + *DFULibrary* folder is optional, as the library is downloaded from jcenter repository automatically. Clone it only when you want to modify the code (not recommended). If you get ["Missing Feature Watch" error](https://github.com/NordicSemiconductor/Android-nRF-Toolbox/issues/41#issuecomment-355291101), switch the configuration to 'app'. ### BleManager and how to use it +**Note:** This section applies only to BLE Library v.1.x. The API has changed in v.2.x of the library. + The nRF Toolbox application is a reference design demonstrating how to use the BLE API on Android. The main class responsible for managing connection to a single device is called [BleManager](https://github.com/NordicSemiconductor/Android-BLE-Library/blob/master/ble/src/main/java/no/nordicsemi/android/ble/BleManager.java). Each of the profiles listed above is using this manager and overriding it to add some profile-related functionality. The BleManager sends events using the [BleManagerCallbacks](https://github.com/NordicSemiconductor/Android-BLE-Library/blob/master/ble/src/main/java/no/nordicsemi/android/ble/BleManagerCallbacks.java) interface, which should be implemented by your controller. A profile's BleManager should override the BleManager and implement required methods, that is: * ```Deque initGatt(BluetoothGatt)``` - method that defines initialization queue * ```boolean isRequiredServiceSupported(BluetoothGatt)``` - method that verifies if the connected device is supported by the profile