蓝牙GATT UUID [英] Bluetooth GATT UUID
本文介绍了蓝牙GATT UUID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试构建一个使用BluetoothLE的android应用.在教程中,他们使用128位UUID,但我只有16位UUID. 我必须使用服务UUID和Bluetooth Base创建一个新的128位UUID.
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.
示例:
- 警报通知服务UUID(16位)=> 0x1811
- 蓝牙基本UUID(128位)=> 00000000-0000-1000-8000-00805F9B34FB
通过合并这两个UUID,我们收到...
By combining those two UUIDs, we receive...
- 警报通知服务UUID(128位)=> 00001811-0000-1000-8000-00805F9B34FB
有适当的方法吗?
推荐答案
我使用这个:
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?
评论中要求的反向操作为:
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;
}
我没有测试.
这篇关于蓝牙GATT UUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文