1. 程式人生 > 其它 >可穿戴智慧手環解決方案之BLE的ADV廣播協議解讀

可穿戴智慧手環解決方案之BLE的ADV廣播協議解讀

一 概念 直接上英文原文,怕自己的翻譯誤導大家。 When a BLE device is advertising, it periodically transmits packets, which contain information such as the preamble, access address, CRC, Bluetooth sender address, and so on. Application developers are often interested in theadvertising payloadthat is0-31 bytes longon the primary channelsbecause it is controlled by the application. For extended advertising, the maximum length is 1650 bytes, but advertising parameters may limit the amount of data that can be sent in a single advertisement. Other fields in the advertising packets are automatically filled by the Bluetooth stack.
  二 協議分析 這裡先記著這幾個常用的資料型別,接下來就容易理解了。 Some of the most commonly used data types are: 0x01 = Flags 0x03 = Complete List of 16-bit Service Class UUIDs 0x09 = Complete Local Name 0x08 = Shortened Local Name 截圖顯示: 對應程式碼:
/**************************************************************************************************
  Advertising Data
*************************************************************************************************
*/ /*! advertising data, discoverable mode */ static const uint8_t fitAdvDataDisc[] = { /*! flags */ 2, /*! length */ DM_ADV_TYPE_FLAGS, /*! AD type */ DM_FLAG_LE_GENERAL_DISC | /*! flags */ DM_FLAG_LE_BREDR_NOT_SUP, /*! tx power
*/ 2, /*! length */ DM_ADV_TYPE_TX_POWER, /*! AD type */ 0, /*! tx power */ /*! service UUID list */ 9, /*! length */ DM_ADV_TYPE_16_UUID, /*! AD type */ UINT16_TO_BYTES(ATT_UUID_HEART_RATE_SERVICE), UINT16_TO_BYTES(ATT_UUID_RUNNING_SPEED_SERVICE), UINT16_TO_BYTES(ATT_UUID_DEVICE_INFO_SERVICE), UINT16_TO_BYTES(ATT_UUID_BATTERY_SERVICE) }; /*! scan data, discoverable mode */ static const uint8_t fitScanDataDisc[] = { /*! device name */ 4, /*! length */ DM_ADV_TYPE_LOCAL_NAME, /*! AD type */ 'F', 'i', 't' };

 

看一下著裡面的幾個的幾個巨集定義,就理解adv廣播的含義了:   #define ATT_UUID_HEALTH_THERM_SERVICE 0x1809 /*!< \brief Health Thermometer Service */ #define ATT_UUID_DEVICE_INFO_SERVICE 0x180A /*!< \brief Device Information Service */ #define ATT_UUID_HEART_RATE_SERVICE 0x180D /*!< \brief Heart Rate Service */ #define ATT_UUID_PHONE_ALERT_SERVICE 0x180E /*!< \brief Phone Alert Status Service */ #define ATT_UUID_BATTERY_SERVICE 0x180F /*!< \brief Battery Service */ #define DM_ADV_TYPE_FLAGS 0x01 /*!< \brief Flag bits */ #define DM_ADV_TYPE_LOCAL_NAME 0x09 /*!< \brief Complete local name */ #define DM_ADV_TYPE_TX_POWER 0x0A /*!< \brief TX power level */ 這兩個結合在一起看,是不是就理解了呢?