Skip to content

Commit

Permalink
ran clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
2bndy5 committed Feb 16, 2024
1 parent 2fa3a10 commit 40f2ff0
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 41 deletions.
42 changes: 28 additions & 14 deletions RF24Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ template<class network_t, class radio_t>
uint8_t ESBMesh<network_t, radio_t>::update()
{
uint8_t type = network.update();
if (mesh_address == MESH_DEFAULT_ADDRESS) return type;
if (mesh_address == MESH_DEFAULT_ADDRESS)
return type;

#if !defined(MESH_NOMASTER)
if (type == NETWORK_REQ_ADDRESS) {
Expand Down Expand Up @@ -106,7 +107,8 @@ uint8_t ESBMesh<network_t, radio_t>::update()
template<class network_t, class radio_t>
bool ESBMesh<network_t, radio_t>::write(uint16_t to_node, const void* data, uint8_t msg_type, size_t size)
{
if (mesh_address == MESH_DEFAULT_ADDRESS) return 0;
if (mesh_address == MESH_DEFAULT_ADDRESS)
return 0;

RF24NetworkHeader header(to_node, msg_type);
return network.write(header, data, size);
Expand All @@ -117,7 +119,8 @@ bool ESBMesh<network_t, radio_t>::write(uint16_t to_node, const void* data, uint
template<class network_t, class radio_t>
bool ESBMesh<network_t, radio_t>::write(const void* data, uint8_t msg_type, size_t size, uint8_t nodeID)
{
if (mesh_address == MESH_DEFAULT_ADDRESS) return 0;
if (mesh_address == MESH_DEFAULT_ADDRESS)
return 0;

int16_t toNode = 0;
uint32_t lookupTimeout = millis() + MESH_WRITE_TIMEOUT;
Expand Down Expand Up @@ -174,8 +177,10 @@ int16_t ESBMesh<network_t, radio_t>::getAddress(uint8_t nodeID)
{ // Master will return and send 00 address for a nodeID with address 0, -1 if not found

//if (nodeID == _nodeID) return mesh_address;
if (!nodeID) return 0;
if (mesh_address == MESH_DEFAULT_ADDRESS) return -2;
if (!nodeID)
return 0;
if (mesh_address == MESH_DEFAULT_ADDRESS)
return -2;

// Lets say 0 if nodeID 0, -1 if write failed or timed out, -2 if not found in list or address is default,
#if !defined(MESH_NOMASTER)
Expand Down Expand Up @@ -210,9 +215,12 @@ int16_t ESBMesh<network_t, radio_t>::getAddress(uint8_t nodeID)
template<class network_t, class radio_t>
int16_t ESBMesh<network_t, radio_t>::getNodeID(uint16_t address)
{
if (address == MESH_BLANK_ID) return _nodeID;
if (address == 0) return 0;
if (mesh_address == MESH_DEFAULT_ADDRESS) return -2;
if (address == MESH_BLANK_ID)
return _nodeID;
if (address == 0)
return 0;
if (mesh_address == MESH_DEFAULT_ADDRESS)
return -2;

#if !defined(MESH_NOMASTER)
if (!mesh_address) { //Master Node
Expand All @@ -230,7 +238,8 @@ int16_t ESBMesh<network_t, radio_t>::getNodeID(uint16_t address)
uint32_t timer = millis();
while (network.update() != MESH_ID_LOOKUP) {
MESH_CALLBACK
if (millis() - timer > MESH_LOOKUP_TIMEOUT) return -1;
if (millis() - timer > MESH_LOOKUP_TIMEOUT)
return -1;
}
int16_t ID = 0;
memcpy(&ID, &network.frame_buffer[sizeof(RF24NetworkHeader)], sizeof(ID));
Expand Down Expand Up @@ -267,7 +276,8 @@ void ESBMesh<network_t, radio_t>::beginDefault()
template<class network_t, class radio_t>
bool ESBMesh<network_t, radio_t>::releaseAddress()
{
if (mesh_address == MESH_DEFAULT_ADDRESS) return 0;
if (mesh_address == MESH_DEFAULT_ADDRESS)
return 0;

RF24NetworkHeader header(00, MESH_ADDR_RELEASE);
if (network.write(header, 0, 0)) {
Expand All @@ -282,7 +292,8 @@ bool ESBMesh<network_t, radio_t>::releaseAddress()
template<class network_t, class radio_t>
uint16_t ESBMesh<network_t, radio_t>::renewAddress(uint32_t timeout)
{
if (radio.available()) network.update();
if (radio.available())
network.update();

uint8_t reqCounter = 0;
uint8_t totalReqs = 0;
Expand All @@ -291,7 +302,8 @@ uint16_t ESBMesh<network_t, radio_t>::renewAddress(uint32_t timeout)

uint32_t start = millis();
while (!requestAddress(reqCounter)) {
if (millis() - start > timeout) break;
if (millis() - start > timeout)
break;

uint32_t timeoutInternal = 50 + ((totalReqs + 1) * (reqCounter + 1)) * 2;
uint32_t startInternal = millis();
Expand Down Expand Up @@ -473,7 +485,8 @@ void ESBMesh<network_t, radio_t>::loadDHCP()

#if defined(__linux) && !defined(__ARDUINO_X86__)
std::ifstream infile("dhcplist.txt", std::ifstream::binary);
if (!infile) return;
if (!infile)
return;

infile.seekg(0, infile.end);
int length = infile.tellg();
Expand Down Expand Up @@ -552,7 +565,8 @@ void ESBMesh<network_t, radio_t>::DHCP()
bool found = false;
newAddress = fwd_by | (i << shiftVal);

if (newAddress == MESH_DEFAULT_ADDRESS) continue;
if (newAddress == MESH_DEFAULT_ADDRESS)
continue;

for (uint8_t i = 0; i < addrListTop; i++) {
IF_MESH_DEBUG_MINIMAL(printf_P(PSTR("ID: %d ADDR: 0%o\n"), addrList[i].nodeID, addrList[i].address));
Expand Down
11 changes: 6 additions & 5 deletions RF24Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ESBMesh
public:
/**
* Construct the mesh.
*
*
* v2.0 supports a backward compatible constructor:
* @code
* RF24 radio(7, 8);
Expand All @@ -91,7 +91,7 @@ class ESBMesh
* RF52Network network1(radio1);
* RF52Mesh mesh1(network1, radio1); // for nRF52xxx family
* @endcode
*
*
* @see v2.0 supports [nrf_to_nrf Arduino library](https://github.com/TMRh20/nrf_to_nrf)
* for nrf52 chips' internal radio.
* @param _radio The underlying radio driver instance
Expand Down Expand Up @@ -249,7 +249,8 @@ class ESBMesh
void setCallback(void (*meshCallback)(void));

#define MESH_CALLBACK \
if (meshCallback) meshCallback();
if (meshCallback) \
meshCallback();

/**
* Set or change a @ref _nodeID "nodeID" : node address (key : value) pair manually.
Expand Down Expand Up @@ -371,11 +372,11 @@ class ESBMesh

/**
* A type definition of the template class `ESBMesh` to maintain backward compatibility.
*
*
* ```.cpp
* RF24 radio(7, 8);
* RF24Network network(radio);
*
*
* RF24Mesh mesh(radio, network);
* // is equivalent to
* ESBMesh<ESBNetwork<RF24>, RF24> mesh(radio, network);
Expand Down
47 changes: 25 additions & 22 deletions examples_RPi/ncurses/RF24Mesh_Ncurses_Master.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@

/*
* RF24Mesh Master Node Monitoring Tool
* This is a generic tool for master nodes running RF24Mesh that will display address
* assignments, and information regarding incoming data, regardless of the specific
* configuration details.
*
* Requirements: NCurses
* Install NCurses: apt-get install libncurses5-dev
* Setup:
* 1: make
* 2: sudo ./RF24Mesh_Ncurses_Master
*
* NOTE: DEBUG MUST BE DISABLED IN RF24Mesh_config.h
*
* Once configured and running, the interface will display the header information, data rate,
* and address assignments for all connected nodes.*
* The master node will also continuously ping each of the child nodes, one per second, while indicating
* the results.
*
*/
* RF24Mesh Master Node Monitoring Tool
* This is a generic tool for master nodes running RF24Mesh that will display address
* assignments, and information regarding incoming data, regardless of the specific
* configuration details.
*
* Requirements: NCurses
* Install NCurses: apt-get install libncurses5-dev
* Setup:
* 1: make
* 2: sudo ./RF24Mesh_Ncurses_Master
*
* NOTE: DEBUG MUST BE DISABLED IN RF24Mesh_config.h
*
* Once configured and running, the interface will display the header information, data rate,
* and address assignments for all connected nodes.*
* The master node will also continuously ping each of the child nodes, one per second, while indicating
* the results.
*
*/

#include <ncurses.h>
#include "RF24Mesh/RF24Mesh.h"
Expand Down Expand Up @@ -241,7 +241,8 @@ void drawTopology()
int y = 0;
int x = 0;
getyx(topoPad, y, x);
if (x >= topoPadmaxX) wprintw(topoPad, "\n");
if (x >= topoPadmaxX)
wprintw(topoPad, "\n");
wprintw(topoPad, "0%o[%d] ", mesh.addrList[j].address, mesh.addrList[j].nodeID);
}
}
Expand All @@ -261,7 +262,8 @@ void drawTopology()
int y = 0;
int x = 0;
getyx(topoPad, y, x);
if (x >= topoPadmaxX) wprintw(topoPad, "\n");
if (x >= topoPadmaxX)
wprintw(topoPad, "\n");
wprintw(topoPad, "0%o[%d] ", mesh.addrList[j].address, mesh.addrList[j].nodeID);
}
}
Expand All @@ -281,7 +283,8 @@ void drawTopology()
int y = 0;
int x = 0;
getyx(topoPad, y, x);
if (x >= topoPadmaxX) wprintw(topoPad, "\n");
if (x >= topoPadmaxX)
wprintw(topoPad, "\n");
wprintw(topoPad, "0%o[%d] ", mesh.addrList[j].address, mesh.addrList[j].nodeID);
}
}
Expand Down

0 comments on commit 40f2ff0

Please sign in to comment.