溫故而知新

來源:互聯網
上載者:User

標籤:

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) 

溫故而知新

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.