在Peripheral例程中,有一個(gè)特征值(characteristic)使用了Notify,通過(guò)linkDB_Register注冊(cè)了一個(gè)回調(diào)函數(shù)用于重置CCCD的狀態(tài)。
????//?Register?with?Link?DB?to?receive?link?status?change?callback ????linkDB_Register(simpleProfile_HandleConnStatusCB); ? /*.........*/ static?void?simpleProfile_HandleConnStatusCB(uint16_t?connHandle,?uint8_t?changeType) { ????//?Make?sure?this?is?not?loopback?connection ????if(connHandle?!=?LOOPBACK_CONNHANDLE) ????{ ????????//?Reset?Client?Char?Config?if?connection?has?dropped ????????if((changeType?==?LINKDB_STATUS_UPDATE_REMOVED)?|| ???????????((changeType?==?LINKDB_STATUS_UPDATE_STATEFLAGS)?&& ????????????(!linkDB_Up(connHandle)))) ????????{ ????????????GATTServApp_InitCharCfg(connHandle,?simpleProfileChar4Config); ????????} ????} }
請(qǐng)問(wèn)如果有多個(gè)特征值需要使用Notify,他們不全在在同一個(gè)service中,但要實(shí)現(xiàn)和示例代碼一樣的自動(dòng)重置CCCD狀態(tài)的功能。該如何實(shí)現(xiàn)?linkDB_Register能注冊(cè)多個(gè)回調(diào)函數(shù)嗎?
還有另一個(gè)疑問(wèn),代碼出自同一個(gè)例程,請(qǐng)問(wèn)為什么GATT_bm_free只在失敗的情況下調(diào)用,成功的情況下不需要釋放嗎?
noti的pValue必須是GATT_bm_alloc分配出來(lái)的嗎?
static?void?peripheralChar4Notify(uint8_t?*pValue,?uint16_t?len) { ????attHandleValueNoti_t?noti; ????if(len?>?(peripheralMTU?-?3)) ????{ ????????PRINT("Too?large?noti\n"); ????????return; ????} ????noti.len?=?len; ????noti.pValue?=?GATT_bm_alloc(peripheralConnList.connHandle,?ATT_HANDLE_VALUE_NOTI,?noti.len,?NULL,?0); ????if(noti.pValue) ????{ ????????tmos_memcpy(noti.pValue,?pValue,?noti.len); ????????if(simpleProfile_Notify(peripheralConnList.connHandle,?¬i)?!=?SUCCESS) ????????{ ????????????GATT_bm_free((gattMsg_t?*)¬i,?ATT_HANDLE_VALUE_NOTI); ????????} ????} }