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.

[参考译文] CC2640R2L:CC2640R2L 主器件

Guru**** 2524550 points
Other Parts Discussed in Thread: CC2640R2L

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/984591/cc2640r2l-cc2640r2l-master

器件型号:CC2640R2L

cc2640r2l do master / host

请举例说明。 我们需要打开“通知”、“接收通知数据”,如果已连接,则数据传输将自动启动,


//初始化应用程序
multi_role_init();

//应用程序主循环
对于(;)

uint32_t 事件;

//等待与调用线程关联的事件被发布。
//请注意,与线程关联的事件在时发布
//消息在线程的消息接收队列中排队
事件= Event_pend (syncEvent、Event_ID_none、MR_All_Events、
iCall_TIMEOUT_FOREVER);

IF (事件)

iCall_EntityID dest;
iCall_ServiceEnum src;
iCall_HciExtEvt *pMsg =空;

if (iCall_fetchServiceMsg (&src、&dest、
(void **)&pMsg)=ICALL_errno_Success)

uint8_t safeToDealloc = true;

IF (((src =ICALL_SERVICE_CLASS_BLE)&&(dest =self Entity))

iCall_Stack_Event *pEvt =(iCall_Stack_Event *) pMsg;

if (pEvt->signature!= 0xFFFF)

//处理任务间消息
safeToDealloc = multi_role_processStackMsg ((iCall_HDR *) pMsg);



if (pMsg && safeToDealloc)

iCall_freeMsg (pMsg);



//如果 RTOS 队列不为空,则处理应用程序消息。
if (事件和 MR_queue_EVT)

while (!Queue_empty (appMsgQueue))

mrEvt_t *pMsg =(mrEvt_t *) Util_dequeueMsg (appMsgQueue);
if (pMsg)

//处理消息。
multi_role_processAppMsg (pMsg);

//从消息中释放空间。
iCall_free (pMsg);




IF (事件和 MR_Period_EVT)

//Util_startClock (周期时钟);
// drct_doConnect (0);

//执行周期性应用任务
//multi_role_performPeriodicTask();

IF (事件和 MR_SWITCH_Period_EVT)

//MR_doScan (0);
//Util_startClock (&switchPeriodicClock);
// drct_doGattRw (connIndex);
//delayM(500);
//drct_rdNotify (connIndex);


if (事件和 MR_DISC_RETERRAY_EVT)

//开始服务发现
// multi_role_startDiscovery (connhdl);







静态空 multi_role_processRoleEvent (gapMultiRoleEvent_t *pEvent)

unsigned char conn_times = 3;
unsigned char res = 0xFF;
switch (pEvent->GAP.opcode)

// GAPRole 已启动

案例 GAP_DEVICE_INIT_DONE_EVENT:

//存储最大 PDU 大小
maxPduSize = pEvent->initDone.dataPtLen;

Display_print0 (dispHandle、MR_ROW_DEV_ADDR、0、Util_convertBdAddr2Str (pEvent->initDone.devAddr));)
Display_print0 (dispHandle、MR_ROW_CONN_STATUS、0、"连接到0");
Display_print0 (dispHandle、MR_ROW_STATUS1、0、"已初始化");

//设置设备信息特性
DevInfo_SetParameter (DevInfo_system_ID、DevInfo_system_ID_LEN、pEvent->initDone.devAddr);
iCall_freeMsg (pEvent);
//MR_doScan (0);
//初始化完成后直接去指定mac建立连接
RES = drct_doConnect (0);
//Util_startClock (周期时钟);


中断;

//已建立连接
案例 GAP_LINK_established _事件:

//如果成功建立
if (pEvent->GAP.HDR.STATUS =成功)

Display_print0 (dispHandle、MR_ROW_STATUS1、0、"已连接!");
Display_Print1 (dispHandle、MR_ROW_CONN_STATUS、0、"连接到%d"、linkDB_NumActive ());

//清除连接标志
连接= false;

//添加 index-to connHandle 映射条目和更新菜单
uint8_t 索引= multi_role_addMappingEntry (pEvent->linkCmpl.connectionHandle、pEvent->linkCmpl.devAddr);

//如果没有可用链接,则关闭广播
if (linkDB_NumActive()>= maxNumBleConns)

uint8_t advertEnabled = false;
GAPRole_SetParameter (GAPROLE_adverted_enabled、sizeof (uint8_t)、&advertEnabled、NULL);
Display_print0 (dispHandle、MR_ROW_ADV、0、"CAN't Adv:no links");


//打印上次连接的设备
Display_print0 (dispHandle、MR_ROW_STATUS2、0、(char*) connHandleMap[index].strAddr);

//返回主菜单
//TBM_GOTO (&mrMenuMain);
connhdl = pEvent->linkCmpl.connectionHandle;
// Util_startClock (&discPeriodicClock);
iCall_freeMsg (pEvent);
//连接建立之后立即Start 服务发现
multi_role_startDiscovery(pEvent->linkCmpl.connectionHandle);

//如果这是第一个连接,则启动周期性时钟
if (linkDB_NumActive ()= 1)

//Util_startClock (周期时钟);


