mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2026-01-07 08:44:24 +01:00
Refactoring and bug fixing
This commit is contained in:
@@ -10,7 +10,7 @@ import android.support.annotation.NonNull;
|
||||
import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.ble.callback.DataCallback;
|
||||
import no.nordicsemi.android.ble.callback.DataReceivedCallback;
|
||||
import no.nordicsemi.android.ble.common.callback.battery.BatteryLevelDataCallback;
|
||||
import no.nordicsemi.android.ble.data.Data;
|
||||
import no.nordicsemi.android.log.LogContract;
|
||||
@@ -43,7 +43,7 @@ public abstract class BatteryManager<T extends BatteryManagerCallbacks> extends
|
||||
@Override
|
||||
protected abstract BatteryManagerGattCallback getGattCallback();
|
||||
|
||||
private DataCallback mBatteryLevelDataCallback = new BatteryLevelDataCallback() {
|
||||
private DataReceivedCallback mBatteryLevelDataCallback = new BatteryLevelDataCallback() {
|
||||
@Override
|
||||
public void onBatteryLevelChanged(@NonNull final BluetoothDevice device, final int batteryLevel) {
|
||||
log(LogContract.Log.Level.APPLICATION,"Battery Level received: " + batteryLevel + "%");
|
||||
@@ -61,7 +61,7 @@ public abstract class BatteryManager<T extends BatteryManagerCallbacks> extends
|
||||
if (isConnected()) {
|
||||
readCharacteristic(mBatteryLevelCharacteristic)
|
||||
.with(mBatteryLevelDataCallback)
|
||||
.fail(status -> log(LogContract.Log.Level.WARNING, "Battery Level characteristic not found"));
|
||||
.fail((device, status) -> log(LogContract.Log.Level.WARNING, "Battery Level characteristic not found"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,8 +70,8 @@ public abstract class BatteryManager<T extends BatteryManagerCallbacks> extends
|
||||
// If the Battery Level characteristic is null, the request will be ignored
|
||||
enableNotifications(mBatteryLevelCharacteristic)
|
||||
.with(mBatteryLevelDataCallback)
|
||||
.done(() -> log(LogContract.Log.Level.INFO, "Battery Level notifications enabled"))
|
||||
.fail(status -> log(LogContract.Log.Level.WARNING, "Battery Level characteristic not found"));
|
||||
.done(device -> log(LogContract.Log.Level.INFO, "Battery Level notifications enabled"))
|
||||
.fail((device, status) -> log(LogContract.Log.Level.WARNING, "Battery Level characteristic not found"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public abstract class BatteryManager<T extends BatteryManagerCallbacks> extends
|
||||
public void disableBatteryLevelCharacteristicNotifications() {
|
||||
if (isConnected()) {
|
||||
disableNotifications(mBatteryLevelCharacteristic)
|
||||
.done(() -> log(LogContract.Log.Level.INFO, "Battery Level notifications disabled"));
|
||||
.done(device -> log(LogContract.Log.Level.INFO, "Battery Level notifications disabled"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public abstract class BatteryManager<T extends BatteryManagerCallbacks> extends
|
||||
protected abstract class BatteryManagerGattCallback extends BleManagerGattCallback {
|
||||
|
||||
@Override
|
||||
protected void initialize(@NonNull final BluetoothGatt gatt) {
|
||||
protected void initialize() {
|
||||
readBatteryLevelCharacteristic();
|
||||
enableBatteryLevelCharacteristicNotifications();
|
||||
}
|
||||
|
||||
@@ -174,8 +174,6 @@ public class BPMActivity extends BleProfileActivity implements BPMManagerCallbac
|
||||
|
||||
@Override
|
||||
public void onBatteryLevelChanged(@NonNull final BluetoothDevice device, final int batteryLevel) {
|
||||
runOnUiThread(() -> {
|
||||
mBatteryLevelView.setText(getString(R.string.battery, batteryLevel));
|
||||
});
|
||||
runOnUiThread(() -> mBatteryLevelView.setText(getString(R.string.battery, batteryLevel)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,8 +78,8 @@ public class BPMManager extends BatteryManager<BPMManagerCallbacks> {
|
||||
private final BatteryManagerGattCallback mGattCallback = new BatteryManagerGattCallback() {
|
||||
|
||||
@Override
|
||||
protected void initialize(@NonNull final BluetoothGatt gatt) {
|
||||
super.initialize(gatt);
|
||||
protected void initialize() {
|
||||
super.initialize();
|
||||
|
||||
enableNotifications(mICPCharacteristic)
|
||||
.with(new IntermediateCuffPressureDataCallback() {
|
||||
|
||||
@@ -96,9 +96,9 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
|
||||
private final BatteryManagerGattCallback mGattCallback = new BatteryManagerGattCallback() {
|
||||
|
||||
@Override
|
||||
protected void initialize(@NonNull final BluetoothGatt gatt) {
|
||||
protected void initialize() {
|
||||
// Enable Battery service
|
||||
super.initialize(gatt);
|
||||
super.initialize();
|
||||
|
||||
// Read CGM Feature characteristic, mainly to see if the device supports E2E CRC.
|
||||
// This is not supported in the experimental CGMS from the SDK.
|
||||
@@ -110,7 +110,7 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
|
||||
mSecured = features.e2eCrcSupported;
|
||||
log(LogContract.Log.Level.APPLICATION, "E2E CRC feature " + (mSecured ? "supported" : "not supported"));
|
||||
}
|
||||
}).fail(status -> log(LogContract.Log.Level.WARNING, "Could not read CGM Feature characteristic"));
|
||||
}).fail((device, status) -> log(LogContract.Log.Level.WARNING, "Could not read CGM Feature characteristic"));
|
||||
|
||||
// Check if the session is already started. This is not supported in the experimental CGMS from the SDK.
|
||||
readCharacteristic(mCGMStatusCharacteristic)
|
||||
@@ -122,7 +122,7 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
|
||||
log(LogContract.Log.Level.APPLICATION, "Session already started");
|
||||
}
|
||||
}
|
||||
}).fail(status -> log(LogContract.Log.Level.WARNING, "Could not read CGM Status characteristic"));
|
||||
}).fail((device, status) -> log(LogContract.Log.Level.WARNING, "Could not read CGM Status characteristic"));
|
||||
|
||||
// Enable Continuous Glucose Measurement notifications
|
||||
enableNotifications(mCGMMeasurementCharacteristic)
|
||||
@@ -154,7 +154,7 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
|
||||
log(LogContract.Log.Level.WARNING, "Continuous Glucose Measurement record received with CRC error");
|
||||
}
|
||||
})
|
||||
.fail((error) -> log(LogContract.Log.Level.WARNING, "Failed to enable Continuous Glucose Measurement notifications (" + error + ")"));
|
||||
.fail((device, status) -> log(LogContract.Log.Level.WARNING, "Failed to enable Continuous Glucose Measurement notifications (" + status + ")"));
|
||||
|
||||
// Enable CGM Specific Ops indications
|
||||
enableIndications(mCGMSpecificOpsControlPointCharacteristic)
|
||||
@@ -202,7 +202,7 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
|
||||
.with(new RecordAccessControlPointDataCallback() {
|
||||
@Override
|
||||
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
||||
log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(mRecordAccessControlPointCharacteristic) + "\" received");
|
||||
log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" received");
|
||||
super.onDataReceived(device, data);
|
||||
}
|
||||
|
||||
@@ -251,13 +251,13 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
|
||||
}
|
||||
}
|
||||
})
|
||||
.fail((error) -> log(LogContract.Log.Level.WARNING, "Failed to enabled Record Access Control Point indications (error " + error + ")"));
|
||||
.fail((device, status) -> log(LogContract.Log.Level.WARNING, "Failed to enabled Record Access Control Point indications (error " + status + ")"));
|
||||
|
||||
// Start Continuous Glucose session if hasn't been started before
|
||||
if (mSessionStartTime == 0L) {
|
||||
writeCharacteristic(mCGMSpecificOpsControlPointCharacteristic, CGMSpecificOpsControlPointData.startSession(mSecured))
|
||||
.done(() -> log(LogContract.Log.Level.APPLICATION, "\"" + CGMSpecificOpsControlPointParser.parse(mCGMSpecificOpsControlPointCharacteristic) + "\" sent"))
|
||||
.fail((error) -> log(LogContract.Log.Level.ERROR, "Failed to start session (error " + error + ")"));
|
||||
.done(device -> log(LogContract.Log.Level.APPLICATION, "\"" + CGMSpecificOpsControlPointParser.parse(mCGMSpecificOpsControlPointCharacteristic) + "\" sent"))
|
||||
.fail((device, status) -> log(LogContract.Log.Level.ERROR, "Failed to start session (error " + status + ")"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
|
||||
mCallbacks.onOperationStarted(getBluetoothDevice());
|
||||
mRecordAccessRequestInProgress = true;
|
||||
writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.reportLastStoredRecord())
|
||||
.done(() -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(mRecordAccessControlPointCharacteristic) + "\" sent"));
|
||||
.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -328,7 +328,7 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
|
||||
mCallbacks.onOperationStarted(getBluetoothDevice());
|
||||
mRecordAccessRequestInProgress = true;
|
||||
writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.reportFirstStoredRecord())
|
||||
.done(() -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(mRecordAccessControlPointCharacteristic) + "\" sent"));
|
||||
.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -339,7 +339,7 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
|
||||
return;
|
||||
|
||||
writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.abortOperation())
|
||||
.done(() -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(mRecordAccessControlPointCharacteristic) + "\" sent"));
|
||||
.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -356,7 +356,7 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
|
||||
mCallbacks.onOperationStarted(getBluetoothDevice());
|
||||
mRecordAccessRequestInProgress = true;
|
||||
writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.reportNumberOfAllStoredRecords())
|
||||
.done(() -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(mRecordAccessControlPointCharacteristic) + "\" sent"));
|
||||
.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -378,7 +378,7 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
|
||||
final int sequenceNumber = mRecords.keyAt(mRecords.size() - 1) + 1;
|
||||
mRecordAccessRequestInProgress = true;
|
||||
writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.reportStoredRecordsGreaterThenOrEqualTo(sequenceNumber))
|
||||
.done(() -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(mRecordAccessControlPointCharacteristic) + "\" sent"));
|
||||
.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent"));
|
||||
// Info:
|
||||
// Operators OPERATOR_GREATER_THEN_OR_EQUAL, OPERATOR_LESS_THEN_OR_EQUAL and OPERATOR_RANGE are not supported by the CGMS sample from SDK
|
||||
// The "Operation not supported" response will be received
|
||||
@@ -397,7 +397,7 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
|
||||
clear();
|
||||
mCallbacks.onOperationStarted(getBluetoothDevice());
|
||||
writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.deleteAllStoredRecords())
|
||||
.done(() -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(mRecordAccessControlPointCharacteristic) + "\" sent"));
|
||||
.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,8 +65,8 @@ public class CSCManager extends BatteryManager<CSCManagerCallbacks> {
|
||||
private final BatteryManagerGattCallback mGattCallback = new BatteryManagerGattCallback() {
|
||||
|
||||
@Override
|
||||
protected void initialize(@NonNull final BluetoothGatt gatt) {
|
||||
super.initialize(gatt);
|
||||
protected void initialize() {
|
||||
super.initialize();
|
||||
|
||||
// CSC characteristic is required
|
||||
enableNotifications(mCSCMeasurementCharacteristic)
|
||||
|
||||
@@ -66,7 +66,6 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
|
||||
private BluetoothGattCharacteristic mRecordAccessControlPointCharacteristic;
|
||||
|
||||
private final SparseArray<GlucoseRecord> mRecords = new SparseArray<>();
|
||||
private boolean mAbort;
|
||||
private Handler mHandler;
|
||||
private static GlucoseManager mInstance;
|
||||
|
||||
@@ -95,8 +94,8 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
|
||||
private final BatteryManagerGattCallback mGattCallback = new BatteryManagerGattCallback() {
|
||||
|
||||
@Override
|
||||
protected void initialize(@NonNull final BluetoothGatt gatt) {
|
||||
super.initialize(gatt);
|
||||
protected void initialize() {
|
||||
super.initialize();
|
||||
|
||||
// The gatt.setCharacteristicNotification(...) method is called in BleManager during enabling
|
||||
// notifications or indications (see BleManager#internalEnableNotifications/Indications).
|
||||
@@ -106,11 +105,13 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
|
||||
// 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) {
|
||||
gatt.setCharacteristicNotification(mGlucoseMeasurementContextCharacteristic, true);
|
||||
device.setCharacteristicNotification(mGlucoseMeasurementContextCharacteristic, true);
|
||||
}
|
||||
gatt.setCharacteristicNotification(mRecordAccessControlPointCharacteristic, true);
|
||||
device.setCharacteristicNotification(mRecordAccessControlPointCharacteristic, true);
|
||||
*/
|
||||
|
||||
enableNotifications(mGlucoseMeasurementCharacteristic)
|
||||
.with(new GlucoseMeasurementDataCallback() {
|
||||
@@ -143,7 +144,7 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
|
||||
// if there is no context information following the measurement data,
|
||||
// notify callback about the new record
|
||||
if (!contextInformationFollows)
|
||||
mCallbacks.onDatasetChanged(gatt.getDevice());
|
||||
mCallbacks.onDatasetChanged(device);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -184,7 +185,7 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
|
||||
|
||||
mHandler.post(() -> {
|
||||
// notify callback about the new record
|
||||
mCallbacks.onDatasetChanged(gatt.getDevice());
|
||||
mCallbacks.onDatasetChanged(device);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -193,7 +194,7 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
|
||||
.with(new RecordAccessControlPointDataCallback() {
|
||||
@Override
|
||||
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
||||
log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(mRecordAccessControlPointCharacteristic) + "\" received");
|
||||
log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" received");
|
||||
super.onDataReceived(device, data);
|
||||
}
|
||||
|
||||
@@ -239,7 +240,7 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
|
||||
}
|
||||
}
|
||||
})
|
||||
.fail((error) -> log(LogContract.Log.Level.WARNING, "Failed to enabled Record Access Control Point indications (error " + error + ")"));
|
||||
.fail((device, status) -> log(LogContract.Log.Level.WARNING, "Failed to enabled Record Access Control Point indications (error " + status + ")"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -296,7 +297,7 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
|
||||
clear();
|
||||
mCallbacks.onOperationStarted(getBluetoothDevice());
|
||||
writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.reportLastStoredRecord())
|
||||
.done(() -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(mRecordAccessControlPointCharacteristic) + "\" sent"));
|
||||
.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -311,7 +312,7 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
|
||||
clear();
|
||||
mCallbacks.onOperationStarted(getBluetoothDevice());
|
||||
writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.reportFirstStoredRecord())
|
||||
.done(() -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(mRecordAccessControlPointCharacteristic) + "\" sent"));
|
||||
.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -327,7 +328,7 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
|
||||
clear();
|
||||
mCallbacks.onOperationStarted(getBluetoothDevice());
|
||||
writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.reportNumberOfAllStoredRecords())
|
||||
.done(() -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(mRecordAccessControlPointCharacteristic) + "\" sent"));
|
||||
.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -354,7 +355,7 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
|
||||
|
||||
writeCharacteristic(mRecordAccessControlPointCharacteristic,
|
||||
RecordAccessControlPointData.reportStoredRecordsGreaterThenOrEqualTo(sequenceNumber))
|
||||
.done(() -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(mRecordAccessControlPointCharacteristic) + "\" sent"));
|
||||
.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent"));
|
||||
// Info:
|
||||
// Operators OPERATOR_LESS_THEN_OR_EQUAL and OPERATOR_RANGE are not supported by Nordic Semiconductor Glucose Service in SDK 4.4.2.
|
||||
}
|
||||
@@ -367,9 +368,8 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
|
||||
if (mRecordAccessControlPointCharacteristic == null)
|
||||
return;
|
||||
|
||||
mAbort = true;
|
||||
writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.abortOperation())
|
||||
.done(() -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(mRecordAccessControlPointCharacteristic) + "\" sent"));
|
||||
.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -385,6 +385,6 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
|
||||
clear();
|
||||
mCallbacks.onOperationStarted(getBluetoothDevice());
|
||||
writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.deleteAllStoredRecords())
|
||||
.done(() -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(mRecordAccessControlPointCharacteristic) + "\" sent"));
|
||||
.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
package no.nordicsemi.android.nrftoolbox.parser;
|
||||
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import no.nordicsemi.android.ble.data.Data;
|
||||
|
||||
public class RecordAccessControlPointParser {
|
||||
private final static int OP_CODE_REPORT_STORED_RECORDS = 1;
|
||||
@@ -49,10 +49,10 @@ public class RecordAccessControlPointParser {
|
||||
private final static int RESPONSE_PROCEDURE_NOT_COMPLETED = 8;
|
||||
private final static int RESPONSE_OPERAND_NOT_SUPPORTED = 9;
|
||||
|
||||
public static String parse(final BluetoothGattCharacteristic characteristic) {
|
||||
public static String parse(final Data data) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
final int opCode = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0);
|
||||
final int operator = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 1);
|
||||
final int opCode = data.getIntValue(Data.FORMAT_UINT8, 0);
|
||||
final int operator = data.getIntValue(Data.FORMAT_UINT8, 1);
|
||||
|
||||
switch (opCode) {
|
||||
case OP_CODE_REPORT_STORED_RECORDS:
|
||||
@@ -63,15 +63,15 @@ public class RecordAccessControlPointParser {
|
||||
break;
|
||||
case OP_CODE_NUMBER_OF_STORED_RECORDS_RESPONSE: {
|
||||
builder.append(getOpCode(opCode)).append(": ");
|
||||
final int value = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, 2);
|
||||
final int value = data.getIntValue(Data.FORMAT_UINT16, 2);
|
||||
builder.append(value).append("\n");
|
||||
break;
|
||||
}
|
||||
case OP_CODE_RESPONSE_CODE: {
|
||||
builder.append(getOpCode(opCode)).append(" for ");
|
||||
final int targetOpCode = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 2);
|
||||
final int targetOpCode = data.getIntValue(Data.FORMAT_UINT8, 2);
|
||||
builder.append(getOpCode(targetOpCode)).append(": ");
|
||||
final int status = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 3);
|
||||
final int status = data.getIntValue(Data.FORMAT_UINT8, 3);
|
||||
builder.append(getStatus(status)).append("\n");
|
||||
break;
|
||||
}
|
||||
@@ -85,15 +85,15 @@ public class RecordAccessControlPointParser {
|
||||
break;
|
||||
case OPERATOR_GREATER_THEN_OR_EQUAL:
|
||||
case OPERATOR_LESS_THEN_OR_EQUAL: {
|
||||
final int filter = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 2);
|
||||
final int value = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, 3);
|
||||
final int filter = data.getIntValue(Data.FORMAT_UINT8, 2);
|
||||
final int value = data.getIntValue(Data.FORMAT_UINT16, 3);
|
||||
builder.append("Operator: ").append(getOperator(operator)).append(" ").append(value).append(" (filter: ").append(filter).append(")\n");
|
||||
break;
|
||||
}
|
||||
case OPERATOR_WITHING_RANGE: {
|
||||
final int filter = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 2);
|
||||
final int value1 = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, 3);
|
||||
final int value2 = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, 5);
|
||||
final int filter = data.getIntValue(Data.FORMAT_UINT8, 2);
|
||||
final int value1 = data.getIntValue(Data.FORMAT_UINT16, 3);
|
||||
final int value2 = data.getIntValue(Data.FORMAT_UINT16, 5);
|
||||
builder.append("Operator: ").append(getOperator(operator)).append(" ").append(value1).append("-").append(value2).append(" (filter: ").append(filter).append(")\n");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ public abstract class BleProfileActivity extends AppCompatActivity implements Bl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBound(final BluetoothDevice device) {
|
||||
public void onBonded(final BluetoothDevice device) {
|
||||
showToast(R.string.bonded);
|
||||
}
|
||||
|
||||
|
||||
@@ -298,7 +298,7 @@ public abstract class BleProfileExpandableListActivity extends ExpandableListAct
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBound(final BluetoothDevice device) {
|
||||
public void onBonded(final BluetoothDevice device) {
|
||||
showToast(R.string.bonded);
|
||||
}
|
||||
|
||||
|
||||
@@ -495,7 +495,7 @@ public abstract class BleProfileService extends Service implements BleManagerCal
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBound(final BluetoothDevice device) {
|
||||
public void onBonded(final BluetoothDevice device) {
|
||||
showToast(no.nordicsemi.android.nrftoolbox.common.R.string.bonded);
|
||||
|
||||
final Intent broadcast = new Intent(BROADCAST_BOND_STATE);
|
||||
|
||||
@@ -151,7 +151,7 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
|
||||
onBondingRequired(bluetoothDevice);
|
||||
break;
|
||||
case BluetoothDevice.BOND_BONDED:
|
||||
onBound(bluetoothDevice);
|
||||
onBonded(bluetoothDevice);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -541,7 +541,7 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBound(final BluetoothDevice device) {
|
||||
public void onBonded(final BluetoothDevice device) {
|
||||
// empty default implementation
|
||||
}
|
||||
|
||||
|
||||
@@ -512,7 +512,7 @@ public abstract class BleMulticonnectProfileService extends Service implements B
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBound(final BluetoothDevice device) {
|
||||
public void onBonded(final BluetoothDevice device) {
|
||||
showToast(no.nordicsemi.android.nrftoolbox.common.R.string.bonded);
|
||||
|
||||
final Intent broadcast = new Intent(BROADCAST_BOND_STATE);
|
||||
|
||||
@@ -138,7 +138,7 @@ public abstract class BleMulticonnectProfileServiceReadyActivity<E extends BleMu
|
||||
onBondingRequired(bluetoothDevice);
|
||||
break;
|
||||
case BluetoothDevice.BOND_BONDED:
|
||||
onBound(bluetoothDevice);
|
||||
onBonded(bluetoothDevice);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -435,7 +435,7 @@ public abstract class BleMulticonnectProfileServiceReadyActivity<E extends BleMu
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBound(final BluetoothDevice device) {
|
||||
public void onBonded(final BluetoothDevice device) {
|
||||
// empty default implementation
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
*/
|
||||
package no.nordicsemi.android.nrftoolbox.proximity;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.bluetooth.BluetoothGattService;
|
||||
@@ -71,8 +70,8 @@ class ProximityManager extends BatteryManager<ProximityManagerCallbacks> {
|
||||
private final BatteryManagerGattCallback mGattCallback = new BatteryManagerGattCallback() {
|
||||
|
||||
@Override
|
||||
protected void initialize(@NonNull final BluetoothDevice device) {
|
||||
super.initialize(device);
|
||||
protected void initialize() {
|
||||
super.initialize();
|
||||
writeCharacteristic(mLinklossCharacteristic, HIGH_ALERT);
|
||||
}
|
||||
|
||||
@@ -124,11 +123,11 @@ class ProximityManager extends BatteryManager<ProximityManagerCallbacks> {
|
||||
|
||||
log(LogContract.Log.Level.VERBOSE, on ? "Setting alarm to HIGH..." : "Disabling alarm...");
|
||||
writeCharacteristic(mAlertLevelCharacteristic, on ? HIGH_ALERT : NO_ALERT)
|
||||
.done(() -> {
|
||||
.done(device -> {
|
||||
mAlertOn = on;
|
||||
log(LogContract.Log.Level.APPLICATION, "\"" + AlertLevelParser.parse(mAlertLevelCharacteristic) + "\" sent");
|
||||
})
|
||||
.fail(status -> log(LogContract.Log.Level.APPLICATION, "Alert Level characteristic not found"));
|
||||
.fail((device, status) -> log(LogContract.Log.Level.APPLICATION, "Alert Level characteristic not found"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user