From 6dd7b9e53080d55ed5b448979f995107023ae6c9 Mon Sep 17 00:00:00 2001 From: Aleksander Nowakowski Date: Mon, 16 Apr 2018 22:18:57 +0200 Subject: [PATCH] Adjusting to match BLE library changes, BPM and CSC done --- .../android/nrftoolbox/bpm/BPMActivity.java | 58 ++++-- .../android/nrftoolbox/bpm/BPMManager.java | 182 ++++++++++-------- .../nrftoolbox/bpm/BPMManagerCallbacks.java | 51 +---- .../android/nrftoolbox/cgms/CGMSManager.java | 35 ++-- .../android/nrftoolbox/csc/CSCActivity.java | 6 - .../android/nrftoolbox/csc/CSCManager.java | 54 +++--- .../nrftoolbox/csc/CSCManagerCallbacks.java | 11 +- .../android/nrftoolbox/csc/CSCService.java | 5 +- .../nrftoolbox/gls/GlucoseManager.java | 22 +-- .../android/nrftoolbox/hrs/HRSManager.java | 6 +- .../android/nrftoolbox/hts/HTSManager.java | 4 +- .../BloodPressureMeasurementParser.java | 33 ++-- .../IntermediateCuffPressureParser.java | 28 +-- .../profile/BleProfileActivity.java | 12 +- .../BleProfileExpandableListActivity.java | 18 +- .../BleProfileServiceReadyActivity.java | 12 +- .../BleMulticonnectProfileService.java | 3 + ...lticonnectProfileServiceReadyActivity.java | 10 +- .../android/nrftoolbox/rsc/RSCManager.java | 4 +- .../nrftoolbox/template/TemplateManager.java | 4 +- .../android/nrftoolbox/uart/UARTManager.java | 6 +- 21 files changed, 271 insertions(+), 293 deletions(-) diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/bpm/BPMActivity.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/bpm/BPMActivity.java index 7d4f9f3e..1beb19e6 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/bpm/BPMActivity.java +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/bpm/BPMActivity.java @@ -23,12 +23,16 @@ package no.nordicsemi.android.nrftoolbox.bpm; import android.bluetooth.BluetoothDevice; import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.widget.TextView; import java.util.Calendar; import java.util.UUID; import no.nordicsemi.android.ble.BleManager; +import no.nordicsemi.android.ble.profile.BloodPressureMeasurementCallback; +import no.nordicsemi.android.ble.profile.IntermediateCuffPressureCallback; import no.nordicsemi.android.nrftoolbox.R; import no.nordicsemi.android.nrftoolbox.profile.BleProfileActivity; @@ -45,6 +49,7 @@ public class BPMActivity extends BleProfileActivity implements BPMManagerCallbac private TextView mMeanAPUnitView; private TextView mPulseView; private TextView mTimestampView; + private TextView mBatteryLevelView; @Override protected void onCreateView(final Bundle savedInstanceState) { @@ -61,6 +66,7 @@ public class BPMActivity extends BleProfileActivity implements BPMManagerCallbac mMeanAPUnitView = findViewById(R.id.mean_ap_unit); mPulseView = findViewById(R.id.pulse); mTimestampView = findViewById(R.id.timestamp); + mBatteryLevelView = findViewById(R.id.battery); } @Override @@ -100,6 +106,7 @@ public class BPMActivity extends BleProfileActivity implements BPMManagerCallbac mMeanAPUnitView.setText(null); mPulseView.setText(R.string.not_available_value); mTimestampView.setText(R.string.not_available); + mBatteryLevelView.setText(R.string.not_available); } @Override @@ -113,48 +120,57 @@ public class BPMActivity extends BleProfileActivity implements BPMManagerCallbac } @Override - public void onBloodPressureMeasurementRead(final BluetoothDevice device, final float systolic, final float diastolic, final float meanArterialPressure, final int unit) { + public void onDeviceDisconnected(final BluetoothDevice device) { + super.onDeviceDisconnected(device); + runOnUiThread(() -> mBatteryLevelView.setText(R.string.not_available)); + } + + @Override + public void onBloodPressureMeasurementReceived(@NonNull final BluetoothDevice device, final float systolic, final float diastolic, final float meanArterialPressure, final int unit, @Nullable final Float pulseRate, @Nullable final Integer userID, @Nullable final BloodPressureMeasurementCallback.Status status, @Nullable final Calendar calendar) { runOnUiThread(() -> { mSystolicView.setText(String.valueOf(systolic)); mDiastolicView.setText(String.valueOf(diastolic)); mMeanAPView.setText(String.valueOf(meanArterialPressure)); + if (pulseRate != null) + mPulseView.setText(String.valueOf(pulseRate)); + else + mPulseView.setText(R.string.not_available_value); + if (calendar != null) + mTimestampView.setText(getString(R.string.bpm_timestamp, calendar)); + else + mTimestampView.setText(R.string.not_available); - mSystolicUnitView.setText(unit == UNIT_mmHG ? R.string.bpm_unit_mmhg : R.string.bpm_unit_kpa); - mDiastolicUnitView.setText(unit == UNIT_mmHG ? R.string.bpm_unit_mmhg : R.string.bpm_unit_kpa); - mMeanAPUnitView.setText(unit == UNIT_mmHG ? R.string.bpm_unit_mmhg : R.string.bpm_unit_kpa); + mSystolicUnitView.setText(unit == BloodPressureMeasurementCallback.UNIT_mmHG ? R.string.bpm_unit_mmhg : R.string.bpm_unit_kpa); + mDiastolicUnitView.setText(unit == BloodPressureMeasurementCallback.UNIT_mmHG ? R.string.bpm_unit_mmhg : R.string.bpm_unit_kpa); + mMeanAPUnitView.setText(unit == BloodPressureMeasurementCallback.UNIT_mmHG ? R.string.bpm_unit_mmhg : R.string.bpm_unit_kpa); }); } @Override - public void onIntermediateCuffPressureRead(final BluetoothDevice device, final float cuffPressure, final int unit) { + public void onIntermediateCuffPressureReceived(@NonNull final BluetoothDevice device, final float cuffPressure, final int unit, @Nullable final Float pulseRate, @Nullable final Integer userID, @Nullable final IntermediateCuffPressureCallback.Status status, @Nullable final Calendar calendar) { runOnUiThread(() -> { mSystolicView.setText(String.valueOf(cuffPressure)); mDiastolicView.setText(R.string.not_available_value); mMeanAPView.setText(R.string.not_available_value); + if (pulseRate != null) + mPulseView.setText(String.valueOf(pulseRate)); + else + mPulseView.setText(R.string.not_available_value); + if (calendar != null) + mTimestampView.setText(getString(R.string.bpm_timestamp, calendar)); + else + mTimestampView.setText(R.string.not_available); - mSystolicUnitView.setText(unit == UNIT_mmHG ? R.string.bpm_unit_mmhg : R.string.bpm_unit_kpa); + mSystolicUnitView.setText(unit == IntermediateCuffPressureCallback.UNIT_mmHG ? R.string.bpm_unit_mmhg : R.string.bpm_unit_kpa); mDiastolicUnitView.setText(null); mMeanAPUnitView.setText(null); }); } @Override - public void onPulseRateRead(final BluetoothDevice device, final float pulseRate) { + public void onBatteryLevelChanged(@NonNull final BluetoothDevice device, final int batteryLevel) { runOnUiThread(() -> { - if (pulseRate >= 0) - mPulseView.setText(String.valueOf(pulseRate)); - else - mPulseView.setText(R.string.not_available_value); - }); - } - - @Override - public void onTimestampRead(final BluetoothDevice device, final Calendar calendar) { - runOnUiThread(() -> { - if (calendar != null) - mTimestampView.setText(getString(R.string.bpm_timestamp, calendar)); - else - mTimestampView.setText(R.string.not_available); + mBatteryLevelView.setText(getString(R.string.battery, batteryLevel)); }); } } 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 f41c58b3..1bd9f2e1 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 @@ -21,32 +21,43 @@ */ package no.nordicsemi.android.nrftoolbox.bpm; +import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattService; import android.content.Context; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import java.util.Calendar; -import java.util.Deque; -import java.util.LinkedList; import java.util.UUID; import no.nordicsemi.android.ble.BleManager; -import no.nordicsemi.android.ble.Request; +import no.nordicsemi.android.ble.callback.Data; +import no.nordicsemi.android.ble.callback.profile.BatteryLevelDataCallback; +import no.nordicsemi.android.ble.callback.profile.BloodPressureMeasurementDataCallback; +import no.nordicsemi.android.ble.callback.profile.IntermediateCuffPressureDataCallback; +import no.nordicsemi.android.ble.profile.BloodPressureMeasurementCallback; +import no.nordicsemi.android.log.LogContract; import no.nordicsemi.android.log.Logger; import no.nordicsemi.android.nrftoolbox.parser.BloodPressureMeasurementParser; import no.nordicsemi.android.nrftoolbox.parser.IntermediateCuffPressureParser; +@SuppressWarnings({"unused", "WeakerAccess"}) public class BPMManager extends BleManager { - /** Blood Pressure service UUID */ + /** Blood Pressure service UUID. */ public final static UUID BP_SERVICE_UUID = UUID.fromString("00001810-0000-1000-8000-00805f9b34fb"); - /** Blood Pressure Measurement characteristic UUID */ + /** Blood Pressure Measurement characteristic UUID. */ private static final UUID BPM_CHARACTERISTIC_UUID = UUID.fromString("00002A35-0000-1000-8000-00805f9b34fb"); - /** Intermediate Cuff Pressure characteristic UUID */ + /** Intermediate Cuff Pressure characteristic UUID. */ private static final UUID ICP_CHARACTERISTIC_UUID = UUID.fromString("00002A36-0000-1000-8000-00805f9b34fb"); + /** Battery Service UUID. */ + private final static UUID BATTERY_SERVICE_UUID = UUID.fromString("0000180F-0000-1000-8000-00805f9b34fb"); + /** Battery Level characteristic UUID. */ + private final static UUID BATTERY_LEVEL_CHARACTERISTIC_UUID = UUID.fromString("00002A19-0000-1000-8000-00805f9b34fb"); private BluetoothGattCharacteristic mBPMCharacteristic, mICPCharacteristic; + private BluetoothGattCharacteristic mBatteryLevelCharacteristic; private static BPMManager managerInstance = null; @@ -69,23 +80,99 @@ public class BPMManager extends BleManager { return mGattCallback; } + public void readBatteryLevelCharacteristic() { + readCharacteristic(mBatteryLevelCharacteristic) + .with(new BatteryLevelDataCallback() { + @Override + public void onBatteryLevelChanged(@NonNull final BluetoothDevice device, final int batteryLevel) { + mCallbacks.onBatteryLevelChanged(device, batteryLevel); + } + + @Override + public void onInvalidDataReceived(@NonNull final BluetoothDevice device, final @NonNull Data data) { + log(LogContract.Log.Level.WARNING, "Invalid Battery Level data received: " + data); + } + }) + .fail(status -> log(LogContract.Log.Level.WARNING, "Battery Level characteristic not found")); + } + + public void enableBatteryLevelCharacteristicNotifications() { + // If the Battery Level characteristic is null, the request will be ignored + enableNotifications(mBatteryLevelCharacteristic) + .with(new BatteryLevelDataCallback() { + @Override + public void onBatteryLevelChanged(@NonNull final BluetoothDevice device, final int batteryLevel) { + mCallbacks.onBatteryLevelChanged(device, batteryLevel); + } + + @Override + public void onInvalidDataReceived(@NonNull final BluetoothDevice device, final @NonNull Data data) { + log(LogContract.Log.Level.WARNING, "Invalid Battery Level data received: " + data); + } + }) + .done(() -> log(LogContract.Log.Level.INFO, "Battery Level notifications enabled")) + .fail(status -> log(LogContract.Log.Level.WARNING, "Battery Level characteristic not found")); + } + + public void disableBatteryLevelCharacteristicNotifications() { + disableNotifications(mBatteryLevelCharacteristic) + .done(() -> log(LogContract.Log.Level.INFO, "Battery Level notifications disabled")); + } + /** * BluetoothGatt callbacks for connection/disconnection, service discovery, receiving notification, etc */ private final BleManagerGattCallback mGattCallback = new BleManagerGattCallback() { @Override - protected Deque initGatt(@NonNull final BluetoothGatt gatt) { - final LinkedList requests = new LinkedList<>(); - if (mICPCharacteristic != null) - requests.add(Request.newEnableNotificationsRequest(mICPCharacteristic)); - requests.add(Request.newEnableIndicationsRequest(mBPMCharacteristic)); - return requests; + protected void initialize(@NonNull final BluetoothDevice device) { + readBatteryLevelCharacteristic(); + enableBatteryLevelCharacteristicNotifications(); + enableNotifications(mICPCharacteristic) + .with(new IntermediateCuffPressureDataCallback() { + @Override + public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) { + log(LogContract.Log.Level.APPLICATION, "\"" + IntermediateCuffPressureParser.parse(data) + "\" received"); + + // Pass through received data + super.onDataReceived(device, data); + } + + @Override + public void onIntermediateCuffPressureReceived(@NonNull final BluetoothDevice device, final float cuffPressure, final int unit, @Nullable final Float pulseRate, @Nullable final Integer userID, @Nullable final Status status, @Nullable final Calendar calendar) { + mCallbacks.onIntermediateCuffPressureReceived(device, cuffPressure, unit, pulseRate, userID, status, calendar); + } + + @Override + public void onInvalidDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) { + log(LogContract.Log.Level.WARNING, "Invalid ICP data received: " + data); + } + }); + enableIndications(mBPMCharacteristic) + .with(new BloodPressureMeasurementDataCallback() { + @Override + public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) { + log(LogContract.Log.Level.APPLICATION, "\"" + BloodPressureMeasurementParser.parse(data) + "\" received"); + + // Pass through received data + super.onDataReceived(device, data); + } + + @Override + public void onBloodPressureMeasurementReceived(@NonNull final BluetoothDevice device, final float systolic, final float diastolic, final float meanArterialPressure, final int unit, @Nullable final Float pulseRate, @Nullable final Integer userID, @Nullable final Status status, @Nullable final Calendar calendar) { + mCallbacks.onBloodPressureMeasurementReceived(device, systolic, diastolic, meanArterialPressure, unit, pulseRate, userID, status, calendar); + } + + @Override + public void onInvalidDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) { + log(LogContract.Log.Level.WARNING, "Invalid BPM data received: " + data); + } + }); } @Override protected boolean isRequiredServiceSupported(@NonNull final BluetoothGatt gatt) { - BluetoothGattService service = gatt.getService(BP_SERVICE_UUID); + final BluetoothGattService service = gatt.getService(BP_SERVICE_UUID); if (service != null) { mBPMCharacteristic = service.getCharacteristic(BPM_CHARACTERISTIC_UUID); mICPCharacteristic = service.getCharacteristic(ICP_CHARACTERISTIC_UUID); @@ -95,6 +182,10 @@ public class BPMManager extends BleManager { @Override protected boolean isOptionalServiceSupported(@NonNull final BluetoothGatt gatt) { + final BluetoothGattService service = gatt.getService(BATTERY_SERVICE_UUID); + if (service != null) { + mBatteryLevelCharacteristic = service.getCharacteristic(BATTERY_LEVEL_CHARACTERISTIC_UUID); + } return mICPCharacteristic != null; } @@ -102,70 +193,7 @@ public class BPMManager extends BleManager { protected void onDeviceDisconnected() { mICPCharacteristic = null; mBPMCharacteristic = null; - } - - @Override - protected void onCharacteristicNotified(@NonNull final BluetoothGatt gatt, @NonNull final BluetoothGattCharacteristic characteristic) { - // Intermediate Cuff Pressure characteristic read - Logger.a(mLogSession, "\"" + IntermediateCuffPressureParser.parse(characteristic) + "\" received"); - - parseBPMValue(gatt, characteristic); - } - - @Override - protected void onCharacteristicIndicated(@NonNull final BluetoothGatt gatt, @NonNull final BluetoothGattCharacteristic characteristic) { - // Blood Pressure Measurement characteristic read - Logger.a(mLogSession, "\"" + BloodPressureMeasurementParser.parse(characteristic) + "\" received"); - - parseBPMValue(gatt, characteristic); - } - - private void parseBPMValue(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) { - // Both BPM and ICP have the same structure. - - // first byte - flags - int offset = 0; - final int flags = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset++); - // See BPMManagerCallbacks.UNIT_* for unit options - final int unit = flags & 0x01; - final boolean timestampPresent = (flags & 0x02) > 0; - final boolean pulseRatePresent = (flags & 0x04) > 0; - - if (BPM_CHARACTERISTIC_UUID.equals(characteristic.getUuid())) { - // following bytes - systolic, diastolic and mean arterial pressure - final float systolic = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset); - final float diastolic = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset + 2); - final float meanArterialPressure = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset + 4); - offset += 6; - mCallbacks.onBloodPressureMeasurementRead(gatt.getDevice(), systolic, diastolic, meanArterialPressure, unit); - } else if (ICP_CHARACTERISTIC_UUID.equals(characteristic.getUuid())) { - // following bytes - cuff pressure. Diastolic and MAP are unused - final float cuffPressure = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset); - offset += 6; - mCallbacks.onIntermediateCuffPressureRead(gatt.getDevice(), cuffPressure, unit); - } - - // parse timestamp if present - if (timestampPresent) { - final Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.YEAR, characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset)); - calendar.set(Calendar.MONTH, characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset + 2) - 1); // months are 1-based - calendar.set(Calendar.DAY_OF_MONTH, characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset + 3)); - calendar.set(Calendar.HOUR_OF_DAY, characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset + 4)); - calendar.set(Calendar.MINUTE, characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset + 5)); - calendar.set(Calendar.SECOND, characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset + 6)); - offset += 7; - mCallbacks.onTimestampRead(gatt.getDevice(), calendar); - } else - mCallbacks.onTimestampRead(gatt.getDevice(), null); - - // parse pulse rate if present - if (pulseRatePresent) { - final float pulseRate = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset); - // offset += 2; - mCallbacks.onPulseRateRead(gatt.getDevice(), pulseRate); - } else - mCallbacks.onPulseRateRead(gatt.getDevice(), -1.0f); + mBatteryLevelCharacteristic = null; } }; } diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/bpm/BPMManagerCallbacks.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/bpm/BPMManagerCallbacks.java index 707192f6..61fa58d2 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/bpm/BPMManagerCallbacks.java +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/bpm/BPMManagerCallbacks.java @@ -21,53 +21,12 @@ */ package no.nordicsemi.android.nrftoolbox.bpm; -import android.bluetooth.BluetoothDevice; - -import java.util.Calendar; - import no.nordicsemi.android.ble.BleManagerCallbacks; +import no.nordicsemi.android.ble.profile.BatteryLevelCallback; +import no.nordicsemi.android.ble.profile.BloodPressureMeasurementCallback; +import no.nordicsemi.android.ble.profile.IntermediateCuffPressureCallback; -public interface BPMManagerCallbacks extends BleManagerCallbacks { - int UNIT_mmHG = 0; - int UNIT_kPa = 1; +interface BPMManagerCallbacks extends BleManagerCallbacks, + BloodPressureMeasurementCallback, IntermediateCuffPressureCallback, BatteryLevelCallback { - /** - * Called when new BPM value has been obtained from the sensor - * - * @param device the target device - * @param systolic - * @param diastolic - * @param meanArterialPressure - * @param unit - * one of the following {@link #UNIT_kPa} or {@link #UNIT_mmHG} - */ - void onBloodPressureMeasurementRead(final BluetoothDevice device, final float systolic, final float diastolic, final float meanArterialPressure, final int unit); - - /** - * Called when new ICP value has been obtained from the device - * - * @param device the target device - * @param cuffPressure - * @param unit - * one of the following {@link #UNIT_kPa} or {@link #UNIT_mmHG} - */ - void onIntermediateCuffPressureRead(final BluetoothDevice device, final float cuffPressure, final int unit); - - /** - * Called when new pulse rate value has been obtained from the device. If there was no pulse rate in the packet the parameter will be equal -1.0f - * - * @param device the target device - * @param pulseRate - * pulse rate or -1.0f - */ - void onPulseRateRead(final BluetoothDevice device, final float pulseRate); - - /** - * Called when the timestamp value has been read from the device. If there was no timestamp information the parameter will be null - * - * @param device the target device - * @param calendar - * the timestamp or null - */ - void onTimestampRead(final BluetoothDevice device, final Calendar calendar); } 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 81d8b68c..9b2e71bc 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 @@ -35,7 +35,7 @@ import java.util.UUID; import no.nordicsemi.android.ble.BleManager; import no.nordicsemi.android.ble.Request; -import no.nordicsemi.android.log.Logger; +import no.nordicsemi.android.log.LogContract; import no.nordicsemi.android.nrftoolbox.parser.CGMMeasurementParser; import no.nordicsemi.android.nrftoolbox.parser.CGMSpecificOpsControlPointParser; import no.nordicsemi.android.nrftoolbox.parser.RecordAccessControlPointParser; @@ -97,21 +97,10 @@ public class CGMSManager extends BleManager { private BluetoothGattCharacteristic mCGMOpsControlPointCharacteristic; private BluetoothGattCharacteristic mRecordAccessControlPointCharacteristic; - private static CGMSManager managerInstance = null; private SparseArray mRecords = new SparseArray<>(); private boolean mAbort; private long mSessionStartTime; - /** - * singleton implementation of HRSManager class - */ - public static synchronized CGMSManager getInstance(final Context context) { - if (managerInstance == null) { - managerInstance = new CGMSManager(context); - } - return managerInstance; - } - public CGMSManager(final Context context) { super(context); } @@ -173,15 +162,15 @@ public class CGMSManager extends BleManager { @Override protected void onCharacteristicWrite(@NonNull final BluetoothGatt gatt, @NonNull final BluetoothGattCharacteristic characteristic) { if (characteristic.getUuid().equals(RACP_UUID)) { - Logger.a(mLogSession, "\"" + RecordAccessControlPointParser.parse(characteristic) + "\" sent"); + log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(characteristic) + "\" sent"); } else { // uuid == CGM_OPS_CONTROL_POINT_UUID - Logger.a(mLogSession, "\"" + CGMSpecificOpsControlPointParser.parse(characteristic) + "\" sent"); + log(LogContract.Log.Level.APPLICATION, "\"" + CGMSpecificOpsControlPointParser.parse(characteristic) + "\" sent"); } } @Override public void onCharacteristicNotified(@NonNull final BluetoothGatt gatt, @NonNull final BluetoothGattCharacteristic characteristic) { - Logger.a(mLogSession, "\"" + CGMMeasurementParser.parse(characteristic) + "\" received"); + log(LogContract.Log.Level.APPLICATION, "\"" + CGMMeasurementParser.parse(characteristic) + "\" received"); // CGM Measurement characteristic may have one or more CGM records int totalSize = characteristic.getValue().length; @@ -204,7 +193,7 @@ public class CGMSManager extends BleManager { @Override protected void onCharacteristicIndicated(@NonNull final BluetoothGatt gatt, @NonNull final BluetoothGattCharacteristic characteristic) { if (characteristic.getUuid().equals(RACP_UUID)) { - Logger.a(mLogSession, "\"" + RecordAccessControlPointParser.parse(characteristic) + "\" received"); + log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(characteristic) + "\" received"); // Record Access Control Point characteristic int offset = 0; @@ -252,7 +241,7 @@ public class CGMSManager extends BleManager { mAbort = false; } } else { // uuid == CGM_OPS_CONTROL_POINT_UUID - Logger.a(mLogSession, "\"" + CGMSpecificOpsControlPointParser.parse(characteristic) + "\" received"); + log(LogContract.Log.Level.APPLICATION, "\"" + CGMSpecificOpsControlPointParser.parse(characteristic) + "\" received"); } } }; @@ -303,7 +292,7 @@ public class CGMSManager extends BleManager { */ public void clear() { mRecords.clear(); - mCallbacks.onDatasetClear(mBluetoothDevice); + mCallbacks.onDatasetClear(getBluetoothDevice()); } /** @@ -315,7 +304,7 @@ public class CGMSManager extends BleManager { return; clear(); - mCallbacks.onOperationStarted(mBluetoothDevice); + mCallbacks.onOperationStarted(getBluetoothDevice()); final BluetoothGattCharacteristic characteristic = mRecordAccessControlPointCharacteristic; setOpCode(characteristic, OP_CODE_REPORT_STORED_RECORDS, OPERATOR_LAST_RECORD); @@ -331,7 +320,7 @@ public class CGMSManager extends BleManager { return; clear(); - mCallbacks.onOperationStarted(mBluetoothDevice); + mCallbacks.onOperationStarted(getBluetoothDevice()); final BluetoothGattCharacteristic characteristic = mRecordAccessControlPointCharacteristic; setOpCode(characteristic, OP_CODE_REPORT_STORED_RECORDS, OPERATOR_FIRST_RECORD); @@ -361,7 +350,7 @@ public class CGMSManager extends BleManager { return; clear(); - mCallbacks.onOperationStarted(mBluetoothDevice); + mCallbacks.onOperationStarted(getBluetoothDevice()); final BluetoothGattCharacteristic characteristic = mRecordAccessControlPointCharacteristic; setOpCode(characteristic, OP_CODE_REPORT_NUMBER_OF_RECORDS, OPERATOR_ALL_RECORDS); @@ -380,7 +369,7 @@ public class CGMSManager extends BleManager { if (mRecords.size() == 0) { getAllRecords(); } else { - mCallbacks.onOperationStarted(mBluetoothDevice); + mCallbacks.onOperationStarted(getBluetoothDevice()); // obtain the last sequence number final int sequenceNumber = mRecords.keyAt(mRecords.size() - 1) + 1; @@ -399,7 +388,7 @@ public class CGMSManager extends BleManager { return; clear(); - mCallbacks.onOperationStarted(mBluetoothDevice); + mCallbacks.onOperationStarted(getBluetoothDevice()); final BluetoothGattCharacteristic characteristic = mRecordAccessControlPointCharacteristic; setOpCode(characteristic, OP_CODE_DELETE_STORED_RECORDS, OPERATOR_ALL_RECORDS); diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/csc/CSCActivity.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/csc/CSCActivity.java index 61ae99f0..933a7bd4 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/csc/CSCActivity.java +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/csc/CSCActivity.java @@ -187,12 +187,6 @@ public class CSCActivity extends BleProfileServiceReadyActivity { - /** - * Cycling Speed and Cadence service UUID. - */ + /** Cycling Speed and Cadence service UUID. */ public final static UUID CYCLING_SPEED_AND_CADENCE_SERVICE_UUID = UUID.fromString("00001816-0000-1000-8000-00805f9b34fb"); - /** - * Cycling Speed and Cadence Measurement characteristic UUID. - */ - private static final UUID CSC_MEASUREMENT_CHARACTERISTIC_UUID = UUID.fromString("00002A5B-0000-1000-8000-00805f9b34fb"); - /** - * Battery Service UUID. - */ + /** Cycling Speed and Cadence Measurement characteristic UUID. */ + private final static UUID CSC_MEASUREMENT_CHARACTERISTIC_UUID = UUID.fromString("00002A5B-0000-1000-8000-00805f9b34fb"); + /** Battery Service UUID. */ private final static UUID BATTERY_SERVICE_UUID = UUID.fromString("0000180F-0000-1000-8000-00805f9b34fb"); - /** - * Battery Level characteristic UUID. - */ + /** Battery Level characteristic UUID. */ private final static UUID BATTERY_LEVEL_CHARACTERISTIC_UUID = UUID.fromString("00002A19-0000-1000-8000-00805f9b34fb"); private final SharedPreferences preferences; @@ -77,14 +67,14 @@ public class CSCManager extends BleManager { public void readBatteryLevelCharacteristic() { readCharacteristic(mBatteryLevelCharacteristic) - .with(new BatteryLevelCallback() { + .with(new BatteryLevelDataCallback() { @Override - public void onBatteryValueChanged(final int batteryLevel) { - mCallbacks.onBatteryLevelChanged(getBluetoothDevice(), batteryLevel); + public void onBatteryLevelChanged(@NonNull final BluetoothDevice device, final int batteryLevel) { + mCallbacks.onBatteryLevelChanged(device, batteryLevel); } @Override - public void onInvalidDataReceived(final @NonNull Data data) { + public void onInvalidDataReceived(@NonNull final BluetoothDevice device, final @NonNull Data data) { log(LogContract.Log.Level.WARNING, "Invalid Battery Level data received: " + data); } }) @@ -94,14 +84,14 @@ public class CSCManager extends BleManager { public void enableBatteryLevelCharacteristicNotifications() { // If the Battery Level characteristic is null, the request will be ignored enableNotifications(mBatteryLevelCharacteristic) - .with(new BatteryLevelCallback() { + .with(new BatteryLevelDataCallback() { @Override - public void onBatteryValueChanged(final int batteryLevel) { - mCallbacks.onBatteryLevelChanged(getBluetoothDevice(), batteryLevel); + public void onBatteryLevelChanged(@NonNull final BluetoothDevice device, final int batteryLevel) { + mCallbacks.onBatteryLevelChanged(device, batteryLevel); } @Override - public void onInvalidDataReceived(final @NonNull Data data) { + public void onInvalidDataReceived(@NonNull final BluetoothDevice device, final @NonNull Data data) { log(LogContract.Log.Level.WARNING, "Invalid Battery Level data received: " + data); } }) @@ -125,32 +115,32 @@ public class CSCManager extends BleManager { // CSC characteristic is required enableNotifications(mCSCMeasurementCharacteristic) - .with(new CyclingSpeedAndCadenceCallback() { + .with(new CyclingSpeedAndCadenceDataCallback() { @Override - public void onDataReceived(final @NonNull Data data) { + public void onDataReceived(@NonNull final BluetoothDevice device, final @NonNull Data data) { log(LogContract.Log.Level.APPLICATION, "\"" + CSCMeasurementParser.parse(data) + "\" received"); // Pass through received data - super.onDataReceived(data); + super.onDataReceived(device, data); } @Override - protected float getWheelCircumference() { + public float getWheelCircumference() { return Integer.parseInt(preferences.getString(SettingsFragment.SETTINGS_WHEEL_SIZE, String.valueOf(SettingsFragment.SETTINGS_WHEEL_SIZE_DEFAULT))); } @Override - protected void onDistanceChanged(final float totalDistance, final float distance, final float speed) { + public void onDistanceChanged(@NonNull final BluetoothDevice device, final float totalDistance, final float distance, final float speed) { mCallbacks.onDistanceChanged(device, totalDistance, distance, speed); } @Override - protected void onCrankDataChanged(final float crankCadence, final float gearRatio) { + public void onCrankDataChanged(@NonNull final BluetoothDevice device, final float crankCadence, final float gearRatio) { mCallbacks.onCrankDataChanged(device, crankCadence, gearRatio); } @Override - public void onInvalidDataReceived(final @NonNull Data data) { + public void onInvalidDataReceived(@NonNull final BluetoothDevice device, final @NonNull Data data) { log(LogContract.Log.Level.WARNING, "Invalid CSC Measurement data received: " + data); } }); diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/csc/CSCManagerCallbacks.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/csc/CSCManagerCallbacks.java index c60d21ed..2ea96cbc 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/csc/CSCManagerCallbacks.java +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/csc/CSCManagerCallbacks.java @@ -21,14 +21,9 @@ */ package no.nordicsemi.android.nrftoolbox.csc; -import android.bluetooth.BluetoothDevice; - import no.nordicsemi.android.ble.BleManagerCallbacks; +import no.nordicsemi.android.ble.profile.BatteryLevelCallback; +import no.nordicsemi.android.ble.profile.CyclingSpeedAndCadenceCallback; -public interface CSCManagerCallbacks extends BleManagerCallbacks { - void onDistanceChanged(final BluetoothDevice device, final float totalDistance, final float distance, final float speed); - - void onCrankDataChanged(final BluetoothDevice device, final float crankCadence, final float gearRatio); - - void onBatteryLevelChanged(final BluetoothDevice device, final int batteryLevel); +interface CSCManagerCallbacks extends BleManagerCallbacks, CyclingSpeedAndCadenceCallback, BatteryLevelCallback { } diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/csc/CSCService.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/csc/CSCService.java index 3872b007..7e0ff6e1 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/csc/CSCService.java +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/csc/CSCService.java @@ -30,6 +30,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.support.annotation.NonNull; import android.support.v4.app.NotificationCompat; import android.support.v4.content.LocalBroadcastManager; @@ -127,7 +128,7 @@ public class CSCService extends BleProfileService implements CSCManagerCallbacks } @Override - public void onDistanceChanged(final BluetoothDevice device, final float totalDistance, final float distance, final float speed) { + public void onDistanceChanged(@NonNull final BluetoothDevice device, final float totalDistance, final float distance, final float speed) { final Intent broadcast = new Intent(BROADCAST_WHEEL_DATA); broadcast.putExtra(EXTRA_DEVICE, getBluetoothDevice()); broadcast.putExtra(EXTRA_SPEED, speed); @@ -137,7 +138,7 @@ public class CSCService extends BleProfileService implements CSCManagerCallbacks } @Override - public void onCrankDataChanged(final BluetoothDevice device, final float crankCadence, final float gearRatio) { + public void onCrankDataChanged(@NonNull final BluetoothDevice device, final float crankCadence, final float gearRatio) { final Intent broadcast = new Intent(BROADCAST_CRANK_DATA); broadcast.putExtra(EXTRA_DEVICE, getBluetoothDevice()); broadcast.putExtra(EXTRA_GEAR_RATIO, gearRatio); 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 265495b9..660b5285 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 @@ -36,7 +36,7 @@ import java.util.UUID; import no.nordicsemi.android.ble.BleManager; import no.nordicsemi.android.ble.Request; -import no.nordicsemi.android.log.Logger; +import no.nordicsemi.android.log.LogContract; import no.nordicsemi.android.nrftoolbox.parser.GlucoseMeasurementContextParser; import no.nordicsemi.android.nrftoolbox.parser.GlucoseMeasurementParser; import no.nordicsemi.android.nrftoolbox.parser.RecordAccessControlPointParser; @@ -178,7 +178,7 @@ public class GlucoseManager extends BleManager { @Override protected void onCharacteristicWrite(@NonNull final BluetoothGatt gatt, @NonNull final BluetoothGattCharacteristic characteristic) { - Logger.a(mLogSession, "\"" + RecordAccessControlPointParser.parse(characteristic) + "\" sent"); + log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(characteristic) + "\" sent"); } @Override @@ -186,7 +186,7 @@ public class GlucoseManager extends BleManager { final UUID uuid = characteristic.getUuid(); if (GM_CHARACTERISTIC.equals(uuid)) { - Logger.a(mLogSession, "\"" + GlucoseMeasurementParser.parse(characteristic) + "\" received"); + log(LogContract.Log.Level.APPLICATION, "\"" + GlucoseMeasurementParser.parse(characteristic) + "\" received"); int offset = 0; final int flags = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset); @@ -259,7 +259,7 @@ public class GlucoseManager extends BleManager { mCallbacks.onDatasetChanged(gatt.getDevice()); }); } else if (GM_CONTEXT_CHARACTERISTIC.equals(uuid)) { - Logger.a(mLogSession, "\"" + GlucoseMeasurementContextParser.parse(characteristic) + "\" received"); + log(LogContract.Log.Level.APPLICATION, "\"" + GlucoseMeasurementContextParser.parse(characteristic) + "\" received"); int offset = 0; final int flags = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset); @@ -331,7 +331,7 @@ public class GlucoseManager extends BleManager { @Override protected void onCharacteristicIndicated(@NonNull final BluetoothGatt gatt, @NonNull final BluetoothGattCharacteristic characteristic) { - Logger.a(mLogSession, "\"" + RecordAccessControlPointParser.parse(characteristic) + "\" received"); + log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(characteristic) + "\" received"); // Record Access Control Point characteristic int offset = 0; @@ -432,7 +432,7 @@ public class GlucoseManager extends BleManager { */ public void clear() { mRecords.clear(); - mCallbacks.onOperationCompleted(mBluetoothDevice); + mCallbacks.onOperationCompleted(getBluetoothDevice()); } /** @@ -444,7 +444,7 @@ public class GlucoseManager extends BleManager { return; clear(); - mCallbacks.onOperationStarted(mBluetoothDevice); + mCallbacks.onOperationStarted(getBluetoothDevice()); final BluetoothGattCharacteristic characteristic = mRecordAccessControlPointCharacteristic; setOpCode(characteristic, OP_CODE_REPORT_STORED_RECORDS, OPERATOR_LAST_RECORD); @@ -460,7 +460,7 @@ public class GlucoseManager extends BleManager { return; clear(); - mCallbacks.onOperationStarted(mBluetoothDevice); + mCallbacks.onOperationStarted(getBluetoothDevice()); final BluetoothGattCharacteristic characteristic = mRecordAccessControlPointCharacteristic; setOpCode(characteristic, OP_CODE_REPORT_STORED_RECORDS, OPERATOR_FIRST_RECORD); @@ -477,7 +477,7 @@ public class GlucoseManager extends BleManager { return; clear(); - mCallbacks.onOperationStarted(mBluetoothDevice); + mCallbacks.onOperationStarted(getBluetoothDevice()); final BluetoothGattCharacteristic characteristic = mRecordAccessControlPointCharacteristic; setOpCode(characteristic, OP_CODE_REPORT_NUMBER_OF_RECORDS, OPERATOR_ALL_RECORDS); @@ -499,7 +499,7 @@ public class GlucoseManager extends BleManager { if (mRecords.size() == 0) { getAllRecords(); } else { - mCallbacks.onOperationStarted(mBluetoothDevice); + mCallbacks.onOperationStarted(getBluetoothDevice()); // obtain the last sequence number final int sequenceNumber = mRecords.keyAt(mRecords.size() - 1) + 1; @@ -535,7 +535,7 @@ public class GlucoseManager extends BleManager { return; clear(); - mCallbacks.onOperationStarted(mBluetoothDevice); + mCallbacks.onOperationStarted(getBluetoothDevice()); final BluetoothGattCharacteristic characteristic = mRecordAccessControlPointCharacteristic; setOpCode(characteristic, OP_CODE_DELETE_STORED_RECORDS, OPERATOR_ALL_RECORDS); 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 85f289fd..c4abed9c 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 @@ -33,7 +33,7 @@ import java.util.UUID; import no.nordicsemi.android.ble.BleManager; import no.nordicsemi.android.ble.Request; -import no.nordicsemi.android.log.Logger; +import no.nordicsemi.android.log.LogContract; import no.nordicsemi.android.nrftoolbox.R; import no.nordicsemi.android.nrftoolbox.parser.BodySensorLocationParser; import no.nordicsemi.android.nrftoolbox.parser.HeartRateMeasurementParser; @@ -104,7 +104,7 @@ public class HRSManager extends BleManager { @Override public void onCharacteristicRead(@NonNull final BluetoothGatt gatt, @NonNull final BluetoothGattCharacteristic characteristic) { - Logger.a(mLogSession, "\"" + BodySensorLocationParser.parse(characteristic) + "\" received"); + log(LogContract.Log.Level.APPLICATION, "\"" + BodySensorLocationParser.parse(characteristic) + "\" received"); final String sensorPosition = getBodySensorPosition(characteristic.getValue()[0]); //This will send callback to HRSActivity when HR sensor position on body is found in HR device @@ -119,7 +119,7 @@ public class HRSManager extends BleManager { @Override public void onCharacteristicNotified(@NonNull final BluetoothGatt gatt, @NonNull final BluetoothGattCharacteristic characteristic) { - Logger.a(mLogSession, "\"" + HeartRateMeasurementParser.parse(characteristic) + "\" received"); + log(LogContract.Log.Level.APPLICATION, "\"" + HeartRateMeasurementParser.parse(characteristic) + "\" received"); int hrValue; if (isHeartRateInUINT16(characteristic.getValue()[0])) { 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 9dc838ad..2c8e9e23 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 @@ -33,7 +33,7 @@ import java.util.UUID; import no.nordicsemi.android.ble.BleManager; import no.nordicsemi.android.ble.Request; -import no.nordicsemi.android.log.Logger; +import no.nordicsemi.android.log.LogContract; import no.nordicsemi.android.nrftoolbox.parser.TemperatureMeasurementParser; import no.nordicsemi.android.nrftoolbox.utility.DebugLogger; @@ -95,7 +95,7 @@ public class HTSManager extends BleManager { @Override public void onCharacteristicIndicated(@NonNull final BluetoothGatt gatt, @NonNull final BluetoothGattCharacteristic characteristic) { - Logger.a(mLogSession, "\"" + TemperatureMeasurementParser.parse(characteristic) + "\" received"); + log(LogContract.Log.Level.APPLICATION, "\"" + TemperatureMeasurementParser.parse(characteristic) + "\" received"); try { final double tempValue = decodeTemperature(characteristic.getValue()); 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 251dcdd2..8ac316a8 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,18 +21,19 @@ */ package no.nordicsemi.android.nrftoolbox.parser; -import android.bluetooth.BluetoothGattCharacteristic; - import java.util.Calendar; import java.util.Locale; +import no.nordicsemi.android.ble.callback.Data; + public class BloodPressureMeasurementParser { - public static String parse(final BluetoothGattCharacteristic characteristic) { + + public static String parse(final Data data) { final StringBuilder builder = new StringBuilder(); // first byte - flags int offset = 0; - final int flags = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset++); + final int flags = data.getIntValue(Data.FORMAT_UINT8, offset++); final int unitType = flags & 0x01; final boolean timestampPresent = (flags & 0x02) > 0; @@ -41,9 +42,9 @@ public class BloodPressureMeasurementParser { final boolean statusPresent = (flags & 0x10) > 0; // following bytes - systolic, diastolic and mean arterial pressure - final float systolic = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset); - final float diastolic = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset + 2); - final float meanArterialPressure = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset + 4); + final float systolic = data.getFloatValue(Data.FORMAT_SFLOAT, offset); + final float diastolic = data.getFloatValue(Data.FORMAT_SFLOAT, offset + 2); + final float meanArterialPressure = data.getFloatValue(Data.FORMAT_SFLOAT, offset + 4); final String unit = unitType == 0 ? " mmHg" : " kPa"; offset += 6; builder.append("Systolic: ").append(systolic).append(unit); @@ -53,31 +54,31 @@ public class BloodPressureMeasurementParser { // parse timestamp if present if (timestampPresent) { final Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.YEAR, characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset)); - calendar.set(Calendar.MONTH, characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset + 2)); - calendar.set(Calendar.DAY_OF_MONTH, characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset + 3)); - calendar.set(Calendar.HOUR_OF_DAY, characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset + 4)); - calendar.set(Calendar.MINUTE, characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset + 5)); - calendar.set(Calendar.SECOND, characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset + 6)); + 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)); 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 = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset); + final float pulseRate = data.getFloatValue(Data.FORMAT_SFLOAT, offset); offset += 2; builder.append("\nPulse: ").append(pulseRate); } if (userIdPresent) { - final int userId = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset); + final int userId = data.getIntValue(Data.FORMAT_UINT8, offset); offset += 1; builder.append("\nUser ID: ").append(userId); } if (statusPresent) { - final int status = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset); + final int status = data.getIntValue(Data.FORMAT_UINT16, offset); // offset += 2; if ((status & 0x0001) > 0) builder.append("\nBody movement detected"); 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 a2198a19..6278a9a3 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,18 +21,18 @@ */ package no.nordicsemi.android.nrftoolbox.parser; -import android.bluetooth.BluetoothGattCharacteristic; - import java.util.Calendar; import java.util.Locale; +import no.nordicsemi.android.ble.callback.Data; + public class IntermediateCuffPressureParser { - public static String parse(final BluetoothGattCharacteristic characteristic) { + public static String parse(final Data data) { final StringBuilder builder = new StringBuilder(); // first byte - flags int offset = 0; - final int flags = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset++); + final int flags = data.getIntValue(Data.FORMAT_UINT8, offset++); final int unitType = flags & 0x01; final boolean timestampPresent = (flags & 0x02) > 0; @@ -41,7 +41,7 @@ public class IntermediateCuffPressureParser { final boolean statusPresent = (flags & 0x10) > 0; // following bytes - pressure - final float pressure = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset); + final float pressure = data.getFloatValue(Data.FORMAT_SFLOAT, offset); final String unit = unitType == 0 ? "mmHg" : "kPa"; offset += 6; builder.append("Cuff pressure: ").append(pressure).append(unit); @@ -49,31 +49,31 @@ public class IntermediateCuffPressureParser { // parse timestamp if present if (timestampPresent) { final Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.YEAR, characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset)); - calendar.set(Calendar.MONTH, characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset + 2)); - calendar.set(Calendar.DAY_OF_MONTH, characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset + 3)); - calendar.set(Calendar.HOUR_OF_DAY, characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset + 4)); - calendar.set(Calendar.MINUTE, characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset + 5)); - calendar.set(Calendar.SECOND, characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset + 6)); + 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)); 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 = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset); + final float pulseRate = data.getFloatValue(Data.FORMAT_SFLOAT, offset); offset += 2; builder.append("\nPulse: ").append(pulseRate); } if (userIdPresent) { - final int userId = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset); + final int userId = data.getIntValue(Data.FORMAT_UINT8, offset); offset += 1; builder.append("\nUser ID: ").append(userId); } if (statusPresent) { - final int status = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset); + final int status = data.getIntValue(Data.FORMAT_UINT16, offset); // offset += 2; if ((status & 0x0001) > 0) builder.append("\nBody movement detected"); diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileActivity.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileActivity.java index f4b617e4..d5e9819c 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileActivity.java +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileActivity.java @@ -106,17 +106,19 @@ public abstract class BleProfileActivity extends AppCompatActivity implements Bl } /** - * Called from {@link #onCreate(Bundle)}. This method should build the activity UI, f.e. using {@link #setContentView(int)}. Use to obtain references to - * views. Connect/Disconnect button, the device name view and battery level view are manager automatically. + * Called from {@link #onCreate(Bundle)}. This method should build the activity UI, i.e. using {@link #setContentView(int)}. + * Use to obtain references to views. Connect/Disconnect button and the device name view are manager automatically. * - * @param savedInstanceState contains the data it most recently supplied in {@link #onSaveInstanceState(Bundle)}. Note: Otherwise it is null. + * @param savedInstanceState contains the data it most recently supplied in {@link #onSaveInstanceState(Bundle)}. + * Note: Otherwise it is null. */ protected abstract void onCreateView(final Bundle savedInstanceState); /** * Called after the view has been created. * - * @param savedInstanceState contains the data it most recently supplied in {@link #onSaveInstanceState(Bundle)}. Note: Otherwise it is null. + * @param savedInstanceState contains the data it most recently supplied in {@link #onSaveInstanceState(Bundle)}. + * Note: Otherwise it is null. */ protected void onViewCreated(final Bundle savedInstanceState) { // empty default implementation @@ -146,7 +148,7 @@ public abstract class BleProfileActivity extends AppCompatActivity implements Bl } @Override - protected void onRestoreInstanceState(@NonNull final Bundle savedInstanceState) { + protected void onRestoreInstanceState(final @NonNull Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); mDeviceConnected = savedInstanceState.getBoolean(SIS_CONNECTION_STATUS); mDeviceName = savedInstanceState.getString(SIS_DEVICE_NAME); diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileExpandableListActivity.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileExpandableListActivity.java index 36ae618d..fbb32353 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileExpandableListActivity.java +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileExpandableListActivity.java @@ -106,17 +106,19 @@ public abstract class BleProfileExpandableListActivity extends ExpandableListAct } /** - * Called from {@link #onCreate(Bundle)}. This method should build the activity UI, f.e. using {@link #setContentView(int)}. Use to obtain references to - * views. Connect/Disconnect button, the device name view and battery level view are manager automatically. + * Called from {@link #onCreate(Bundle)}. This method should build the activity UI, i.e. using {@link #setContentView(int)}. + * Use to obtain references to views. Connect/Disconnect button and the device name view are manager automatically. * - * @param savedInstanceState contains the data it most recently supplied in {@link #onSaveInstanceState(Bundle)}. Note: Otherwise it is null. + * @param savedInstanceState contains the data it most recently supplied in {@link #onSaveInstanceState(Bundle)}. + * Note: Otherwise it is null. */ protected abstract void onCreateView(final Bundle savedInstanceState); /** * Called after the view has been created. * - * @param savedInstanceState contains the data it most recently supplied in {@link #onSaveInstanceState(Bundle)}. Note: Otherwise it is null. + * @param savedInstanceState contains the data it most recently supplied in {@link #onSaveInstanceState(Bundle)}. + * Note: Otherwise it is null. */ protected void onViewCreated(final Bundle savedInstanceState) { // empty default implementation @@ -146,7 +148,7 @@ public abstract class BleProfileExpandableListActivity extends ExpandableListAct } @Override - protected void onRestoreInstanceState(@NonNull final Bundle savedInstanceState) { + protected void onRestoreInstanceState(final @NonNull Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); mDeviceConnected = savedInstanceState.getBoolean(SIS_CONNECTION_STATUS); mDeviceName = savedInstanceState.getString(SIS_DEVICE_NAME); @@ -305,12 +307,6 @@ public abstract class BleProfileExpandableListActivity extends ExpandableListAct showToast(R.string.bonding_failed); } - @Override - public boolean shouldEnableBatteryLevelNotifications(final BluetoothDevice device) { - // Yes, we want battery level updates - return true; - } - @Override public void onError(final BluetoothDevice device, final String message, final int errorCode) { DebugLogger.e(TAG, "Error occurred: " + message + ", error code: " + errorCode); diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileServiceReadyActivity.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileServiceReadyActivity.java index 4a266470..5e14e988 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileServiceReadyActivity.java +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/BleProfileServiceReadyActivity.java @@ -341,17 +341,19 @@ public abstract class BleProfileServiceReadyActivityOtherwise it is null. + * @param savedInstanceState contains the data it most recently supplied in {@link #onSaveInstanceState(Bundle)}. + * Note: Otherwise it is null. */ protected abstract void onCreateView(final Bundle savedInstanceState); /** * Called after the view has been created. * - * @param savedInstanceState contains the data it most recently supplied in {@link #onSaveInstanceState(Bundle)}. Note: Otherwise it is null. + * @param savedInstanceState contains the data it most recently supplied in {@link #onSaveInstanceState(Bundle)}. + * Note: Otherwise it is null. */ protected void onViewCreated(final Bundle savedInstanceState) { // empty default implementation @@ -377,7 +379,7 @@ public abstract class BleProfileServiceReadyActivity manager = mBleManagers.get(device); return manager.getBatteryValue(); diff --git a/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/multiconnect/BleMulticonnectProfileServiceReadyActivity.java b/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/multiconnect/BleMulticonnectProfileServiceReadyActivity.java index 2d008e5e..792dca7f 100644 --- a/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/multiconnect/BleMulticonnectProfileServiceReadyActivity.java +++ b/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile/multiconnect/BleMulticonnectProfileServiceReadyActivity.java @@ -295,17 +295,19 @@ public abstract class BleMulticonnectProfileServiceReadyActivityOtherwise it is null. + * @param savedInstanceState contains the data it most recently supplied in {@link #onSaveInstanceState(Bundle)}. + * Note: Otherwise it is null. */ protected abstract void onCreateView(final Bundle savedInstanceState); /** * Called after the view has been created. * - * @param savedInstanceState contains the data it most recently supplied in {@link #onSaveInstanceState(Bundle)}. Note: Otherwise it is null. + * @param savedInstanceState contains the data it most recently supplied in {@link #onSaveInstanceState(Bundle)}. + * Note: Otherwise it is null. */ protected void onViewCreated(final Bundle savedInstanceState) { // empty default implementation 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 d8c15bf8..b277b63a 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 @@ -34,7 +34,7 @@ import java.util.UUID; import no.nordicsemi.android.ble.BleManager; import no.nordicsemi.android.ble.Request; -import no.nordicsemi.android.log.Logger; +import no.nordicsemi.android.log.LogContract; import no.nordicsemi.android.nrftoolbox.parser.RSCMeasurementParser; public class RSCManager extends BleManager { @@ -86,7 +86,7 @@ public class RSCManager extends BleManager { @Override public void onCharacteristicNotified(@NonNull final BluetoothGatt gatt, @NonNull final BluetoothGattCharacteristic characteristic) { - Logger.a(mLogSession, "\"" + RSCMeasurementParser.parse(characteristic) + "\" received"); + log(LogContract.Log.Level.APPLICATION, "\"" + RSCMeasurementParser.parse(characteristic) + "\" received"); // Decode the new data int offset = 0; 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 97cceeb0..f7a75f7a 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 @@ -33,7 +33,7 @@ import java.util.UUID; import no.nordicsemi.android.ble.BleManager; import no.nordicsemi.android.ble.Request; -import no.nordicsemi.android.log.Logger; +import no.nordicsemi.android.log.LogContract; import no.nordicsemi.android.nrftoolbox.parser.TemplateParser; /** @@ -101,7 +101,7 @@ public class TemplateManager extends BleManager { // TODO this method is called when a notification has been received // This method may be removed from this class if not required - Logger.a(mLogSession, "\"" + TemplateParser.parse(characteristic) + "\" received"); + log(LogContract.Log.Level.APPLICATION, "\"" + TemplateParser.parse(characteristic) + "\" received"); int value; final int flags = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0); 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 ec7a4d64..1246cf7e 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 @@ -36,7 +36,7 @@ import java.util.UUID; import no.nordicsemi.android.ble.BleManager; import no.nordicsemi.android.ble.Request; -import no.nordicsemi.android.log.Logger; +import no.nordicsemi.android.log.LogContract; public class UARTManager extends BleManager { /** Nordic UART Service UUID */ @@ -110,7 +110,7 @@ public class UARTManager extends BleManager { if (mBufferOffset == buffer.length) { try { final String data = new String(buffer, "UTF-8"); - Logger.a(mLogSession, "\"" + data + "\" sent"); + log(LogContract.Log.Level.APPLICATION, "\"" + data + "\" sent"); mCallbacks.onDataSent(gatt.getDevice(), data); } catch (final UnsupportedEncodingException e) { // do nothing @@ -126,7 +126,7 @@ public class UARTManager extends BleManager { @Override public void onCharacteristicNotified(@NonNull final BluetoothGatt gatt, @NonNull final BluetoothGattCharacteristic characteristic) { final String data = characteristic.getStringValue(0); - Logger.a(mLogSession, "\"" + data + "\" received"); + log(LogContract.Log.Level.APPLICATION, "\"" + data + "\" received"); mCallbacks.onDataReceived(gatt.getDevice(), data); } };