//如果连接未成功建立
其他

Display_print0 (dispHandle、MR_ROW_STATUS1、0、"连接失败");
Display_Print1 (dispHandle、MR_ROW_STATUS2、0、"原因:%d"、pEvent->GAP.HDR.STATUS);


中断;




静态空 multi_role_processGATTDiscEvent (gattMsgEvent_t *pMsg)

//将连接句柄映射到索引
connIndex = multi_role_mapConnHandleToIndex (pMsg->connHandle);
//检查以防止缓冲区溢出
if (connIndex < maxNumBleConns)

//MTU 更新
if (pMsg->method =ATT_MTU_Update_event)

// MTU 大小已更新
Display_Print1 (dispHandle、MR_ROW_STATUS1+1、0、"MTU 大小:%d"、pMsg->msg.mtuEvt.MTU);

//如果我们更新了 MTU 大小
否则、如果(discInfo[connIndex].discState =BLE_DISC_State_MTU)

//收到 MTU 大小响应,发现简单服务
if (pMsg->method =ATT_EXCHANGE_MTU_RSP)

uint8_t uuuid[ATT_BT_UUID_SIZE]={LO_UINT16 (SIMPLEPROFILE_SERV_UUID)、
hi_uint16 (SIMPLEPROFILE_SERV_UUID)};

//高级状态
discInfo[connIndex].discState= BLE_DISC_State_SVC;

//发现简单的服务
void GATT_DiscPrimaryServiceByUUID (pMsg->connHandle、uuid、ATT_BT_UUART_size、
自实体);


//如果我们正在执行服务发现
否则、如果(discInfo[connIndex].discState =BLE_DISC_State_SVC)

//找到服务,存储句柄
if (pMsg->method = ATT_find_BY_TYPE_Value_RSP &&
pMsg->msg.findByTypeValueRsp.numInfo >0)

discInfo[connIndex].svcStartHdl = ATT_attr_handle (pMsg->msg.findByTypeValueRsp.pHandlesInfo、0);
discInfo[connIndex].svcEndHdl = ATT_GRP_END_Handle (pMsg->msg.findByTypeValueRsp.pHandlesInfo、0);


//如果过程完成
if (((pMsg->method =ATT_find_BY_TYPE_Value_RSP)&&
(pMsg->HDR.status == bleProcedureComplete)||
(pMsg->method == ATT_ERROR_RSP))

//如果我们发现了该服务
if (discInfo[connIndex].svcStartHdl!= 0)

如果(0)

attReadByTypeReq_t req;

//发现特征
discInfo[connIndex].discState = BLE_DISC_State_char;
REQ.startHandle = discInfo[connIndex].svcStartHdl;
REQ.endHandle = discInfo[connIndex].svcEndHdl;
REQ.TYPE.Len = ATT_BT_UUUART_SIZE;
REQ.TYPE.uuid[0]= LO_UINT16 (SIMPLEPROFILE_CHAR1_UUID);
REQ.TYPE.uuid[1]= HI_UINT16 (SIMPLEPROFILE_CHAR1_UUID);

//发送特征发现请求
void GATT_DiscCharsByUUID (pMsg->connHandle、&req、self 实体);

其他

attReadByTypeReq_t req;

//发现特征
discInfo[connIndex].discState = BLE_DISC_State_char;
REQ.startHandle = discInfo[connIndex].svcStartHdl;
REQ.endHandle = discInfo[connIndex].svcEndHdl;
REQ.TYPE.Len = ATT_BT_UUUART_SIZE;
REQ.TYPE.uuid[0]= LO_UINT16 (SIMPLEPROFILE_CHAR4_UUID);
REQ.TYPE.uuid[1]= HI_UINT16 (SIMPLEPROFILE_CHAR4_UUID);

//发送特征发现请求
void GATT_DiscCharsByUUID (pMsg->connHandle、&req、self 实体);




//如果我们发现特征
否则、如果(discInfo[connIndex].discState =BLE_DISC_State_char)

//找到特征
if ((pMsg->method =ATT_READ_BY_TYPE_RSP)&&
(pMsg->msg.readByTypeRsp.numPairs >0)

//存储句柄
discInfo[connIndex].charHdl = build_uint16 (pMsg->msg.readByTypeRsp.pDataList[3],
pMsg->msg.readByTypeRsp.pDataList[4]);

Display_Print1 (dispHandle、MR_ROW_STATUS1、0、"Simple Svc found %d\n"、discInfo[connIndex].charHdl);
//写入数据
iCall_freeMsg (pMsg);
//查找到 char 之后立即开始写特征值
drct_doGattRw (connIndex);
// Util_startClock (&switchPeriodicClock);



  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

    对于您的用例、我建议您从 simple_central 项目开始。 它实现了蓝牙中心所需的所有基本功能、应该是您项目的良好开端。 我还建议查看 SimpleLink Academy。 这些实验中的内容涵盖了开始和进行项目所需的修改所需了解的所有内容。 具体而言、我建议您查看 低功耗蓝牙基础知识、 扫描和广播以及 Connexions 实验室。 我相信这些实验将非常有用。

    此致、

    1月