Skip to content

Commit

Permalink
Add examples, update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
TMRh20 committed Jul 16, 2020
1 parent c1cb484 commit c8cb7fa
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 19 deletions.
12 changes: 6 additions & 6 deletions Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ PROJECT_NUMBER =
# for a project that appears at the top of each page and should give viewer a
# quick idea about the purpose of the project. Keep the description short.

PROJECT_BRIEF = "2014-2015 - Optimized RF24 Network Layer for NRF24L01 radios"
PROJECT_BRIEF = "2020 - Optimized RF24 Network Layer for NRF24L01 radios"

# With the PROJECT_LOGO tag one can specify a logo or an icon that is included
# in the documentation. The maximum height of the logo should not exceed 55
Expand Down Expand Up @@ -177,15 +177,15 @@ SHORT_NAMES = NO
# description.)
# The default value is: NO.

JAVADOC_AUTOBRIEF = YES
JAVADOC_AUTOBRIEF = NO

# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first
# line (until the first dot) of a Qt-style comment as the brief description. If
# set to NO, the Qt-style will behave just like regular Qt-style comments (thus
# requiring an explicit \brief command for a brief description.)
# The default value is: NO.

QT_AUTOBRIEF = YES
QT_AUTOBRIEF = NO

# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a
# multi-line C++ special comment block (i.e. a block of //! or /// comments) as
Expand Down Expand Up @@ -216,7 +216,7 @@ SEPARATE_MEMBER_PAGES = NO
# uses this value to replace tabs by spaces in code fragments.
# Minimum value: 1, maximum value: 16, default value: 4.

TAB_SIZE = 8
TAB_SIZE = 4

# This tag can be used to specify a number of aliases that act as commands in
# the documentation. An alias has the form:
Expand Down Expand Up @@ -281,7 +281,7 @@ OPTIMIZE_OUTPUT_VHDL = NO
# Note that for custom extensions you also need to set FILE_PATTERNS otherwise
# the files are not read by doxygen.

EXTENSION_MAPPING =
EXTENSION_MAPPING = ino=c

# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments
# according to the Markdown format, which allows for more readable
Expand Down Expand Up @@ -1863,7 +1863,7 @@ MAN_LINKS = NO
# captures the structure of the code including all documentation.
# The default value is: NO.

GENERATE_XML = YES
GENERATE_XML = NO

# The XML_OUTPUT tag is used to specify where the XML pages will be put. If a
# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
Expand Down
43 changes: 30 additions & 13 deletions RF24Network.h
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,19 @@ class RF24Network
* Rx a nice message every 2 seconds which rx will print out for us.
*/

/**
* @example helloworld_tx_advanced.ino
*
* A more advanced version of helloworld_tx using fragmentation/reassembly
* and variable payload sizes
*/

/**
* @example helloworld_rx_advanced.ino
* A more advanced version of helloworld_rx using fragmentation/reassembly
* and variable payload sizes
*/

/**
* @example Network_Ping.ino
*
Expand Down Expand Up @@ -910,6 +923,16 @@ class RF24Network
*
*/

/**
* @example Network_Priority_TX.ino
* An example of handling/prioritizing different types of data passing through the RF24Network
*/

/**
* @example Network_Priority_RX.ino
* An example of handling/prioritizing different types of data passing through the RF24Network
*/

