GATT_Notification vs. GATTServApp_ProcessCharCfg

A:Notification连接后,从机向主机发送的数据包,不需要主机确认收到,适合大量数据快速发送。
从机 Notification发送方式有两种,用户根据自身要求选择:
(1)调用GATT_Notification( uint16 connHandle, attHandleValueNoti_t *pNoti, uint8 authenticated );直接发送
(2)调用GATTServApp_ProcessCharCfg函数,这个函数内部最终会导致master那边调用一个read请求,回调到simpleProfile_ReadAttrCB()。用这个函数,只有master向Peripheral的Notification允许位写1,才能使能从机,从而调用GATT_Notification向主机发送Notification。

//声明attHandleValueNoti_t这个结构体
static attHandleValueNoti_t pReport ;
//存放handle
uint16 noti_cHandle; 
//读取notification对应的handle
pReport.handle = simpleProfileAttrTbl[11].handle;
//获取Connection Handle
GAPRole_GetParameter( GAPROLE_CONNHANDLE, ¬i_cHandle);
pReport.len = 1;            //数据长度
pReport.value[0] = 0x03;    //赋值
GATT_Notification(noti_cHandle,&pReport,FALSE);
//!< Connection Handle. Read Only. Size is uint16.
#define GAPROLE_CONNHANDLE          0x30E 
//eg: 
GAPRole_GetParameter( GAPROLE_CONNHANDLE, &gapConnHandle );

simpleBLECentral
1、添加notification的接收
simpleBLECentralProcessGATTMsg()
类似
if ( ( pMsg->method == ATT_READ_RSP ) || ........)
添加
else if ( ( pMsg->method == ATT_HANDLE_VALUE_NOTI ) ||......)

你可能感兴趣的:(BLE,notification,BLE)