Files
AC7911BB_JL-AIBT-SoundBox/wifi/wifi_manager.h
T

80 lines
2.0 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef WIFI_MANAGER_H
#define WIFI_MANAGER_H
#include "system/includes.h"
/*
* wifi_manager
*
* 职责:
* 1. 注册并直接处理 AC79NN SDK Wi-Fi 事件
* 2. 维护 Wi-Fi 业务状态
* 3. 管理 Wi-Fi 模块启动时机
* 4. 启动阶段配置目标 STA 默认模式
* 5. Wi-Fi 已启动后调用 wifi_sta 切换/连接指定 STA
*
* 当前不负责:
* - SSID / password 持久化
* - 自动重连
* - BLE 配网
* - MQTT
* - 雷达业务
*/
struct wifi_manager_status {
u8 initialized; //管理层:清零WiFi状态值、ssid和password
// 并注册回调函数
u8 module_initialized; //驱动层
u8 module_started;
u8 sta_started;
u8 connecting;
u8 sta_associated;
u8 network_ready;
};
/*
* 初始化 manager 本身:
* - 检查 Wi-Fi 尚未被其他代码启动
* - 注册 SDK Wi-Fi callback
* - 初始化 manager 软件状态
*
* 注意:
* 本函数不调用 wifi_on()。
* 第一次实际启动 Wi-Fi 由 wifi_manager_connect() 完成,
* 这样 manager 可以在 WIFI_EVENT_MODULE_INIT 阶段
* 先把本次目标 SSID/password 配成启动默认 STA。
*/
int wifi_manager_init(void);
/*
* 请求连接指定 STA 网络。
*
* 第一次调用且 Wi-Fi 还未启动:
* 保存目标凭据 -> wifi_on()
* -> MODULE_INIT 中配置强制 STA 默认模式
* -> SDK 自动进入 STA 并连接目标网络
*
* Wi-Fi 已经启动后再次调用:
* 通过 wifi_sta_connect() 发起运行期 STA 连接/切换。
*
* return == 0 只表示请求已接受,
* 真正可联网必须以 network_ready == 1 为准。
*/
int wifi_manager_connect(
const char *ssid,
const char *password
);
/* 获取当前 Wi-Fi 状态快照。 */
int wifi_manager_get_status(
struct wifi_manager_status *out
);
/* 只表示 802.11 已完成 STA -> AP 关联。 */
int wifi_manager_is_sta_associated(void);
/* DHCP 成功后才返回 1MQTT/TCP 应以此为准。 */
int wifi_manager_is_network_ready(void);
#endif