CC2640R2F 添加notify 接口


-----------------------------------------------------------------------------------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,&notify_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, &noti, FALSE );
          }


        if ( status != SUCCESS )
        {
          GATT_bm_free( (gattMsg_t *)&noti, ATT_HANDLE_VALUE_NOTI );
        }
      }
      else
      {
        GATT_bm_free( (gattMsg_t *)&noti, 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{
  }
}






评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值