一 概念
直接上英文原文,怕自己的翻译误导大家。
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 */
这两个结合在一起看,是不是就理解了呢?