修改服務需要對藍牙比較熟悉的工程師去完成,否則在例程功能滿足自己需求時,不建議修改,很容易改錯,下面就簡單介紹下如何在別的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端的顯示
浙公網安備 33010602011771號