在对ble系列应用时,很多时候拿手机充当主机。在使用ble 调试助手时常会用到write、read、notify等功能。有时可能会根据自己的需求对这些服务进行修改。下图是官方例程体现出的services。

想要对服务进行修改,要从从机抓起。毕竟执行服务的是从机。需要操作的gattprofile.c的文件。

以添加服务为例新增一个notify服务,在UUID为0XFFF2的服务进行修改。要模拟一个服务就要做到神形兼备 ,既有相应的功能选项又要能够实现相应的功能。

首先让他先有形,这一步是比较容易的在图中的部分进行修改(根据已经有的notify服务进行修改),修改后的代码为

static uint8_t simpleProfileChar2Props = GATT_PROP_READ | GATT_PROP_NOTIFY;下载程序后的效果为,但是是无法实现notify的功能的。

接下来就要为notify实现功能而努力。继续往下看程序我们会发现关于UUID为0XFFF4的notify服务的配置。经过对比我们会发现具体实现notify的功能的程序在红框中

,

那我们就要对我们新增的notify进行修改

// Characteristic 2 Declaration
{
{ATT_BT_UUID_SIZE, characterUUID},
GATT_PERMIT_READ,
0,
&simpleProfileChar2Props}, // Characteristic Value 2
{
{ATT_BT_UUID_SIZE, simpleProfilechar2UUID},
GATT_PERMIT_READ,
0,
simpleProfileChar2},
// rzz
{
{ATT_BT_UUID_SIZE, simpleProfilechar2UUID},
0,
0,
simpleProfileChar2}, // rzz
{
{ATT_BT_UUID_SIZE, clientCharCfgUUID},
GATT_PERMIT_READ | GATT_PERMIT_WRITE,
0,
(uint8_t *)simpleProfileChar2Config}, // Characteristic 2 User Description
{
{ATT_BT_UUID_SIZE, charUserDescUUID},
GATT_PERMIT_READ,
0,
simpleProfileChar2UserDesp},

到这里就能使用了吗?不,仍需努力。接下来我们要继续浏览gattprofile.c中的程序。

请看好接下来的操作:这里可以发现红框中出现的simpleProfileChar4Config与前面的的相对应,在这里要考虑新增一个

GATTServApp_InitCharCfg(INVALID_CONNHANDLE, simpleProfileChar2Config)语句,再回头看一下有对simpleProfileChar4Config的定义的全局变量。

static gattCharCfg_t simpleProfileChar4Config[PERIPHERAL_MAX_CONNECTION];

static gattCharCfg_t simpleProfileChar2Config[PERIPHERAL_MAX_CONNECTION];

接下来对NOTIFY进行操作,

bStatus_t simpleProfile_Notify(uint16_t connHandle, attHandleValueNoti_t *pNoti)
{
uint16_t value = GATTServApp_ReadCharCfg(connHandle, simpleProfileChar4Config);
uint16_t value1 = GATTServApp_ReadCharCfg(connHandle, simpleProfileChar2Config);
// If notifications enabled
if(value & GATT_CLIENT_CFG_NOTIFY)
{
// Set the handle
pNoti->handle = simpleProfileAttrTbl[SIMPLEPROFILE_CHAR4_VALUE_POS].handle;
// Send the notification
return GATT_Notification(connHandle, pNoti, FALSE);
}
if(value1 & GATT_CLIENT_CFG_NOTIFY)
{
// Set the handle
pNoti->handle = simpleProfileAttrTbl[SIMPLEPROFILE_CHAR2_VALUE_POS].handle; //rzz
// Send the notification
return GATT_Notification(connHandle, pNoti, FALSE);
}
return bleIncorrectMode;
}

static void simpleProfile_HandleConnStatusCB(uint16_t connHandle, uint8_t changeType)
{
// Make sure this is not loopback connection
if(connHandle != LOOPBACK_CONNHANDLE)
{
// Reset Client Char Config if connection has dropped
if((changeType == LINKDB_STATUS_UPDATE_REMOVED) ||
((changeType == LINKDB_STATUS_UPDATE_STATEFLAGS) &&
(!linkDB_Up(connHandle))))
{
GATTServApp_InitCharCfg(connHandle, simpleProfileChar4Config);
GATTServApp_InitCharCfg(connHandle, simpleProfileChar2Config);//rzz
}
}
}

 

更改到此处notify的功能已经可以用了,根据自己的需求在peripheral.c中进行修改,在notify中接收相应的数据。

这只是最基础的修改,如有问题请指正!

最新文章

  1. 运行tomcat8w.exe未安装指定的服务
  2. Ggoogle Protocol Buffer的使用 (基于C++语言)
  3. (转)SVN 服务端、客户端安装及配置、导入导出项目
  4. overflow 那些我们忽略的特点
  5. phantompy — phantompy 0.10 documentation
  6. C++学习笔记3
  7. SQL 横转竖 、竖专横(转载) 列转行 行转列
  8. java编程(2)——servlet和Ajax异步请求的接口编程(有调用数据库的数据)
  9. MD5加密解密类(asp.net)&使用MD5过时处理
  10. (4opencv)对OpenCV中“旋转”的思考和实验
  11. Object-c 调用unity的 UIViewController和UnitySendMessage
  12. 设计模式 笔记 适配器模式 Adapter
  13. 设置adb server的端口号
  14. POJ-2181 Jumping Cows(贪心)
  15. git stash,git cherry-pick
  16. vb 读取指定路径文件名
  17. Python3.5 学习十
  18. 为什么排版引擎解析 CSS 选择器时一定要从右往左解析?
  19. OGNL表达式语言中的"#"和"$"的区别
  20. [转载]Spring配置文件详解一:

热门文章

  1. 使用Docker搭建Nextcloud私有网盘
  2. HCNP Routing&Switching之端口安全
  3. smile——Java机器学习引擎
  4. sql报错收集
  5. KingbaseES R6 集群手工配置VIP案例
  6. 如何修改SAO用户密码
  7. .NET 反向代理-YARP
  8. Java 热更新 Groovy 实践及踩坑指南
  9. 一文了解 Java 中的构造器
  10. Openstack neutron:云数据中心底层网络架构