CH579主機(jī)GATT_ReadUsingCharUUID和GATT_DiscCharsByUUID的區(qū)別是什么?

使用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?);?
????????????}
????????}

為什么???

如果按照主機(jī)程序的流程會先發(fā)現(xiàn)handle的范圍,同時(shí)已知UUID,因此可以DiscCharsByUUID,且我們自己在進(jìn)行藍(lán)牙連接和透傳數(shù)據(jù)時(shí)是會修改為這個(gè)的。設(shè)置為ReadUsingCharUUID是已知UUID就可以了。


@TECH_Lpc:

你沒認(rèn)真審我的題呀~

DiscCharsByUUID和ReadUsingCharUUID都是在獲取到service范圍,且已知uuid的情況,同時(shí)他們的參數(shù)都是一樣的。


我按照主機(jī)例程使用ReadUsingCharUUID可以讀出來特征,但是我新增服務(wù)表,卻只能用DiscCharsByUUID。為什么呢?



檢查一下你的LED_CHAR2_UUID是否帶有讀屬性,如果不帶有讀屬性那就使用DiscCharsByUUID,如果帶有讀屬性嘗試使用ReadUsingCharUUID,可以進(jìn)行驗(yàn)證,如驗(yàn)證現(xiàn)象不符合我們這里會進(jìn)一步驗(yàn)證。



@TECH_Lpc

按照你四樓的回復(fù)。還是不行。我描述下我的測試過程。


1,我的服務(wù)表如下:

static?gattAttribute_t?tempProfileAttrTbl[]?=
{
????//?Temp?Profile?服務(wù)
????{
????????{?ATT_BT_UUID_SIZE,?primaryServiceUUID?},?/*?type?*/
????????GATT_PERMIT_READ,?????????????????????????/*?permissions?*/
????????0,????????????????????????????????????????/*?handle?*/
????????(uint8?*)&tempProfileService????????????/*?pValue?*/
????},

???
???
??????//?Characteristic?2?Declaration
??????(省略不寫,notify類型)
?????
???
????//?Characteristic?3?Declaration
????{
????????{?ATT_BT_UUID_SIZE,?characterUUID?},
????????GATT_PERMIT_READ,
????????0,
????????&tempProfileChar3Props?
????},

??????//?Characteristic?Value?3
????{
????????{?ATT_UUID_SIZE,?tempProfilechar3UUID?},
????????GATT_PERMIT_READ?|?GATT_PERMIT_WRITE,
????????0,
????????tempProfileChar3?
????},

??????//?Characteristic?3?User?Description
??????{
????????{?ATT_BT_UUID_SIZE,?charUserDescUUID?},
????????GATT_PERMIT_READ,
????????0,
????????tempProfileChar3UserDesp?
??????},

????//?Characteristic?4?Declaration
????(省略不寫,notify類型)

?
};

2,tempProfileChar3Props定義為:

static?uint8?tempProfileChar3Props?=?GATT_PROP_WRITE?|?GATT_PROP_READ;


3,獲取屬性特征值:

?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;
#if?1
????????????????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);
#else
????????????????//?Characteristic?1?UUID:?0xF002
????????????????uint8?uuidx[ATT_UUID_SIZE]?=
????????????????{?
????????????????????0xFB,0x34,0x9B,0x5f,0x80,0,0,0x80,0,0x10,0,0,
????????????????????LO_UINT16(TEMPPROFILE_CHAR3_UUID),?HI_UINT16(TEMPPROFILE_CHAR3_UUID),
????????????????????0,0,
????????????????};
????????????????tmos_memcpy(req.type.uuid,?uuidx,?ATT_UUID_SIZE);?????????
#endif
????????????????GATT_ReadUsingCharUUID(?centralConnHandle,?&req,?centralTaskId?);
????????????????//GATT_DiscCharsByUUID(?centralConnHandle,?&req,?centralTaskId?);
????????????}
????????}

4,結(jié)果如下,可以看到,沒有找到特征值句柄,沒有打印

Found Characteristic 1 handle :

Param?Update...
Conn?1?-?Int?60?
Found?Profile?Service?handle?:?e?~?ffff?
numPairs?=?2,?cccdX?[0]?=?12
numPairs?=?2,?cccdX?[1]?=?18
Found?client?characteristic?configuration?handle?:?18?
numPairs?=?2
Write?success

Char2和char4 是notify。即,cccdx0和cccdx1



5,另外我想描述下這里和主機(jī)的一個(gè)區(qū)別點(diǎn),這里的tempProfilechar3UUID是16otc。

不知道獲取特征值句柄,是不是也需要傳入16otc


如果是為了將通道3設(shè)置為具有讀寫功能的,可以直接參考peripheral例程里的通道1的設(shè)置;設(shè)置非通道4具有noti功能,可以先簡單的設(shè)置通道4的noti切換為如通道2的noti,然后再進(jìn)行添加相應(yīng)的noti 功能。

這里建議發(fā)送郵件至郵箱lpc@wch.cn,描述一下具體需求和發(fā)送相應(yīng)的工程,我們這里進(jìn)行查看驗(yàn)證。


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频