微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > TI蓝牙设计交流 > central中用GATT_ReadUsingCharUUID获取characteristic句柄,读取不到

central中用GATT_ReadUsingCharUUID获取characteristic句柄,读取不到

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

// If procedure complete
if ( ( pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP &&
pMsg->hdr.status == bleProcedureComplete ) ||
( pMsg->method == ATT_ERROR_RSP ) )
{
if ( simpleBLESvcStartHdl != 0 )
{
// Discover characteristic
simpleBLEDiscState = BLE_DISC_STATE_CHAR;

req.startHandle = simpleBLESvcStartHdl;
req.endHandle = simpleBLESvcEndHdl;
req.type.len = ATT_BT_UUID_SIZE;
req.type.uuid[0] = LO_UINT16(SIMPLEPROFILE_CHAR1_UUID);
req.type.uuid[1] = HI_UINT16(SIMPLEPROFILE_CHAR1_UUID);

GATT_ReadUsingCharUUID( simpleBLEConnHandle, &req, simpleBLETaskId );}

}

}
else if ( simpleBLEDiscState == BLE_DISC_STATE_CHAR )
{
sprintf(charBuf,"%x,%d\r\n", pMsg->method, pMsg->msg.readByTypeRsp.numPairs);
ComPrint(charBuf);

// Characteristic found, store handle
if ( pMsg->method == ATT_READ_BY_TYPE_RSP &&
pMsg->msg.readByTypeRsp.numPairs > 0 )
{
simpleBLECharHdl = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[0],
pMsg->msg.readByTypeRsp.dataList[1] );


LCD_WRITE_STRING( "Simple Svc Found", HAL_LCD_LINE_1 );
simpleBLEProcedureInProgress = FALSE;
}

原来代码中是读SIMPLEPROFILE_CHAR1_UUID的句柄,没有问题。当我把它改为SIMPLEPROFILE_CHAR4_UUID时,读取就失败。

// If procedure complete
if ( ( pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP && 
pMsg->hdr.status == bleProcedureComplete ) ||
( pMsg->method == ATT_ERROR_RSP ) )
{
if ( simpleBLESvcStartHdl != 0 )
{
// Discover characteristic
simpleBLEDiscState = BLE_DISC_STATE_CHAR;

req.startHandle = simpleBLESvcStartHdl;
req.endHandle = simpleBLESvcEndHdl;
req.type.len = ATT_BT_UUID_SIZE;
req.type.uuid[0] = LO_UINT16(SIMPLEPROFILE_CHAR4_UUID);
req.type.uuid[1] = HI_UINT16(SIMPLEPROFILE_CHAR4_UUID);

GATT_ReadUsingCharUUID( simpleBLEConnHandle, &req, simpleBLETaskId );}

}

}
else if ( simpleBLEDiscState == BLE_DISC_STATE_CHAR )
{
sprintf(charBuf,"%x,%d\r\n", pMsg->method, pMsg->msg.readByTypeRsp.numPairs); 
ComPrint(charBuf);

// Characteristic found, store handle
if ( pMsg->method == ATT_READ_BY_TYPE_RSP && 
pMsg->msg.readByTypeRsp.numPairs > 0 )
{
simpleBLECharHdl = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[0],
pMsg->msg.readByTypeRsp.dataList[1] );


LCD_WRITE_STRING( "Simple Svc Found", HAL_LCD_LINE_1 );
simpleBLEProcedureInProgress = FALSE;
}

pMsg->method 看了一下,是ATT_ERROR_RSP。但是上面的例子用GATT_DiscCharsByUUID 读取就能读到句柄。

还有,我一个service明明6个characteristics,使用GATT_DiscAllChars 来获取只返回3个,这些接口英文描述的不是很容易懂啊。能否麻烦解释一下啊。多谢了。

杰克,

GATT_ReadUsingCharUUID() 这个函数,不是用来读取句柄,是通过UUID读取对应的characteristic 的 值。你调用这个函数,就是去读CHAR4的值了,并不是去获取句柄。CHAR4 为什么读不到?因为CHAR4的属性只是notify,并没有被读的属性,换句话说就是禁止被读,所以会返回错误。

GATT_DiscAllChars ()调用后只返回了一次吗?

hi yan!

    看函数名GATT_ReadUsingCharUUID() 这个函数确实是读取characteristic 的 值,但是,看下面的代码

// Characteristic found, store handle
if ( pMsg->method == ATT_READ_BY_TYPE_RSP && 
pMsg->msg.readByTypeRsp.numPairs > 0 )
{
simpleBLECharHdl = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[0],
pMsg->msg.readByTypeRsp.dataList[1] );


LCD_WRITE_STRING( "Simple Svc Found", HAL_LCD_LINE_1 );
simpleBLEProcedureInProgress = FALSE;
}

表明GATT_ReadUsingCharUUID()读的是一个句柄,并不是value。

GATT_DiscCharsByUUID读到的句柄,比GATT_ReadUsingCharUUID()读到的句柄小1。 我的理解是,GATT_DiscCharsByUUID读到的是characteristic的句柄,而GATT_ReadUsingCharUUID()读到的是characteristic value的句柄。由于一个characteristic定义是由:characteristic declaration,characteristic value,characteristic configuration组成。所以GATT_DiscCharsByUUID读到的比GATT_ReadUsingCharUUID()小1。但是为什么GATT_ReadUsingCharUUID()读notify的value句柄就读不到呢?

GATT_DiscAllChars ()调用后真的只返回了一次。6个特性只返回了3个uuid。也不知道为什么。

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

网站地图

Top