2021-01-02 10:57:03 +01:00
# ifndef H_MESH_OTA
# define H_MESH_OTA
2021-01-02 00:30:13 +01:00
2021-01-02 10:57:03 +01:00
# include <string.h>
# include "esp_wifi.h"
2021-01-02 00:30:13 +01:00
# include "esp_system.h"
# include "esp_event.h"
# include "esp_log.h"
2021-01-02 10:57:03 +01:00
# include "esp_mesh.h"
# include "esp_mesh_internal.h"
# include "nvs_flash.h"
# include "driver/gpio.h"
# include "esp_ota_ops.h"
# include "esp_partition.h"
2021-01-02 00:30:13 +01:00
2021-01-11 22:56:39 +01:00
# include "Mesh_network.h"
2021-01-17 23:47:59 +01:00
# include "HTTPS_client.h"
2021-01-11 15:22:45 +01:00
# define ERASE_NVS //erase non volatile storage if full
2021-01-17 23:27:01 +01:00
# define QUEUE_NODES_SIZE 10
# define QUEUE_MESSAGE_OTA_SIZE 10
# define SERVER_CHECK_INTERVAL 30 //in seconds
2021-01-18 17:38:08 +01:00
# define OTA_HTTPS_SEGMENT_SIZE 2048U
2021-01-18 19:03:32 +01:00
# define OTA_PROGRESS_LOG_INTERVAL 7U
2021-01-11 15:22:45 +01:00
# define ERROR_CHECK(x) if (err == ESP_OK) \
{ \
err = ( x ) ; \
if ( err ! = ESP_OK ) \
{ \
2021-01-17 23:27:01 +01:00
ESP_LOGE ( LOG_TAG , " %s failed with error: 0x%x -> %s " , # x , err , esp_err_to_name ( err ) ) ; \
2021-01-11 15:22:45 +01:00
} \
} \
2021-01-16 18:23:10 +01:00
2021-01-17 23:27:01 +01:00
esp_err_t errMeshOTAInitialize ( ) ;
2021-01-02 00:30:13 +01:00
2021-01-18 12:49:52 +01:00
esp_err_t errOTAHTTPS ( bool * pbNewOTAImage ) ;
2021-01-17 23:27:01 +01:00
//helper functions
2021-01-06 18:10:12 +01:00
bool bNewerVersion ( const char * pu8Local , const char * pu8Remote ) ;
2021-01-07 23:10:36 +01:00
esp_err_t errExtractVersionNumber ( const char * pu8Data , uint32_t * pu32DataLenght , char * pc8RemoteVersionNumber ) ;
esp_err_t errFindImageStart ( const char * pu8Data , uint32_t * pu32DataLenght , uint32_t * pu32StartOffset ) ;
2021-01-18 19:03:32 +01:00
void vPrintOTAProgress ( const uint32_t * const pu32TotalImageSize , const uint32_t * const pu32BytesWritten ) ;
2021-01-18 22:56:42 +01:00
void vAddAllNeighboursToQueue ( void ) ;
2021-01-02 10:57:03 +01:00
2021-01-17 23:27:01 +01:00
//Handler
2021-01-18 22:56:42 +01:00
void vAddNodeToPossibleUpdatableQueue ( uint8_t * pu8MAC ) ;
2021-01-17 23:27:01 +01:00
void vAddOTAControllMessageToQueue ( MESH_PACKET_t * puMeshPacket ) ;
void vChangeStateOfServerWorker ( bool state ) ;
//Tasks
2021-01-18 22:56:42 +01:00
void vTaskServerWorker ( void * arg ) ;
void vTaskOTAWorker ( void * arg ) ;
2021-01-17 23:27:01 +01:00
2021-01-02 10:57:03 +01:00
# endif /* H_MESH_OTA */