added all doxygen comments
This commit is contained in:
@ -1,17 +1,32 @@
|
||||
/**
|
||||
* @file Mesh_OTA_Util.c
|
||||
* @brief Utility and helper functions to perfrom mesh OTA updates
|
||||
* @author Hendrik Schutter
|
||||
* @date 21.01.2021
|
||||
*/
|
||||
|
||||
#include "Mesh_OTA_Util.h"
|
||||
#include "Mesh_OTA_Globals.h"
|
||||
|
||||
static const char *LOG_TAG = "mesh_ota";
|
||||
|
||||
/**
|
||||
* @fn bool bMeshOtaUtilNewerVersion(const char* cpu8Local, const char* cpu8Remote)
|
||||
* @brief compares to version strings
|
||||
* @param cpu8Local local image version string
|
||||
* @param cpu8Remote remote image version string
|
||||
* @return bool
|
||||
* @author Hendrik Schutter
|
||||
* @date 21.01.2021
|
||||
*
|
||||
* Returns true if remote is newer
|
||||
*/
|
||||
bool bMeshOtaUtilNewerVersion(const char* cpu8Local, const char* cpu8Remote)
|
||||
{
|
||||
/*
|
||||
* Return true if remote version is newer (higher) than local version
|
||||
*/
|
||||
char u8LocalTmp[12]; //local version
|
||||
char u8RemoteTmp[12]; //remote version
|
||||
char* pu8saveptrLocal; //context for strok_r
|
||||
char* pu8saveptrRemote; //context for strok_r
|
||||
char* pu8saveptrLocal = NULL; //context for strok_r
|
||||
char* pu8saveptrRemote = NULL; //context for strok_r
|
||||
bool bReturn = false; //flag to stop loop
|
||||
uint8_t u8Index = 0; //numbers counter in version string
|
||||
|
||||
@ -34,6 +49,18 @@ bool bMeshOtaUtilNewerVersion(const char* cpu8Local, const char* cpu8Remote)
|
||||
return bReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn esp_err_t errMeshOtaUtilExtractVersionNumber(const char* cpu8Data, uint32_t* const cpcu32DataLenght, char* const pc8RemoteVersionNumber)
|
||||
* @brief extract version number from image data
|
||||
* @param cpu8Data image data buffer
|
||||
* @param cpcu32DataLenght pointer to lenght of image data
|
||||
* @param pc8RemoteVersionNumber pointer version number
|
||||
* @return ESP32 error code
|
||||
* @author Hendrik Schutters
|
||||
* @date 21.01.2021
|
||||
*
|
||||
* Search version number in raw image data
|
||||
*/
|
||||
esp_err_t errMeshOtaUtilExtractVersionNumber(const char* cpu8Data, uint32_t* const cpcu32DataLenght, char* const pc8RemoteVersionNumber)
|
||||
{
|
||||
uint32_t u32StartOffset;
|
||||
@ -51,14 +78,25 @@ esp_err_t errMeshOtaUtilExtractVersionNumber(const char* cpu8Data, uint32_t* con
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn esp_err_t errMeshOtaUtilFindImageStart(const char* const cpu8Data, const uint32_t* const cpcu32DataLenght, uint32_t* const cpu32StartOffset)
|
||||
* @brief find start offset from image raw data
|
||||
* @param cpu8Data image data buffer
|
||||
* @param cpcu32DataLenght pointer to lenght of image data
|
||||
* @param cpu32StartOffset pointer to determined offset
|
||||
* @return ESP32 error code
|
||||
* @author Hendrik Schutter
|
||||
* @date 21.01.2021
|
||||
*
|
||||
* Search offset in raw image data from server (exclude HTTP response)
|
||||
*/
|
||||
esp_err_t errMeshOtaUtilFindImageStart(const char* const cpu8Data, const uint32_t* const cpcu32DataLenght, uint32_t* const cpu32StartOffset)
|
||||
{
|
||||
/*
|
||||
Offset value
|
||||
0 = 0xE9 (first byte in image --> magic byte)
|
||||
48 = first digit of version number
|
||||
*/
|
||||
|
||||
|
||||
// Offset value
|
||||
// 0 = 0xE9 (first byte in image --> magic byte)
|
||||
// 48 = first digit of version number
|
||||
|
||||
esp_err_t errReturn = ESP_OK;
|
||||
bool bImageStartOffsetFound = false;
|
||||
uint32_t u32DataIndex = 0;
|
||||
@ -129,13 +167,21 @@ esp_err_t errMeshOtaUtilFindImageStart(const char* const cpu8Data, const uint32_
|
||||
return errReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn esp_err_t errMeshOtaUtilSendOTAVersionRequest(const mesh_addr_t* const cpcMeshReceiverAddr)
|
||||
* @brief send OTA_Version_Request to node
|
||||
* @param cpcMeshReceiverAddr node addr
|
||||
* @return ESP32 error code
|
||||
* @author Hendrik Schutter
|
||||
* @date 21.01.2021
|
||||
*/
|
||||
esp_err_t errMeshOtaUtilSendOTAVersionRequest(const mesh_addr_t* const cpcMeshReceiverAddr)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
MESH_PACKET_t packet;
|
||||
packet.type = OTA_Version_Request;
|
||||
|
||||
const esp_partition_t* pBootPartition; //pointer to boot partition (that will booted after reset)
|
||||
const esp_partition_t* pBootPartition = NULL; //pointer to boot partition (that will booted after reset)
|
||||
esp_app_desc_t bootPartitionDesc; //Metadata from boot partition
|
||||
|
||||
pBootPartition = esp_ota_get_boot_partition(); //get boot partition (that will booted after reset), not the running partition
|
||||
@ -145,25 +191,43 @@ esp_err_t errMeshOtaUtilSendOTAVersionRequest(const mesh_addr_t* const cpcMeshRe
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn esp_err_t errMeshOtaUtilSendOTAVersionResponse(const mesh_addr_t* const cpcMeshReceiverAddr)
|
||||
* @brief send OTA_Version_Response to node
|
||||
* @param cpcMeshReceiverAddr node addr
|
||||
* @return ESP32 error code
|
||||
* @author Hendrik Schutter
|
||||
* @date 21.01.2021
|
||||
*/
|
||||
esp_err_t errMeshOtaUtilSendOTAVersionResponse(const mesh_addr_t* const cpcMeshReceiverAddr)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
MESH_PACKET_t packet;
|
||||
packet.type = OTA_Version_Response;
|
||||
|
||||
const esp_partition_t* pBootPartition; //pointer to boot partition (that will booted after reset)
|
||||
const esp_partition_t* pBootPartition = NULL; //pointer to boot partition (that will booted after reset)
|
||||
esp_app_desc_t bootPartitionDesc; //Metadata from boot partition
|
||||
|
||||
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 metadate of partition
|
||||
memcpy(&packet.au8Payload, &bootPartitionDesc.version, 12); //copy local version to OTA_Version_Response packet
|
||||
|
||||
ESP_LOGI(LOG_TAG, "Send OTA_Version_Response to 0x%x", cpcMeshReceiverAddr->addr[5]);
|
||||
ESP_LOGD(LOG_TAG, "Send OTA_Version_Response to 0x%x", cpcMeshReceiverAddr->addr[5]);
|
||||
|
||||
err = errMeshNetworkSendMeshPacket(cpcMeshReceiverAddr, &packet);
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn void vMeshOtaUtilPrintOTAProgress(const uint32_t* const cpcu32TotalImageSize, const uint32_t* const cpcu32BytesWritten, const OTA_MESH_ROLE_t ceRole)
|
||||
* @brief print LOG for OTA process progress
|
||||
* @param cpcu32TotalImageSize size of OTA partition
|
||||
* @param cpcu32BytesWritten actual bytes written
|
||||
* @param ceRole role if this OTA process
|
||||
* @return void
|
||||
* @author Hendrik Schutter
|
||||
* @date 21.01.2021
|
||||
*/
|
||||
void vMeshOtaUtilPrintOTAProgress(const uint32_t* const cpcu32TotalImageSize, const uint32_t* const cpcu32BytesWritten, const OTA_MESH_ROLE_t ceRole)
|
||||
{
|
||||
uint32_t u32Percentage = 0U;
|
||||
@ -196,6 +260,14 @@ void vMeshOtaUtilPrintOTAProgress(const uint32_t* const cpcu32TotalImageSize, co
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn void vMeshOtaUtilAddAllNeighboursToQueue(void)
|
||||
* @brief add all neigbhours (children and parent) to queue
|
||||
* @param void
|
||||
* @return void
|
||||
* @author Hendrik Schutter
|
||||
* @date 21.01.2021
|
||||
*/
|
||||
void vMeshOtaUtilAddAllNeighboursToQueue(void)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
@ -209,7 +281,6 @@ void vMeshOtaUtilAddAllNeighboursToQueue(void)
|
||||
if(err == ESP_OK)
|
||||
{
|
||||
vMeshOtaUtilAddNodeToPossibleUpdatableQueue(addrParent.addr);
|
||||
ESP_LOGI(LOG_TAG, "added parent");
|
||||
}
|
||||
|
||||
err = ESP_OK; //reset error code
|
||||
@ -219,10 +290,17 @@ void vMeshOtaUtilAddAllNeighboursToQueue(void)
|
||||
for (uint16_t u16Index = 0; ((u16Index < u16ChildrenSize) && (err == ESP_OK)); u16Index++)
|
||||
{
|
||||
vMeshOtaUtilAddNodeToPossibleUpdatableQueue(childrenAddr[u16Index].addr);
|
||||
ESP_LOGI(LOG_TAG, "added child");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn void vMeshOtaUtilClearOtaMessageQueue(const mesh_addr_t* const cpcMeshNodeAddr)
|
||||
* @brief remode all OTA messages from this node in queue
|
||||
* @param cpcMeshNodeAddr node addr
|
||||
* @return void
|
||||
* @author Hendrik Schutter
|
||||
* @date 21.01.2021
|
||||
*/
|
||||
void vMeshOtaUtilClearOtaMessageQueue(const mesh_addr_t* const cpcMeshNodeAddr)
|
||||
{
|
||||
MESH_PACKET_t sMeshPacket; //packet for sending and receiving
|
||||
@ -235,14 +313,18 @@ void vMeshOtaUtilClearOtaMessageQueue(const mesh_addr_t* const cpcMeshNodeAddr)
|
||||
//received OTA message is NOT from cpcMeshNodeAddr --> keep it in queue
|
||||
vMeshOtaUtilAddOtaMessageToQueue(&sMeshPacket);
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGI(LOG_TAG, "Removed type %i from node 0x%x", sMeshPacket.type, cpcMeshNodeAddr->addr[5]);
|
||||
}
|
||||
}
|
||||
}//end OTA message loop
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn void vMeshOtaUtilClearNeighboursQueue(const mesh_addr_t* const cpcMeshNodeAddr)
|
||||
* @brief remode all instances of this node in queue
|
||||
* @param cpcMeshNodeAddr node addr
|
||||
* @return void
|
||||
* @author Hendrik Schutter
|
||||
* @date 21.01.2021
|
||||
*/
|
||||
void vMeshOtaUtilClearNeighboursQueue(const mesh_addr_t* const cpcMeshNodeAddr)
|
||||
{
|
||||
mesh_addr_t sNode; //packet for sending and receiving
|
||||
@ -255,15 +337,18 @@ void vMeshOtaUtilClearNeighboursQueue(const mesh_addr_t* const cpcMeshNodeAddr)
|
||||
//node is NOT cpcMeshNodeAddr --> keep it in queue
|
||||
vMeshOtaUtilAddNodeToPossibleUpdatableQueue(cpcMeshNodeAddr->addr);
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGI(LOG_TAG, "Removed node 0x%x", cpcMeshNodeAddr->addr[5]);
|
||||
}
|
||||
}
|
||||
}//end OTA message loop
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn void vMeshOtaUtilAddNodeToPossibleUpdatableQueue(const uint8_t* const cpcu8MAC)
|
||||
* @brief add node instance to queue
|
||||
* @param cpcu8MAC MAC addr of node
|
||||
* @return void
|
||||
* @author Hendrik Schutter
|
||||
* @date 21.01.2021
|
||||
*/
|
||||
void vMeshOtaUtilAddNodeToPossibleUpdatableQueue(const uint8_t* const cpcu8MAC)
|
||||
{
|
||||
//send payload to node queues
|
||||
@ -276,10 +361,18 @@ void vMeshOtaUtilAddNodeToPossibleUpdatableQueue(const uint8_t* const cpcu8MAC)
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGI(LOG_TAG, "added node \"%x:%x:%x:%x:%x:%x\" to possible updatable queue", addrNode.addr[0], addrNode.addr[1], addrNode.addr[2], addrNode.addr[3], addrNode.addr[4], addrNode.addr[5]);
|
||||
ESP_LOGD(LOG_TAG, "added node \"%x:%x:%x:%x:%x:%x\" to possible updatable queue", addrNode.addr[0], addrNode.addr[1], addrNode.addr[2], addrNode.addr[3], addrNode.addr[4], addrNode.addr[5]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn void vMeshOtaUtilAddOtaMessageToQueue(const MESH_PACKET_t* const cpcuMeshPacket)
|
||||
* @brief add OTA message to queue
|
||||
* @param cpcuMeshPacket OTA message
|
||||
* @return void
|
||||
* @author Hendrik Schutter
|
||||
* @date 21.01.2021
|
||||
*/
|
||||
void vMeshOtaUtilAddOtaMessageToQueue(const MESH_PACKET_t* const cpcuMeshPacket)
|
||||
{
|
||||
//send ota packet to packet queue
|
||||
@ -292,14 +385,14 @@ void vMeshOtaUtilAddOtaMessageToQueue(const MESH_PACKET_t* const cpcuMeshPacket)
|
||||
switch (cpcuMeshPacket->type)
|
||||
{
|
||||
case OTA_Abort:
|
||||
ESP_LOGI(LOG_TAG, "added ota message to queue: OTA_Abort from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]);
|
||||
ESP_LOGD(LOG_TAG, "added ota message to queue: OTA_Abort from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]);
|
||||
break;
|
||||
case OTA_Version_Request:
|
||||
ESP_LOGI(LOG_TAG, "added ota message to queue: OTA_Version_Request from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]);
|
||||
ESP_LOGD(LOG_TAG, "added ota message to queue: OTA_Version_Request from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]);
|
||||
break;
|
||||
|
||||
case OTA_Version_Response:
|
||||
ESP_LOGI(LOG_TAG, "added ota message to queue: OTA_Version Response from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]);
|
||||
ESP_LOGD(LOG_TAG, "added ota message to queue: OTA_Version Response from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -307,14 +400,20 @@ void vMeshOtaUtilAddOtaMessageToQueue(const MESH_PACKET_t* const cpcuMeshPacket)
|
||||
}
|
||||
}
|
||||
|
||||
void vMeshOtaUtilChangeStateOfServerWorker(const bool cbState) //allow access via function ptn to network_handler
|
||||
/**
|
||||
* @fn void vMeshOtaUtilChangeStateOfServerWorker(const bool cbState)
|
||||
* @brief callback for mesh network if connectivity to server changed
|
||||
* @param cbState boolean state
|
||||
* @return void
|
||||
* @author Hendrik Schutter
|
||||
* @date 21.01.2021
|
||||
*/
|
||||
void vMeshOtaUtilChangeStateOfServerWorker(const bool cbState)
|
||||
{
|
||||
static bool bLastState = false;
|
||||
|
||||
if(cbState != bLastState) //change only if necessary
|
||||
{
|
||||
ESP_LOGI(LOG_TAG, "server worker change handler");
|
||||
|
||||
if(cbState == true)
|
||||
{
|
||||
if (xSemaphoreGive(bsStartStopServerWorker) != pdTRUE)
|
||||
|
Reference in New Issue
Block a user