官方核心文档
11 ADVERTISING AND SCAN RESPONSE DATA FORMAT
[[Core_v5.4.pdf#page=1353&selection=12,0,13,6|Core_v5.4, page 1,353]]
广播数据格式
广播数据分为:
- 有效数据部分
- 有效数据部分用 AD Structure 填充
- 无效数据部分
- 无效数据部分全部填充分 0
AD Structure 结构:
- Length: Length 除外,整个 AD Structure 数据包的长度
- Data:
- Type: 数据的类型,广播数据的类型可以在[[Assigned_Numbers.pdf]]中查看
-
2.3 Common Data Types
[[Assigned_Numbers.pdf#page=12&selection=6,0,8,17|Assigned_Numbers, page 12]]
-
- AD Data: 实际数据的内容
- Type: 数据的类型,广播数据的类型可以在[[Assigned_Numbers.pdf]]中查看
GATTS 示例中数据分析
struct uint8_t raw_adv_data[] = {
/* flags */
0x02, 0x01, 0x06,
/* tx power */
0x02, 0x0A, 0xEB,
/* service uuid */
0x03, 0x03, 0xFF, 0x00,
/* device name */
0x0F, 0x09, 'E', 'S', 'P', '_', 'G', 'A', 'T', 'T', 'S', '_', 'D', 'E', 'M', 'O'
};
-
flags:
- Length: 0x02 表示后面有两个数据
- Type: 0x01,数据类型
-
0x01
[[Assigned_Numbers.pdf#page=12&selection=32,0,33,1|Assigned_Numbers, page 12]] - flags 详细说明,可以在核心文档的补充文档中查看
-
1.3 FLAGS
[[CSS_v11.pdf#page=15&selection=12,0,14,5|CSS_v11, page 15]]
-
- AD Data
-
tx power:
- Length: 0x02 表示后面有两个数据
- Type: 0x0A,数据类型
-
0x0A
[[Assigned_Numbers.pdf#page=12&selection=95,0,96,0|Assigned_Numbers, page 12]]
-
- AD Data
-
service uuid:
- Length: 0x03,表示后面有三个数据
- Type: 0x03,数据类型
-
0x03
[[Assigned_Numbers.pdf#page=12&selection=46,0,47,0|Assigned_Numbers, page 12]]
-
- AD Data
-
device name:
- Length: 0x0F,后面有 0x0F(15) 个数据
- Type: 0x09,数据类型
-
0x09
[[Assigned_Numbers.pdf#page=12&selection=88,0,88,4|Assigned_Numbers, page 12]]
-
- AD Data
- 此处的设备名与
esp_ble_gap_set_device_name()
设置的名字不同。- 这个函数设置的名字是用来设备扫描之后显示的名字
- 而此处的名字是用来在广播数据中广播的名字。
-
广播数据包能携带多少个数据,与蓝牙的种类和广播类型来决定。
-
These PDUs are sent by the Link Layer in the Advertising state and received by a Link Layer in the Scanning state or Initiating state. The ADV_IND, ADV_DIRECT_IND, ADV_NONCONN_IND, and ADV_SCAN_IND PDUs are called “legacy advertising PDUs”. The ADV_EXT_IND, AUX_ADV_IND, AUX_SYNC_IND, AUX_CHAIN_IND, AUX_SYNC_SUBEVENT_IND, and AUX_SYNC_SUBEVENT_RSP PDUs are called “extended advertising PDUs”. Advertising events using legacy advertising PDUs are called “legacy advertising events”.
[[Core_v5.4.pdf#page=2691&selection=56,0,63,20|Core_v5.4, page 2,691]]
其中,"legacy advertising PDUs"用于蓝牙 4.1、4.2 的广播,而"extended advertising PDUs"用于蓝牙 5.0 以上。 -
蓝牙 5.0 以下,广播包中只能携带 31 字节的有效数据。
2.3.1.1 ADV_IND
[[Core_v5.4.pdf#page=2691&selection=65,0,65,15|Core_v5.4, page 2,691]]
- 而蓝牙 5.0 以上,可以携带不超过 254 个字节的有效数据。
2.3.4 Common Extended Advertising Payload Format
[[Core_v5.4.pdf#page=2704&selection=12,0,12,48|Core_v5.4, page 2,704]]
- 蓝牙 5.0 以上,若使用 分段技术(fragmentation),可以将广播报最大有效数据量提升到 1650 个字节的数据。
2.3.4.9 Host Advertising Data
[[Core_v5.4.pdf#page=2711&selection=37,0,37,29|Core_v5.4, page 2,711]]
- 广播参数定义中
static esp_ble_adv_params_t adv_params = {
.adv_int_min = 0x20,
.adv_int_max = 0x40,
.adv_type = ADV_TYPE_IND,
.own_addr_type = BLE_ADDR_TYPE_PUBLIC,
.channel_map = ADV_CHNL_ALL,
.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
};
.adv_type = ADV_TYPE_IND
为蓝牙 4.0 。
广播类型定义
2.3.1 Advertising PDUs
[[Core_v5.4.pdf#page=2691&selection=22,0,22,22|Core_v5.4, page 2,691]]