Using no Broadcast logic for speed but its working now. There is to much Acks going on but for the prototyp that is okay
82 lines
3.0 KiB
C
82 lines
3.0 KiB
C
#ifndef OTA_UPDATE_H
|
|
#define OTA_UPDATE_H
|
|
|
|
#include "client_handler.h"
|
|
#include "esp_err.h"
|
|
#include "esp_now.h"
|
|
#include "esp_partition.h"
|
|
#include "message_structs.h"
|
|
#include <stdint.h>
|
|
#include <sys/types.h>
|
|
|
|
#define UPDATE_BUFFER_SIZE 4096
|
|
#define UPDATE_PAYLOAD_SIZE 200
|
|
#define UPDATE_MAX_SEQUENZES (UPDATE_BUFFER_SIZE / UPDATE_PAYLOAD_SIZE)
|
|
|
|
typedef enum {
|
|
OTA_SEND_SLAVES_PREPARE_MESSAGE,
|
|
OTA_SLAVE_WILL_PREPARE,
|
|
OTA_SLAVE_IS_PREPARED,
|
|
OTA_SLAVE_ACKED,
|
|
OTA_SLAVE_ERROR,
|
|
OTA_MASTER_SEND_PREAPRE_REQUEST,
|
|
OTA_MASTER_SEND_CHUNK,
|
|
OTA_MASTER_SEND_FINISH,
|
|
} ota_command_t;
|
|
|
|
typedef struct {
|
|
ota_command_t command;
|
|
uint8_t mac_addr[ESP_NOW_ETH_ALEN];
|
|
} ota_task_queue_message_t;
|
|
|
|
typedef struct {
|
|
ClientList *client_list;
|
|
} MasterOTA_TaskParams_t;
|
|
|
|
void init_ota();
|
|
void MasterOTATask(void *pvParameter);
|
|
void slave_ota_task(void *pvParameter);
|
|
|
|
u_int32_t get_app_size(const esp_partition_t *app_size_partition);
|
|
|
|
int prepare_ota_update();
|
|
esp_err_t write_ota_update(uint32_t write_len, const uint8_t *payload);
|
|
esp_err_t end_ota_update();
|
|
|
|
void slave_Prep_Upgrade_Callback(const esp_now_recv_info_t *esp_now_info,
|
|
const uint8_t *data, int data_len);
|
|
void slave_Update_Chunk_Callback(const esp_now_recv_info_t *esp_now_info,
|
|
const uint8_t *data, int data_len);
|
|
void slave_Update_Finished_Callback(const esp_now_recv_info_t *esp_now_info,
|
|
const uint8_t *data, int data_len);
|
|
|
|
void master_ota_prepare_acknowledge_callback(
|
|
const esp_now_recv_info_t *esp_now_info, const uint8_t *data, int data_len);
|
|
|
|
void master_ota_ready_to_recieve_callback(
|
|
const esp_now_recv_info_t *esp_now_info, const uint8_t *data, int data_len);
|
|
|
|
void master_ota_update_slave_acknowledge_callback(
|
|
const esp_now_recv_info_t *esp_now_info, const uint8_t *data, int data_len);
|
|
|
|
void start_uart_update(uint8_t msgid, const uint8_t *payload,
|
|
size_t payload_len, uint8_t *send_payload_buffer,
|
|
size_t send_payload_buffer_size, uint8_t *send_buffer,
|
|
size_t send_buffer_size);
|
|
void payload_uart_update(uint8_t msgid, const uint8_t *payload_data_from_uart,
|
|
size_t total_payload_len_from_uart,
|
|
uint8_t *send_payload_buffer,
|
|
size_t send_payload_buffer_size, uint8_t *send_buffer,
|
|
size_t send_buffer_size);
|
|
void end_uart_update(uint8_t msgid, const uint8_t *payload, size_t payload_len,
|
|
uint8_t *send_payload_buffer,
|
|
size_t send_payload_buffer_size, uint8_t *send_buffer,
|
|
size_t send_buffer_size);
|
|
|
|
void start_ota_update_espnow(uint8_t msgid, const uint8_t *payload,
|
|
size_t payload_len, uint8_t *send_payload_buffer,
|
|
size_t send_payload_buffer_size,
|
|
uint8_t *send_buffer, size_t send_buffer_size);
|
|
|
|
#endif
|