用户工具

站点工具


cc2640r2f:notify_characteristic6

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

cc2640r2f:notify_characteristic6 [2017/09/01 20:36]
wuyl
cc2640r2f:notify_characteristic6 [2021/06/22 23:14]
行 1: 行 1:
-<markdown> 
- 
-# CC2640增加一个具有通知属性的 characteristic # 
- 
-## 介绍 ## 
- 
-本章使用 simple_peripheral 作为实验平台,创建一个自定义属性的 characteristic 。 
-simple_peripheral 的 IAR 工程可以在目录C:\ti\simplelink_cc2640r2_sdk_1_35_00_33\examples\rtos\CC2640R2_LAUNCHXL\ble5stack\simple_peripheral\tirtos\iar 下找到。 
-有关工程配置和编译选项以及下载方法参考<a href="..\..\..\get_started\development_environment_set_up\development_environment_set_up.html"> CC2640R2 BLE 开发环境搭建</a>部分和<a href="..\..\..\cc2640r2f_architecture\iar\development_with_iar.html">使用 IAR 进行开发</a> 
- 
-## 硬件环境 ## 
- 
-使用USB连接开发板如下图所示: 
- 
-![](http://www.leconiot.com/md_res/cc2640r2f/ble_stack_app/app_examples/notify_characteristic/image/picture.jpg) 
- 
-成功连接开发板之后,打开电脑的设备管理器,有XDS110 的两个端口,BLE Device Monitor 使用 XDS110 Class Application/User UART ( COM25 )这个端口。 
- 
->注意: 
-> XDS110 驱动程序在安装 IAR 时会默认安装,如果你没有安装 IAR ,可以手动更新驱动程序软件。XDS 驱动可以在<a href="..\..\..\get_started\development_tools_kit\develpoment_tool_kits.html"> CC2640R2 开发工具集介绍</a>里获得。 
- 
-![](http://www.leconiot.com/md_res/cc2640r2f/ble_stack_app/app_examples/notify_characteristic/image/XDS110.png) 
- 
-## 软件环境 ## 
- 
-- IAR Embedded workbench 7.80.3 
-- BLE-STACK V3.0.1 
-- flash_programmer 2 
-- BLE Device Monitor 
- 
-协议栈和 IAR 安装参考<a href="..\..\..\get_started\development_environment_set_up\development_environment_set_up.html"> CC2640R2 BLE 开发环境搭建</a>。本例程需要使用 BLE Device Monitor,有关 BLE Device Monitor 使用介绍请参考:<a href="..\..\..\tool_kits\ble_device_monitor\ble_device_monitor.html">BLE Device Monitor</a> 所有工具可以在<a href="..\..\..\get_started\development_tools_kit\develpoment_tool_kits.html"> CC2640R2 开发工具集介绍</a>里获得。 
- 
-## BLE Device Monitor 环境搭建 ## 
- 
-有关 BLE Device Monitor 环境搭建以及使用方法请参考:<a href="..\..\..\tool_kits\ble_device_monitor\ble_device_monitor.html"> BLE Device Monitor </a> 
- 
-## 开发步骤 ## 
- 
-在 simple_perpheral 工程中添加一个 characteristic 6,主要通过修改 simple_gatt_profile.c 和 simple_perpheral.c 两个文件完成。 
- 
-1. 在 simple_gatt_profile.h 文件里面添加以下宏定义: 
- 
-````C 
-//source\ti\ble5stack\profiles\simple_profile\simple_gatt_profile.h SIMPLEPROFILE_CHAR6 line 87  
-#define SIMPLEPROFILE_CHAR6                         //特征值 
-#define SIMPLEPROFILE_CHAR6_UUID              0xFFF6  //特征值UUID 
-#define SIMPLEPROFILE_CHAR6_LEN                     //特征值长度 
-```` 
- 
-2. 在 simple_peripheral.c 文件中设置特征值初始值,添加如下代码: 
- 
-````C 
-//examples\rtos\CC2640R2_LAUNCHXL\ble5stack\simple_peripheral\src\app\simple_peripheral.c charValue6 line 618 
-uint8_t charValue6[SIMPLEPROFILE_CHAR6_LEN] = { 'a', 'b', 'c', 'd', 'e' }; 
-//examples\rtos\CC2640R2_LAUNCHXL\ble5stack\simple_peripheral\src\app\simple_peripheral.c SimpleProfile_SetParameter line 629 
-SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR6, SIMPLEPROFILE_CHAR6_LEN, 
-                               charValue6); 
-```` 
- 
-3. SimpleProfile_SetParameter 这个函数作用是设置特征值,当特征值具有通知属性就使用通知发送出来。由于该函数没有 characteristic 6 的处理过程,所以需要我们自己添加,在 simple_gatt_profile.c 文件中,增加如下代码: 
- 
-````C 
-//examples\rtos\CC2640R2_LAUNCHXL\ble5stack\simple_peripheral\src\app\simple_peripheral.c SimpleProfile_SetParameter line 547 
-case SIMPLEPROFILE_CHAR6: 
-if ( len == SIMPLEPROFILE_CHAR6_LEN ) { 
-    VOID memcpy( simpleProfileChar6, value, SIMPLEPROFILE_CHAR6_LEN ); 
-    // See if Notification has been enabled 
-    GATTServApp_ProcessCharCfg( simpleProfileChar6Config, simpleProfileChar6, FALSE, 
-                                simpleProfileAttrTbl, GATT_NUM_ATTRS( simpleProfileAttrTbl ), 
-                                INVALID_TASK_ID, simpleProfile_ReadAttrCB ); 
-} else{ 
-    ret = bleInvalidRange; 
-}break;    
-```` 
- 
-4. 同理在 SimpleProfile_GetParameter 函数中也没有 characteristic 6 的处理过程,在 SimpleProfile_GetParameter 中增加如下代码: 
- 
-````C 
-//examples\rtos\CC2640R2_LAUNCHXL\ble5stack\simple_peripheral\src\app\simple_peripheral.c SimpleProfile_GetParameter line 604 
-case SIMPLEPROFILE_CHAR6: 
-  VOID memcpy( value, simpleProfileChar6, SIMPLEPROFILE_CHAR6_LEN ); 
-  break;  
-```` 
- 
-5. 在 simple_gatt_profile.c 定义 characteristic 6 属性变量,并在 simpleProfileAttrTbl 属性数组表中添加如下代码: 
- 
-````C 
-//examples\rtos\CC2640R2_LAUNCHXL\ble5stack\simple_peripheral\src\app\simple_peripheral.c  simpleProfileChar6Props line 197 
-static uint8 simpleProfileChar6Props = GATT_PROP_NOTIFY; 
-static gattCharCfg_t *simpleProfileChar6Config; 
-static uint8 simpleProfileChar6[SIMPLEPROFILE_CHAR6_LEN] = { 0, 0, 0, 0, 0 }; 
-static uint8 simpleProfileChar6UserDesp[17] = "Characteristic 6"; 
- 
-//examples\rtos\CC2640R2_LAUNCHXL\ble5stack\simple_peripheral\src\app\simple_peripheral.c  simpleProfilechar6UUID line 197 
-// Characteristic 6 UUID: 0xFFF6 
-CONST uint8 simpleProfilechar6UUID[ATT_BT_UUID_SIZE] ={  
-  LO_UINT16(SIMPLEPROFILE_CHAR6_UUID), HI_UINT16(SIMPLEPROFILE_CHAR6_UUID) 
-}; 
- 
-//examples\rtos\CC2640R2_LAUNCHXL\ble5stack\simple_peripheral\src\app\simple_peripheral.c  simpleProfileAttrTbl line 340 
-// Characteristic 6 Declaration 
-{ { ATT_BT_UUID_SIZE, characterUUID }, 
-GATT_PERMIT_READ,  
-0, 
-&simpleProfileChar6Props }, 
-// Characteristic Value 6 
-{ { ATT_BT_UUID_SIZE, simpleProfilechar6UUID }, 
-0,  
-0,  
-simpleProfileChar6 }, 
-{ { ATT_BT_UUID_SIZE, clientCharCfgUUID }, 
-GATT_PERMIT_READ | GATT_PERMIT_WRITE,  
-0,  
-(uint8 *)&simpleProfileChar6Config }, 
-// Characteristic 6 User Description 
-{ { ATT_BT_UUID_SIZE, charUserDescUUID }, 
-GATT_PERMIT_READ,  
-0,  
-simpleProfileChar6UserDesp }, 
-```` 
- 
->注意修改 simpleProfileAttrTbl [ SERVAPP_NUM_ATTR_SUPPORTED ]数组大小,SERVAPP_NUM_ATTR_SUPPORTED 定义的是 17 ,由于我们添加了 4 个属性,所以这里需要修改成 21 。 
- 
-6. 接下来在 simple_gatt_profile.c 的 SimpleProfile_AddService 函数中对 characteristic 6 的 simpleProfileChar4Config 参数分配内存,并初始化配置属性表。 
- 
-````C 
-//examples\rtos\CC2640R2_LAUNCHXL\ble5stack\simple_peripheral\src\app\simple_peripheral.c  SimpleProfile_AddService line 419 
-simpleProfileChar6Config = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t)*linkDBNumConns ); 
-if ( simpleProfileChar6Config == NULL ){      
-return ( bleMemAllocError ); 
-} 
-GATTServApp_InitCharCfg( INVALID_CONNHANDLE, simpleProfileChar6Config ); 
-```` 
- 
-7. 回调改写,走读一下 SimpleProfile_SetParameter() 这个函数可以发现:TI 的处理过程是每次设置参数后会调用回调读取当前值,然后使用通知发送出来。如果要成功的使用通知发送数据,还必须在 simpleProfile_ReadAttrCB 回调函数中增加 characteristic 6 的代码。 
-在 simple_gatt_profile.c 文件中 simpleProfile_ReadAttrCB 函数里添加如下代码: 
- 
-````C 
-//examples\rtos\CC2640R2_LAUNCHXL\ble5stack\simple_peripheral\src\app\simple_peripheral.c  simpleProfile_ReadAttrCB line 670 
-case SIMPLEPROFILE_CHAR6_UUID: 
-  *pLen = SIMPLEPROFILE_CHAR6_LEN; 
-  VOID memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR6_LEN ); 
-  break; 
-```` 
- 
-经过上面 7 步就完成了增加通知属性的 characteristic 特征值,我们可以通过按键方式或定时器每秒进行一次通知。本文演示的是使用定时器每秒通知一次characteristic 6 的值,在 simple_peripheral.c 文件里 SimpleBLEPeripheral_performPeriodicTask 函数中增加下面代码: 
- 
-````C 
-//examples\rtos\CC2640R2_LAUNCHXL\ble5stack\simple_peripheral\src\app\simple_peripheral.c  SimpleBLEPeripheral_performPeriodicTask line 1380 
-uint8_t charValue6[SIMPLEPROFILE_CHAR6_LEN] = { 'a', 'b', 'c', 'd', 'e' }; 
-SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR6, SIMPLEPROFILE_CHAR6_LEN, charValue6); 
-```` 
- 
-如下图所示,使用 BLE Device Monitor 就能接收到开发板发送出来的数据,这里显示的 abcde 和我们设置的一样。 
- 
-![](http://www.leconiot.com/md_res/cc2640r2f/ble_stack_app/app_examples/notify_characteristic/image/characteristic6.png) 
- 
-## 加入我们 ## 
-文章所有代码、工具、文档开源。加入我们[**QQ群 591679055**](http://shang.qq.com/wpa/qunwpa?idkey=d94f12d37c3b37892af4b757c6dc34bea140f3f3128a8d68e556a3d728148e85)获取更多支持,共同研究CC2640R2F&BLE5.0。 
-<div> 
-<p align="right"> 
-<a target="_blank" href="http://shang.qq.com/wpa/qunwpa?idkey=d94f12d37c3b37892af4b757c6dc34bea140f3f3128a8d68e556a3d728148e85"><img border="0"  src="http://pub.idqqimg.com/wpa/images/group.png" alt="CC2640R2F&BLE5.0-乐控畅联" align="right" title="CC2640R2F&BLE5.0-乐控畅联"></a> 
-© Copyright 2017, 成都乐控畅联科技有限公司.   
-</p> 
-</div> 
- 
- 
- 
- 
- 
- 
-</markdown> 
  
cc2640r2f/notify_characteristic6.txt · 最后更改: 2021/06/22 23:14 (外部编辑)