BLE之UUID

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jet007_007/article/details/52932346

GATT层中定义的所有属性都有一个UUID值,UUID是全球唯一的128位的号码,它用来识别不同的特性。

首先来说明一下含义:

GATT(Generic Attribute Profile),通用属性配置文件,其中的数据都是实际发送的,也就是蓝牙事件所产生的协议栈事件都是在这里发生的。

UUID(Universally Unique Identifier),通用唯一识别码。

UUID一般可以分为两种:1、蓝牙技术联盟UUIDs;2、供应商特定的UUID

1、蓝牙技术联盟UUIDs

蓝牙核心规范制定了两种不同的UUID,1、基本的UUID;2、代替基本UUID的16位UUID。

注意:所有的蓝牙技术联盟定义UUID共用了一个基本的UUID:0x0000xxxx-0000-1000-8000-00805F9B34FB。总共128位,换算成8位位组(octet)也就是16个8位位组(8*16=128嘛)。为了进一步简化基本UUID,每一个蓝牙技术联盟定义的属性有一个唯一的16位UUID,以代替上面的基本UUID的‘x’部分,也就是第12、13个八位位组。

2、供应商特定的UUID

与蓝牙技术联盟定义的UUID类似,供应商特定的UUID也有基本UUID和16位的UUID(类似一个别名,再加载在基本UUID之上)。基本UUID由nRFgo Studio产生,16位UUID可以按照自己的意图来任意分配。

因此,按照上述原则,nRF51822的SDK关于UUID的数据结构如下所示:

/** @brief 128 bit UUID values. */
typedef struct
{ 
    unsigned char uuid128[16];
} ble_uuid128_t;

/** @brief  Bluetooth Low Energy UUID type, encapsulates both 16-bit and 128-bit UUIDs. */
typedef struct
{
    uint16_t    uuid; /**< 16-bit UUID value or octets 12-13 of 128-bit UUID. */
    uint8_t     type; /**< UUID type, see @ref BLE_UUID_TYPES. If type is BLE_UUID_TYPE_UNKNOWN, the value of uuid is undefined. */
} ble_uuid_t;
结构体ble_uuid128_t内部只有一个结构体成员,其中结构体成员为一个包含16个无符号字符型元素的一维数组,也就是16个8位位组,刚好能够表示128位UUID。

按照SDK中的注释,结构体ble_uuid_t是低功耗蓝牙UUID类型,压缩了16位和128位UUID。其中,包含两个结构体成员,1、无符号16位整型数uuid,也就是16位UUID值或者128位UUID的第12-13个八位位组;2、无符号8位整型数type,也就是UUID类型,其值有如下三种情况:

/** @defgroup BLE_UUID_TYPES Types of UUID
 * @{ */
#define BLE_UUID_TYPE_UNKNOWN       0x00 /**< Invalid UUID type. */
#define BLE_UUID_TYPE_BLE           0x01 /**< Bluetooth SIG UUID (16-bit). */
#define BLE_UUID_TYPE_VENDOR_BEGIN  0x02 /**< Vendor UUID types start at this index (128-bit). */
/** @} */
1、BLE_UUID_TYPE_UNKNOWN:不可用的UUID类型,这也与ble_uuid_t中的如果类型是BLE_UUID_TYPE_UNKNOWN,UUID值是未定义的。

2、BLE_UUID_TYPE_BLE:蓝牙兴趣小组的UUID。

3、BLE_UUID_TYPE_VENDOR_BEGIN:供应商UUID类型开始在这个指针(128位)。

通过如下协议栈函数可以添加一个供应商特定的UUID。

uint32_t sd_ble_uuid_vs_add ( ble_uuid128_t const *const  p_vs_uuid,
    uint8_t *const  p_uuid_type 
  )
Note
Bytes 12 and 13 of the provided UUID will not be used internally, since those are always replaced by the 16-bit uuid field in ble_uuid_t.
Parameters
[in] p_vs_uuid Pointer to a 16-octet (128-bit) little endian Vendor Specific UUID disregarding bytes 12 and 13.
[out] p_uuid_type Pointer where the type field in ble_uuid_t corresponding to this UUID will be stored.
由注意可以知道,提供的UUID的12、13字节并不会被内部直接使用,因为他们通常被ble_uuid_t中的16位UUID位域代替。

猜你喜欢

转载自blog.csdn.net/jet007_007/article/details/52932346
今日推荐