powerpods/main/ota_espnow.h
simon 0eea27a876 Fix web OTA upload and isolate OTA sessions across firmware and goTool.
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>
2026-05-31 16:35:18 +02:00

47 lines
1.8 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);
/** True while master is pushing a staged image to slaves. */
bool ota_espnow_distribution_active(void);
/** Slave: work queue for OTA (no esp_now_send from recv callback). */
void ota_espnow_slave_init(void);
#endif