added all doxygen comments

This commit is contained in:
2021-01-21 11:11:37 +01:00
parent f3749b9985
commit 7fe1f18985
11 changed files with 406 additions and 112 deletions

View File

@ -1,3 +1,10 @@
/**
* @file Mesh_OTA.c
* @brief Start and implement OTA updates via HTTPS from server and other mesh nodes (bidirectional)
* @author Hendrik Schutter
* @date 21.01.2021
*/
#include "Mesh_OTA.h"
#include "Mesh_OTA_Util.h"
#include "Mesh_OTA_Globals.h"
@ -5,7 +12,18 @@
static const char *LOG_TAG = "mesh_ota";
esp_err_t errMeshOTAInitialize()
/**
* @fn esp_err_t errMeshOTAInitialize(void)
* @brief Starts Mesh OTA functionality
* @param void
* @return ESP32 error code
* @author Hendrik Schutter
* @date 21.01.2021
*
* Initialize queues and tasks
* Set callbacks
*/
esp_err_t errMeshOTAInitialize(void)
{
esp_err_t err = ESP_OK;
BaseType_t xReturned;
@ -15,7 +33,7 @@ esp_err_t errMeshOTAInitialize()
queueNodes = xQueueCreate(QUEUE_NODES_SIZE, sizeof(mesh_addr_t));
if (queueNodes == 0) // Queue not created
{
ESP_LOGE(LOG_TAG, "Unable to create Queue for Nodes");
ESP_LOGE(LOG_TAG, "Unable to create queue for nodes");
err = ESP_FAIL;
}
@ -25,7 +43,7 @@ esp_err_t errMeshOTAInitialize()
queueMessageOTA = xQueueCreate(QUEUE_MESSAGE_OTA_SIZE, sizeof(MESH_PACKET_t));
if (queueMessageOTA == 0) // Queue not created
{
ESP_LOGE(LOG_TAG, "Unable to create Queue for OTA Messages");
ESP_LOGE(LOG_TAG, "Unable to create queue for OTA messages");
err = ESP_FAIL;
}
}
@ -35,7 +53,7 @@ esp_err_t errMeshOTAInitialize()
bsStartStopServerWorker = xSemaphoreCreateBinary();
if( bsStartStopServerWorker == NULL )
{
ESP_LOGE(LOG_TAG, "Unable to create Mutex to represent state of Server worker");
ESP_LOGE(LOG_TAG, "Unable to create mutex to represent state of server worker");
err = ESP_FAIL;
}
}
@ -45,7 +63,7 @@ esp_err_t errMeshOTAInitialize()
bsOTAProcess = xSemaphoreCreateBinary();
if( bsOTAProcess == NULL )
{
ESP_LOGE(LOG_TAG, "Unable to create Mutex to grant access to OTA Process");
ESP_LOGE(LOG_TAG, "Unable to create mutex to grant access to OTA process");
err = ESP_FAIL;
}
}
@ -55,11 +73,12 @@ esp_err_t errMeshOTAInitialize()
xSemaphoreGive(bsOTAProcess); //unlock binary semaphore
if( bsOTAProcess == NULL )
{
ESP_LOGE(LOG_TAG, "Unable to unlock Mutex to grant access to OTA Process");
ESP_LOGE(LOG_TAG, "Unable to unlock mutex to grant access to OTA process");
err = ESP_FAIL;
}
}
//register callbacks in network
ERROR_CHECK(errMeshNetworkSetChildConnectedHandle(vMeshOtaUtilAddNodeToPossibleUpdatableQueue));
ERROR_CHECK(errMeshNetworkSetOTAMessageHandleHandle(vMeshOtaUtilAddOtaMessageToQueue));
ERROR_CHECK(errMeshNetworkSetChangeStateOfServerWorkerHandle(vMeshOtaUtilChangeStateOfServerWorker));
@ -99,9 +118,17 @@ esp_err_t errMeshOTAInitialize()
return err;
}
/**
* @fn void vMeshOtaTaskServerWorker(void *arg)
* @brief Task for updating from server via HTTPS
* @param arg
* @return void
* @author Hendrik Schutter
* @date 21.01.2021
*/
void vMeshOtaTaskServerWorker(void *arg)
{
esp_err_t err;
esp_err_t err = ESP_OK;
bool bNewOTAImage; //true if a new ota image was downloaded and validated
bool bFirstRun = true;
@ -118,6 +145,7 @@ void vMeshOtaTaskServerWorker(void *arg)
if(bFirstRun == true)
{
//init on first run
ERROR_CHECK(errHTTPSClientInitialize());
bFirstRun = false;
}
@ -141,6 +169,14 @@ void vMeshOtaTaskServerWorker(void *arg)
}
}
/**
* @fn void vMeshOtaTaskServerWorker(void *arg)
* @brief Task for updating from nodes in mesh network
* @param arg
* @return void
* @author Hendrik Schutter
* @date 21.01.2021
*/
void vMeshOtaTaskOTAWorker(void *arg)
{
esp_err_t err = ESP_OK;
@ -155,8 +191,6 @@ void vMeshOtaTaskOTAWorker(void *arg)
if((uxQueueSpacesAvailable(queueNodes) - QUEUE_NODES_SIZE) == 0)
{
//nodes queue is empty
ESP_LOGI(LOG_TAG, "nodes queue is empty");
if((bWantReboot == true) && (OTA_ALLOW_REBOOT == 1))
{
ESP_LOGE(LOG_TAG, "ESP32 Reboot ...");
@ -169,8 +203,6 @@ void vMeshOtaTaskOTAWorker(void *arg)
else
{
//queue not empty
ESP_LOGI(LOG_TAG, "nodes queue not empty: %i", (QUEUE_NODES_SIZE - uxQueueSpacesAvailable(queueNodes)));
if (xQueueReceive(queueNodes, &meshNodeAddr, ((100) / portTICK_PERIOD_MS)) != pdTRUE)
{
ESP_LOGE(LOG_TAG, "Unable to receive OTA Messages from Queue");
@ -188,7 +220,6 @@ void vMeshOtaTaskOTAWorker(void *arg)
{
vMeshOtaUtilClearNeighboursQueue(&meshNodeAddr); //remove this node from queue
}
}
if(bNewOTAImage == true)
@ -196,18 +227,28 @@ void vMeshOtaTaskOTAWorker(void *arg)
//set want reboot
ESP_LOGI(LOG_TAG, "Updated successfully via Mesh, set pending reboot");
bWantReboot = true;
vMeshOtaUtilAddAllNeighboursToQueue(); //add all existing neighbours to queue
}
vTaskDelay( (1000) / portTICK_PERIOD_MS);
}
}
/**
* @fn esp_err_t errMeshOtaSlaveEndpoint(bool* const cpbNewOTAImage)
* @brief Endpoint for OTA process that is called from remote node
* @param cpbNewOTAImage pointer to boolean to signal if a new image was successfully received
* @return ESP32 error code
* @author Hendrik Schutter
* @date 21.01.2021
*
* Answers the OTA_Version_Request with OTA_Version_Response
* calls errMeshOtaPartitionAccessMeshReceive OR errMeshOtaPartitionAccessMeshTransmit based on version number
*/
esp_err_t errMeshOtaSlaveEndpoint(bool* const cpbNewOTAImage)
{
esp_err_t err = ESP_OK;
MESH_PACKET_t sOTAMessage;
const esp_partition_t* pBootPartition; //pointer to boot partition (that will booted after reset)
const esp_partition_t* cpBootPartition = NULL; //pointer to boot partition (that will booted after reset)
esp_app_desc_t bootPartitionDesc; //Metadate from boot partition
*cpbNewOTAImage = false; //set default false
@ -225,8 +266,8 @@ esp_err_t errMeshOtaSlaveEndpoint(bool* const cpbNewOTAImage)
{
xSemaphoreTake(bsOTAProcess, portMAX_DELAY); //wait for binary semaphore that allows to start the OTA process
pBootPartition = esp_ota_get_boot_partition(); //get boot partition (that will booted after reset), not the running partition
ERROR_CHECK(esp_ota_get_partition_description(pBootPartition, &bootPartitionDesc)); //get metadata of partition
cpBootPartition = esp_ota_get_boot_partition(); //get boot partition (that will booted after reset), not the running partition
ERROR_CHECK(esp_ota_get_partition_description(cpBootPartition, &bootPartitionDesc)); //get metadata of partition
//send OTA_Version_Response to sender of OTA_Version_Request packet wirh version in payload
ERROR_CHECK(errMeshOtaUtilSendOTAVersionResponse(&sOTAMessage.meshSenderAddr));
@ -252,11 +293,23 @@ esp_err_t errMeshOtaSlaveEndpoint(bool* const cpbNewOTAImage)
return err;
}
/**
* @fn esp_err_t errMeshOtaMasterEndpoint(bool* const cpbNewOTAImage, const mesh_addr_t* const cpcMeshNodeAddr)
* @brief Endpoint for OTA process that calls remote node
* @param cpbNewOTAImage pointer to boolean to signal if a new image was successfully received
* @param cpcMeshNodeAddr pointer to remote node addr
* @return ESP32 error code
* @author Hendrik Schutter
* @date 21.01.2021
*
* Sends the OTA_Version_Request to remote node
* calls errMeshOtaPartitionAccessMeshReceive OR errMeshOtaPartitionAccessMeshTransmit based on version number received
*/
esp_err_t errMeshOtaMasterEndpoint(bool* const cpbNewOTAImage, const mesh_addr_t* const cpcMeshNodeAddr)
{
esp_err_t err = ESP_OK;
MESH_PACKET_t sOTAMessage;
const esp_partition_t* pBootPartition; //pointer to boot partition (that will booted after reset)
const esp_partition_t* cpBootPartition = NULL; //pointer to boot partition (that will booted after reset)
esp_app_desc_t bootPartitionDesc; //Metadata from boot partition
bool bNodeIsConnected = false;
bool bNodeIsResponding = false;
@ -268,7 +321,6 @@ esp_err_t errMeshOtaMasterEndpoint(bool* const cpbNewOTAImage, const mesh_addr_t
bNodeIsConnected = true; //node is one of the neighbours
xSemaphoreTake(bsOTAProcess, portMAX_DELAY); //wait for binary semaphore that allows to start the OTA process
ESP_LOGI(LOG_TAG, "Mesh-Master: send Version_Request to 0x%x", cpcMeshNodeAddr->addr[5]);
ERROR_CHECK(errMeshOtaUtilSendOTAVersionRequest(cpcMeshNodeAddr)); //send OTA_VERSION_REQUEST with local version in payload
for (uint32_t u32Index = 0; u32Index < QUEUE_MESSAGE_OTA_SIZE; u32Index++) //loop through all OTA messages
@ -285,8 +337,8 @@ esp_err_t errMeshOtaMasterEndpoint(bool* const cpbNewOTAImage, const mesh_addr_t
if((err == ESP_OK) && (sOTAMessage.type == OTA_Version_Response) && (bMeshNetworkCheckMACEquality(sOTAMessage.meshSenderAddr.addr, cpcMeshNodeAddr->addr))) //if OTA_Version_Request
{
bNodeIsResponding = true;
pBootPartition = esp_ota_get_boot_partition(); //get boot partition (that will booted after reset), not the running partition
ERROR_CHECK(esp_ota_get_partition_description(pBootPartition, &bootPartitionDesc)); //get metadata of partition
cpBootPartition = esp_ota_get_boot_partition(); //get boot partition (that will booted after reset), not the running partition
ERROR_CHECK(esp_ota_get_partition_description(cpBootPartition, &bootPartitionDesc)); //get metadata of partition
if((bMeshOtaUtilNewerVersion((bootPartitionDesc).version, (char*) sOTAMessage.au8Payload)) && (err == ESP_OK)) //compare local and remote version
{
@ -313,7 +365,7 @@ esp_err_t errMeshOtaMasterEndpoint(bool* const cpbNewOTAImage, const mesh_addr_t
else
{
// OTA Message queue is empty --> wait some time
ESP_LOGI(LOG_TAG, "OTA-Master: OTA Message queue is empty --> wait some time");
ESP_LOGD(LOG_TAG, "OTA-Master: OTA Message queue is empty --> wait some time");
vTaskDelay( (1000/QUEUE_MESSAGE_OTA_SIZE) / portTICK_PERIOD_MS);
}
}//end loop
@ -323,7 +375,7 @@ esp_err_t errMeshOtaMasterEndpoint(bool* const cpbNewOTAImage, const mesh_addr_t
if((bNodeIsResponding == false) && (bNodeIsConnected == true))
{
//add node back to queue if connected and NOT responding
ESP_LOGI(LOG_TAG, "OTA-Master: connected and NOT responding --> add node back to queue ");
ESP_LOGD(LOG_TAG, "OTA-Master: connected and NOT responding --> add node back to queue ");
vMeshOtaUtilAddNodeToPossibleUpdatableQueue(cpcMeshNodeAddr->addr);
}
return err;