Java Code Examples for no.nordicsemi.android.ble.data.Data#getFloatValue()

The following examples show how to use no.nordicsemi.android.ble.data.Data#getFloatValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TemperatureMeasurementDataCallback.java    From Android-BLE-Common-Library with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
	super.onDataReceived(device, data);

	if (data.size() < 5) {
		onInvalidDataReceived(device, data);
		return;
	}

	int offset = 0;
	final int flags = data.getIntValue(Data.FORMAT_UINT8, offset);
	final int unit = (flags & 0x01) == UNIT_C ? UNIT_C : UNIT_F;
	final boolean timestampPresent = (flags & 0x02) != 0;
	final boolean temperatureTypePresent = (flags & 0x04) != 0;
	offset += 1;

	if (data.size() < 5 + (timestampPresent ? 7 : 0) + (temperatureTypePresent ? 1 : 0)) {
		onInvalidDataReceived(device, data);
		return;
	}

	final float temperature = data.getFloatValue(Data.FORMAT_FLOAT, 1);
	offset += 4;

	Calendar calendar = null;
	if (timestampPresent) {
		calendar = DateTimeDataCallback.readDateTime(data, offset);
		offset += 7;
	}

	Integer type = null;
	if (temperatureTypePresent) {
		type = data.getIntValue(Data.FORMAT_UINT8, offset);
		// offset += 1;
	}

	onTemperatureMeasurementReceived(device, temperature, unit, calendar, type);
}
 
Example 2
Source File: TemperatureMeasurementDataCallback.java    From Android-BLE-Library with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
	super.onDataReceived(device, data);

	if (data.size() < 5) {
		onInvalidDataReceived(device, data);
		return;
	}

	int offset = 0;
	final int flags = data.getIntValue(Data.FORMAT_UINT8, offset);
	final int unit = (flags & 0x01) == UNIT_C ? UNIT_C : UNIT_F;
	final boolean timestampPresent = (flags & 0x02) != 0;
	final boolean temperatureTypePresent = (flags & 0x04) != 0;
	offset += 1;

	if (data.size() < 5 + (timestampPresent ? 7 : 0) + (temperatureTypePresent ? 1 : 0)) {
		onInvalidDataReceived(device, data);
		return;
	}

	final float temperature = data.getFloatValue(Data.FORMAT_FLOAT, 1);
	offset += 4;

	Calendar calendar = null;
	if (timestampPresent) {
		calendar = DateTimeDataCallback.readDateTime(data, offset);
		offset += 7;
	}

	Integer type = null;
	if (temperatureTypePresent) {
		type = data.getIntValue(Data.FORMAT_UINT8, offset);
		// offset += 1;
	}

	onTemperatureMeasurementReceived(device, temperature, unit, calendar, type);
}
 
Example 3
Source File: BloodPressureMeasurementDataCallback.java    From Android-BLE-Common-Library with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
	super.onDataReceived(device, data);

	if (data.size() < 7) {
		onInvalidDataReceived(device, data);
		return;
	}
	// First byte: flags
	int offset = 0;
	final int flags = data.getIntValue(Data.FORMAT_UINT8, offset++);

	// See UNIT_* for unit options
	final int unit = (flags & 0x01) == UNIT_mmHg ? UNIT_mmHg : UNIT_kPa;
	final boolean timestampPresent         = (flags & 0x02) != 0;
	final boolean pulseRatePresent         = (flags & 0x04) != 0;
	final boolean userIdPresent            = (flags & 0x08) != 0;
	final boolean measurementStatusPresent = (flags & 0x10) != 0;

	if (data.size() < 7
			+ (timestampPresent ? 7 : 0) + (pulseRatePresent ? 2 : 0)
			+ (userIdPresent ? 1 : 0) + (measurementStatusPresent ? 2 : 0)) {
		onInvalidDataReceived(device, data);
		return;
	}

	// Following bytes - systolic, diastolic and mean arterial pressure
	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);
	offset += 6;

	// Parse timestamp if present
	Calendar calendar = null;
	if (timestampPresent) {
		calendar = DateTimeDataCallback.readDateTime(data, offset);
		offset += 7;
	}

	// Parse pulse rate if present
	Float pulseRate = null;
	if (pulseRatePresent) {
		pulseRate = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
		offset += 2;
	}

	// Read user id if present
	Integer userId = null;
	if (userIdPresent) {
		userId = data.getIntValue(Data.FORMAT_UINT8, offset);
		offset += 1;
	}

	// Read measurement status if present
	BPMStatus status = null;
	if (measurementStatusPresent) {
		final int measurementStatus = data.getIntValue(Data.FORMAT_UINT16, offset);
		// offset += 2;
		status = new BPMStatus(measurementStatus);
	}

	onBloodPressureMeasurementReceived(device, systolic, diastolic, meanArterialPressure, unit, pulseRate, userId, status, calendar);
}
 
