Skip to content

Commit

Permalink
Add interrupt code
Browse files Browse the repository at this point in the history
Testing support for interrupts #173
  • Loading branch information
TMRh20 committed Dec 18, 2015
1 parent 3f3caf5 commit 50a037d
Show file tree
Hide file tree
Showing 10 changed files with 830 additions and 94 deletions.
58 changes: 40 additions & 18 deletions Doxyfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Doxyfile 1.8.9
# Doxyfile 1.8.10

# This file describes the settings to be used by the documentation system
# doxygen (www.doxygen.org) for a project.
Expand Down Expand Up @@ -58,7 +58,7 @@ PROJECT_LOGO =
# entered, it will be relative to the location where doxygen was started. If
# left blank the current directory will be used.

OUTPUT_DIRECTORY = "../../../ArduinoBuilds/RF24Gateway Docs"
OUTPUT_DIRECTORY = "C:/Users/tmrh20/Documents/ArduinoBuilds/RF24Gateway Docs"

# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub-
# directories (in 2 levels) under the output directory of each output format and
Expand Down Expand Up @@ -354,6 +354,13 @@ IDL_PROPERTY_SUPPORT = YES

DISTRIBUTE_GROUP_DOC = NO

# If one adds a struct or class to a group and this option is enabled, then also
# any nested class or struct is added to the same group. By default this option
# is disabled and one has to add nested compounds explicitly via \ingroup.
# The default value is: NO.

GROUP_NESTED_COMPOUNDS = NO

# Set the SUBGROUPING tag to YES to allow class member groups of the same type
# (for instance a group of public functions) to be put as a subgroup of that
# type (e.g. under the Public Functions section). Set it to NO to prevent
Expand Down Expand Up @@ -766,7 +773,7 @@ WARN_LOGFILE =
# The INPUT tag is used to specify the files and/or directories that contain
# documented source files. You may enter file names like myfile.cpp or
# directories like /usr/src/myproject. Separate the files or directories with
# spaces.
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.

INPUT = ./
Expand All @@ -782,12 +789,17 @@ INPUT_ENCODING = UTF-8

# If the value of the INPUT tag contains directories, you can use the
# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and
# *.h) to filter out the source-files in the directories. If left blank the
# following patterns are tested:*.c, *.cc, *.cxx, *.cpp, *.c++, *.java, *.ii,
# *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, *.hh, *.hxx, *.hpp,
# *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, *.m, *.markdown,
# *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf,
# *.qsf, *.as and *.js.
# *.h) to filter out the source-files in the directories.
#
# Note that for custom extensions or not directly supported extensions you also
# need to set EXTENSION_MAPPING for the extension otherwise the files are not
# read by doxygen.
#
# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp,
# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h,
# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc,
# *.m, *.markdown, *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd,
# *.vhdl, *.ucf, *.qsf, *.as and *.js.

FILE_PATTERNS = *.c \
*.cc \
Expand Down Expand Up @@ -1200,8 +1212,9 @@ HTML_COLORSTYLE_GAMMA = 80

# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML
# page will contain the date and time when the page was generated. Setting this
# to NO can help when comparing the output of multiple runs.
# The default value is: YES.
# to YES can help to show when doxygen was last run and thus if the
# documentation is up to date.
# The default value is: NO.
# This tag requires that the tag GENERATE_HTML is set to YES.

HTML_TIMESTAMP = YES
Expand Down Expand Up @@ -1675,9 +1688,12 @@ COMPACT_LATEX = NO
PAPER_TYPE = a4

# The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names
# that should be included in the LaTeX output. To get the times font for
# instance you can specify
# EXTRA_PACKAGES=times
# that should be included in the LaTeX output. The package can be specified just
# by its name or with the correct syntax as to be used with the LaTeX
# \usepackage command. To get the times font for instance you can specify :
# EXTRA_PACKAGES=times or EXTRA_PACKAGES={times}
# To use the option intlimits with the amsmath package you can specify:
# EXTRA_PACKAGES=[intlimits]{amsmath}
# If left blank no extra packages will be included.
# This tag requires that the tag GENERATE_LATEX is set to YES.

