本文整理匯總了Java中android.bluetooth.BluetoothGattCharacteristic.getFloatValue方法的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothGattCharacteristic.getFloatValue方法的具體用法?Java BluetoothGattCharacteristic.getFloatValue怎麽用?Java BluetoothGattCharacteristic.getFloatValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.bluetooth.BluetoothGattCharacteristic
的用法示例。
在下文中一共展示了BluetoothGattCharacteristic.getFloatValue方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parse
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
public static String parse(final BluetoothGattCharacteristic characteristic) {
int offset = 0;
final int flags = characteristic.getIntValue(BluetoothGattCharacteristic.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 = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_FLOAT, offset);
offset += 4;
String dateTime = null;
if (timestampIncluded) {
dateTime = DateTimeParser.parse(characteristic, offset);
offset += 7;
}
String type = null;
if (temperatureTypeIncluded) {
type = TemperatureTypeParser.parse(characteristic, offset);
// offset++;
}
final StringBuilder builder = new StringBuilder();
builder.append(String.format("%.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();
}
示例2: parseBPMValue
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
private void parseBPMValue(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(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(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(calendar);
} else
mCallbacks.onTimestampRead(null);
// parse pulse rate if present
if (pulseRatePresent) {
final float pulseRate = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_SFLOAT, offset);
// offset += 2;
mCallbacks.onPulseRateRead(pulseRate);
} else
mCallbacks.onPulseRateRead(-1.0f);
}
示例3: parse
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
public static String parse(final BluetoothGattCharacteristic characteristic) {
final StringBuilder builder = new StringBuilder();
// first byte - flags
int offset = 0;
final int flags = characteristic.getIntValue(BluetoothGattCharacteristic.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 = characteristic.getFloatValue(BluetoothGattCharacteristic.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) {
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));
offset += 7;
builder.append(String.format("\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);
offset += 2;
builder.append("\nPulse: ").append(pulseRate);
}
if (userIdPresent) {
final int userId = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset);
offset += 1;
builder.append("\nUser ID: ").append(userId);
}
if (statusPresent) {
final int status = characteristic.getIntValue(BluetoothGattCharacteristic.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();
}
示例4: parse
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
public static String parse(final BluetoothGattCharacteristic characteristic) {
final StringBuilder builder = new StringBuilder();
int offset = 0;
final int flags = characteristic.getIntValue(BluetoothGattCharacteristic.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 = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
offset += 2;
if (moreFlagsPresent) // not supported yet
offset += 1;
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);
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);
builder.append("\nMeal: ").append(getMeal(meal));
offset += 1;
}
if (testerHealthPresent) {
final int testerHealth = characteristic.getIntValue(BluetoothGattCharacteristic.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 = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
final int exerciseIntensity = characteristic.getIntValue(BluetoothGattCharacteristic.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);
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);
builder.append("\nHbA1c: ").append(HbA1c).append("%");
}
return builder.toString();
}
示例5: parse
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
public static String parse(final BluetoothGattCharacteristic characteristic) {
final StringBuilder builder = new StringBuilder();
int offset = 0;
final int flags = characteristic.getIntValue(BluetoothGattCharacteristic.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 = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
builder.append("Sequence Number: ").append(sequenceNumber);
offset += 2;
builder.append("\nBase Time: ").append(DateTimeParser.parse(characteristic, offset));
offset += 7;
if (timeOffsetPresent) {
// time offset is ignored in the current release
final int timeOffset = characteristic.getIntValue(BluetoothGattCharacteristic.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 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 = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
builder.append("Status:\n").append(getStatusAnnunciation(status));
}
builder.append("\nContext information follows: ").append(contextInfoFollows);
return builder.toString();
}
示例6: parse
import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
public static String parse(final BluetoothGattCharacteristic characteristic) {
final StringBuilder builder = new StringBuilder();
// first byte - flags
int offset = 0;
final int flags = characteristic.getIntValue(BluetoothGattCharacteristic.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 = 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 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) {
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));
offset += 7;
builder.append(String.format("\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);
offset += 2;
builder.append("\nPulse: ").append(pulseRate);
}
if (userIdPresent) {
final int userId = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset);
offset += 1;
builder.append("\nUser ID: ").append(userId);
}
if (statusPresent) {
final int status = characteristic.getIntValue(BluetoothGattCharacteristic.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();
}