Example 4
Source File: IntermediateCuffPressureDataCallback.java    From Android-BLE-Common-Library with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
	super.onDataReceived(device, data);

	if (data.size() < 7) {
		onInvalidDataReceived(device, data);
		return;
	}
	// First byte: flags
	int offset = 0;
	final int flags = data.getIntValue(Data.FORMAT_UINT8, offset++);

	// See UNIT_* for unit options
	final int unit = (flags & 0x01) == UNIT_mmHg ? UNIT_mmHg : UNIT_kPa;
	final boolean timestampPresent         = (flags & 0x02) != 0;
	final boolean pulseRatePresent         = (flags & 0x04) != 0;
	final boolean userIdPresent            = (flags & 0x08) != 0;
	final boolean measurementStatusPresent = (flags & 0x10) != 0;

	if (data.size() < 7
			+ (timestampPresent ? 7 : 0) + (pulseRatePresent ? 2 : 0)
			+ (userIdPresent ? 1 : 0) + (measurementStatusPresent ? 2 : 0)) {
		onInvalidDataReceived(device, data);
		return;
	}

	// Following bytes - systolic, diastolic and mean arterial pressure
	final float cuffPressure = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
	// final float ignored_1 = data.getFloatValue(Data.FORMAT_SFLOAT, offset + 2);
	// final float ignored_2 = data.getFloatValue(Data.FORMAT_SFLOAT, offset + 4);
	offset += 6;

	// Parse timestamp if present
	Calendar calendar = null;
	if (timestampPresent) {
		calendar = DateTimeDataCallback.readDateTime(data, offset);
		offset += 7;
	}

	// Parse pulse rate if present
	Float pulseRate = null;
	if (pulseRatePresent) {
		pulseRate = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
		offset += 2;
	}

	// Read user id if present
	Integer userId = null;
	if (userIdPresent) {
		userId = data.getIntValue(Data.FORMAT_UINT8, offset);
		offset += 1;
	}

	// Read measurement status if present
	BPMStatus status = null;
	if (measurementStatusPresent) {
		final int measurementStatus = data.getIntValue(Data.FORMAT_UINT16, offset);
		// offset += 2;
		status = new BPMStatus(measurementStatus);
	}

	onIntermediateCuffPressureReceived(device, cuffPressure, unit, pulseRate, userId, status, calendar);
}
 
