Skip to content

Commit

Permalink
Fix return of getNodeID
Browse files Browse the repository at this point in the history
- #define MESH_BLANK_ID 65535
- getNodeID() function was using a 0 value to determine if it was a
self-identification. Changed to use MESH_BLANK_ID as
self-identification, and 0 now reports correctly for master node
- Issue identified per #24 &
#25
  • Loading branch information
TMRh20 committed Sep 26, 2015
1 parent b207da6 commit d49dea1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
17 changes: 10 additions & 7 deletions RF24Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,19 @@ uint16_t RF24Mesh::getAddress(uint8_t nodeID){

int RF24Mesh::getNodeID(uint16_t address){

if(!address){
if(address == MESH_BLANK_ID){
return _nodeID;
}
}else
if(address == 0){
return 0;
}

if(!getNodeID()){ //Master Node
if(!mesh_address){ //Master Node
for(uint8_t i=0; i<addrListTop; i++){
if(addrList[i].address == address){
return addrList[i].nodeID;
}
}
}
}else{
if(mesh_address == MESH_DEFAULT_ADDRESS){ return -1; }
RF24NetworkHeader header( 00, MESH_ID_LOOKUP );
Expand Down Expand Up @@ -304,7 +307,7 @@ bool RF24Mesh::requestAddress(uint8_t level){
//Serial.print("response took");
//Serial.println(millis()-timr);
#ifdef MESH_DEBUG_SERIAL
uint8_t mask = 7; char addr[5] = " ", count=3; uint16_t newAddr;
uint8_t mask = 7; char addrs[5] = " ", count=3; uint16_t newAddr;
#endif
uint8_t registerAddrCount = 0;

Expand All @@ -322,11 +325,11 @@ bool RF24Mesh::requestAddress(uint8_t level){
Serial.print( millis() );Serial.print(F(" Set address: "));
newAddr = addrResponse.new_address;
while(newAddr){
addr[count] = (newAddr & mask)+48; //get the individual Octal numbers, specified in chunks of 3 bits, convert to ASCII by adding 48
addrs[count] = (newAddr & mask)+48; //get the individual Octal numbers, specified in chunks of 3 bits, convert to ASCII by adding 48
newAddr >>= 3;
count--;
}
Serial.println(addr);
Serial.println(addrs);
#elif defined (MESH_DEBUG_PRINTF)
printf("Set address 0%o rcvd 0%o\n",mesh_address,addrResponse.new_address);
#endif
Expand Down
3 changes: 2 additions & 1 deletion RF24Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define MESH_ADDR_RELEASE 197
#define MESH_ID_LOOKUP 198

#define MESH_BLANK_ID 65535

/**
* @file RF24Mesh.h
Expand Down Expand Up @@ -135,7 +136,7 @@ class RF24Mesh
*
* @return Returns the unique identifier (1-255) or -1 if not found.
*/
int getNodeID(uint16_t address=0);
int getNodeID(uint16_t address=MESH_BLANK_ID);

/**
* Tests connectivity of this node to the mesh.
Expand Down

0 comments on commit d49dea1

Please sign in to comment.