2026-05-31 03:20:26 +08:00
|
|
|
/*
|
2026-04-27 00:42:26 +08:00
|
|
|
* wifi_ota.h - WiFi OTA 服务器
|
|
|
|
|
* T4.1 - T4.5
|
2026-05-31 03:20:26 +08:00
|
|
|
*
|
|
|
|
|
* WifiOta 类封装 WiFi 初始化、HTTP OTA 服务器和网络状态查询。
|
2026-04-27 00:42:26 +08:00
|
|
|
*/
|
|
|
|
|
#ifndef WIFI_OTA_H
|
|
|
|
|
#define WIFI_OTA_H
|
|
|
|
|
|
|
|
|
|
#include "ota_relay.h"
|
2026-05-31 03:20:26 +08:00
|
|
|
#include "esp_ota_ops.h"
|
|
|
|
|
#include "esp_http_server.h"
|
|
|
|
|
#include "esp_event.h"
|
2026-04-27 00:42:26 +08:00
|
|
|
|
|
|
|
|
typedef enum {
|
2026-05-31 03:20:26 +08:00
|
|
|
OTA_WIFI_MODE_AP,
|
|
|
|
|
OTA_WIFI_MODE_STA
|
2026-04-27 00:42:26 +08:00
|
|
|
} ota_wifi_mode_t;
|
|
|
|
|
|
2026-05-31 03:20:26 +08:00
|
|
|
class WifiOta {
|
|
|
|
|
public:
|
|
|
|
|
static WifiOta& instance();
|
2026-04-27 00:42:26 +08:00
|
|
|
|
2026-05-31 03:20:26 +08:00
|
|
|
bool earlyInit();
|
|
|
|
|
static void taskEntry(void *pvParameters);
|
|
|
|
|
void signalRelay();
|
2026-05-05 03:28:44 +08:00
|
|
|
|
2026-05-31 03:20:26 +08:00
|
|
|
static ota_wifi_mode_t getMode();
|
|
|
|
|
static int8_t getRssi();
|
|
|
|
|
static bool isConnected();
|
2026-04-27 00:42:26 +08:00
|
|
|
|
2026-05-31 03:20:26 +08:00
|
|
|
// 以下状态为 public,供 C 回调函数访问
|
|
|
|
|
ota_wifi_mode_t m_wifiMode = OTA_WIFI_MODE_AP;
|
|
|
|
|
bool m_coldBoot = false;
|
|
|
|
|
bool m_relayTriggered = false;
|
|
|
|
|
bool m_staConnected = false;
|
|
|
|
|
int m_staRetryCount = 0;
|
|
|
|
|
bool m_staRetryExhausted = false;
|
|
|
|
|
SemaphoreHandle_t m_staConnectedSem = NULL;
|
|
|
|
|
SemaphoreHandle_t m_staGotIpSem = NULL;
|
2026-04-27 00:42:26 +08:00
|
|
|
|
2026-05-31 03:20:26 +08:00
|
|
|
bool m_esp32OtaActive = false;
|
|
|
|
|
esp_ota_handle_t m_esp32OtaHandle = 0;
|
|
|
|
|
const esp_partition_t *m_esp32UpdatePartition = NULL;
|
|
|
|
|
size_t m_esp32Received = 0;
|
|
|
|
|
bool m_gd32StorageDone = false;
|
|
|
|
|
httpd_handle_t m_httpServer = NULL;
|
2026-04-27 00:42:26 +08:00
|
|
|
|
2026-05-31 03:20:26 +08:00
|
|
|
void initAp();
|
|
|
|
|
esp_err_t initSta();
|
|
|
|
|
void setStaticIp();
|
|
|
|
|
static void wifiEventHandler(void *arg, esp_event_base_t event_base,
|
|
|
|
|
int32_t event_id, void *event_data);
|
|
|
|
|
esp_err_t httpServerStart();
|
|
|
|
|
esp_err_t waitStaConnected(char *ip_str, size_t ip_len);
|
|
|
|
|
};
|
2026-04-27 00:42:26 +08:00
|
|
|
|
2026-05-31 03:20:26 +08:00
|
|
|
#endif // WIFI_OTA_H
|