Example 5
Source File: GlucoseMeasurementDataCallback.java    From Android-BLE-Common-Library with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
	super.onDataReceived(device, data);

	if (data.size() < 10) {
		onInvalidDataReceived(device, data);
		return;
	}

	int offset = 0;

	final int flags = data.getIntValue(Data.FORMAT_UINT8, offset++);
	final boolean timeOffsetPresent = (flags & 0x01) != 0;
	final boolean glucoseDataPresent = (flags & 0x02) != 0;
	final boolean unitMolL = (flags & 0x04) != 0;
	final boolean sensorStatusAnnunciationPresent = (flags & 0x08) != 0;
	final boolean contextInformationFollows = (flags & 0x10) != 0;

	if (data.size() < 10 + (timeOffsetPresent ? 2 : 0) + (glucoseDataPresent ? 3 : 0)
		+ (sensorStatusAnnunciationPresent ? 2 : 0)) {
		onInvalidDataReceived(device, data);
		return;
	}

	// Required fields
	final int sequenceNumber = data.getIntValue(Data.FORMAT_UINT16, offset);
	offset += 2;
	final Calendar baseTime = DateTimeDataCallback.readDateTime(data, 3);
	offset += 7;

	if (baseTime == null) {
		onInvalidDataReceived(device, data);
		return;
	}

	// Optional fields
	if (timeOffsetPresent) {
		final int timeOffset = data.getIntValue(Data.FORMAT_SINT16, offset);
		offset += 2;

		baseTime.add(Calendar.MINUTE, timeOffset);
	}

	Float glucoseConcentration = null;
	Integer unit = null;
	Integer type = null;
	Integer sampleLocation = null;
	if (glucoseDataPresent) {
		glucoseConcentration = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
		final int typeAndSampleLocation = data.getIntValue(Data.FORMAT_UINT8, offset + 2);
		offset += 3;

		type = typeAndSampleLocation & 0x0F;
		sampleLocation = typeAndSampleLocation >> 4;
		unit = unitMolL ? UNIT_mol_L : UNIT_kg_L;
	}

	GlucoseStatus status = null;
	if (sensorStatusAnnunciationPresent) {
		final int value = data.getIntValue(Data.FORMAT_UINT16, offset);
		// offset += 2;

		status = new GlucoseStatus(value);
	}

	onGlucoseMeasurementReceived(device, sequenceNumber, baseTime /* with offset */,
			glucoseConcentration, unit, type, sampleLocation, status, contextInformationFollows);
}
 
Example 6
Source File: GlucoseMeasurementContextDataCallback.java    From Android-BLE-Common-Library with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
	super.onDataReceived(device, data);
	
	if (data.size() < 3) {
		onInvalidDataReceived(device, data);
		return;
	}

	int offset = 0;

	final int flags = data.getIntValue(Data.FORMAT_UINT8, offset++);
	final boolean carbohydratePresent = (flags & 0x01) != 0;
	final boolean mealPresent = (flags & 0x02) != 0;
	final boolean testerHealthPresent = (flags & 0x04) != 0;
	final boolean exercisePresent = (flags & 0x08) != 0;
	final boolean medicationPresent = (flags & 0x10) != 0;
	final boolean medicationUnitLiter = (flags & 0x20) != 0;
	final boolean HbA1cPresent = (flags & 0x40) != 0;
	final boolean extendedFlagsPresent = (flags & 0x80) != 0;

	if (data.size() < 3 + (carbohydratePresent ? 3 : 0) + (mealPresent ? 1 : 0) + (testerHealthPresent ? 1 : 0)
			+ (exercisePresent ? 3 : 0) + (medicationPresent ? 3 : 0) + (HbA1cPresent ? 2 : 0)
			+ (extendedFlagsPresent ? 1 : 0)) {
		onInvalidDataReceived(device, data);
		return;
	}

	final int sequenceNumber = data.getIntValue(Data.FORMAT_UINT16, offset);
	offset += 2;

	// Optional fields
	if (extendedFlagsPresent) {
		// ignore extended flags
		offset += 1;
	}

	Carbohydrate carbohydrate = null;
	Float carbohydrateAmount = null;
	if (carbohydratePresent) {
		final int carbohydrateId = data.getIntValue(Data.FORMAT_UINT8, offset);
		carbohydrate = Carbohydrate.from(carbohydrateId);
		carbohydrateAmount = data.getFloatValue(Data.FORMAT_SFLOAT, offset + 1); // in grams
		offset += 3;
	}

	Meal meal = null;
	if (mealPresent) {
		final int mealId = data.getIntValue(Data.FORMAT_UINT8, offset);
		meal = Meal.from(mealId);
		offset += 1;
	}

	Tester tester = null;
	Health health = null;
	if (testerHealthPresent) {
		final int testerAndHealth = data.getIntValue(Data.FORMAT_UINT8, offset);
		tester = Tester.from(testerAndHealth & 0x0F);
		health = Health.from(testerAndHealth >> 4);
		offset += 1;
	}

	Integer exerciseDuration = null;
	Integer exerciseIntensity = null;
	if (exercisePresent) {
		exerciseDuration = data.getIntValue(Data.FORMAT_UINT16, offset); // in seconds
		exerciseIntensity = data.getIntValue(Data.FORMAT_UINT8, offset + 2); // in percentage
		offset += 3;
	}

	Medication medication = null;
	Float medicationAmount = null;
	Integer medicationUnit = null;
	if (medicationPresent) {
		final int medicationId = data.getIntValue(Data.FORMAT_UINT8, offset);
		medication = Medication.from(medicationId);
		medicationAmount = data.getFloatValue(Data.FORMAT_SFLOAT, offset + 1); // mg or ml
		medicationUnit = medicationUnitLiter ? UNIT_ml : UNIT_mg;
		offset += 3;
	}

	Float HbA1c = null;
	if (HbA1cPresent) {
		HbA1c = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
		// offset += 2;
	}

	onGlucoseMeasurementContextReceived(device, sequenceNumber, carbohydrate, carbohydrateAmount,
			meal, tester, health, exerciseDuration, exerciseIntensity,
			medication, medicationAmount, medicationUnit, HbA1c);
}
 
