TI中文支持网
TI专业的中文技术问题搜集分享网站

怎么获取多个特征值的句柄?

各位好!

比如,主从机连接后,想要实现,按UP键读写特征值1;按Down键读取特征值6。

在simpleBLEGATTDiscoveryEvent里面,

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);
//hc: To discover the characteristic 6 req_char6.startHandle = simpleBLESvcStartHdl;
req_char6.endHandle = simpleBLESvcEndHdl;
req_char6.type.len = ATT_BT_UUID_SIZE;
req_char6.type.uuid[0] = LO_UINT16(SIMPLEPROFILE_CHAR6_UUID);
req_char6.type.uuid[1] = HI_UINT16(SIMPLEPROFILE_CHAR6_UUID);
GATT_ReadUsingCharUUID( simpleBLEConnHandle, &req, simpleBLETaskId );
GATT_ReadUsingCharUUID( simpleBLEConnHandle, &req_char6, simpleBLETaskId );

else if ( simpleBLEDiscState == BLE_DISC_STATE_CHAR )
{
// 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] );

HalLcdWriteStringValue("numPairs=",pMsg->msg.readByTypeRsp.numPairs,10,HAL_LCD_LINE_5);
HalLcdWriteStringValue("len=",pMsg->msg.readByTypeRsp.len,10,HAL_LCD_LINE_6);
HalLcdWriteStringValueValue(" dataList",pMsg->msg.readByTypeRsp.dataList[0],16,pMsg->msg.readByTypeRsp.dataList[1],16,HAL_LCD_LINE_7);
LCD_WRITE_STRING( "Simple Svc Found", HAL_LCD_LINE_3 );
simpleBLEProcedureInProgress = FALSE;
}

1、发现numPairs一直是1

2、GATT_ReadUsingCharUUID( simpleBLEConnHandle, &req, simpleBLETaskId );函数的具体作用。如果传递的是req,则len=3;如果是req_char6,则len=7;为什么?

typedef struct
{
uint8 numPairs; //!< Number of attribute handle-UUID pairs found
uint8 len; //!< Size of each attribute handle-value pair
uint8 dataList[ATT_MTU_SIZE-2]; //!< List of 1 or more attribute handle-value pairs
} attReadByTypeRsp_t;

You You:

怎么没人????

You You:

这样做为什么不行?得到的特征值1的句柄是25,对;特征值6的句柄是250,是错的。

