refactor(arch): 精简架构去除样板代码并修复BLE OTA虚假ACK问题
- 移除OtaCoordinator中重复的状态查询锁操作,改为单次取值后比较 - 将GD32存储wrapper函数改为inline实现并移入头文件,删除对应的cpp实现 - HTTP路由注册改为路由表+循环注册,消除复制粘贴的URI注册代码 - OtaRelay事件分发中提取通用拒绝逻辑到commonReject helper函数 - SpiMaster中折叠加锁/无锁镜像函数,通过内部Impl实现统一路径 - HealthMonitor使用RAII LockGuard替代重复的mutex操作代码 - 修复BLE OTA中ESP32路径的虚假ACK问题,窗口边界ACK仅在实际写入时触发 - 修复BLE OTA中GD32路径的重复包ACK问题,重复包静默跳过不发送ACK - 调整发送端首轮ACK超时从3000ms提升至5000ms,适配设备端flash写入速度 - 清理临时文件和无用的配置宏定义 - 在main.cpp中添加GD32版本探测逻辑
This commit is contained in:
@@ -530,13 +530,21 @@ esp_err_t OtaCoordinator::beginEsp32OtaWithRetry(uint32_t total_size, ota_channe
|
||||
return err;
|
||||
}
|
||||
|
||||
// ★ 已持锁版本的 ESP32 状态切换 helper:设置 m_sysState 并打印一条 INFO 日志。
|
||||
// 供 notifyEsp32*Complete / notifyEsp32Rebooting 等锁内路径复用,避免重复样板代码。
|
||||
void OtaCoordinator::setEsp32StateLocked(ota_system_state_t s, const char *dbg_msg)
|
||||
{
|
||||
m_sysState = s;
|
||||
DEBUG_INFO(TAG, "%s", dbg_msg);
|
||||
}
|
||||
|
||||
/** @brief 通知协调器:ESP32 固件接收完毕,状态转为 FINALIZING。 */
|
||||
void OtaCoordinator::notifyEsp32ReceiveComplete()
|
||||
{
|
||||
bool h = lock();
|
||||
if (h && m_sysState == OTA_SYS_ESP32_RECEIVING) {
|
||||
m_sysState = OTA_SYS_ESP32_FINALIZING;
|
||||
DEBUG_INFO(TAG, "ESP32 固件接收完毕, 系统状态 → ESP32_FINALIZING");
|
||||
setEsp32StateLocked(OTA_SYS_ESP32_FINALIZING,
|
||||
"ESP32 固件接收完毕, 系统状态 → ESP32_FINALIZING");
|
||||
}
|
||||
unlock(h);
|
||||
}
|
||||
@@ -546,8 +554,8 @@ void OtaCoordinator::notifyEsp32FinalizeComplete()
|
||||
{
|
||||
bool h = lock();
|
||||
if (h) {
|
||||
m_sysState = OTA_SYS_ESP32_REBOOTING;
|
||||
DEBUG_INFO(TAG, "ESP32 OTA 收尾完成, 系统状态 → ESP32_REBOOTING");
|
||||
setEsp32StateLocked(OTA_SYS_ESP32_REBOOTING,
|
||||
"ESP32 OTA 收尾完成, 系统状态 → ESP32_REBOOTING");
|
||||
}
|
||||
unlock(h);
|
||||
}
|
||||
@@ -557,8 +565,8 @@ void OtaCoordinator::notifyEsp32Rebooting()
|
||||
{
|
||||
bool h = lock();
|
||||
if (h) {
|
||||
m_sysState = OTA_SYS_ESP32_REBOOTING;
|
||||
DEBUG_INFO(TAG, "ESP32 即将重启, 系统状态 → ESP32_REBOOTING");
|
||||
setEsp32StateLocked(OTA_SYS_ESP32_REBOOTING,
|
||||
"ESP32 即将重启, 系统状态 → ESP32_REBOOTING");
|
||||
}
|
||||
unlock(h);
|
||||
}
|
||||
|
||||
@@ -476,6 +476,10 @@ private:
|
||||
// 并把状态机复位为 IDLE。abortCurrent / abortCurrentIfEpoch 共享此实现。
|
||||
void doAbortLocked();
|
||||
|
||||
// ★ 已持锁版本的 ESP32 状态切换 helper:设置 m_sysState 并打印一条 INFO 日志。
|
||||
// 供 notifyEsp32*Complete / notifyEsp32Rebooting 等锁内路径复用,避免重复样板代码。
|
||||
void setEsp32StateLocked(ota_system_state_t s, const char *dbg_msg);
|
||||
|
||||
// 系统状态
|
||||
ota_system_state_t m_sysState = OTA_SYS_IDLE;
|
||||
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
/*
|
||||
* ota_snapshot.h - OTA 状态只读快照(便捷聚合头文件)
|
||||
*
|
||||
* 本文件本身不包含结构体定义,仅聚合两个快照来源:
|
||||
* - RelaySnapshot → 定义在 relay/ota_relay.h(一次锁保护读取 relay 进度)
|
||||
* - OtaSnapshot → 定义在 ota/ota_coordinator.h(coordinator + meta + relay 快照)
|
||||
*
|
||||
* HTTP handler 等消费方只需 #include "ota/ota_snapshot.h" 即可使用两种快照。
|
||||
*/
|
||||
#ifndef OTA_SNAPSHOT_H
|
||||
#define OTA_SNAPSHOT_H
|
||||
|
||||
#include "relay/ota_relay.h" // RelaySnapshot
|
||||
#include "ota/ota_coordinator.h" // OtaSnapshot
|
||||
|
||||
#endif // OTA_SNAPSHOT_H
|
||||
Reference in New Issue
Block a user