標籤:
1. 在外圍裝置和中心裝置建立串連的過程:
a) 從裝置發射廣播(廣播中包含從裝置的服務的 UUID 清單);
b) 主裝置掃描,讓主裝置掃描只是一個簡單的 API ;
c) 如果主裝置掃描到裝置後(正是根據從裝置的廣播而發現的,此時是沒有建立串連但是主裝置和從裝置通訊了),就會觸發一個裝置發現的事件;
d) 在這個事件中根據 UUID 尋找需要的服務,把符合要求的裝置添加到裝置列表中;
e) 掃描完成事件這時也會被觸發,在這個事件裡發起向從裝置的串連,向從裝置的串連也是一個 API;
f) 串連完成後同樣也會觸發一個事件,這時就可以找從裝置的特徵值了。
warning:
one) 從裝置的廣播中的 UUID 的列表資料格式大致如下:
長度是以位元組為單位的,如果 adlen = 2, adtype = 16bit, 那麼也就是說 UUID 長度為16個位元組的服務只有一個。
還有這裡的 adtype ,也就是地址類型,一般有三種類型,16位、32位、128位。
two) GAP 層的事件:
typedef union
{
gapEventHdr_t gap; //!< GAP_MSG_EVENT and status.
gapDeviceInitDoneEvent_t initDone; //!< GAP initialization done.
gapDeviceInfoEvent_t deviceInfo; //!< Discovery device information event structure.
gapDevDiscEvent_t discCmpl; //!< Discovery complete event structure.
gapEstLinkReqEvent_t linkCmpl; //!< Link complete event structure.
gapLinkUpdateEvent_t linkUpdate; //!< Link update event structure.
gapTerminateLinkEvent_t linkTerminate; //!< Link terminated event structure.
} gapCentralRoleEvent_t;
three) 廣播的訊息都有些什麼內容呢?
/**
* GAP_DEVICE_INFO_EVENT message format. This message is sent to the
* app during a Device Discovery Request, when a new advertisement or scan
* response is received.
*/
typedef struct
{
osal_event_hdr_t hdr; //!< GAP_MSG_EVENT and status
uint8 opcode; //!< GAP_DEVICE_INFO_EVENT
uint8 eventType; //!< Advertisement Type: @ref GAP_ADVERTISEMENT_REPORT_TYPE_DEFINES
uint8 addrType; //!< address type: @ref GAP_ADDR_TYPE_DEFINES
uint8 addr[B_ADDR_LEN]; //!< Address of the advertisement or SCAN_RSP
int8 rssi; //!< Advertisement or SCAN_RSP RSSI 這裡竟然能得到rssi的值,以前都沒注意!!!!
uint8 dataLen; //!< Length (in bytes) of the data field (evtData)
uint8 *pEvtData; //!< Data field of advertisement or SCAN_RSP
} gapDeviceInfoEvent_t;
four)
溫故而知新