I'm trying to build an android app that uses the BluetoothLE. In tutorials they use a 128bit UUID but I only have the 16 bit UUID. I have to create a new 128 bit UUID using the service UUID and the Bluetooth Base.
Example :
By combining those two UUIDs, we receive...
Is there a proper way to do this?
I use this:
public class BLEUtils {
public static final long BT_UUID_LOWER_BITS = 0x800000805F9B34FBl;
public static final long BT_UUID_UPPER_BITS = 0x1000l;
public static final long BT_CCCD_SHORT_UUID = 0x2902l;
public static final UUID BT_CCCD_UUID = get16BitBTUUID(BT_CCCD_SHORT_UUID);
public static UUID get16BitBTUUID(long uuid) {
return new UUID(BT_UUID_UPPER_BITS + (uuid << 32), BT_UUID_LOWER_BITS);
}
}
Your example looks sane. Is it recognized properly by other devices?
Edit: The reverse operation requested in the comment would be:
public static long getShortUuid(UUID uuid) {
long result = uuid.getMostSignificantBits();
result = result - BT_UUID_UPPER_BITS;
result = result >> 32;
return result;
}
I didn't test it though.