WCH官方你們好!我現(xiàn)在是想要在 peripheral 案例上稍作修改,借此學(xué)習(xí)下你們這套藍(lán)牙庫,隨后我再繼續(xù)開發(fā)實(shí)現(xiàn)自己需要的功能。
--------------------------------- 問題1 ---------------------------------
我想要在 Characteristic 5 后面添加一個(gè) My Characteristic,也就是第六個(gè) Characteristic,我是這么寫的:
首先是 gattprofile.c 這個(gè)文件,有這么一段代碼:
static?gattAttribute_t?simpleProfileAttrTbl[]?=?{ ????//?Simple?Profile?Service ????{ ????????{ATT_BT_UUID_SIZE,?primaryServiceUUID},?/*?type?*/ ????????GATT_PERMIT_READ,?????????????/*?permissions?*/ ????????0,?????????????????????/*?handle?*/ ????????(uint8_t?*)&simpleProfileService??????/*?pValue?*/ ????},
這段代碼里面就是 GATT 的定義了,我在這段代碼的上面添加了CHAR的UUID,讀寫屬性,Value,User Desp。我是這么改的:
//?****************************************?MY?CODE?BEGIN?****************************************?// #define?MY_CHAR_UUID?0x8888 const?uint8_t?MyCharUUID[ATT_BT_UUID_SIZE]?=?{ ????LO_UINT16(MY_CHAR_UUID),?HI_UINT16(MY_CHAR_UUID) }; static?uint8_t?MyCharProps?=?GATT_PROP_READ; const?uint8_t?MyCharValue[4]?=?{ ????0x01,?0x02,?0x03,?0x04 }; static?uint8_t?MyCharValueUserDesp[]?=?"MyCharValueUserDesp\0"; //?****************************************?MY?CODE?END?****************************************?// static?gattAttribute_t?simpleProfileAttrTbl[]?=?{ ????//?Simple?Profile?Service ????{ ????????{ATT_BT_UUID_SIZE,?primaryServiceUUID},?/*?type?*/ ????????GATT_PERMIT_READ,???????????????????????/*?permissions?*/ ????????0,??????????????????????????????????????/*?handle?*/ ????????(uint8_t?*)&simpleProfileService????????/*?pValue?*/ ????},
隨后在 simpleProfileAttrTbl[] 的最后,我又添加了這么一段代碼:
????//?Characteristic?5?User?Description ????{ ????????{ATT_BT_UUID_SIZE,?charUserDescUUID}, ????????GATT_PERMIT_READ, ????????0, ????????simpleProfileChar5UserDesp}, ????//?****************************************?MY?CODE?BEGIN?****************************************?// ????//?My?Characteristic?Declaration ????{ ????????{ATT_BT_UUID_SIZE,?characterUUID}, ????????GATT_PERMIT_READ, ????????0, ????????&MyCharProps}, ????//?My?Characteristic?Value ????{ ????????{ATT_BT_UUID_SIZE,?MyCharUUID}, ????????GATT_PERMIT_READ, ????????0, ????????(uint8_t*)MyCharValue}, ????//?My?Characteristic?User?Desc ????{ ????????{ATT_BT_UUID_SIZE,?charUserDescUUID}, ????????GATT_PERMIT_READ, ????????0, ????????MyCharValueUserDesp}, ????//?****************************************?MY?CODE?END?****************************************?// };
經(jīng)過手機(jī)端的藍(lán)牙調(diào)試助手,以及 nRF Connect 這兩款軟件測試,User Desp 的值都是可以取出來的,但是 “My Characteristic Value”的值(即 0x01,0x02,0x03,0x04)卻無論如何都取不出來,請問我還少寫了什么?
--------------------------------- 問題2 ---------------------------------
此外,我還有一個(gè)別的問題:
我在 peripheral 案例中的 “void Peripheral_Init()”函數(shù)中,找到了這么一段代碼,如果我沒有理解錯(cuò)誤的話,這應(yīng)該就是給每個(gè) Characteristic 的 Value 賦予初值。
????//?Setup?the?SimpleProfile?Characteristic?Values ????{ ????????uint8_t?charValue1[SIMPLEPROFILE_CHAR1_LEN]?=?{1}; ????????uint8_t?charValue2[SIMPLEPROFILE_CHAR2_LEN]?=?{2}; ????????uint8_t?charValue3[SIMPLEPROFILE_CHAR3_LEN]?=?{3}; ????????uint8_t?charValue4[SIMPLEPROFILE_CHAR4_LEN]?=?{4}; ????????uint8_t?charValue5[SIMPLEPROFILE_CHAR5_LEN]?=?{1,?2,?3,?4,?5}; ????????SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR1,?SIMPLEPROFILE_CHAR1_LEN,?charValue1); ????????SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR2,?SIMPLEPROFILE_CHAR2_LEN,?charValue2); ????????SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR3,?SIMPLEPROFILE_CHAR3_LEN,?charValue3); ????????SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR4,?SIMPLEPROFILE_CHAR4_LEN,?charValue4); ????????SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR5,?SIMPLEPROFILE_CHAR5_LEN,?charValue5); ????}
但是,當(dāng)我打開 HID_Keyboard 案例后,我發(fā)現(xiàn)在 HID_Keyboard 案例中,并沒有為 BLE HID Service 的每個(gè)字段都調(diào)用 HidDev_SetParameter() 或 Hid_SetParameter()。
請問這是為什么?
--------------------------------- 問題3 ---------------------------------
請問:
SimpleProfile_SetParameter 和 simpleProfile_WriteAttrCB 有什么區(qū)別?為什么要分成這兩個(gè)函數(shù)呢?