CC2540 如何连续读取characteristic的handle?
时间:10-02
整理:3721RD
点击:
在一个服务里面定义了4个char,每个都有read权限,在central代码里测试了下,发现只有第一个跟第三个的char可以读,第二个第四个读不到信息,若循环读取同一个char,则是一次能读到则下一次不能读到,这样看来是无法连续读取两个handle?请问下是否是连续读取时有何讲究或者判断条件有问题?
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 ( ( 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_CHAR1; req.startHandle = simpleBLESvcStartHdl; req.endHandle = simpleBLESvcEndHdl; req.type.len = ATT_BT_UUID_SIZE; req.type.uuid[0] = LO_UINT16(CHAR1_UUID); req.type.uuid[1] = HI_UINT16(CHAR1_UUID); GATT_ReadUsingCharUUID( simpleBLEConnHandle, &req, simpleBLETaskId ); LCD_WRITE_STRING( "GATT_Read CHAR1_UUID\r\n", HAL_LCD_LINE_1 ); } } } else if ( simpleBLEDiscState == BLE_DISC_STATE_CHAR1 ) { // Tel number found, store handle if ( ( pMsg->method == ATT_READ_BY_TYPE_RSP && pMsg->hdr.status == bleProcedureComplete ) || pMsg->msg.readByTypeRsp.numPairs > 0 ) { if ( simpleBLESvcStartHdl != 0 ) { TelNumCharHdl = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[0], pMsg->msg.readByTypeRsp.dataList[1] ); LCD_WRITE_STRING( "BLE_DISC_STATE_CHAR1 Found:", HAL_LCD_LINE_1 ); simpleBLEDiscState = BLE_DISC_STATE_CHAR2; req.startHandle = simpleBLESvcStartHdl; req.endHandle = simpleBLESvcEndHdl; req.type.len = ATT_BT_UUID_SIZE; req.type.uuid[0] = LO_UINT16(CHAR2_UUID); req.type.uuid[1] = HI_UINT16(CHAR2_UUID); GATT_ReadUsingCharUUID( simpleBLEConnHandle, &req, simpleBLETaskId ); LCD_WRITE_STRING( "GATT_Read CHAR2\r\n", HAL_LCD_LINE_1 ); } } } else if ( simpleBLEDiscState == BLE_DISC_STATE_CHAR2 ) { if ( ( pMsg->method == ATT_READ_BY_TYPE_RSP && pMsg->hdr.status == bleProcedureComplete ) || pMsg->msg.readByTypeRsp.numPairs > 0 ) { if ( simpleBLESvcStartHdl != 0 ) { TelNumCharHdl = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[0], pMsg->msg.readByTypeRsp.dataList[1] ); LCD_WRITE_STRING( "BLE_DISC_STATE_CHAR2 Found:", HAL_LCD_LINE_1 ); simpleBLEDiscState = BLE_DISC_STATE_CHAR3; req.startHandle = simpleBLESvcStartHdl; req.endHandle = simpleBLESvcEndHdl; req.type.len = ATT_BT_UUID_SIZE; req.type.uuid[0] = LO_UINT16(CHAR3_UUID); req.type.uuid[1] = HI_UINT16(CHAR3_UUID); GATT_ReadUsingCharUUID( simpleBLEConnHandle, &req, simpleBLETaskId ); LCD_WRITE_STRING( "GATT_Read CHAR3\r\n", HAL_LCD_LINE_1 ); } } } else if ( simpleBLEDiscState == BLE_DISC_STATE_CHAR3 ) { if ( ( pMsg->method == ATT_READ_BY_TYPE_RSP && pMsg->hdr.status == bleProcedureComplete ) || pMsg->msg.readByTypeRsp.numPairs > 0 ) { if ( simpleBLESvcStartHdl != 0 ) { TelNumCharHdl = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[0], pMsg->msg.readByTypeRsp.dataList[1] ); LCD_WRITE_STRING( "BLE_DISC_STATE_CHAR3 Found:", HAL_LCD_LINE_1 ); simpleBLEDiscState = BLE_DISC_STATE_CHAR4; req.startHandle = simpleBLESvcStartHdl; req.endHandle = simpleBLESvcEndHdl; req.type.len = ATT_BT_UUID_SIZE; req.type.uuid[0] = LO_UINT16(CHAR4_UUID); req.type.uuid[1] = HI_UINT16(CHAR4_UUID); GATT_ReadUsingCharUUID( simpleBLEConnHandle, &req, simpleBLETaskId ); LCD_WRITE_STRING( "GATT_Read CHAR4\r\n", HAL_LCD_LINE_1 ); } } } else if ( simpleBLEDiscState == BLE_DISC_STATE_CHAR4 ) { // Tel number found, store handle if ( ( pMsg->method == ATT_READ_BY_TYPE_RSP && pMsg->hdr.status == bleProcedureComplete ) || pMsg->msg.readByTypeRsp.numPairs > 0 ) { if ( simpleBLESvcStartHdl != 0 ) { TelNumCharHdl = BUILD_UINT16( pMsg->msg.readByTypeRsp.dataList[0], pMsg->msg.readByTypeRsp.dataList[1] ); LCD_WRITE_STRING( "BLE_DISC_STATE_CHAR4 Found:", HAL_LCD_LINE_1 ); } } simpleBLEDiscState = BLE_DISC_STATE_IDLE; } }
感觉这样不行啊
一个服务里面四个char肯定是可以单独操作的
首先检查一下代码为什么只有其中两个可以读
看看回调函数里面是不是也修改了