BLE Direction Finding 是 Bluetooth 5.1 引入的测向能力,核心机制是发送端或接收端在 CTE(Constant Tone Extension)阶段采集 IQ 数据,再由应用结合天线阵列做角度估计。
需要先分清两个边界:
#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。
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, ¶ms);
bt_df_adv_cte_tx_enable(adv);
常见接口:
bt_df_set_adv_cte_tx_param()bt_df_adv_cte_tx_enable()bt_df_adv_cte_tx_disable()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);
常见接口:
bt_df_per_adv_sync_cte_rx_enable()bt_df_per_adv_sync_cte_rx_disable()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);
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);
方向查找的重点不是“有没有 API”,而是 IQ 报告怎么处理。
连接场景的回调参数看:
struct bt_df_conn_iq_samples_report广播同步场景的回调参数看:
struct bt_df_per_adv_sync_iq_samples_report应用里通常会拿到:
这些数据足够做相位差、阵列校准和角度估算,但角度算法要你自己做。
Zephyr 当前目录里可以直接对上的是:
zephyr/samples/bluetooth/direction_finding_connectionless_txzephyr/samples/bluetooth/direction_finding_connectionless_rxzephyr/samples/bluetooth/direction_finding_peripheralzephyr/samples/bluetooth/direction_finding_central如果你关注的是 Bluetooth 6.0 里的 Channel Sounding,要看:
zephyr/samples/bluetooth/channel_soundingDirection Finding 和 Channel Sounding 都与“定位/测距”相关,但它们不是同一个功能。
ant_ids 的顺序要和真实阵列布局一致struct bt_df_cte_tx_param 这类不存在的结构体direction_finding_connectionless_tx/rxdirection_finding_peripheral/centralzephyr/include/zephyr/bluetooth/direction.hzephyr/samples/bluetooth/direction_finding_*zephyr/samples/bluetooth/channel_sounding