Minor refactoring

This commit is contained in:
Aleksander Nowakowski
2018-05-22 17:38:43 +02:00
parent 37df7ea57c
commit 06da68c3b7
13 changed files with 78 additions and 70 deletions

View File

@@ -40,6 +40,7 @@ public abstract class BatteryManager<T extends BatteryManagerCallbacks> extends
super(context);
}
@NonNull
@Override
protected abstract BatteryManagerGattCallback getGattCallback();

View File

@@ -67,6 +67,7 @@ public class BPMManager extends BatteryManager<BPMManagerCallbacks> {
super(context);
}
@NonNull
@Override
protected BatteryManagerGattCallback getGattCallback() {
return mGattCallback;

View File

@@ -85,6 +85,7 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
super(context);
}
@NonNull
@Override
protected BatteryManagerGattCallback getGattCallback() {
return mGattCallback;
@@ -129,7 +130,7 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
.with(new ContinuousGlucoseMeasurementDataCallback() {
@Override
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
log(LogContract.Log.Level.APPLICATION, "\"" + CGMMeasurementParser.parse(mCGMMeasurementCharacteristic) + "\" received");
log(LogContract.Log.Level.APPLICATION, "\"" + CGMMeasurementParser.parse(data) + "\" received");
super.onDataReceived(device, data);
}
@@ -159,7 +160,7 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
.with(new CGMSpecificOpsControlPointDataCallback() {
@Override
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
log(LogContract.Log.Level.APPLICATION, "\"" + CGMSpecificOpsControlPointParser.parse(mCGMSpecificOpsControlPointCharacteristic) + "\" received");
log(LogContract.Log.Level.APPLICATION, "\"" + CGMSpecificOpsControlPointParser.parse(data) + "\" received");
super.onDataReceived(device, data);
}
@@ -261,7 +262,7 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
// Start Continuous Glucose session if hasn't been started before
if (mSessionStartTime == 0L) {
writeCharacteristic(mCGMSpecificOpsControlPointCharacteristic, CGMSpecificOpsControlPointData.startSession(mSecured))
.done(device -> log(LogContract.Log.Level.APPLICATION, "\"" + CGMSpecificOpsControlPointParser.parse(mCGMSpecificOpsControlPointCharacteristic) + "\" sent"))
.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + CGMSpecificOpsControlPointParser.parse(data) + "\" sent"))
.fail((device, status) -> log(LogContract.Log.Level.ERROR, "Failed to start session (error " + status + ")"));
}
}

View File

