I want to parse the GATT characteristic org.bluetooth.characteristic.glucose_measurement (0x2A18) with Java/Android. More details here: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.glucose_measurement.xml
all worked so far, starting with
byte[] values = characteristic.getValue();
then according to the description above i parsed the values:
boolean timeOffsetPresent = (values[0] & 0x01) > 0;
boolean typeAndLocationPresent = (values[0] & 0x02) > 0;
String concentrationUnit = (values[0] & 0x04) > 0 ? "mol/L" : "kg/L";
boolean sensorStatusAnnunciationPresent = (values[0] & 0x08) > 0;
boolean contextInfoFollows = (values[0] & 0x10) > 0;
long seqNum = (long) (values[1] & 255);
seqNum |= (long) (values[2] & 255) << 8;
int glucose = values[10] & 255;
glucose |= (values[11] & 255) << 8;
int year = values[3] & 255;
year |= (values[4] & 255) << 8;
byte month = values[5];
byte day = values[6];
byte hour = values[7];
byte min = values[8];
byte sec = values[9];
All values are correct, except the glucose value. I received concentrationUnit=kg/L so the value was sent according to "Glucose Concentration - units of kg/L" from the documentation. Unfortunately the test value is
System.out.println("glucose: "+glucose); // equals 28336
28336 is total wrong, as the value should be 110 mg/dl.
Any suggestions what is wrong here and how I can fix this? Strange thing is that all other values are correct.
The documentation you linked states that the concentration is an SFLOAT
, which should be an "IEEE-11073 16-bit SFLOAT".
This SO post tells you how to decode such a thing.