static void simpleBLEGATTDiscoveryEvent( gattMsgEvent_t *pMsg ){ attReadByTypeReq_t req; attReadByTypeReq_t req_char6; if ( simpleBLEDiscState == BLE_DISC_STATE_SVC ) { // Service found, store handles if ( pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP && pMsg->msg.findByTypeValueRsp.numInfo > 0 ) { simpleBLESvcStartHdl = pMsg->msg.findByTypeValueRsp.handlesInfo[0].handle; simpleBLESvcEndHdl = pMsg->msg.findByTypeValueRsp.handlesInfo[0].grpEndHandle; simpleBLESvcStartHdl6 = pMsg->msg.findByTypeValueRsp.handlesInfo[1].handle; simpleBLESvcEndHdl6 = pMsg->msg.findByTypeValueRsp.handlesInfo[1].grpEndHandle; } // 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); req_char6.startHandle = simpleBLESvcStartHdl6; req_char6.endHandle = simpleBLESvcEndHdl6; req_char6.type.len = ATT_BT_UUID_SIZE; req_char6.type.uuid[0] = LO_UINT16(SIMPLEPROFILE_CHAR6_UUID); req_char6.type.uuid[1] = HI_UINT16(SIMPLEPROFILE_CHAR6_UUID); GATT_ReadUsingCharUUID( simpleBLEConnHandle, &req, simpleBLETaskId ); GATT_ReadUsingCharUUID( simpleBLEConnHandle, &req_char6, simpleBLETaskId ); } } } else if ( simpleBLEDiscState == BLE_DISC_STATE_CHAR ) { // 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] ); simpleBLECharHdl6 = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[2], pMsg->msg.readByTypeRsp.dataList[3] ); HalLcdWriteStringValue("CharHdl:",simpleBLECharHdl,16,HAL_LCD_LINE_4); HalLcdWriteStringValue("CharHdl6:",simpleBLECharHdl6,16,HAL_LCD_LINE_5); HalLcdWriteStringValue("numPairs=",pMsg->msg.readByTypeRsp.numPairs,10,HAL_LCD_LINE_6); HalLcdWriteStringValue("len=",pMsg->msg.readByTypeRsp.len,10,HAL_LCD_LINE_7); HalLcdWriteStringValueValue("dL",pMsg->msg.readByTypeRsp.dataList[2],16,pMsg->msg.readByTypeRsp.dataList[3],16,HAL_LCD_LINE_8); LCD_WRITE_STRING( "Simple Svc Found", HAL_LCD_LINE_3 ); simpleBLEProcedureInProgress = FALSE; } simpleBLEDiscState = BLE_DISC_STATE_IDLE; } }

Fred Wang:

回复 You You:

首先使用GATT_DiscAllChars函数启动扫描,然后就可以在*pDiscState == BLE_DISC_STATE_CHAR的中断中得到msg.readByTypeRsp,里面包含有扫描到的特征值的handle,缓存起来就可以进行读写操作了。

You You:

回复 Fred Wang:

谢谢!

还有几个问题想请教一下:

1、GATT_DiscAllChars函数在哪里调用?

2、msg.readByTypeRsp里面是不是dataList[]存储了特征值的handle?

3、特征值1和特征值5分别对应dataList的第几个元素?

simpleBLECharHdl = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[0], pMsg->msg.readByTypeRsp.dataList[1] );

4、GATT_ReadUsingCharUUID函数的作用?

如果 GATT_ReadUsingCharUUID( simpleBLEConnHandle, &req, simpleBLETaskId );

主机程序里面dataList[0]、dataList[1]就对应特征值1的handle

You You:

回复 Fred Wang:

Hi,Fred

我按照你的方法,调用GATT_DiscAllChars启动扫描,在BLE_DISC_STATE_CHAR里面

打印出来

pMsg->msg.readByTypeRsp.numPairs为1

pMsg->msg.readByTypeRsp.dataList[0]       25

pMsg->msg.readByTypeRsp.dataList[1]       0

下面依次为01,02,00,00,3E,00

还是只有特征值1的句柄

CQ JiMi:

回复 Fred Wang:

能不能在详细点呢

CQ JiMi:

回复 You You:

你好You You,你的这段代码

{
simpleBLESvcStartHdl = pMsg->msg.findByTypeValueRsp.handlesInfo[0].handle;
simpleBLESvcEndHdl = pMsg->msg.findByTypeValueRsp.handlesInfo[0].grpEndHandle;
simpleBLESvcStartHdl6 = pMsg->msg.findByTypeValueRsp.handlesInfo[1].handle;
simpleBLESvcEndHdl6 = pMsg->msg.findByTypeValueRsp.handlesInfo[1].grpEndHandle;
}

特征值1和特征值6获取的是服务开始句柄和结束句柄是一样的吧。。因为char1和char6都是同属于一个服务下。服务句柄区间应该包含了char1和char6的句柄。

shuzhou wong:

回复 Fred Wang:

dearFred:

       我已经获得了特征值1的句柄0x25,但是在使用句柄读取特征值的时候GATT_ReadCharValue函数返回值却是0x16,意思是在等待,不知道这是怎么回事,你有遇到过或者知道怎么回事吗?

谢谢!

赞(0)
未经允许不得转载:TI中文支持网 » 怎么获取多个特征值的句柄?
分享到: 更多 (0)