如题 。。。。。。。。。。。
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.
蓝牙从机向主机发送信息可以通过notification或者indication,在simpleBLEPeripheral工程里面,可调用GATTServApp_ProcessCharCfg()来进行发送,具体请看代码:
/*------------------------------------------------------------------- * GATT Server Sub-Procedure APIs */ /** * @brief Send a GATT Indication * * This sub-procedure is used when a server is configured to * indicate a characteristic value to a client and expects an * attribute protocol layer acknowledgement that the indication * was successfully received. * * @ref ATT_HandleValueInd is used in this sub-procedure. * * @par Corresponding Events * If the return status from this function is @ref SUCCESS and the GATT client * succesfully sends an acknowledgement, the calling * application task will receive a @ref GATT_MSG_EVENT message with method: * @ref ATT_HANDLE_VALUE_CFM of type @ref attHandleValueInd_t , with * status @ref SUCCESS or @ref bleTimeout . At this point, the procedure * is complete. * * @warning The payload must be dynamically allocated using @ref GATT_bm_alloc * * @note The client must use @ref GATT_RegisterForInd in order to receive * Indications in the application task and use * @ref ATT_HandleValueCfm to return the acknowledgement to the server * * @param connHandle - connection to use * @param pInd - pointer to indication to be sent * @param authenticated - whether an authenticated link is required * 0x01: LE Legacy authenticated * 0x02: Secure Connections authenticated * @param taskId - task to be notified of response * * @return @ref SUCCESS : Indication was queued successfully. * @return @ref INVALIDPARAMETER * @return @ref MSG_BUFFER_NOT_AVAIL * @return @ref bleNotConnected * @return @ref blePending : A confirmation is pending with this client. * @return @ref bleMemAllocError * @return @ref bleInvalidMtuSize : Packet length is larger than connection's MTU size. * @return @ref bleTimeout : Previous transaction timed out. */ extern bStatus_t GATT_Indication( uint16 connHandle, attHandleValueInd_t *pInd, uint8 authenticated, uint8 taskId ); /** * @brief Send a GATT Notification * * This sub-procedure is used when a server is configured to * notify a characteristic value to a client without expecting * any attribute protocol layer acknowledgement that the * notification was successfully received. * * @ref ATT_HandleValueNoti is used in this sub-procedure. * * @note * A notification may be sent at any time. * No confirmation will be sent to the calling task for * this sub-procedure. * * @warning The payload must be dynamically allocated using @ref GATT_bm_alloc * * @note The client must use @ref GATT_RegisterForInd in order to receive * Notifications in the application task * * @param connHandle - connection to use * @param pNoti - pointer to notification to be sent * @param authenticated - whether an authenticated link is required * 0x01: LE Legacy authenticated * 0x02: Secure Connections authenticated * * @return @ref SUCCESS : Notification was queued successfully. * @return @ref INVALIDPARAMETER * @return @ref MSG_BUFFER_NOT_AVAIL * @return @ref bleNotConnected * @return @ref bleMemAllocError * @return @ref bleInvalidMtuSize : Packet length is larger than connection's MTU size. * @return @ref bleTimeout : Previous transaction timed out. */ extern bStatus_t GATT_Notification( uint16 connHandle, attHandleValueNoti_t *pNoti, uint8 authenticated );
/********************************************************************* * @fn GATTServApp_ProcessCharCfg * * @brief Process Client Characteristic Configuration change. * * @param charCfgTbl - characteristic configuration table. * @param pValue - pointer to attribute value. * @param authenticated - whether an authenticated link is required. * @param attrTbl - attribute table. * @param numAttrs - number of attributes in attribute table. * @param taskId - task to be notified of confirmation. * @param pfnReadAttrCB - read callback function pointer. * * @return Success or Failure */ bStatus_t GATTServApp_ProcessCharCfg( gattCharCfg_t *charCfgTbl, uint8 *pValue, uint8 authenticated, gattAttribute_t *attrTbl, uint16 numAttrs, uint8 taskId, pfnGATTReadAttrCB_t pfnReadAttrCB ) { uint8 i; bStatus_t status = SUCCESS; // Verify input parameters if ( ( charCfgTbl == NULL ) || ( pValue == NULL ) || ( attrTbl == NULL ) || ( pfnReadAttrCB == NULL ) ) { return ( INVALIDPARAMETER ); } for ( i = 0; i < linkDBNumConns; i++ ) { gattCharCfg_t *pItem = &(charCfgTbl[i]); if ( ( pItem->connHandle != CONNHANDLE_INVALID ) && ( pItem->value != GATT_CFG_NO_OPERATION ) ) { gattAttribute_t *pAttr; // Find the characteristic value attribute pAttr = GATTServApp_FindAttr( attrTbl, numAttrs, pValue ); if ( pAttr != NULL ) { if ( pItem->value & GATT_CLIENT_CFG_NOTIFY ) { status |= gattServApp_SendNotiInd( pItem->connHandle, GATT_CLIENT_CFG_NOTIFY, authenticated, pAttr, taskId, pfnReadAttrCB ); } if ( pItem->value & GATT_CLIENT_CFG_INDICATE ) { status |= gattServApp_SendNotiInd( pItem->connHandle, GATT_CLIENT_CFG_INDICATE, authenticated, pAttr, taskId, pfnReadAttrCB ); } } } } // for return ( status ); }