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.

cc2540在哪里捕获上位机读取Characteristic的事件



亲爱的TI工程师,您好:

        想在上位读取下位机的Characteristic之后,下位机能够捕获到这个事件,然后就主动断开与主机的连接,以防止因与主机长时间保持连接,而增加从机的功耗。

所以,我想问一下,主机读取完从机Characteristic这个事件在哪个函数的哪个事件里面捕获,麻烦您了,谢谢~o(∩_∩)o 哈哈

  • 在相应的Profile里面的读回调

  • 您好,能具体描述一下怎么实现吗?

    前期,在示例工程 SimpleBLEPeripheral 中我看到 simpleBLEPeripheral.c 文件中有有一个关于Profile的回调函数

    static void simpleProfileChangeCB( uint8 paramID )

    然后在其中插入CHAR5(我要读的那个characteristic)的代码,如下:

    static void simpleProfileChangeCB( uint8 paramID )
    {
      switch( paramID )
      {
        //..(其它case)
        case SIMPLEPROFILE_CHAR5:
          //xxxx(其它代码)
        break;
      }
    }

    但是仿真的时候,发现,我用上位机读取CHAR5的时候,并不会进入这个回调函数,是不是说这个函数只对Profile的写有响应。

    然后,上面那个函数即 simpleProfileChangeCB 是注册在 simpleBLEPeripheral_SimpleProfileCBs 这个结构体中,这个结构体是一个 simpleProfileCBs_t类型的结构体。

    //Simple GATT Profile Callbacks
    static simpleProfileCBs_t simpleBLEPeripheral_SimpleProfileCBs=
    {
      simpleProfileChangeCB    // Characteristic value change callback
    }

    并把这个结构体赋值给了 simpleProfile_AppCBs  这个同样是 simpleProfileCBs_t结构体类型的指针

    最后在

    static bStatus_t simpleProfile_WriteAttrB( uint16 connHandle, gattAttribute_t  *pAttr, uint8 *pValue, uint8 len, uint16 offset ) 
    {
      //..(其它代码)
      
      //If a charactersitic value changed then callback function to notify application of change
      if( (notifyApp!=0xff) && simpleProfile_AppCBs && simpleProfile_AppCBs->pfnSimpleProfileChange )
      {
        simpleProfile_AppCBs->pfnSimpleProfileChange( notifyApp );
      }
    }

    这个函数中被调用。

    不管是从字面解释上看,还是从函数的调用关系,他应该是Characteristic 值变化的时候,才会回调,即面向的是主机对从机的写过程。而主机对从机的读过程,因为不会改变Characteristic的值,所以并不会触发这个回调,不知道我理解的是否正确。

    那如果这样的话,那 “相应的Profile里面的读回调”在哪儿啊?

    还望您不惜赐教,谢谢~o(∩_∩)o 哈哈

  • static uint8 simpleProfile_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr, uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen )

    留意一下这个函数

  • 哈哈,非常感谢,将下面这段代码,添加到 static uint8 simpleProfile_ReadAttrCB(..)函数中,并作适当的修改之后,就成功响应了,并对CC2540的GATTProfile的实现方法有了进一步的了解~
    //If a charactersitic value changed then callback function to notify application of change
      if( (notifyApp!=0xff) && simpleProfile_AppCBs && simpleProfile_AppCBs->pfnSimpleProfileChange )
      {
        simpleProfile_AppCBs->pfnSimpleProfileChange( notifyApp );
      }

    再次表示感谢~o(∩_∩)o 哈哈