问题描述
需要帮助来解析血糖仪android BLE上的膳食类型.
Need help to parse mealtype on glucometer android BLE.
这是我的数据:[27,5,0,-28,7,8,24,17,18,41,-29,1,102,-80,-8,0,0]
Here's my data:[27, 5, 0, -28, 7, 8, 24, 17, 18, 41, -29, 1, 102, -80, -8, 0, 0]
我也发现了这个:C3:如果字段的第1位的密钥存在,则该字段存在标志字段设置为1
I also found this one:C3: Field exists if the key of bit 1 of theFlags field is set to 1
这是我的枚举
public static Meal from(final int code) {
switch (code) {
case 1:
return PREPRANDIAL;
case 2:
return POSTPRANDIAL;
case 3:
return FASTING;
case 4:
return CASUAL;
case 5:
return BEDTIME;
default:
return RESERVED;
}
}
这是我的代码,但我的进餐类型值提高了20,而不是不到6
Here's my code but I got a mealtype value greather that 20 instead of less than 6
public final ByteBuffer data;
public final byte flags;
public byte secondaryFlags;
public byte carbFlags;
public int carbInfo;
public int mealType = -1;
public final int sequence;
public final boolean hasSecondaryFlags;
public final boolean hasMealType;
public final boolean hasCarbInfo;
public ContextBG(byte[] packet) {
data = ByteBuffer.wrap(packet).order(ByteOrder.LITTLE_ENDIAN);
flags = data.get();
hasSecondaryFlags = (flags & 128) > 0;
hasMealType = (flags & 2) > 0;
hasCarbInfo = (flags & 1) > 0;
sequence = data.getShort();
if (hasSecondaryFlags) {
secondaryFlags = data.get();
}
if (hasCarbInfo) {
carbFlags = data.get();
carbInfo = data.getShort();
}
if (hasMealType) {
mealType = data.get();
Log.d("MEAL TYPE", "======= " + mealType);
}
}
推荐答案
您共享的数据长17个字节.
The data you have shared is 17 bytes long.
我使用了此xml 以获取字段.
第一个字节是flags
,并且在您的数据中是十进制的27,它是二进制00011011
The first byte is flags
and in your data that is decimal 27 which is binary 00011011
因此标记设置如下:
<Bit index="0" size="1" name="Carbohydrate ID And Carbohydrate Present"> = True
<Bit index="1" size="1" name="Meal Present"> = True
<Bit index="2" size="1" name="Tester-Health Present"> = False
<Bit index="3" size="1" name="Exercise Duration And Exercise Intensity Present"> = True
<Bit index="4" size="1" name="Medication ID And Medication Present"> = True
<Bit index="5" size="1" name="Medication Value Units"> = kilograms
<Bit index="6" size="1" name="HbA1c Present"> = False
<Bit index="7" size="1" name="Extended Flags Present"> = False
我认为数据应该是:
<Field name="Flags"> = 1 byte
<Field name="Sequence Number"> = 2 bytes
<Field name="Extended Flags "> = 1 byte
<Field name="Carbohydrate ID"> = 1 byte
<Field name="Carbohydrate - units of kilograms"> = 2 bytes
<Field name="Meal"> = 1 byte
<Field name="Exercise Duration"> = 2 bytes
<Field name="Exercise Intensity"> = 1 byte
<Field name="Medication ID"> = 1 byte
<Field name="Medication - units of kilograms"> = 2 bytes
<Field name="Medication - units of liters"> = 2 bytes
这是16个字节长,而示例数据是17个字节长.另外,这些值似乎都不会为Meal
字段提供合理的值.
Which is 16 bytes long whereas the example data is 17 bytes long. In addition none of the values look like they would make sensible values for the Meal
field.
org.bluetooth.characteristic.glucose_measurement
[0x2A18]长17个字节.可能是您将这两个特征混在一起了吗?
The org.bluetooth.characteristic.glucose_measurement
[0x2A18] is 17 bytes long. Could it be that you have mixed the two characteristics up?
这篇关于需要帮助来解析血糖仪android BLE上的饭食类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!