Example 7
Source File: BloodPressureMeasurementDataCallback.java    From Android-BLE-Library with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
	super.onDataReceived(device, data);

	if (data.size() < 7) {
		onInvalidDataReceived(device, data);
		return;
	}
	// First byte: flags
	int offset = 0;
	final int flags = data.getIntValue(Data.FORMAT_UINT8, offset++);

	// See UNIT_* for unit options
	final int unit = (flags & 0x01) == UNIT_mmHg ? UNIT_mmHg : UNIT_kPa;
	final boolean timestampPresent         = (flags & 0x02) != 0;
	final boolean pulseRatePresent         = (flags & 0x04) != 0;
	final boolean userIdPresent            = (flags & 0x08) != 0;
	final boolean measurementStatusPresent = (flags & 0x10) != 0;

	if (data.size() < 7
			+ (timestampPresent ? 7 : 0) + (pulseRatePresent ? 2 : 0)
			+ (userIdPresent ? 1 : 0) + (measurementStatusPresent ? 2 : 0)) {
		onInvalidDataReceived(device, data);
		return;
	}

	// Following bytes - systolic, diastolic and mean arterial pressure
	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);
	offset += 6;

	// Parse timestamp if present
	Calendar calendar = null;
	if (timestampPresent) {
		calendar = DateTimeDataCallback.readDateTime(data, offset);
		offset += 7;
	}

	// Parse pulse rate if present
	Float pulseRate = null;
	if (pulseRatePresent) {
		pulseRate = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
		offset += 2;
	}

	// Read user id if present
	Integer userId = null;
	if (userIdPresent) {
		userId = data.getIntValue(Data.FORMAT_UINT8, offset);
		offset += 1;
	}

	// Read measurement status if present
	BPMStatus status = null;
	if (measurementStatusPresent) {
		final int measurementStatus = data.getIntValue(Data.FORMAT_UINT16, offset);
		// offset += 2;
		status = new BPMStatus(measurementStatus);
	}

	onBloodPressureMeasurementReceived(device, systolic, diastolic, meanArterialPressure, unit, pulseRate, userId, status, calendar);
}
 
