Added an option to call BLE requests in synchronous way. Not tested.

This commit is contained in:
Aleksander Nowakowski
2018-05-04 16:32:39 +02:00
parent 1f2d78c8f5
commit 396983cb24
5 changed files with 49 additions and 36 deletions

View File

@@ -68,8 +68,9 @@ public abstract class BatteryManager<T extends BatteryManagerCallbacks> extends
public void enableBatteryLevelCharacteristicNotifications() {
if (isConnected()) {
// If the Battery Level characteristic is null, the request will be ignored
setNotificationCallback(mBatteryLevelCharacteristic)
.with(mBatteryLevelDataCallback);
enableNotifications(mBatteryLevelCharacteristic)
.with(mBatteryLevelDataCallback)
.done(device -> log(LogContract.Log.Level.INFO, "Battery Level notifications enabled"))
.fail((device, status) -> log(LogContract.Log.Level.WARNING, "Battery Level characteristic not found"));
}

View File

@@ -81,31 +81,30 @@ public class BPMManager extends BatteryManager<BPMManagerCallbacks> {
protected void initialize() {
super.initialize();
enableNotifications(mICPCharacteristic)
setNotificationCallback(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");
@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);
}
// 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 BPMStatus status, @Nullable final Calendar calendar) {
mCallbacks.onIntermediateCuffPressureReceived(device, cuffPressure, unit, pulseRate, userID, status, calendar);
}
@Override
public void onIntermediateCuffPressureReceived(@NonNull final BluetoothDevice device,
final float cuffPressure, final int unit,
@Nullable final Float pulseRate, @Nullable final Integer userID,
@Nullable final BPMStatus 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)
@Override
public void onInvalidDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
log(LogContract.Log.Level.WARNING, "Invalid ICP data received: " + data);
}
});
setIndicationCallback(mBPMCharacteristic)
.with(new BloodPressureMeasurementDataCallback() {
@Override
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
@@ -129,6 +128,9 @@ public class BPMManager extends BatteryManager<BPMManagerCallbacks> {
log(LogContract.Log.Level.WARNING, "Invalid BPM data received: " + data);
}
});
enableNotifications(mICPCharacteristic);
enableIndications(mBPMCharacteristic);
}
@Override

View File

@@ -124,8 +124,8 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
}
}).fail((device, status) -> log(LogContract.Log.Level.WARNING, "Could not read CGM Status characteristic"));
// Enable Continuous Glucose Measurement notifications
enableNotifications(mCGMMeasurementCharacteristic)
// Set notification and indication callbacks
setNotificationCallback(mCGMMeasurementCharacteristic)
.with(new ContinuousGlucoseMeasurementDataCallback() {
@Override
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
@@ -153,11 +153,9 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
public void onContinuousGlucoseMeasurementReceivedWithCrcError(@NonNull final BluetoothDevice device, @NonNull final Data data) {
log(LogContract.Log.Level.WARNING, "Continuous Glucose Measurement record received with CRC error");
}
})
.fail((device, status) -> log(LogContract.Log.Level.WARNING, "Failed to enable Continuous Glucose Measurement notifications (" + status + ")"));
});
// Enable CGM Specific Ops indications
enableIndications(mCGMSpecificOpsControlPointCharacteristic)
setIndicationCallback(mCGMSpecificOpsControlPointCharacteristic)
.with(new CGMSpecificOpsControlPointDataCallback() {
@Override
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
@@ -198,7 +196,7 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
}
});
enableIndications(mRecordAccessControlPointCharacteristic)
setIndicationCallback(mRecordAccessControlPointCharacteristic)
.with(new RecordAccessControlPointDataCallback() {
@Override
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
@@ -250,7 +248,14 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
mCallbacks.onOperationFailed(device);
}
}
})
});
// Enable notifications and indications
enableNotifications(mCGMMeasurementCharacteristic)
.fail((device, status) -> log(LogContract.Log.Level.WARNING, "Failed to enable Continuous Glucose Measurement notifications (" + status + ")"));
enableIndications(mCGMSpecificOpsControlPointCharacteristic)
.fail((device, status) -> log(LogContract.Log.Level.WARNING, "Failed to enable CGM Specific Ops Control Point indications notifications (" + status + ")"));
enableIndications(mRecordAccessControlPointCharacteristic)
.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

View File

@@ -69,7 +69,7 @@ public class CSCManager extends BatteryManager<CSCManagerCallbacks> {
super.initialize();
// CSC characteristic is required
enableNotifications(mCSCMeasurementCharacteristic)
setNotificationCallback(mCSCMeasurementCharacteristic)
.with(new CyclingSpeedAndCadenceDataCallback() {
@Override
public void onDataReceived(@NonNull final BluetoothDevice device, final @NonNull Data data) {
@@ -99,6 +99,7 @@ public class CSCManager extends BatteryManager<CSCManagerCallbacks> {
log(LogContract.Log.Level.WARNING, "Invalid CSC Measurement data received: " + data);
}
});
enableNotifications(mCSCMeasurementCharacteristic);
}
@Override

View File

@@ -112,8 +112,7 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
}
device.setCharacteristicNotification(mRecordAccessControlPointCharacteristic, true);
*/
enableNotifications(mGlucoseMeasurementCharacteristic)
setNotificationCallback(mGlucoseMeasurementCharacteristic)
.with(new GlucoseMeasurementDataCallback() {
@Override
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
@@ -148,7 +147,8 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
});
}
});
enableNotifications(mGlucoseMeasurementContextCharacteristic)
setNotificationCallback(mGlucoseMeasurementContextCharacteristic)
.with(new GlucoseMeasurementContextDataCallback() {
@Override
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
@@ -190,7 +190,7 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
}
});
enableIndications(mRecordAccessControlPointCharacteristic)
setIndicationCallback(mRecordAccessControlPointCharacteristic)
.with(new RecordAccessControlPointDataCallback() {
@Override
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
@@ -239,7 +239,11 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
mCallbacks.onOperationFailed(device);
}
}
})
});
enableNotifications(mGlucoseMeasurementCharacteristic);
enableNotifications(mGlucoseMeasurementContextCharacteristic);
enableIndications(mRecordAccessControlPointCharacteristic)
.fail((device, status) -> log(LogContract.Log.Level.WARNING, "Failed to enabled Record Access Control Point indications (error " + status + ")"));
}