【发布时间】:2017-08-08 12:54:37
【问题描述】:
我想用 Java/Android 解析 GATT 特征 org.bluetooth.characteristic.glucose_measurement (0x2A18)。更多细节在这里:https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.glucose_measurement.xml
到目前为止一切正常,从
byte[] values = characteristic.getValue();
然后根据上面的描述我解析了值:
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];
所有值都是正确的,除了葡萄糖值。我收到了浓度单位=千克/升,因此该值是根据文档中的“葡萄糖浓度 - 千克/升单位”发送的。不幸的是,测试值是
System.out.println("glucose: "+glucose); // equals 28336
28336 完全错误,因为该值应为 110 mg/dl。
任何建议这里有什么问题以及如何解决这个问题?奇怪的是所有其他值都是正确的。
【问题讨论】:
标签: java android bluetooth bluetooth-lowenergy gatt