Wi-Fi Station 接口

[English]

公共头文件: #include "brookesia/hal_interface/interfaces/wifi/station.hpp"

类名: StationIface

StationIface 定义 Station 模式动作、AP 元数据持久化钩子、 扫描配置、扫描控制,以及扫描和 AP 更新回调。重试、fallback 和自动连接策略不属于该接口职责。

API 参考

Header File

Classes

class StationIface : public esp_brookesia::hal::Interface

Wi-Fi station interface for AP connection and scanning.

Public Functions

inline StationIface()

Construct a station Wi-Fi interface.

virtual ~StationIface() = default

Virtual destructor for polymorphic interfaces.

virtual bool configure(Callbacks callbacks) = 0

Configure station callbacks.

参数

callbacks -- [in] Callback hooks used to report station state and data.

返回

true on success; otherwise false.

virtual void clear_callbacks() = 0

Clear all configured callbacks.

virtual bool do_action(StationAction action, bool is_force = false) = 0

Request a station action.

参数
  • action -- [in] Action to execute.

  • is_force -- [in] Whether to force the action even if state checks would normally skip it.

返回

true on success; otherwise false.

virtual bool is_action_running(StationAction action) = 0

Check whether a station action is running.

参数

action -- [in] Action to query.

返回

true if the action is running; otherwise false.

virtual bool is_event_ready(StationEvent event) = 0

Check whether a station event is ready.

参数

event -- [in] Event to query.

返回

true if the event is ready; otherwise false.

virtual void mark_target_connect_ap_info_connectable(bool connectable) = 0

Mark whether the target AP is currently connectable.

参数

connectable -- [in] Whether the target AP can be used for connection attempts.

virtual bool set_target_connect_ap_info(const ConnectApInfo &ap_info) = 0

Set the target AP connection information.

参数

ap_info -- [in] Target AP connection information.

返回

true on success; otherwise false.

virtual bool set_last_connected_ap_info(const ConnectApInfo &ap_info) = 0

Set the last connected AP information.

参数

ap_info -- [in] Last connected AP information.

返回

true on success; otherwise false.

virtual bool set_connected_ap_infos(const ConnectApInfoList &ap_infos) = 0

Set the persisted known AP list.

参数

ap_infos -- [in] Known AP list.

返回

true on success; otherwise false.

virtual const ConnectApInfo &get_target_connect_ap_info() const = 0

Get the target AP connection information.

返回

Target AP connection information.

virtual const ConnectApInfo &get_last_connected_ap_info() const = 0

Get the last connected AP information.

返回

Last connected AP information.

virtual const ConnectApInfoList &get_connected_ap_infos() const = 0

Get the persisted known AP list.

返回

Known AP list.

virtual bool set_scan_params(const ScanParams &params) = 0

Set periodic scan parameters.

参数

params -- [in] Scan parameters.

返回

true on success; otherwise false.

virtual const ScanParams &get_scan_params() const = 0

Get periodic scan parameters.

返回

Scan parameters.

virtual bool start_scan() = 0

Start periodic AP scanning.

返回

true on success; otherwise false.

virtual void stop_scan() = 0

Stop periodic AP scanning.

Public Static Attributes

static constexpr const char *NAME = "WifiStation"

Interface registry name.

struct Callbacks

Public Members

std::function<void(StationAction)> on_action

Called when a station action is triggered.

std::function<void(StationEvent, bool)> on_event

Called when a station event happens.

std::function<void()> on_error

Called when a station action fails.

std::function<bool(StationAction)> on_action_requested

Called when backend requests a station action.

std::function<void(bool)> on_scan_state_changed

Called when periodic scan state changes.

std::function<void(std::span<const ScanApInfo>)> on_scan_ap_infos_updated

Called with scan results.

std::function<void(const ConnectApInfo&)> on_last_connected_ap_info_updated

Persist last AP.

std::function<void(const ConnectApInfoList&)> on_connected_ap_infos_updated

Persist known APs.