当前位置:   article > 正文

CC2541/CC2640 如何实现一主多从_cc2640多连接

cc2640多连接

首先由于芯片自身问题导致CC2541 可以最多一主三从 ,CC2640可以一主八从。

 我们这里以CC2541为例子

1.扫描从机保存从机mac地址

  1. //首先主机需要去扫描设备
  2. GAPCentralRole_StartDiscovery( DEFAULT_DISCOVERY_MODE, DEFAULT_DISCOVERY_ACTIVE_SCAN, DEFAULT_DISCOVERY_WHITE_LIST )
  3. //当扫描完成会进入
  4. GAP_DEVICE_DISCOVERY_EVENT
  5. //请查看
  6. uint16 SimpleBLECentral_ProcessEvent( uint8 task_id, uint16 events )
  7. case GAP_DEVICE_DISCOVERY_EVENT:
  8. {
  9. // discovery complete
  10. simpleBLEScanning = FALSE;
  11. // if not filtering device discovery results based on service UUID
  12. if ( DEFAULT_DEV_DISC_BY_SVC_UUID == FALSE )
  13. {
  14. // Copy results
  15. simpleBLEScanRes = pEvent->discCmpl.numDevs;
  16. osal_memcpy( simpleBLEDevList, pEvent->discCmpl.pDevList,
  17. (sizeof( gapDevRec_t ) * pEvent->discCmpl.numDevs) );
  18. }
  19. }

2.建立链接,通过上面的程序我们可以把从机的信息保存下来并保存链接句柄

  1. uint8 addrType;
  2. uint8 *peerAddr;
  3. simpleBLEScanIdx = devMacResult[0];
  4. // connect to current device in scan result
  5. peerAddr = simpleBLEDevList[simpleBLEScanIdx].addr;
  6. addrType = simpleBLEDevList[simpleBLEScanIdx].addrType;
  7. simpleBLEState = BLE_STATE_CONNECTING;
  8. GAPCentralRole_EstablishLink( DEFAULT_LINK_HIGH_DUTY_CYCLE,
  9. DEFAULT_LINK_WHITE_LIST,
  10. addrType, peerAddr );
  1. //在GAP_LINK_ESTABLISHED_EVENT事件中保存连接的handle:
  2. MultiConnHandle[num]=ppEvent->linkCmpl.connectionHandle;
3.保存后的句柄可以用于数据的发送以及特征值的读写,连接的断开
  1. attWriteReq_t req;
  2. req.handle = BLE_NotifyChar_Handle+1;
  3. req.len = 1;
  4. req.value[0] = 0x01;
  5. req.sig = 0;
  6. req.cmd = 0;
  7. status = GATT_WriteCharValue( MultiConnHandle[0], &req, simpleBLETaskId );
  8. GAPCentralRole_TerminateLink( MultiConnHandle[0]);
4.附上TI提供的多路连接的例程链接:


http://processors.wiki.ti.com/index.php/Cc2640_MultiRole_Demo
processors.wiki.ti.com/.../File:SimpleBLEMulti_patch.zip 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/933199
推荐阅读
相关标签
  

闽ICP备14008679号