使用CH579做低功耗藍(lán)牙主機(jī)。在主機(jī)例程中,獲取特征值句柄的代碼如下:
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?);? ????????????} ????????}
我模仿主機(jī)例程,新增了一個(gè)服務(wù)表,特征值均采用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?);? ????????????} ????????}
為什么???