Browse Source

OTA message handle call and vAddAllNeighboursToQueue()

feature/blockingOTA
Hendrik Schutter 1 year ago
parent
commit
6446049876
  1. 71
      components/mesh_ota/Mesh_OTA.c
  2. 21
      components/mesh_ota/Mesh_network.c
  3. 6
      components/mesh_ota/include/Mesh_OTA.h
  4. 3
      components/mesh_ota/include/Mesh_network.h

71
components/mesh_ota/Mesh_OTA.c

@ -91,14 +91,25 @@ esp_err_t errMeshOTAInitialize()
}
}
if(err == ESP_OK)
{
xReturned = xTaskCreate(vTaskOTAWorker, "vTaskOTAWorker", 8192, NULL, 5, NULL);
if(xReturned != pdPASS)
{
ESP_LOGE(LOG_TAG, "Unable to create the OTA worker task");
err = ESP_FAIL;
}
}
return err;
}
void vAddNodeToPossibleUpdatableQueue(uint8_t* pu8Data)
void vAddNodeToPossibleUpdatableQueue(uint8_t* pu8MAC)
{
//send payload to node queue
//send payload to node queues
mesh_addr_t addrNode;
memcpy(&addrNode.addr, (uint8_t *)pu8Data, 6); //copy MAC
memcpy(&addrNode.addr, (uint8_t *)pu8MAC, 6); //copy MAC
if (xQueueSend(queueNodes, &addrNode, portMAX_DELAY) != pdPASS)
{
@ -151,11 +162,37 @@ void vChangeStateOfServerWorker(bool bState) //allow access via function ptn to
void vTaskOTAWorker(void *arg)
{
while(true)
{
if((uxQueueSpacesAvailable(queueNodes) - QUEUE_NODES_SIZE) == 0)
{
//nodes queue is empty
ESP_LOGI(LOG_TAG, "nodes queue is empty");
if(bWantReboot == true)
{
ESP_LOGI(LOG_TAG, "ESP32 Reboot ...");
//vTaskDelay( (1000) / portTICK_PERIOD_MS);
//esp_restart();
}
//read OTAMessages queue
//if OTA_Version_Response
// --> send OTA_Version_Request
// --> this version older --> start OTA_Rx --> vAddAllNeighboursToQueue(); //add all existing neighbours to queues
// --> this version newer --> start OTA_Tx
//if not OTA_Version_Response --> do nothing
}
vTaskDelay( (1000) / portTICK_PERIOD_MS);
}
}
void vTaskServerWorker(void *arg)
@ -193,8 +230,9 @@ void vTaskServerWorker(void *arg)
//set want reboot
ESP_LOGI(LOG_TAG, "Updated successfully via HTTPS, set pending reboot");
bWantReboot = true;
vAddAllNeighboursToQueue(); //add all existing neighbours to queue (aparent will not be added because this node is the root)
}
vTaskDelay( (SERVER_CHECK_INTERVAL*1000) / portTICK_PERIOD_MS); //sleep till next server check
vTaskDelay( (SERVER_CHECK_INTERVAL*1000) / portTICK_PERIOD_MS); //sleep till next server checks
}
}
}
@ -404,7 +442,7 @@ esp_err_t errExtractVersionNumber(const char* pu8Data, uint32_t* pu32DataLenght,
return err;
}
inline void vPrintOTAProgress(const uint32_t* const pu32TotalImageSize, const uint32_t* const pu32BytesWritten)
void vPrintOTAProgress(const uint32_t* const pu32TotalImageSize, const uint32_t* const pu32BytesWritten)
{
uint32_t u32Percentage = 0U;
static uint32_t u32LastPercentage = 0U;
@ -425,6 +463,29 @@ inline void vPrintOTAProgress(const uint32_t* const pu32TotalImageSize, const ui
}
}
void vAddAllNeighboursToQueue(void)
{
esp_err_t err = ESP_OK;
mesh_addr_t addrParent; //addr of parent node
mesh_addr_t childrenAddr[CONFIG_MESH_ROUTE_TABLE_SIZE]; //array of children attached to this node
uint16_t u16ChildrenSize; //number of children attached to this node
err = errGetParentNode(&addrParent);
if(err == ESP_OK)
{
vAddNodeToPossibleUpdatableQueue(addrParent.addr);
}
ERROR_CHECK(errGetChildren(childrenAddr, &u16ChildrenSize)); //get all children
for (uint16_t u16Index = 0; u16Index < u16ChildrenSize; u16Index++)
{
vAddNodeToPossibleUpdatableQueue(childrenAddr[u16Index].addr);
}
}
/*
esp_err_t esp_mesh_ota_send(mesh_addr_t* dest)
{

21
components/mesh_ota/Mesh_network.c

@ -160,12 +160,14 @@ esp_err_t errGetParentNode(mesh_addr_t* pMeshParentAddr)
{
esp_err_t err = ESP_OK;
if(bIsMeshConnected == false)
if((bIsMeshConnected == false) || (esp_mesh_is_root()))
{
//this node is not connected or is the root --> this node has no parent
err = ESP_FAIL;
}
else
{
//node has parent
memcpy(pMeshParentAddr, &meshParentAddr, sizeof(mesh_addr_t));
}
return err;
@ -253,7 +255,8 @@ void vTaskReceiveMeshData(void *arg)
continue;
}
MESH_PACKET_t packet;
memcpy(&packet, (uint8_t *)rx_buf, sizeof(MESH_PACKET_t));
memcpy(&packet, (uint8_t *)rx_buf, sizeof(MESH_PACKET_t)); //parse MESH_PACKET_t
memcpy(&packet.meshSenderAddr, &from, sizeof(mesh_addr_t)); //copy sender into packet
switch (packet.type)
{
@ -263,19 +266,15 @@ void vTaskReceiveMeshData(void *arg)
pAppRxHandle(packet.au8Payload, from.addr); //hand over payload and sender of this mesh packet
break;
case OTA_Version_Request:
ESP_LOGI(LOG_TAG, "recv: OTA_Version_Request");
break;
case OTA_Version_Respone:
ESP_LOGI(LOG_TAG, "recv: OTA_Version_Respone");
break;
case OTA_Data:
ESP_LOGI(LOG_TAG, "recv: OTA_Data");
break;
case OTA_ACK:
ESP_LOGI(LOG_TAG, "recv: OTA_ACK");
break;
case OTA_Complete:
ESP_LOGI(LOG_TAG, "recv: OTA_Complete");
//call the rx handle from OTA
if(pOTAMessageHandle)
{
pOTAMessageHandle(&packet);
}
break;
default:
ESP_LOGE(LOG_TAG, "recv: something");

6
components/mesh_ota/include/Mesh_OTA.h

@ -41,14 +41,16 @@ bool bNewerVersion(const char* pu8Local, const char* pu8Remote);
esp_err_t errExtractVersionNumber(const char* pu8Data, uint32_t* pu32DataLenght, char* pc8RemoteVersionNumber);
esp_err_t errFindImageStart(const char* pu8Data, uint32_t* pu32DataLenght, uint32_t* pu32StartOffset);
void vPrintOTAProgress(const uint32_t* const pu32TotalImageSize, const uint32_t* const pu32BytesWritten);
void vAddAllNeighboursToQueue(void);
//Handler
void vAddNodeToPossibleUpdatableQueue(uint8_t* pu8Data);
void vAddNodeToPossibleUpdatableQueue(uint8_t* pu8MAC);
void vAddOTAControllMessageToQueue(MESH_PACKET_t* puMeshPacket);
void vChangeStateOfServerWorker(bool state);
//Tasks
inline void vTaskServerWorker(void *arg);
void vTaskServerWorker(void *arg);
void vTaskOTAWorker(void *arg);

3
components/mesh_ota/include/Mesh_network.h

@ -95,5 +95,8 @@ void vIPEventHandler(void *arg, esp_event_base_t event_base, int32_t i32EventID,
esp_err_t errSendMeshPacket(mesh_addr_t* pAddrDest, MESH_PACKET_t* pPacket);
#endif /* H_MESH_NETWORK */

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