首页 > 其他分享 >CH58X服务修改

CH58X服务修改

时间:2022-11-02 11:56:25浏览次数:36  
标签:connHandle 服务 UUID GATT 修改 CH58X notify handle

在对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中接收相应的数据。

 

 

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

标签:connHandle,服务,UUID,GATT,修改,CH58X,notify,handle
From: https://www.cnblogs.com/frontier/p/16845596.html

相关文章