mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2026-01-07 00:34:33 +01:00
Refactoring and bug fixing
This commit is contained in:
@@ -91,7 +91,7 @@ To open the DFU settings click the *Settings* button in the top toolbar when on
|
||||
|
||||
**MBR size** - This value is used only to convert HEX files into BIN files. If your packet is already in the BIN format, this value is ignored. The data from addresses lower then this value are being skipped while converting HEX to BIN. This is to prevent from sending the MBR (Master Boot Record) part from the HEX file that contains the Soft Device. The compiled Soft Device contains data that starts at address 0x0000 and contains the MBR. It is followed by the jump to address 0x1000 (default MBR size) where the Soft Device firmware starts. Only the Soft Device part must be sent over DFU.
|
||||
|
||||
**Keep bond information** - When upgrading the application on a bound device the DFU bootloader may be configured to preserve some pages of the application's memory intact, so that the new application may read them. The new application must know the old data format in order to read them correctly. Our HRS DFU sample stores the Long Term Key (LTK) and the Service Attributes in two first pages. However, the DFU Bootloader, by default, clears the whole application's memory when the new application upload completes, and the bond information is lost. In order to configure the number of pages to be preserved set the **DFU_APP_DATA_RESERVED** value in the *dfu_types.h* file in the DFU bootloader code (line ~56). To preserve two pages the value should be set to 0x0800. When your DFU bootloader has been modified to keep the bond information after updating the application set the switch to ON. Otherwise the bond information will be removed from the phone.
|
||||
**Keep bond information** - When upgrading the application on a bonded device the DFU bootloader may be configured to preserve some pages of the application's memory intact, so that the new application may read them. The new application must know the old data format in order to read them correctly. Our HRS DFU sample stores the Long Term Key (LTK) and the Service Attributes in two first pages. However, the DFU Bootloader, by default, clears the whole application's memory when the new application upload completes, and the bond information is lost. In order to configure the number of pages to be preserved set the **DFU_APP_DATA_RESERVED** value in the *dfu_types.h* file in the DFU bootloader code (line ~56). To preserve two pages the value should be set to 0x0800. When your DFU bootloader has been modified to keep the bond information after updating the application set the switch to ON. Otherwise the bond information will be removed from the phone.
|
||||
|
||||
**External MCU DFU** - The DFU service from the library, when connected to a DFU target, will check whether it is in application or in DFU bootloader mode. For DFU implementations from SDK 7.0 or newer this is done by reading the value of DFU Version characteristic. If the returned value is equal to 0x0100 (major = 0, minor = 1) it means that we are in the application mode and jump to the bootloader mode is required.
|
||||
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -67,7 +67,7 @@ public class DevicesAdapter extends WearableListView.Adapter {
|
||||
mNotAvailable = context.getString(R.string.not_available);
|
||||
mConnectingText = context.getString(R.string.state_connecting);
|
||||
mAvailableText = context.getString(R.string.devices_list_available);
|
||||
mBondedText = context.getString(R.string.devices_list_bound);
|
||||
mBondedText = context.getString(R.string.devices_list_bonded);
|
||||
mBondingText = context.getString(R.string.devices_list_bonding);
|
||||
mListView = listView;
|
||||
mHandler = new Handler();
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
<string name="devices_list_scanning">Scanning for nearby devices…</string>
|
||||
<string name="devices_list_start_scan">Scan for nearby devices</string>
|
||||
<string name="devices_list_available">Available</string>
|
||||
<string name="devices_list_bound">Bound</string>
|
||||
<string name="devices_list_bonded">Bonded</string>
|
||||
<string name="devices_list_bonding">Bonding…</string>
|
||||
<string name="devices_list_device_not_supported">Device not supported.</string>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user