From 4626fec71bd77ecd78f27439bd0b6dbd0f5b4ada Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sat, 15 Jun 2024 08:23:13 -0700 Subject: [PATCH] change SERIAL_DEBUG into RF24NETWORK_DEBUG see nRF24/RF24#980 --- CMakeLists.txt | 40 ++++----- RF24Network.cpp | 120 ++++++++++++------------- RF24Network_config.h | 34 +++---- examples/Network_Ping/Network_Ping.ino | 2 +- 4 files changed, 98 insertions(+), 98 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 14ba074e..07dc9099 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,17 +29,17 @@ target_compile_features(${LibTargetName}_project_options INTERFACE cxx_std_17) add_compile_options(-Ofast -Wall) # allow using CMake options to adjust RF24Network_config.h without modiying source code -option(SERIAL_DEBUG "enable/disable general debugging output" OFF) -option(SERIAL_DEBUG_MINIMAL "enable/disable minimal debugging output" OFF) -option(SERIAL_DEBUG_ROUTING +option(RF24NETWORK_DEBUG "enable/disable general debugging output" OFF) +option(RF24NETWORK_DEBUG_MINIMAL "enable/disable minimal debugging output" OFF) +option(RF24NETWORK_DEBUG_ROUTING "enable/disable debugging output related to transmission routing" OFF ) -option(SERIAL_DEBUG_FRAGMENTATION +option(RF24NETWORK_DEBUG_FRAGMENTATION "enable/disable debugging output related to message fragmentation" OFF ) -option(SERIAL_DEBUG_FRAGMENTATION_L2 +option(RF24NETWORK_DEBUG_FRAGMENTATION_L2 "enable/disable debugging output related to fragmented messages' transmission success" OFF ) @@ -114,25 +114,25 @@ set_target_properties( ) # assert the appropriate preprocessor macros for RF24Network_config.h -if(SERIAL_DEBUG) - message(STATUS "SERIAL_DEBUG asserted") - target_compile_definitions(${LibTargetName} PUBLIC SERIAL_DEBUG) +if(RF24NETWORK_DEBUG) + message(STATUS "RF24NETWORK_DEBUG asserted") + target_compile_definitions(${LibTargetName} PUBLIC RF24NETWORK_DEBUG) endif() -if(SERIAL_DEBUG_MINIMAL) - message(STATUS "SERIAL_DEBUG_MINIMAL asserted") - target_compile_definitions(${LibTargetName} PUBLIC SERIAL_DEBUG_MINIMAL) +if(RF24NETWORK_DEBUG_MINIMAL) + message(STATUS "RF24NETWORK_DEBUG_MINIMAL asserted") + target_compile_definitions(${LibTargetName} PUBLIC RF24NETWORK_DEBUG_MINIMAL) endif() -if(SERIAL_DEBUG_ROUTING) - message(STATUS "SERIAL_DEBUG_ROUTING asserted") - target_compile_definitions(${LibTargetName} PUBLIC SERIAL_DEBUG_ROUTING) +if(RF24NETWORK_DEBUG_ROUTING) + message(STATUS "RF24NETWORK_DEBUG_ROUTING asserted") + target_compile_definitions(${LibTargetName} PUBLIC RF24NETWORK_DEBUG_ROUTING) endif() -if(SERIAL_DEBUG_FRAGMENTATION) - message(STATUS "SERIAL_DEBUG_FRAGMENTATION asserted") - target_compile_definitions(${LibTargetName} PUBLIC SERIAL_DEBUG_FRAGMENTATION) +if(RF24NETWORK_DEBUG_FRAGMENTATION) + message(STATUS "RF24NETWORK_DEBUG_FRAGMENTATION asserted") + target_compile_definitions(${LibTargetName} PUBLIC RF24NETWORK_DEBUG_FRAGMENTATION) endif() -if(SERIAL_DEBUG_FRAGMENTATION_L2) - message(STATUS "SERIAL_DEBUG_FRAGMENTATION_L2 asserted") - target_compile_definitions(${LibTargetName} PUBLIC SERIAL_DEBUG_FRAGMENTATION_L2) +if(RF24NETWORK_DEBUG_FRAGMENTATION_L2) + message(STATUS "RF24NETWORK_DEBUG_FRAGMENTATION_L2 asserted") + target_compile_definitions(${LibTargetName} PUBLIC RF24NETWORK_DEBUG_FRAGMENTATION_L2) endif() if(DISABLE_FRAGMENTATION) message(STATUS "DISABLE_FRAGMENTATION asserted") diff --git a/RF24Network.cpp b/RF24Network.cpp index 85793ad0..6cd1c282 100644 --- a/RF24Network.cpp +++ b/RF24Network.cpp @@ -157,16 +157,16 @@ uint8_t ESBNetwork::update(void) if (frame_size < sizeof(RF24NetworkHeader) || !is_valid_address(header->to_node) || !is_valid_address(header->from_node)) { continue; } - //IF_SERIAL_DEBUG(printf_P(PSTR("MAC Received " PRIPSTR + //IF_RF24NETWORK_DEBUG(printf_P(PSTR("MAC Received " PRIPSTR // "\n\r"), // header->toString())); #if defined(RF24_LINUX) if (frame_size) { - IF_SERIAL_DEBUG_FRAGMENTATION_L2(printf_P(PSTR("%u: FRG Rcv frame size %i\n"), millis(), frame_size);); - IF_SERIAL_DEBUG_FRAGMENTATION_L2(printf_P(PSTR("%u: FRG Rcv frame "), millis()); const char* charPtr = reinterpret_cast(frame_buffer); for (uint16_t i = 0; i < frame_size; i++) { printf_P(PSTR("%02X "), charPtr[i]); }; printf_P(PSTR("\n\r"))); + IF_RF24NETWORK_DEBUG_FRAGMENTATION_L2(printf_P(PSTR("%u: FRG Rcv frame size %i\n"), millis(), frame_size);); + IF_RF24NETWORK_DEBUG_FRAGMENTATION_L2(printf_P(PSTR("%u: FRG Rcv frame "), millis()); const char* charPtr = reinterpret_cast(frame_buffer); for (uint16_t i = 0; i < frame_size; i++) { printf_P(PSTR("%02X "), charPtr[i]); }; printf_P(PSTR("\n\r"))); } #else - IF_SERIAL_DEBUG(const uint16_t* i = reinterpret_cast(frame_buffer + sizeof(RF24NetworkHeader)); printf_P(PSTR("NET message %04x\n\r"), *i)); + IF_RF24NETWORK_DEBUG(const uint16_t* i = reinterpret_cast(frame_buffer + sizeof(RF24NetworkHeader)); printf_P(PSTR("NET message %04x\n\r"), *i)); #endif returnVal = header->type; @@ -190,14 +190,14 @@ uint8_t ESBNetwork::update(void) continue; } if ((returnSysMsgs && header->type > MAX_USER_DEFINED_HEADER_TYPE) || header->type == NETWORK_ACK) { - IF_SERIAL_DEBUG_ROUTING(printf_P(PSTR("MAC System payload rcvd %d\n"), returnVal);); + IF_RF24NETWORK_DEBUG_ROUTING(printf_P(PSTR("MAC System payload rcvd %d\n"), returnVal);); if (header->type != NETWORK_FIRST_FRAGMENT && header->type != NETWORK_MORE_FRAGMENTS && header->type != EXTERNAL_DATA_TYPE && header->type != NETWORK_LAST_FRAGMENT) { return returnVal; } } if (enqueue(header) == 2) { //External data received - IF_SERIAL_DEBUG_MINIMAL(printf_P(PSTR("ret ext\n"));); + IF_RF24NETWORK_DEBUG_MINIMAL(printf_P(PSTR("ret ext\n"));); return EXTERNAL_DATA_TYPE; } } @@ -223,7 +223,7 @@ uint8_t ESBNetwork::update(void) uint8_t val = enqueue(header); if (multicastRelay) { - IF_SERIAL_DEBUG_ROUTING(printf_P(PSTR("MAC FWD multicast frame from 0%o to level %u\n"), header->from_node, _multicast_level + 1);); + IF_RF24NETWORK_DEBUG_ROUTING(printf_P(PSTR("MAC FWD multicast frame from 0%o to level %u\n"), header->from_node, _multicast_level + 1);); if ((node_address >> 3) != 0) { // for all but the first level of nodes, those not directly connected to the master, we add the total delay per level delayMicroseconds(600 * 4); @@ -279,14 +279,14 @@ uint8_t ESBNetwork::enqueue(RF24NetworkHeader* header) else if (isFragment) { //The received frame contains the a fragmented payload //Set the more fragments flag to indicate a fragmented frame - IF_SERIAL_DEBUG_FRAGMENTATION_L2(printf_P(PSTR("%u: FRG Payload type %d of size %i Bytes with fragmentID '%i' received.\n\r"), millis(), frame.header.type, frame.message_size, frame.header.reserved);); + IF_RF24NETWORK_DEBUG_FRAGMENTATION_L2(printf_P(PSTR("%u: FRG Payload type %d of size %i Bytes with fragmentID '%i' received.\n\r"), millis(), frame.header.type, frame.message_size, frame.header.reserved);); //Append payload result = appendFragmentToFrame(frame); //The header.reserved contains the actual header.type on the last fragment if (result && frame.header.type == NETWORK_LAST_FRAGMENT) { - IF_SERIAL_DEBUG_FRAGMENTATION(printf_P(PSTR("%u: FRG Last fragment received\n"), millis())); - IF_SERIAL_DEBUG(printf_P(PSTR("%u: NET Enqueue assembled frame @ %u\n"), millis(), frame_queue.size())); + IF_RF24NETWORK_DEBUG_FRAGMENTATION(printf_P(PSTR("%u: FRG Last fragment received\n"), millis())); + IF_RF24NETWORK_DEBUG(printf_P(PSTR("%u: NET Enqueue assembled frame @ %u\n"), millis(), frame_queue.size())); RF24NetworkFrame* f = &(frameFragmentsCache[frame.header.from_node]); @@ -308,7 +308,7 @@ uint8_t ESBNetwork::enqueue(RF24NetworkHeader* header) //if (frame.header.type <= MAX_USER_DEFINED_HEADER_TYPE) { //This is not a fragmented payload but a whole frame. - IF_SERIAL_DEBUG(printf_P(PSTR("%u: NET Enqueue @ %u\n"), millis(), frame_queue.size())); + IF_RF24NETWORK_DEBUG(printf_P(PSTR("%u: NET Enqueue @ %u\n"), millis(), frame_queue.size())); // Copy the current frame into the frame queue result = frame.header.type == EXTERNAL_DATA_TYPE ? 2 : 1; //Load external payloads into a separate queue on linux @@ -321,16 +321,16 @@ uint8_t ESBNetwork::enqueue(RF24NetworkHeader* header) } /* else { //Undefined/Unknown header.type received. Drop frame! - IF_SERIAL_DEBUG_MINIMAL( printf("%u: FRG Received unknown or system header type %d with fragment id %d\n",millis(),frame.header.type, frame.header.reserved); ); + IF_RF24NETWORK_DEBUG_MINIMAL( printf("%u: FRG Received unknown or system header type %d with fragment id %d\n",millis(),frame.header.type, frame.header.reserved); ); //The frame is not explicitly dropped, but the given object is ignored. //FIXME: does this causes problems with memory management? }*/ if (result) { - //IF_SERIAL_DEBUG(printf_P(PSTR("ok\n\r"))); + //IF_RF24NETWORK_DEBUG(printf_P(PSTR("ok\n\r"))); } else { - IF_SERIAL_DEBUG(printf_P(PSTR("failed\n\r"))); + IF_RF24NETWORK_DEBUG(printf_P(PSTR("failed\n\r"))); } return result; @@ -363,7 +363,7 @@ bool ESBNetwork::appendFragmentToFrame(RF24NetworkFrame frame) RF24NetworkFrame* f = &(frameFragmentsCache[frame.header.from_node]); if (f->message_size + frame.message_size > MAX_PAYLOAD_SIZE) { - IF_SERIAL_DEBUG_FRAGMENTATION(printf_P(PSTR("%u: FRG Frame of size %d plus enqueued frame of size %d exceeds max payload size \n"), millis(), frame.message_size, f->message_size);); + IF_RF24NETWORK_DEBUG_FRAGMENTATION(printf_P(PSTR("%u: FRG Frame of size %d plus enqueued frame of size %d exceeds max payload size \n"), millis(), frame.message_size, f->message_size);); return false; } @@ -375,7 +375,7 @@ bool ESBNetwork::appendFragmentToFrame(RF24NetworkFrame frame) return true; } else { - IF_SERIAL_DEBUG_FRAGMENTATION(printf_P(PSTR("%u: FRG Dropping fragment for frame with header id:%d, out of order fragment(s).\n"), millis(), frame.header.id);); + IF_RF24NETWORK_DEBUG_FRAGMENTATION(printf_P(PSTR("%u: FRG Dropping fragment for frame with header id:%d, out of order fragment(s).\n"), millis(), frame.header.id);); return false; } } @@ -389,12 +389,12 @@ bool ESBNetwork::appendFragmentToFrame(RF24NetworkFrame frame) RF24NetworkFrame* f = &(frameFragmentsCache[frame.header.from_node]); if (f->message_size + frame.message_size > MAX_PAYLOAD_SIZE) { - IF_SERIAL_DEBUG_FRAGMENTATION(printf_P(PSTR("%u: FRG Frame of size %d plus enqueued frame of size %d exceeds max payload size \n"), millis(), frame.message_size, f->message_size);); + IF_RF24NETWORK_DEBUG_FRAGMENTATION(printf_P(PSTR("%u: FRG Frame of size %d plus enqueued frame of size %d exceeds max payload size \n"), millis(), frame.message_size, f->message_size);); return false; } //Error checking for missed fragments and payload size if (f->header.reserved - 1 != 1 || f->header.id != frame.header.id) { - IF_SERIAL_DEBUG_FRAGMENTATION(printf_P(PSTR("%u: FRG Duplicate or out of sequence frame %d, expected %d. Cleared.\n\r"), millis(), frame.header.reserved, f->header.reserved);); + IF_RF24NETWORK_DEBUG_FRAGMENTATION(printf_P(PSTR("%u: FRG Duplicate or out of sequence frame %d, expected %d. Cleared.\n\r"), millis(), frame.header.reserved, f->header.reserved);); //frameFragmentsCache.erase( std::make_pair(frame.header.id,frame.header.from_node) ); return false; } @@ -423,7 +423,7 @@ uint8_t ESBNetwork::enqueue(RF24NetworkHeader* header) bool result = false; uint16_t message_size = frame_size - sizeof(RF24NetworkHeader); - IF_SERIAL_DEBUG(printf_P(PSTR("NET Enqueue @%x\n"), next_frame - frame_queue)); + IF_RF24NETWORK_DEBUG(printf_P(PSTR("NET Enqueue @%x\n"), next_frame - frame_queue)); #if !defined(DISABLE_FRAGMENTATION) @@ -436,25 +436,25 @@ uint8_t ESBNetwork::enqueue(RF24NetworkHeader* header) memcpy((char*)(&frag_queue), &frame_buffer, sizeof(RF24NetworkHeader)); memcpy(frag_queue.message_buffer, frame_buffer + sizeof(RF24NetworkHeader), message_size); - IF_SERIAL_DEBUG_FRAGMENTATION(printf_P(PSTR("queue first, total frags %d\n\r"), header->reserved);); + IF_RF24NETWORK_DEBUG_FRAGMENTATION(printf_P(PSTR("queue first, total frags %d\n\r"), header->reserved);); //Store the total size of the stored frame in message_size frag_queue.message_size = message_size; --frag_queue.header.reserved; - IF_SERIAL_DEBUG_FRAGMENTATION_L2(for (int i = 0; i < frag_queue.message_size; i++) { printf_P(PSTR("%02x"), frag_queue.message_buffer[i]); }); + IF_RF24NETWORK_DEBUG_FRAGMENTATION_L2(for (int i = 0; i < frag_queue.message_size; i++) { printf_P(PSTR("%02x"), frag_queue.message_buffer[i]); }); return true; } // else if not first fragment else if (header->type == NETWORK_LAST_FRAGMENT || header->type == NETWORK_MORE_FRAGMENTS) { if (frag_queue.message_size + message_size > MAX_PAYLOAD_SIZE) { - #if defined(SERIAL_DEBUG_FRAGMENTATION) || defined(SERIAL_DEBUG_MINIMAL) + #if defined(RF24NETWORK_DEBUG_FRAGMENTATION) || defined(RF24NETWORK_DEBUG_MINIMAL) printf_P(PSTR("Drop frag %d Size exceeds max\n\r"), header->reserved); #endif frag_queue.header.reserved = 0; return false; } if (frag_queue.header.reserved == 0 || (header->type != NETWORK_LAST_FRAGMENT && header->reserved != frag_queue.header.reserved) || frag_queue.header.id != header->id) { - #if defined(SERIAL_DEBUG_FRAGMENTATION) || defined(SERIAL_DEBUG_MINIMAL) + #if defined(RF24NETWORK_DEBUG_FRAGMENTATION) || defined(RF24NETWORK_DEBUG_MINIMAL) printf_P(PSTR("Drop frag %d Out of order\n\r"), header->reserved); #endif return false; @@ -470,8 +470,8 @@ uint8_t ESBNetwork::enqueue(RF24NetworkHeader* header) frag_queue.header.reserved = 0; frag_queue.header.type = header->reserved; - IF_SERIAL_DEBUG_FRAGMENTATION(printf_P(PSTR("fq 3: %d\n"), frag_queue.message_size);); - IF_SERIAL_DEBUG_FRAGMENTATION_L2(for (int i = 0; i < frag_queue.message_size; i++) { printf_P(PSTR("%02X"), frag_queue.message_buffer[i]); }); + IF_RF24NETWORK_DEBUG_FRAGMENTATION(printf_P(PSTR("fq 3: %d\n"), frag_queue.message_size);); + IF_RF24NETWORK_DEBUG_FRAGMENTATION_L2(for (int i = 0; i < frag_queue.message_size; i++) { printf_P(PSTR("%02X"), frag_queue.message_buffer[i]); }); // Frame assembly complete, copy to main buffer if OK if (frag_queue.header.type == EXTERNAL_DATA_TYPE) { @@ -490,10 +490,10 @@ uint8_t ESBNetwork::enqueue(RF24NetworkHeader* header) next_frame += 4 - padding; } #endif - IF_SERIAL_DEBUG_FRAGMENTATION(printf_P(PSTR("enq size %d\n"), frag_queue.message_size);); + IF_RF24NETWORK_DEBUG_FRAGMENTATION(printf_P(PSTR("enq size %d\n"), frag_queue.message_size);); return true; } - IF_SERIAL_DEBUG_FRAGMENTATION(printf_P(PSTR("Drop frag payload, queue full\n"));); + IF_RF24NETWORK_DEBUG_FRAGMENTATION(printf_P(PSTR("Drop frag payload, queue full\n"));); return false; } //If more or last fragments @@ -520,7 +520,7 @@ uint8_t ESBNetwork::enqueue(RF24NetworkHeader* header) memcpy(next_frame + 8, &message_size, 2); memcpy(next_frame + 10, frame_buffer + 8, message_size); - //IF_SERIAL_DEBUG_FRAGMENTATION( for(int i=0; i::enqueue(RF24NetworkHeader* header) next_frame += 4 - padding; } #endif - //IF_SERIAL_DEBUG_FRAGMENTATION( Serial.print("Enq "); Serial.println(next_frame-frame_queue); );//printf_P(PSTR("enq %d\n"),next_frame-frame_queue); ); + //IF_RF24NETWORK_DEBUG_FRAGMENTATION( Serial.print("Enq "); Serial.println(next_frame-frame_queue); );//printf_P(PSTR("enq %d\n"),next_frame-frame_queue); ); result = true; } else { result = false; - IF_SERIAL_DEBUG(printf_P(PSTR("NET **Drop Payload** Buffer Full"))); + IF_RF24NETWORK_DEBUG(printf_P(PSTR("NET **Drop Payload** Buffer Full"))); } return result; } @@ -630,10 +630,10 @@ uint16_t ESBNetwork::read(RF24NetworkHeader& header, void* message, uin memcpy(&header, &(frame.header), sizeof(RF24NetworkHeader)); memcpy(message, frame.message_buffer, bufsize); - IF_SERIAL_DEBUG(printf_P(PSTR("%u: FRG message size %i\n"), millis(), frame.message_size);); - IF_SERIAL_DEBUG(printf_P(PSTR("%u: FRG message "), millis()); const char* charPtr = reinterpret_cast(message); for (uint16_t i = 0; i < bufsize; i++) { printf_P(PSTR("%02X "), charPtr[i]); }; printf(PSTR("\n\r"))); + IF_RF24NETWORK_DEBUG(printf_P(PSTR("%u: FRG message size %i\n"), millis(), frame.message_size);); + IF_RF24NETWORK_DEBUG(printf_P(PSTR("%u: FRG message "), millis()); const char* charPtr = reinterpret_cast(message); for (uint16_t i = 0; i < bufsize; i++) { printf_P(PSTR("%02X "), charPtr[i]); }; printf(PSTR("\n\r"))); - IF_SERIAL_DEBUG(printf_P(PSTR("%u: NET read " PRIPSTR + IF_RF24NETWORK_DEBUG(printf_P(PSTR("%u: NET read " PRIPSTR "\n\r"), millis(), header.toString())); @@ -647,9 +647,9 @@ uint16_t ESBNetwork::read(RF24NetworkHeader& header, void* message, uin if (maxlen > 0) { maxlen = rf24_min(maxlen, bufsize); memcpy(message, frame_queue + 10, maxlen); - IF_SERIAL_DEBUG(printf_P(PSTR("NET message size %d\n"), bufsize);); + IF_RF24NETWORK_DEBUG(printf_P(PSTR("NET message size %d\n"), bufsize);); - IF_SERIAL_DEBUG(uint16_t len = maxlen; printf_P(PSTR("NET message ")); const uint8_t* charPtr = reinterpret_cast(message); while (len--) { printf_P(PSTR("%02x "), charPtr[len]); } printf_P(PSTR("\n\r"))); + IF_RF24NETWORK_DEBUG(uint16_t len = maxlen; printf_P(PSTR("NET message ")); const uint8_t* charPtr = reinterpret_cast(message); while (len--) { printf_P(PSTR("%02x "), charPtr[len]); } printf_P(PSTR("\n\r"))); } next_frame -= bufsize + 10; uint8_t padding = 0; @@ -660,7 +660,7 @@ uint16_t ESBNetwork::read(RF24NetworkHeader& header, void* message, uin } #endif // !defined(ARDUINO_ARCH_AVR) memmove(frame_queue, frame_queue + bufsize + 10 + padding, sizeof(frame_queue) - bufsize); - //IF_SERIAL_DEBUG(printf_P(PSTR("%u: NET Received %s\n\r"), millis(), header.toString())); + //IF_RF24NETWORK_DEBUG(printf_P(PSTR("%u: NET Received %s\n\r"), millis(), header.toString())); #endif // !defined(RF24_LINUX) return bufsize; @@ -705,7 +705,7 @@ bool ESBNetwork::write(RF24NetworkHeader& header, const void* message, //Check payload size if (len > MAX_PAYLOAD_SIZE) { - IF_SERIAL_DEBUG(printf_P(PSTR("NET write message failed. Given 'len' %d is bigger than the MAX Payload size %i\n\r"), len, MAX_PAYLOAD_SIZE);); + IF_RF24NETWORK_DEBUG(printf_P(PSTR("NET write message failed. Given 'len' %d is bigger than the MAX Payload size %i\n\r"), len, MAX_PAYLOAD_SIZE);); return false; } @@ -714,7 +714,7 @@ bool ESBNetwork::write(RF24NetworkHeader& header, const void* message, uint8_t msgCount = 0; - IF_SERIAL_DEBUG_FRAGMENTATION(printf_P(PSTR("FRG Total message fragments %d\n\r"), fragment_id);); + IF_RF24NETWORK_DEBUG_FRAGMENTATION(printf_P(PSTR("FRG Total message fragments %d\n\r"), fragment_id);); if (header.to_node != NETWORK_MULTICAST_ADDRESS) { networkFlags |= FLAG_FAST_FRAG; @@ -762,12 +762,12 @@ bool ESBNetwork::write(RF24NetworkHeader& header, const void* message, //if(writeDirect != NETWORK_AUTO_ROUTING){ delay(2); } //Delay 2ms between sending multicast payloads if (!ok && retriesPerFrag >= 3) { - IF_SERIAL_DEBUG_FRAGMENTATION(printf_P(PSTR("FRG TX with fragmentID '%d' failed after %d fragments. Abort.\n\r"), fragment_id, msgCount)); + IF_RF24NETWORK_DEBUG_FRAGMENTATION(printf_P(PSTR("FRG TX with fragmentID '%d' failed after %d fragments. Abort.\n\r"), fragment_id, msgCount)); break; } // Message was successful sent - IF_SERIAL_DEBUG_FRAGMENTATION_L2(printf_P(PSTR("FRG message transmission with fragmentID '%d' successful.\n\r"), fragment_id)); + IF_RF24NETWORK_DEBUG_FRAGMENTATION_L2(printf_P(PSTR("FRG message transmission with fragmentID '%d' successful.\n\r"), fragment_id)); } header.type = type; if (networkFlags & FLAG_FAST_FRAG) { @@ -778,7 +778,7 @@ bool ESBNetwork::write(RF24NetworkHeader& header, const void* message, networkFlags &= ~FLAG_FAST_FRAG; // Return true if all the chunks where sent successfully - IF_SERIAL_DEBUG_FRAGMENTATION(printf_P(PSTR("FRG total message fragments sent %i.\r\n"), msgCount);); + IF_RF24NETWORK_DEBUG_FRAGMENTATION(printf_P(PSTR("FRG total message fragments sent %i.\r\n"), msgCount);); if (!ok || fragment_id > 0) { return false; @@ -799,19 +799,19 @@ bool ESBNetwork::_write(RF24NetworkHeader& header, const void* message, // Build the full frame to send memcpy(frame_buffer, &header, sizeof(RF24NetworkHeader)); - //IF_SERIAL_DEBUG(printf_P(PSTR("NET Sending " PRIPSTR + //IF_RF24NETWORK_DEBUG(printf_P(PSTR("NET Sending " PRIPSTR // "\n\r"), // header.toString())); if (len) { #if defined(RF24_LINUX) memcpy(frame_buffer + sizeof(RF24NetworkHeader), message, rf24_min(frame_size - sizeof(RF24NetworkHeader), len)); - IF_SERIAL_DEBUG(printf_P(PSTR("%u: FRG frame size %i\n"), millis(), frame_size);); - IF_SERIAL_DEBUG(printf_P(PSTR("%u: FRG frame "), millis()); const char* charPtr = reinterpret_cast(frame_buffer); for (uint16_t i = 0; i < frame_size; i++) { printf_P(PSTR("%02X "), charPtr[i]); }; printf_P(PSTR("\n\r"))); + IF_RF24NETWORK_DEBUG(printf_P(PSTR("%u: FRG frame size %i\n"), millis(), frame_size);); + IF_RF24NETWORK_DEBUG(printf_P(PSTR("%u: FRG frame "), millis()); const char* charPtr = reinterpret_cast(frame_buffer); for (uint16_t i = 0; i < frame_size; i++) { printf_P(PSTR("%02X "), charPtr[i]); }; printf_P(PSTR("\n\r"))); #else memcpy(frame_buffer + sizeof(RF24NetworkHeader), message, len); - IF_SERIAL_DEBUG(uint16_t tmpLen = len; printf_P(PSTR("NET message ")); const uint8_t* charPtr = reinterpret_cast(message); while (tmpLen--) { printf_P(PSTR("%02x "), charPtr[tmpLen]); } printf_P(PSTR("\n\r"))); + IF_RF24NETWORK_DEBUG(uint16_t tmpLen = len; printf_P(PSTR("NET message ")); const uint8_t* charPtr = reinterpret_cast(message); while (tmpLen--) { printf_P(PSTR("%02x "), charPtr[tmpLen]); } printf_P(PSTR("\n\r"))); #endif } @@ -862,7 +862,7 @@ bool ESBNetwork::write(uint16_t to_node, uint8_t sendType) logicalToPhysicalStruct conversion = {to_node, sendType, 0}; logicalToPhysicalAddress(&conversion); - IF_SERIAL_DEBUG(printf_P(PSTR("MAC Sending to 0%o via 0%o on pipe %x\n\r"), to_node, conversion.send_node, conversion.send_pipe)); + IF_RF24NETWORK_DEBUG(printf_P(PSTR("MAC Sending to 0%o via 0%o on pipe %x\n\r"), to_node, conversion.send_node, conversion.send_pipe)); /**Write it*/ if (sendType == TX_ROUTED && conversion.send_node == to_node && isAckType) { delay(2); @@ -870,7 +870,7 @@ bool ESBNetwork::write(uint16_t to_node, uint8_t sendType) ok = write_to_pipe(conversion.send_node, conversion.send_pipe, conversion.multicast); if (!ok) { - IF_SERIAL_DEBUG_ROUTING(printf_P(PSTR("MAC Send fail to 0%o via 0%o on pipe %x\n\r"), to_node, conversion.send_node, conversion.send_pipe);); + IF_RF24NETWORK_DEBUG_ROUTING(printf_P(PSTR("MAC Send fail to 0%o via 0%o on pipe %x\n\r"), to_node, conversion.send_node, conversion.send_pipe);); } if (sendType == TX_ROUTED && ok && conversion.send_node == to_node && isAckType) { @@ -892,7 +892,7 @@ bool ESBNetwork::write(uint16_t to_node, uint8_t sendType) write_to_pipe(conversion.send_node, conversion.send_pipe, conversion.multicast); // dynLen=0; - IF_SERIAL_DEBUG_ROUTING(printf_P(PSTR("MAC Route OK to 0%o ACK sent to 0%o\n"), to_node, header->from_node);); + IF_RF24NETWORK_DEBUG_ROUTING(printf_P(PSTR("MAC Route OK to 0%o ACK sent to 0%o\n"), to_node, header->from_node);); } if (ok && conversion.send_node != to_node && (sendType == TX_NORMAL || sendType == USER_TX_TO_LOGICAL_ADDRESS) && isAckType) { @@ -910,7 +910,7 @@ bool ESBNetwork::write(uint16_t to_node, uint8_t sendType) delayMicroseconds(900); #endif if (millis() - reply_time > routeTimeout) { - IF_SERIAL_DEBUG_ROUTING(printf_P(PSTR("MAC Network ACK fail from 0%o via 0%o on pipe %x\n\r"), to_node, conversion.send_node, conversion.send_pipe);); + IF_RF24NETWORK_DEBUG_ROUTING(printf_P(PSTR("MAC Network ACK fail from 0%o via 0%o on pipe %x\n\r"), to_node, conversion.send_node, conversion.send_pipe);); ok = false; break; } @@ -1004,9 +1004,9 @@ bool ESBNetwork::write_to_pipe(uint16_t node, uint8_t pipe, bool multic /* #if defined (__arm__) || defined (RF24_LINUX) - IF_SERIAL_DEBUG(printf_P(PSTR("%u: MAC Sent on %x %s\n\r"), millis(), (uint32_t)out_pipe, ok ? PSTR("ok") : PSTR("failed"))); + IF_RF24NETWORK_DEBUG(printf_P(PSTR("%u: MAC Sent on %x %s\n\r"), millis(), (uint32_t)out_pipe, ok ? PSTR("ok") : PSTR("failed"))); #else - IF_SERIAL_DEBUG(printf_P(PSTR("%u: MAC Sent on %lx %S\n\r"), millis(), (uint32_t)out_pipe, ok ? PSTR("ok") : PSTR("failed"))); + IF_RF24NETWORK_DEBUG(printf_P(PSTR("%u: MAC Sent on %lx %S\n\r"), millis(), (uint32_t)out_pipe, ok ? PSTR("ok") : PSTR("failed"))); #endif */ return ok; @@ -1084,11 +1084,11 @@ void ESBNetwork::setup_address(void) } parent_pipe = i; - IF_SERIAL_DEBUG_MINIMAL(printf_P(PSTR("setup_address node=0%o mask=0%o parent=0%o pipe=0%o\n\r"), node_address, node_mask, parent_node, parent_pipe);); - // IF_SERIAL_DEBUG_MINIMAL(Serial.print(F("setup_address node="))); - // IF_SERIAL_DEBUG_MINIMAL(Serial.print(node_address,OCT)); - // IF_SERIAL_DEBUG_MINIMAL(Serial.print(F(" parent="))); - // IF_SERIAL_DEBUG_MINIMAL(Serial.println(parent_node,OCT)); + IF_RF24NETWORK_DEBUG_MINIMAL(printf_P(PSTR("setup_address node=0%o mask=0%o parent=0%o pipe=0%o\n\r"), node_address, node_mask, parent_node, parent_pipe);); + // IF_RF24NETWORK_DEBUG_MINIMAL(Serial.print(F("setup_address node="))); + // IF_RF24NETWORK_DEBUG_MINIMAL(Serial.print(node_address,OCT)); + // IF_RF24NETWORK_DEBUG_MINIMAL(Serial.print(F(" parent="))); + // IF_RF24NETWORK_DEBUG_MINIMAL(Serial.println(parent_node,OCT)); } /******************************************************************/ @@ -1129,14 +1129,14 @@ bool ESBNetwork::is_valid_address(uint16_t node) return result; } uint8_t count = 0; -#if defined(SERIAL_DEBUG_MINIMAL) +#if defined(RF24NETWORK_DEBUG_MINIMAL) uint16_t origNode = node; #endif while (node) { uint8_t digit = node & 0x07; if (digit < 1 || digit > (NUM_PIPES - 1)) { result = false; - IF_SERIAL_DEBUG_MINIMAL(printf_P(PSTR("*** WARNING *** Invalid address 0%o\n\r"), origNode);); + IF_RF24NETWORK_DEBUG_MINIMAL(printf_P(PSTR("*** WARNING *** Invalid address 0%o\n\r"), origNode);); break; } node >>= 3; @@ -1144,7 +1144,7 @@ bool ESBNetwork::is_valid_address(uint16_t node) } if (count > 4) { - IF_SERIAL_DEBUG_MINIMAL(printf_P(PSTR("*** WARNING *** Invalid address 0%o\n\r"), origNode);); + IF_RF24NETWORK_DEBUG_MINIMAL(printf_P(PSTR("*** WARNING *** Invalid address 0%o\n\r"), origNode);); return false; } return result; @@ -1225,7 +1225,7 @@ uint64_t ESBNetwork::pipe_address(uint16_t node, uint8_t pipe) else out[1] = address_translation[count - 1]; #endif - IF_SERIAL_DEBUG(uint32_t* top = reinterpret_cast(out + 1); printf_P(PSTR("NET Pipe %i on node 0%o has address %x%x\n\r"), pipe, node, *top, *out)); + IF_RF24NETWORK_DEBUG(uint32_t* top = reinterpret_cast(out + 1); printf_P(PSTR("NET Pipe %i on node 0%o has address %x%x\n\r"), pipe, node, *top, *out)); return result; } diff --git a/RF24Network_config.h b/RF24Network_config.h index 33513c86..861a5055 100644 --- a/RF24Network_config.h +++ b/RF24Network_config.h @@ -89,11 +89,11 @@ #define NUM_PIPES 6 /* Debug Options */ - //#define SERIAL_DEBUG - //#define SERIAL_DEBUG_MINIMAL - //#define SERIAL_DEBUG_ROUTING - //#define SERIAL_DEBUG_FRAGMENTATION - //#define SERIAL_DEBUG_FRAGMENTATION_L2 + //#define RF24NETWORK_DEBUG + //#define RF24NETWORK_DEBUG_MINIMAL + //#define RF24NETWORK_DEBUG_ROUTING + //#define RF24NETWORK_DEBUG_FRAGMENTATION + //#define RF24NETWORK_DEBUG_FRAGMENTATION_L2 /*************************************/ #else // Different set of defaults for ATTiny - fragmentation is disabled and user payloads are set to 3 max @@ -130,28 +130,28 @@ #endif #endif -#if defined(SERIAL_DEBUG_MINIMAL) - #define IF_SERIAL_DEBUG_MINIMAL(x) ({ x; }) +#if defined(RF24NETWORK_DEBUG_MINIMAL) + #define IF_RF24NETWORK_DEBUG_MINIMAL(x) ({ x; }) #else - #define IF_SERIAL_DEBUG_MINIMAL(x) + #define IF_RF24NETWORK_DEBUG_MINIMAL(x) #endif -#if defined(SERIAL_DEBUG_FRAGMENTATION) - #define IF_SERIAL_DEBUG_FRAGMENTATION(x) ({ x; }) +#if defined(RF24NETWORK_DEBUG_FRAGMENTATION) + #define IF_RF24NETWORK_DEBUG_FRAGMENTATION(x) ({ x; }) #else - #define IF_SERIAL_DEBUG_FRAGMENTATION(x) + #define IF_RF24NETWORK_DEBUG_FRAGMENTATION(x) #endif -#if defined(SERIAL_DEBUG_FRAGMENTATION_L2) - #define IF_SERIAL_DEBUG_FRAGMENTATION_L2(x) ({ x; }) +#if defined(RF24NETWORK_DEBUG_FRAGMENTATION_L2) + #define IF_RF24NETWORK_DEBUG_FRAGMENTATION_L2(x) ({ x; }) #else - #define IF_SERIAL_DEBUG_FRAGMENTATION_L2(x) + #define IF_RF24NETWORK_DEBUG_FRAGMENTATION_L2(x) #endif -#if defined(SERIAL_DEBUG_ROUTING) - #define IF_SERIAL_DEBUG_ROUTING(x) ({ x; }) +#if defined(RF24NETWORK_DEBUG_ROUTING) + #define IF_RF24NETWORK_DEBUG_ROUTING(x) ({ x; }) #else - #define IF_SERIAL_DEBUG_ROUTING(x) + #define IF_RF24NETWORK_DEBUG_ROUTING(x) #endif #endif // RF24_CONFIG_H diff --git a/examples/Network_Ping/Network_Ping.ino b/examples/Network_Ping/Network_Ping.ino index 317a9e1f..f5d6be55 100644 --- a/examples/Network_Ping/Network_Ping.ino +++ b/examples/Network_Ping/Network_Ping.ino @@ -18,7 +18,7 @@ * periodically sends out its whole known list of nodes to everyone. * * To see the underlying frames being relayed, compile RF24Network with - * #define SERIAL_DEBUG. + * #define RF24NETWORK_DEBUG. * * Update: The logical node address of each node is set below, and are grouped in twos for demonstration. * Number 0 is the master node. Numbers 1-2 represent the 2nd layer in the tree (02,05).