/**
* @example sensornet.pde
*
Expand Down Expand Up @@ -938,23 +961,17 @@ class RF24Network
* $6 from many sources. With the RF24Network layer, I hope to cover many
* common communication scenarios.
*
* Please see the @ref Zigbee page for a comparison against the ZigBee protocols
* Please see https://tmrh20.blogspot.com/2019/05/comparative-performance-analysis.html for a comparison against the ZigBee protocols
*
* @section Features Features
*
* <b>Whats new? </b><br>
* @li New: (Dec 8) Merge of RPi and Arduino code. Finally moving closer to a stable release. Report issues at https://github.com/TMRh20/RF24Network/issues
* @li New functionality: (Dec 8) Support for fragmented multicast payloads on both RPi and Arduino
* @li New functionality: (Nov 24) Fragmentation & reassembly supported on both RPi and Arduino
* @li Note: structure of network frames is changed, these are only used by external applications like RF24Ethernet and RF24toTUN, and for fragmentation
* @li New functionality: User message types 1 through 64 will not receive a network ack
*
* The layer provides:
* @li <b>New</b> (2014): Network ACKs: Efficient acknowledgement of network-wide transmissions, via dynamic radio acks and network protocol acks.
* @li <b>New</b> (2014): Updated addressing standard for optimal radio transmission.
* @li <b>New</b> (2014): Extended timeouts and staggered timeout intervals. The new txTimeout variable allows fully automated extended timeout periods via auto-retry/auto-reUse of payloads.
* @li <b>New</b> (2014): Optimization to the core library provides improvements to reliability, speed and efficiency. See https://tmrh20.github.io/RF24 for more info.
* @li <b>New</b> (2014): Built in sleep mode using interrupts. (Still under development. (Enable via RF24Network_config.h))
* @li Network ACKs: Efficient acknowledgement of network-wide transmissions, via dynamic radio acks and network protocol acks.
* @li Updated addressing standard for optimal radio transmission.
* @li Extended timeouts and staggered timeout intervals. The new txTimeout variable allows fully automated extended timeout periods via auto-retry/auto-reUse of payloads.
* @li Optimization to the core library provides improvements to reliability, speed and efficiency. See https://tmrh20.github.io/RF24 for more info.
* @li Built in sleep mode using interrupts. (Still under development. (Enable via RF24Network_config.h))
* @li Host Addressing. Each node has a logical address on the local network.
* @li Message Forwarding. Messages can be sent from one node to any other, and
* this layer will get them there no matter how many hops it takes.
Expand All @@ -963,7 +980,7 @@ class RF24Network
*
* The layer does not provide:
* @li Dynamic address assignment. (See RF24Mesh)
* @li Layer 4 protocols (TCP/IP - See RF24Ethernet and RF24toTUN)
* @li Layer 4 protocols (TCP/IP - See RF24Ethernet and RF24Gateway)
*
* @section More How to learn more
*
Expand Down
125 changes: 125 additions & 0 deletions examples/Network_Priority_RX/Network_Priority_RX.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
Copyright (C) 2020 TMRh20([email protected])
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/

/**
* This sketch demonstrates handling of external data
*
* RF24Network contains a buffer for storing user payloads that have been received via the network.update()
* function. If using protocols like TCP/IP over RF24Network, the memory on small devices is very limited.
* Instead of using the user-payload buffer for such large payloads, they can be designated as an
* EXTERNAL_DATA_TYPE in the header.type field. This allows users to prioritize these payloads, as they are
* often very large, and would take up most or all of the user data buffer.
*
* The network.update function will return immediately upon receiving a payload marked as EXTERNAL_DATA_TYPE
* Users can then process the data immediately.
* All other payload types are handled via the network.available() and network.read() functionality.
*
* Functionality:
* The TX node will send normal user data designated with header.type = 33, along with additional data
* marked as header.type = EXTERNAL_DATA_TYPE.
* The RX node demonstrates how to handle such data, allowing separation of standard data that is processed
* normally vs data that needs to be passed elsewhere, like network interface for TCP/IP packets.
* These methods are used in RF24Gateway & RF24Ethernet TCP/IP libraries for nrf24l01+.
*/

#include <RF24.h>
#include <RF24Network.h>
#include "printf.h"

RF24 radio(7,8); // nRF24L01(+) radio attached using Getting Started board

RF24Network network(radio); // Network uses that radio

const uint16_t this_node = 00; // Address of our node in Octal format
const uint16_t other_node = 01; // Address of the other node in Octal format

uint32_t myVariable = 0;

void setup() {

Serial.begin(115200);
Serial.println("RF24Network/examples/Network_Separation_RX/");
printf_begin(); //Used to enable printf on AVR devices

radio.begin();
network.begin(/*channel*/ 90, /*node address*/ this_node);
radio.printDetails();

}//setup


uint32_t sendTimer = 0;

/**** Create a large array for data to be received ****
* MAX_PAYLOAD_SIZE is defined in RF24Network_config.h
* Payload sizes of ~1-2 KBytes or more are practical when radio conditions are good
*/
#define EXTERNAL_DATA_MAX_SIZE MAX_PAYLOAD_SIZE

uint8_t dataBuffer[EXTERNAL_DATA_MAX_SIZE];

uint32_t userDataTimer = 0;


/*
* The main loop behaviour demonstrates the different prioritization of handling data
* External data is handled immediately upon reception, with the network.update() function being
* called very regularly to handle incoming/outgoing radio traffic.
*
* The network.available() function is only called every 5 seconds, to simulate a busy microcontroller,
* so the user payloads will only print out every 5 seconds
*
* The radio has 3, 32-byte FIFO buffers operating independantly of the MCU, and RF24Network will buffer
* up to MAX_PAYLOAD_SIZE (see RF24Network_config.h) of user data.
*/

