修改了广播数据,主机搜索不到从机了?如何修改simpleBLEFindSvcUuid
我想在广播数据里加入每一个从机的特征信息,比如IMEI号码等,
static uint8 advertData[] =
{
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
0x0A,
0x02,
0x00,
0x01,
0x05,
0x05,
0x01,
0x05,
GAP_ADTYPE_16BIT_MORE, // some of the UUID's, but not all
LO_UINT16( SIMPLEPROFILE_SERV_UUID ),
HI_UINT16( SIMPLEPROFILE_SERV_UUID ),
};通过Packet Sniff抓包发现广播数据正确,但simpleBLECentral例程却无法搜索到从机,问题应该出在simpleBLEFindSvcUuid
static void simpleBLECentralEventCB( gapCentralRoleEvent_t *pEvent )
{
switch ( pEvent->gap.opcode )
{
。。。
case GAP_DEVICE_INFO_EVENT:
{
// if filtering device discovery results based on service UUID
if ( DEFAULT_DEV_DISC_BY_SVC_UUID == TRUE )
{
if ( simpleBLEFindSvcUuid( SIMPLEPROFILE_SERV_UUID,
pEvent->deviceInfo.pEvtData,
pEvent->deviceInfo.dataLen ) )
{
simpleBLEAddDeviceInfo( pEvent->deviceInfo.addr, pEvent->deviceInfo.addrType );
//打印主机搜索到的广播数据
NPI_WriteTransport ( pEvent->deviceInfo.pEvtData, osal_strlen((char *)(pEvent->deviceInfo.pEvtData)));
}
}
}
break;
我想问以下几个问题:
1.广播数据包的具体格式规定是什么?
2. static bool simpleBLEFindSvcUuid( uint16 uuid, uint8 *pData, uint8 dataLen )下的pData[0]\[1]是怎么在结构体里解析出来的?
// For each UUID in list
while ( adLen >= 2 && pData < pEnd )
{
// Check for match
if ( pData[0] == LO_UINT16(uuid) && pData[1] == HI_UINT16(uuid) )
{
// Match found
return TRUE;
}
3.如果上述两个问题说清楚了,我该怎么修改了?非常感谢!
4.我通过串口查看 pEvent->deviceInfo.pEvtData 的内容:
NPI_WriteTransport ( pEvent->deviceInfo.pEvtData, osal_strlen((char *)(pEvent->deviceInfo.pEvtData))); 发现里面不只含有广播包的内容,还会跟着2~4个字节别的数据,我想问下能否每次接收广播数据前先清零该数组了?如果可以在哪清0比较合适?
问题已解决,首先我修改的广播包格式不对,具体格式:
1. 数据长度
2. 数据类型
3. 具体数据,所以 GAP_ADTYPE_16BIT_MORE, // some of the UUID's, but not all
0x02,
0x00,
0x01,
0x05,
0x05,
0x01,
0x05,这样就对了,此外主机那的static bool simpleBLEFindSvcUuid( uint16 uuid, uint8 *pData, uint8 dataLen )下if ( pData[0] == LO_UINT16(uuid) && pData[1] == HI_UINT16(uuid) ),也要根据数据包长度去修改PData下标