From 728e264ee3731730d279b3763d2481d66435e213 Mon Sep 17 00:00:00 2001
From: Aleksander Nowakowski
Date: Tue, 19 Jun 2018 13:47:06 +0200
Subject: [PATCH] Comments updated.
---
.../nrftoolbox/battery/BatteryManager.java | 2 +-
.../android/nrftoolbox/bpm/BPMManager.java | 10 +-
.../android/nrftoolbox/cgms/CGMSManager.java | 24 +--
.../android/nrftoolbox/csc/CSCManager.java | 3 +-
.../nrftoolbox/gls/GlucoseManager.java | 41 ++---
.../android/nrftoolbox/hrs/HRSManager.java | 5 +-
.../android/nrftoolbox/hts/HTSManager.java | 3 +-
.../nrftoolbox/parser/AlertLevelParser.java | 1 +
.../BloodPressureMeasurementParser.java | 15 +-
.../parser/BodySensorLocationParser.java | 1 +
.../parser/CGMMeasurementParser.java | 1 +
.../CGMSpecificOpsControlPointParser.java | 1 +
.../parser/CSCMeasurementParser.java | 1 +
.../nrftoolbox/parser/DateTimeParser.java | 12 +-
.../GlucoseMeasurementContextParser.java | 1 +
.../parser/GlucoseMeasurementParser.java | 1 +
.../parser/HeartRateMeasurementParser.java | 1 +
.../IntermediateCuffPressureParser.java | 13 +-
.../parser/RSCMeasurementParser.java | 1 +
.../RecordAccessControlPointParser.java | 1 +
.../parser/TemperatureMeasurementParser.java | 1 +
.../parser/TemperatureTypeParser.java | 1 +
.../nrftoolbox/parser/TemplateParser.java | 17 +-
.../proximity/LinkLossFragment.java | 5 +-
.../proximity/ProximityManager.java | 9 +-
.../proximity/ProximityServerManager.java | 158 +++++++++++-------
.../proximity/ProximityService.java | 81 +++++----
.../android/nrftoolbox/rsc/RSCManager.java | 3 +-
.../nrftoolbox/template/TemplateManager.java | 24 ++-
.../android/nrftoolbox/uart/UARTManager.java | 3 +-
30 files changed, 260 insertions(+), 180 deletions(-)
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/battery/BatteryManager.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/battery/BatteryManager.java
index 8c702513..f07fc8f3 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/battery/BatteryManager.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/battery/BatteryManager.java
@@ -35,7 +35,7 @@ public abstract class BatteryManager extends
/**
* The manager constructor.
*
- * @param context context
+ * @param context context.
*/
public BatteryManager(final Context context) {
super(context);
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/bpm/BPMManager.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/bpm/BPMManager.java
index 5c078ea8..37eaec85 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/bpm/BPMManager.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/bpm/BPMManager.java
@@ -54,7 +54,7 @@ public class BPMManager extends BatteryManager {
private static BPMManager managerInstance = null;
/**
- * Returns the singleton implementation of BPMManager
+ * Returns the singleton implementation of BPMManager.
*/
public static synchronized BPMManager getBPMManager(final Context context) {
if (managerInstance == null) {
@@ -74,7 +74,8 @@ public class BPMManager extends BatteryManager {
}
/**
- * BluetoothGatt callbacks for connection/disconnection, service discovery, receiving notification, etc
+ * BluetoothGatt callbacks for connection/disconnection, service discovery,
+ * receiving notification, etc.
*/
private final BatteryManagerGattCallback mGattCallback = new BatteryManagerGattCallback() {
@@ -131,7 +132,10 @@ public class BPMManager extends BatteryManager {
}
});
- enableNotifications(mICPCharacteristic).enqueue();
+ enableNotifications(mICPCharacteristic)
+ .fail((device, status) -> log(LogContract.Log.Level.WARNING,
+ "Intermediate Cuff Pressure characteristic not found"))
+ .enqueue();
enableIndications(mBPMCharacteristic).enqueue();
}
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 23c318b8..050afecc 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
@@ -68,11 +68,14 @@ public class CGMSManager extends BatteryManager {
/** A flag set to true if the remote device supports E2E CRC. */
private boolean mSecured;
/**
- * A flag set when records has been requested using RACP. This is to distinguish CGM packets received
- * as continuous measurements or requested.
+ * A flag set when records has been requested using RACP. This is to distinguish CGM packets
+ * received as continuous measurements or requested.
*/
private boolean mRecordAccessRequestInProgress;
- /** The timestamp when the session has started. This is needed to display the user facing times of samples. */
+ /**
+ * The timestamp when the session has started. This is needed to display the user facing
+ * times of samples.
+ */
private long mSessionStartTime;
CGMSManager(final Context context) {
@@ -86,7 +89,8 @@ public class CGMSManager extends BatteryManager {
}
/**
- * BluetoothGatt callbacks for connection/disconnection, service discovery, receiving notification, etc
+ * BluetoothGatt callbacks for connection/disconnection, service discovery,
+ * receiving notification, etc.
*/
private final BatteryManagerGattCallback mGattCallback = new BatteryManagerGattCallback() {
@@ -375,9 +379,9 @@ public class CGMSManager extends BatteryManager {
}
/**
- * Sends the request to obtain all records from glucose device. Initially we want to notify the user
- * about the number of the records so the Report Number of Stored Records request is send. The
- * data will be returned to Glucose Measurement characteristic as a notification followed by
+ * Sends the request to obtain all records from glucose device. Initially we want to notify the
+ * user about the number of the records so the Report Number of Stored Records request is send.
+ * The data will be returned to Glucose Measurement characteristic as a notification followed by
* Record Access Control Point indication with status code Success or other in case of error.
*/
public void getAllRecords() {
@@ -393,9 +397,9 @@ public class CGMSManager extends BatteryManager {
}
/**
- * Sends the request to obtain all records from glucose device. Initially we want to notify the user
- * about the number of the records so the Report Number of Stored Records request is send. The
- * data will be returned to Glucose Measurement characteristic as a notification followed by
+ * Sends the request to obtain all records from glucose device. Initially we want to notify the
+ * user about the number of the records so the Report Number of Stored Records request is send.
+ * The data will be returned to Glucose Measurement characteristic as a notification followed by
* Record Access Control Point indication with status code Success or other in case of error.
*/
public void refreshRecords() {
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/csc/CSCManager.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/csc/CSCManager.java
index 46be0af5..cdba9c88 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/csc/CSCManager.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/csc/CSCManager.java
@@ -61,7 +61,8 @@ public class CSCManager extends BatteryManager {
}
/**
- * BluetoothGatt callbacks for connection/disconnection, service discovery, receiving indication, etc
+ * BluetoothGatt callbacks for connection/disconnection, service discovery,
+ * receiving indication, etc.
*/
private final BatteryManagerGattCallback mGattCallback = new BatteryManagerGattCallback() {
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 896cc319..a76d649a 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
@@ -70,7 +70,7 @@ public class GlucoseManager extends BatteryManager {
private static GlucoseManager mInstance;
/**
- * Returns the singleton implementation of GlucoseManager
+ * Returns the singleton implementation of GlucoseManager.
*/
public static GlucoseManager getGlucoseManager(final Context context) {
if (mInstance == null)
@@ -90,7 +90,8 @@ public class GlucoseManager extends BatteryManager {
}
/**
- * BluetoothGatt callbacks for connection/disconnection, service discovery, receiving notification, etc
+ * BluetoothGatt callbacks for connection/disconnection, service discovery,
+ * receiving notification, etc.
*/
private final BatteryManagerGattCallback mGattCallback = new BatteryManagerGattCallback() {
@@ -98,14 +99,16 @@ public class GlucoseManager extends BatteryManager {
protected void initialize() {
super.initialize();
- // The gatt.setCharacteristicNotification(...) method is called in BleManager during enabling
- // notifications or indications (see BleManager#internalEnableNotifications/Indications).
+ // The gatt.setCharacteristicNotification(...) method is called in BleManager during
+ // enabling notifications or indications
+ // (see BleManager#internalEnableNotifications/Indications).
// However, on Samsung S3 with Android 4.3 it looks like the 2 gatt calls
// (gatt.setCharacteristicNotification(...) and gatt.writeDescriptor(...)) are called
- // too quickly, or from a wrong thread, and in result the notification listener is not set,
- // causing onCharacteristicChanged(...) callback never being called when a notification comes.
- // Enabling them here, like below, solves the problem.
- // However... the original approach works for the Battery Level CCCD, which makes it even weirder.
+ // too quickly, or from a wrong thread, and in result the notification listener is not
+ // set, causing onCharacteristicChanged(...) callback never being called when a
+ // notification comes. Enabling them here, like below, solves the problem.
+ // However... the original approach works for the Battery Level CCCD, which makes it
+ // even weirder.
/*
gatt.setCharacteristicNotification(mGlucoseMeasurementCharacteristic, true);
if (mGlucoseMeasurementContextCharacteristic != null) {
@@ -280,7 +283,7 @@ public class GlucoseManager extends BatteryManager {
/**
* Returns all records as a sparse array where sequence number is the key.
*
- * @return the records list
+ * @return the records list.
*/
public SparseArray getRecords() {
return mRecords;
@@ -312,8 +315,8 @@ public class GlucoseManager extends BatteryManager {
/**
* 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 Success or other in case of error.
+ * returned to Glucose Measurement characteristic as a notification followed by Record Access
+ * Control Point indication with status code Success or other in case of error.
*/
public void getFirstRecord() {
if (mRecordAccessControlPointCharacteristic == null)
@@ -344,14 +347,14 @@ public class GlucoseManager extends BatteryManager {
}
/**
- * 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 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 Success
+ * or other in case of error.
*
* Refresh button will not download records older than the oldest in the local memory.
- * I.e. if you have pressed Last and then Refresh, than it will try to get only newer records.
+ * 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)
@@ -375,7 +378,7 @@ public class GlucoseManager extends BatteryManager {
}
/**
- * Sends abort operation signal to the device
+ * Sends abort operation signal to the device.
*/
public void abort() {
if (mRecordAccessControlPointCharacteristic == null)
@@ -387,8 +390,8 @@ public class GlucoseManager extends BatteryManager {
}
/**
- * Sends the request to delete all data from the device. A Record Access Control Point indication
- * with status code 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 Success (or other in case of error) will be send.
*/
public void deleteAllRecords() {
if (mRecordAccessControlPointCharacteristic == null)
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/hrs/HRSManager.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/hrs/HRSManager.java
index 29e70943..ac8a3952 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/hrs/HRSManager.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/hrs/HRSManager.java
@@ -56,7 +56,7 @@ public class HRSManager extends BatteryManager {
private static HRSManager managerInstance = null;
/**
- * singleton implementation of HRSManager class
+ * Singleton implementation of HRSManager class.
*/
public static synchronized HRSManager getInstance(final Context context) {
if (managerInstance == null) {
@@ -76,7 +76,8 @@ public class HRSManager extends BatteryManager {
}
/**
- * BluetoothGatt callbacks for connection/disconnection, service discovery, receiving notification, etc
+ * BluetoothGatt callbacks for connection/disconnection, service discovery,
+ * receiving notification, etc.
*/
private final BatteryManagerGattCallback mGattCallback = new BatteryManagerGattCallback() {
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/hts/HTSManager.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/hts/HTSManager.java
index 6a545191..cac0d27d 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/hts/HTSManager.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/hts/HTSManager.java
@@ -63,7 +63,8 @@ public class HTSManager extends BatteryManager {
}
/**
- * BluetoothGatt callbacks for connection/disconnection, service discovery, receiving indication, etc.
+ * BluetoothGatt callbacks for connection/disconnection, service discovery,
+ * receiving indication, etc..
*/
private final BatteryManagerGattCallback mGattCallback = new BatteryManagerGattCallback() {
@Override
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/AlertLevelParser.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/AlertLevelParser.java
index 6c30de89..68ff78b1 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/AlertLevelParser.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/AlertLevelParser.java
@@ -25,6 +25,7 @@ import android.bluetooth.BluetoothGattCharacteristic;
import no.nordicsemi.android.ble.data.Data;
+@SuppressWarnings("ConstantConditions")
public class AlertLevelParser {
public static String parse(final BluetoothGattCharacteristic characteristic) {
return parse(Data.from(characteristic));
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/BloodPressureMeasurementParser.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/BloodPressureMeasurementParser.java
index 6208f4c5..fa8cbd49 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/BloodPressureMeasurementParser.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/BloodPressureMeasurementParser.java
@@ -21,11 +21,9 @@
*/
package no.nordicsemi.android.nrftoolbox.parser;
-import java.util.Calendar;
-import java.util.Locale;
-
import no.nordicsemi.android.ble.data.Data;
+@SuppressWarnings("ConstantConditions")
public class BloodPressureMeasurementParser {
public static String parse(final Data data) {
@@ -53,22 +51,15 @@ public class BloodPressureMeasurementParser {
// parse timestamp if present
if (timestampPresent) {
- final Calendar calendar = Calendar.getInstance();
- calendar.set(Calendar.YEAR, data.getIntValue(Data.FORMAT_UINT16, offset));
- calendar.set(Calendar.MONTH, data.getIntValue(Data.FORMAT_UINT8, offset + 2));
- calendar.set(Calendar.DAY_OF_MONTH, data.getIntValue(Data.FORMAT_UINT8, offset + 3));
- calendar.set(Calendar.HOUR_OF_DAY, data.getIntValue(Data.FORMAT_UINT8, offset + 4));
- calendar.set(Calendar.MINUTE, data.getIntValue(Data.FORMAT_UINT8, offset + 5));
- calendar.set(Calendar.SECOND, data.getIntValue(Data.FORMAT_UINT8, offset + 6));
+ builder.append("Timestamp: ").append(DateTimeParser.parse(data, offset));
offset += 7;
- builder.append(String.format(Locale.US, "\nTimestamp: %1$tT %1$te.%1$tm.%1$tY", calendar));
}
// parse pulse rate if present
if (pulseRatePresent) {
final float pulseRate = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
offset += 2;
- builder.append("\nPulse: ").append(pulseRate).append(" bpm");;
+ builder.append("\nPulse: ").append(pulseRate).append(" bpm");
}
if (userIdPresent) {
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/BodySensorLocationParser.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/BodySensorLocationParser.java
index bb1186ce..22d17312 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/BodySensorLocationParser.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/BodySensorLocationParser.java
@@ -23,6 +23,7 @@ package no.nordicsemi.android.nrftoolbox.parser;
import no.nordicsemi.android.ble.data.Data;
+@SuppressWarnings("ConstantConditions")
public class BodySensorLocationParser {
public static String parse(final Data data) {
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/CGMMeasurementParser.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/CGMMeasurementParser.java
index 76ce017e..6c9c8075 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/CGMMeasurementParser.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/CGMMeasurementParser.java
@@ -25,6 +25,7 @@ import java.util.Locale;
import no.nordicsemi.android.ble.data.Data;
+@SuppressWarnings("ConstantConditions")
public class CGMMeasurementParser {
private static final int FLAGS_CGM_TREND_INFO_PRESENT = 1;
private static final int FLAGS_CGM_QUALITY_PRESENT = 1 << 1;
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/CGMSpecificOpsControlPointParser.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/CGMSpecificOpsControlPointParser.java
index 035a393e..c8afc88a 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/CGMSpecificOpsControlPointParser.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/CGMSpecificOpsControlPointParser.java
@@ -23,6 +23,7 @@ package no.nordicsemi.android.nrftoolbox.parser;
import no.nordicsemi.android.ble.data.Data;
+@SuppressWarnings("ConstantConditions")
public class CGMSpecificOpsControlPointParser {
private final static int OP_SET_CGM_COMMUNICATION_INTERVAL = 1;
private final static int OP_GET_CGM_COMMUNICATION_INTERVAL = 2;
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/CSCMeasurementParser.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/CSCMeasurementParser.java
index 8275782a..a5a28cce 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/CSCMeasurementParser.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/CSCMeasurementParser.java
@@ -23,6 +23,7 @@ package no.nordicsemi.android.nrftoolbox.parser;
import no.nordicsemi.android.ble.data.Data;
+@SuppressWarnings("ConstantConditions")
public class CSCMeasurementParser {
private static final byte WHEEL_REV_DATA_PRESENT = 0x01; // 1 bit
private static final byte CRANK_REV_DATA_PRESENT = 0x02; // 1 bit
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/DateTimeParser.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/DateTimeParser.java
index 4f963f75..5e3e79b0 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/DateTimeParser.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/DateTimeParser.java
@@ -24,6 +24,7 @@ package no.nordicsemi.android.nrftoolbox.parser;
import java.util.Calendar;
import java.util.Locale;
+import no.nordicsemi.android.ble.common.callback.DateTimeDataCallback;
import no.nordicsemi.android.ble.data.Data;
public class DateTimeParser {
@@ -46,16 +47,7 @@ public class DateTimeParser {
* @return time in human readable format
*/
/* package */static String parse(final Data data, final int offset) {
- final int year = data.getIntValue(Data.FORMAT_UINT16, offset);
- final int month = data.getIntValue(Data.FORMAT_UINT8, offset + 2);
- final int day = data.getIntValue(Data.FORMAT_UINT8, offset + 3);
- final int hours = data.getIntValue(Data.FORMAT_UINT8, offset + 4);
- final int minutes = data.getIntValue(Data.FORMAT_UINT8, offset + 5);
- final int seconds = data.getIntValue(Data.FORMAT_UINT8, offset + 6);
-
- final Calendar calendar = Calendar.getInstance();
- calendar.set(year, month - 1, day, hours, minutes, seconds);
-
+ final Calendar calendar = DateTimeDataCallback.readDateTime(data, offset);
return String.format(Locale.US, "%1$te %1$tb %1$tY, %1$tH:%1$tM:%1$tS", calendar);
}
}
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/GlucoseMeasurementContextParser.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/GlucoseMeasurementContextParser.java
index bf285771..8a814406 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/GlucoseMeasurementContextParser.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/GlucoseMeasurementContextParser.java
@@ -23,6 +23,7 @@ package no.nordicsemi.android.nrftoolbox.parser;
import no.nordicsemi.android.ble.data.Data;
+@SuppressWarnings("ConstantConditions")
public class GlucoseMeasurementContextParser {
private static final int UNIT_kg = 0;
private static final int UNIT_l = 1;
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/GlucoseMeasurementParser.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/GlucoseMeasurementParser.java
index d28b22b6..18d59b44 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/GlucoseMeasurementParser.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/GlucoseMeasurementParser.java
@@ -24,6 +24,7 @@ package no.nordicsemi.android.nrftoolbox.parser;
import no.nordicsemi.android.ble.data.Data;
+@SuppressWarnings("ConstantConditions")
public class GlucoseMeasurementParser {
private static final int UNIT_kgpl = 0;
private static final int UNIT_molpl = 1;
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/HeartRateMeasurementParser.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/HeartRateMeasurementParser.java
index ca65506f..96220727 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/HeartRateMeasurementParser.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/HeartRateMeasurementParser.java
@@ -27,6 +27,7 @@ import java.util.Locale;
import no.nordicsemi.android.ble.data.Data;
+@SuppressWarnings("ConstantConditions")
public class HeartRateMeasurementParser {
private static final byte HEART_RATE_VALUE_FORMAT = 0x01; // 1 bit
private static final byte SENSOR_CONTACT_STATUS = 0x06; // 2 bits
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/IntermediateCuffPressureParser.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/IntermediateCuffPressureParser.java
index 109b7e6c..632dc5e2 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/IntermediateCuffPressureParser.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/IntermediateCuffPressureParser.java
@@ -21,11 +21,9 @@
*/
package no.nordicsemi.android.nrftoolbox.parser;
-import java.util.Calendar;
-import java.util.Locale;
-
import no.nordicsemi.android.ble.data.Data;
+@SuppressWarnings("ConstantConditions")
public class IntermediateCuffPressureParser {
public static String parse(final Data data) {
final StringBuilder builder = new StringBuilder();
@@ -48,15 +46,8 @@ public class IntermediateCuffPressureParser {
// parse timestamp if present
if (timestampPresent) {
- final Calendar calendar = Calendar.getInstance();
- calendar.set(Calendar.YEAR, data.getIntValue(Data.FORMAT_UINT16, offset));
- calendar.set(Calendar.MONTH, data.getIntValue(Data.FORMAT_UINT8, offset + 2));
- calendar.set(Calendar.DAY_OF_MONTH, data.getIntValue(Data.FORMAT_UINT8, offset + 3));
- calendar.set(Calendar.HOUR_OF_DAY, data.getIntValue(Data.FORMAT_UINT8, offset + 4));
- calendar.set(Calendar.MINUTE, data.getIntValue(Data.FORMAT_UINT8, offset + 5));
- calendar.set(Calendar.SECOND, data.getIntValue(Data.FORMAT_UINT8, offset + 6));
+ builder.append("Timestamp: ").append(DateTimeParser.parse(data, offset));
offset += 7;
- builder.append(String.format(Locale.US, "\nTimestamp: %1$tT %1$te.%1$tm.%1$tY", calendar));
}
// parse pulse rate if present
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/RSCMeasurementParser.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/RSCMeasurementParser.java
index 7f7ff96b..6d196229 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/RSCMeasurementParser.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/RSCMeasurementParser.java
@@ -25,6 +25,7 @@ import java.util.Locale;
import no.nordicsemi.android.ble.data.Data;
+@SuppressWarnings("ConstantConditions")
public class RSCMeasurementParser {
private static final byte INSTANTANEOUS_STRIDE_LENGTH_PRESENT = 0x01; // 1 bit
private static final byte TOTAL_DISTANCE_PRESENT = 0x02; // 1 bit
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/RecordAccessControlPointParser.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/RecordAccessControlPointParser.java
index 2362494d..0ef5954c 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/RecordAccessControlPointParser.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/RecordAccessControlPointParser.java
@@ -23,6 +23,7 @@ package no.nordicsemi.android.nrftoolbox.parser;
import no.nordicsemi.android.ble.data.Data;
+@SuppressWarnings("ConstantConditions")
public class RecordAccessControlPointParser {
private final static int OP_CODE_REPORT_STORED_RECORDS = 1;
private final static int OP_CODE_DELETE_STORED_RECORDS = 2;
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/TemperatureMeasurementParser.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/TemperatureMeasurementParser.java
index 2ddd58ad..cdefad70 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/TemperatureMeasurementParser.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/TemperatureMeasurementParser.java
@@ -25,6 +25,7 @@ import java.util.Locale;
import no.nordicsemi.android.ble.data.Data;
+@SuppressWarnings("ConstantConditions")
public class TemperatureMeasurementParser {
private static final byte TEMPERATURE_UNIT_FLAG = 0x01; // 1 bit
private static final byte TIMESTAMP_FLAG = 0x02; // 1 bits
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/TemperatureTypeParser.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/TemperatureTypeParser.java
index e29f81b1..10d755ed 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/TemperatureTypeParser.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/TemperatureTypeParser.java
@@ -23,6 +23,7 @@ package no.nordicsemi.android.nrftoolbox.parser;
import no.nordicsemi.android.ble.data.Data;
+@SuppressWarnings("ConstantConditions")
public class TemperatureTypeParser {
public static String parse(final Data data) {
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/TemplateParser.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/TemplateParser.java
index 6d244353..ed0490a4 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/TemplateParser.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/parser/TemplateParser.java
@@ -21,21 +21,24 @@
*/
package no.nordicsemi.android.nrftoolbox.parser;
-import android.bluetooth.BluetoothGattCharacteristic;
+import no.nordicsemi.android.ble.data.Data;
// TODO this method may be used for developing purposes to log the data from your device using the nRF Logger application.
+
+@SuppressWarnings("ConstantConditions")
public class TemplateParser {
// TODO add some flags, if needed
private static final byte HEART_RATE_VALUE_FORMAT = 0x01; // 1 bit
/**
* This method converts the value of the characteristic to the String. The String is then logged in the nRF logger log session
- * @param characteristic the characteristic to be parsed
+ * @param data the characteristic data to be parsed
* @return human readable value of the characteristic
*/
- public static String parse(final BluetoothGattCharacteristic characteristic) {
+ @SuppressWarnings("UnusedAssignment")
+ public static String parse(final Data data) {
int offset = 0;
- final int flags = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset++);
+ final int flags = data.getIntValue(Data.FORMAT_UINT8, offset++);
/*
* In the template we are using the HRM values as an example.
@@ -45,14 +48,12 @@ public class TemplateParser {
final boolean value16bit = (flags & HEART_RATE_VALUE_FORMAT) > 0;
// heart rate value is 8 or 16 bit long
- int value = characteristic.getIntValue(value16bit ? BluetoothGattCharacteristic.FORMAT_UINT16 : BluetoothGattCharacteristic.FORMAT_UINT8, offset++); // bits per minute
+ int value = data.getIntValue(value16bit ? Data.FORMAT_UINT16 : Data.FORMAT_UINT8, offset++); // bits per minute
if (value16bit)
offset++;
// TODO parse more data
- final StringBuilder builder = new StringBuilder();
- builder.append("Template Measurement: ").append(value).append(" bpm");
- return builder.toString();
+ return "Template Measurement: " + value + " bpm";
}
}
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/proximity/LinkLossFragment.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/proximity/LinkLossFragment.java
index 79d62949..1916a777 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/proximity/LinkLossFragment.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/proximity/LinkLossFragment.java
@@ -52,9 +52,10 @@ public class LinkLossFragment extends DialogFragment {
}
@NonNull
- @Override
+ @Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
- return new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.app_name)).setMessage(getString(R.string.proximity_notification_linkloss_alert, mName))
+ return new AlertDialog.Builder(requireContext())
+ .setTitle(getString(R.string.app_name)).setMessage(getString(R.string.proximity_notification_linkloss_alert, mName))
.setPositiveButton(R.string.ok, null).create();
}
}
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 1489b061..b3e4ad07 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
@@ -62,7 +62,8 @@ class ProximityManager extends BatteryManager {
}
/**
- * BluetoothGatt callbacks for connection/disconnection, service discovery, receiving indication, etc
+ * BluetoothGatt callbacks for connection/disconnection, service discovery,
+ * receiving indication, etc.
*/
private final BatteryManagerGattCallback mGattCallback = new BatteryManagerGattCallback() {
@@ -105,7 +106,7 @@ class ProximityManager extends BatteryManager {
/**
* Toggles the immediate alert on the target device.
*
- * @return true if alarm has been enabled, false if disabled
+ * @return True if alarm has been enabled, false if disabled.
*/
public boolean toggleImmediateAlert() {
writeImmediateAlert(!mAlertOn);
@@ -113,9 +114,9 @@ class ProximityManager extends BatteryManager {
}
/**
- * Writes the HIGH ALERT or NO ALERT command to the target device
+ * Writes the HIGH ALERT or NO ALERT command to the target device.
*
- * @param on true to enable the alarm on proximity tag, false to disable it
+ * @param on true to enable the alarm on proximity tag, false to disable it.
*/
public void writeImmediateAlert(final boolean on) {
if (!isConnected())
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/proximity/ProximityServerManager.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/proximity/ProximityServerManager.java
index f8d80830..cf54f890 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/proximity/ProximityServerManager.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/proximity/ProximityServerManager.java
@@ -64,9 +64,14 @@ class ProximityServerManager {
private boolean mServerReady;
public interface OnServerOpenCallback {
- /** Method called when the GATT server was created and all services were added successfully. */
+ /**
+ * Method called when the GATT server was created and all services were added successfully.
+ */
void onGattServerOpen();
- /** Method called when the GATT server failed to open and initialize services. -1 is returned when the server failed to start. */
+ /**
+ * Method called when the GATT server failed to open and initialize services.
+ * -1 is returned when the server failed to start.
+ */
void onGattServerFailed(final int error);
}
@@ -77,6 +82,7 @@ class ProximityServerManager {
/**
* Sets the logger object. Logger is used to create logs in nRF Logger application.
+ *
* @param logger the logger object
*/
public void setLogger(final IDeviceLogger logger) {
@@ -86,8 +92,9 @@ class ProximityServerManager {
/**
* Opens GATT server and creates 2 services: Link Loss Service and Immediate Alert Service.
* The callback is called when initialization is complete.
- * @param context the context
- * @param callback optional callback notifying when all services has been added
+ *
+ * @param context the context.
+ * @param callback optional callback notifying when all services has been added.
*/
public void openGattServer(final Context context, final OnServerOpenCallback callback) {
// Is the server already open?
@@ -133,10 +140,12 @@ class ProximityServerManager {
}
/**
- * This method notifies the Android that the Proximity profile will use the server connection to given device.
- * If the server hasn't been open this method does nothing. The {@link #cancelConnection(BluetoothDevice)} method
- * should be called when the connection is no longer used.
- * @param device target device
+ * This method notifies the Android that the Proximity profile will use the server connection
+ * to given device. If the server hasn't been open this method does nothing.
+ * The {@link #cancelConnection(BluetoothDevice)} method should be called when the connection
+ * is no longer used.
+ *
+ * @param device the target device.
*/
public void openConnection(final BluetoothDevice device) {
if (mBluetoothGattServer != null) {
@@ -147,22 +156,26 @@ class ProximityServerManager {
}
/**
- * Cancels the connection to the given device. This notifies Android that this profile will no longer
- * use this connection and it can be disconnected. In practice, this method does not disconnect, so
- * if the remote device decides still to use the phone's GATT server it will be able to do so.
- * This bug/feature can be tested using a proximity tag that does not release its connection when it got
- * disconnected:
+ * Cancels the connection to the given device. This notifies Android that this profile will
+ * no longer use this connection and it can be disconnected. In practice, this method does
+ * not disconnect, so if the remote device decides still to use the phone's GATT server it
+ * will be able to do so.
+ *
+ * This bug/feature can be tested using a proximity tag that does not release its connection
+ * when it got disconnected:
*
* - Connect to your Proximity Tag.
- * - Verify that the bidirectional connection works - test the FIND ME button in nRF Toolbox and
- * the FIND PHONE button on the tag.
+ * - Verify that the bidirectional connection works - test the FIND ME button in
+ * nRF Toolbox and the FIND PHONE button on the tag.
* - Disconnect from the tag
- * - When the device disappear from the list of devices click the FIND PHONE button on the tag.
- * Your phone should still trigger an alarm, as the connection tag->phone is still active.
+ * - When the device disappear from the list of devices click the FIND PHONE button on
+ * the tag. Your phone should still trigger an alarm, as the connection tag->phone
+ * is still active.
*
- * In order to avoid this issue make sure that your tag disconnects gently from phone when it got disconnected itself.
- *
- * @param device the device that will no longer be used
+ * In order to avoid this issue make sure that your tag disconnects gently from phone when it
+ * got disconnected itself.
+ *
+ * @param device the device that will no longer be used.
*/
public void cancelConnection(final BluetoothDevice device) {
if (mBluetoothGattServer != null) {
@@ -174,26 +187,34 @@ class ProximityServerManager {
private void addImmediateAlertService() {
/*
- * This method must be called in UI thread. It works fine on Nexus devices but if called from other thread (e.g. from onServiceAdded in gatt server callback) it hangs the app.
+ * This method must be called in UI thread. It works fine on Nexus devices but if called
+ * from other thread (e.g. from onServiceAdded in gatt server callback) it hangs the app.
*/
- final BluetoothGattCharacteristic alertLevel = new BluetoothGattCharacteristic(ALERT_LEVEL_CHARACTERISTIC_UUID, BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE,
- BluetoothGattCharacteristic.PERMISSION_WRITE);
+ final BluetoothGattCharacteristic alertLevel =
+ new BluetoothGattCharacteristic(ALERT_LEVEL_CHARACTERISTIC_UUID,
+ BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE,
+ BluetoothGattCharacteristic.PERMISSION_WRITE);
alertLevel.setValue(NO_ALERT);
- final BluetoothGattService immediateAlertService = new BluetoothGattService(IMMEDIATE_ALERT_SERVICE_UUID, BluetoothGattService.SERVICE_TYPE_PRIMARY);
+ final BluetoothGattService immediateAlertService =
+ new BluetoothGattService(IMMEDIATE_ALERT_SERVICE_UUID, BluetoothGattService.SERVICE_TYPE_PRIMARY);
immediateAlertService.addCharacteristic(alertLevel);
mBluetoothGattServer.addService(immediateAlertService);
}
- private void addLinklossService() {
+ private void addLinkLossService() {
/*
- * This method must be called in UI thread. It works fine on Nexus devices but if called from other thread (e.g. from onServiceAdded in gatt server callback) it hangs the app.
+ * This method must be called in UI thread. It works fine on Nexus devices but if called
+ * from other thread (e.g. from onServiceAdded in gatt server callback) it hangs the app.
*/
- final BluetoothGattCharacteristic linklossAlertLevel = new BluetoothGattCharacteristic(ALERT_LEVEL_CHARACTERISTIC_UUID, BluetoothGattCharacteristic.PROPERTY_WRITE
- | BluetoothGattCharacteristic.PROPERTY_READ, BluetoothGattCharacteristic.PERMISSION_WRITE | BluetoothGattCharacteristic.PERMISSION_READ);
- linklossAlertLevel.setValue(HIGH_ALERT);
- final BluetoothGattService linklossService = new BluetoothGattService(LINKLOSS_SERVICE_UUID, BluetoothGattService.SERVICE_TYPE_PRIMARY);
- linklossService.addCharacteristic(linklossAlertLevel);
- mBluetoothGattServer.addService(linklossService);
+ final BluetoothGattCharacteristic linkLossAlertLevel =
+ new BluetoothGattCharacteristic(ALERT_LEVEL_CHARACTERISTIC_UUID,
+ BluetoothGattCharacteristic.PROPERTY_WRITE | BluetoothGattCharacteristic.PROPERTY_READ,
+ BluetoothGattCharacteristic.PERMISSION_WRITE | BluetoothGattCharacteristic.PERMISSION_READ);
+ linkLossAlertLevel.setValue(HIGH_ALERT);
+ final BluetoothGattService linkLossService =
+ new BluetoothGattService(LINKLOSS_SERVICE_UUID, BluetoothGattService.SERVICE_TYPE_PRIMARY);
+ linkLossService.addCharacteristic(linkLossAlertLevel);
+ mBluetoothGattServer.addService(linkLossService);
}
private final BluetoothGattServerCallback mGattServerCallbacks = new BluetoothGattServerCallback() {
@@ -203,7 +224,7 @@ class ProximityServerManager {
// Adding another service from callback thread fails on Samsung S4 with Android 4.3
mHandler.post(() -> {
if (IMMEDIATE_ALERT_SERVICE_UUID.equals(service.getUuid())) {
- addLinklossService();
+ addLinkLossService();
} else {
mServerReady = true;
// Both services has been added
@@ -222,23 +243,31 @@ class ProximityServerManager {
@Override
public void onConnectionStateChange(final BluetoothDevice device, final int status, final int newState) {
- mLogger.log(device, LogContract.Log.Level.DEBUG, "[Server callback] Connection state changed with status: " + status + " and new state: " + stateToString(newState) + " (" + newState + ")");
+ mLogger.log(device, LogContract.Log.Level.DEBUG,
+ "[Server callback] Connection state changed with status: " + status
+ + " and new state: " + stateToString(newState) + " (" + newState + ")");
if (status == BluetoothGatt.GATT_SUCCESS) {
if (newState == BluetoothGatt.STATE_CONNECTED) {
- mLogger.log(device, LogContract.Log.Level.INFO, "[Server] Device with address " + device.getAddress() + " connected");
+ mLogger.log(device, LogContract.Log.Level.INFO,
+ "[Server] Device with address " + device.getAddress() + " connected");
} else {
mLogger.log(device, LogContract.Log.Level.INFO, "[Server] Device disconnected");
mCallbacks.onAlarmStopped(device);
}
} else {
- mLogger.log(device, LogContract.Log.Level.ERROR, "[Server] Error " + status + " (0x" + Integer.toHexString(status) + "): " + GattError.parseConnectionError(status));
+ mLogger.log(device, LogContract.Log.Level.ERROR, "[Server] Error " + status +
+ " (0x" + Integer.toHexString(status) + "): " + GattError.parseConnectionError(status));
}
}
@Override
- public void onCharacteristicReadRequest(final BluetoothDevice device, final int requestId, final int offset, final BluetoothGattCharacteristic characteristic) {
- mLogger.log(device, LogContract.Log.Level.DEBUG, "[Server callback] Read request for characteristic " + characteristic.getUuid() + " (requestId=" + requestId + ", offset=" + offset + ")");
- mLogger.log(device, LogContract.Log.Level.INFO, "[Server] READ request for characteristic " + characteristic.getUuid() + " received");
+ public void onCharacteristicReadRequest(final BluetoothDevice device, final int requestId,
+ final int offset, final BluetoothGattCharacteristic characteristic) {
+ mLogger.log(device, LogContract.Log.Level.DEBUG,
+ "[Server callback] Read request for characteristic " + characteristic.getUuid()
+ + " (requestId=" + requestId + ", offset=" + offset + ")");
+ mLogger.log(device, LogContract.Log.Level.INFO,
+ "[Server] READ request for characteristic " + characteristic.getUuid() + " received");
byte[] value = characteristic.getValue();
if (value != null && offset > 0) {
@@ -246,21 +275,26 @@ class ProximityServerManager {
System.arraycopy(value, offset, offsetValue, 0, offsetValue.length);
value = offsetValue;
}
- if (value != null)
- mLogger.log(device, LogContract.Log.Level.DEBUG, "server.sendResponse(GATT_SUCCESS, value=" + ParserUtils.parseDebug(value) + ")");
- else
+ if (value != null) {
+ mLogger.log(device, LogContract.Log.Level.DEBUG,
+ "server.sendResponse(GATT_SUCCESS, value=" + ParserUtils.parseDebug(value) + ")");
+ } else {
mLogger.log(device, LogContract.Log.Level.DEBUG, "server.sendResponse(GATT_SUCCESS, value=null)");
+ }
mBluetoothGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, offset, value);
mLogger.log(device, LogContract.Log.Level.VERBOSE, "[Server] Response sent");
}
@Override
- public void onCharacteristicWriteRequest(final BluetoothDevice device, final int requestId, final BluetoothGattCharacteristic characteristic, final boolean preparedWrite,
+ public void onCharacteristicWriteRequest(final BluetoothDevice device, final int requestId,
+ final BluetoothGattCharacteristic characteristic, final boolean preparedWrite,
final boolean responseNeeded, final int offset, final byte[] value) {
mLogger.log(device, LogContract.Log.Level.DEBUG, "[Server callback] Write request to characteristic " + characteristic.getUuid()
- + " (requestId=" + requestId + ", prepareWrite=" + preparedWrite + ", responseNeeded=" + responseNeeded + ", offset=" + offset + ", value=" + ParserUtils.parseDebug(value) + ")");
+ + " (requestId=" + requestId + ", prepareWrite=" + preparedWrite + ", responseNeeded=" + responseNeeded
+ + ", offset=" + offset + ", value=" + ParserUtils.parseDebug(value) + ")");
final String writeType = !responseNeeded ? "WRITE NO RESPONSE" : "WRITE COMMAND";
- mLogger.log(device, LogContract.Log.Level.INFO, "[Server] " + writeType + " request for characteristic " + characteristic.getUuid() + " received, value: " + ParserUtils.parse(value));
+ mLogger.log(device, LogContract.Log.Level.INFO, "[Server] " + writeType
+ + " request for characteristic " + characteristic.getUuid() + " received, value: " + ParserUtils.parse(value));
if (offset == 0) {
characteristic.setValue(value);
@@ -274,23 +308,29 @@ class ProximityServerManager {
if (!preparedWrite && value != null && value.length == 1) { // small validation
if (value[0] != NO_ALERT[0]) {
- mLogger.log(device, LogContract.Log.Level.APPLICATION, "[Server] Immediate alarm request received: " + AlertLevelParser.parse(characteristic));
+ mLogger.log(device, LogContract.Log.Level.APPLICATION,
+ "[Server] Immediate alarm request received: " + AlertLevelParser.parse(characteristic));
mCallbacks.onAlarmTriggered(device);
} else {
- mLogger.log(device, LogContract.Log.Level.APPLICATION, "[Server] Immediate alarm request received: OFF");
+ mLogger.log(device, LogContract.Log.Level.APPLICATION,
+ "[Server] Immediate alarm request received: OFF");
mCallbacks.onAlarmStopped(device);
}
}
- mLogger.log(device, LogContract.Log.Level.DEBUG, "server.sendResponse(GATT_SUCCESS, offset=" + offset + ", value=" + ParserUtils.parseDebug(value) + ")");
+ mLogger.log(device, LogContract.Log.Level.DEBUG, "server.sendResponse(GATT_SUCCESS, offset="
+ + offset + ", value=" + ParserUtils.parseDebug(value) + ")");
mBluetoothGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, offset, null);
mLogger.log(device, LogContract.Log.Level.VERBOSE, "[Server] Response sent");
}
@Override
- public void onDescriptorReadRequest(final BluetoothDevice device, final int requestId, final int offset, final BluetoothGattDescriptor descriptor) {
- mLogger.log(device, LogContract.Log.Level.DEBUG, "[Server callback] Write request to descriptor " + descriptor.getUuid() + " (requestId=" + requestId + ", offset=" + offset + ")");
- mLogger.log(device, LogContract.Log.Level.INFO, "[Server] READ request for descriptor " + descriptor.getUuid() + " received");
+ public void onDescriptorReadRequest(final BluetoothDevice device, final int requestId,
+ final int offset, final BluetoothGattDescriptor descriptor) {
+ mLogger.log(device, LogContract.Log.Level.DEBUG,
+ "[Server callback] Write request to descriptor " + descriptor.getUuid() + " (requestId=" + requestId + ", offset=" + offset + ")");
+ mLogger.log(device, LogContract.Log.Level.INFO,
+ "[Server] READ request for descriptor " + descriptor.getUuid() + " received");
// This method is not supported
mLogger.log(device, LogContract.Log.Level.WARNING, "[Server] Operation not supported");
mLogger.log(device, LogContract.Log.Level.DEBUG, "[Server] server.sendResponse(GATT_REQUEST_NOT_SUPPORTED)");
@@ -299,10 +339,12 @@ class ProximityServerManager {
}
@Override
- public void onDescriptorWriteRequest(final BluetoothDevice device, final int requestId, final BluetoothGattDescriptor descriptor, final boolean preparedWrite,
+ public void onDescriptorWriteRequest(final BluetoothDevice device, final int requestId,
+ final BluetoothGattDescriptor descriptor, final boolean preparedWrite,
final boolean responseNeeded, final int offset, final byte[] value) {
mLogger.log(device, LogContract.Log.Level.DEBUG, "[Server callback] Write request to descriptor " + descriptor.getUuid()
- + " (requestId=" + requestId + ", prepareWrite=" + preparedWrite + ", responseNeeded=" + responseNeeded + ", offset=" + offset + ", value=" + ParserUtils.parse(value) + ")");
+ + " (requestId=" + requestId + ", prepareWrite=" + preparedWrite + ", responseNeeded=" + responseNeeded
+ + ", offset=" + offset + ", value=" + ParserUtils.parse(value) + ")");
mLogger.log(device, LogContract.Log.Level.INFO, "[Server] READ request for descriptor " + descriptor.getUuid() + " received");
// This method is not supported
mLogger.log(device, LogContract.Log.Level.WARNING, "[Server] Operation not supported");
@@ -313,7 +355,8 @@ class ProximityServerManager {
@Override
public void onExecuteWrite(final BluetoothDevice device, final int requestId, final boolean execute) {
- mLogger.log(device, LogContract.Log.Level.DEBUG, "[Server callback] Execute write request (requestId=" + requestId + ", execute=" + execute + ")");
+ mLogger.log(device, LogContract.Log.Level.DEBUG,
+ "[Server callback] Execute write request (requestId=" + requestId + ", execute=" + execute + ")");
// This method is not supported
mLogger.log(device, LogContract.Log.Level.WARNING, "[Server] Operation not supported");
mLogger.log(device, LogContract.Log.Level.DEBUG, "[Server] server.sendResponse(GATT_REQUEST_NOT_SUPPORTED)");
@@ -323,9 +366,10 @@ class ProximityServerManager {
};
/**
- * Converts the connection state to String value
- * @param state the connection state
- * @return state as String
+ * Converts the connection state to String value.
+ *
+ * @param state the connection state.
+ * @return The state as String.
*/
private String stateToString(final int state) {
switch (state) {
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/proximity/ProximityService.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/proximity/ProximityService.java
index 94b386b7..1357340d 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/proximity/ProximityService.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/proximity/ProximityService.java
@@ -85,13 +85,15 @@ public class ProximityService extends BleMulticonnectProfileService implements P
private final static int MAX_ATTEMPTS = 1;
/**
- * This local binder is an interface for the bonded activity to operate with the proximity sensor
+ * This local binder is an interface for the bonded activity to operate with the proximity
+ * sensor.
*/
public class ProximityBinder extends LocalBinder {
/**
* Toggles the Immediate Alert on given remote device.
- * @param device the connected device
- * @return true if alarm has been enabled, false if disabled
+ *
+ * @param device the connected device.
+ * @return True if alarm has been enabled, false if disabled.
*/
public boolean toggleImmediateAlert(final BluetoothDevice device) {
final ProximityManager manager = (ProximityManager) getBleManager(device);
@@ -99,10 +101,11 @@ public class ProximityService extends BleMulticonnectProfileService implements P
}
/**
- * Returns the current alarm state on given device. This value is not read from the device, it's just the last value written to it
- * (initially false).
- * @param device the connected device
- * @return true if alarm has been enabled, false if disabled
+ * Returns the current alarm state on given device. This value is not read from the device,
+ * it's just the last value written to it (initially false).
+ *
+ * @param device the connected device.
+ * @return True if alarm has been enabled, false if disabled.
*/
public boolean isImmediateAlertOn(final BluetoothDevice device) {
final ProximityManager manager = (ProximityManager) getBleManager(device);
@@ -111,9 +114,10 @@ public class ProximityService extends BleMulticonnectProfileService implements P
/**
* Returns the last received battery level value.
- * @param device the device of which battery level should be returned
- * @return battery value or null if no value was received or Battery Level characteristic was not found,
- * or the device is disconnected
+ *
+ * @param device the device of which battery level should be returned.
+ * @return Battery value or null if no value was received or Battery Level characteristic
+ * was not found, or the device is disconnected.
*/
public Integer getBatteryLevel(final BluetoothDevice device) {
final ProximityManager manager = (ProximityManager) getBleManager(device);
@@ -132,7 +136,8 @@ public class ProximityService extends BleMulticonnectProfileService implements P
}
/**
- * This broadcast receiver listens for {@link #ACTION_DISCONNECT} that may be fired by pressing Disconnect action button on the notification.
+ * This broadcast receiver listens for {@link #ACTION_DISCONNECT} that may be fired by pressing
+ * Disconnect action button on the notification.
*/
private final BroadcastReceiver mDisconnectActionBroadcastReceiver = new BroadcastReceiver() {
@Override
@@ -144,7 +149,8 @@ public class ProximityService extends BleMulticonnectProfileService implements P
};
/**
- * This broadcast receiver listens for {@link #ACTION_FIND} or {@link #ACTION_SILENT} that may be fired by pressing Find me action button on the notification.
+ * This broadcast receiver listens for {@link #ACTION_FIND} or {@link #ACTION_SILENT} that may
+ * be fired by pressing Find me action button on the notification.
*/
private final BroadcastReceiver mToggleAlarmActionBroadcastReceiver = new BroadcastReceiver() {
@Override
@@ -200,7 +206,8 @@ public class ProximityService extends BleMulticonnectProfileService implements P
public void run() {
final Runnable that = this;
// Start the GATT Server only if Bluetooth is enabled
- mServerManager.openGattServer(ProximityService.this, new ProximityServerManager.OnServerOpenCallback() {
+ mServerManager.openGattServer(ProximityService.this,
+ new ProximityServerManager.OnServerOpenCallback() {
@Override
public void onGattServerOpen() {
// We are now ready to reconnect devices
@@ -237,8 +244,10 @@ public class ProximityService extends BleMulticonnectProfileService implements P
// When the activity rebinds to the service, remove the notification
cancelNotifications();
- // This method will read the Battery Level value from each connected device, if possible and then try to enable battery notifications (if it has NOTIFY property).
- // If the Battery Level characteristic has only the NOTIFY property, it will only try to enable notifications.
+ // This method will read the Battery Level value from each connected device, if possible
+ // and then try to enable battery notifications (if it has NOTIFY property).
+ // If the Battery Level characteristic has only the NOTIFY property, it will only try to
+ // enable notifications.
for (final BluetoothDevice device : getManagedDevices()) {
final ProximityManager manager = (ProximityManager) getBleManager(device);
manager.readBatteryLevelCharacteristic();
@@ -248,8 +257,8 @@ public class ProximityService extends BleMulticonnectProfileService implements P
@Override
public void onUnbind() {
- // When we are connected, but the application is not open, we are not really interested in battery level notifications.
- // But we will still be receiving other values, if enabled.
+ // When we are connected, but the application is not open, we are not really interested
+ // in battery level notifications. But we will still be receiving other values, if enabled.
for (final BluetoothDevice device : getManagedDevices()) {
final ProximityManager manager = (ProximityManager) getBleManager(device);
manager.disableBatteryLevelCharacteristicNotifications();
@@ -282,7 +291,7 @@ public class ProximityService extends BleMulticonnectProfileService implements P
if (!mBound) {
createBackgroundNotification();
if (BluetoothAdapter.getDefaultAdapter().isEnabled())
- createLinklossNotification(device);
+ createLinkLossNotification(device);
else
cancelNotification(device);
}
@@ -329,7 +338,9 @@ public class ProximityService extends BleMulticonnectProfileService implements P
private void createSummaryNotification() {
final NotificationCompat.Builder builder = getNotificationBuilder();
builder.setColor(ContextCompat.getColor(this, R.color.actionBarColorDark));
- builder.setShowWhen(false).setDefaults(0).setOngoing(true); // an ongoing notification will not be shown on Android Wear
+ builder.setShowWhen(false).setDefaults(0);
+ // An ongoing notification will not be shown on Android Wear.
+ builder.setOngoing(true);
builder.setGroup(PROXIMITY_GROUP_ID).setGroupSummary(true);
builder.setContentTitle(getString(R.string.app_name));
@@ -340,8 +351,8 @@ public class ProximityService extends BleMulticonnectProfileService implements P
final int numberOfManagedDevices = managedDevices.size();
if (numberOfManagedDevices == 1) {
final String name = getDeviceName(managedDevices.get(0));
- // We don't use plurals here, as we only have the default language and 'one' is not in every language (versions differ in %d or %s)
- // and throw an exception in e.g. in Chinese
+ // We don't use plurals here, as we only have the default language and 'one' is not
+ // in every language (versions differ in %d or %s) and throw an exception in e.g. in Chinese.
builder.setContentText(getString(R.string.proximity_notification_text_nothing_connected_one_disconnected, name));
} else {
builder.setContentText(getString(R.string.proximity_notification_text_nothing_connected_number_disconnected, numberOfManagedDevices));
@@ -390,27 +401,36 @@ public class ProximityService extends BleMulticonnectProfileService implements P
private void createNotificationForConnectedDevice(final BluetoothDevice device) {
final NotificationCompat.Builder builder = getNotificationBuilder();
builder.setColor(ContextCompat.getColor(this, R.color.actionBarColorDark));
- builder.setGroup(PROXIMITY_GROUP_ID).setDefaults(0).setOngoing(true); // an ongoing notification will not be shown on Android Wear
+ builder.setGroup(PROXIMITY_GROUP_ID).setDefaults(0);
+ // An ongoing notification will not be shown on Android Wear.
+ builder.setOngoing(true);
builder.setContentTitle(getString(R.string.proximity_notification_text, getDeviceName(device)));
// Add DISCONNECT action
final Intent disconnect = new Intent(ACTION_DISCONNECT);
disconnect.putExtra(EXTRA_DEVICE, device);
- final PendingIntent disconnectAction = PendingIntent.getBroadcast(this, DISCONNECT_REQ + device.hashCode(), disconnect, PendingIntent.FLAG_UPDATE_CURRENT);
+ final PendingIntent disconnectAction =
+ PendingIntent.getBroadcast(this, DISCONNECT_REQ + device.hashCode(),
+ disconnect, PendingIntent.FLAG_UPDATE_CURRENT);
builder.addAction(new NotificationCompat.Action(R.drawable.ic_action_bluetooth, getString(R.string.proximity_action_disconnect), disconnectAction));
- builder.setSortKey(getDeviceName(device) + device.getAddress()); // This will keep the same order of notification even after an action was clicked on one of them
+ // This will keep the same order of notification even after an action was clicked on one of them.
+ builder.setSortKey(getDeviceName(device) + device.getAddress());
// Add FIND or SILENT action
final ProximityManager manager = (ProximityManager) getBleManager(device);
if (manager.isAlertEnabled()) {
final Intent silentAllIntent = new Intent(ACTION_SILENT);
silentAllIntent.putExtra(EXTRA_DEVICE, device);
- final PendingIntent silentAction = PendingIntent.getBroadcast(this, SILENT_REQ + device.hashCode(), silentAllIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+ final PendingIntent silentAction =
+ PendingIntent.getBroadcast(this, SILENT_REQ + device.hashCode(),
+ silentAllIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.addAction(new NotificationCompat.Action(R.drawable.ic_stat_notify_proximity_silent, getString(R.string.proximity_action_silent), silentAction));
} else {
final Intent findAllIntent = new Intent(ACTION_FIND);
findAllIntent.putExtra(EXTRA_DEVICE, device);
- final PendingIntent findAction = PendingIntent.getBroadcast(this, FIND_REQ + device.hashCode(), findAllIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+ final PendingIntent findAction =
+ PendingIntent.getBroadcast(this, FIND_REQ + device.hashCode(),
+ findAllIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.addAction(new NotificationCompat.Action(R.drawable.ic_stat_notify_proximity_find, getString(R.string.proximity_action_find), findAction));
}
@@ -422,15 +442,18 @@ public class ProximityService extends BleMulticonnectProfileService implements P
/**
* Creates a notification showing information about a device that got disconnected.
*/
- private void createLinklossNotification(final BluetoothDevice device) {
+ private void createLinkLossNotification(final BluetoothDevice device) {
final NotificationCompat.Builder builder = getNotificationBuilder();
builder.setColor(ContextCompat.getColor(this, R.color.orange));
final Uri notificationUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
- builder.setSound(notificationUri, AudioManager.STREAM_ALARM); // make sure the sound is played even in DND mode
+ // Make sure the sound is played even in DND mode
+ builder.setSound(notificationUri, AudioManager.STREAM_ALARM);
builder.setPriority(NotificationCompat.PRIORITY_HIGH);
builder.setCategory(NotificationCompat.CATEGORY_ALARM);
- builder.setShowWhen(true).setOngoing(false); // an ongoing notification would not be shown on Android Wear
+ builder.setShowWhen(true);
+ // An ongoing notification would not be shown on Android Wear.
+ builder.setOngoing(false);
// This notification is to be shown not in a group
final String name = getDeviceName(device);
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/rsc/RSCManager.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/rsc/RSCManager.java
index 4ddf9362..d9081881 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/rsc/RSCManager.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/rsc/RSCManager.java
@@ -57,7 +57,8 @@ public class RSCManager extends BatteryManager {
}
/**
- * BluetoothGatt callbacks for connection/disconnection, service discovery, receiving indication, etc
+ * BluetoothGatt callbacks for connection/disconnection, service discovery,
+ * receiving indication, etc.
*/
private final BatteryManagerGattCallback mGattCallback = new BatteryManagerGattCallback() {
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/template/TemplateManager.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/template/TemplateManager.java
index a8735a13..584ec48b 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/template/TemplateManager.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/template/TemplateManager.java
@@ -34,6 +34,7 @@ import no.nordicsemi.android.ble.BleManager;
import no.nordicsemi.android.ble.data.Data;
import no.nordicsemi.android.log.LogContract;
import no.nordicsemi.android.nrftoolbox.battery.BatteryManager;
+import no.nordicsemi.android.nrftoolbox.parser.TemplateParser;
import no.nordicsemi.android.nrftoolbox.template.callback.TemplateDataCallback;
/**
@@ -46,23 +47,23 @@ import no.nordicsemi.android.nrftoolbox.template.callback.TemplateDataCallback;
public class TemplateManager extends BatteryManager {
// TODO Replace the services and characteristics below to match your device.
/**
- * The service UUID
+ * The service UUID.
*/
static final UUID SERVICE_UUID = UUID.fromString("0000180D-0000-1000-8000-00805f9b34fb"); // Heart Rate service
/**
- * A UUID of a characteristic with notify property
+ * A UUID of a characteristic with notify property.
*/
private static final UUID MEASUREMENT_CHARACTERISTIC_UUID = UUID.fromString("00002A37-0000-1000-8000-00805f9b34fb"); // Heart Rate Measurement
/**
- * A UUID of a characteristic with read property
+ * A UUID of a characteristic with read property.
*/
private static final UUID READABLE_CHARACTERISTIC_UUID = UUID.fromString("00002A38-0000-1000-8000-00805f9b34fb"); // Body Sensor Location
/**
- * Some other service UUID
+ * Some other service UUID.
*/
private static final UUID OTHER_SERVICE_UUID = UUID.fromString("00001800-0000-1000-8000-00805f9b34fb"); // Generic Access service
/**
- * A UUID of a characteristic with write property
+ * A UUID of a characteristic with write property.
*/
private static final UUID WRITABLE_CHARACTERISTIC_UUID = UUID.fromString("00002A00-0000-1000-8000-00805f9b34fb"); // Device Name
@@ -80,7 +81,8 @@ public class TemplateManager extends BatteryManager {
}
/**
- * BluetoothGatt callbacks for connection/disconnection, service discovery, receiving indication, etc
+ * BluetoothGatt callbacks for connection/disconnection, service discovery,
+ * receiving indication, etc.
*/
private final BatteryManagerGattCallback mGattCallback = new BatteryManagerGattCallback() {
@@ -111,6 +113,12 @@ public class TemplateManager extends BatteryManager {
setNotificationCallback(mRequiredCharacteristic)
// This callback will be called each time the notification is received
.with(new TemplateDataCallback() {
+ @Override
+ public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
+ log(LogContract.Log.Level.APPLICATION, TemplateParser.parse(data));
+ super.onDataReceived(device, data);
+ }
+
@Override
public void onSampleValueReceived(@NonNull final BluetoothDevice device, final int value) {
// Let's lass received data to the service
@@ -194,7 +202,7 @@ public class TemplateManager extends BatteryManager {
log(LogContract.Log.Level.WARNING, "Value is empty!");
}
})
- .enqueue();
+ .enqueue();
}
};
@@ -220,6 +228,6 @@ public class TemplateManager extends BatteryManager {
.done(device -> log(LogContract.Log.Level.APPLICATION, "Device name set to \"" + parameter + "\""))
// Callback called when write has failed.
.fail((device, status) -> log(LogContract.Log.Level.WARNING, "Failed to change device name"))
- .enqueue();
+ .enqueue();
}
}
diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/uart/UARTManager.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/uart/UARTManager.java
index 0378fb9e..9ed288b4 100644
--- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/uart/UARTManager.java
+++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/uart/UARTManager.java
@@ -57,7 +57,8 @@ public class UARTManager extends BleManager {
}
/**
- * BluetoothGatt callbacks for connection/disconnection, service discovery, receiving indication, etc.
+ * BluetoothGatt callbacks for connection/disconnection, service discovery,
+ * receiving indication, etc.
*/
private final BleManagerGattCallback mGattCallback = new BleManagerGattCallback() {