-----------------------------------------------------------------------------------simple_gatt_profile.c
uint16_t GATTServApp_FindCharhandle( gattAttribute_t *pAttrTbl,
uint16 numAttrs, uint16 uuid )
{
uint16 i;
uint8 charuuid[ATT_BT_UUID_SIZE] =
{
LO_UINT16(uuid), HI_UINT16(uuid)
};
for ( i = 0; i < numAttrs; i++ )
{
if(memcmp(pAttrTbl[i].type.uuid,charuuid,sizeof(charuuid)) == 0)
{
return ( pAttrTbl[i].handle );
}
}
return ( 0 );
}
bStatus_t ServApp_SendNotiInd( uint8_t *nvalue,uint16_t nlen,uint16_t char_uuid)
{
attHandleValueNoti_t noti;
uint16_t slen;
bStatus_t status = FAILURE;
slen = nlen;
uint16 notify_Handle;
GAPRole_GetParameter(GAPROLE_CONNHANDLE,¬ify_Handle); //获取当前连接的handle
if ( notify_Handle != INVALID_CONNHANDLE )
{
noti.pValue = (uint8 *)GATT_bm_alloc( notify_Handle, ATT_HANDLE_VALUE_NOTI,slen,&slen);
if ( noti.pValue != NULL )
{
noti.handle = GATTServApp_FindCharhandle(simpleProfileAttrTbl,GATT_NUM_ATTRS( simpleProfileAttrTbl ),char_uuid);
noti.len = slen;
memcpy(noti.pValue, nvalue, slen);
if(noti.handle != 0)
{
status = GATT_Notification( notify_Handle, ¬i, FALSE );
}
if ( status != SUCCESS )
{
GATT_bm_free( (gattMsg_t *)¬i, ATT_HANDLE_VALUE_NOTI );
}
}
else
{
GATT_bm_free( (gattMsg_t *)¬i, ATT_HANDLE_VALUE_NOTI );
status = bleNoResources;
}
}
return ( status );
}
-----------------------------------------------------------------------------------simple_gatt_profile.h
extern bStatus_t CoolBan_SendNotiInd_Char4( uint8 *nvalue,uint8 nlen); // add
-----------------------------------------------------------------------------------simple_peripheral.
static void SimpleBLEPeripheral_performPeriodicTask(void) // event= SBP_PERIODIC_EVT period= SBP_PERIODIC_EVT_PERIOD
{
bStatus_t ret;
static uint8 Txbuf[300]= {0};
static uint8 TxLen = 10;
uint8 i = 0;
for(i = 0; i < 0xFF ;i++){
Txbuf[i] = i;
}
ret = CoolBan_SendNotiInd_Char4( Txbuf,TxLen);
if(ret == SUCCESS){
}else{
}
}