mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2026-01-24 00:54:19 +01:00
Adjusting to match BLE library changes, BPM and CSC done
This commit is contained in:
@@ -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));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<BPMManagerCallbacks> {
|
||||
/** 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<BPMManagerCallbacks> {
|
||||
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<Request> initGatt(@NonNull final BluetoothGatt gatt) {
|
||||
final LinkedList<Request> 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<BPMManagerCallbacks> {
|
||||
|
||||
@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<BPMManagerCallbacks> {
|
||||
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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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 <code>null</code>
|
||||
*
|
||||
* @param device the target device
|
||||
* @param calendar
|
||||
* the timestamp or <code>null</code>
|
||||
*/
|
||||
void onTimestampRead(final BluetoothDevice device, final Calendar calendar);
|
||||
}
|
||||
|
||||
@@ -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<CGMSManagerCallbacks> {
|
||||
private BluetoothGattCharacteristic mCGMOpsControlPointCharacteristic;
|
||||
private BluetoothGattCharacteristic mRecordAccessControlPointCharacteristic;
|
||||
|
||||
private static CGMSManager managerInstance = null;
|
||||
private SparseArray<CGMSRecord> 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<CGMSManagerCallbacks> {
|
||||
@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<CGMSManagerCallbacks> {
|
||||
@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<CGMSManagerCallbacks> {
|
||||
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<CGMSManagerCallbacks> {
|
||||
*/
|
||||
public void clear() {
|
||||
mRecords.clear();
|
||||
mCallbacks.onDatasetClear(mBluetoothDevice);
|
||||
mCallbacks.onDatasetClear(getBluetoothDevice());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -315,7 +304,7 @@ public class CGMSManager extends BleManager<CGMSManagerCallbacks> {
|
||||
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<CGMSManagerCallbacks> {
|
||||
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<CGMSManagerCallbacks> {
|
||||
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<CGMSManagerCallbacks> {
|
||||
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<CGMSManagerCallbacks> {
|
||||
return;
|
||||
|
||||
clear();
|
||||
mCallbacks.onOperationStarted(mBluetoothDevice);
|
||||
mCallbacks.onOperationStarted(getBluetoothDevice());
|
||||
|
||||
final BluetoothGattCharacteristic characteristic = mRecordAccessControlPointCharacteristic;
|
||||
setOpCode(characteristic, OP_CODE_DELETE_STORED_RECORDS, OPERATOR_ALL_RECORDS);
|
||||
|
||||
@@ -187,12 +187,6 @@ public class CSCActivity extends BleProfileServiceReadyActivity<CSCService.CSCBi
|
||||
mBatteryLevelView.setText(R.string.not_available);
|
||||
}
|
||||
|
||||
// This method will not be called, as CSC Service connects with autoConnect = false
|
||||
@Override
|
||||
public void onLinklossOccur(final BluetoothDevice device) {
|
||||
mBatteryLevelView.setText(R.string.not_available);
|
||||
}
|
||||
|
||||
private void onMeasurementReceived(float speed, float distance, float totalDistance) {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
final int unit = Integer.parseInt(preferences.getString(SettingsFragment.SETTINGS_UNIT, String.valueOf(SettingsFragment.SETTINGS_UNIT_DEFAULT)));
|
||||
|
||||
@@ -34,31 +34,21 @@ import android.support.annotation.NonNull;
|
||||
import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.ble.ReadRequest;
|
||||
import no.nordicsemi.android.ble.Request;
|
||||
import no.nordicsemi.android.ble.callback.Data;
|
||||
import no.nordicsemi.android.ble.callback.profile.BatteryLevelCallback;
|
||||
import no.nordicsemi.android.ble.callback.profile.CyclingSpeedAndCadenceCallback;
|
||||
import no.nordicsemi.android.ble.callback.profile.BatteryLevelDataCallback;
|
||||
import no.nordicsemi.android.ble.callback.profile.CyclingSpeedAndCadenceDataCallback;
|
||||
import no.nordicsemi.android.log.LogContract;
|
||||
import no.nordicsemi.android.nrftoolbox.csc.settings.SettingsFragment;
|
||||
import no.nordicsemi.android.nrftoolbox.parser.CSCMeasurementParser;
|
||||
|
||||
public class CSCManager extends BleManager<CSCManagerCallbacks> {
|
||||
/**
|
||||
* 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<CSCManagerCallbacks> {
|
||||
|
||||
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<CSCManagerCallbacks> {
|
||||
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<CSCManagerCallbacks> {
|
||||
|
||||
// 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);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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 {
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<GlucoseManagerCallbacks> {
|
||||
|
||||
@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<GlucoseManagerCallbacks> {
|
||||
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<GlucoseManagerCallbacks> {
|
||||
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<GlucoseManagerCallbacks> {
|
||||
|
||||
@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<GlucoseManagerCallbacks> {
|
||||
*/
|
||||
public void clear() {
|
||||
mRecords.clear();
|
||||
mCallbacks.onOperationCompleted(mBluetoothDevice);
|
||||
mCallbacks.onOperationCompleted(getBluetoothDevice());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -444,7 +444,7 @@ public class GlucoseManager extends BleManager<GlucoseManagerCallbacks> {
|
||||
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<GlucoseManagerCallbacks> {
|
||||
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<GlucoseManagerCallbacks> {
|
||||
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<GlucoseManagerCallbacks> {
|
||||
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<GlucoseManagerCallbacks> {
|
||||
return;
|
||||
|
||||
clear();
|
||||
mCallbacks.onOperationStarted(mBluetoothDevice);
|
||||
mCallbacks.onOperationStarted(getBluetoothDevice());
|
||||
|
||||
final BluetoothGattCharacteristic characteristic = mRecordAccessControlPointCharacteristic;
|
||||
setOpCode(characteristic, OP_CODE_DELETE_STORED_RECORDS, OPERATOR_ALL_RECORDS);
|
||||
|
||||
@@ -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<HRSManagerCallbacks> {
|
||||
|
||||
@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<HRSManagerCallbacks> {
|
||||
|
||||
@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])) {
|
||||
|
||||
@@ -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<HTSManagerCallbacks> {
|
||||
|
||||
@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());
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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: <b>Otherwise it is null</b>.
|
||||
* @param savedInstanceState contains the data it most recently supplied in {@link #onSaveInstanceState(Bundle)}.
|
||||
* Note: <b>Otherwise it is null</b>.
|
||||
*/
|
||||
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: <b>Otherwise it is null</b>.
|
||||
* @param savedInstanceState contains the data it most recently supplied in {@link #onSaveInstanceState(Bundle)}.
|
||||
* Note: <b>Otherwise it is null</b>.
|
||||
*/
|
||||
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);
|
||||
|
||||
@@ -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: <b>Otherwise it is null</b>.
|
||||
* @param savedInstanceState contains the data it most recently supplied in {@link #onSaveInstanceState(Bundle)}.
|
||||
* Note: <b>Otherwise it is null</b>.
|
||||
*/
|
||||
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: <b>Otherwise it is null</b>.
|
||||
* @param savedInstanceState contains the data it most recently supplied in {@link #onSaveInstanceState(Bundle)}.
|
||||
* Note: <b>Otherwise it is null</b>.
|
||||
*/
|
||||
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);
|
||||
|
||||
@@ -341,17 +341,19 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
|
||||
}
|
||||
|
||||
/**
|
||||
* 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, the device name view are manager automatically.
|
||||
*
|
||||
* @param savedInstanceState contains the data it most recently supplied in {@link #onSaveInstanceState(Bundle)}. Note: <b>Otherwise it is null</b>.
|
||||
* @param savedInstanceState contains the data it most recently supplied in {@link #onSaveInstanceState(Bundle)}.
|
||||
* Note: <b>Otherwise it is null</b>.
|
||||
*/
|
||||
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: <b>Otherwise it is null</b>.
|
||||
* @param savedInstanceState contains the data it most recently supplied in {@link #onSaveInstanceState(Bundle)}.
|
||||
* Note: <b>Otherwise it is null</b>.
|
||||
*/
|
||||
protected void onViewCreated(final Bundle savedInstanceState) {
|
||||
// empty default implementation
|
||||
@@ -377,7 +379,7 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(@NonNull final Bundle savedInstanceState) {
|
||||
protected void onRestoreInstanceState(final @NonNull Bundle savedInstanceState) {
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
mDeviceName = savedInstanceState.getString(SIS_DEVICE_NAME);
|
||||
mBluetoothDevice = savedInstanceState.getParcelable(SIS_DEVICE);
|
||||
|
||||
@@ -55,6 +55,7 @@ public abstract class BleMulticonnectProfileService extends Service implements B
|
||||
public static final String BROADCAST_SERVICES_DISCOVERED = "no.nordicsemi.android.nrftoolbox.BROADCAST_SERVICES_DISCOVERED";
|
||||
public static final String BROADCAST_DEVICE_READY = "no.nordicsemi.android.nrftoolbox.DEVICE_READY";
|
||||
public static final String BROADCAST_BOND_STATE = "no.nordicsemi.android.nrftoolbox.BROADCAST_BOND_STATE";
|
||||
@Deprecated
|
||||
public static final String BROADCAST_BATTERY_LEVEL = "no.nordicsemi.android.nrftoolbox.BROADCAST_BATTERY_LEVEL";
|
||||
public static final String BROADCAST_ERROR = "no.nordicsemi.android.nrftoolbox.BROADCAST_ERROR";
|
||||
|
||||
@@ -63,6 +64,7 @@ public abstract class BleMulticonnectProfileService extends Service implements B
|
||||
public static final String EXTRA_BOND_STATE = "no.nordicsemi.android.nrftoolbox.EXTRA_BOND_STATE";
|
||||
public static final String EXTRA_SERVICE_PRIMARY = "no.nordicsemi.android.nrftoolbox.EXTRA_SERVICE_PRIMARY";
|
||||
public static final String EXTRA_SERVICE_SECONDARY = "no.nordicsemi.android.nrftoolbox.EXTRA_SERVICE_SECONDARY";
|
||||
@Deprecated
|
||||
public static final String EXTRA_BATTERY_LEVEL = "no.nordicsemi.android.nrftoolbox.EXTRA_BATTERY_LEVEL";
|
||||
public static final String EXTRA_ERROR_MESSAGE = "no.nordicsemi.android.nrftoolbox.EXTRA_ERROR_MESSAGE";
|
||||
public static final String EXTRA_ERROR_CODE = "no.nordicsemi.android.nrftoolbox.EXTRA_ERROR_CODE";
|
||||
@@ -187,6 +189,7 @@ public abstract class BleMulticonnectProfileService extends Service implements B
|
||||
* @return battery value or -1 if no value was received or Battery Level characteristic was not found
|
||||
* @deprecated Keep battery value in your manager instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getBatteryValue(final BluetoothDevice device) {
|
||||
final BleManager<BleManagerCallbacks> manager = mBleManagers.get(device);
|
||||
return manager.getBatteryValue();
|
||||
|
||||
@@ -295,17 +295,19 @@ public abstract class BleMulticonnectProfileServiceReadyActivity<E extends BleMu
|
||||
}
|
||||
|
||||
/**
|
||||
* 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: <b>Otherwise it is null</b>.
|
||||
* @param savedInstanceState contains the data it most recently supplied in {@link #onSaveInstanceState(Bundle)}.
|
||||
* Note: <b>Otherwise it is null</b>.
|
||||
*/
|
||||
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: <b>Otherwise it is null</b>.
|
||||
* @param savedInstanceState contains the data it most recently supplied in {@link #onSaveInstanceState(Bundle)}.
|
||||
* Note: <b>Otherwise it is null</b>.
|
||||
*/
|
||||
protected void onViewCreated(final Bundle savedInstanceState) {
|
||||
// empty default implementation
|
||||
|
||||
@@ -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<RSCManagerCallbacks> {
|
||||
@@ -86,7 +86,7 @@ public class RSCManager extends BleManager<RSCManagerCallbacks> {
|
||||
|
||||
@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;
|
||||
|
||||
@@ -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<TemplateManagerCallbacks> {
|
||||
// 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);
|
||||
|
||||
@@ -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<UARTManagerCallbacks> {
|
||||
/** Nordic UART Service UUID */
|
||||
@@ -110,7 +110,7 @@ public class UARTManager extends BleManager<UARTManagerCallbacks> {
|
||||
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<UARTManagerCallbacks> {
|
||||
@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);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user