powerpods/main/ota_uart.h
simon 9b7bda8551 Distribute master OTA images to slaves over ESP-NOW.
After UART OTA the master reads the staged partition in 4 KiB blocks (200 B ESP-NOW chunks), waits for per-slave block ACKs, and fixes the final partial block. Slaves reuse ota_uart; send pacing and logging improve reliability.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-19 01:00:56 +02:00

59 lines
1.6 KiB
C

#ifndef OTA_UART_H
#define OTA_UART_H
#include "esp_err.h"
#include "esp_partition.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#define OTA_UART_HOST_CHUNK_SIZE 200u
#define OTA_UART_FLASH_BLOCK_SIZE 4096u
/** OtaStatusPayload.status values (device → host). */
typedef enum {
OTA_UART_ST_PREPARING = 1,
OTA_UART_ST_READY = 2,
OTA_UART_ST_BLOCK_ACK = 3,
OTA_UART_ST_SUCCESS = 4,
OTA_UART_ST_FAILED = 5,
} ota_uart_status_t;
typedef enum {
OTA_FEED_OK = 0,
OTA_FEED_BLOCK_WRITTEN,
OTA_FEED_ERROR,
} ota_feed_result_t;
bool ota_uart_is_active(void);
/** 0/1 while session active, else -1. */
int ota_uart_target_slot(void);
/** Begin OTA on the inactive app partition (esp_ota_begin). Returns target slot 0/1. */
int ota_uart_prepare(uint32_t total_size);
void ota_uart_abort(void);
/** Append up to 200 bytes; flushes 4 KiB blocks to flash when full. */
ota_feed_result_t ota_uart_feed(const uint8_t *data, size_t len);
uint32_t ota_uart_bytes_written(void);
/**
* Flush remainder and esp_ota_end. When set_boot is false, the staged image
* remains readable via ota_uart_get_staged_image() until ota_uart_apply_boot().
*/
esp_err_t ota_uart_finish(bool set_boot, bool *success_out);
/** Staged partition after ota_uart_finish(false, …); valid until apply_boot or abort. */
bool ota_uart_get_staged_image(const esp_partition_t **partition_out,
uint32_t *size_out);
/** Set boot partition to the last staged image (after slave distribution). */
esp_err_t ota_uart_apply_boot(void);
void ota_uart_clear_staged(void);
#endif