手机端发送读数据时, Peripheral例程中的哪个函数被触发回调?修改哪里让它读到我指定想返回的数据,谢谢!
热门产品 :
CH32X035: 32位USB+USB PD单片机
手机端发送读数据时, Peripheral例程中的哪个函数被触发回调?修改哪里让它读到我指定想返回的数据,谢谢!
在EVT\EXAM\BLE\Peripheral 的example中,这些读操作最先会调用下面这个函数:
文件: EVT\EXAM\BLE\Peripheral\Profile.c 中的部分代码
static bStatus_t simpleProfile_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr, uint8 *pValue, uint16 *pLen, uint16 offset, uint16 maxLen,uint8 method ) { bStatus_t status = SUCCESS; // If attribute permissions require authorization to read, return error if ( gattPermitAuthorRead( pAttr->permissions ) ) { // Insufficient authorization return ( ATT_ERR_INSUFFICIENT_AUTHOR ); } // Make sure it's not a blob operation (no attributes in the profile are long) if ( offset > 0 ) { return ( ATT_ERR_ATTR_NOT_LONG ); } 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 ) { // No need for "GATT_SERVICE_UUID" or "GATT_CLIENT_CHAR_CFG_UUID" cases; // gattserverapp handles those reads // characteristics 1 and 2 have read permissions // characteritisc 3 does not have read permissions; therefore it is not // included here // characteristic 4 does not have read permissions, but because it // can be sent as a notification, it is included here case SIMPLEPROFILE_CHAR1_UUID: *pLen = SIMPLEPROFILE_CHAR1_LEN; tmos_memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR1_LEN ); break; case SIMPLEPROFILE_CHAR2_UUID: *pLen = SIMPLEPROFILE_CHAR2_LEN; tmos_memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR2_LEN ); break; case SIMPLEPROFILE_CHAR4_UUID: *pLen = SIMPLEPROFILE_CHAR4_LEN; tmos_memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR4_LEN ); break; case SIMPLEPROFILE_CHAR5_UUID: *pLen = SIMPLEPROFILE_CHAR5_LEN; tmos_memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR5_LEN ); break; default: // Should never get here! (characteristics 3 and 4 do not have read permissions) *pLen = 0; status = ATT_ERR_ATTR_NOT_FOUND; break; }