Hi Yan,
我尝试了几次,然后用这种方法再次查找,终于发现了CHAR4的句柄,如下红色部分:
static void simpleBLECentralProcessGATTMsg( gattMsgEvent_t *pMsg )
[
……
else if ( simpleBLEDiscState != BLE_DISC_STATE_IDLE )
[
simpleBLEGATTDiscoveryEvent( pMsg );
/*=====================================================*/
simpleBLEGATTDiscoveryEvent( pMsg ); //再次执行
/*=====================================================*/
]
]
static void simpleBLEGATTDiscoveryEvent( gattMsgEvent_t *pMsg )
[
attReadByTypeReq_t req;
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;
]
// 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 )
[
// 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;
]
// simpleBLEDiscState = BLE_DISC_STATE_IDLE;
//]
/*================================================================================*/
if ( simpleBLESvcStartHdl != 0 )
[
// Discover characteristic
simpleBLEDiscState = BLE_DISC_STATE_CHAR4;
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_CHAR4 )
[
// Characteristic found, store handle
if ( pMsg->method == ATT_READ_BY_TYPE_RSP &&
pMsg->msg.readByTypeRsp.numPairs > 0 )
[
simpleBLECharHd4 = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[0],
pMsg->msg.readByTypeRsp.dataList[1] );
LCD_WRITE_STRING( "Simple Svc Found", HAL_LCD_LINE_1 );
simpleBLEProcedureInProgress = FALSE;
]
simpleBLEDiscState = BLE_DISC_STATE_IDLE;
]
/*================================================================================*/
]
在线调试可以看到CHAR4的句柄:simpleBLECharHd4 =0x0025;
但是我感觉这样写的程序比较纠结、不顺眼,如下:
else if ( simpleBLEDiscState != BLE_DISC_STATE_IDLE )
[
simpleBLEGATTDiscoveryEvent( pMsg );
/*=====================================================*/
simpleBLEGATTDiscoveryEvent( pMsg ); //再次执行
/*=====================================================*/
]
执行一次,再执行一次一样的函数,感觉非常的2,还有没有更好的方法?
谢谢!