关于上面贴出的代码好像不是那么回事。。。。。。。有没有大神知道CC2640从机能够自己使能notify的咧?我尝试用了CC2541的主机去使能CC2640从机notify功能,但是没反应,以下是我发送使能notify的程序
- //此部分为获取句柄,用了GATT_DiscAllChars获取,句柄存放于simpleBLECharHdl[1]当中
- static void simpleBLEGATTDiscoveryEvent( gattMsgEvent_t *pMsg )
- {
- attReadByTypeReq_t req;
-
- if( simpleBLEDiscState == BLE_DISC_STATE_SVC )
- {
- // Service found, store handles
- if(( pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP) && (pMsg->msg.findByTypeValueRsp.numInfo > 0))
- {
- simpleBLESvcStartHdl = pMsg->msg.findByTypeValueRsp.handlesInfo[0].handle;
- simpleBLESvcEndHdl = pMsg->msg.findByTypeValueRsp.handlesInfo[0].grpEndHandle;
- }
-
- // If procedure complete
- if(( pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP && pMsg->hdr.status == bleProcedureComplete )||
- ( pMsg->method == ATT_ERROR_RSP ) )
- {
- // if ( simpleBLESvcStartHdl != 0 )
- {
- simpleBLEDiscState = BLE_DISC_STATE_CHAR;
- //req.startHandle = simpleBLESvcStartHdl;
- //req.endHandle = simpleBLESvcEndHdl;
- //req.type.len = ATT_BT_UUID_SIZE;
- //req.type.uuid[0] = LO_UINT16(PROFILE_CHAR1_UUID);//通道1
- //req.type.uuid[1] = HI_UINT16(PROFILE_CHAR1_UUID);
- //GATT_ReadUsingCharUUID( simpleBLEConnHandle, &req, simpleBLETaskId );
-
- GATT_DiscAllChars(simpleBLEConnHandle,simpleBLESvcStartHdl,simpleBLESvcEndHdl,simpleBLETaskId);
- }
- }
- }
- else if( simpleBLEDiscState == BLE_DISC_STATE_CHAR )
- {
- // Characteristic found, store handle
- if ( pMsg->method == ATT_READ_BY_TYPE_RSP && pMsg->msg.readByTypeRsp.numPairs > 0 )
- {
-
- //simpleBLECharHdl[1] = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[2],pMsg->msg.readByTypeRsp.dataList[3]);
-
- simpleBLECharHdl[0] = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[3],pMsg->msg.readByTypeRsp.dataList[4]);
- simpleBLECharHdl[1] = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[7],pMsg->msg.readByTypeRsp.dataList[8]);
- // simpleBLEProcedureInProgress = FALSE;
- // osal_set_event( simpleBLETaskId, CEN_DISCOVERY_OK_EVT);//发现完成事件OK
- osal_set_event( simpleBLETaskId, CEN_DATA_SEND_EVT );
-
-
-
-
- }
- else
- {
- osal_start_timerEx( simpleBLETaskId, CEN_START_DISCOVERY_EVT, DEFAULT_SVC_DISCOVERY_DELAY );
- }
- simpleBLEDiscState = BLE_DISC_STATE_IDLE;
- }
- }
- 这部分为发送notify使能消息到从机,
- static uint8 CentralConfig(void)
- {
- attWriteReq_t writeReq;
- uint8 state;
-
- writeReq.len = 2;
- writeReq.value[0] = LO_UINT16(GATT_CLIENT_CFG_NOTIFY);
- writeReq.value[1] = HI_UINT16(GATT_CLIENT_CFG_NOTIFY);
- writeReq.sig = 0;
- writeReq.cmd = 0;
- writeReq.handle = simpleBLECharHdl[1]+1;
- state = GATT_WriteCharValue(simpleBLEConnHandle, &writeReq, simpleBLETaskId);
- return(state);
- }
以下为主机的写回调函数
- static bStatus_t Test_WriteAttrCB(uint16_t connHandle,
- gattAttribute_t *pAttr,
- uint8_t *pValue, uint16_t len,
- uint16_t offset, uint8_t method)
- {
- bStatus_t status = SUCCESS;
- uint8 notifyApp = 0xFF;
-
- // If attribute permissions require authorization to write, return error
- if ( gattPermitAuthorWrite( pAttr->permissions ) )
- {
- // Insufficient authorization
- return ( ATT_ERR_INSUFFICIENT_AUTHOR );
- }
-
- if ( pAttr->type.len == ATT_BT_UUID_SIZE )
- {
- // 16-bit UUID
- uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
- switch ( uuid )
- {
- case TEST_CHAR1_UUID:
- //Validate the value
- // Make sure it's not a blob oper
- if ( offset == 0 )
- {
- if ( len > TEST_CHAR1_LEN )
- {
- status = ATT_ERR_INVALID_VALUE_SIZE;
- }
- }
- else
- {
- status = ATT_ERR_ATTR_NOT_LONG;
- }
-
- //Write the value
- if ( status == SUCCESS )
- {
- //VOID osal_memcpy(pAttr->pValue, pValue, len);
- for(char i=0;i<len;i++)
- pAttr->pValue[i]=pValue[i];
-
- notifyApp = TEST_CHAR1;
- }
- break;
- //使能notify处理函数
- case GATT_CLIENT_CHAR_CFG_UUID:
-
- status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,
- offset, GATT_CLIENT_CFG_NOTIFY );
- break;
-
- default:
- // Should never get here! (characteristics 2 and 4 do not have write permissions)
- status = ATT_ERR_ATTR_NOT_FOUND;
- break;
- }
- }
- else
- {
- // 128-bit UUID
- status = ATT_ERR_INVALID_HANDLE;
- }
- // If a characteristic value changed then callback function to notify application of change
- if ( (notifyApp != 0xFF ) && Test_AppCBs && Test_AppCBs->pfnTestChange )
- {
- Test_AppCBs->pfnTestChange( notifyApp);
- }
-
- return ( status );
- }
我设了断电,但是主机发送使能notify后,无法跳进GATT_CLIENT_CHAR_CFG_UUID中,我用手机使能从机notify则可以跳转进去,求救。。。。
|