refactor(app): 删除过时的app.js备份文件

移除 _assistant_backups 目录中的 app.js.bak_2026-05-05_0451 备份文件,
该文件包含完整的JavaScript应用程序代码,包括全局状态管理、工具函数、
日志系统、连接管理、CAN帧发送、文件处理、固件上传等功能模块。
This commit is contained in:
小龙虾
2026-05-07 23:50:04 +08:00
parent 6641ca4afd
commit adb7dc65ca
24 changed files with 1754 additions and 8969 deletions
+227 -110
View File
@@ -10,6 +10,7 @@
#include "esp_err.h"
#include "esp_partition.h"
#include "cJSON.h"
#include "aes/esp_aes.h"
#include "ota_relay.h"
#include "spi_master.h"
@@ -23,6 +24,8 @@ relay_state_t g_relay_state = RELAY_IDLE;
static const esp_partition_t *g_gd32_partition = NULL;
/** @brief OTA 认证会话上下文,包含会话密钥和 IV。 */
static session_ctx_t g_session_ctx;
static uint8_t g_nonce_server[16] = {0};
static uint8_t g_k_session[16] = {0};
/** @brief OTA 命令分发队列,从 WiFi/BLE 任务接收指令。 */
QueueHandle_t g_ota_dispatch_queue = NULL;
@@ -60,6 +63,93 @@ static ota_result_t relay_packets_from_flash(void);
*/
static ota_result_t finish_ota(void);
static int aes128_ecb_encrypt_block_local(const uint8_t *key, const uint8_t *in, uint8_t *out)
{
esp_aes_context aes;
esp_aes_init(&aes);
int ret = esp_aes_setkey(&aes, key, 128);
if (ret == 0) {
ret = esp_aes_crypt_ecb(&aes, ESP_AES_ENCRYPT, in, out);
}
esp_aes_free(&aes);
return ret;
}
static int aes128_ecb_decrypt_block_local(const uint8_t *key, const uint8_t *in, uint8_t *out)
{
esp_aes_context aes;
esp_aes_init(&aes);
int ret = esp_aes_setkey(&aes, key, 128);
if (ret == 0) {
ret = esp_aes_crypt_ecb(&aes, ESP_AES_DECRYPT, in, out);
}
esp_aes_free(&aes);
return ret;
}
static bool aes128_ecb_encrypt_48bytes_local(const uint8_t *key, const uint8_t *in, uint8_t *out)
{
for (int i = 0; i < 3; ++i) {
if (aes128_ecb_encrypt_block_local(key, in + i * 16, out + i * 16) != 0) {
return false;
}
}
return true;
}
static void calculate_crc32_with_key_local(const uint8_t *key, const uint8_t *data48, uint8_t *output)
{
uint32_t crc = 0xFFFFFFFFU;
for (int i = 0; i < 16; ++i) {
crc ^= key[i];
for (int j = 0; j < 8; ++j) {
crc = (crc >> 1) ^ (0xEDB88320U & (0U - (crc & 1U)));
}
}
for (size_t i = 0; i < GD32_OTA_PACKET_SIZE; ++i) {
crc ^= data48[i];
for (int j = 0; j < 8; ++j) {
crc = (crc >> 1) ^ (0xEDB88320U & (0U - (crc & 1U)));
}
}
crc ^= 0xFFFFFFFFU;
output[0] = (uint8_t)(crc & 0xFFU);
output[1] = (uint8_t)((crc >> 8) & 0xFFU);
output[2] = (uint8_t)((crc >> 16) & 0xFFU);
output[3] = (uint8_t)((crc >> 24) & 0xFFU);
}
static void log_resp_payload(const char *stage, uint8_t resp_type, const uint8_t *payload, size_t len)
{
char hex[193] = {0};
size_t n = (len > 32U) ? 32U : len;
for (size_t i = 0; i < n; ++i) {
snprintf(&hex[i * 2], sizeof(hex) - i * 2, "%02X", payload[i]);
}
DEBUG_INFO("OTA", "%s 响应: type=0x%02X len=%u payload[%u]=%s%s",
stage, resp_type, (unsigned)len, (unsigned)n,
n > 0 ? hex : "<empty>",
len > n ? "..." : "");
}
static esp_err_t wait_until_not_wait(const char *stage, uint8_t *resp_type,
uint8_t *resp_payload, size_t resp_max,
size_t *resp_len, uint32_t timeout_ms, uint32_t max_wait_rounds)
{
if (!resp_type) return ESP_ERR_INVALID_ARG;
uint32_t round = 0;
while (*resp_type == SPI_OTA_RSP_WAIT && round < max_wait_rounds) {
++round;
DEBUG_WARN("OTA", "%s 收到 WAIT,开始第 %u 次只读轮询...", stage, round);
esp_err_t err = spi_ota_poll_response(resp_type, resp_payload, resp_max, resp_len, timeout_ms);
if (err != ESP_OK) {
return err;
}
log_resp_payload(stage, *resp_type, resp_payload, resp_len ? *resp_len : 0);
}
return ESP_OK;
}
/**
* @brief 从 Flash 加载元数据
* @param meta 输出参数,加载后的元数据结构体。
@@ -215,28 +305,29 @@ static ota_result_t send_handshake_req(void)
DEBUG_INFO("OTA", "=== 阶段1: 握手开始 ===");
DEBUG_INFO("OTA", "发送 HANDSHAKE_REQ (0x00 0xAC)");
uint8_t tx_frame[32];
uint8_t rx_frame[32];
uint8_t payload[] = {0x00, 0xAC};
frame_build(CMD_HANDSHAKE_REQ, payload, sizeof(payload), tx_frame);
uint8_t resp_type = 0;
uint8_t resp_payload[64] = {0};
size_t resp_len = 0;
/** @brief 当前 OTA 中继状态机状态。 */
g_relay_state = RELAY_HANDSHAKE_SENT;
DEBUG_INFO("OTA", "状态: RELAY_HANDSHAKE_SENT");
esp_err_t err = spi_sync_transfer(CMD_HANDSHAKE_REQ, payload, sizeof(payload),
rx_frame, sizeof(rx_frame), 3000);
if (err != ESP_OK) {
DEBUG_ERR("OTA", "HANDSHAKE_REQ 失败, err=%d", err);
/** @brief 当前 OTA 中继状态机状态。 */
esp_err_t err = spi_ota_transfer(SPI_OTA_CMD_REQ, payload, sizeof(payload),
&resp_type, resp_payload, sizeof(resp_payload), &resp_len, 3000);
log_resp_payload("HANDSHAKE_REQ", resp_type, resp_payload, resp_len);
if (err == ESP_OK) {
err = wait_until_not_wait("HANDSHAKE_REQ", &resp_type, resp_payload, sizeof(resp_payload), &resp_len, 1000, 8);
}
if (err != ESP_OK || resp_type != SPI_OTA_RSP_ACK || resp_len < 2 ||
resp_payload[0] != 0x00 || resp_payload[1] != 0xAC) {
DEBUG_ERR("OTA", "HANDSHAKE_REQ 失败, err=%d, resp_type=0x%02X, resp_len=%zu", err, resp_type, resp_len);
g_relay_state = RELAY_ERROR;
return OTA_RESULT_ERR_TIMEOUT;
}
DEBUG_INFO("OTA", "握手请求已发送,等待 GD32 响应...");
vTaskDelay(pdMS_TO_TICKS(100));
DEBUG_INFO("OTA", "握手请求已确认");
return OTA_RESULT_OK;
}
@@ -246,66 +337,77 @@ static ota_result_t send_handshake_req(void)
*/
static ota_result_t send_nonce_and_authenticate(void)
{
uint8_t tx_frame[64];
uint8_t rx_frame[64];
uint8_t nonce_server[16];
uint8_t resp_type = 0;
uint8_t resp_payload[64] = {0};
size_t resp_len = 0;
uint32_t timestamp = xTaskGetTickCount();
uint32_t mem_addr = (uint32_t)nonce_server;
uint32_t mem_addr = (uint32_t)(uintptr_t)g_nonce_server;
uint32_t rand_seed = 0x12345678;
scramble_generate(timestamp, mem_addr, rand_seed, nonce_server);
scramble_generate(timestamp, mem_addr, rand_seed, g_nonce_server);
DEBUG_INFO("OTA", "--- 认证步骤 1: 发送 CHALLENGE ---");
DEBUG_INFO("OTA", "发送 nonce_server (16B), timestamp=0x%08X", timestamp);
/** @brief 当前 OTA 中继状态机状态。 */
g_relay_state = RELAY_CHALLENGE_SENT;
DEBUG_INFO("OTA", "状态: RELAY_CHALLENGE_SENT");
frame_build(CMD_CHALLENGE, nonce_server, 16, tx_frame);
esp_err_t err = spi_sync_transfer(CMD_CHALLENGE, nonce_server, 16,
rx_frame, sizeof(rx_frame), 5000);
if (err != ESP_OK) {
DEBUG_ERR("OTA", "CHALLENGE 发送失败, err=%d", err);
/** @brief 当前 OTA 中继状态机状态。 */
esp_err_t err = spi_ota_transfer(SPI_OTA_CMD_REQ, g_nonce_server, 16,
&resp_type, resp_payload, sizeof(resp_payload), &resp_len, 5000);
log_resp_payload("CHALLENGE", resp_type, resp_payload, resp_len);
if (err == ESP_OK) {
err = wait_until_not_wait("CHALLENGE", &resp_type, resp_payload, sizeof(resp_payload), &resp_len, 1000, 12);
}
if (err != ESP_OK || resp_type != SPI_OTA_RSP_ACK || resp_len != 36) {
DEBUG_ERR("OTA", "CHALLENGE 发送失败, err=%d, resp_type=0x%02X, resp_len=%zu", err, resp_type, resp_len);
g_relay_state = RELAY_ERROR;
return OTA_RESULT_ERR_TIMEOUT;
}
/** @brief 当前 OTA 中继状态机状态。 */
g_relay_state = RELAY_CHALLENGE_RESPOND;
DEBUG_INFO("OTA", "已收到 GD32 握手数据包");
DEBUG_INFO("OTA", "状态: RELAY_CHALLENGE_RESPOND");
// 发送 SESSION_KEY(带变换后的随机数)
uint8_t transformed_nonce[16];
memcpy(transformed_nonce, nonce_server, 16);
if (aes128_ecb_encrypt_block_local(MASTER_KEY, g_nonce_server, g_k_session) != 0) {
DEBUG_ERR("OTA", "计算 K_session 失败");
g_relay_state = RELAY_ERROR;
return OTA_RESULT_ERR_AUTH;
}
DEBUG_INFO("OTA", "--- 认证步骤 2: 发送 SESSION_KEY ---");
DEBUG_INFO("OTA", "发送变换后的随机数 (16B)");
/** @brief 当前 OTA 中继状态机状态。 */
uint8_t plaintext[16];
for (int i = 0; i < 16; ++i) {
plaintext[i] = g_nonce_server[i] ^ 0x55U;
}
uint8_t encrypted_confirm[16] = {0};
if (aes128_ecb_encrypt_block_local(g_k_session, plaintext, encrypted_confirm) != 0) {
DEBUG_ERR("OTA", "加密确认块失败");
g_relay_state = RELAY_ERROR;
return OTA_RESULT_ERR_AUTH;
}
DEBUG_INFO("OTA", "--- 认证步骤 2: 发送 SESSION_KEY/CONFIRM ---");
g_relay_state = RELAY_SESSION_KEY_SENT;
DEBUG_INFO("OTA", "状态: RELAY_SESSION_KEY_SENT");
frame_build(CMD_SESSION_KEY, transformed_nonce, 16, tx_frame);
esp_err_t err2 = spi_sync_transfer(CMD_SESSION_KEY, transformed_nonce, 16,
rx_frame, sizeof(rx_frame), 3000);
if (err2 != ESP_OK) {
DEBUG_ERR("OTA", "SESSION_KEY 发送失败, err=%d", err2);
/** @brief 当前 OTA 中继状态机状态。 */
resp_len = 0;
err = spi_ota_transfer(SPI_OTA_CMD_REQ, encrypted_confirm, 16,
&resp_type, resp_payload, sizeof(resp_payload), &resp_len, 3000);
log_resp_payload("CONFIRM", resp_type, resp_payload, resp_len);
if (err == ESP_OK) {
err = wait_until_not_wait("CONFIRM", &resp_type, resp_payload, sizeof(resp_payload), &resp_len, 1000, 8);
}
if (err != ESP_OK || resp_type != SPI_OTA_RSP_ACK || resp_len < 2 ||
resp_payload[0] != 0xBA || resp_payload[1] != 0xC0) {
DEBUG_ERR("OTA", "SESSION_KEY/CONFIRM 失败, err=%d, resp_type=0x%02X, resp_len=%zu", err, resp_type, resp_len);
g_relay_state = RELAY_ERROR;
return OTA_RESULT_ERR_TIMEOUT;
}
/** @brief 当前 OTA 中继状态机状态。 */
g_relay_state = RELAY_AUTH_COMPLETE;
DEBUG_INFO("OTA", "状态: RELAY_AUTH_COMPLETE");
DEBUG_INFO("OTA", "=== 阶段1 认证完成: 安全通道已建立 ===");
uint8_t k_session[16] = {0};
session_key_init(&g_session_ctx, k_session);
session_key_init(&g_session_ctx, g_k_session);
return OTA_RESULT_OK;
}
@@ -316,8 +418,9 @@ static ota_result_t send_nonce_and_authenticate(void)
*/
static ota_result_t send_firmware_size(uint32_t size)
{
uint8_t tx_frame[32];
uint8_t rx_frame[32];
uint8_t resp_type = 0;
uint8_t resp_payload[32] = {0};
size_t resp_len = 0;
DEBUG_INFO("OTA", "=== 阶段2: 发送固件大小 ===");
DEBUG_INFO("OTA", "固件大小: %u 字节", size);
@@ -328,22 +431,23 @@ static ota_result_t send_firmware_size(uint32_t size)
size_payload[2] = (uint8_t)((size >> 16) & 0xFF);
size_payload[3] = (uint8_t)((size >> 24) & 0xFF);
/** @brief 当前 OTA 中继状态机状态。 */
g_relay_state = RELAY_SIZE_SENT;
DEBUG_INFO("OTA", "状态: RELAY_SIZE_SENT");
frame_build(CMD_SEND_SIZE, size_payload, 4, tx_frame);
esp_err_t err = spi_sync_transfer(CMD_SEND_SIZE, size_payload, 4,
rx_frame, sizeof(rx_frame), 3000);
if (err != ESP_OK) {
DEBUG_ERR("OTA", "SEND_SIZE 失败, err=%d", err);
/** @brief 当前 OTA 中继状态机状态。 */
esp_err_t err = spi_ota_transfer(SPI_OTA_CMD_DATA, size_payload, sizeof(size_payload),
&resp_type, resp_payload, sizeof(resp_payload), &resp_len, 3000);
log_resp_payload("SEND_SIZE", resp_type, resp_payload, resp_len);
if (err == ESP_OK) {
err = wait_until_not_wait("SEND_SIZE", &resp_type, resp_payload, sizeof(resp_payload), &resp_len, 1500, 12);
}
if (err != ESP_OK || resp_type != SPI_OTA_RSP_ACK || resp_len < 2 ||
resp_payload[0] != 0xBA || resp_payload[1] != 0xC0) {
DEBUG_ERR("OTA", "SEND_SIZE 失败, err=%d, resp_type=0x%02X, resp_len=%zu", err, resp_type, resp_len);
g_relay_state = RELAY_ERROR;
return OTA_RESULT_ERR_TIMEOUT;
}
DEBUG_INFO("OTA", "大小已发送: %u 字节,等待 GD32 确认...", size);
/** @brief 当前 OTA 中继状态机状态。 */
g_relay_state = RELAY_SIZE_ACK;
DEBUG_INFO("OTA", "状态: RELAY_SIZE_ACK");
@@ -364,15 +468,16 @@ static ota_result_t relay_packets_from_flash(void)
return OTA_RESULT_ERR_STORAGE;
}
uint32_t total_packets = (meta.total_size + 47) / 48;
uint32_t total_packets = (meta.total_size + GD32_OTA_PACKET_SIZE - 1U) / GD32_OTA_PACKET_SIZE;
uint32_t flash_offset = 0;
uint8_t tx_buf[64];
uint8_t rx_buf[32];
uint8_t tx_buf[64] = {0};
uint8_t resp_type = 0;
uint8_t resp_payload[32] = {0};
size_t resp_len = 0;
ota_result_t result = OTA_RESULT_OK;
DEBUG_INFO("OTA", "总包数: %u, 每包 48 字节", total_packets);
DEBUG_INFO("OTA", "总包数: %u, 每包 %u 字节", total_packets, (unsigned)GD32_OTA_PACKET_SIZE);
DEBUG_INFO("OTA", "状态: RELAY_RELAY_ACTIVE");
/** @brief 当前 OTA 中继状态机状态。 */
g_relay_state = RELAY_RELAY_ACTIVE;
for (uint32_t seq = 0; seq < total_packets; seq++) {
@@ -384,50 +489,76 @@ static ota_result_t relay_packets_from_flash(void)
}
}
size_t chunk_size = 48;
uint8_t plain48[GD32_OTA_PACKET_SIZE];
memset(plain48, 0xFF, sizeof(plain48));
size_t chunk_size = GD32_OTA_PACKET_SIZE;
if (seq == total_packets - 1) {
chunk_size = meta.total_size - (seq * 48);
chunk_size = meta.total_size - (seq * GD32_OTA_PACKET_SIZE);
}
esp_err_t err = flash_read_chunk(flash_offset, &tx_buf[2], chunk_size);
esp_err_t err = flash_read_chunk(flash_offset, plain48, chunk_size);
if (err != ESP_OK) {
DEBUG_ERR("OTA", "Flash 读取失败, offset=%u, err=%d", flash_offset, err);
return OTA_RESULT_ERR_STORAGE;
}
tx_buf[0] = (uint8_t)(seq & 0xFF);
tx_buf[1] = (uint8_t)((seq >> 8) & 0xFF);
tx_buf[0] = 0x00; tx_buf[1] = 0x00; tx_buf[2] = 0x00; tx_buf[3] = 0x00; /* session_num 预留 */
tx_buf[4] = (uint8_t)(seq & 0xFFU);
tx_buf[5] = (uint8_t)((seq >> 8) & 0xFFU);
tx_buf[6] = 0x00;
tx_buf[7] = 0x00;
uint16_t crc = crc16_modbus(tx_buf, 2 + chunk_size);
tx_buf[2 + chunk_size] = (uint8_t)(crc & 0xFF);
tx_buf[2 + chunk_size + 1] = (uint8_t)((crc >> 8) & 0xFF);
if (!aes128_ecb_encrypt_48bytes_local(g_k_session, plain48, &tx_buf[8])) {
DEBUG_ERR("OTA", "包 %u 加密失败", seq);
return OTA_RESULT_ERR_AUTH;
}
uint32_t if_end = (seq == total_packets - 1) ? 0xFFFFFFFFU : 0x00000000U;
tx_buf[56] = (uint8_t)(if_end & 0xFFU);
tx_buf[57] = (uint8_t)((if_end >> 8) & 0xFFU);
tx_buf[58] = (uint8_t)((if_end >> 16) & 0xFFU);
tx_buf[59] = (uint8_t)((if_end >> 24) & 0xFFU);
calculate_crc32_with_key_local(g_k_session, plain48, &tx_buf[60]);
DEBUG_INFO("OTA", "包 %u: chunk=%u if_end=0x%08X crc32=%02X%02X%02X%02X",
seq, (unsigned)chunk_size, (unsigned)if_end,
tx_buf[60], tx_buf[61], tx_buf[62], tx_buf[63]);
/** @brief 当前 OTA 中继状态机状态。 */
g_relay_state = RELAY_PACKET_SENT;
uint8_t cmd = (seq == total_packets - 1) ? CMD_DATA_END : CMD_DATA_PACKET;
size_t tx_len = 2 + chunk_size + 2;
err = spi_sync_transfer(cmd, tx_buf, tx_len, rx_buf, sizeof(rx_buf), 3000);
if (err != ESP_OK) {
DEBUG_WARN("OTA", "数据包 %u 发送失败, err=%d, 重试中...", seq, err);
resp_len = 0;
err = spi_ota_transfer(SPI_OTA_CMD_DATA, tx_buf, sizeof(tx_buf),
&resp_type, resp_payload, sizeof(resp_payload), &resp_len, 3000);
log_resp_payload("DATA_PACKET", resp_type, resp_payload, resp_len);
if (err == ESP_OK) {
err = wait_until_not_wait("DATA_PACKET", &resp_type, resp_payload, sizeof(resp_payload), &resp_len, 1000, 10);
}
if (err != ESP_OK || resp_type != SPI_OTA_RSP_ACK || resp_len < 4) {
DEBUG_WARN("OTA", "数据包 %u 发送失败, err=%d, resp_type=0x%02X, resp_len=%zu", seq, err, resp_type, resp_len);
result = OTA_RESULT_ERR_TIMEOUT;
break;
}
flash_offset += chunk_size;
/** @brief 当前 OTA 中继状态机状态。 */
uint32_t ack_value = (uint32_t)resp_payload[0] |
((uint32_t)resp_payload[1] << 8) |
((uint32_t)resp_payload[2] << 16) |
((uint32_t)resp_payload[3] << 24);
uint32_t expected_ack = (seq == total_packets - 1) ? 0xFFFFFFFFU : (seq + 1U);
if (ack_value != expected_ack) {
DEBUG_ERR("OTA", "包 %u ACK 不匹配: got=0x%08X expected=0x%08X", seq, ack_value, expected_ack);
result = OTA_RESULT_ERR_GD32;
break;
}
flash_offset += (uint32_t)chunk_size;
g_relay_state = RELAY_PACKET_ACK_OK;
// 每 10% 记录一次进度
if (seq % (total_packets / 10 + 1) == 0) {
uint32_t progress = (seq * 100) / total_packets;
DEBUG_INFO("OTA", "转发进度: %u/%u 包 (%u%%)",
seq, total_packets, progress);
uint32_t progress = (seq * 100U) / total_packets;
DEBUG_INFO("OTA", "转发进度: %u/%u 包 (%u%%)", seq, total_packets, progress);
}
}
/** @brief 当前 OTA 中继状态机状态。 */
g_relay_state = RELAY_RECEIVE_DONE;
DEBUG_INFO("OTA", "状态: RELAY_RECEIVE_DONE");
return result;
@@ -440,39 +571,18 @@ static ota_result_t relay_packets_from_flash(void)
static ota_result_t finish_ota(void)
{
DEBUG_INFO("OTA", "=== 阶段4: 结束 OTA ===");
DEBUG_INFO("OTA", "发送 FINISH_OTA (0x0A 0xAC)");
uint8_t tx_frame[16];
uint8_t rx_frame[16];
uint8_t payload[] = {0x0A, 0xAC};
frame_build(CMD_FINISH_OTA, payload, sizeof(payload), tx_frame);
/** @brief 当前 OTA 中继状态机状态。 */
g_relay_state = RELAY_FINISH_SENT;
DEBUG_INFO("OTA", "状态: RELAY_FINISH_SENT");
esp_err_t err = spi_sync_transfer(CMD_FINISH_OTA, payload, sizeof(payload),
rx_frame, sizeof(rx_frame), 5000);
if (err != ESP_OK) {
DEBUG_ERR("OTA", "FINISH_OTA 失败, err=%d", err);
/** @brief 当前 OTA 中继状态机状态。 */
g_relay_state = RELAY_ERROR;
return OTA_RESULT_ERR_TIMEOUT;
}
DEBUG_INFO("OTA", "等待 GD32 跳转确认...");
DEBUG_INFO("OTA", "GD32 当前实现已在最后一个 DATA 包后自行 ACK 并跳转,无需额外 FINISH 命令");
session_key_clear(&g_session_ctx);
memset(&g_session_ctx, 0, sizeof(session_ctx_t));
memset(g_k_session, 0, sizeof(g_k_session));
memset(g_nonce_server, 0, sizeof(g_nonce_server));
/** @brief 当前 OTA 中继状态机状态。 */
g_relay_state = RELAY_DONE;
DEBUG_INFO("OTA", "状态: RELAY_DONE");
DEBUG_INFO("OTA", "=== OTA 完成 ===");
meta_clear();
return OTA_RESULT_OK;
}
@@ -567,11 +677,20 @@ void ota_relay_task(void *pvParameters)
/** @brief OTA 结果回传队列,将执行结果返回给调用方。 */
g_ota_result_queue = xQueueCreate(4, sizeof(uint32_t));
uint32_t msg;
BaseType_t ret = xQueueReceive(g_ota_dispatch_queue, &msg, portMAX_DELAY);
if (!g_ota_dispatch_queue || !g_ota_result_queue) {
DEBUG_ERR("OTA", "OTA 队列创建失败");
vTaskDelete(NULL);
return;
}
if (ret == pdTRUE) {
DEBUG_INFO("OTA", "收到 OTA 调度信号,开始转发...");
while (1) {
uint32_t msg = 0;
BaseType_t ret = xQueueReceive(g_ota_dispatch_queue, &msg, portMAX_DELAY);
if (ret != pdTRUE) {
continue;
}
DEBUG_INFO("OTA", "收到 OTA 调度信号: %lu,开始转发...", (unsigned long)msg);
ota_result_t result = ota_relay_forward_firmware();
uint32_t result_msg = (uint32_t)result;
@@ -581,9 +700,7 @@ void ota_relay_task(void *pvParameters)
DEBUG_INFO("OTA", "OTA 转发成功完成");
} else {
DEBUG_ERR("OTA", "OTA 转发失败,错误码: %d", result);
ota_relay_reset();
}
}
DEBUG_INFO("OTA", "OTA 中继任务结束");
vTaskDelete(NULL);
}