renamed functions in modules
This commit is contained in:
@ -3,76 +3,7 @@
|
||||
|
||||
static const char *LOG_TAG = "mesh_ota";
|
||||
|
||||
void vAddNodeToPossibleUpdatableQueue(uint8_t* pu8MAC)
|
||||
{
|
||||
//send payload to node queues
|
||||
mesh_addr_t addrNode;
|
||||
memcpy(&addrNode.addr, (uint8_t *)pu8MAC, 6); //copy MAC
|
||||
|
||||
if (xQueueSend(queueNodes, &addrNode, portMAX_DELAY) != pdPASS)
|
||||
{
|
||||
ESP_LOGE(LOG_TAG, "Unable to push node into node queue");
|
||||
}
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
void vAddOtaMessageToQueue(MESH_PACKET_t* puMeshPacket)
|
||||
{
|
||||
//send ota packet to packet queue
|
||||
if (xQueueSend(queueMessageOTA, puMeshPacket, portMAX_DELAY) != pdPASS)
|
||||
{
|
||||
ESP_LOGE(LOG_TAG, "Unable to push ota packet into packet queue");
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (puMeshPacket->type)
|
||||
{
|
||||
case OTA_Abort:
|
||||
ESP_LOGI(LOG_TAG, "added ota message to queue: OTA_Abort from 0x%x", puMeshPacket->meshSenderAddr.addr[5]);
|
||||
break;
|
||||
case OTA_Version_Request:
|
||||
ESP_LOGI(LOG_TAG, "added ota message to queue: OTA_Version_Request from 0x%x", puMeshPacket->meshSenderAddr.addr[5]);
|
||||
break;
|
||||
|
||||
case OTA_Version_Response:
|
||||
ESP_LOGI(LOG_TAG, "added ota message to queue: OTA_Version Response from 0x%x", puMeshPacket->meshSenderAddr.addr[5]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void vChangeStateOfServerWorker(bool bState) //allow access via function ptn to networl_handler
|
||||
{
|
||||
static bool bLastState = false;
|
||||
|
||||
if(bState != bLastState) //change only if necessary
|
||||
{
|
||||
ESP_LOGI(LOG_TAG, "server worker change handler");
|
||||
|
||||
if(bState == true)
|
||||
{
|
||||
if (xSemaphoreGive(bsStartStopServerWorker) != pdTRUE)
|
||||
{
|
||||
ESP_LOGE(LOG_TAG, "Unable to give mutex to activate the server worker");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xSemaphoreTake(bsStartStopServerWorker,( TickType_t ) 10 ) != pdTRUE)
|
||||
{
|
||||
ESP_LOGE(LOG_TAG, "Unable to obtain mutex to deactivate the server worker");
|
||||
}
|
||||
}
|
||||
bLastState = bState;
|
||||
}
|
||||
}
|
||||
|
||||
bool bNewerVersion(const char* pu8Local, const char* pu8Remote)
|
||||
bool bMeshOtaUtilNewerVersion(const char* pu8Local, const char* pu8Remote)
|
||||
{
|
||||
/*
|
||||
* Return true if remote version is newer (higher) than local version
|
||||
@ -103,7 +34,24 @@ bool bNewerVersion(const char* pu8Local, const char* pu8Remote)
|
||||
return bReturn;
|
||||
}
|
||||
|
||||
esp_err_t errFindImageStart(const char* pu8Data, uint32_t* pu32DataLenght, uint32_t* pu32StartOffset)
|
||||
esp_err_t errMeshOtaUtilExtractVersionNumber(const char* pu8Data, uint32_t* pu32DataLenght, char* pc8RemoteVersionNumber)
|
||||
{
|
||||
uint32_t u32StartOffset;
|
||||
esp_err_t err = ESP_OK;
|
||||
|
||||
strcpy(pc8RemoteVersionNumber, "999.999.999"); //init value
|
||||
err = errMeshOtaUtilFindImageStart(pu8Data, pu32DataLenght, &u32StartOffset); //get image start offset
|
||||
|
||||
if(err == ESP_OK)
|
||||
{
|
||||
//image found
|
||||
strncpy(pc8RemoteVersionNumber, pu8Data+(u32StartOffset+48), 11); //copy version number
|
||||
pc8RemoteVersionNumber[12] = '\0';
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t errMeshOtaUtilFindImageStart(const char* pu8Data, uint32_t* pu32DataLenght, uint32_t* pu32StartOffset)
|
||||
{
|
||||
/*
|
||||
Offset value
|
||||
@ -181,24 +129,42 @@ esp_err_t errFindImageStart(const char* pu8Data, uint32_t* pu32DataLenght, uint3
|
||||
return errReturn;
|
||||
}
|
||||
|
||||
esp_err_t errExtractVersionNumber(const char* pu8Data, uint32_t* pu32DataLenght, char* pc8RemoteVersionNumber)
|
||||
esp_err_t errMeshOtaUtilSendOTAVersionRequest(mesh_addr_t* pMeshReceiverAddr)
|
||||
{
|
||||
uint32_t u32StartOffset;
|
||||
esp_err_t err = ESP_OK;
|
||||
MESH_PACKET_t packet;
|
||||
packet.type = OTA_Version_Request;
|
||||
|
||||
strcpy(pc8RemoteVersionNumber, "999.999.999"); //init value
|
||||
err = errFindImageStart(pu8Data, pu32DataLenght, &u32StartOffset); //get image start offset
|
||||
const esp_partition_t* pBootPartition; //pointer to boot partition (that will booted after reset)
|
||||
esp_app_desc_t bootPartitionDesc; //Metadata from boot partition
|
||||
|
||||
if(err == ESP_OK)
|
||||
{
|
||||
//image found
|
||||
strncpy(pc8RemoteVersionNumber, pu8Data+(u32StartOffset+48), 11); //copy version number
|
||||
pc8RemoteVersionNumber[12] = '\0';
|
||||
}
|
||||
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_Request packet
|
||||
err = errMeshNetworkSendMeshPacket(pMeshReceiverAddr, &packet);
|
||||
return err;
|
||||
}
|
||||
|
||||
void vPrintOTAProgress(const uint32_t* const pu32TotalImageSize, const uint32_t* const pu32BytesWritten, OTA_MESH_ROLE_t eRole)
|
||||
esp_err_t errMeshOtaUtilSendOTAVersionResponse(mesh_addr_t* pMeshReceiverAddr)
|
||||
{
|
||||
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)
|
||||
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", pMeshReceiverAddr->addr[5]);
|
||||
|
||||
err = errMeshNetworkSendMeshPacket(pMeshReceiverAddr, &packet);
|
||||
return err;
|
||||
}
|
||||
|
||||
void vMeshOtaUtilPrintOTAProgress(const uint32_t* const pu32TotalImageSize, const uint32_t* const pu32BytesWritten, OTA_MESH_ROLE_t eRole)
|
||||
{
|
||||
uint32_t u32Percentage = 0U;
|
||||
static uint32_t u32LastPercentage = 0U;
|
||||
@ -230,7 +196,7 @@ void vPrintOTAProgress(const uint32_t* const pu32TotalImageSize, const uint32_t*
|
||||
}
|
||||
}
|
||||
|
||||
void vAddAllNeighboursToQueue(void)
|
||||
void vMeshOtaUtilAddAllNeighboursToQueue(void)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
|
||||
@ -238,55 +204,36 @@ void vAddAllNeighboursToQueue(void)
|
||||
mesh_addr_t childrenAddr[CONFIG_MESH_ROUTE_TABLE_SIZE]; //array of children attached to this node
|
||||
uint16_t u16ChildrenSize = 0U; //number of children attached to this node
|
||||
|
||||
err = errGetParentNode(&addrParent);
|
||||
err = errMeshNetworkGetParentNode(&addrParent);
|
||||
|
||||
if(err == ESP_OK)
|
||||
{
|
||||
vAddNodeToPossibleUpdatableQueue(addrParent.addr);
|
||||
vMeshOtaUtilAddNodeToPossibleUpdatableQueue(addrParent.addr);
|
||||
ESP_LOGI(LOG_TAG, "added parent");
|
||||
}
|
||||
|
||||
err = ESP_OK; //reset error code
|
||||
|
||||
ERROR_CHECK(errGetChildren(childrenAddr, &u16ChildrenSize)); //get all children
|
||||
ERROR_CHECK(errMeshNetworkGetChildren(childrenAddr, &u16ChildrenSize)); //get all children
|
||||
|
||||
for (uint16_t u16Index = 0; ((u16Index < u16ChildrenSize) && (err == ESP_OK)); u16Index++)
|
||||
{
|
||||
vAddNodeToPossibleUpdatableQueue(childrenAddr[u16Index].addr);
|
||||
vMeshOtaUtilAddNodeToPossibleUpdatableQueue(childrenAddr[u16Index].addr);
|
||||
ESP_LOGI(LOG_TAG, "added child");
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t errSendOTAVersionResponse(mesh_addr_t* pMeshReceiverAddr)
|
||||
{
|
||||
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)
|
||||
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", pMeshReceiverAddr->addr[5]);
|
||||
|
||||
err = errSendMeshPacket(pMeshReceiverAddr, &packet);
|
||||
return err;
|
||||
}
|
||||
|
||||
void vClearOtaMessageQueue(mesh_addr_t* pMeshNodeAddr)
|
||||
void vMeshOtaUtilClearOtaMessageQueue(mesh_addr_t* pMeshNodeAddr)
|
||||
{
|
||||
MESH_PACKET_t sMeshPacket; //packet for sending and receiving
|
||||
for (uint32_t u32Index = 0; (u32Index < QUEUE_MESSAGE_OTA_SIZE); u32Index++) //loop through all OTA messages
|
||||
{
|
||||
if (xQueueReceive(queueMessageOTA, &sMeshPacket, 0) == pdTRUE)
|
||||
{
|
||||
if(!(bCheckMACEquality(sMeshPacket.meshSenderAddr.addr, pMeshNodeAddr->addr)))
|
||||
if(!(bMeshNetworkCheckMACEquality(sMeshPacket.meshSenderAddr.addr, pMeshNodeAddr->addr)))
|
||||
{
|
||||
//received OTA message is NOT from pMeshNodeAddr --> keep it in queue
|
||||
vAddOtaMessageToQueue(&sMeshPacket);
|
||||
vMeshOtaUtilAddOtaMessageToQueue(&sMeshPacket);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -296,19 +243,71 @@ void vClearOtaMessageQueue(mesh_addr_t* pMeshNodeAddr)
|
||||
}//end OTA message loop
|
||||
}
|
||||
|
||||
esp_err_t errSendOTAVersionRequest(mesh_addr_t* pMeshReceiverAddr)
|
||||
void vMeshOtaUtilAddNodeToPossibleUpdatableQueue(uint8_t* pu8MAC)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
MESH_PACKET_t packet;
|
||||
packet.type = OTA_Version_Request;
|
||||
//send payload to node queues
|
||||
mesh_addr_t addrNode;
|
||||
memcpy(&addrNode.addr, (uint8_t *)pu8MAC, 6); //copy MAC
|
||||
|
||||
const esp_partition_t* pBootPartition; //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_Request packet
|
||||
err = errSendMeshPacket(pMeshReceiverAddr, &packet);
|
||||
return err;
|
||||
if (xQueueSend(queueNodes, &addrNode, portMAX_DELAY) != pdPASS)
|
||||
{
|
||||
ESP_LOGE(LOG_TAG, "Unable to push node into node queue");
|
||||
}
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
void vMeshOtaUtilAddOtaMessageToQueue(MESH_PACKET_t* puMeshPacket)
|
||||
{
|
||||
//send ota packet to packet queue
|
||||
if (xQueueSend(queueMessageOTA, puMeshPacket, portMAX_DELAY) != pdPASS)
|
||||
{
|
||||
ESP_LOGE(LOG_TAG, "Unable to push ota packet into packet queue");
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (puMeshPacket->type)
|
||||
{
|
||||
case OTA_Abort:
|
||||
ESP_LOGI(LOG_TAG, "added ota message to queue: OTA_Abort from 0x%x", puMeshPacket->meshSenderAddr.addr[5]);
|
||||
break;
|
||||
case OTA_Version_Request:
|
||||
ESP_LOGI(LOG_TAG, "added ota message to queue: OTA_Version_Request from 0x%x", puMeshPacket->meshSenderAddr.addr[5]);
|
||||
break;
|
||||
|
||||
case OTA_Version_Response:
|
||||
ESP_LOGI(LOG_TAG, "added ota message to queue: OTA_Version Response from 0x%x", puMeshPacket->meshSenderAddr.addr[5]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void vMeshOtaUtilChangeStateOfServerWorker(bool bState) //allow access via function ptn to networl_handler
|
||||
{
|
||||
static bool bLastState = false;
|
||||
|
||||
if(bState != bLastState) //change only if necessary
|
||||
{
|
||||
ESP_LOGI(LOG_TAG, "server worker change handler");
|
||||
|
||||
if(bState == true)
|
||||
{
|
||||
if (xSemaphoreGive(bsStartStopServerWorker) != pdTRUE)
|
||||
{
|
||||
ESP_LOGE(LOG_TAG, "Unable to give mutex to activate the server worker");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xSemaphoreTake(bsStartStopServerWorker,( TickType_t ) 10 ) != pdTRUE)
|
||||
{
|
||||
ESP_LOGE(LOG_TAG, "Unable to obtain mutex to deactivate the server worker");
|
||||
}
|
||||
}
|
||||
bLastState = bState;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user