Example 8
Source File: IntermediateCuffPressureDataCallback.java    From Android-BLE-Library with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
	super.onDataReceived(device, data);

	if (data.size() < 7) {
		onInvalidDataReceived(device, data);
		return;
	}
	// First byte: flags
	int offset = 0;
	final int flags = data.getIntValue(Data.FORMAT_UINT8, offset++);

	// See UNIT_* for unit options
	final int unit = (flags & 0x01) == UNIT_mmHg ? UNIT_mmHg : UNIT_kPa;
	final boolean timestampPresent         = (flags & 0x02) != 0;
	final boolean pulseRatePresent         = (flags & 0x04) != 0;
	final boolean userIdPresent            = (flags & 0x08) != 0;
	final boolean measurementStatusPresent = (flags & 0x10) != 0;

	if (data.size() < 7
			+ (timestampPresent ? 7 : 0) + (pulseRatePresent ? 2 : 0)
			+ (userIdPresent ? 1 : 0) + (measurementStatusPresent ? 2 : 0)) {
		onInvalidDataReceived(device, data);
		return;
	}

	// Following bytes - systolic, diastolic and mean arterial pressure
	final float cuffPressure = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
	// final float ignored_1 = data.getFloatValue(Data.FORMAT_SFLOAT, offset + 2);
	// final float ignored_2 = data.getFloatValue(Data.FORMAT_SFLOAT, offset + 4);
	offset += 6;

	// Parse timestamp if present
	Calendar calendar = null;
	if (timestampPresent) {
		calendar = DateTimeDataCallback.readDateTime(data, offset);
		offset += 7;
	}

	// Parse pulse rate if present
	Float pulseRate = null;
	if (pulseRatePresent) {
		pulseRate = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
		offset += 2;
	}

	// Read user id if present
	Integer userId = null;
	if (userIdPresent) {
		userId = data.getIntValue(Data.FORMAT_UINT8, offset);
		offset += 1;
	}

	// Read measurement status if present
	BPMStatus status = null;
	if (measurementStatusPresent) {
		final int measurementStatus = data.getIntValue(Data.FORMAT_UINT16, offset);
		// offset += 2;
		status = new BPMStatus(measurementStatus);
	}

	onIntermediateCuffPressureReceived(device, cuffPressure, unit, pulseRate, userId, status, calendar);
}
 
Example 9
Source File: GlucoseMeasurementDataCallback.java    From Android-BLE-Library with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
	super.onDataReceived(device, data);

	if (data.size() < 10) {
		onInvalidDataReceived(device, data);
		return;
	}

	int offset = 0;

	final int flags = data.getIntValue(Data.FORMAT_UINT8, offset++);
	final boolean timeOffsetPresent = (flags & 0x01) != 0;
	final boolean glucoseDataPresent = (flags & 0x02) != 0;
	final boolean unitMolL = (flags & 0x04) != 0;
	final boolean sensorStatusAnnunciationPresent = (flags & 0x08) != 0;
	final boolean contextInformationFollows = (flags & 0x10) != 0;

	if (data.size() < 10 + (timeOffsetPresent ? 2 : 0) + (glucoseDataPresent ? 3 : 0)
		+ (sensorStatusAnnunciationPresent ? 2 : 0)) {
		onInvalidDataReceived(device, data);
		return;
	}

	// Required fields
	final int sequenceNumber = data.getIntValue(Data.FORMAT_UINT16, offset);
	offset += 2;
	final Calendar baseTime = DateTimeDataCallback.readDateTime(data, 3);
	offset += 7;

	if (baseTime == null) {
		onInvalidDataReceived(device, data);
		return;
	}

	// Optional fields
	if (timeOffsetPresent) {
		final int timeOffset = data.getIntValue(Data.FORMAT_SINT16, offset);
		offset += 2;

		baseTime.add(Calendar.MINUTE, timeOffset);
	}

	Float glucoseConcentration = null;
	Integer unit = null;
	Integer type = null;
	Integer sampleLocation = null;
	if (glucoseDataPresent) {
		glucoseConcentration = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
		final int typeAndSampleLocation = data.getIntValue(Data.FORMAT_UINT8, offset + 2);
		offset += 3;

		type = typeAndSampleLocation & 0x0F;
		sampleLocation = typeAndSampleLocation >> 4;
		unit = unitMolL ? UNIT_mol_L : UNIT_kg_L;
	}

	GlucoseStatus status = null;
	if (sensorStatusAnnunciationPresent) {
		final int value = data.getIntValue(Data.FORMAT_UINT16, offset);
		// offset += 2;

		status = new GlucoseStatus(value);
	}

	onGlucoseMeasurementReceived(device, sequenceNumber, baseTime /* with offset */,
			glucoseConcentration, unit, type, sampleLocation, status, contextInformationFollows);
}
 