void loop() {


// Immediate handling of data with header type EXTERNAL_DATA_TYPE

if(network.update() == EXTERNAL_DATA_TYPE){
uint16_t size = network.frag_ptr->message_size;
memcpy(&dataBuffer,network.frag_ptr->message_buffer,network.frag_ptr->message_size);

// Handle the external data however...
Serial.print("External Data RX, size: ");
Serial.println(network.frag_ptr->message_size);

for(uint16_t i=0; i<network.frag_ptr->message_size; i++){
Serial.print(dataBuffer[i]);
Serial.print(":");
}
Serial.println();
}


// Use a timer to simulate a busy MCU where normal network data cannot be processed in a timely manner
if(millis() - userDataTimer > 5000){
userDataTimer = millis();

// Handling of standard RF24Network User Data
while(network.available()){

RF24NetworkHeader header; // Create an empty header
uint16_t dataSize = network.peek(header); // Peek to get the size of the data
uint32_t someVariable;
if(header.type = '32'){ // If a certain header type is recieved
network.read(header,&someVariable,sizeof(someVariable)); // Handle the data a specific way
Serial.print("RX User Data:\nHeader Type ");
Serial.print(header.type);
Serial.print(" Value ");
Serial.println(someVariable);
}else{
network.read(header,&someVariable,0); // Clear the user data from the buffer if
// some other header type is received
}
}
}

}//loop
96 changes: 96 additions & 0 deletions examples/Network_Priority_TX/Network_Priority_TX.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
Copyright (C) 2020 TMRh20([email protected])
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/

/**
* This sketch demonstrates handling of external data
*
* RF24Network contains a buffer for storing user payloads that have been received via the network.update()
* function. If using protocols like TCP/IP over RF24Network, the memory on small devices is very limited.
* Instead of using the user-payload buffer for such large payloads, they can be designated as an
* EXTERNAL_DATA_TYPE in the header.type field. This allows users to prioritize these payloads, as they are
* often very large, and would take up most or all of the user data buffer.
*
* The network.update function will return immediately upon receiving a payload marked as EXTERNAL_DATA_TYPE
* Users can then process the data immediately.
* All other payload types are handled via the network.available() and network.read() functionality.
*
* Functionality:
* The TX node will send normal user data designated with header.type = 33, along with additional data
* marked as header.type = EXTERNAL_DATA_TYPE.
* The RX node demonstrates how to handle such data, allowing separation of standard data that is processed
* normally vs data that needs to be passed elsewhere, like network interface for TCP/IP packets.
* These methods are used in RF24Gateway & RF24Ethernet TCP/IP libraries for nrf24l01+.
*/

#include <RF24.h>
#include <RF24Network.h>
#include "printf.h"

RF24 radio(7,8); // nRF24L01(+) radio attached using Getting Started board

RF24Network network(radio); // Network uses that radio

const uint16_t this_node = 01; // Address of our node in Octal format
const uint16_t other_node = 00; // Address of the other node in Octal format

uint8_t dataBuffer[33];

void setup() {

Serial.begin(115200);
Serial.println("RF24Network/examples/Network_Separation_TX/");
printf_begin(); //Used to enable printf on AVR devices

radio.begin();
network.begin(/*channel*/ 90, /*node address*/ this_node);
radio.printDetails();

// Load our data buffer with numbered data
for(uint16_t i=0;i<33;i++){
dataBuffer[i] = i;
}

}//setup


uint32_t sendTimer = 0;

/*
* The main loop sends two types of data to be processed with different priority per the RX
* example
*/

void loop() {

network.update();

if(millis() - sendTimer > 1000){
sendTimer = millis();

Serial.println("Sending data...");

// Sending of External data, which will be handled immediately
RF24NetworkHeader header(other_node,EXTERNAL_DATA_TYPE);
bool ok = network.write(header,&dataBuffer,33);
Serial.println(ok ? "OK 1":"Fail 1");

// Sending normal user data, which may be buffered and handled later
RF24NetworkHeader header2(other_node,32);
uint32_t someVariable = 1234;
ok = network.write(header2,&someVariable,sizeof(someVariable));
Serial.println(ok ? "OK 2":"Fail 2");
}

// Dummy operation to read 0 bytes from all incoming user payloads
// Ensures the buffer doesnt fill up
if(network.available()){
RF24NetworkHeader header;
network.read(header,&dataBuffer,0);
}

}//loop

0 comments on commit c8cb7fa

Please sign in to comment.