说明:
以SimpleBLEPeripheral工程为例,说明如何使用自定义的128bit的UUID。
环境:
协议栈:simplelink_cc2640r2_sdk_1_50_00_58
仿真器:XDS110
编译软件:Code Composer Studio Version: 7.3.0.00019
硬件平台:LAUNCHXL-CC2640R2
UUID:
UUID(Universally Unique Identifier)是通用唯一识别码。 在蓝牙设备中,每个服务、特征值都有一个对应的UUID。 UUID是128bit的,但在CC2541、CC2640的协议栈中默认使用的是简短的16bit的UUID。代码中看起来是简短,实际上最终还是会补齐为128bit。 例如simpleGATTprofile服务的16bit的UUID是0xFFF0,特征值的16bit的UUID是0xFFF1~0xFFF5,它会被补齐为128bit
步骤:
1.修改PROFILE/simple_gatt_profile.h:
// Simple Profile Service UUID:03B80E5A-EDE8-4B33-A751-6CE34EC4C700
#define SIMPLEPROFILE_SERV_UUID 0x00, 0xC7, 0xC4, 0x4E, 0xE3, 0x6C, 0x51, 0xA7, 0x33, 0x4B, 0xE8, 0xED, 0x5A,0x0E, 0xB8, 0x03
// Characteristic UUID:7772E5DB-3868-4112-A1A9-F2669D106BF3
#define SIMPLEPROFILE_CHAR_UUID 0xF3, 0x6B, 0x10, 0x9D, 0x66, 0xF2, 0xA9, 0xA1, 0x12, 0x41, 0x68, 0x38, 0xDB,0xE5, 0x72, 0x77
2.修改PROFILE/simple_gatt_profile.c:
...
/*********************************************************************
* GLOBAL VARIABLES
*/
// Simple GATT Profile Service UUID: 0xFFF0
CONST uint8 simpleProfileServUUID[ATT_UUID_SIZE] =
{
SIMPLEPROFILE_SERV_UUID
};
// Characteristic 1 UUID: 0xFFF1
CONST uint8 simpleProfileCharUUID[ATT_UUID_SIZE] =
{
SIMPLEPROFILE_CHAR_UUID
};
...
/*********************************************************************
* LOCAL VARIABLES
*/
...
// Simple Profile Service attribute
static CONST gattAttrType_t simpleProfileService = { ATT_UUID_SIZE, simpleProfileServUUID };
...
/*********************************************************************
* Profile Attributes - Table
*/
static gattAttribute_t simpleProfileAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED] =
{
// Simple Profile Service
{
{ ATT_BT_UUID_SIZE, primaryServiceUUID }, /* type */
GATT_PERMIT_READ, /* permissions */
0, /* handle */
(uint8 *)&simpleProfileService /* pValue */
},
// Characteristic Declaration:GATT_PROP_READ | GATT_PROP_WRITE | GATT_PROP_WRITE_NO_RSP | GATT_PROP_NOTIFY
{
{ ATT_BT_UUID_SIZE, characterUUID },
GATT_PERMIT_READ,
0,
&simpleProfileCharProps
},
// Characteristic Value 1
{
{ ATT_UUID_SIZE, simpleProfileCharUUID },
GATT_PERMIT_READ | GATT_PERMIT_WRITE,
0,
&simpleProfileChar
},
//Characteristic configuration
{
{ ATT_BT_UUID_SIZE, clientCharCfgUUID },
GATT_PERMIT_READ | GATT_PERMIT_WRITE,
0,
(uint8 *)&simpleProfileCharConfig
},
// Characteristic User Description
{
{ ATT_BT_UUID_SIZE, charUserDescUUID },
GATT_PERMIT_READ,
0,
simpleProfileCharUserDesp
},
};
3.修改广播数据adverData[],打开simple_peripheral.c
// Advertisement data (max size = 31 bytes, though this is
// best kept short to conserve power while advertising)
static uint8_t advertData[] =
{
// Flags: this field sets the device to use general discoverable
// mode (advertises indefinitely) instead of general
// discoverable mode (advertise for 30 seconds at a time)
0x02, // length of this data
GAP_ADTYPE_FLAGS,
DEFAULT_DISCOVERABLE_MODE | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED,
// service UUID, to notify central devices what services are included
// in this peripheral
0x11, // Length of this data
GAP_ADTYPE_128BIT_COMPLETE, // Complete list of 128-bit UUIDs
MIDI_PROFILE_SERV_UUID // MIDI Service UUID
};