Example 10
Source File: GlucoseMeasurementContextDataCallback.java    From Android-BLE-Library with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
	super.onDataReceived(device, data);
	
	if (data.size() < 3) {
		onInvalidDataReceived(device, data);
		return;
	}

	int offset = 0;

	final int flags = data.getIntValue(Data.FORMAT_UINT8, offset++);
	final boolean carbohydratePresent = (flags & 0x01) != 0;
	final boolean mealPresent = (flags & 0x02) != 0;
	final boolean testerHealthPresent = (flags & 0x04) != 0;
	final boolean exercisePresent = (flags & 0x08) != 0;
	final boolean medicationPresent = (flags & 0x10) != 0;
	final boolean medicationUnitLiter = (flags & 0x20) != 0;
	final boolean HbA1cPresent = (flags & 0x40) != 0;
	final boolean extendedFlagsPresent = (flags & 0x80) != 0;

	if (data.size() < 3 + (carbohydratePresent ? 3 : 0) + (mealPresent ? 1 : 0) + (testerHealthPresent ? 1 : 0)
			+ (exercisePresent ? 3 : 0) + (medicationPresent ? 3 : 0) + (HbA1cPresent ? 2 : 0)
			+ (extendedFlagsPresent ? 1 : 0)) {
		onInvalidDataReceived(device, data);
		return;
	}

	final int sequenceNumber = data.getIntValue(Data.FORMAT_UINT16, offset);
	offset += 2;

	// Optional fields
	if (extendedFlagsPresent) {
		// ignore extended flags
		offset += 1;
	}

	Carbohydrate carbohydrate = null;
	Float carbohydrateAmount = null;
	if (carbohydratePresent) {
		final int carbohydrateId = data.getIntValue(Data.FORMAT_UINT8, offset);
		carbohydrate = Carbohydrate.from(carbohydrateId);
		carbohydrateAmount = data.getFloatValue(Data.FORMAT_SFLOAT, offset + 1); // in grams
		offset += 3;
	}

	Meal meal = null;
	if (mealPresent) {
		final int mealId = data.getIntValue(Data.FORMAT_UINT8, offset);
		meal = Meal.from(mealId);
		offset += 1;
	}

	Tester tester = null;
	Health health = null;
	if (testerHealthPresent) {
		final int testerAndHealth = data.getIntValue(Data.FORMAT_UINT8, offset);
		tester = Tester.from(testerAndHealth & 0x0F);
		health = Health.from(testerAndHealth >> 4);
		offset += 1;
	}

	Integer exerciseDuration = null;
	Integer exerciseIntensity = null;
	if (exercisePresent) {
		exerciseDuration = data.getIntValue(Data.FORMAT_UINT16, offset); // in seconds
		exerciseIntensity = data.getIntValue(Data.FORMAT_UINT8, offset + 2); // in percentage
		offset += 3;
	}

	Medication medication = null;
	Float medicationAmount = null;
	Integer medicationUnit = null;
	if (medicationPresent) {
		final int medicationId = data.getIntValue(Data.FORMAT_UINT8, offset);
		medication = Medication.from(medicationId);
		medicationAmount = data.getFloatValue(Data.FORMAT_SFLOAT, offset + 1); // mg or ml
		medicationUnit = medicationUnitLiter ? UNIT_ml : UNIT_mg;
		offset += 3;
	}

	Float HbA1c = null;
	if (HbA1cPresent) {
		HbA1c = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
		// offset += 2;
	}

	onGlucoseMeasurementContextReceived(device, sequenceNumber, carbohydrate, carbohydrateAmount,
			meal, tester, health, exerciseDuration, exerciseIntensity,
			medication, medicationAmount, medicationUnit, HbA1c);
}
 
Example 11
Source File: TemperatureMeasurementParser.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static String parse(final Data data) {
	int offset = 0;
	final int flags = data.getIntValue(Data.FORMAT_UINT8, offset++);

	/*
	 * false 	Temperature is in Celsius degrees 
	 * true 	Temperature is in Fahrenheit degrees 
	 */
	final boolean fahrenheit = (flags & TEMPERATURE_UNIT_FLAG) > 0;

	/*
	 * false 	No Timestamp in the packet
	 * true 	There is a timestamp information
	 */
	final boolean timestampIncluded = (flags & TIMESTAMP_FLAG) > 0;

	/*
	 * false 	Temperature type is not included
	 * true 	Temperature type included in the packet
	 */
	final boolean temperatureTypeIncluded = (flags & TEMPERATURE_TYPE_FLAG) > 0;

	final float tempValue = data.getFloatValue(Data.FORMAT_FLOAT, offset);
	offset += 4;

	String dateTime = null;
	if (timestampIncluded) {
		dateTime = DateTimeParser.parse(data, offset);
		offset += 7;
	}

	String type = null;
	if (temperatureTypeIncluded) {
		type = TemperatureTypeParser.parse(data, offset);
		// offset++;
	}

	final StringBuilder builder = new StringBuilder();
	builder.append(String.format(Locale.US, "%.02f", tempValue));

	if (fahrenheit)
		builder.append("°F");
	else
		builder.append("°C");

	if (timestampIncluded)
		builder.append("\nTime: ").append(dateTime);
	if (temperatureTypeIncluded)
		builder.append("\nType: ").append(type);
	return builder.toString();
}
 
