返回首页

BLE Direction Finding 学习笔记

概述

BLE Direction Finding 是 Bluetooth 5.1 引入的测向能力,核心机制是发送端或接收端在 CTE(Constant Tone Extension)阶段采集 IQ 数据,再由应用结合天线阵列做角度估计。

需要先分清两个边界:


1. 两种基本模式

1.1 AoA

1.2 AoD


2. 当前 Zephyr 里的关键头文件

#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/direction.h>

这页要以 zephyr/include/zephyr/bluetooth/direction.h 为准。 不要自己重新定义 bt_df_* 结构体,也不要把算法层数据结构当成 SDK 官方 API。


3. 广播场景的常用接口

3.1 发射侧

struct bt_df_adv_cte_tx_param params = {
    .cte_len = 20,
    .cte_type = BT_DF_CTE_TYPE_AOA,
    .num_ant_ids = 0,
    .ant_ids = NULL,
};

bt_df_set_adv_cte_tx_param(adv, &params);
bt_df_adv_cte_tx_enable(adv);

常见接口:

3.2 接收侧

const struct bt_df_per_adv_sync_cte_rx_param rx_params = {
    .cte_types = BT_DF_CTE_TYPE_AOA,
    .slot_durations = BT_DF_ANTENNA_SWITCHING_SLOT_2US,
    .max_cte_count = 5,
    .num_ant_ids = ARRAY_SIZE(ant_patterns),
    .ant_ids = ant_patterns,
};

bt_df_per_adv_sync_cte_rx_enable(sync, &rx_params);

常见接口:


4. 连接场景的常用接口

4.1 Peripheral / 响应侧

const struct bt_df_conn_cte_tx_param tx_params = {
    .cte_types = BT_DF_CTE_TYPE_AOD_2US,
    .num_ant_ids = ARRAY_SIZE(ant_ids),
    .ant_ids = ant_ids,
};

bt_df_set_conn_cte_tx_param(conn, &tx_params);
bt_df_conn_cte_rsp_enable(conn);

4.2 Central / 请求侧

const struct bt_df_conn_cte_rx_param rx_params = {
    .cte_types = BT_DF_CTE_TYPE_AOD_2US,
    .slot_durations = BT_DF_ANTENNA_SWITCHING_SLOT_2US,
    .num_ant_ids = ARRAY_SIZE(ant_ids),
    .ant_ids = ant_ids,
};

const struct bt_df_conn_cte_req_params req_params = {
    .interval = 10,
    .cte_length = 20,
    .cte_type = BT_DF_CTE_TYPE_AOD_2US,
};

bt_df_conn_cte_rx_enable(conn, &rx_params);
bt_df_conn_cte_req_enable(conn, &req_params);

5. IQ 数据回调

方向查找的重点不是“有没有 API”,而是 IQ 报告怎么处理。

连接场景的回调参数看:

广播同步场景的回调参数看:

应用里通常会拿到:

这些数据足够做相位差、阵列校准和角度估算,但角度算法要你自己做。


6. 当前可直接参考的 sample

Zephyr 当前目录里可以直接对上的是:

如果你关注的是 Bluetooth 6.0 里的 Channel Sounding,要看:

Direction Finding 和 Channel Sounding 都与“定位/测距”相关,但它们不是同一个功能。


7. 板卡与天线注意事项


8. 常见误区


9. 学习顺序建议

  1. 先跑 direction_finding_connectionless_tx/rx
  2. 再看 direction_finding_peripheral/central
  3. 最后再进入天线校准、滤波和角度算法

参考入口