Skip to content

Commit

Permalink
change DEBUG_LEVEL into RF24GATEWAY_DEBUG_LEVEL (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
2bndy5 committed Jun 16, 2024
1 parent 9fb4e28 commit 2983da0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()

###########################
Expand Down
32 changes: 16 additions & 16 deletions RF24Gateway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void RF24Gateway::begin(uint16_t address, uint8_t _channel, rf24_datarate_e data

bool RF24Gateway::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
Expand Down Expand Up @@ -80,7 +80,7 @@ bool RF24Gateway::begin(bool configTUN, bool meshEnable, uint16_t address, uint8
}
network.multicastRelay = 1;

//#if (DEBUG_LEVEL >= 1)
//#if (RF24GATEWAY_DEBUG_LEVEL >= 1)
radio.printDetails();
//#endif

Expand Down Expand Up @@ -164,7 +164,7 @@ int RF24Gateway::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;
}
Expand Down Expand Up @@ -199,7 +199,7 @@ int RF24Gateway::allocateTunDevice(char* dev, int flags, uint16_t address)
// 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;
Expand All @@ -208,7 +208,7 @@ int RF24Gateway::allocateTunDevice(char* dev, int flags, uint16_t address)

// 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;
Expand All @@ -228,7 +228,7 @@ int RF24Gateway::allocateTunDevice(char* dev, int flags, uint16_t address)
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
}
Expand Down Expand Up @@ -370,10 +370,10 @@ void RF24Gateway::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++) {
Expand Down Expand Up @@ -439,11 +439,11 @@ void RF24Gateway::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");
Expand Down Expand Up @@ -578,10 +578,10 @@ void RF24Gateway::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++)
{
Expand All @@ -600,7 +600,7 @@ void RF24Gateway::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
}
Expand Down Expand Up @@ -633,18 +633,18 @@ void RF24Gateway::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++) {
Expand Down
6 changes: 3 additions & 3 deletions RF24Gateway.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() */

Expand Down

0 comments on commit 2983da0

Please sign in to comment.