功能:集成SU-03T语音模块,完善UI代码文档
- 在CMakeLists.txt中添加SU-03T语音模块依赖。 - 在main.cpp中实现SU-03T接收回调函数,处理接收消息。 - 完善各UI源文件文档,包括动作、屏幕和字体,明确模块作用与数据流向。 - 更新主应用逻辑,初始化并启动SU-03T接收器。 - 修改过程中确保兼容性,保留原有接口。
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
/*
|
||||
* 文件: components/wifi-connect/include/wifi-connect.h
|
||||
* 角色: Wi-Fi 连接、配网与网络状态管理
|
||||
* 说明:
|
||||
* - 本文件用于实现当前模块的核心功能或接口定义。
|
||||
* - 修改前请先确认该模块与其它任务/外设之间的数据流关系。
|
||||
* - 涉及协议与硬件时,优先保持现有接口兼容,避免联调回归。
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/*
|
||||
* 文件: components/wifi-connect/wifi-connect.c
|
||||
* 角色: Wi-Fi 连接、配网与网络状态管理
|
||||
* 说明:
|
||||
* - 本文件用于实现当前模块的核心功能或接口定义。
|
||||
* - 修改前请先确认该模块与其它任务/外设之间的数据流关系。
|
||||
* - 涉及协议与硬件时,优先保持现有接口兼容,避免联调回归。
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@@ -36,6 +45,10 @@
|
||||
|
||||
static const char *TAG = "wifi_connect";
|
||||
|
||||
/* 函数: wifi_connect_log_state_i
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static void wifi_connect_log_state_i(const char *state, const char *detail)
|
||||
{
|
||||
if (detail != NULL && detail[0] != '\0')
|
||||
@@ -44,6 +57,10 @@ static void wifi_connect_log_state_i(const char *state, const char *detail)
|
||||
ESP_LOGI(TAG, "【状态】%s", state);
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_log_state_w
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static void wifi_connect_log_state_w(const char *state, const char *detail)
|
||||
{
|
||||
if (detail != NULL && detail[0] != '\0')
|
||||
@@ -52,6 +69,10 @@ static void wifi_connect_log_state_w(const char *state, const char *detail)
|
||||
ESP_LOGW(TAG, "【状态】%s", state);
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_log_state_e
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static void wifi_connect_log_state_e(const char *state, const char *detail)
|
||||
{
|
||||
if (detail != NULL && detail[0] != '\0')
|
||||
@@ -192,11 +213,19 @@ static const char *s_html_page =
|
||||
"setInterval(()=>{if(isConnected)fetchInfo();},3000);"
|
||||
"</script></body></html>";
|
||||
|
||||
/* 函数: wifi_connect_set_status_locked
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static void wifi_connect_set_status_locked(wifi_connect_status_t status)
|
||||
{
|
||||
s_ctx.status = status;
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_set_error_locked
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static void wifi_connect_set_error_locked(const char *message)
|
||||
{
|
||||
if (message == NULL)
|
||||
@@ -207,6 +236,10 @@ static void wifi_connect_set_error_locked(const char *message)
|
||||
snprintf(s_ctx.last_error, sizeof(s_ctx.last_error), "%s", message);
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_save_credentials
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static esp_err_t wifi_connect_save_credentials(const char *ssid, const char *password)
|
||||
{
|
||||
nvs_handle_t handle;
|
||||
@@ -220,6 +253,10 @@ static esp_err_t wifi_connect_save_credentials(const char *ssid, const char *pas
|
||||
return err;
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_clear_config
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
esp_err_t wifi_connect_clear_config(void)
|
||||
{
|
||||
nvs_handle_t handle;
|
||||
@@ -270,6 +307,10 @@ esp_err_t wifi_connect_clear_config(void)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_get_config
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
esp_err_t wifi_connect_get_config(wifi_connect_config_t *config)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(config != NULL, ESP_ERR_INVALID_ARG, TAG, "config is null");
|
||||
@@ -290,6 +331,10 @@ esp_err_t wifi_connect_get_config(wifi_connect_config_t *config)
|
||||
return err;
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_status_to_string
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static const char *wifi_connect_status_to_string(wifi_connect_status_t status)
|
||||
{
|
||||
switch (status)
|
||||
@@ -311,6 +356,10 @@ static const char *wifi_connect_status_to_string(wifi_connect_status_t status)
|
||||
}
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_get_status
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
wifi_connect_status_t wifi_connect_get_status(void)
|
||||
{
|
||||
if (!s_ctx.initialized || s_ctx.lock == NULL)
|
||||
@@ -323,6 +372,10 @@ wifi_connect_status_t wifi_connect_get_status(void)
|
||||
return status;
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_get_ip
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
const char *wifi_connect_get_ip(void)
|
||||
{
|
||||
if (!s_ctx.initialized || s_ctx.lock == NULL)
|
||||
@@ -335,12 +388,20 @@ const char *wifi_connect_get_ip(void)
|
||||
return ip_buf;
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_send_json
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static esp_err_t wifi_connect_send_json(httpd_req_t *req, const char *json)
|
||||
{
|
||||
httpd_resp_set_type(req, "application/json");
|
||||
return httpd_resp_sendstr(req, json);
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_json_escape
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static void wifi_connect_json_escape(const char *src, char *dst, size_t dst_size)
|
||||
{
|
||||
size_t j = 0;
|
||||
@@ -358,6 +419,10 @@ static void wifi_connect_json_escape(const char *src, char *dst, size_t dst_size
|
||||
dst[j] = '\0';
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_auth_to_string
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static const char *wifi_connect_auth_to_string(wifi_auth_mode_t auth)
|
||||
{
|
||||
switch (auth)
|
||||
@@ -383,6 +448,10 @@ static const char *wifi_connect_auth_to_string(wifi_auth_mode_t auth)
|
||||
}
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_http_scan_handler
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static esp_err_t wifi_connect_http_scan_handler(httpd_req_t *req)
|
||||
{
|
||||
wifi_scan_config_t scan_cfg = {.show_hidden = false};
|
||||
@@ -430,6 +499,10 @@ static esp_err_t wifi_connect_http_scan_handler(httpd_req_t *req)
|
||||
return err;
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_extract_json_string
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static bool wifi_connect_extract_json_string(const char *json, const char *key, char *out, size_t out_len)
|
||||
{
|
||||
char pattern[32];
|
||||
@@ -449,6 +522,10 @@ static bool wifi_connect_extract_json_string(const char *json, const char *key,
|
||||
return idx > 0 || strcmp(key, "password") == 0;
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_apply_sta_credentials
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static esp_err_t wifi_connect_apply_sta_credentials(const char *ssid, const char *password)
|
||||
{
|
||||
wifi_config_t sta_cfg = {0};
|
||||
@@ -468,6 +545,10 @@ static esp_err_t wifi_connect_apply_sta_credentials(const char *ssid, const char
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_http_connect_handler
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static esp_err_t wifi_connect_http_connect_handler(httpd_req_t *req)
|
||||
{
|
||||
if (req->content_len <= 0 || req->content_len >= WIFI_CONNECT_HTTP_BUF_SIZE)
|
||||
@@ -513,6 +594,10 @@ static esp_err_t wifi_connect_http_connect_handler(httpd_req_t *req)
|
||||
return wifi_connect_send_json(req, "{\"ok\":true}");
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_http_status_handler
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static esp_err_t wifi_connect_http_status_handler(httpd_req_t *req)
|
||||
{
|
||||
wifi_connect_status_t status;
|
||||
@@ -531,6 +616,10 @@ static esp_err_t wifi_connect_http_status_handler(httpd_req_t *req)
|
||||
return wifi_connect_send_json(req, payload);
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_http_clear_handler
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static esp_err_t wifi_connect_http_clear_handler(httpd_req_t *req)
|
||||
{
|
||||
esp_err_t err = wifi_connect_clear_config();
|
||||
@@ -539,6 +628,10 @@ static esp_err_t wifi_connect_http_clear_handler(httpd_req_t *req)
|
||||
return wifi_connect_send_json(req, "{\"ok\":true}");
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_http_sysinfo_handler
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static esp_err_t wifi_connect_http_sysinfo_handler(httpd_req_t *req)
|
||||
{
|
||||
char payload[128];
|
||||
@@ -546,6 +639,10 @@ static esp_err_t wifi_connect_http_sysinfo_handler(httpd_req_t *req)
|
||||
return wifi_connect_send_json(req, payload);
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_http_index_handler
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static esp_err_t wifi_connect_http_index_handler(httpd_req_t *req)
|
||||
{
|
||||
httpd_resp_set_hdr(req, "Cache-Control", "no-store, no-cache, must-revalidate, max-age=0");
|
||||
@@ -554,6 +651,10 @@ static esp_err_t wifi_connect_http_index_handler(httpd_req_t *req)
|
||||
return httpd_resp_send(req, s_html_page, HTTPD_RESP_USE_STRLEN);
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_get_ap_http_url
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static void wifi_connect_get_ap_http_url(char *out, size_t out_len)
|
||||
{
|
||||
esp_netif_ip_info_t ip_info = {0};
|
||||
@@ -567,6 +668,10 @@ static void wifi_connect_get_ap_http_url(char *out, size_t out_len)
|
||||
snprintf(out, out_len, "http://192.168.4.1/");
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_http_probe_handler
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static esp_err_t wifi_connect_http_probe_handler(httpd_req_t *req)
|
||||
{
|
||||
char location[48] = {0};
|
||||
@@ -580,6 +685,10 @@ static esp_err_t wifi_connect_http_probe_handler(httpd_req_t *req)
|
||||
static esp_err_t wifi_connect_http_start(void);
|
||||
static void wifi_connect_http_stop(void);
|
||||
|
||||
/* 函数: wifi_connect_http_start
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static esp_err_t wifi_connect_http_start(void)
|
||||
{
|
||||
if (s_ctx.http_server != NULL)
|
||||
@@ -622,6 +731,10 @@ static esp_err_t wifi_connect_http_start(void)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_http_stop
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static void wifi_connect_http_stop(void)
|
||||
{
|
||||
if (s_ctx.http_server != NULL)
|
||||
@@ -631,6 +744,10 @@ static void wifi_connect_http_stop(void)
|
||||
}
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_build_dns_response
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static size_t wifi_connect_build_dns_response(const uint8_t *req, size_t req_len, uint8_t *resp, size_t resp_max, uint32_t ip_addr)
|
||||
{
|
||||
if (req_len < 12 || resp_max < 64)
|
||||
@@ -683,6 +800,10 @@ static size_t wifi_connect_build_dns_response(const uint8_t *req, size_t req_len
|
||||
return pos;
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_dns_task
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static void wifi_connect_dns_task(void *arg)
|
||||
{
|
||||
uint8_t rx_buf[256], tx_buf[512];
|
||||
@@ -728,6 +849,10 @@ static void wifi_connect_dns_task(void *arg)
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_dns_start
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static esp_err_t wifi_connect_dns_start(void)
|
||||
{
|
||||
if (s_ctx.dns_running)
|
||||
@@ -741,6 +866,10 @@ static esp_err_t wifi_connect_dns_start(void)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_dns_stop
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static void wifi_connect_dns_stop(void)
|
||||
{
|
||||
if (!s_ctx.dns_running)
|
||||
@@ -751,6 +880,10 @@ static void wifi_connect_dns_stop(void)
|
||||
s_ctx.dns_task = NULL;
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_connect_timeout_cb
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static void wifi_connect_connect_timeout_cb(void *arg)
|
||||
{
|
||||
xSemaphoreTake(s_ctx.lock, portMAX_DELAY);
|
||||
@@ -775,6 +908,10 @@ static void wifi_connect_connect_timeout_cb(void *arg)
|
||||
xSemaphoreGive(s_ctx.lock);
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_ap_stop_timer_cb
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static void wifi_connect_ap_stop_timer_cb(void *arg)
|
||||
{
|
||||
xSemaphoreTake(s_ctx.lock, portMAX_DELAY);
|
||||
@@ -788,6 +925,10 @@ static void wifi_connect_ap_stop_timer_cb(void *arg)
|
||||
xSemaphoreGive(s_ctx.lock);
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_event_handler
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static void wifi_connect_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
|
||||
{
|
||||
if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP)
|
||||
@@ -849,6 +990,10 @@ static void wifi_connect_event_handler(void *arg, esp_event_base_t event_base, i
|
||||
}
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_generate_ap_ssid
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static void wifi_connect_generate_ap_ssid(char *out, size_t out_len)
|
||||
{
|
||||
uint8_t mac[6] = {0};
|
||||
@@ -857,6 +1002,10 @@ static void wifi_connect_generate_ap_ssid(char *out, size_t out_len)
|
||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_start_apsta_locked
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static esp_err_t wifi_connect_start_apsta_locked(void)
|
||||
{
|
||||
wifi_config_t ap_cfg = {0};
|
||||
@@ -879,6 +1028,10 @@ static esp_err_t wifi_connect_start_apsta_locked(void)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_start
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
esp_err_t wifi_connect_start(void)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(s_ctx.initialized, ESP_ERR_INVALID_STATE, TAG, "not initialized");
|
||||
@@ -909,6 +1062,10 @@ esp_err_t wifi_connect_start(void)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_stop
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
esp_err_t wifi_connect_stop(void)
|
||||
{
|
||||
if (!s_ctx.initialized)
|
||||
@@ -941,6 +1098,10 @@ esp_err_t wifi_connect_stop(void)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_try_auto_connect
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
static esp_err_t wifi_connect_try_auto_connect(void)
|
||||
{
|
||||
wifi_connect_config_t config = {0};
|
||||
@@ -980,6 +1141,10 @@ static esp_err_t wifi_connect_try_auto_connect(void)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/* 函数: wifi_connect_init
|
||||
* 作用: 执行模块内与函数名对应的业务逻辑。
|
||||
* 重点: 关注输入合法性、返回码与并发安全。
|
||||
*/
|
||||
esp_err_t wifi_connect_init(void)
|
||||
{
|
||||
if (s_ctx.initialized)
|
||||
|
||||
Reference in New Issue
Block a user