Expand Down Expand Up @@ -2278,7 +2294,8 @@ INCLUDED_BY_GRAPH = YES
#
# Note that enabling this option will significantly increase the time of a run.
# So in most cases it will be better to enable call graphs for selected
# functions only using the \callgraph command.
# functions only using the \callgraph command. Disabling a call graph can be
# accomplished by means of the command \hidecallgraph.
# The default value is: NO.
# This tag requires that the tag HAVE_DOT is set to YES.

Expand All @@ -2289,7 +2306,8 @@ CALL_GRAPH = NO
#
# Note that enabling this option will significantly increase the time of a run.
# So in most cases it will be better to enable caller graphs for selected
# functions only using the \callergraph command.
# functions only using the \callergraph command. Disabling a caller graph can be
# accomplished by means of the command \hidecallergraph.
# The default value is: NO.
# This tag requires that the tag HAVE_DOT is set to YES.

Expand All @@ -2312,11 +2330,15 @@ GRAPHICAL_HIERARCHY = YES
DIRECTORY_GRAPH = YES

# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
# generated by dot.
# generated by dot. For an explanation of the image formats see the section
# output formats in the documentation of the dot tool (Graphviz (see:
# http://www.graphviz.org/)).
# Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order
# to make the SVG files visible in IE 9+ (other browsers do not have this
# requirement).
# Possible values are: png, jpg, gif and svg.
# Possible values are: png, jpg, gif, svg, png:gd, png:gd:gd, png:cairo,
# png:cairo:gd, png:cairo:cairo, png:cairo:gdiplus, png:gdiplus and
# png:gdiplus:gdiplus.
# The default value is: png.
# This tag requires that the tag HAVE_DOT is set to YES.

