fix: ensure OTA prompt plays before upgrade

This commit is contained in:
chenjintao
2026-09-21 16:33:19 +08:00
parent 90a6a0fff0
commit 815918c99d
3 changed files with 93 additions and 19 deletions
@@ -43,7 +43,8 @@
#define OTA_STATE_TMP_FILE "U:/ota_state.tmp"
#define OTA_STATE_MAGIC 0x4F544131U
#define OTA_STATE_FORMAT_VERSION 1U
#define OTA_PROMPT_WAIT_MS 5000
#define OTA_PROMPT_PLAY_TIMEOUT_MS 10000
#define OTA_PROMPT_POLL_MS 50
#define OTA_ALLOWED_URL_PREFIX "http://101.35.224.118:8080/assets/firmware/"
static ql_timer_t mqtt_event_task_timer = NULL;
@@ -101,7 +102,9 @@ int app_mqtt_connect_sem(char flag);
#define MQTT_PAYLOAD_SIZE 2048
static char payload[MQTT_PAYLOAD_SIZE] = {0};
extern int fota_start;
extern int fota_start;
int app_play_ota_tips_file(void);
int xiaoice_get_play_counter(void);
typedef struct {
uint32_t magic;
@@ -1294,6 +1297,7 @@ static void handle_ota_upgrade(command_t *cmd)
char *resp;
int compare_result;
int ret;
uint32_t prompt_start_time;
if (cmd == NULL || fota_start == 1) {
RLOGE("OTA request ignored: invalid command or OTA already running");
@@ -1347,8 +1351,23 @@ static void handle_ota_upgrade(command_t *cmd)
}
fota_start = 1;
app_play_tips_file(3);
ql_rtos_task_sleep_ms(OTA_PROMPT_WAIT_MS);
ret = app_play_ota_tips_file();
if (ret != 0) {
RLOGE("OTA prompt could not start: %d", ret);
} else {
prompt_start_time = hal_os_up_time_ms();
while (xiaoice_get_play_counter() > 0) {
ql_rtos_task_sleep_ms(OTA_PROMPT_POLL_MS);
if (hal_os_up_time_ms() - prompt_start_time > OTA_PROMPT_PLAY_TIMEOUT_MS) {
RLOGE("OTA prompt playback timeout, counter=%d",
xiaoice_get_play_counter());
break;
}
}
if (xiaoice_get_play_counter() == 0) {
printf("OTA prompt playback completed\r\n");
}
}
/* Product requirement: keep deleting the configured audio files before OTA. */
app_file_check_del();