使用CH579做低功耗蓝牙主机。在主机例程中,获取特征值句柄的代码如下:
if ( ( pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP && pMsg->hdr.status == bleProcedureComplete ) || ( pMsg->method == ATT_ERROR_RSP ) ) { if ( centralSvcStartHdl != 0 ) { // Discover characteristic centralDiscState = BLE_DISC_STATE_CHAR; req.startHandle = centralSvcStartHdl; req.endHandle = centralSvcEndHdl; req.type.len = ATT_BT_UUID_SIZE; req.type.uuid[0] = LO_UINT16(TEMPPROFILE_CHAR3_UUID); req.type.uuid[1] = HI_UINT16(TEMPPROFILE_CHAR3_UUID); GATT_ReadUsingCharUUID( centralConnHandle, &req, centralTaskId ); } }
我模仿主机例程,新增了一个服务表,特征值均采用16oct,然而无法获取到特征值句柄,代码如下:
if ( ( pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP && pMsg->hdr.status == bleProcedureComplete ) || ( pMsg->method == ATT_ERROR_RSP ) ) { if ( centralSvcStartHdl != 0 ) { // Discover characteristic centralDiscState = BLE_DISC_STATE_CHAR; req.startHandle = centralSvcStartHdl; req.endHandle = centralSvcEndHdl; req.type.len = ATT_BT_UUID_SIZE; req.type.uuid[0] = LO_UINT16(LED_CHAR2_UUID); req.type.uuid[1] = HI_UINT16(LED_CHAR2_UUID); GATT_ReadUsingCharUUID( centralConnHandle, &req, centralTaskId ); } }
但是,如果使用如下代码,只换了GATT_DiscCharsByUUID就可以了:
if ( ( pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP && pMsg->hdr.status == bleProcedureComplete ) || ( pMsg->method == ATT_ERROR_RSP ) ) { if ( centralSvcStartHdl != 0 ) { // Discover characteristic centralDiscState = BLE_DISC_STATE_CHAR; req.startHandle = centralSvcStartHdl; req.endHandle = centralSvcEndHdl; req.type.len = ATT_BT_UUID_SIZE; req.type.uuid[0] = LO_UINT16(LED_CHAR2_UUID); req.type.uuid[1] = HI_UINT16(LED_CHAR2_UUID); GATT_DiscCharsByUUID( centralConnHandle, &req, centralTaskId ); } }
为什么啊?