Skip to content

Commit

Permalink
move allocation of addrList to setNodeID()
Browse files Browse the repository at this point in the history
resolves #221 as proposed
  • Loading branch information
2bndy5 committed Jun 21, 2024
1 parent 3d26ba7 commit 40a2edc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
17 changes: 8 additions & 9 deletions RF24Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ ESBMesh<network_t, radio_t>::ESBMesh(radio_t& _radio, network_t& _network) : rad
setCallback(NULL);
meshStarted = false;
#if !defined(MESH_NOMASTER)
addrMemAllocated = false;
addrList = nullptr;
addrListTop = 0;
#endif
}

Expand All @@ -42,14 +43,6 @@ bool ESBMesh<network_t, radio_t>::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);
}
Expand Down Expand Up @@ -438,6 +431,12 @@ template<class network_t, class radio_t>
void ESBMesh<network_t, radio_t>::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
}

/*****************************************************/
Expand Down
2 changes: 0 additions & 2 deletions RF24Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down

0 comments on commit 40a2edc

Please sign in to comment.