changed the most params to const
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
|
||||
static const char *LOG_TAG = "mesh_ota";
|
||||
|
||||
bool bMeshOtaUtilNewerVersion(const char* pu8Local, const char* pu8Remote)
|
||||
bool bMeshOtaUtilNewerVersion(const char* cpu8Local, const char* cpu8Remote)
|
||||
{
|
||||
/*
|
||||
* Return true if remote version is newer (higher) than local version
|
||||
@ -15,8 +15,8 @@ bool bMeshOtaUtilNewerVersion(const char* pu8Local, const char* pu8Remote)
|
||||
bool bReturn = false; //flag to stop loop
|
||||
uint8_t u8Index = 0; //numbers counter in version string
|
||||
|
||||
strncpy(u8LocalTmp, pu8Local, 12); //copy in tmp
|
||||
strncpy(u8RemoteTmp, pu8Remote, 12); //copy in tmp
|
||||
strncpy(u8LocalTmp, cpu8Local, 12); //copy in tmp
|
||||
strncpy(u8RemoteTmp, cpu8Remote, 12); //copy in tmp
|
||||
|
||||
char* pu8TokenLocal = strtok_r(u8LocalTmp, ".", &pu8saveptrLocal); //split tokens
|
||||
char* pu8TokenRemote = strtok_r(u8RemoteTmp, ".", &pu8saveptrRemote); //split tokens
|
||||
@ -34,24 +34,24 @@ bool bMeshOtaUtilNewerVersion(const char* pu8Local, const char* pu8Remote)
|
||||
return bReturn;
|
||||
}
|
||||
|
||||
esp_err_t errMeshOtaUtilExtractVersionNumber(const char* pu8Data, uint32_t* pu32DataLenght, char* pc8RemoteVersionNumber)
|
||||
esp_err_t errMeshOtaUtilExtractVersionNumber(const char* cpu8Data, uint32_t* const cpcu32DataLenght, char* const 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
|
||||
err = errMeshOtaUtilFindImageStart(cpu8Data, cpcu32DataLenght, &u32StartOffset); //get image start offset
|
||||
|
||||
if(err == ESP_OK)
|
||||
{
|
||||
//image found
|
||||
strncpy(pc8RemoteVersionNumber, pu8Data+(u32StartOffset+48), 11); //copy version number
|
||||
strncpy(pc8RemoteVersionNumber, cpu8Data+(u32StartOffset+48), 11); //copy version number
|
||||
pc8RemoteVersionNumber[12] = '\0';
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t errMeshOtaUtilFindImageStart(const char* pu8Data, uint32_t* pu32DataLenght, uint32_t* pu32StartOffset)
|
||||
esp_err_t errMeshOtaUtilFindImageStart(const char* const cpu8Data, const uint32_t* const cpcu32DataLenght, uint32_t* const cpu32StartOffset)
|
||||
{
|
||||
/*
|
||||
Offset value
|
||||
@ -67,20 +67,20 @@ esp_err_t errMeshOtaUtilFindImageStart(const char* pu8Data, uint32_t* pu32DataLe
|
||||
uint8_t u8FirstDotIndex = 0;
|
||||
uint8_t u8SecondDotIndex = 0;
|
||||
|
||||
*pu32StartOffset = 0U; //reset offset to zero
|
||||
*cpu32StartOffset = 0U; //reset offset to zero
|
||||
|
||||
while((u32DataIndex < *pu32DataLenght) && (bImageStartOffsetFound == false))
|
||||
while((u32DataIndex < *cpcu32DataLenght) && (bImageStartOffsetFound == false))
|
||||
{
|
||||
//search for magic byte
|
||||
if(pu8Data[u32DataIndex] == 0xe9)
|
||||
if(cpu8Data[u32DataIndex] == 0xe9)
|
||||
{
|
||||
//magic byte found
|
||||
while ((u8FirstDotIndex < 3) && (u32FirstDotOffset == 0))
|
||||
{
|
||||
//search first dot in version number
|
||||
if((u32DataIndex+49+u8FirstDotIndex) < *pu32DataLenght)
|
||||
if((u32DataIndex+49+u8FirstDotIndex) < *cpcu32DataLenght)
|
||||
{
|
||||
if((pu8Data[(u32DataIndex+49+u8FirstDotIndex)] == 0x2e))
|
||||
if((cpu8Data[(u32DataIndex+49+u8FirstDotIndex)] == 0x2e))
|
||||
{
|
||||
//first dot found
|
||||
u32FirstDotOffset = (u32DataIndex+49+u8FirstDotIndex);
|
||||
@ -92,9 +92,9 @@ esp_err_t errMeshOtaUtilFindImageStart(const char* pu8Data, uint32_t* pu32DataLe
|
||||
while ((u8SecondDotIndex < 3) && (u32SecondDotOffset == 0) && (u32FirstDotOffset != 0))
|
||||
{
|
||||
//search first dot in version number
|
||||
if((u32FirstDotOffset+(u8SecondDotIndex+2)) < *pu32DataLenght)
|
||||
if((u32FirstDotOffset+(u8SecondDotIndex+2)) < *cpcu32DataLenght)
|
||||
{
|
||||
if((pu8Data[(u32FirstDotOffset+(u8SecondDotIndex+2))] == 0x2e))
|
||||
if((cpu8Data[(u32FirstDotOffset+(u8SecondDotIndex+2))] == 0x2e))
|
||||
{
|
||||
//second dot found
|
||||
u32SecondDotOffset = (u32FirstDotOffset+(u8SecondDotIndex+2));
|
||||
@ -106,7 +106,7 @@ esp_err_t errMeshOtaUtilFindImageStart(const char* pu8Data, uint32_t* pu32DataLe
|
||||
if((u32FirstDotOffset != 0) && (u32SecondDotOffset != 0))
|
||||
{
|
||||
//image start found based on magic byte and version number systax
|
||||
*pu32StartOffset = u32DataIndex; //store image start offset
|
||||
*cpu32StartOffset = u32DataIndex; //store image start offset
|
||||
bImageStartOffsetFound = true;
|
||||
}
|
||||
else
|
||||
@ -129,7 +129,7 @@ esp_err_t errMeshOtaUtilFindImageStart(const char* pu8Data, uint32_t* pu32DataLe
|
||||
return errReturn;
|
||||
}
|
||||
|
||||
esp_err_t errMeshOtaUtilSendOTAVersionRequest(mesh_addr_t* pMeshReceiverAddr)
|
||||
esp_err_t errMeshOtaUtilSendOTAVersionRequest(const mesh_addr_t* const cpcMeshReceiverAddr)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
MESH_PACKET_t packet;
|
||||
@ -141,11 +141,11 @@ esp_err_t errMeshOtaUtilSendOTAVersionRequest(mesh_addr_t* pMeshReceiverAddr)
|
||||
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);
|
||||
err = errMeshNetworkSendMeshPacket(cpcMeshReceiverAddr, &packet);
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t errMeshOtaUtilSendOTAVersionResponse(mesh_addr_t* pMeshReceiverAddr)
|
||||
esp_err_t errMeshOtaUtilSendOTAVersionResponse(const mesh_addr_t* const cpcMeshReceiverAddr)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
MESH_PACKET_t packet;
|
||||
@ -158,34 +158,34 @@ esp_err_t errMeshOtaUtilSendOTAVersionResponse(mesh_addr_t* pMeshReceiverAddr)
|
||||
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]);
|
||||
ESP_LOGI(LOG_TAG, "Send OTA_Version_Response to 0x%x", cpcMeshReceiverAddr->addr[5]);
|
||||
|
||||
err = errMeshNetworkSendMeshPacket(pMeshReceiverAddr, &packet);
|
||||
err = errMeshNetworkSendMeshPacket(cpcMeshReceiverAddr, &packet);
|
||||
return err;
|
||||
}
|
||||
|
||||
void vMeshOtaUtilPrintOTAProgress(const uint32_t* const pu32TotalImageSize, const uint32_t* const pu32BytesWritten, OTA_MESH_ROLE_t eRole)
|
||||
void vMeshOtaUtilPrintOTAProgress(const uint32_t* const cpcu32TotalImageSize, const uint32_t* const cpcu32BytesWritten, const OTA_MESH_ROLE_t ceRole)
|
||||
{
|
||||
uint32_t u32Percentage = 0U;
|
||||
static uint32_t u32LastPercentage = 0U;
|
||||
|
||||
if((*pu32BytesWritten) >= (*pu32TotalImageSize))
|
||||
if((*cpcu32BytesWritten) >= (*cpcu32TotalImageSize))
|
||||
{
|
||||
u32Percentage = 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
u32Percentage = (uint32_t) (((float) (*pu32BytesWritten)/(float) (*pu32TotalImageSize)) * 100.0);
|
||||
u32Percentage = (uint32_t) (((float) (*cpcu32BytesWritten)/(float) (*cpcu32TotalImageSize)) * 100.0);
|
||||
}
|
||||
|
||||
if((u32Percentage-u32LastPercentage) >= OTA_PROGRESS_LOG_INTERVAL)
|
||||
{
|
||||
if(eRole == Transmitter)
|
||||
if(ceRole == Transmitter)
|
||||
{
|
||||
ESP_LOGI(LOG_TAG, "Transmitting OTA update: %i %%", u32Percentage);
|
||||
}
|
||||
|
||||
if(eRole == Receiver)
|
||||
if(ceRole == Receiver)
|
||||
{
|
||||
ESP_LOGI(LOG_TAG, "Receiving OTA update: %i %%", u32Percentage);
|
||||
}
|
||||
@ -223,31 +223,31 @@ void vMeshOtaUtilAddAllNeighboursToQueue(void)
|
||||
}
|
||||
}
|
||||
|
||||
void vMeshOtaUtilClearOtaMessageQueue(mesh_addr_t* pMeshNodeAddr)
|
||||
void vMeshOtaUtilClearOtaMessageQueue(const mesh_addr_t* const cpcMeshNodeAddr)
|
||||
{
|
||||
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(!(bMeshNetworkCheckMACEquality(sMeshPacket.meshSenderAddr.addr, pMeshNodeAddr->addr)))
|
||||
if(!(bMeshNetworkCheckMACEquality(sMeshPacket.meshSenderAddr.addr, cpcMeshNodeAddr->addr)))
|
||||
{
|
||||
//received OTA message is NOT from pMeshNodeAddr --> keep it in queue
|
||||
//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, pMeshNodeAddr->addr[5]);
|
||||
ESP_LOGI(LOG_TAG, "Removed type %i from node 0x%x", sMeshPacket.type, cpcMeshNodeAddr->addr[5]);
|
||||
}
|
||||
}
|
||||
}//end OTA message loop
|
||||
}
|
||||
|
||||
void vMeshOtaUtilAddNodeToPossibleUpdatableQueue(uint8_t* pu8MAC)
|
||||
void vMeshOtaUtilAddNodeToPossibleUpdatableQueue(const uint8_t* const cpcu8MAC)
|
||||
{
|
||||
//send payload to node queues
|
||||
mesh_addr_t addrNode;
|
||||
memcpy(&addrNode.addr, (uint8_t *)pu8MAC, 6); //copy MAC
|
||||
memcpy(&addrNode.addr, (uint8_t *)cpcu8MAC, 6); //copy MAC
|
||||
|
||||
if (xQueueSend(queueNodes, &addrNode, portMAX_DELAY) != pdPASS)
|
||||
{
|
||||
@ -259,26 +259,26 @@ void vMeshOtaUtilAddNodeToPossibleUpdatableQueue(uint8_t* pu8MAC)
|
||||
}
|
||||
}
|
||||
|
||||
void vMeshOtaUtilAddOtaMessageToQueue(MESH_PACKET_t* puMeshPacket)
|
||||
void vMeshOtaUtilAddOtaMessageToQueue(const MESH_PACKET_t* const cpcuMeshPacket)
|
||||
{
|
||||
//send ota packet to packet queue
|
||||
if (xQueueSend(queueMessageOTA, puMeshPacket, portMAX_DELAY) != pdPASS)
|
||||
if (xQueueSend(queueMessageOTA, cpcuMeshPacket, portMAX_DELAY) != pdPASS)
|
||||
{
|
||||
ESP_LOGE(LOG_TAG, "Unable to push ota packet into packet queue");
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (puMeshPacket->type)
|
||||
switch (cpcuMeshPacket->type)
|
||||
{
|
||||
case OTA_Abort:
|
||||
ESP_LOGI(LOG_TAG, "added ota message to queue: OTA_Abort from 0x%x", puMeshPacket->meshSenderAddr.addr[5]);
|
||||
ESP_LOGI(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", puMeshPacket->meshSenderAddr.addr[5]);
|
||||
ESP_LOGI(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", puMeshPacket->meshSenderAddr.addr[5]);
|
||||
ESP_LOGI(LOG_TAG, "added ota message to queue: OTA_Version Response from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -286,15 +286,15 @@ void vMeshOtaUtilAddOtaMessageToQueue(MESH_PACKET_t* puMeshPacket)
|
||||
}
|
||||
}
|
||||
|
||||
void vMeshOtaUtilChangeStateOfServerWorker(bool bState) //allow access via function ptn to networl_handler
|
||||
void vMeshOtaUtilChangeStateOfServerWorker(const bool cbState) //allow access via function ptn to network_handler
|
||||
{
|
||||
static bool bLastState = false;
|
||||
|
||||
if(bState != bLastState) //change only if necessary
|
||||
if(cbState != bLastState) //change only if necessary
|
||||
{
|
||||
ESP_LOGI(LOG_TAG, "server worker change handler");
|
||||
|
||||
if(bState == true)
|
||||
if(cbState == true)
|
||||
{
|
||||
if (xSemaphoreGive(bsStartStopServerWorker) != pdTRUE)
|
||||
{
|
||||
@ -308,6 +308,6 @@ void vMeshOtaUtilChangeStateOfServerWorker(bool bState) //allow access via funct
|
||||
ESP_LOGE(LOG_TAG, "Unable to obtain mutex to deactivate the server worker");
|
||||
}
|
||||
}
|
||||
bLastState = bState;
|
||||
bLastState = cbState;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user