主機使用CH592F的MultiCentral 例程
從機用沁恒的BLE調(diào)試助手模擬
使用BLE調(diào)試助手向主機發(fā)送數(shù)據(jù)時提示通知未打開.
代碼格式有問題,代碼里面的空格會被替換成未知符號,我上傳了工程了
//遍歷/打開通知的代碼如下,使用代碼格式有問題,我換成文本看一下
//通知遍歷/打開任務 //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); }