这是发送函数:
bStatus_t WeChat_SentIndicate( uint16 connHandle, uint8 *pValue, uint8 len, uint8 taskId) { uint8 status = FAILURE; if ( WeChat_Indicate_check(connHandle) ) //判断是否打开通知开关,打开了则发送数据 { attHandleValueInd_t indi; indi.pValue = GATT_bm_alloc(connHandle, ATT_HANDLE_VALUE_IND,len, NULL); if( indi.pValue != NULL ) { memset(indi.pValue,0,len); indi.handle = WeChat_GetAttHandleByUUID(WECHAT_INDICATE_UUID); indi.len = len; memcpy( indi.pValue, pValue, len); status = GATT_Indication( connHandle, &indi, FALSE, taskId ); TaskUARTPrintf("status:%d,%d,%d,%d,%d,%d\r\n",status,connHandle,indi.handle,indi.len,indi.pValue[3],indi.pValue[4]); if( status != SUCCESS ) { GATT_bm_free((gattMsg_t *)&indi, ATT_HANDLE_VALUE_IND); } } } return status; }
程序中第一次调用时是发送成功的,并且app收到了indicate数据,再次调用时,传入的参数除了数据不一样,其他都一样但返回FAILURE。两次调用间隔50ms或100ms都不好使,通过GATT_Indication()中调用的getStatusValueFromErrNo(ICall_Errno errno)的error发现error是-5,定义如下,
/** * ICall function return value in case the calling * thread context is not a registered thread, * or the entity id passed is not a registered entity. */ #define ICALL_ERRNO_UNKNOWN_THREAD -5
程序主体流程是app开启indicate ccc后调用GATT_Indication(),发送了2个包(第二个包通过if( pMsg->method == ATT_HANDLE_VALUE_CFM)满足后发送的),都成功了,这两个包用来认证,认证成功后app发出response,2640接收到response后再次调用GATT_Indication()发送给app数据包,这时执行GATT_Indication()出错了,出错内容如上,不知道应该如何解决这个问题。