主机使用CH592F的MultiCentral 例程
从机用沁恒的BLE调试助手模拟
使用BLE调试助手向主机发送数据时提示通知未打开.
代码格式有问题,代码里面的空格会被替换成未知符号,我上传了工程了
//遍历/打开通知的代码如下,使用代码格式有问题,我换成文本看一下
//通知遍历/打开任务 //staticvoidcentralGATTDiscoveryEvent(uint8_tconnItem,gattMsgEvent_t*pMsg) elseif(centralConnList[connItem].discState==BLE_DISC_STATE_CHAR) { log_i("charpMsg->method:%dandlen%d",pMsg->method,pMsg->msg.readByTypeRsp.numPairs); //Characteristicfound,storehandle if(pMsg->method==ATT_READ_BY_TYPE_RSP&& pMsg->msg.readByTypeRsp.numPairs>0) { log_i("Found%d,Characteristic1handle:%d",pMsg->msg.readByTypeRsp.numPairs,centralConnList[0].charHdl); for(unsignedchari=0;imsg.readByTypeRsp.numPairs;i++) { //characteristicproperties uint8_tchar_properties=pMsg->msg.readByTypeRsp.pDataList[pMsg->msg.readByTypeRsp.len*i+2]; uint16_tchar_value_handle=BUILD_UINT16(pMsg->msg.readByTypeRsp.pDataList[pMsg->msg.readByTypeRsp.len*i+3],\ pMsg->msg.readByTypeRsp.pDataList[pMsg->msg.readByTypeRsp.len*i+4]); //characteristicuuidlength uint8_tchar_uuid_length=pMsg->msg.readByGrpTypeRsp.len-5; //uuid uint8_t*char_uuid=&(pMsg->msg.readByGrpTypeRsp.pDataList[pMsg->msg.readByGrpTypeRsp.len*i+5]); log_i("char_properties:%02x,%s",char_properties,(char_properties&(GATT_PROP_WRITE|GATT_PROP_WRITE_NO_RSP))?"witehandle":""); log_i("char_value_handle:%04x",char_value_handle); log_i("char_uuid_length:%02d",char_uuid_length); log_i("char_uuid:"); MODUL_PRINTF_HEX(LOG_TAG,8,char_uuid,char_uuid_length); if(char_properties&(GATT_PROP_WRITE|GATT_PROP_WRITE_NO_RSP)) { log_i("wtitehandle:%04x\r\n",char_value_handle); } if(char_properties&GATT_PROP_NOTIFY) { log_i("notifyhandle:%04x\r\n",char_value_handle); } } } if((pMsg->method==ATT_READ_BY_TYPE_RSP&& pMsg->hdr.status==bleProcedureComplete)|| (pMsg->method==ATT_ERROR_RSP)) { //Discovercharacteristic centralConnList[connItem].discState=BLE_DISC_STATE_CCCD; req.startHandle=centralConnList[connItem].svcStartHdl; req.endHandle=centralConnList[connItem].svcEndHdl; req.type.len=ATT_BT_UUID_SIZE; req.type.uuid[0]=LO_UINT16(GATT_CLIENT_CHAR_CFG_UUID); req.type.uuid[1]=HI_UINT16(GATT_CLIENT_CHAR_CFG_UUID); //bStatus_tack=GATT_ReadUsingCharUUID(centralConnList[connItem].connHandle,&req,centralTaskId); bStatus_tack=GATT_DiscCharsByUUID(centralConnList[connItem].connHandle,&req,centralTaskId); log_i("starttoreadcccdack:%d,s:%d,e:%d",ack,req.startHandle,req.endHandle); } } elseif(centralConnList[connItem].discState==BLE_DISC_STATE_CCCD) { log_i("CCCDpMsg->method:%dandlen%d",pMsg->method,pMsg->msg.readByTypeRsp.numPairs); //Characteristicfound,storehandle if(pMsg->method==ATT_READ_BY_TYPE_RSP&& pMsg->msg.readByTypeRsp.numPairs>0) { centralConnList[connItem].cccHdl=BUILD_UINT16(pMsg->msg.readByTypeRsp.pDataList[0], pMsg->msg.readByTypeRsp.pDataList[1]);; centralConnList[connItem].procedureInProgress=FALSE; //StartdowriteCCCD tmos_start_task(centralConnList[connItem].taskID,START_WRITE_CCCD_EVT,DEFAULT_WRITE_CCCD_DELAY); //DisplayCharacteristic1handle log_i("Foundclientcharacteristicconfigurationhandle:%x\n",centralConnList[connItem].cccHdl); } centralConnList[connItem].discState=BLE_DISC_STATE_IDLE; } //CCCD任务 //static?uint16_t?connect0_ProcessEvent(uint8_t?task_id,?uint16_t?events) if(events&START_WRITE_CCCD_EVT) { if(centralConnList[CONNECT0_ITEM].procedureInProgress==FALSE) { //Doawrite attWriteReq_treq; req.cmd=FALSE; req.sig=FALSE; req.handle=centralConnList[CONNECT0_ITEM].cccHdl; req.len=2; req.pValue=GATT_bm_alloc(centralConnList[CONNECT0_ITEM].connHandle,ATT_WRITE_REQ,req.len,NULL,0); if(req.pValue!=NULL) { req.pValue[0]=1; req.pValue[1]=0; bStatus_tack=GATT_WriteCharValue(centralConnList[CONNECT0_ITEM].connHandle,&req,centralTaskId); if(ack==SUCCESS) { centralConnList[CONNECT0_ITEM].procedureInProgress=TRUE; log_i("WriteCCCDsuccess\n"); } else { GATT_bm_free((gattMsg_t*)&req,ATT_WRITE_REQ); log_e("WriteCCCDfailed:%x\n",ack); } } } return(events^START_WRITE_CCCD_EVT); }