powerpods/main/ota_espnow.h
simon a0f4a81a55 Add per-slave ESP-NOW OTA progress over UART and fix dashboard updates.
Expose OTA_SLAVE_PROGRESS on the master, track per-slave state during
distribution, run ESP-NOW OTA in a background task so the host can poll
while slaves update, and show master/slave progress in the dashboard
with table layout and faster WebSocket refresh during uploads.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-19 21:07:46 +02:00

41 lines
1.6 KiB
C

#ifndef OTA_ESPNOW_H
#define OTA_ESPNOW_H
#include "esp_err.h"
#include "esp_now_messages.pb.h"
#include "esp_partition.h"
#include "uart_messages.pb.h"
#include <stdint.h>
typedef struct {
/** bytes_done, total_bytes, number of slaves targeted. */
void (*aggregate)(uint32_t bytes_done, uint32_t total_bytes,
uint8_t slave_count);
/** Per-slave block ACK (slave_id, bytes_written on that slave, total_bytes). */
void (*per_slave)(uint32_t slave_id, uint32_t bytes_done, uint32_t total_bytes);
} ota_espnow_progress_cbs_t;
/** Master: read staged image from partition and push to all available slaves. */
esp_err_t ota_espnow_distribute(const esp_partition_t *partition, uint32_t size,
const ota_espnow_progress_cbs_t *progress);
/** Master: handle slave → master OTA status / block ACK. */
void ota_espnow_master_on_status(const uint8_t slave_mac[6],
const alox_EspNowOtaStatus *status);
/** Slave: handle master → slave OTA commands. */
void ota_espnow_slave_on_start(const uint8_t master_mac[6],
const alox_EspNowOtaStart *start);
void ota_espnow_slave_on_payload(const uint8_t master_mac[6],
const alox_EspNowOtaPayload *payload);
void ota_espnow_slave_on_end(const uint8_t master_mac[6]);
/**
* Fill UART OtaSlaveProgressResponse from tracked per-slave state.
* filter_client_id 0 = all slaves in the last/current distribution session.
*/
void ota_espnow_progress_query(uint32_t filter_client_id,
alox_OtaSlaveProgressResponse *out);
#endif