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.

请教下从机数据接收和发送问题



  请问一下,

1)从机收到主机发过来的数据后,从机接收数据的入口函数在哪呢,我看既有函数SimpleProfile_GetParameter,也有SimpleProfile_ReadAttrCB,还有回调函数simpleProfileChangeCB,对这几个函数的关系不是很了解。目前我在simpleProfileChangeCB中添加串口打印程序,是可以将主机发送过来的数据打印出来的

2)还有发送数据时,SimpleProfile_SetParameter和GATT_Notification两个是不是都可以呢?

3)simpleProfile_WriteAttrCB这个函数在从机数据传递过程中的作用是什么呢

  • 1. 首先SimpleProfile_GetParameter是留给客户来读取这个特征值的参数的,你可以再任何地方调用,读取特征值。SimpleProfile_ReadAttrCB这个函数就是主机想要读从机的值的时候,和从机连接的入口,当主机发送读命令后,会进入这个函数。simpleProfileChangeCB是一个回调函数,当特征值改变时,会自动调用,所以你在这个函数添加打印程序是可以打印出来的。

    2. SimpleProfile_SetParameter是留给用户自己设定这个参数的,光靠这一个函数无法实现数据的发送,这个函数应用在simplePeripheral工程中的特定特征值char4,因为char4是notify属性,具体对其有这样一段程序

     case SIMPLEPROFILE_CHAR4:
          if ( len == sizeof ( uint8 ) )
          {
            simpleProfileChar4 = *((uint8*)value);
           
            // See if Notification has been enabled
            GATTServApp_ProcessCharCfg( simpleProfileChar4Config, &simpleProfileChar4, FALSE,
                                        simpleProfileAttrTbl, GATT_NUM_ATTRS( simpleProfileAttrTbl ),
                                        INVALID_TASK_ID );
          }
          else
          {
            ret = bleInvalidRange;
          }
          break;

    它调用了这个GATTServApp_ProcessCharCfg函数,这个函数会间接调用GATT_Notification函数来实现数据发送。其实最底层、最基础的函数是GATT_notification,这个来发通知的。

    3. 当主机要写某个特征值的时候,就会进这个函数接口

  • hua huamao你好,非常感谢你的回答,我知道这些内容很基础,可目前的确很困扰我。

    照你上面的说法,SimpleProfile_ReadAttrCB是主机读取从机发送过来的数据,SimpleProfile_WriteAttrCB是主机写某个特征值,那么

    1)想确认下这两个函数是否和从机收发数据没有任何关系,只是主机会用到

    2)还有GATT_ReadCharValue和GATT_WriteCharValue这两个函数好像也是读取和写数据,和SimpleProfile_ReadAttrCB,SimpleProfile_WriteAttrCB之间的关系呢