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.

请教个GATT_DiscPrimaryServiceByUUID 函数的问题



GATT_DiscPrimaryServiceByUUID 这个执行后,event里回的ATT_FindByTypeValueRsp这个结构体包含了哪些信息?和static gattAttribute_t simpleProfileAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED] =
{
  // Simple Profile Service
  {
    { ATT_BT_UUID_SIZE, primaryServiceUUID }, /* type */
    GATT_PERMIT_READ,                         /* permissions */
    0,                                        /* handle */
    (uint8 *)&simpleProfileService            /* pValue */
  },

这个结构体有关么?有关的话这个对应关系是咋样的呢?看了很久代码,没想明白,先谢谢了

  • 跟这个关系不大.

    GATT_DiscPrimaryServiceByUUID 通过你指定的UUID去发现一个Primary service.

    ATT_FindByTypeValueRsp 里面 的结构体 attFindByTypeValueRsp_t, 内容是根据你需要的UUID, 返回的primary service的attribute handle的个数, 以及以这个primary service的attribute handle值开始, 到这个primary service 所有属性定义结束为一个group的最有一个属性的attribute handle值.

    总而言之, 返回的是总共有几个这个UUID的primary service, 以及这几个primary service, 每一个primary service的attribute handle, 最后一个属性的attribute handle.

    看这两个:

    /**
    * Handles Infomation format.
    */
    typedef struct
    {
    uint16 handle; //!< Found attribute handle
    uint16 grpEndHandle; //!< Group end handle
    } attHandlesInfo_t;

    /**
    * Find By Type Value Response format.
    */
    typedef struct
    {
    uint8 numInfo; //!< Number of handles information found
    attHandlesInfo_t handlesInfo[ATT_MAX_NUM_HANDLES_INFO]; //!< List of 1 or more handles information
    } attFindByTypeValueRsp_t;

  • 那这个primary service的attribute handle的个数primary service的attribute handle的开始值是在哪边定义的呢?

  • Hi Feng,

    在每个示例程序里面的init函数里面, 都会有一系列Add service之类的函数.

    通过你之前看到的那些定义好的service结构体, 通过调用add service函数, 底层的协议栈会自动分配好Handle. 

  • 这个handle代码啥意思呢?和init注册的结构体的关系是怎么样的呢?

  • GATT_DiscPrimaryServiceByUUID传入的UUID就是simpleProfileAttrTbl结构体中primaryServiceUUID的UUID么?

  • 没错, 在simple peripheral 这个例子里面, 就是SIMPLEPROFILE_SERV_UUID

  • 这里面的数据的传输,好像完全是借鉴网络数据传输的那种概念,和网络传输的协议和封装的都很相似

  • 在问两个问题

    1.这张表的开头是佛必须以开始?

      // Simple Profile Service
      {
        { ATT_BT_UUID_SIZE, primaryServiceUUID }, /* type */
        GATT_PERMIT_READ,                         /* permissions */
        0,                                        /* handle */
        (uint8 *)&simpleProfileService            /* pValue */
      },

    2. characteristic  declaration 和value分别是做什么用的呢?这两个有关系么

        // Characteristic 1 Declaration
        {
          { ATT_BT_UUID_SIZE, characterUUID },
          GATT_PERMIT_READ,
          0,
          &simpleProfileChar1Props
        },

          // Characteristic Value 1
          {
            { ATT_BT_UUID_SIZE, simpleProfilechar1UUID },
            GATT_PERMIT_READ | GATT_PERMIT_WRITE,
            0,
            &simpleProfileChar1
          },

  • Hi Feng,

    你的第一个问题看不懂是要问什么?

    第二个问题, 这个value就是这个characteristic对应的要操作的值.

    这些都是可以在蓝牙协议栈介绍中可以找到的关于BLE的GATT定义的非常基本的概念.

    我这里开课的话不太合适, 东西比较多, 你可以看上面的教学视频, 也可以看上面的深度培训文档, 最好是可以去blueooth sig 官网上下载spec:

    https://www.bluetooth.org/en-us/specification/adopted-specifications

    其中第三章 volume 3  Core System Package 里面的 part G: GENERIC ATTRIBUTE PROFILE (GATT) 里面的第三章 3 SERVICE INTEROPERABILITY REQUIREMENTS, 这里面有很详细的介绍 service, characteristic 定义的内容.

    最后, 你也可以看一下TI_BLE_Software_Developer's_Guide.pdf, 这个是跟着你下载的BLE协议栈一起有的.

    里面的第37页, 有个很详细的以simpleBLEPeripheral为例子的service和characteristic定义的表格.