TI中文支持网
TI专业的中文技术问题咨询交流网站

2640r2f simple_perial 怎样定时发送20个字节的蓝牙数据

如题 。。。。。。。。。。。

Viki Shi:

蓝牙从机向主机发送信息可以通过notification或者indication,在simpleBLEPeripheral工程里面,可调用GATTServApp_ProcessCharCfg()来进行发送,具体请看代码:

/*-------------------------------------------------------------------* GATT Server Sub-Procedure APIs*//*** @briefSend 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** @paramconnHandle - connection to use* @parampInd - pointer to indication to be sent* @paramauthenticated - whether an authenticated link is required*0x01: LE Legacy authenticated*0x02: Secure Connections authenticated* @paramtaskId - 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 );/*** @briefSend 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** @paramconnHandle - connection to use* @parampNoti - pointer to notification to be sent* @paramauthenticated - 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 );
/********************************************************************** @fnGATTServApp_ProcessCharCfg** @briefProcess Client Characteristic Configuration change.** @paramcharCfgTbl - characteristic configuration table.* @parampValue - pointer to attribute value.* @paramauthenticated - whether an authenticated link is required.* @paramattrTbl - attribute table.* @paramnumAttrs - number of attributes in attribute table.* @paramtaskId - task to be notified of confirmation.* @parampfnReadAttrCB - read callback function pointer.** @returnSuccess 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 parametersif ( ( 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 attributepAttr = 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 );}}}} // forreturn ( status );
}

YiKai Chen:

定時事件可以參考 sunmaysky.blogspot.com/…/how-to-create-periodic-event-to-toggle.html

赞(0)
未经允许不得转载:TI中文支持网 » 2640r2f simple_perial 怎样定时发送20个字节的蓝牙数据
分享到: 更多 (0)