@@ -33,7 +33,7 @@ import android.support.annotation.NonNull;
import java.util.UUID;
import no.nordicsemi.android.ble.common.callback.csc.CyclingSpeedAndCadenceDataCallback;
import no.nordicsemi.android.ble.common.callback.csc.CyclingSpeedAndCadenceMeasurementDataCallback;
import no.nordicsemi.android.ble.data.Data;
import no.nordicsemi.android.log.LogContract;
import no.nordicsemi.android.nrftoolbox.battery.BatteryManager;
@@ -54,6 +54,7 @@ public class CSCManager extends BatteryManager<CSCManagerCallbacks> {
preferences = PreferenceManager.getDefaultSharedPreferences(context);
}
@NonNull
@Override
protected BatteryManagerGattCallback getGattCallback() {
return mGattCallback;
@@ -70,7 +71,7 @@ public class CSCManager extends BatteryManager<CSCManagerCallbacks> {
// CSC characteristic is required
setNotificationCallback(mCSCMeasurementCharacteristic)
.with(new CyclingSpeedAndCadenceDataCallback() {
.with(new CyclingSpeedAndCadenceMeasurementDataCallback() {
@Override
public void onDataReceived(@NonNull final BluetoothDevice device, final @NonNull Data data) {
log(LogContract.Log.Level.APPLICATION, "\"" + CSCMeasurementParser.parse(data) + "\" received");

View File

@@ -147,10 +147,10 @@ public class CSCService extends BleProfileService implements CSCManagerCallbacks
}
@Override
public void onBatteryLevelChanged(@NonNull final BluetoothDevice device, final int value) {
public void onBatteryLevelChanged(@NonNull final BluetoothDevice device, final int batteryLevel) {
final Intent broadcast = new Intent(BROADCAST_BATTERY_LEVEL);
broadcast.putExtra(EXTRA_DEVICE, getBluetoothDevice());
broadcast.putExtra(EXTRA_BATTERY_LEVEL, value);
broadcast.putExtra(EXTRA_BATTERY_LEVEL, batteryLevel);
LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
}

View File

@@ -83,6 +83,7 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
mHandler = new Handler();
}
@NonNull
@Override
protected BatteryManagerGattCallback getGattCallback() {
return mGattCallback;
@@ -116,7 +117,7 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
.with(new GlucoseMeasurementDataCallback() {
@Override
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
log(LogContract.Log.Level.APPLICATION, "\"" + GlucoseMeasurementParser.parse(mGlucoseMeasurementCharacteristic) + "\" received");
log(LogContract.Log.Level.APPLICATION, "\"" + GlucoseMeasurementParser.parse(data) + "\" received");
super.onDataReceived(device, data);
}
@@ -152,7 +153,7 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
.with(new GlucoseMeasurementContextDataCallback() {
@Override
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
log(LogContract.Log.Level.APPLICATION, "\"" + GlucoseMeasurementContextParser.parse(mGlucoseMeasurementContextCharacteristic) + "\" received");
log(LogContract.Log.Level.APPLICATION, "\"" + GlucoseMeasurementContextParser.parse(data) + "\" received");
super.onDataReceived(device, data);
}

View File

@@ -65,6 +65,7 @@ public class HRSManager extends BleManager<HRSManagerCallbacks> {
super(context);
}
@NonNull
@Override
protected BleManagerGattCallback getGattCallback() {
return mGattCallback;

View File

@@ -21,10 +21,10 @@
*/
package no.nordicsemi.android.nrftoolbox.parser;
import android.bluetooth.BluetoothGattCharacteristic;
import java.util.Locale;
import no.nordicsemi.android.ble.data.Data;
public class CGMMeasurementParser {
private static final int FLAGS_CGM_TREND_INFO_PRESENT = 1;
private static final int FLAGS_CGM_QUALITY_PRESENT = 1 << 1;
@@ -55,24 +55,24 @@ public class CGMMeasurementParser {
private static final int SSA_RESULT_LOWER_THAN_DEVICE_CAN_PROCESS = 1 << 22;
private static final int SSA_RESULT_HIGHER_THAN_DEVICE_CAN_PROCESS = 1 << 23;
public static String parse(final BluetoothGattCharacteristic characteristic) {
public static String parse(final Data data) {
// The CGM Measurement characteristic is a variable length structure containing one or more CGM Measurement records
int totalSize = characteristic.getValue().length;
int totalSize = data.getValue().length;
final StringBuilder builder = new StringBuilder();
int offset = 0;
while (offset < totalSize) {
offset += parseRecord(builder, characteristic, offset);
offset += parseRecord(builder, data, offset);
if (offset < totalSize)
builder.append("\n\n");
}
return builder.toString();
}
private static int parseRecord(final StringBuilder builder, final BluetoothGattCharacteristic characteristic, int offset) {
private static int parseRecord(final StringBuilder builder, final Data data, int offset) {
// Read size and flags bytes
final int size = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset++);
final int flags = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset++);
final int size = data.getIntValue(Data.FORMAT_UINT8, offset++);
final int flags = data.getIntValue(Data.FORMAT_UINT8, offset++);
/*
* false CGM Trend Information is not preset
@@ -105,18 +105,18 @@ public class CGMMeasurementParser {
final boolean ssaStatusOctetPresent = (flags & FLAGS_SENSOR_STATUS_ANNUNCIATION_STATUS_OCTET_PRESENT) > 0;
// Read CGM Glucose Concentration
final float glucoseConcentration = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset);
final float glucoseConcentration = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
offset += 2;
// Read time offset
final int timeOffset = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
final int timeOffset = data.getIntValue(Data.FORMAT_UINT16, offset);
offset += 2;
builder.append("Glucose concentration: ").append(glucoseConcentration).append(" mg/dL\n");
builder.append("Sequence number: ").append(timeOffset).append(" (Time Offset in min)\n");
if (ssaWarningOctetPresent) {
final int ssaWarningOctet = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset++);
final int ssaWarningOctet = data.getIntValue(Data.FORMAT_UINT8, offset++);
builder.append("Warnings:\n");
if ((ssaWarningOctet & SSA_SESSION_STOPPED) > 0)
builder.append("- Session Stopped\n");
@@ -133,7 +133,7 @@ public class CGMMeasurementParser {
}
if (ssaCalTempOctetPresent) {
final int ssaCalTempOctet = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset++);
final int ssaCalTempOctet = data.getIntValue(Data.FORMAT_UINT8, offset++);
builder.append("Cal/Temp Info:\n");
if ((ssaCalTempOctet & SSA_TIME_SYNC_REQUIRED) > 0)
builder.append("- Time Synchronization Required\n");
@@ -150,7 +150,7 @@ public class CGMMeasurementParser {
}
if (ssaStatusOctetPresent) {
final int ssaStatusOctet = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset++);
final int ssaStatusOctet = data.getIntValue(Data.FORMAT_UINT8, offset++);
builder.append("Status:\n");
if ((ssaStatusOctet & SSA_RESULT_LOWER_THAN_PATIENT_LOW_LEVEL) > 0)
builder.append("- Result Lower then Patient Low Level\n");
@@ -171,19 +171,19 @@ public class CGMMeasurementParser {
}
if (cgmTrendInformationPresent) {
final float trend = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset);
final float trend = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
offset += 2;
builder.append("Trend: ").append(trend).append(" mg/dL/min\n");
}
if (cgmQualityPresent) {
final float quality = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset);
final float quality = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
offset += 2;
builder.append("Quality: ").append(quality).append("%\n");
}
if (size > offset + 1) {
final int crc = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
final int crc = data.getIntValue(Data.FORMAT_UINT16, offset);
// offset += 2;
builder.append(String.format(Locale.US, "E2E-CRC: 0x%04X\n", crc));
}

View File

@@ -21,7 +21,7 @@
*/
package no.nordicsemi.android.nrftoolbox.parser;
import android.bluetooth.BluetoothGattCharacteristic;
import no.nordicsemi.android.ble.data.Data;
public class CGMSpecificOpsControlPointParser {
private final static int OP_SET_CGM_COMMUNICATION_INTERVAL = 1;
@@ -55,32 +55,32 @@ public class CGMSpecificOpsControlPointParser {
// TODO this parser does not support E2E-CRC!
public static String parse(final BluetoothGattCharacteristic characteristic) {
public static String parse(final Data data) {
int offset = 0;
final int opCode = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset++);
final int opCode = data.getIntValue(Data.FORMAT_UINT8, offset++);
final StringBuilder builder = new StringBuilder();
builder.append(parseOpCode(opCode));
switch (opCode) {
case OP_SET_CGM_COMMUNICATION_INTERVAL:
case OP_CGM_COMMUNICATION_INTERVAL_RESPONSE: {
final int interval = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset);
final int interval = data.getIntValue(Data.FORMAT_UINT8, offset);
builder.append(" to ").append(interval).append(" min");
break;
}
case OP_SET_GLUCOSE_CALIBRATION_VALUE: {
final float calConcentration = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset);
final float calConcentration = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
offset += 2;
final int calTime = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
final int calTime = data.getIntValue(Data.FORMAT_UINT16, offset);
offset += 2;
final int calTypeSampleLocation = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset++);
final int calTypeSampleLocation = data.getIntValue(Data.FORMAT_UINT8, offset++);
final int calType = calTypeSampleLocation & 0x0F;
final int calSampleLocation = (calTypeSampleLocation & 0xF0) >> 4;
final int calNextCalibrationTime = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
final int calNextCalibrationTime = data.getIntValue(Data.FORMAT_UINT16, offset);
// offset += 2;
// final int calCalibrationDataRecordNumber = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
// final int calCalibrationDataRecordNumber = data.getIntValue(Data.FORMAT_UINT16, offset);
// offset += 2;
// final int calStatus = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset++);
// final int calStatus = data.getIntValue(Data.FORMAT_UINT8, offset++);
builder.append(" to:\n");
builder.append("Glucose Concentration of Calibration: ").append(calConcentration).append(" mg/dL\n");
@@ -93,23 +93,23 @@ public class CGMSpecificOpsControlPointParser {
break;
}
case OP_GET_GLUCOSE_CALIBRATION_VALUE: {
final int calibrationRecordNumber = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
final int calibrationRecordNumber = data.getIntValue(Data.FORMAT_UINT16, offset);
builder.append(": ").append(parseRecordNumber(calibrationRecordNumber));
break;
}
case OP_GLUCOSE_CALIBRATION_VALUE_RESPONSE: {
final float calConcentration = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset);
final float calConcentration = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
offset += 2;
final int calTime = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
final int calTime = data.getIntValue(Data.FORMAT_UINT16, offset);
offset += 2;
final int calTypeSampleLocation = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset++);
final int calTypeSampleLocation = data.getIntValue(Data.FORMAT_UINT8, offset++);
final int calType = calTypeSampleLocation & 0x0F;
final int calSampleLocation = (calTypeSampleLocation & 0xF0) >> 4;
final int calNextCalibrationTime = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
final int calNextCalibrationTime = data.getIntValue(Data.FORMAT_UINT16, offset);
offset += 2;
final int calCalibrationDataRecordNumber = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
final int calCalibrationDataRecordNumber = data.getIntValue(Data.FORMAT_UINT16, offset);
offset += 2;
final int calStatus = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset);
final int calStatus = data.getIntValue(Data.FORMAT_UINT8, offset);
builder.append(":\n");
if (calCalibrationDataRecordNumber > 0) {
@@ -129,7 +129,7 @@ public class CGMSpecificOpsControlPointParser {
case OP_SET_PATIENT_LOW_ALERT_LEVEL:
case OP_SET_HYPO_ALERT_LEVEL:
case OP_SET_HYPER_ALERT_LEVEL: {
final float level = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset);
final float level = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
builder.append(" to: ").append(level).append(" mg/dL");
break;
}
@@ -137,25 +137,25 @@ public class CGMSpecificOpsControlPointParser {
case OP_PATIENT_LOW_ALERT_LEVEL_RESPONSE:
case OP_HYPO_ALERT_LEVEL_RESPONSE:
case OP_HYPER_ALERT_LEVEL_RESPONSE: {
final float level = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset);
final float level = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
builder.append(": ").append(level).append(" mg/dL");
break;
}
case OP_SET_RATE_OF_DECREASE_ALERT_LEVEL:
case OP_SET_RATE_OF_INCREASE_ALERT_LEVEL: {
final float level = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset);
final float level = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
builder.append(" to: ").append(level).append(" mg/dL/min");
break;
}
case OP_RATE_OF_DECREASE_ALERT_LEVEL_RESPONSE:
case OP_RATE_OF_INCREASE_ALERT_LEVEL_RESPONSE: {
final float level = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset);
final float level = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
builder.append(": ").append(level).append(" mg/dL/min");
break;
}
case OP_CODE_RESPONSE_CODE:
final int requestOpCode = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset++);
final int responseCode = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset++);
final int requestOpCode = data.getIntValue(Data.FORMAT_UINT8, offset++);
final int responseCode = data.getIntValue(Data.FORMAT_UINT8, offset++);
builder.append(" to ").append(parseOpCode(requestOpCode)).append(": ").append(parseResponseCode(responseCode));
break;
}

View File

@@ -21,17 +21,17 @@
*/
package no.nordicsemi.android.nrftoolbox.parser;
import android.bluetooth.BluetoothGattCharacteristic;
import no.nordicsemi.android.ble.data.Data;
public class GlucoseMeasurementContextParser {
private static final int UNIT_kg = 0;
private static final int UNIT_l = 1;
public static String parse(final BluetoothGattCharacteristic characteristic) {
public static String parse(final Data data) {
final StringBuilder builder = new StringBuilder();
int offset = 0;
final int flags = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset);
final int flags = data.getIntValue(Data.FORMAT_UINT8, offset);
offset += 1;
final boolean carbohydratePresent = (flags & 0x01) > 0;
@@ -43,7 +43,7 @@ public class GlucoseMeasurementContextParser {
final boolean hbA1cPresent = (flags & 0x40) > 0;
final boolean moreFlagsPresent = (flags & 0x80) > 0;
final int sequenceNumber = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
final int sequenceNumber = data.getIntValue(Data.FORMAT_UINT16, offset);
offset += 2;
if (moreFlagsPresent) // not supported yet
@@ -52,20 +52,20 @@ public class GlucoseMeasurementContextParser {
builder.append("Sequence number: ").append(sequenceNumber);
if (carbohydratePresent) {
final int carbohydrateId = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset);
final float carbohydrateUnits = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset + 1);
final int carbohydrateId = data.getIntValue(Data.FORMAT_UINT8, offset);
final float carbohydrateUnits = data.getFloatValue(Data.FORMAT_SFLOAT, offset + 1);
builder.append("\nCarbohydrate: ").append(getCarbohydrate(carbohydrateId)).append(" (").append(carbohydrateUnits).append(carbohydrateUnits == UNIT_kg ? "kg" : "l").append(")");
offset += 3;
}
if (mealPresent) {
final int meal = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset);
final int meal = data.getIntValue(Data.FORMAT_UINT8, offset);
builder.append("\nMeal: ").append(getMeal(meal));
offset += 1;
}
if (testerHealthPresent) {
final int testerHealth = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset);
final int testerHealth = data.getIntValue(Data.FORMAT_UINT8, offset);
final int tester = (testerHealth & 0xF0) >> 4;
final int health = (testerHealth & 0x0F);
builder.append("\nTester: ").append(getTester(tester));
@@ -74,21 +74,21 @@ public class GlucoseMeasurementContextParser {
}
if (exercisePresent) {
final int exerciseDuration = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
final int exerciseIntensity = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset + 2);
final int exerciseDuration = data.getIntValue(Data.FORMAT_UINT16, offset);
final int exerciseIntensity = data.getIntValue(Data.FORMAT_UINT8, offset + 2);
builder.append("\nExercise duration: ").append(exerciseDuration).append("s (intensity ").append(exerciseIntensity).append("%)");
offset += 3;
}
if (medicationPresent) {
final int medicationId = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset);
final float medicationQuantity = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset + 1);
final int medicationId = data.getIntValue(Data.FORMAT_UINT8, offset);
final float medicationQuantity = data.getFloatValue(Data.FORMAT_SFLOAT, offset + 1);
builder.append("\nMedication: ").append(getMedicationId(medicationId)).append(" (").append(medicationQuantity).append(medicationUnit == UNIT_kg ? "kg" : "l");
offset += 3;
}
if (hbA1cPresent) {
final float HbA1c = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset);
final float HbA1c = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
builder.append("\nHbA1c: ").append(HbA1c).append("%");
}
return builder.toString();

View File

@@ -22,7 +22,7 @@
package no.nordicsemi.android.nrftoolbox.parser;
import android.bluetooth.BluetoothGattCharacteristic;
import no.nordicsemi.android.ble.data.Data;
public class GlucoseMeasurementParser {
private static final int UNIT_kgpl = 0;
@@ -41,11 +41,11 @@ public class GlucoseMeasurementParser {
private static final int STATUS_GENERAL_DEVICE_FAULT = 0x0400;
private static final int STATUS_TIME_FAULT = 0x0800;
public static String parse(final BluetoothGattCharacteristic characteristic) {
public static String parse(final Data data) {
final StringBuilder builder = new StringBuilder();
int offset = 0;
final int flags = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset);
final int flags = data.getIntValue(Data.FORMAT_UINT8, offset);
offset += 1;
final boolean timeOffsetPresent = (flags & 0x01) > 0;
@@ -55,23 +55,23 @@ public class GlucoseMeasurementParser {
final boolean contextInfoFollows = (flags & 0x10) > 0;
// create and fill the new record
final int sequenceNumber = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
final int sequenceNumber = data.getIntValue(Data.FORMAT_UINT16, offset);
builder.append("Sequence Number: ").append(sequenceNumber);
offset += 2;
builder.append("\nBase Time: ").append(DateTimeParser.parse(characteristic, offset));
builder.append("\nBase Time: ").append(DateTimeParser.parse(data, offset));
offset += 7;
if (timeOffsetPresent) {
// time offset is ignored in the current release
final int timeOffset = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_SINT16, offset);
final int timeOffset = data.getIntValue(Data.FORMAT_SINT16, offset);
builder.append("\nTime Offset: ").append(timeOffset).append(" min");
offset += 2;
}
if (typeAndLocationPresent) {
final float glucoseConcentration = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset);
final int typeAndLocation = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset + 2);
final float glucoseConcentration = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
final int typeAndLocation = data.getIntValue(Data.FORMAT_UINT8, offset + 2);
final int type = (typeAndLocation & 0xF0) >> 4; // TODO this way or around?
final int sampleLocation = (typeAndLocation & 0x0F);
builder.append("\nGlucose Concentration: ").append(glucoseConcentration).append(concentrationUnit == UNIT_kgpl ? " kg/l" : " mol/l");
@@ -81,7 +81,7 @@ public class GlucoseMeasurementParser {
}
if (sensorStatusAnnunciationPresent) {
final int status = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
final int status = data.getIntValue(Data.FORMAT_UINT16, offset);
builder.append("Status:\n").append(getStatusAnnunciation(status));
}

View File

@@ -54,6 +54,7 @@ public class TemplateManager extends BleManager<TemplateManagerCallbacks> {
super(context);
}
@NonNull
@Override
protected BleManagerGattCallback getGattCallback() {
return mGattCallback;

View File

@@ -56,6 +56,7 @@ public class UARTManager extends BleManager<UARTManagerCallbacks> {
super(context);
}
@NonNull
@Override
protected BleManagerGattCallback getGattCallback() {
return mGattCallback;