Split ESP-NOW into core/master/slave modules, block non-OTA UART traffic during updates, and hold the host serial port exclusively so dashboard polling cannot interleave with firmware uploads. Co-authored-by: Cursor <cursoragent@cursor.com>
54 lines
1.8 KiB
C
54 lines
1.8 KiB
C
#include "cmd_ota_slave_progress.h"
|
|
#include "ota_espnow.h"
|
|
#include "uart_cmd.h"
|
|
#include "esp_log.h"
|
|
|
|
static const char *TAG = "[OTA_PROG]";
|
|
|
|
static void handle_ota_slave_progress(const uint8_t *data, size_t len) {
|
|
alox_UartMessage uart_msg;
|
|
uint32_t filter = 0;
|
|
|
|
if (len > 0) {
|
|
if (uart_cmd_decode(data, len, &uart_msg) != ESP_OK) {
|
|
ESP_LOGW(TAG, "decode failed");
|
|
alox_UartMessage response;
|
|
uart_cmd_init_response(
|
|
&response, alox_MessageType_OTA_SLAVE_PROGRESS,
|
|
alox_UartMessage_ota_slave_progress_response_tag);
|
|
uart_cmd_send(&response, TAG);
|
|
return;
|
|
}
|
|
const alox_OtaSlaveProgressRequest *req =
|
|
UART_CMD_REQ(&uart_msg, alox_UartMessage_ota_slave_progress_request_tag,
|
|
ota_slave_progress_request);
|
|
if (req == NULL) {
|
|
ESP_LOGW(TAG, "missing ota_slave_progress_request");
|
|
alox_UartMessage response;
|
|
uart_cmd_init_response(
|
|
&response, alox_MessageType_OTA_SLAVE_PROGRESS,
|
|
alox_UartMessage_ota_slave_progress_response_tag);
|
|
uart_cmd_send(&response, TAG);
|
|
return;
|
|
}
|
|
filter = req->client_id;
|
|
}
|
|
|
|
alox_UartMessage response;
|
|
uart_cmd_init_response(
|
|
&response, alox_MessageType_OTA_SLAVE_PROGRESS,
|
|
alox_UartMessage_ota_slave_progress_response_tag);
|
|
ota_espnow_progress_query(filter, &response.payload.ota_slave_progress_response);
|
|
|
|
ESP_LOGI(TAG, "query client_id=%lu -> %u slave(s) active=%d",
|
|
(unsigned long)filter,
|
|
(unsigned)response.payload.ota_slave_progress_response.slaves_count,
|
|
(int)response.payload.ota_slave_progress_response.active);
|
|
uart_cmd_send(&response, TAG);
|
|
}
|
|
|
|
void cmd_ota_slave_progress_register(void) {
|
|
uart_cmd_register(alox_MessageType_OTA_SLAVE_PROGRESS,
|
|
handle_ota_slave_progress);
|
|
}
|