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.

获取特征值句柄问题



技术你好,我使用从机例程,CC2640R2F,版本是cc2640r2_sdk_1_40_00_45,iar软件,在从机例程添加自定义服务,目前有一个需求,主机想要读取多个服务中其中一个服务里卖弄的某一个特征值句柄,从而获取这个特征值的对应数据。

那么有没有什么函数或者方法能定位到这个目标呢?

  • 由于读写函数都是底层注册的回掉函数,参数也都是底层传递的,所以我没找到能直接获取到对应句柄的地方.

  • 没看懂,能否具体举个例子,要获取哪个handle?
  • 比如我有两个服务一个是心率,一个是电量,每个服务里面有五个特征值。那么我主机想要得到电量服务中其中一个特征值,我如何去定位到这个特征值。如何读取他的uuid呢?
  • 还是说我直接读取那个属性表中的handle的值就行了?就能得到系统给的句柄了吗?
  • 确实是通过底层callback函数传递的,主机发现服务后,可以通过特征值的UUID获取到特征值的句柄

    static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle,
                                              gattAttribute_t *pAttr,
                                              uint8_t *pValue, uint16_t *pLen,
                                              uint16_t offset, uint16_t maxLen,
                                              uint8_t method)
    {
      bStatus_t status = SUCCESS;
    
      // 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:
          case SIMPLEPROFILE_CHAR2_UUID:
          case SIMPLEPROFILE_CHAR4_UUID:
            *pLen = 1;
            pValue[0] = *pAttr->pValue;
            break;
    
          case SIMPLEPROFILE_CHAR5_UUID:
            *pLen = SIMPLEPROFILE_CHAR5_LEN;
            VOID 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;
        }
      }
      else
      {
        // 128-bit UUID
        *pLen = 0;
        status = ATT_ERR_INVALID_HANDLE;
      }
    
      return ( status );
    }

  • 了解和我想的一样。