修改服务需要对蓝牙比较熟悉的工程师去完成,否则在例程功能满足自己需求时,不建议修改,很容易改错,下面就简单介绍下如何在别的char添加一个nofify属性。
step1:
给Simple Profile Characteristic 1 Properties添加一个notify属性,原先只有读写属性:
// Simple Profile Characteristic 1 Properties
static uint8_t simpleProfileChar1Props = GATT_PROP_READ | GATT_PROP_WRITE | GATT_PROP_NOTIF;
step2:
模仿char4在char1的value 1下添加:
// Characteristic 1 configuration
{
{ATT_BT_UUID_SIZE, clientCharCfgUUID},
GATT_PERMIT_READ | GATT_PERMIT_WRITE,
0,
(uint8_t *)simpleProfileChar1Config},
step3:
全局搜索下simpleProfileChar4Config,共有五处,上面已经改了两处,
bStatus_t SimpleProfile_AddService(uint32_t services)
{
uint8_t status = SUCCESS;
// Initialize Client Characteristic Configuration attributes
GATTServApp_InitCharCfg(INVALID_CONNHANDLE, simpleProfileChar4Config);
GATTServApp_InitCharCfg(INVALID_CONNHANDLE, simpleProfileChar1Config);
// Register with Link DB to receive link status change callback
linkDB_Register(simpleProfile_HandleConnStatusCB);
if(services & SIMPLEPROFILE_SERVICE)
{
// Register GATT attribute list and CBs with GATT Server App
status = GATTServApp_RegisterService(simpleProfileAttrTbl,
GATT_NUM_ATTRS(simpleProfileAttrTbl),
GATT_MAX_ENCRYPT_KEY_SIZE,
&simpleProfileCBs);
}
step4:
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, simpleProfileChar1Config);
}
}
}
step5:
新建一个通知函数:
step6:
前五步设置好,notify的通道就已经打通了,接下来调用发送就可以验证了:
ps:后面会加一些app端的显示
标签:connHandle,CH573F,InitCharCfg,例程,Characteristic,peripheral,uint8,GATT,GATTServAp From: https://www.cnblogs.com/risc5-ble/p/16866045.html