Example 12
Source File: IntermediateCuffPressureParser.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static String parse(final Data data) {
	final StringBuilder builder = new StringBuilder();

	// first byte - flags
	int offset = 0;
	final int flags = data.getIntValue(Data.FORMAT_UINT8, offset++);

	final int unitType = flags & 0x01;
	final boolean timestampPresent = (flags & 0x02) > 0;
	final boolean pulseRatePresent = (flags & 0x04) > 0;
	final boolean userIdPresent = (flags & 0x08) > 0;
	final boolean statusPresent = (flags & 0x10) > 0;

	// following bytes - pressure
	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);

	// parse timestamp if present
	if (timestampPresent) {
		builder.append("Timestamp: ").append(DateTimeParser.parse(data, offset));
		offset += 7;
	}

	// parse pulse rate if present
	if (pulseRatePresent) {
		final float pulseRate = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
		offset += 2;
		builder.append("\nPulse: ").append(pulseRate).append(" bpm");
	}

	if (userIdPresent) {
		final int userId = data.getIntValue(Data.FORMAT_UINT8, offset);
		offset += 1;
		builder.append("\nUser ID: ").append(userId);
	}

	if (statusPresent) {
		final int status = data.getIntValue(Data.FORMAT_UINT16, offset);
		// offset += 2;
		if ((status & 0x0001) > 0)
			builder.append("\nBody movement detected");
		if ((status & 0x0002) > 0)
			builder.append("\nCuff too lose");
		if ((status & 0x0004) > 0)
			builder.append("\nIrregular pulse detected");
		if ((status & 0x0018) == 0x0008)
			builder.append("\nPulse rate exceeds upper limit");
		if ((status & 0x0018) == 0x0010)
			builder.append("\nPulse rate is less than lower limit");
		if ((status & 0x0018) == 0x0018)
			builder.append("\nPulse rate range: Reserved for future use ");
		if ((status & 0x0020) > 0)
			builder.append("\nImproper measurement position");
	}

	return builder.toString();
}
 
Example 13
Source File: GlucoseMeasurementContextParser.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static String parse(final Data data) {
	final StringBuilder builder = new StringBuilder();

	int offset = 0;
	final int flags = data.getIntValue(Data.FORMAT_UINT8, offset);
	offset += 1;

	final boolean carbohydratePresent = (flags & 0x01) > 0;
	final boolean mealPresent = (flags & 0x02) > 0;
	final boolean testerHealthPresent = (flags & 0x04) > 0;
	final boolean exercisePresent = (flags & 0x08) > 0;
	final boolean medicationPresent = (flags & 0x10) > 0;
	final int medicationUnit = (flags & 0x20) > 0 ? UNIT_l : UNIT_kg;
	final boolean hbA1cPresent = (flags & 0x40) > 0;
	final boolean moreFlagsPresent = (flags & 0x80) > 0;

	final int sequenceNumber = data.getIntValue(Data.FORMAT_UINT16, offset);
	offset += 2;

	if (moreFlagsPresent) // not supported yet
		offset += 1;

	builder.append("Sequence number: ").append(sequenceNumber);

	if (carbohydratePresent) {
		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 = data.getIntValue(Data.FORMAT_UINT8, offset);
		builder.append("\nMeal: ").append(getMeal(meal));
		offset += 1;
	}

	if (testerHealthPresent) {
		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));
		builder.append("\nHealth: ").append(getHealth(health));
		offset += 1;
	}

	if (exercisePresent) {
		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 = 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 = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
		builder.append("\nHbA1c: ").append(HbA1c).append("%");
	}
	return builder.toString();
}
 
