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

change DEBUG_LEVEL into RF24GATEWAY_DEBUG_LEVEL #34

Merged
merged 1 commit into from
Jun 16, 2024
Merged
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
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 @@ -37,7 +37,7 @@ void ESBGateway<mesh_t, network_t, radio_t>::begin(uint16_t address, uint8_t _ch
template<class mesh_t, class network_t, class radio_t>
bool ESBGateway<mesh_t, network_t, radio_t>::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 @@ -84,7 +84,7 @@ bool ESBGateway<mesh_t, network_t, radio_t>::begin(bool configTUN, bool meshEnab
}
network.multicastRelay = 1;

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

Expand Down Expand Up @@ -171,7 +171,7 @@ int ESBGateway<mesh_t, network_t, radio_t>::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 @@ -207,7 +207,7 @@ int ESBGateway<mesh_t, network_t, radio_t>::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;
Expand All @@ -216,7 +216,7 @@ int ESBGateway<mesh_t, network_t, radio_t>::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;
Expand All @@ -236,7 +236,7 @@ int ESBGateway<mesh_t, network_t, radio_t>::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
}
Expand Down Expand Up @@ -385,10 +385,10 @@ void ESBGateway<mesh_t, network_t, radio_t>::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 @@ -456,11 +456,11 @@ void ESBGateway<mesh_t, network_t, radio_t>::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 @@ -596,10 +596,10 @@ void ESBGateway<mesh_t, network_t, radio_t>::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 @@ -618,7 +618,7 @@ void ESBGateway<mesh_t, network_t, radio_t>::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 @@ -652,18 +652,18 @@ void ESBGateway<mesh_t, network_t, radio_t>::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