Expand Down
98 changes: 40 additions & 58 deletions RF24Gateway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,30 +243,40 @@ int RF24Gateway::setIP( char *ip_addr, char *mask) {

/***************************************************************************************/

void RF24Gateway::update(){
handleRadio();
//handleTX();
//handleRX();
void RF24Gateway::update(bool interrupts){

if(interrupts){
handleRadioIn();
}else{
handleRadioIn();
handleRX();
handleRadioOut();
}
}

void RF24Gateway::poll(uint32_t waitDelay){

handleRX(waitDelay);
rfNoInterrupts();
handleRadioOut();
handleRadioIn();
rfInterrupts();

}
/***************************************************************************************/

void RF24Gateway::handleRadio(){



if(mesh_enabled){

while(mesh.update());

if(!thisNodeAddress){
mesh.DHCP();
}
}else{
while(network.update());
}

RF24NetworkFrame f;
void RF24Gateway::handleRadioIn(){

if(mesh_enabled){
while(mesh.update());
if(!thisNodeAddress){
mesh.DHCP();
}
}else{
while(network.update());
}

RF24NetworkFrame f;
while(network.external_queue.size() > 0 ){
f = network.external_queue.front();

Expand Down Expand Up @@ -300,44 +310,15 @@ void RF24Gateway::handleRadio(){
network.external_queue.pop();

}
handleTX();
if(mesh_enabled){

while(mesh.update());

if(!thisNodeAddress){
mesh.DHCP();
}
}else{
while(network.update());
}
handleRX();

if(network.external_queue.size() == 0 || txQueue.empty()){
//sched_yield();
if(dataRate == RF24_2MBPS){
delayMicroseconds(850);
}else
if(dataRate == RF24_1MBPS){
delayMicroseconds(1000);
}else
if(dataRate == RF24_250KBPS){
delayMicroseconds(4500);
}
}
// TX section
handleTX();
}


void RF24Gateway::handleRadioOut(){

bool ok = 0;

while(!txQueue.empty() && !radio.available() && network.external_queue.size() == 0) {
if(dataRate == RF24_2MBPS){
delayMicroseconds(850);
}else
if(dataRate == RF24_1MBPS){
delayMicroseconds(1500);
}else
if(dataRate == RF24_250KBPS){
delayMicroseconds(4500);
}
msgStruct *msgTx = &txQueue.front();

#if (DEBUG >= 1)
Expand Down Expand Up @@ -429,7 +410,7 @@ void RF24Gateway::handleRadio(){

/***************************************************************************************/

void RF24Gateway::handleRX(){
void RF24Gateway::handleRX(uint32_t waitDelay){

fd_set socketSet;
struct timeval selectTimeout;
Expand All @@ -440,7 +421,7 @@ void RF24Gateway::handleRX(){
FD_SET(tunFd, &socketSet);

selectTimeout.tv_sec = 0;
selectTimeout.tv_usec = 0;
selectTimeout.tv_usec = waitDelay*1000;

if (select(tunFd + 1, &socketSet, NULL, NULL,&selectTimeout) != 0) {
if (FD_ISSET(tunFd, &socketSet)) {
Expand All @@ -460,12 +441,13 @@ void RF24Gateway::handleRX(){
msgStruct msg;
memcpy(&msg.message,&buffer,nread);
msg.size = nread;

rfNoInterrupts();
if(txQueue.size() < 2){
txQueue.push(msg);
}else{
droppedIncoming++;
}
rfInterrupts();

} else{
#if (DEBUG >= 1)
Expand Down
27 changes: 24 additions & 3 deletions RF24Gateway.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,16 @@ class RF24Gateway {
* ...do something
* }
* @endcode
* @param interrupts. Set true if called from an interrupt handler & call poll() from the main loop or a thread.
*/
void update();
void update(bool interrupts=0);

/**
* gw.poll(); needs to be called to handle incoming data from the network interface.
* The function will perform a delayed wait of max 3ms unless otherwise specified.
* @param waitDelay How long in milliseconds this function will wait for incoming data.
*/
void poll(uint32_t waitDelay=3);

uint16_t thisNodeAddress; /**< Address of our node in Octal format (01,021, etc) */
uint8_t thisNodeID; /**< NodeID (0-255) */
Expand Down Expand Up @@ -130,8 +138,9 @@ class RF24Gateway {
unsigned long packets_sent; /**< How many have we sent already */
uint32_t interfaceInTimer;

void handleRadio();
void handleRX();
void handleRadioOut();
void handleRadioIn();
void handleRX(uint32_t waitDelay=0);
void handleTX();

int configDevice(uint16_t address);
Expand Down Expand Up @@ -178,6 +187,18 @@ class RF24Gateway {
* @image html ncurses.JPG
*/

/**
* @example gwNodeInt.cpp
*
* A copy of the RF24GatewayNode example using interrupts.
*/

/**
* @example RF24Gateway_ncursesInt.cpp
*
* A copy of the ncurses example using interrupts.
*/

/** @example bClient.sh
*
* Once RF24Gateway and RF24Ethernet are configured, standard tools can be used to interact with
Expand Down
21 changes: 13 additions & 8 deletions examples/RF24GatewayNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@ RF24Network network(radio);
RF24Mesh mesh(radio,network);
RF24Gateway gw(radio,network,mesh);

void intHandler(){

gw.update(true);

}


int main(int argc, char** argv) {

//Config for use with RF24Mesh as Master Node
//uint8_t nodeID=0;
gw.begin();

//Config for use with RF24Mesh as child Node
// uint8_t nodeID = 1;
// uint8_t nodeID = 2;
// gw.begin(nodeID);


Expand All @@ -36,16 +43,14 @@ int main(int argc, char** argv) {

// The gateway handles all IP traffic (marked as EXTERNAL_DATA_TYPE) and passes it to the associated network interface
// RF24Network user payloads are loaded into the user cache
gw.update();

if( network.available() ){
gw.update();
if( network.available() ){
RF24NetworkHeader header;
size_t size = network.peek(header);
uint8_t buf[size];
network.read(header,&buf,size);
printf("Received Network Message, type: %d id %d \n",header.type,header.id);
printf("Received Network Message, type: %d id %d from %d\n",header.type,header.id,mesh.getNodeID(header.from_node));
}
}

}
return 0;
}
}
Loading

3 comments on commit 50a037d

@TMRh20
Copy link
Member Author

@TMRh20 TMRh20 commented on 50a037d Dec 18, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Oitzu
Copy link

@Oitzu Oitzu commented on 50a037d Dec 18, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the ncurses interface. 👍 I need to copy that for my own project. :D

@TMRh20
Copy link
Member Author

@TMRh20 TMRh20 commented on 50a037d Dec 18, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✌️

Please # to comment.