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.
大家好、
我使用 simplelink_cc13xx_cc26xx_sdk_7_10_01_24 SDK、这是 CC2652RB 的 simple_central 示例
e2e.ti.com/.../2860.simple_5F00_central_5F00_LP_5F00_CC2652RB_5F00_tirtos7_5F00_ticlang.zip
在服务器端、我每100ms 通知一次 I byte 数据、我可以在手机上接收该数据。 我希望使用我们的 LP cc2652rb EVM 板和使用简单的中央示例接收该通知。 我从 该线程迁移代码。 我将服务器端的服务和特征 uuid 设置为与启用 simple_central 相同。 以下是示例中添加的2个主要 fxn、您是否需要指导我如何接收通知? 我的代码中遗漏了什么?
bool SimpleCentral_enableNotif(uint8_t index) { // Process message. attWriteReq_t req; bStatus_t retVal = FAILURE; uint8 configData[2] = { 0x01, 0x00 }; req.pValue = GATT_bm_alloc(scConnHandle, ATT_WRITE_REQ, 2, NULL); uint8_t connIndex = SimpleCentral_getConnIndex(scConnHandle); SIMPLECENTRAL_ASSERT(connIndex < MAX_NUM_BLE_CONNS); // Enable notify for outgoing data Notification if ((req.pValue != NULL) && streamServiceHandle.chars[0].cccdHandle) { req.handle = streamServiceHandle.chars[0].cccdHandle; req.len = 2; memcpy(req.pValue, configData, 2); req.cmd = TRUE; req.sig = FALSE; retVal = GATT_WriteNoRsp(scConnHandle, &req); Display_printf(dispHandle, SC_ROW_NON_CONN, 0, "gatt read 0x%02x", retVal); } if (retVal == SUCCESS) { return (true); } return (false); } static void SimpleCentral_processGATTMsg(gattMsgEvent_t *pMsg) { if (linkDB_Up(pMsg->connHandle)) { // See if GATT server was unable to transmit an ATT response if (pMsg->hdr.status == blePending) { // No HCI buffer was available. App can try to retransmit the response // on the next connection event. Drop it for now. Display_printf(dispHandle, SC_ROW_CUR_CONN, 0, "ATT Rsp dropped %d", pMsg->method); } else if ((pMsg->method == ATT_READ_RSP) || ((pMsg->method == ATT_ERROR_RSP) && (pMsg->msg.errorRsp.reqOpcode == ATT_READ_REQ))) { if (pMsg->method == ATT_ERROR_RSP) { Display_printf(dispHandle, SC_ROW_CUR_CONN, 0, "Read Error %d", pMsg->msg.errorRsp.errCode); } else { // After a successful read, display the read value Display_printf(dispHandle, SC_ROW_CUR_CONN, 0, "Read rsp: 0x%02x", pMsg->msg.readRsp.pValue[0]); } } else if ((pMsg->method == ATT_WRITE_RSP) || ((pMsg->method == ATT_ERROR_RSP) && (pMsg->msg.errorRsp.reqOpcode == ATT_WRITE_REQ))) { if (pMsg->method == ATT_ERROR_RSP) { Display_printf(dispHandle, SC_ROW_CUR_CONN, 0, "Write Error %d", pMsg->msg.errorRsp.errCode); } else { // After a successful write, display the value that was written and // increment value Display_printf(dispHandle, SC_ROW_CUR_CONN, 0, "Write sent: 0x%02x", charVal); } tbm_goTo(&scMenuPerConn); } else if (pMsg->method == ATT_HANDLE_VALUE_NOTI) { // Matt Display_printf(dispHandle, SC_ROW_CUR_CONN, 0, "Notification: 0x%02x", pMsg->msg.handleValueNoti.pValue[0]); } else if (pMsg->method == ATT_FLOW_CTRL_VIOLATED_EVENT) { // ATT request-response or indication-confirmation flow control is // violated. All subsequent ATT requests or indications will be dropped. // The app is informed in case it wants to drop the connection. // Display the opcode of the message that caused the violation. Display_printf(dispHandle, SC_ROW_CUR_CONN, 0, "FC Violated: %d", pMsg->msg.flowCtrlEvt.opcode); } else if (pMsg->method == ATT_MTU_UPDATED_EVENT) { // MTU size updated Display_printf(dispHandle, SC_ROW_CUR_CONN, 0, "MTU Size: %d", pMsg->msg.mtuEvt.MTU); } else if (discState != BLE_DISC_STATE_IDLE) { SimpleCentral_processGATTDiscEvent(pMsg); } } // else - in case a GATT message came after a connection has dropped, ignore it. // Needed only for ATT Protocol messages GATT_bm_free(&pMsg->msg, pMsg->method); }
马修
您好、Clement、
目前、在我连接服务器之后、 我选择 enableNotification 调用 SimpleCentral_enableNotif 函数、如下所示。
menu_item_action (scMenuPerConn、2、"Enable Notif"、SimpleCentral_enableNotif )----- >调用 SimpleCentral_enableNotif
在我选择 菜单中的"Enable Notif"后、没有发生任何情况、也没有显示任何信息
当我在第22行创建一个断点时,我发布的代码。 它显示 RetVal 为0x01、这表示失败。 在我建立连接后、req.pvalue 仍然等于 NULL。 在我的连接后、未存储相应句柄的原因。
Matthew。
您好、Clement、
当我尝试启用通知时、程序在下面停止、函数无法获取 connhandle。
if (Error_policy_D == Error_SPIN) { for(;;) { } } else if (((eb == &defErr) && (Error_policy_D == Error_UNWIND)) || (Error_policy_D == Error_TERMINATE)) { System_abort("ti_sysbios_runtime_Error_raise: terminating execution\n"); } }
Matthew、您好!
您似乎在取得一些进展。
如前所述、函数 menu_item_action 无法传递连接句柄、因此、您必须为此使用一个替代方法。
通常、"req.pvalue"应该是使用 GATT_BM_alloc ()动态分配的。 此外、确保 ocode 参数(第二个参数)设置为要分配缓冲区的消息操作码。
此致、
尊敬的 Clemet:
感谢您的答复。
我参考 simple_serial_socket_client_app_CC26X2R1_LAUNCHXL_tirtos_ccs 示例来启用通知。 我构建一个计时器来发布 EVT 并启用通知、当尝试传递 connhandle 并且程序在以下位置停止时、问题仍然会发生。
e2e.ti.com/.../8015.simple_5F00_central_5F00_LP_5F00_CC2652RB_5F00_tirtos7_5F00_ticlang.zip
if (Error_policy_D == Error_SPIN) { for(;;) { } } else if (((eb == &defErr) && (Error_policy_D == Error_UNWIND)) || (Error_policy_D == Error_TERMINATE)) { System_abort("ti_sysbios_runtime_Error_raise: terminating execution\n"); } }
对此、您有何建议?
马修
Matthew、您好!
您共享的代码是错误的结果-它不是导致错误的代码。
我建议您尝试确定导致此错误的是哪一行。 为此、您可以使用一些断点来确定执行停止的位置。
我希望这将有所帮助、
此致、