V1.4:修复串口RESET/OTA命令复位丢失;补回ota_simulate_fail回退测试开关(默认关);WiFi OTA与回退实测通过

This commit is contained in:
helei 2026-08-08 22:51:10 +08:00
parent 680362202c
commit 308119a45c
2 changed files with 18 additions and 4 deletions

View File

@ -57,7 +57,7 @@ void app_init(void)
{ {
log_info(""); log_info("");
log_info("* * * * * * * * * * * * * * * * * *"); log_info("* * * * * * * * * * * * * * * * * *");
log_info("* Version: 1.4.0 (RTOS) *"); log_info("* Version: 1.4.3 (RTOS) *");
log_info("* * * * * * * By Helei * * * *"); log_info("* * * * * * * By Helei * * * *");
/* EEPROM 中的 MQTT/版本配置 */ /* EEPROM 中的 MQTT/版本配置 */
@ -110,6 +110,8 @@ static void app_task(void *arg)
/* 主循环状态变量 */ /* 主循环状态变量 */
static uint8_t ota_confirmed = 0; static uint8_t ota_confirmed = 0;
static uint8_t ota_simulate_fail = 0; /* =1测试模拟 OTA 确认失败(验证回退) */
static uint8_t ota_fail_logged = 0;
static uint32_t ota_confirm_tick = 0; static uint32_t ota_confirm_tick = 0;
static uint32_t mqtt_ready_tick = 0; static uint32_t mqtt_ready_tick = 0;
static uint8_t mqtt_ready_recorded = 0; static uint8_t mqtt_ready_recorded = 0;
@ -135,9 +137,17 @@ static void app_task(void *arg)
/* 首次发布成功后延迟 3s 再 OTA 确认 */ /* 首次发布成功后延迟 3s 再 OTA 确认 */
if (!ota_confirmed && g_net_mqtt_ready && g_net_first_publish_ok && if (!ota_confirmed && g_net_mqtt_ready && g_net_first_publish_ok &&
(HAL_GetTick() - ota_confirm_tick) > 3000) { (HAL_GetTick() - ota_confirm_tick) > 3000) {
ota_confirmed = 1; if (ota_simulate_fail) {
NET_ota_confirm(); if (!ota_fail_logged) {
log_info("> OTA confirmed (MQTT ready + first publish ok + 3s delay)"); ota_fail_logged = 1;
log_info("> OTA confirm skipped (simulate fail for rollback test)");
}
/* 不置位 ota_confirmed让 1 分钟健康超时触发复位 */
} else {
ota_confirmed = 1;
NET_ota_confirm();
log_info("> OTA confirmed (MQTT ready + first publish ok + 3s delay)");
}
} }
/* MQTT 就绪后 1 分钟仍未首次 MPUB主动复位 */ /* MQTT 就绪后 1 分钟仍未首次 MPUB主动复位 */

View File

@ -57,6 +57,8 @@ void process_usart1_command(void)
if (cmd_is(cmd, "RESET")) { if (cmd_is(cmd, "RESET")) {
log_warn("> USART1 RESET command received, rebooting..."); log_warn("> USART1 RESET command received, rebooting...");
HAL_Delay(100);
NVIC_SystemReset();
} }
else if (cmd_is(cmd, "INFO")) { else if (cmd_is(cmd, "INFO")) {
log_info("> BT INFO: ver=%u, server=%s:%d, client=%s", log_info("> BT INFO: ver=%u, server=%s:%d, client=%s",
@ -86,6 +88,8 @@ void process_usart1_command(void)
} }
else if (cmd_is(cmd, "OTA")) { else if (cmd_is(cmd, "OTA")) {
log_info("> BT OTA: reboot to bootloader for OTA check"); log_info("> BT OTA: reboot to bootloader for OTA check");
HAL_Delay(100);
NVIC_SystemReset();
} }
else if (cmd_is(cmd, "RECOVERY")) { else if (cmd_is(cmd, "RECOVERY")) {
/* WiFi 模块 AT+RESTORE 恢复出厂(忘掉已保存的热点),用于测试 SmartConfig /* WiFi 模块 AT+RESTORE 恢复出厂(忘掉已保存的热点),用于测试 SmartConfig