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.

BLE中如何实现SPP类似协议?

Other Parts Discussed in Thread: CC2541

dear all:

   看到BLE中好像不支持SPP协议,我该如何实现类似SPP协议,来进行无线数据传输?

 

  • 这是个好问题.

    其实很简单, 你可以自己定义一个很简单的service,  这个service的作用只是最其中的characteristic的value进行读写或者notify.

    这个value就可以是一个指向某个内存空间的buffer, 用来接收或者发送数据.

    类似如下: (这个只是本人随手写的, 但是大概框架就是如此, 仅供参考)

    /* Attribute table. */
    static gattAttribute_t customSPPServiceAttrTbl[] =
    {
                        /* Service defination */
                       {
                                  { ATT_BT_UUID_SIZE, primaryServiceUUID }, /* type */
                                  GATT_PERMIT_READ, /* permissions */
                                   0, /* handle */
                                   (uint8 *)&customSPPService /* pValue */
                       },

                      /* Characteristic Declaration */
                     {
                              { ATT_BT_UUID_SIZE, characterUUID },
                              GATT_PERMIT_READ,
                              0,
                              &customSPPCharValProps
                        },

                       /* Characteristic value Declaration */
                      {
                              { ATT_BT_UUID_SIZE, customSPPValueUUID },
                              GATT_PERMIT_READ | GATT_PERMIT_WRITE,
                               0,
                              sppBuffer                         /* SPP的数据buffer, 可以用一个buffer来接收发送, 也可以再定义一个characteristic, 指定另外一个buffer, 两个可以分开, 一个发送, 一个接收. */
                        },
                 

                      /* Characteristic value User Description */
                     {
                                { ATT_BT_UUID_SIZE, charUserDescUUID },
                                GATT_PERMIT_READ,
                                0,
                               (uint8*)&customSPPUserDesc
                      },

    };

    然后再定义一下callback, 用于通知应用层数据的收发:

    /* For registering the service */
    CONST gattServiceCBs_t customSPP_GattCBs =
    {
    customSPP_ReadAttrCB, // Read callback function pointer
    customSPP_WriteAttrCB, // Write callback function pointer
    NULL // Authorization callback function pointer
    };

    最后你可以再参照一下TI提供的其他服务如何注册初始化的代码, 进行一些添加.

    另外, UUID什么的也请参考TI的实例代码进行自定义.

  • 其实TI的wiki上有个现成的BLE SPP的例子, 有代码:

    http://processors.wiki.ti.com/index.php/LPRF_BLE_SerialApp

  • Yan:

    这个示例怎么不能编译?

    编译错误[Su007]: Unable to open the command file "D:\UCOS\SerialApp2\Projects\ble\SerialAppCentral\CC2541\..\..\config\buildComponents.cfg"

  • 建议你下载安装一下BLE的协议栈, 然后比较, 把缺的文件从BLE协议栈里面拷过去

  • 编译错误[Su007]: Unable to open the command file "D:\UCOS\SerialApp2\Projects\ble\SerialAppCentral\CC2541\..\..\config\buildComponents.cfg"

    请问这个问题你怎么解决的啊,我也遇到了。。。

  • 命令行语句执行到了buildComponents.cfg这个文件,而该文件不存在。

    可以到Project->Option->C/C++ Complier界面,Extra Options下面找一找是不是有对应的命令行语句。或者在Option的其他界面。

    D:\UCOS\SerialApp2\Projects\ble\SerialAppCentral\CC2541应该是工作区,\..\..\config代表工作区的上上层路径下的config文件夹