2016-04-20 9 views
0

Ich versuche, eine Android-App zu erstellen, die den BluetoothLE verwendet. In Tutorials verwenden sie eine 128-Bit-UUID, aber ich habe nur die 16-Bit-UUID. Ich muss eine neue 128-Bit-UUID mit der Service-UUID und der Bluetooth-Base erstellen.Bluetooth GATT UUID

Beispiel:

  • Alert Notification Service-UUID (16bit) => 0x1811
  • Bluetooth Base-UUID (128bit) => 00000000-0000-1000-8000-00805F9B34FB

Durch die Kombination von diese beiden UUID erhalten wir ...

  • Alert Notification Service-UUID (128bit) => 00001811-0000-1000-8000-00805 F9B34FB

Gibt es einen geeigneten Weg, dies zu tun?

Antwort

1

Ich benutze diese:

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); 
    } 
} 

Ihr Beispiel gesund aussieht. Wird es von anderen Geräten richtig erkannt?

Edit: Der umgekehrte Vorgang im Kommentar angefordert wäre: wenn

public static long getShortUuid(UUID uuid) { 
    long result = uuid.getMostSignificantBits(); 
    result = result - BT_UUID_UPPER_BITS; 
    result = result >> 32; 
    return result; 
} 

ich es nicht testen.

+0

Hey, Danke für Ihre Antwort! Aber, wenn ich die "BT_CCCD_SHORT_UUID" von "BT_CCCD_UUID" extrahieren möchte, wie kann ich das erreichen? – Max