微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > TI蓝牙设计交流 > 关于主机去读取notify

关于主机去读取notify

时间:10-02 整理:3721RD 点击:

现有一款蓝牙温度计(ifever),有电量服务,连接状态,温度。用GATT_ReadCharValue读出了电量和连接状态,温度的数据用GATT_ReadCharValue没读出来,在lightblue中点击Listen for otifications 会不停地显示Characteristic Notified (0x4800C00FE2C),像这样的notify主机应该如何读取,还请告知,谢谢。

主机用的是CC2541

如下述代码所示,加入处理notify和indicate的分支

else if ( pMsg->method == ATT_HANDLE_VALUE_NOTI ||
pMsg->method == ATT_HANDLE_VALUE_IND )

static void simpleBLECentralProcessGATTMsg( gattMsgEvent_t *pMsg )
{
  if ( simpleBLEState != BLE_STATE_CONNECTED )
  {
    // In case a GATT message came after a connection has dropped,
    // ignore the message
    return;
  }
  
  if ( ( pMsg->method == ATT_READ_RSP ) ||
       ( ( pMsg->method == ATT_ERROR_RSP ) &&
         ( pMsg->msg.errorRsp.reqOpcode == ATT_READ_REQ ) ) )
  {
    if ( pMsg->method == ATT_ERROR_RSP )
    {
      uint8 status = pMsg->msg.errorRsp.errCode;
      
      //LCD_WRITE_STRING_VALUE( "Read Error", status, 10, HAL_LCD_LINE_1 );
    }
    else
    {
      // After a successful read, display the read value
      uint8 valueRead = pMsg->msg.readRsp.value[0];

      //LCD_WRITE_STRING_VALUE( "Read rsp:", valueRead, 10, HAL_LCD_LINE_1 );
    }
    
    simpleBLEProcedureInProgress = FALSE;
  }
  else if ( ( pMsg->method == ATT_WRITE_RSP ) ||
       ( ( pMsg->method == ATT_ERROR_RSP ) &&
         ( pMsg->msg.errorRsp.reqOpcode == ATT_WRITE_REQ ) ) )
  {
    
    if ( pMsg->method == ATT_ERROR_RSP == ATT_ERROR_RSP )
    {
      uint8 status = pMsg->msg.errorRsp.errCode;
      
      //LCD_WRITE_STRING_VALUE( "Write Error", status, 10, HAL_LCD_LINE_1 );
    }
    else
    {
      // After a succesful write, display the value that was written and increment value
      //LCD_WRITE_STRING_VALUE( "Write sent:", simpleBLECharVal++, 10, HAL_LCD_LINE_1 );
    }
    
    simpleBLEProcedureInProgress = FALSE;    

  }
  else if ( pMsg->method == ATT_HANDLE_VALUE_NOTI ||
       pMsg->method == ATT_HANDLE_VALUE_IND )
  {
    
    if(pMsg->msg.handleValueNoti.handle == 0x001B)
    {
        //在此处处理notify,注意对应的handle替换成正确的值
    }
    else if(pMsg->msg.handleValueInd.handle == 0x001F)
    {     
        //在此处处理indicate,注意对应的handle替换成正确的值
        ATT_HandleValueCfm(simpleBLEConnHandle);
      
    }
    
  }  
  else if ( simpleBLEDiscState != BLE_DISC_STATE_IDLE )
  {
    simpleBLEGATTDiscoveryEvent( pMsg );
  }
  
}

问题解决了,非常感谢~

请问一下,为什么会这样呢?

还有个问题咨询下,主机通过从机notify对应的handle+1  去写入0x0001打开notify,这个是协议规定的还是可以随意修改的?

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top