Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move allocation of addrList into setNodeID() #248

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,7 @@ void setup() {
}

// Set the nodeID to 0 for the master node
mesh.setNodeID(0);
Serial.println(mesh.getNodeID());
// Connect to the mesh
if (!mesh.begin()) {
// if mesh.begin() returns false for a master node, then radio.begin() returned false.
Serial.println(F("Radio hardware not responding."));
while (1) {
// hold in an infinite loop
}
}
mesh.setNodeID(0); // must be called before setStaticAddress()

// In this case, assign a static address to nodeIDs 23,24 at RF24Network address 02 && 03
// This will prevent this master node from assigning the address to another node
Expand All @@ -51,10 +42,20 @@ void setup() {
// With this example, assign nodes 02 and 03 statically. This allows child nodes to join
// the network as children of 00(master), node 02, or node 03, or as children of other
// mesh nodes. If nodes 02 and 03 are placed in proximity to a group of mesh nodes, the
// mesh nodes can attatch to the network via the static nodes, and route traffic through
// mesh nodes can attach to the network via the static nodes, and route traffic through
// either node, to the master node.
mesh.setStaticAddress(23, 02);
mesh.setStaticAddress(24, 03);

Serial.println(mesh.getNodeID());
// Connect to the mesh
if (!mesh.begin()) {
// if mesh.begin() returns false for a master node, then radio.begin() returned false.
Serial.println(F("Radio hardware not responding."));
while (1) {
// hold in an infinite loop
}
}
}

uint32_t displayTimer = 0;
Expand Down
2 changes: 1 addition & 1 deletion examples/RF24Mesh_SerialConfig/RF24Mesh_SerialConfig.ino
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void setup() {
while (!mesh.getNodeID()) {
// Wait for the nodeID to be set via Serial
if (Serial.available()) {
mesh.setNodeID(Serial.read());
mesh.setNodeID(Serial.parseInt() & 0xFF);
Copy link
Member Author

@2bndy5 2bndy5 Jun 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any noticeable increase in reported compile size comes from this change.

Serial.print("Set NodeID: ");
Serial.println(mesh.getNodeID());
}
Expand Down