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 6e9433e commit b4fb11a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 37 deletions.
42 changes: 28 additions & 14 deletions RF24Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ bool RF24Mesh::begin(uint8_t channel, rf24_datarate_e data_rate, uint32_t timeou
uint8_t RF24Mesh::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 @@ -102,7 +103,8 @@ uint8_t RF24Mesh::update()

bool RF24Mesh::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 @@ -112,7 +114,8 @@ bool RF24Mesh::write(uint16_t to_node, const void* data, uint8_t msg_type, size_

bool RF24Mesh::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 @@ -165,8 +168,10 @@ int16_t RF24Mesh::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 @@ -200,9 +205,12 @@ int16_t RF24Mesh::getAddress(uint8_t nodeID)

int16_t RF24Mesh::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 @@ -220,7 +228,8 @@ int16_t RF24Mesh::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 @@ -254,7 +263,8 @@ void RF24Mesh::beginDefault()

bool RF24Mesh::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 @@ -268,7 +278,8 @@ bool RF24Mesh::releaseAddress()

uint16_t RF24Mesh::renewAddress(uint32_t timeout)
{
if (radio.available()) network.update();
if (radio.available())
network.update();

uint8_t reqCounter = 0;
uint8_t totalReqs = 0;
Expand All @@ -277,7 +288,8 @@ uint16_t RF24Mesh::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 @@ -454,7 +466,8 @@ void RF24Mesh::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 @@ -531,7 +544,8 @@ void RF24Mesh::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
3 changes: 2 additions & 1 deletion RF24Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ class RF24Mesh
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
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 b4fb11a

Please sign in to comment.