From 4f702fed7c97cb698f7881f136dd06ef9c3dd29b Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sat, 15 Jun 2024 15:40:57 -0700 Subject: [PATCH] change `DEBUG_LEVEL` into `RF24GATEWAY_DEBUG_LEVEL` see nRF24/RF24#980 --- CMakeLists.txt | 8 ++++---- RF24Gateway.cpp | 32 ++++++++++++++++---------------- RF24Gateway.h | 6 +++--- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ccea80..cbf03e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ target_compile_features(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(DEBUG_LEVEL "adjust the verbosity of the debugging messages" 0) +option(RF24GATEWAY_DEBUG_LEVEL "adjust the verbosity of the debugging messages" 0) # detect CPU and add compiler flags accordingly include(cmake/detectCPU.cmake) @@ -79,9 +79,9 @@ if("${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND" OR DEFINED RF24_NO_INTERRUPT) endif() # assert the appropriate preprocessor macros for RF24Network_config.h -if(DEBUG_LEVEL GREATER 0) - message(STATUS "DEBUG_LEVEL set to ${DEBUG_LEVEL}") - target_compile_definitions(${LibTargetName} PUBLIC DEBUG_LEVEL=${DEBUG_LEVEL}) +if(RF24GATEWAY_DEBUG_LEVEL GREATER 0) + message(STATUS "RF24GATEWAY_DEBUG_LEVEL set to ${RF24GATEWAY_DEBUG_LEVEL}") + target_compile_definitions(${LibTargetName} PUBLIC RF24GATEWAY_DEBUG_LEVEL=${RF24GATEWAY_DEBUG_LEVEL}) endif() ########################### diff --git a/RF24Gateway.cpp b/RF24Gateway.cpp index 7dbd047..62e4952 100644 --- a/RF24Gateway.cpp +++ b/RF24Gateway.cpp @@ -37,7 +37,7 @@ void ESBGateway::begin(uint16_t address, uint8_t _ch template bool ESBGateway::begin(bool configTUN, bool meshEnable, uint16_t address, uint8_t mesh_nodeID, rf24_datarate_e data_rate, uint8_t _channel) { -#if (DEBUG_LEVEL >= 1) +#if (RF24GATEWAY_DEBUG_LEVEL >= 1) printf("GW Begin\n"); printf("Config Device address 0%o nodeID %d\n", address, mesh_nodeID); #endif @@ -84,7 +84,7 @@ bool ESBGateway::begin(bool configTUN, bool meshEnab } network.multicastRelay = 1; - //#if (DEBUG_LEVEL >= 1) + //#if (RF24GATEWAY_DEBUG_LEVEL >= 1) radio.printDetails(); //#endif @@ -171,7 +171,7 @@ int ESBGateway::configDevice(uint16_t address) flags = IFF_TAP | IFF_NO_PI | IFF_MULTI_QUEUE; } tunFd = allocateTunDevice(tunName, flags, address); -#if DEBUG_LEVEL >= 1 +#if RF24GATEWAY_DEBUG_LEVEL >= 1 if (tunFd >= 0) { std::cout << "RF24Gw: Successfully attached to tun/tap device " << tunTapDevice << std::endl; } @@ -207,7 +207,7 @@ int ESBGateway::allocateTunDevice(char* dev, int fla // Create device if (ioctl(fd, TUNSETIFF, (void*)&ifr) < 0) { // close(fd); - //#if (DEBUG_LEVEL >= 1) + //#if (RF24GATEWAY_DEBUG_LEVEL >= 1) std::cerr << "RF24Gw: Error: enabling TUNSETIFF" << std::endl; std::cerr << "RF24Gw: If changing from TAP/TUN, run 'sudo ip link delete tun_nrf24' to remove the interface" << std::endl; return -1; @@ -216,7 +216,7 @@ int ESBGateway::allocateTunDevice(char* dev, int fla // Make persistent if (ioctl(fd, TUNSETPERSIST, 1) < 0) { -#if (DEBUG_LEVEL >= 1) +#if (RF24GATEWAY_DEBUG_LEVEL >= 1) std::cerr << "RF24Gw: Error: enabling TUNSETPERSIST" << std::endl; #endif return -1; @@ -236,7 +236,7 @@ int ESBGateway::allocateTunDevice(char* dev, int fla memcpy((char*)&ifr.ifr_hwaddr, (char*)&sap, sizeof(struct sockaddr)); if (ioctl(fd, SIOCSIFHWADDR, &ifr) < 0) { -#if DEBUG_LEVEL >= 1 +#if RF24GATEWAY_DEBUG_LEVEL >= 1 fprintf(stderr, "RF24Gw: Failed to set MAC address\n"); #endif } @@ -385,10 +385,10 @@ void ESBGateway::handleRadioIn() memcpy(&msg.message, &f.message_buffer, bytesRead); msg.size = bytesRead; -#if (DEBUG_LEVEL >= 1) +#if (RF24GATEWAY_DEBUG_LEVEL >= 1) std::cout << "Radio: Received " << bytesRead << " bytes ... " << std::endl; #endif -#if (DEBUG_LEVEL >= 3) +#if (RF24GATEWAY_DEBUG_LEVEL >= 3) // printPayload(msg.getPayloadStr(),"radio RX"); std::cout << "TunRead: " << std::endl; for (size_t i = 0; i < msg.size; i++) { @@ -456,11 +456,11 @@ void ESBGateway::handleRadioOut() msgStruct* msgTx = &txQueue.front(); -#if (DEBUG_LEVEL >= 1) +#if (RF24GATEWAY_DEBUG_LEVEL >= 1) std::cout << "Radio: Sending " << msgTx->size << " bytes ... "; std::cout << std::endl; #endif -#if (DEBUG_LEVEL >= 3) +#if (RF24GATEWAY_DEBUG_LEVEL >= 3) // PrintDebug == 1 does not have an endline. // printPayload(msg.getPayloadStr(),"radio TX"); @@ -596,10 +596,10 @@ void ESBGateway::handleRX(uint32_t waitDelay) if (FD_ISSET(tunFd, &socketSet)) { if ((nread = read(tunFd, buffer, MAX_PAYLOAD_SIZE)) >= 0) { -#if (DEBUG_LEVEL >= 1) +#if (RF24GATEWAY_DEBUG_LEVEL >= 1) std::cout << "Tun: Successfully read " << nread << " bytes from tun device" << std::endl; #endif -#if (DEBUG_LEVEL >= 3) +#if (RF24GATEWAY_DEBUG_LEVEL >= 3) std::cout << "TunRead: " << std::endl; for (int i = 0; i < nread; i++) { @@ -618,7 +618,7 @@ void ESBGateway::handleRX(uint32_t waitDelay) } } else { -#if (DEBUG_LEVEL >= 1) +#if (RF24GATEWAY_DEBUG_LEVEL >= 1) std::cerr << "Tun: Error while reading from tun/tap interface." << std::endl; #endif } @@ -652,18 +652,18 @@ void ESBGateway::handleTX() if (writtenBytes != msg->size) { // std::cerr << "Tun: Less bytes written to tun/tap device then requested." << std::endl; -#if DEBUG_LEVEL >= 1 +#if RF24GATEWAY_DEBUG_LEVEL >= 1 printf("Tun: Less bytes written %d to tun/tap device then requested %d.", writtenBytes, msg->size); #endif } else { -#if (DEBUG_LEVEL >= 1) +#if (RF24GATEWAY_DEBUG_LEVEL >= 1) std::cout << "Tun: Successfully wrote " << writtenBytes << " bytes to tun device" << std::endl; #endif } -#if (DEBUG_LEVEL >= 3) +#if (RF24GATEWAY_DEBUG_LEVEL >= 3) // printPayload(msg.message,"tun write"); std::cout << "TunRead: " << std::endl; for (size_t i = 0; i < msg->size; i++) { diff --git a/RF24Gateway.h b/RF24Gateway.h index 375dd86..c12c688 100644 --- a/RF24Gateway.h +++ b/RF24Gateway.h @@ -33,9 +33,9 @@ #define IFF_MULTI_QUEUE 0x0100 #endif -#ifndef DEBUG_LEVEL - #define DEBUG_LEVEL 0 -#endif // DEBUG_LEVEL +#ifndef RF24GATEWAY_DEBUG_LEVEL + #define RF24GATEWAY_DEBUG_LEVEL 0 +#endif // RF24GATEWAY_DEBUG_LEVEL #define BACKLOG 10 /* Passed to listen() */