Need help to parse mealtype on glucometer android BLE.
Here's my data: [27, 5, 0, -28, 7, 8, 24, 17, 18, 41, -29, 1, 102, -80, -8, 0, 0]
I also found this one: C3: Field exists if the key of bit 1 of the Flags field is set to 1
Here's my enum
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;
}
}
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);
}
}