From 40a2edc0e77093f7d02cb8a126eedd1bf8bf9329 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Fri, 21 Jun 2024 15:32:19 -0700 Subject: [PATCH] move allocation of addrList to setNodeID() resolves #221 as proposed --- RF24Mesh.cpp | 17 ++++++++--------- RF24Mesh.h | 2 -- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/RF24Mesh.cpp b/RF24Mesh.cpp index be6ef20..d781ee3 100644 --- a/RF24Mesh.cpp +++ b/RF24Mesh.cpp @@ -16,7 +16,8 @@ ESBMesh::ESBMesh(radio_t& _radio, network_t& _network) : rad setCallback(NULL); meshStarted = false; #if !defined(MESH_NOMASTER) - addrMemAllocated = false; + addrList = nullptr; + addrListTop = 0; #endif } @@ -42,14 +43,6 @@ bool ESBMesh::begin(uint8_t channel, rf24_datarate_e data_ra } } else { -#if !defined(MESH_NOMASTER) - if (!addrMemAllocated) { - addrMemAllocated = true; - addrList = (addrListStruct*)malloc((MESH_MEM_ALLOC_SIZE * sizeof(addrListStruct))); - addrListTop = 0; - loadDHCP(); - } -#endif mesh_address = 0; network.begin(mesh_address); } @@ -438,6 +431,12 @@ template void ESBMesh::setNodeID(uint8_t nodeID) { _nodeID = nodeID; +#if !defined(MESH_NOMASTER) + if (!nodeID && addrList == nullptr) { + addrList = (addrListStruct*)malloc((MESH_MEM_ALLOC_SIZE * sizeof(addrListStruct))); + loadDHCP(); + } +#endif } /*****************************************************/ diff --git a/RF24Mesh.h b/RF24Mesh.h index 603adcb..1673306 100644 --- a/RF24Mesh.h +++ b/RF24Mesh.h @@ -369,8 +369,6 @@ class ESBMesh #if !defined(MESH_NOMASTER) /** Indicator that an address request is available. */ bool doDHCP; - /** Just ensures we don't re-allocate the memory buffer if restarting the mesh on master. **/ - bool addrMemAllocated; #endif /** Starts up the network layer with default address. */