This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2540做主机怎么获取从机的设备名称,另外怎么实现通过密码连接从机设备

Other Parts Discussed in Thread: CC2540

如题,因公司开发需要用到这款IC,之前又没接触过,找的例程好像都没有关于这方面的,求助一下

是存在这个pEvent->deviceInfo.pEvtData里面吗?可是看不懂里面的数据,希望能详细解答一下

  • 参考这边详细解读: https://e2e.ti.com/support/wireless_connectivity/bluetooth_low_energy/f/538/t/406885

  • 在pEvent->deviceInfo.pEvtData中怎么解析出来设备名呢。还有一个问题,为啥手机连接CC2540从设备需要密码,而CC2540主机连接CC2540从设备只用MAC地址就可以连接上了?

  • 哎,没人鸟我,不过还是解决了,贴上自己的代码让后来的人少走点弯路

    case GAP_DEVICE_INFO_EVENT:
    {//处理扫描发送设备信息
    if(pEvent->deviceInfo.eventType == GAP_ADTYPE_SCAN_RSP_IND)//GAP_ADRPT_SCAN_RSP
    {
    CheckDeviceScanRspData(pEvent->deviceInfo.pEvtData,pEvent->deviceInfo.dataLen);
    }
    }break;

    //获取从机名称
    static void CheckDeviceScanRspData( uint8 *pEvtData, uint8 dataLen)
    {
    uint8 i,j=0;
    for ( i = 0; i < simpleBLEScanRes; i++ )
    {
    if ( osal_memcmp( pEvtData, gapDeviceInfoEvent_Data[i].pEvtData , dataLen ) )
    {//过滤相同的名称
    return;
    }
    }
    gapDeviceInfoEvent_Data[DeviceEvientNum].pEvtData=pEvtData;
    gapDeviceInfoEvent_Data[DeviceEvientNum].dataLen=dataLen;

    //保存从机设备名
    for(i=0;i<dataLen-9;i++)
    {
    if(i>1)
    {
    tabBLEPeripheralName[DeviceEvientNum][j]=*pEvtData++;
    j++;
    }
    else
    {
    *pEvtData++;
    }
    }
    tabBLEPeripheralNameLength[DeviceEvientNum]=j;

    DeviceEvientNum++;
    if(DeviceEvientNum>DEFAULT_MAX_SCAN_RES-1)
    {//超过最大的缓存
    DeviceEvientNum=0;
    }
    }

    上面源码完成设备名称的报错