Example 14
Source File: GlucoseMeasurementParser.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static String parse(final Data data) {
	final StringBuilder builder = new StringBuilder();

	int offset = 0;
	final int flags = data.getIntValue(Data.FORMAT_UINT8, offset);
	offset += 1;

	final boolean timeOffsetPresent = (flags & 0x01) > 0;
	final boolean typeAndLocationPresent = (flags & 0x02) > 0;
	final int concentrationUnit = (flags & 0x04) > 0 ? UNIT_molpl : UNIT_kgpl;
	final boolean sensorStatusAnnunciationPresent = (flags & 0x08) > 0;
	final boolean contextInfoFollows = (flags & 0x10) > 0;

	// create and fill the new record
	final int sequenceNumber = data.getIntValue(Data.FORMAT_UINT16, offset);
	builder.append("Sequence Number: ").append(sequenceNumber);
	offset += 2;

	builder.append("\nBase Time: ").append(DateTimeParser.parse(data, offset));
	offset += 7;

	if (timeOffsetPresent) {
		// time offset is ignored in the current release
		final int timeOffset = data.getIntValue(Data.FORMAT_SINT16, offset);
		builder.append("\nTime Offset: ").append(timeOffset).append(" min");
		offset += 2;
	}

	if (typeAndLocationPresent) {
		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");
		builder.append("\nSample Type: ").append(getType(type));
		builder.append("\nSample Location: ").append(getLocation(sampleLocation));
		offset += 3;
	}

	if (sensorStatusAnnunciationPresent) {
		final int status = data.getIntValue(Data.FORMAT_UINT16, offset);
		builder.append("Status:\n").append(getStatusAnnunciation(status));
	}

	builder.append("\nContext information follows: ").append(contextInfoFollows);
	return builder.toString();
}
 
Example 15
Source File: BloodPressureMeasurementParser.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static String parse(final Data data) {
	final StringBuilder builder = new StringBuilder();

	// first byte - flags
	int offset = 0;
	final int flags = data.getIntValue(Data.FORMAT_UINT8, offset++);

	final int unitType = flags & 0x01;
	final boolean timestampPresent = (flags & 0x02) > 0;
	final boolean pulseRatePresent = (flags & 0x04) > 0;
	final boolean userIdPresent = (flags & 0x08) > 0;
	final boolean statusPresent = (flags & 0x10) > 0;

	// following bytes - systolic, diastolic and mean arterial pressure 
	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);
	builder.append("\nDiastolic: ").append(diastolic).append(unit);
	builder.append("\nMean AP: ").append(meanArterialPressure).append(unit);

	// parse timestamp if present
	if (timestampPresent) {
		builder.append("\nTimestamp: ").append(DateTimeParser.parse(data, offset));
		offset += 7;
	}

	// parse pulse rate if present
	if (pulseRatePresent) {
		final float pulseRate = data.getFloatValue(Data.FORMAT_SFLOAT, offset);
		offset += 2;
		builder.append("\nPulse: ").append(pulseRate).append(" bpm");
	}

	if (userIdPresent) {
		final int userId = data.getIntValue(Data.FORMAT_UINT8, offset);
		offset += 1;
		builder.append("\nUser ID: ").append(userId);
	}

	if (statusPresent) {
		final int status = data.getIntValue(Data.FORMAT_UINT16, offset);
		// offset += 2;
		if ((status & 0x0001) > 0)
			builder.append("\nBody movement detected");
		if ((status & 0x0002) > 0)
			builder.append("\nCuff too lose");
		if ((status & 0x0004) > 0)
			builder.append("\nIrregular pulse detected");
		if ((status & 0x0018) == 0x0008)
			builder.append("\nPulse rate exceeds upper limit");
		if ((status & 0x0018) == 0x0010)
			builder.append("\nPulse rate is less than lower limit");
		if ((status & 0x0018) == 0x0018)
			builder.append("\nPulse rate range: Reserved for future use ");
		if ((status & 0x0020) > 0)
			builder.append("\nImproper measurement position");
	}

	return builder.toString();
}