refactor #2
| @ -282,7 +282,7 @@ bool bMeshNetworkIsNodeNeighbour(const mesh_addr_t* const cpcNode) | ||||
|  | ||||
|     if(err == ESP_OK) | ||||
|         { | ||||
|             if(bMeshNetworkCheckMACEquality(cpcNode->addr,  addrParent.addr) == true) | ||||
|             if(bMeshNetworkCheckMacEquality(cpcNode->addr,  addrParent.addr) == true) | ||||
|                 { | ||||
|                     bReturn = true; //node was found | ||||
|                 } | ||||
| @ -296,7 +296,7 @@ bool bMeshNetworkIsNodeNeighbour(const mesh_addr_t* const cpcNode) | ||||
|  | ||||
|             for (uint16_t u16Index = 0; ((u16Index < u16ChildrenSize) && (err == ESP_OK) && (bReturn == false)); u16Index++) | ||||
|                 { | ||||
|                     if(bMeshNetworkCheckMACEquality(cpcNode->addr,  childrenAddr[u16Index].addr) == true) | ||||
|                     if(bMeshNetworkCheckMacEquality(cpcNode->addr,  childrenAddr[u16Index].addr) == true) | ||||
|                         { | ||||
|                             bReturn = true; //node was found | ||||
|                         } | ||||
| @ -307,7 +307,7 @@ bool bMeshNetworkIsNodeNeighbour(const mesh_addr_t* const cpcNode) | ||||
|  | ||||
|  | ||||
| /** | ||||
| * @fn bool bMeshNetworkCheckMACEquality(const uint8_t* const cpcu8aMAC, const uint8_t* const cpcu8bMAC) | ||||
| * @fn bool bMeshNetworkCheckMacEquality(const uint8_t* const cpcu8aMAC, const uint8_t* const cpcu8bMAC) | ||||
| * @brief returns true if MAC address is equal | ||||
| * @param cpcu8aMAC first MAC | ||||
| * @param cpcu8bMAC second MAC | ||||
| @ -315,7 +315,7 @@ bool bMeshNetworkIsNodeNeighbour(const mesh_addr_t* const cpcNode) | ||||
| * @author Hendrik Schutter | ||||
| * @date 21.01.2021 | ||||
| */ | ||||
| bool bMeshNetworkCheckMACEquality(const uint8_t* const cpcu8aMAC, const uint8_t* const cpcu8bMAC) | ||||
| bool bMeshNetworkCheckMacEquality(const uint8_t* const cpcu8aMAC, const uint8_t* const cpcu8bMAC) | ||||
| { | ||||
|     bool bRet = true; | ||||
|     uint8_t index = 0; | ||||
| @ -396,7 +396,7 @@ esp_err_t errMeshNetworkGetChildren(mesh_addr_t* const cpChildren, uint16_t* con | ||||
|         { | ||||
|             for(uint16_t index = 0; index < esp_mesh_get_routing_table_size(); index++) | ||||
|                 { | ||||
|                     if(! (bMeshNetworkCheckMACEquality(u8ownMAC, route_table[index].addr))  ) | ||||
|                     if(! (bMeshNetworkCheckMacEquality(u8ownMAC, route_table[index].addr))  ) | ||||
|                         { | ||||
|                             //child node | ||||
|                             //ESP_LOGI(LOG_TAG, "adding Node: \"0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\" ", route_table[index].addr[0], route_table[index].addr[1], route_table[index].addr[2], route_table[index].addr[3], route_table[index].addr[4], route_table[index].addr[5]); | ||||
|  | ||||
| @ -236,7 +236,7 @@ void vMeshOtaTaskOTAWorker(void *arg) | ||||
| /** | ||||
| * @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  | ||||
| * @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 | ||||
| @ -270,7 +270,7 @@ esp_err_t errMeshOtaSlaveEndpoint(bool* const cpbNewOTAImage) | ||||
|                     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)); | ||||
|                     ERROR_CHECK(errMeshOtaUtilSendOtaVersionResponse(&sOTAMessage.meshSenderAddr)); | ||||
|  | ||||
|                     if((bMeshOtaUtilNewerVersion((bootPartitionDesc).version, (char*) sOTAMessage.au8Payload)) && (err == ESP_OK)) //compare local and remote version | ||||
|                         { | ||||
| @ -296,7 +296,7 @@ esp_err_t errMeshOtaSlaveEndpoint(bool* const cpbNewOTAImage) | ||||
| /** | ||||
| * @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 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 | ||||
| @ -321,7 +321,7 @@ 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 | ||||
|  | ||||
|             ERROR_CHECK(errMeshOtaUtilSendOTAVersionRequest(cpcMeshNodeAddr)); //send OTA_VERSION_REQUEST with local version in payload | ||||
|             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 | ||||
|                 { | ||||
| @ -334,7 +334,7 @@ esp_err_t errMeshOtaMasterEndpoint(bool* const cpbNewOTAImage, const mesh_addr_t | ||||
|                                     err = ESP_FAIL; | ||||
|                                 } | ||||
|  | ||||
|                             if((err == ESP_OK) && (sOTAMessage.type == OTA_Version_Response) && (bMeshNetworkCheckMACEquality(sOTAMessage.meshSenderAddr.addr, cpcMeshNodeAddr->addr))) //if OTA_Version_Request | ||||
|                             if((err == ESP_OK) && (sOTAMessage.type == OTA_Version_Response) && (bMeshNetworkCheckMacEquality(sOTAMessage.meshSenderAddr.addr, cpcMeshNodeAddr->addr))) //if OTA_Version_Request | ||||
|                                 { | ||||
|                                     bNodeIsResponding = true; | ||||
|                                     cpBootPartition = esp_ota_get_boot_partition(); //get boot partition (that will booted after reset), not the running partition | ||||
|  | ||||
| @ -45,7 +45,7 @@ esp_err_t errMeshOtaPartitionAccessHttps(bool* const cpbNewOTAImage) | ||||
|     ERROR_CHECK(errMeshOtaUtilExtractVersionNumber(u8OTABuffer, &u32BytesRead, pcRemoteVersionNumber)); //extract version numbers | ||||
|  | ||||
|     //check if version number is found | ||||
|     if(err == ESP_OK)  | ||||
|     if(err == ESP_OK) | ||||
|         { | ||||
|             xSemaphoreTake(bsOTAProcess, portMAX_DELAY); //wait for binary semaphore that allows to start the OTA process | ||||
|  | ||||
| @ -66,7 +66,7 @@ esp_err_t errMeshOtaPartitionAccessHttps(bool* const cpbNewOTAImage) | ||||
|                             ESP_LOGI(LOG_TAG, "start OTA download via HTTPS"); | ||||
|                             do | ||||
|                                 { | ||||
|                                     vMeshOtaUtilPrintOTAProgress(&(pOTAPartition->size), &u32OTABytesWritten, Receiver); | ||||
|                                     vMeshOtaUtilPrintOtaProgress(&(pOTAPartition->size), &u32OTABytesWritten, Receiver); | ||||
|                                     ERROR_CHECK(esp_ota_write(otaHandle, (const void*) u8OTABuffer+u32StartOffset, (u32BytesRead-u32StartOffset))); | ||||
|  | ||||
|                                     if(err == ESP_OK) | ||||
| @ -141,7 +141,7 @@ esp_err_t errMeshOtaPartitionAccessMeshTransmit(const mesh_addr_t* const cpcMesh | ||||
|             // read partition with offset based in index | ||||
|             ERROR_CHECK(esp_partition_read(pBootPartition, (OTA_MESH_SEGMENT_SIZE * u32SegmentCounter), sMeshPacket.au8Payload, OTA_MESH_SEGMENT_SIZE)); | ||||
|             u32OTABytesWritten = ((u32SegmentCounter+1) * OTA_MESH_SEGMENT_SIZE); //calc bytes that are written in this ota process | ||||
|             vMeshOtaUtilPrintOTAProgress(&(pBootPartition->size), &u32OTABytesWritten, Transmitter); | ||||
|             vMeshOtaUtilPrintOtaProgress(&(pBootPartition->size), &u32OTABytesWritten, Transmitter); | ||||
|  | ||||
|             if(err == ESP_OK) | ||||
|                 { | ||||
| @ -176,7 +176,7 @@ esp_err_t errMeshOtaPartitionAccessMeshTransmit(const mesh_addr_t* const cpcMesh | ||||
|                         } | ||||
|  | ||||
|                     //check if from correct node | ||||
|                     if((err == ESP_OK) && (bMeshNetworkCheckMACEquality(sMeshPacket.meshSenderAddr.addr, cpcMeshNodeAddr->addr)))  | ||||
|                     if((err == ESP_OK) && (bMeshNetworkCheckMacEquality(sMeshPacket.meshSenderAddr.addr, cpcMeshNodeAddr->addr))) | ||||
|                         { | ||||
|                             //packet from node received --> handle it | ||||
|                             switch (sMeshPacket.type) | ||||
| @ -215,7 +215,7 @@ esp_err_t errMeshOtaPartitionAccessMeshTransmit(const mesh_addr_t* const cpcMesh | ||||
|  | ||||
| /** | ||||
| * @fn esp_err_t errMeshOtaPartitionAccessMeshReceive(bool* const cpbNewOTAImage, const mesh_addr_t* const cpcMeshNodeAddr) | ||||
| * @brief Downloads and writes the image from the remote node  | ||||
| * @brief Downloads and writes the image from the remote node | ||||
| * @param cpbNewOTAImage pointer to boolean to signal if a new image was successfully received | ||||
| * @param cpcMeshNodeAddr pointer to mesh node addr to receive the image segments from | ||||
| * @return ESP32 error code | ||||
| @ -257,19 +257,19 @@ esp_err_t errMeshOtaPartitionAccessMeshReceive(bool* const cpbNewOTAImage, const | ||||
|                             err = ESP_FAIL; | ||||
|                         } | ||||
|  | ||||
|                     if((err == ESP_OK) && (bMeshNetworkCheckMACEquality(sMeshPacket.meshSenderAddr.addr, cpcMeshNodeAddr->addr))) //if OTA_Version_Request | ||||
|                     if((err == ESP_OK) && (bMeshNetworkCheckMacEquality(sMeshPacket.meshSenderAddr.addr, cpcMeshNodeAddr->addr))) //if OTA_Version_Request | ||||
|                         { | ||||
|                             //packet from node received | ||||
|                             switch (sMeshPacket.type) | ||||
|                                 { | ||||
|                                 case OTA_Complete: //signal end of this OTA process, fall through because same behavior as OTA_Data | ||||
|                                     bComplete = true; | ||||
|                                     //fall through | ||||
|                                 //fall through | ||||
|                                 case OTA_Data: //data segement received | ||||
|                                     bNodeIsResponding = true; | ||||
|                                     ERROR_CHECK(esp_ota_write(otaHandle, sMeshPacket.au8Payload, OTA_MESH_SEGMENT_SIZE)); | ||||
|                                     u32OTABytesWritten = ((u32SegmentCounter+1) * OTA_MESH_SEGMENT_SIZE); //calc bytes that are written in this ota process | ||||
|                                     vMeshOtaUtilPrintOTAProgress(&(pOTAPartition->size), &u32OTABytesWritten, Receiver);  | ||||
|                                     vMeshOtaUtilPrintOtaProgress(&(pOTAPartition->size), &u32OTABytesWritten, Receiver); | ||||
|                                     u32Index = QUEUE_MESSAGE_OTA_SIZE; //this will end the loop through all OTA messages | ||||
|                                     break; | ||||
|                                 case OTA_Abort: //abort this OTA process | ||||
|  | ||||
| @ -92,11 +92,11 @@ esp_err_t errMeshOtaUtilExtractVersionNumber(const char* cpu8Data, uint32_t* con | ||||
| */ | ||||
| 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 | ||||
|      | ||||
|  | ||||
|     esp_err_t errReturn = ESP_OK; | ||||
|     bool bImageStartOffsetFound = false; | ||||
|     uint32_t u32DataIndex = 0; | ||||
| @ -168,14 +168,14 @@ esp_err_t errMeshOtaUtilFindImageStart(const char* const cpu8Data, const uint32_ | ||||
| } | ||||
|  | ||||
| /** | ||||
| * @fn esp_err_t errMeshOtaUtilSendOTAVersionRequest(const mesh_addr_t* const cpcMeshReceiverAddr) | ||||
| * @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 errMeshOtaUtilSendOtaVersionRequest(const mesh_addr_t* const cpcMeshReceiverAddr) | ||||
| { | ||||
|     esp_err_t err = ESP_OK; | ||||
|     MESH_PACKET_t packet; | ||||
| @ -192,14 +192,14 @@ esp_err_t errMeshOtaUtilSendOTAVersionRequest(const mesh_addr_t* const cpcMeshRe | ||||
| } | ||||
|  | ||||
| /** | ||||
| * @fn esp_err_t errMeshOtaUtilSendOTAVersionResponse(const mesh_addr_t* const cpcMeshReceiverAddr) | ||||
| * @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 errMeshOtaUtilSendOtaVersionResponse(const mesh_addr_t* const cpcMeshReceiverAddr) | ||||
| { | ||||
|     esp_err_t err = ESP_OK; | ||||
|     MESH_PACKET_t packet; | ||||
| @ -219,7 +219,7 @@ esp_err_t errMeshOtaUtilSendOTAVersionResponse(const mesh_addr_t* const cpcMeshR | ||||
| } | ||||
|  | ||||
| /** | ||||
| * @fn void vMeshOtaUtilPrintOTAProgress(const uint32_t* const cpcu32TotalImageSize, const uint32_t* const cpcu32BytesWritten, const OTA_MESH_ROLE_t ceRole) | ||||
| * @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 | ||||
| @ -228,7 +228,7 @@ esp_err_t errMeshOtaUtilSendOTAVersionResponse(const mesh_addr_t* const cpcMeshR | ||||
| * @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) | ||||
| 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; | ||||
| @ -308,7 +308,7 @@ void vMeshOtaUtilClearOtaMessageQueue(const mesh_addr_t* const cpcMeshNodeAddr) | ||||
|         { | ||||
|             if (xQueueReceive(queueMessageOTA, &sMeshPacket, 0) == pdTRUE) | ||||
|                 { | ||||
|                     if(!(bMeshNetworkCheckMACEquality(sMeshPacket.meshSenderAddr.addr, cpcMeshNodeAddr->addr))) | ||||
|                     if(!(bMeshNetworkCheckMacEquality(sMeshPacket.meshSenderAddr.addr, cpcMeshNodeAddr->addr))) | ||||
|                         { | ||||
|                             //received OTA message is NOT from cpcMeshNodeAddr --> keep it in queue | ||||
|                             vMeshOtaUtilAddOtaMessageToQueue(&sMeshPacket); | ||||
| @ -332,7 +332,7 @@ void vMeshOtaUtilClearNeighboursQueue(const mesh_addr_t* const cpcMeshNodeAddr) | ||||
|         { | ||||
|             if (xQueueReceive(queueNodes, &sNode, 0) == pdTRUE) | ||||
|                 { | ||||
|                     if(!(bMeshNetworkCheckMACEquality(sNode.addr, cpcMeshNodeAddr->addr))) | ||||
|                     if(!(bMeshNetworkCheckMacEquality(sNode.addr, cpcMeshNodeAddr->addr))) | ||||
|                         { | ||||
|                             //node is NOT cpcMeshNodeAddr --> keep it in queue | ||||
|                             vMeshOtaUtilAddNodeToPossibleUpdatableQueue(cpcMeshNodeAddr->addr); | ||||
|  | ||||
| @ -104,7 +104,7 @@ esp_err_t errMeshNetworkSetChangeStateOfServerWorkerHandle(void (*pChangeStateOf | ||||
|  | ||||
| bool bMeshNetworkIsRootNode(void); | ||||
| bool bMeshNetworkIsNodeNeighbour(const mesh_addr_t* const cpcNode); | ||||
| bool bMeshNetworkCheckMACEquality(const uint8_t* const cpcu8aMAC, const uint8_t* const cpcu8bMAC); | ||||
| bool bMeshNetworkCheckMacEquality(const uint8_t* const cpcu8aMAC, const uint8_t* const cpcu8bMAC); | ||||
|  | ||||
| esp_err_t errMeshNetworkStartReceiveTask(void); | ||||
| esp_err_t errMeshNetworkGetParentNode(mesh_addr_t* const cpMeshParentAddr); | ||||
|  | ||||
| @ -28,9 +28,9 @@ typedef  enum otaMeshRole OTA_MESH_ROLE_t; | ||||
| bool bMeshOtaUtilNewerVersion(const char* cpu8Local, const char* cpu8Remote); | ||||
| esp_err_t errMeshOtaUtilExtractVersionNumber(const char* cpu8Data, uint32_t* const cpu32DataLenght, char* const pc8RemoteVersionNumber); | ||||
| esp_err_t errMeshOtaUtilFindImageStart(const  char* const cpu8Data, const uint32_t* const cpu32DataLenght, uint32_t* const cpu32StartOffset); | ||||
| esp_err_t errMeshOtaUtilSendOTAVersionRequest(const mesh_addr_t* const cpcMeshReceiverAddr); | ||||
| esp_err_t errMeshOtaUtilSendOTAVersionResponse(const mesh_addr_t* const cpcMeshReceiverAddr); | ||||
| void vMeshOtaUtilPrintOTAProgress(const uint32_t* const cpcu32TotalImageSize, const uint32_t* const cpcu32BytesWritten, const OTA_MESH_ROLE_t ceRole); | ||||
| esp_err_t errMeshOtaUtilSendOtaVersionRequest(const mesh_addr_t* const cpcMeshReceiverAddr); | ||||
| esp_err_t errMeshOtaUtilSendOtaVersionResponse(const mesh_addr_t* const cpcMeshReceiverAddr); | ||||
| void vMeshOtaUtilPrintOtaProgress(const uint32_t* const cpcu32TotalImageSize, const uint32_t* const cpcu32BytesWritten, const OTA_MESH_ROLE_t ceRole); | ||||
| void vMeshOtaUtilAddAllNeighboursToQueue(void); | ||||
| void vMeshOtaUtilClearOtaMessageQueue(const mesh_addr_t* const cpcMeshNodeAddr); | ||||
| void vMeshOtaUtilClearNeighboursQueue(const mesh_addr_t* const cpcMeshNodeAddr); | ||||
|  | ||||
| @ -236,7 +236,7 @@ void vTaskReceiveData(void *arg) | ||||
|             for (uint16_t u16Index = 0; u16Index < u16ChildrenSize; u16Index++) | ||||
|                 { | ||||
|                     //loop through children | ||||
|                     if(bMeshNetworkCheckMACEquality(bTmpPacket.meshSenderAddr.addr,  childrenAddr[u16Index].addr) == false) //exclude the sender node | ||||
|                     if(bMeshNetworkCheckMacEquality(bTmpPacket.meshSenderAddr.addr,  childrenAddr[u16Index].addr) == false) //exclude the sender node | ||||
|                         { | ||||
|                             ERROR_CHECK (errMeshNetworkSendMeshPacket(&childrenAddr[u16Index], &meshPacket)); //send to child | ||||
|                         } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user