Browse Source

fixed update of all neighbours after update

pull/2/head
Hendrik Schutter 1 year ago
parent
commit
05dfe8528b
  1. 195
      components/mesh_ota/Mesh_OTA.c
  2. 10
      components/mesh_ota/Mesh_network.c
  3. 1
      components/mesh_ota/include/Mesh_network.h

195
components/mesh_ota/Mesh_OTA.c

@ -130,7 +130,21 @@ void vAddOTAControllMessageToQueue(MESH_PACKET_t* puMeshPacket)
}
else
{
//ESP_LOGI(LOG_TAG, "added ota message to queue: %i (type)", puMeshPacket->type);
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;
}
}
}
@ -216,7 +230,7 @@ void vTaskOTAWorker(void *arg)
if((uxQueueSpacesAvailable(queueNodes) - QUEUE_NODES_SIZE) == 0)
{
//nodes queue is empty
// ESP_LOGI(LOG_TAG, "nodes queue is empty");
ESP_LOGI(LOG_TAG, "nodes queue is empty");
if(bWantReboot == true)
{
@ -402,6 +416,7 @@ esp_err_t errOTAMeshMaster(bool* pbNewOTAImage, mesh_addr_t* pMeshNodeAddr)
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", pMeshNodeAddr->addr[5]);
ERROR_CHECK(errSendOTAVersionRequest(pMeshNodeAddr)); //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
@ -446,6 +461,7 @@ esp_err_t errOTAMeshMaster(bool* pbNewOTAImage, mesh_addr_t* pMeshNodeAddr)
else
{
// OTA Message queue is empty --> wait some time
ESP_LOGI(LOG_TAG, "OTA-Master: OTA Message queue is empty --> wait some time");
vTaskDelay( (1000/QUEUE_MESSAGE_OTA_SIZE) / portTICK_PERIOD_MS);
}
}//end loop
@ -455,6 +471,7 @@ esp_err_t errOTAMeshMaster(bool* pbNewOTAImage, mesh_addr_t* pMeshNodeAddr)
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 ");
vAddNodeToPossibleUpdatableQueue(pMeshNodeAddr->addr);
}
return err;
@ -682,7 +699,7 @@ esp_err_t errOTAMeshTransmit(mesh_addr_t* pMeshNodeAddr)
esp_err_t err = ESP_OK;
const esp_partition_t* pBootPartition; //pointer to boot partition (that will booted after reset)
MESH_PACKET_t sMeshPacket; //packet for sending and receiving
// uint32_t u32Index = 0U; //index for partition read offset
// uint32_t u32Index = 0U; //index for partition read offset
bool bAbort = false; //abort the OTA process
bool bNodeIsResponding = false; //remote node is still active
uint32_t u32OTABytesWritten = 0U;
@ -711,7 +728,7 @@ esp_err_t errOTAMeshTransmit(mesh_addr_t* pMeshNodeAddr)
ESP_LOGI(LOG_TAG, "OTA-TX: last segment--> send Complete");
sMeshPacket.type = OTA_Complete;
}
ESP_LOGI(LOG_TAG, "OTA-TX: send packet");
//ESP_LOGI(LOG_TAG, "OTA-TX: send packet");
err = errSendMeshPacket(pMeshNodeAddr, &sMeshPacket);
}
else
@ -726,49 +743,49 @@ esp_err_t errOTAMeshTransmit(mesh_addr_t* pMeshNodeAddr)
// loop through all OTA messages or until abort is called or error
for (uint32_t u32Index = 0; ((u32Index < QUEUE_MESSAGE_OTA_SIZE) && (bAbort == false) && (err == ESP_OK)); u32Index++) //loop through all OTA messages
{
// if(uxQueueSpacesAvailable(queueMessageOTA) < QUEUE_MESSAGE_OTA_SIZE)
// {
//queue not empty
if (xQueueReceive(queueMessageOTA, &sMeshPacket, ((3000) / portTICK_PERIOD_MS)) != pdTRUE)
{
ESP_LOGE(LOG_TAG, "Unable to receive OTA Messages from queue");
err = ESP_FAIL;
}
// if(uxQueueSpacesAvailable(queueMessageOTA) < QUEUE_MESSAGE_OTA_SIZE)
// {
//queue not empty
if (xQueueReceive(queueMessageOTA, &sMeshPacket, ((3000) / portTICK_PERIOD_MS)) != pdTRUE)
{
ESP_LOGE(LOG_TAG, "Unable to receive OTA Messages from queue");
err = ESP_FAIL;
}
if((err == ESP_OK) && (bCheckMACEquality(sMeshPacket.meshSenderAddr.addr, pMeshNodeAddr->addr))) //if OTA_Version_Request
{
//packet from node received
switch (sMeshPacket.type)
{
case OTA_ACK: //increase index for next round
u32Index++;
bNodeIsResponding = true;
u32Index = QUEUE_MESSAGE_OTA_SIZE;//this will end the loop through all OTA messages
break;
case OTA_Abort: //abort this OTA process
bAbort = true;
bNodeIsResponding = true;
break;
default:
//receives wrong OTA message type from node --> back to queue
//vAddOTAControllMessageToQueue(&sMeshPacket);
break;
}
}
else if (err == ESP_OK)
if((err == ESP_OK) && (bCheckMACEquality(sMeshPacket.meshSenderAddr.addr, pMeshNodeAddr->addr))) //if OTA_Version_Request
{
//packet from node received
switch (sMeshPacket.type)
{
//received from wrong node --> back to queue
vAddOTAControllMessageToQueue(&sMeshPacket);
case OTA_ACK: //increase index for next round
u32Index++;
bNodeIsResponding = true;
u32Index = QUEUE_MESSAGE_OTA_SIZE;//this will end the loop through all OTA messages
break;
case OTA_Abort: //abort this OTA process
bAbort = true;
bNodeIsResponding = true;
break;
default:
//receives wrong OTA message type from node --> back to queue
//vAddOTAControllMessageToQueue(&sMeshPacket);
break;
}
/*
}
else
else if (err == ESP_OK)
{
// OTA Message queue is empty --> wait some time
ESP_LOGI(LOG_TAG, "OTA-TX: ota message queue empty --> wait");
vTaskDelay( (OTA_MESH_TIMEOUT) / portTICK_PERIOD_MS);
//received from wrong node --> back to queue
vAddOTAControllMessageToQueue(&sMeshPacket);
}
*/
/*
}
else
{
// OTA Message queue is empty --> wait some time
ESP_LOGI(LOG_TAG, "OTA-TX: ota message queue empty --> wait");
vTaskDelay( (OTA_MESH_TIMEOUT) / portTICK_PERIOD_MS);
}
*/
}//end OTA message loop
@ -779,7 +796,7 @@ esp_err_t errOTAMeshTransmit(mesh_addr_t* pMeshNodeAddr)
bAbort = true;
err = ESP_FAIL; //this OTA process failed with error
}
u32SegmentCounter++;
u32SegmentCounter++;
}//end of partition segment loop
return err;
}
@ -807,56 +824,56 @@ esp_err_t errOTAMeshReceive(bool* pbNewOTAImage, mesh_addr_t* pMeshNodeAddr)
for (uint32_t u32Index = 0; ((u32Index < QUEUE_MESSAGE_OTA_SIZE) && (bAbort == false)); u32Index++) //loop through all OTA messages
{
//if(uxQueueSpacesAvailable(queueMessageOTA) < QUEUE_MESSAGE_OTA_SIZE)
// {
//queue not empty
if (xQueueReceive(queueMessageOTA, &sMeshPacket, ((3000) / portTICK_PERIOD_MS)) != pdTRUE)
{
ESP_LOGE(LOG_TAG, "Unable to receive OTA Messages from queue");
err = ESP_FAIL;
}
// {
//queue not empty
if (xQueueReceive(queueMessageOTA, &sMeshPacket, ((3000) / portTICK_PERIOD_MS)) != pdTRUE)
{
ESP_LOGE(LOG_TAG, "Unable to receive OTA Messages from queue");
err = ESP_FAIL;
}
if((err == ESP_OK) && (bCheckMACEquality(sMeshPacket.meshSenderAddr.addr, pMeshNodeAddr->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;
ESP_LOGI(LOG_TAG, "OTA-RX: rec Complete --> last segment");
//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);
vPrintOTAProgress(&(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
bAbort = true;
bNodeIsResponding = true;
ESP_LOGI(LOG_TAG, "OTA-RX: rec Abort");
//this will end the loop through all OTA messages
break;
default:
//receives wrong OTA message type from node --> back to queue
//vAddOTAControllMessageToQueue(&sMeshPacket);
break;
}
}
else if (err == ESP_OK)
if((err == ESP_OK) && (bCheckMACEquality(sMeshPacket.meshSenderAddr.addr, pMeshNodeAddr->addr))) //if OTA_Version_Request
{
//packet from node received
switch (sMeshPacket.type)
{
//received from wrong node --> back to queue
vAddOTAControllMessageToQueue(&sMeshPacket);
case OTA_Complete: //signal end of this OTA process, fall through because same behavior as OTA_Data
bComplete = true;
ESP_LOGI(LOG_TAG, "OTA-RX: rec Complete --> last segment");
//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);
vPrintOTAProgress(&(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
bAbort = true;
bNodeIsResponding = true;
ESP_LOGI(LOG_TAG, "OTA-RX: rec Abort");
//this will end the loop through all OTA messages
break;
default:
//receives wrong OTA message type from node --> back to queue
//vAddOTAControllMessageToQueue(&sMeshPacket);
break;
}
/* }
else
}
else if (err == ESP_OK)
{
ESP_LOGI(LOG_TAG, "OTA-RX: ota message queue empty --> wait");
// OTA Message queue is empty --> wait some time
vTaskDelay( (OTA_MESH_TIMEOUT) / portTICK_PERIOD_MS);
//received from wrong node --> back to queue
vAddOTAControllMessageToQueue(&sMeshPacket);
}
*/
/* }
else
{
ESP_LOGI(LOG_TAG, "OTA-RX: ota message queue empty --> wait");
// OTA Message queue is empty --> wait some time
vTaskDelay( (OTA_MESH_TIMEOUT) / portTICK_PERIOD_MS);
}
*/
}//end of OTA message loop
@ -876,7 +893,7 @@ esp_err_t errOTAMeshReceive(bool* pbNewOTAImage, mesh_addr_t* pMeshNodeAddr)
if(bAbort == false)
{
//no error while ota write --> send OTA_ACK packet
ESP_LOGI(LOG_TAG, "OTA-RX: no error while ota write --> send OTA_ACK packet");
//ESP_LOGI(LOG_TAG, "OTA-RX: no error while ota write --> send OTA_ACK packet");
sMeshPacket.type = OTA_ACK;
err = errSendMeshPacket(pMeshNodeAddr, &sMeshPacket);
}
@ -890,7 +907,7 @@ esp_err_t errOTAMeshReceive(bool* pbNewOTAImage, mesh_addr_t* pMeshNodeAddr)
errSendMeshPacket(pMeshNodeAddr, &sMeshPacket);
}
}
u32SegmentCounter++;
u32SegmentCounter++;
}//end of partition segement loop
if(bComplete == true)

10
components/mesh_ota/Mesh_network.c

@ -127,6 +127,16 @@ bool bCheckMACEquality(uint8_t* pu8aMAC, uint8_t* pu8bMAC)
{
bRet = false;
}
if(index == 5)
{
//last byte of mac
if(abs((pu8aMAC[index] - pu8bMAC[index])) <= 1)
{
bRet = true; //last byte differs 1 ore less
}
}
index++;
}
return bRet;

1
components/mesh_ota/include/Mesh_network.h

@ -8,6 +8,7 @@
#include "esp_log.h"
#include "esp_mesh.h"
#include "esp_mesh_internal.h"
#include <stdlib.h>
#ifndef CONFIG_MESH_MESSAGE_SIZE
#define CONFIG_MESH_MESSAGE_SIZE 1500

Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close