TI论坛
直播中

周杰

8年用户 143经验值
私信 关注
[问答]

请问BLE中广播者可以广播自定义·UUID值吗?

如题,求解。将UUID值设为变量,然后扫描得到。。。可以吗? 如果可以的话怎么做?

回帖(3)

苏醒

2019-10-11 07:44:53
广播可以自定义UUID
但是不能将UUID设为变量通过扫描得到
举报

汪佳丽

2019-10-11 08:02:35
你好,
可以在广播中设定UUID,但是无法设置为一个变量,因为我们事前是把UUID作为一个属性列表都做成一个数组在蓝牙初始化之前加入到服务里面。
属性列表你可以参考simpleGATTprofile.c文件:
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 1 Declaration
[
[ ATT_BT_UUID_SIZE, characterUUID ],
GATT_PERMIT_READ,
0,
&simpleProfileChar1Props
],
// Characteristic Value 1
[
[ ATT_BT_UUID_SIZE, simpleProfilechar1UUID ],
GATT_PERMIT_READ | GATT_PERMIT_WRITE,
0,
&simpleProfileChar1
],
// Characteristic 1 User Description
[
[ ATT_BT_UUID_SIZE, charUserDescUUID ],
GATT_PERMIT_READ,
0,
simpleProfileChar1UserDesp
],
// Characteristic 2 Declaration
[
[ ATT_BT_UUID_SIZE, characterUUID ],
GATT_PERMIT_READ,
0,
&simpleProfileChar2Props
],
// Characteristic Value 2
[
[ ATT_BT_UUID_SIZE, simpleProfilechar2UUID ],
GATT_PERMIT_READ,
0,
&simpleProfileChar2
],
// Characteristic 2 User Description
[
[ ATT_BT_UUID_SIZE, charUserDescUUID ],
GATT_PERMIT_READ,
0,
simpleProfileChar2UserDesp
],

// Characteristic 3 Declaration
[
[ ATT_BT_UUID_SIZE, characterUUID ],
GATT_PERMIT_READ,
0,
&simpleProfileChar3Props
],
// Characteristic Value 3
[
[ ATT_BT_UUID_SIZE, simpleProfilechar3UUID ],
GATT_PERMIT_WRITE,
0,
&simpleProfileChar3
],
// Characteristic 3 User Description
[
[ ATT_BT_UUID_SIZE, charUserDescUUID ],
GATT_PERMIT_READ,
0,
simpleProfileChar3UserDesp
],
// Characteristic 4 Declaration
[
[ ATT_BT_UUID_SIZE, characterUUID ],
GATT_PERMIT_READ,
0,
&simpleProfileChar4Props
],
// Characteristic Value 4
[
[ ATT_BT_UUID_SIZE, simpleProfilechar4UUID ],
0,
0,
&simpleProfileChar4
],
// Characteristic 4 configuration
[
[ ATT_BT_UUID_SIZE, clientCharCfgUUID ],
GATT_PERMIT_READ | GATT_PERMIT_WRITE,
0,
(uint8 *)&simpleProfileChar4Config
],

// Characteristic 4 User Description
[
[ ATT_BT_UUID_SIZE, charUserDescUUID ],
GATT_PERMIT_READ,
0,
simpleProfileChar4UserDesp
],

// Characteristic 5 Declaration
[
[ ATT_BT_UUID_SIZE, characterUUID ],
GATT_PERMIT_READ,
0,
&simpleProfileChar5Props
],
// Characteristic Value 5
[
[ ATT_BT_UUID_SIZE, simpleProfilechar5UUID ],
0,
0,
simpleProfileChar5
],

// Characteristic 5 configuration
[
[ ATT_BT_UUID_SIZE, clientCharCfgUUID ],
GATT_PERMIT_READ | GATT_PERMIT_WRITE,
0,
(uint8 *)&simpleProfileChar5Config
],

// Characteristic 5 User Description
[
[ ATT_BT_UUID_SIZE, charUserDescUUID ],
GATT_PERMIT_READ,
0,
simpleProfileChar5UserDesp
],

];
加入到广播里面你需要修改广播包数据:
// GAP - Advertisement data (max size = 31 bytes, though this is
// best kept short to conserve power while advertisting)
static uint8_t advertData[] =
[
// Flags; this sets the device to use limited discoverable
// mode (advertises for 30 seconds at a time) instead of general
// discoverable mode (advertises indefinitely)
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
0x03, // length of this data
GAP_ADTYPE_16BIT_MORE, // some of the UUID's, but not all
#ifdef FEATURE_OAD
LO_UINT16(OAD_SERVICE_UUID),
HI_UINT16(OAD_SERVICE_UUID)
#else
LO_UINT16(SERIALPORTSERVICE_SERV_UUID),
HI_UINT16(SERIALPORTSERVICE_SERV_UUID)
#endif //!FEATURE_OAD
];


                                                                         Michael Qian
举报

周杰

2019-10-11 08:09:02
引用: vctwetrwer 发表于 2019-10-11 08:02
你好,
可以在广播中设定UUID,但是无法设置为一个变量,因为我们事前是把UUID作为一个属性列表都做成一个数组在蓝牙初始化之前加入到服务里面。
属性列表你可以参考simpleGATTprofile.c文件:

谢谢耐心的回答
举报

更多回帖

发帖
×
20
完善资料,
赚取积分