From a08ea9bc7d8a79d8695d4c7123e1592546c6e42e Mon Sep 17 00:00:00 2001 From: Duye Chen Date: Wed, 2 Dec 2015 18:51:05 +0800 Subject: [PATCH 1/6] BBB example --- examples_BBB/Makefile | 44 +++++++++ examples_BBB/README.md | 41 ++++++++ examples_BBB/rf24_bbb.cpp | 196 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 281 insertions(+) create mode 100644 examples_BBB/Makefile create mode 100644 examples_BBB/README.md create mode 100644 examples_BBB/rf24_bbb.cpp diff --git a/examples_BBB/Makefile b/examples_BBB/Makefile new file mode 100644 index 000000000..b8480abf9 --- /dev/null +++ b/examples_BBB/Makefile @@ -0,0 +1,44 @@ +############################################################################# +# +# Makefile for librf24 examples on Raspberry Pi +# +# License: GPL (General Public License) +# Author: gnulnulf +# Date: 2013/02/07 (version 1.0) +# +# Description: +# ------------ +# use make all and make install to install the examples +# You can change the install directory by editing the prefix line +# +prefix := /usr/local + +# Detect the Raspberry Pi by the existence of the bcm_host.h file +BCMLOC=/opt/vc/include/bcm_host.h + +ifneq ("$(wildcard $(BCMLOC))","") +# The recommended compiler flags for the Raspberry Pi +CCFLAGS=-Ofast -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s +endif + +# define all programs +#PROGRAMS = gettingstarted gettingstarted_call_response transfer pingpair_dyn +PROGRAMS = rf24lib +SOURCES = ${PROGRAMS:=.cpp} + +all: ${PROGRAMS} + +${PROGRAMS}: ${SOURCES} + g++ ${CCFLAGS} -Wall -I../ -lrf24-bcm $@.cpp -o $@ + +clean: + rm -rf $(PROGRAMS) + +install: all + test -d $(prefix) || mkdir $(prefix) + test -d $(prefix)/bin || mkdir $(prefix)/bin + for prog in $(PROGRAMS); do \ + install -m 0755 $$prog $(prefix)/bin; \ + done + +.PHONY: install diff --git a/examples_BBB/README.md b/examples_BBB/README.md new file mode 100644 index 000000000..914f1d4c9 --- /dev/null +++ b/examples_BBB/README.md @@ -0,0 +1,41 @@ +rf24_bbb is a program for BBB Node.JS developer. + +### Usage: + + Usage: rf24_bbb [-w target] [[-c channel] -r read_addr] ... + -D show module detail + -h show this help + -w target set target address + -r read addr set read address + -c channel set read channel + -R[timeout] read string + -S string send string + +### Node.JS Example + + var exec = require('child_process').exec; + // rf24_bbb binary file + var _nrflib = __dirname + "/rf24_bbb"; + // set RF24 writing pipe address to 2NODE and reading pipe 1NODE. + var nrf = exec(_nrflib + " " + "-w 2Node -r 1Node -D"); + + // Send string "Hello" per second + setInterval(function(){ + var x = exec(_nrflib + " " + "-S Hello"); + x.stdout.on('data', function (data) + { + console.log(data); + }); + }, 1000); + + nrf.stdout.on('data', function (data) + { + console.log(data); + }); + + nrf.stderr.on('data', function (data) + { + console.log(data); + }); + +See http://tmrh20.github.io/RF24 for more information \ No newline at end of file diff --git a/examples_BBB/rf24_bbb.cpp b/examples_BBB/rf24_bbb.cpp new file mode 100644 index 000000000..5b6812e9f --- /dev/null +++ b/examples_BBB/rf24_bbb.cpp @@ -0,0 +1,196 @@ +/** + * + * RF24 for BBB + * + * This program provide a way to help BBB developer easy to use RF24 library. + * + */ + +#include +#include +#include +#include +#include +#include + +using namespace std; + +/****************** Linux (BBB,x86,etc) ***********************/ + +// See http://tmrh20.github.io/RF24/pages.html for more information on usage +// See http://iotdk.intel.com/docs/master/mraa/ for more information on MRAA +// See https://www.kernel.org/doc/Documentation/spi/spidev for more information on SPIDEV + +// Setup for ARM(Linux) devices like BBB using spidev (default is "/dev/spidev1.0" ) +//RF24 radio(115,0); + +//BBB Alternate, with mraa +// CE pin = (Header P9, Pin 13) = 59 = 13 + 46 +//Note: Specify SPI BUS 0 or 1 instead of CS pin number. +//RF24 radio(59,0); +RF24 radio(51,0); + +/********** User Config *********/ +// Assign a unique identifier for this node, 0 or 1 +bool radioNumber = 1; +const int min_payload_size = 4; +const int max_payload_size = 32; +char receive_payload[max_payload_size+1]; +extern char *optarg; +/********************************/ +int channel = 1; + +void setWritingPipe(char *Addr) +{ + radio.openWritingPipe((uint8_t*) Addr); + cout << "WRITE: " << Addr << endl; + cout.flush(); +} + +void setReadingPipe(char *Addr, int pipe) +{ + radio.openReadingPipe(pipe, (uint8_t*) Addr); + cout << "READ: " << Addr << endl; + cout.flush(); +} + +void sendData(char *data) +{ + int length = strlen(data); + bool timeout = false; + radio.stopListening(); + + bool isSent = radio.write( data, length ); + + if(!isSent) + { + printf("{\"status\":\"failed\"}"); + } + + radio.startListening(); + unsigned long started_time = millis(); + + while (!radio.available() && !timeout) + { + if (millis() - started_time > 200 ) + { + timeout = true; + } + } + + if ( timeout ) + { + printf("{\"status\":\"timeout\"}"); + } else { + printf("{\"status\":\"success\"}"); + } + fflush(stdout); +} + +void readData(char *setTimeout) +{ + // Dump the payloads until we've gotten everything + unsigned int len, waiting_time; + bool timeout = false; + + if ( setTimeout > 0) + waiting_time = atoi(setTimeout); + else + waiting_time = 200; + + radio.startListening(); + unsigned long started_time = millis(); + + + while (!radio.available() && !timeout) + { + if (millis() - started_time > waiting_time ) + { + timeout = true; + } + } + + if( timeout ) + { + printf("{\"status\":\"timeout\"}"); + } + else + { + // Fetch the payload, and see if this was the last one. + len = radio.getDynamicPayloadSize(); + radio.read( receive_payload, len ); + + // Put a zero at the end for easy printing + receive_payload[len] = 0; + + printf("{\"status\":\"received\", \"length\":\"%i\", \"value\":\"%s\"}",len,receive_payload); + fflush(stdout); + + radio.stopListening(); + + radio.write( "R", 1 ); + + // Now, resume listening so we catch the next packets. + radio.startListening(); + } +} + +void showHelp() +{ + cout << "Usage: r24lib [-w target] [[-c channel] -r read_addr] [-options...]" << endl; + cout << "-D\tshow module detail" << endl; + cout << "-h\tshow this help" << endl; + cout << "-w target\tset target address" << endl; + cout << "-r read addr\tset read address" << endl; + cout << "-c channel\tset read channel" << endl; + cout << "-R[timeout]\tread string" << endl; + cout << "-S string\tsend string" << endl; + cout.flush(); +} + + +int main(int argc, char** argv) +{ + + // Setup and configure rf radio + radio.begin(); + radio.enableDynamicPayloads(); + // optionally, increase the delay between retries & # of retries + radio.setRetries(15,15); + + int c; + fprintf(stderr, "argc:%d\n", argc); + while((c = getopt( argc, argv, "Dhw:r:S:c:R::"))!=-1) + { + //fprintf(stdout, "proces index:%d\n", optind); + + switch(c) + { + case 'w': setWritingPipe(optarg); + break; + case 'r': setReadingPipe(optarg, channel); + break; + case 'S': sendData(optarg); + break; + case 'D': radio.printDetails(); + break; + case 'R': readData(optarg); + break; + case 'h': showHelp(); + break; + case 'c': channel = 1; + break; + case '?': fprintf(stdout, "Illegal option:-%c\n", isprint(optopt)?optopt:'#'); + showHelp(); + break; + default: showHelp(); + break; + } + } + + //radio.printDetails(); + fflush(stdout); + radio.startListening(); + + return 0; +} \ No newline at end of file From 167e82202ba6887a682d5e564abc6a133a1db1b9 Mon Sep 17 00:00:00 2001 From: Duye Chen Date: Wed, 2 Dec 2015 18:59:38 +0800 Subject: [PATCH 2/6] Add comment for BBB CE pin --- examples_BBB/rf24_bbb.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/examples_BBB/rf24_bbb.cpp b/examples_BBB/rf24_bbb.cpp index 5b6812e9f..7aac711cb 100644 --- a/examples_BBB/rf24_bbb.cpp +++ b/examples_BBB/rf24_bbb.cpp @@ -28,6 +28,7 @@ using namespace std; // CE pin = (Header P9, Pin 13) = 59 = 13 + 46 //Note: Specify SPI BUS 0 or 1 instead of CS pin number. //RF24 radio(59,0); +// CE pin = P9_16 RF24 radio(51,0); /********** User Config *********/ From 550b7812bbed5f71f6275504df1c4df17bf0d194 Mon Sep 17 00:00:00 2001 From: Duye Chen Date: Fri, 4 Dec 2015 23:18:38 +0800 Subject: [PATCH 3/6] Fixes respond message. Add nodejs example to README file --- examples_BBB/README.md | 30 +++++++++++++++++++++++++++++- examples_BBB/rf24_bbb.cpp | 9 +++------ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/examples_BBB/README.md b/examples_BBB/README.md index 914f1d4c9..e60cd6919 100644 --- a/examples_BBB/README.md +++ b/examples_BBB/README.md @@ -11,7 +11,9 @@ rf24_bbb is a program for BBB Node.JS developer. -R[timeout] read string -S string send string -### Node.JS Example +## Node.JS Example + +### Send var exec = require('child_process').exec; // rf24_bbb binary file @@ -38,4 +40,30 @@ rf24_bbb is a program for BBB Node.JS developer. console.log(data); }); +### Receive + + var exec = require('child_process').exec; + // rf24_bbb binary file + var _nrflib = __dirname + "/rf24_bbb"; + // set RF24 writing pipe address to 1NODE and reading pipe 2NODE. + var nrf = exec(_nrflib + " " + "-w 1Node -r 2Node -D"); + + // Start listening and set timeout 1000 ms (default: 200 ms) + var x = exec(_nrflib + " " + "-R1000"); + x.stdout.on('data', function (data) + { + var d = JSON.parse(data); + console.log(d); + }); + + nrf.stdout.on('data', function (data) + { + console.log(data); + }); + + nrf.stderr.on('data', function (data) + { + console.log(data); + }); + See http://tmrh20.github.io/RF24 for more information \ No newline at end of file diff --git a/examples_BBB/rf24_bbb.cpp b/examples_BBB/rf24_bbb.cpp index 7aac711cb..433380815 100644 --- a/examples_BBB/rf24_bbb.cpp +++ b/examples_BBB/rf24_bbb.cpp @@ -66,6 +66,7 @@ void sendData(char *data) if(!isSent) { printf("{\"status\":\"failed\"}"); + return; } radio.startListening(); @@ -160,11 +161,8 @@ int main(int argc, char** argv) radio.setRetries(15,15); int c; - fprintf(stderr, "argc:%d\n", argc); while((c = getopt( argc, argv, "Dhw:r:S:c:R::"))!=-1) - { - //fprintf(stdout, "proces index:%d\n", optind); - + { switch(c) { case 'w': setWritingPipe(optarg); @@ -181,7 +179,7 @@ int main(int argc, char** argv) break; case 'c': channel = 1; break; - case '?': fprintf(stdout, "Illegal option:-%c\n", isprint(optopt)?optopt:'#'); + case '?': fprintf(stderr, "Illegal option:-%c\n", isprint(optopt)?optopt:'#'); showHelp(); break; default: showHelp(); @@ -189,7 +187,6 @@ int main(int argc, char** argv) } } - //radio.printDetails(); fflush(stdout); radio.startListening(); From 6ff443c5429bd0499c59aaec8145a83f3d191a1e Mon Sep 17 00:00:00 2001 From: Duye Chen Date: Fri, 4 Dec 2015 23:23:38 +0800 Subject: [PATCH 4/6] Fixes Makefile --- examples_BBB/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples_BBB/Makefile b/examples_BBB/Makefile index b8480abf9..20156e558 100644 --- a/examples_BBB/Makefile +++ b/examples_BBB/Makefile @@ -23,7 +23,7 @@ endif # define all programs #PROGRAMS = gettingstarted gettingstarted_call_response transfer pingpair_dyn -PROGRAMS = rf24lib +PROGRAMS = rf24_bbb SOURCES = ${PROGRAMS:=.cpp} all: ${PROGRAMS} From 06bb96bfd565fe072dfb1ea83362ba81b89302d4 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 23 Apr 2014 21:07:00 +0000 Subject: [PATCH 5/6] move examples_BBB to examples_linux/BBB --- examples_linux/BBB/Makefile | 23 ++++ examples_linux/BBB/README.md | 69 ++++++++++++ examples_linux/BBB/rf24_bbb.cpp | 194 ++++++++++++++++++++++++++++++++ 3 files changed, 286 insertions(+) create mode 100644 examples_linux/BBB/Makefile create mode 100644 examples_linux/BBB/README.md create mode 100644 examples_linux/BBB/rf24_bbb.cpp diff --git a/examples_linux/BBB/Makefile b/examples_linux/BBB/Makefile new file mode 100644 index 000000000..cf4d8ff6e --- /dev/null +++ b/examples_linux/BBB/Makefile @@ -0,0 +1,23 @@ +############################################################################# +# +# Makefile for librf24 examples on Linux +# +# License: GPL (General Public License) +# Author: gnulnulf +# Date: 2013/02/07 (version 1.0) +# +# Description: +# ------------ +# use make all and make install to install the examples +# + +ifeq ($(wildcard ../../Makefile.inc), ) + $(error Configuration not found. Run ./configure first) +endif + +include ../../Makefile.inc + +# define all programs +PROGRAMS = rf24_bbb + +include ../Makefile.examples diff --git a/examples_linux/BBB/README.md b/examples_linux/BBB/README.md new file mode 100644 index 000000000..e60cd6919 --- /dev/null +++ b/examples_linux/BBB/README.md @@ -0,0 +1,69 @@ +rf24_bbb is a program for BBB Node.JS developer. + +### Usage: + + Usage: rf24_bbb [-w target] [[-c channel] -r read_addr] ... + -D show module detail + -h show this help + -w target set target address + -r read addr set read address + -c channel set read channel + -R[timeout] read string + -S string send string + +## Node.JS Example + +### Send + + var exec = require('child_process').exec; + // rf24_bbb binary file + var _nrflib = __dirname + "/rf24_bbb"; + // set RF24 writing pipe address to 2NODE and reading pipe 1NODE. + var nrf = exec(_nrflib + " " + "-w 2Node -r 1Node -D"); + + // Send string "Hello" per second + setInterval(function(){ + var x = exec(_nrflib + " " + "-S Hello"); + x.stdout.on('data', function (data) + { + console.log(data); + }); + }, 1000); + + nrf.stdout.on('data', function (data) + { + console.log(data); + }); + + nrf.stderr.on('data', function (data) + { + console.log(data); + }); + +### Receive + + var exec = require('child_process').exec; + // rf24_bbb binary file + var _nrflib = __dirname + "/rf24_bbb"; + // set RF24 writing pipe address to 1NODE and reading pipe 2NODE. + var nrf = exec(_nrflib + " " + "-w 1Node -r 2Node -D"); + + // Start listening and set timeout 1000 ms (default: 200 ms) + var x = exec(_nrflib + " " + "-R1000"); + x.stdout.on('data', function (data) + { + var d = JSON.parse(data); + console.log(d); + }); + + nrf.stdout.on('data', function (data) + { + console.log(data); + }); + + nrf.stderr.on('data', function (data) + { + console.log(data); + }); + +See http://tmrh20.github.io/RF24 for more information \ No newline at end of file diff --git a/examples_linux/BBB/rf24_bbb.cpp b/examples_linux/BBB/rf24_bbb.cpp new file mode 100644 index 000000000..433380815 --- /dev/null +++ b/examples_linux/BBB/rf24_bbb.cpp @@ -0,0 +1,194 @@ +/** + * + * RF24 for BBB + * + * This program provide a way to help BBB developer easy to use RF24 library. + * + */ + +#include +#include +#include +#include +#include +#include + +using namespace std; + +/****************** Linux (BBB,x86,etc) ***********************/ + +// See http://tmrh20.github.io/RF24/pages.html for more information on usage +// See http://iotdk.intel.com/docs/master/mraa/ for more information on MRAA +// See https://www.kernel.org/doc/Documentation/spi/spidev for more information on SPIDEV + +// Setup for ARM(Linux) devices like BBB using spidev (default is "/dev/spidev1.0" ) +//RF24 radio(115,0); + +//BBB Alternate, with mraa +// CE pin = (Header P9, Pin 13) = 59 = 13 + 46 +//Note: Specify SPI BUS 0 or 1 instead of CS pin number. +//RF24 radio(59,0); +// CE pin = P9_16 +RF24 radio(51,0); + +/********** User Config *********/ +// Assign a unique identifier for this node, 0 or 1 +bool radioNumber = 1; +const int min_payload_size = 4; +const int max_payload_size = 32; +char receive_payload[max_payload_size+1]; +extern char *optarg; +/********************************/ +int channel = 1; + +void setWritingPipe(char *Addr) +{ + radio.openWritingPipe((uint8_t*) Addr); + cout << "WRITE: " << Addr << endl; + cout.flush(); +} + +void setReadingPipe(char *Addr, int pipe) +{ + radio.openReadingPipe(pipe, (uint8_t*) Addr); + cout << "READ: " << Addr << endl; + cout.flush(); +} + +void sendData(char *data) +{ + int length = strlen(data); + bool timeout = false; + radio.stopListening(); + + bool isSent = radio.write( data, length ); + + if(!isSent) + { + printf("{\"status\":\"failed\"}"); + return; + } + + radio.startListening(); + unsigned long started_time = millis(); + + while (!radio.available() && !timeout) + { + if (millis() - started_time > 200 ) + { + timeout = true; + } + } + + if ( timeout ) + { + printf("{\"status\":\"timeout\"}"); + } else { + printf("{\"status\":\"success\"}"); + } + fflush(stdout); +} + +void readData(char *setTimeout) +{ + // Dump the payloads until we've gotten everything + unsigned int len, waiting_time; + bool timeout = false; + + if ( setTimeout > 0) + waiting_time = atoi(setTimeout); + else + waiting_time = 200; + + radio.startListening(); + unsigned long started_time = millis(); + + + while (!radio.available() && !timeout) + { + if (millis() - started_time > waiting_time ) + { + timeout = true; + } + } + + if( timeout ) + { + printf("{\"status\":\"timeout\"}"); + } + else + { + // Fetch the payload, and see if this was the last one. + len = radio.getDynamicPayloadSize(); + radio.read( receive_payload, len ); + + // Put a zero at the end for easy printing + receive_payload[len] = 0; + + printf("{\"status\":\"received\", \"length\":\"%i\", \"value\":\"%s\"}",len,receive_payload); + fflush(stdout); + + radio.stopListening(); + + radio.write( "R", 1 ); + + // Now, resume listening so we catch the next packets. + radio.startListening(); + } +} + +void showHelp() +{ + cout << "Usage: r24lib [-w target] [[-c channel] -r read_addr] [-options...]" << endl; + cout << "-D\tshow module detail" << endl; + cout << "-h\tshow this help" << endl; + cout << "-w target\tset target address" << endl; + cout << "-r read addr\tset read address" << endl; + cout << "-c channel\tset read channel" << endl; + cout << "-R[timeout]\tread string" << endl; + cout << "-S string\tsend string" << endl; + cout.flush(); +} + + +int main(int argc, char** argv) +{ + + // Setup and configure rf radio + radio.begin(); + radio.enableDynamicPayloads(); + // optionally, increase the delay between retries & # of retries + radio.setRetries(15,15); + + int c; + while((c = getopt( argc, argv, "Dhw:r:S:c:R::"))!=-1) + { + switch(c) + { + case 'w': setWritingPipe(optarg); + break; + case 'r': setReadingPipe(optarg, channel); + break; + case 'S': sendData(optarg); + break; + case 'D': radio.printDetails(); + break; + case 'R': readData(optarg); + break; + case 'h': showHelp(); + break; + case 'c': channel = 1; + break; + case '?': fprintf(stderr, "Illegal option:-%c\n", isprint(optopt)?optopt:'#'); + showHelp(); + break; + default: showHelp(); + break; + } + } + + fflush(stdout); + radio.startListening(); + + return 0; +} \ No newline at end of file From 36125242d03fd96da54e3bd7643a79ed4a140d31 Mon Sep 17 00:00:00 2001 From: Duye Chen Date: Wed, 23 Apr 2014 21:18:42 +0000 Subject: [PATCH 6/6] delete old examples_BBB folder --- examples_BBB/Makefile | 44 --------- examples_BBB/README.md | 69 -------------- examples_BBB/rf24_bbb.cpp | 194 -------------------------------------- 3 files changed, 307 deletions(-) delete mode 100644 examples_BBB/Makefile delete mode 100644 examples_BBB/README.md delete mode 100644 examples_BBB/rf24_bbb.cpp diff --git a/examples_BBB/Makefile b/examples_BBB/Makefile deleted file mode 100644 index 20156e558..000000000 --- a/examples_BBB/Makefile +++ /dev/null @@ -1,44 +0,0 @@ -############################################################################# -# -# Makefile for librf24 examples on Raspberry Pi -# -# License: GPL (General Public License) -# Author: gnulnulf -# Date: 2013/02/07 (version 1.0) -# -# Description: -# ------------ -# use make all and make install to install the examples -# You can change the install directory by editing the prefix line -# -prefix := /usr/local - -# Detect the Raspberry Pi by the existence of the bcm_host.h file -BCMLOC=/opt/vc/include/bcm_host.h - -ifneq ("$(wildcard $(BCMLOC))","") -# The recommended compiler flags for the Raspberry Pi -CCFLAGS=-Ofast -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -endif - -# define all programs -#PROGRAMS = gettingstarted gettingstarted_call_response transfer pingpair_dyn -PROGRAMS = rf24_bbb -SOURCES = ${PROGRAMS:=.cpp} - -all: ${PROGRAMS} - -${PROGRAMS}: ${SOURCES} - g++ ${CCFLAGS} -Wall -I../ -lrf24-bcm $@.cpp -o $@ - -clean: - rm -rf $(PROGRAMS) - -install: all - test -d $(prefix) || mkdir $(prefix) - test -d $(prefix)/bin || mkdir $(prefix)/bin - for prog in $(PROGRAMS); do \ - install -m 0755 $$prog $(prefix)/bin; \ - done - -.PHONY: install diff --git a/examples_BBB/README.md b/examples_BBB/README.md deleted file mode 100644 index e60cd6919..000000000 --- a/examples_BBB/README.md +++ /dev/null @@ -1,69 +0,0 @@ -rf24_bbb is a program for BBB Node.JS developer. - -### Usage: - - Usage: rf24_bbb [-w target] [[-c channel] -r read_addr] ... - -D show module detail - -h show this help - -w target set target address - -r read addr set read address - -c channel set read channel - -R[timeout] read string - -S string send string - -## Node.JS Example - -### Send - - var exec = require('child_process').exec; - // rf24_bbb binary file - var _nrflib = __dirname + "/rf24_bbb"; - // set RF24 writing pipe address to 2NODE and reading pipe 1NODE. - var nrf = exec(_nrflib + " " + "-w 2Node -r 1Node -D"); - - // Send string "Hello" per second - setInterval(function(){ - var x = exec(_nrflib + " " + "-S Hello"); - x.stdout.on('data', function (data) - { - console.log(data); - }); - }, 1000); - - nrf.stdout.on('data', function (data) - { - console.log(data); - }); - - nrf.stderr.on('data', function (data) - { - console.log(data); - }); - -### Receive - - var exec = require('child_process').exec; - // rf24_bbb binary file - var _nrflib = __dirname + "/rf24_bbb"; - // set RF24 writing pipe address to 1NODE and reading pipe 2NODE. - var nrf = exec(_nrflib + " " + "-w 1Node -r 2Node -D"); - - // Start listening and set timeout 1000 ms (default: 200 ms) - var x = exec(_nrflib + " " + "-R1000"); - x.stdout.on('data', function (data) - { - var d = JSON.parse(data); - console.log(d); - }); - - nrf.stdout.on('data', function (data) - { - console.log(data); - }); - - nrf.stderr.on('data', function (data) - { - console.log(data); - }); - -See http://tmrh20.github.io/RF24 for more information \ No newline at end of file diff --git a/examples_BBB/rf24_bbb.cpp b/examples_BBB/rf24_bbb.cpp deleted file mode 100644 index 433380815..000000000 --- a/examples_BBB/rf24_bbb.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/** - * - * RF24 for BBB - * - * This program provide a way to help BBB developer easy to use RF24 library. - * - */ - -#include -#include -#include -#include -#include -#include - -using namespace std; - -/****************** Linux (BBB,x86,etc) ***********************/ - -// See http://tmrh20.github.io/RF24/pages.html for more information on usage -// See http://iotdk.intel.com/docs/master/mraa/ for more information on MRAA -// See https://www.kernel.org/doc/Documentation/spi/spidev for more information on SPIDEV - -// Setup for ARM(Linux) devices like BBB using spidev (default is "/dev/spidev1.0" ) -//RF24 radio(115,0); - -//BBB Alternate, with mraa -// CE pin = (Header P9, Pin 13) = 59 = 13 + 46 -//Note: Specify SPI BUS 0 or 1 instead of CS pin number. -//RF24 radio(59,0); -// CE pin = P9_16 -RF24 radio(51,0); - -/********** User Config *********/ -// Assign a unique identifier for this node, 0 or 1 -bool radioNumber = 1; -const int min_payload_size = 4; -const int max_payload_size = 32; -char receive_payload[max_payload_size+1]; -extern char *optarg; -/********************************/ -int channel = 1; - -void setWritingPipe(char *Addr) -{ - radio.openWritingPipe((uint8_t*) Addr); - cout << "WRITE: " << Addr << endl; - cout.flush(); -} - -void setReadingPipe(char *Addr, int pipe) -{ - radio.openReadingPipe(pipe, (uint8_t*) Addr); - cout << "READ: " << Addr << endl; - cout.flush(); -} - -void sendData(char *data) -{ - int length = strlen(data); - bool timeout = false; - radio.stopListening(); - - bool isSent = radio.write( data, length ); - - if(!isSent) - { - printf("{\"status\":\"failed\"}"); - return; - } - - radio.startListening(); - unsigned long started_time = millis(); - - while (!radio.available() && !timeout) - { - if (millis() - started_time > 200 ) - { - timeout = true; - } - } - - if ( timeout ) - { - printf("{\"status\":\"timeout\"}"); - } else { - printf("{\"status\":\"success\"}"); - } - fflush(stdout); -} - -void readData(char *setTimeout) -{ - // Dump the payloads until we've gotten everything - unsigned int len, waiting_time; - bool timeout = false; - - if ( setTimeout > 0) - waiting_time = atoi(setTimeout); - else - waiting_time = 200; - - radio.startListening(); - unsigned long started_time = millis(); - - - while (!radio.available() && !timeout) - { - if (millis() - started_time > waiting_time ) - { - timeout = true; - } - } - - if( timeout ) - { - printf("{\"status\":\"timeout\"}"); - } - else - { - // Fetch the payload, and see if this was the last one. - len = radio.getDynamicPayloadSize(); - radio.read( receive_payload, len ); - - // Put a zero at the end for easy printing - receive_payload[len] = 0; - - printf("{\"status\":\"received\", \"length\":\"%i\", \"value\":\"%s\"}",len,receive_payload); - fflush(stdout); - - radio.stopListening(); - - radio.write( "R", 1 ); - - // Now, resume listening so we catch the next packets. - radio.startListening(); - } -} - -void showHelp() -{ - cout << "Usage: r24lib [-w target] [[-c channel] -r read_addr] [-options...]" << endl; - cout << "-D\tshow module detail" << endl; - cout << "-h\tshow this help" << endl; - cout << "-w target\tset target address" << endl; - cout << "-r read addr\tset read address" << endl; - cout << "-c channel\tset read channel" << endl; - cout << "-R[timeout]\tread string" << endl; - cout << "-S string\tsend string" << endl; - cout.flush(); -} - - -int main(int argc, char** argv) -{ - - // Setup and configure rf radio - radio.begin(); - radio.enableDynamicPayloads(); - // optionally, increase the delay between retries & # of retries - radio.setRetries(15,15); - - int c; - while((c = getopt( argc, argv, "Dhw:r:S:c:R::"))!=-1) - { - switch(c) - { - case 'w': setWritingPipe(optarg); - break; - case 'r': setReadingPipe(optarg, channel); - break; - case 'S': sendData(optarg); - break; - case 'D': radio.printDetails(); - break; - case 'R': readData(optarg); - break; - case 'h': showHelp(); - break; - case 'c': channel = 1; - break; - case '?': fprintf(stderr, "Illegal option:-%c\n", isprint(optopt)?optopt:'#'); - showHelp(); - break; - default: showHelp(); - break; - } - } - - fflush(stdout); - radio.startListening(); - - return 0; -} \ No newline at end of file