From 3ec039f9d6be42e0444f0d86339b9d5960ba321b Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Fri, 30 Aug 2013 08:14:44 +0100 Subject: [PATCH 01/11] reduce code size on ATtiny --- RF24Network_config.h | 1 + 1 file changed, 1 insertion(+) diff --git a/RF24Network_config.h b/RF24Network_config.h index 16f5b97..d5dbd9e 100644 --- a/RF24Network_config.h +++ b/RF24Network_config.h @@ -32,6 +32,7 @@ extern HardwareSPI SPI; #define IF_SERIAL_DEBUG(x) ({x;}) #else #define IF_SERIAL_DEBUG(x) +#define printf_P(...) #endif // Avoid spurious warnings From 8bf5ef1b11737b623e0d15f97ae781a3faf851f3 Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Thu, 5 Sep 2013 14:44:58 +0100 Subject: [PATCH 02/11] #ifdefs for attiny --- RF24Network_config.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RF24Network_config.h b/RF24Network_config.h index d5dbd9e..5f37436 100644 --- a/RF24Network_config.h +++ b/RF24Network_config.h @@ -32,8 +32,10 @@ extern HardwareSPI SPI; #define IF_SERIAL_DEBUG(x) ({x;}) #else #define IF_SERIAL_DEBUG(x) +#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny85__) #define printf_P(...) #endif +#endif // Avoid spurious warnings #if ! defined( NATIVE ) && defined( ARDUINO ) From 1c6dddf2f7bb20346ba43902fe1238b2f701308e Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Tue, 19 Nov 2013 12:34:52 +0000 Subject: [PATCH 03/11] updates for raspberry pi --- Makefile | 45 ++++++++++++++++++++++++++++++++++++++++++++ RF24Network.cpp | 2 +- RF24Network_config.h | 5 ++++- Sync.cpp | 4 ++-- 4 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bc58871 --- /dev/null +++ b/Makefile @@ -0,0 +1,45 @@ +############################################################################# +# +# Makefile for librf24-bcm on Raspberry Pi +# +# License: GPL (General Public License) +# Author: Charles-Henri Hallard +# Date: 2013/03/13 +# +# Description: +# ------------ +# use make all and mak install to install the library +# You can change the install directory by editing the LIBDIR line +# +PREFIX=/usr/local + +# Library parameters +# where to put the lib +LIBDIR=$(PREFIX)/lib +# lib name +LIB=librf24-network +# shared library name +LIBNAME=$(LIB).so.1.0 + +CPPFLAGS=-I$(PREFIX)/include -I. + +# The recommended compiler flags for the Raspberry Pi +CCFLAGS=-Ofast -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s + +all: librf24-bcm + +# Make the library +librf24-bcm: RF24Network.o Sync.o + g++ -shared -Wl,-soname,$@.so.1 ${CCFLAGS} -o ${LIBNAME} $^ + +clean: + rm -rf *.o ${LIB}.* + +# Install the library to LIBPATH +install: + if ( test ! -d $(PREFIX)/lib ) ; then mkdir -p $(PREFIX)/lib ; fi + install -m 0755 ${LIBNAME} ${LIBDIR} + ln -sf ${LIBDIR}/${LIBNAME} ${LIBDIR}/${LIB}.so.1 + ln -sf ${LIBDIR}/${LIBNAME} ${LIBDIR}/${LIB}.so + ldconfig + install RF24Network.h RF24Network_config.h $(PREFIX)/include diff --git a/RF24Network.cpp b/RF24Network.cpp index 07d438a..b7588eb 100644 --- a/RF24Network.cpp +++ b/RF24Network.cpp @@ -57,7 +57,7 @@ void RF24Network::update(void) while ( radio.available(&pipe_num) ) { // Dump the payloads until we've gotten everything - boolean done = false; + bool done = false; while (!done) { // Fetch the payload, and see if this was the last one. diff --git a/RF24Network_config.h b/RF24Network_config.h index 5f37436..a1ca1cd 100644 --- a/RF24Network_config.h +++ b/RF24Network_config.h @@ -10,11 +10,13 @@ #ifndef __RF24_CONFIG_H__ #define __RF24_CONFIG_H__ +#ifdef ARDUINO #if ARDUINO < 100 #include #else #include #endif +#endif #include @@ -23,7 +25,6 @@ #include #include #include -extern HardwareSPI SPI; #define _BV(x) (1<<(x)) #endif @@ -54,10 +55,12 @@ typedef char const prog_char; typedef uint16_t prog_uint16_t; #define PSTR(x) (x) #define printf_P printf +#define snprintf_P snprintf #define strlen_P strlen #define PROGMEM #define pgm_read_word(p) (*(p)) #define PRIPSTR "%s" +#define min(a,b) (a // Framework headers // Library headers -#include +#include "RF24Network.h" // Project headers // This component's header -#include +#include "Sync.h" /****************************************************************************/ From c2e385fe4280287b9b6315f010bf11b938c867c7 Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Tue, 19 Nov 2013 13:26:07 +0000 Subject: [PATCH 04/11] more rpi --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index bc58871..ff372a4 100644 --- a/Makefile +++ b/Makefile @@ -24,12 +24,12 @@ LIBNAME=$(LIB).so.1.0 CPPFLAGS=-I$(PREFIX)/include -I. # The recommended compiler flags for the Raspberry Pi -CCFLAGS=-Ofast -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s +CXXFLAGS=-Ofast -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -all: librf24-bcm +all: $(LIB) # Make the library -librf24-bcm: RF24Network.o Sync.o +$(LIB): RF24Network.o Sync.o g++ -shared -Wl,-soname,$@.so.1 ${CCFLAGS} -o ${LIBNAME} $^ clean: From de4d3d9bd9df1680395a06ea691e7ed456083483 Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Tue, 29 Jul 2014 12:01:42 +0100 Subject: [PATCH 05/11] - break out debugging object --- RF24Network.cpp | 47 ++++++++------------------------ RF24Network.h | 26 ++++++++++++------ RF24NetworkSerialDebug.cpp | 56 ++++++++++++++++++++++++++++++++++++++ RF24NetworkSerialDebug.h | 24 ++++++++++++++++ RF24Network_config.h | 25 ++++------------- Sync.cpp | 2 ++ 6 files changed, 118 insertions(+), 62 deletions(-) create mode 100644 RF24NetworkSerialDebug.cpp create mode 100644 RF24NetworkSerialDebug.h diff --git a/RF24Network.cpp b/RF24Network.cpp index 9ea36b4..e890028 100644 --- a/RF24Network.cpp +++ b/RF24Network.cpp @@ -69,8 +69,8 @@ void RF24Network::update(void) // Read the beginning of the frame as the header const RF24NetworkHeader& header = * reinterpret_cast(frame_buffer); - IF_SERIAL_DEBUG(printf_P(PSTR("%lu: MAC Received on %u %s\n\r"),millis(),pipe_num,header.toString())); - IF_SERIAL_DEBUG(const uint16_t* i = reinterpret_cast(frame_buffer + sizeof(RF24NetworkHeader));printf_P(PSTR("%lu: NET message %04x\n\r"),millis(),*i)); + if (dbg) + dbg->on_header(pipe_num, header, frame_buffer); // Throw it away if it's not a valid address if ( !is_valid_address(header.to_node) ) @@ -109,21 +109,15 @@ bool RF24Network::enqueue(void) { bool result = false; - IF_SERIAL_DEBUG(printf_P(PSTR("%lu: NET Enqueue @%x "),millis(),next_frame-frame_queue)); - // Copy the current frame into the frame queue if ( next_frame < frame_queue + sizeof(frame_queue) ) { memcpy(next_frame,frame_buffer, frame_size ); next_frame += frame_size; - result = true; - IF_SERIAL_DEBUG(printf_P(PSTR("ok\n\r"))); - } - else - { - IF_SERIAL_DEBUG(printf_P(PSTR("failed\n\r"))); } + if (dbg) + dbg->on_enqueue(next_frame - frame_queue, result); return result; } @@ -180,7 +174,8 @@ size_t RF24Network::read(RF24NetworkHeader& header,void* message, size_t maxlen) memcpy(message,frame+sizeof(RF24NetworkHeader),bufsize); } - IF_SERIAL_DEBUG(printf_P(PSTR("%lu: NET Received %s\n\r"),millis(),header.toString())); + if (dbg) + dbg->on_receive(header); } return bufsize; @@ -198,12 +193,8 @@ bool RF24Network::write(RF24NetworkHeader& header,const void* message, size_t le if (len) memcpy(frame_buffer + sizeof(RF24NetworkHeader),message,min(frame_size-sizeof(RF24NetworkHeader),len)); - IF_SERIAL_DEBUG(printf_P(PSTR("%lu: NET Sending %s\n\r"),millis(),header.toString())); - if (len) - { - IF_SERIAL_DEBUG(const uint16_t* i = reinterpret_cast(message);printf_P(PSTR("%lu: NET message %04x\n\r"),millis(),*i)); - } - + if (dbg) + dbg->on_send(header, message, len); // If the user is trying to send it to himself if ( header.to_node == node_address ) @@ -250,7 +241,8 @@ bool RF24Network::write(uint16_t to_node) send_pipe = 0; } - IF_SERIAL_DEBUG(printf_P(PSTR("%lu: MAC Sending to 0%o via 0%o on pipe %x\n\r"),millis(),to_node,send_node,send_pipe)); + if (dbg) + dbg->on_write(to_node, send_node, send_pipe); // First, stop listening so we can talk radio.stopListening(); @@ -298,22 +290,11 @@ bool RF24Network::write_to_pipe( uint16_t node, uint8_t pipe ) } while ( !ok && --attempts ); - IF_SERIAL_DEBUG(printf_P(PSTR("%lu: MAC Sent on %lx %S\n\r"),millis(),(uint32_t)out_pipe,ok?PSTR("ok"):PSTR("failed"))); - return ok; } /******************************************************************/ -const char* RF24NetworkHeader::toString(void) const -{ - static char buffer[45]; - snprintf_P(buffer,sizeof(buffer),PSTR("id %04x from 0%o to 0%o type %c"),id,from_node,to_node,type); - return buffer; -} - -/******************************************************************/ - bool RF24Network::is_direct_child( uint16_t node ) { bool result = false; @@ -369,9 +350,8 @@ void RF24Network::setup_address(void) } parent_pipe = i; -#ifdef SERIAL_DEBUG - printf_P(PSTR("setup_address node=0%o mask=0%o parent=0%o pipe=0%o\n\r"),node_address,node_mask,parent_node,parent_pipe); -#endif + if (dbg) + dbg->on_setup_address(node_address, node_mask, parent_node, parent_pipe); } /******************************************************************/ @@ -412,7 +392,6 @@ bool is_valid_address( uint16_t node ) if (digit < 1 || digit > 5) { result = false; - printf_P(PSTR("*** WARNING *** Invalid address 0%o\n\r"),node); break; } node >>= 3; @@ -444,8 +423,6 @@ uint64_t pipe_address( uint16_t node, uint8_t pipe ) shift -= 4; } - IF_SERIAL_DEBUG(uint32_t* top = reinterpret_cast(out+1);printf_P(PSTR("%lu: NET Pipe %i on node 0%o has address %lx%x\n\r"),millis(),pipe,node,*top,*out)); - return result; } diff --git a/RF24Network.h b/RF24Network.h index 0da9781..0f3c469 100644 --- a/RF24Network.h +++ b/RF24Network.h @@ -19,6 +19,7 @@ #include class RF24; +class RF24NetworkDebug; /** * Header which is sent with each message @@ -60,15 +61,20 @@ struct RF24NetworkHeader RF24NetworkHeader(uint16_t _to, unsigned char _type = 0): to_node(_to), id(next_id++), type(_type&0x7f) {} /** - * Create debugging string - * - * Useful for debugging. Dumps all members into a single string, using - * internal static memory. This memory will get overridden next time - * you call the method. - * - * @return String representation of this object + * Prints debugging string */ - const char* toString(void) const; + void toString(void) const; +}; + +class RF24NetworkDebug +{ +public: + virtual void on_header(uint8_t pipe_num, const RF24NetworkHeader &header, uint8_t *frame_buffer) {} + virtual void on_enqueue(size_t frame, bool result) {} + virtual void on_receive(const RF24NetworkHeader& header) {} + virtual void on_send(const RF24NetworkHeader& header, const void *message, size_t len) {} + virtual void on_write(uint16_t to_node, uint16_t send_node, uint8_t send_pipe) {} + virtual void on_setup_address(uint16_t node_address, uint16_t node_mask, uint16_t parent_node, uint16_t parent_pipe) {} }; /** @@ -89,6 +95,8 @@ class RF24Network */ RF24Network( RF24& _radio ); + void setDebug(RF24NetworkDebug *dbg) { this->dbg = dbg; } + /** * Bring up the network * @@ -179,6 +187,8 @@ class RF24Network uint16_t parent_node; /**< Our parent's node address */ uint8_t parent_pipe; /**< The pipe our parent uses to listen to us */ uint16_t node_mask; /**< The bits which contain signfificant node address information */ + + RF24NetworkDebug *dbg; }; /** diff --git a/RF24NetworkSerialDebug.cpp b/RF24NetworkSerialDebug.cpp new file mode 100644 index 0000000..42fea88 --- /dev/null +++ b/RF24NetworkSerialDebug.cpp @@ -0,0 +1,56 @@ +#include "RF24Network_config.h" +#include "RF24Network.h" +#include "RF24NetworkSerialDebug.h" + +#ifdef ENERGIA +extern "C" { + int putchar(int c) { + Serial.print((char)c); + return c; + } +} +#endif + +void RF24NetworkHeader::toString() const +{ + printf_P(PSTR("id %04x from 0%o to 0%o type %c"),id,from_node,to_node,type); +} + +void NetworkSerialDebug::on_header(uint8_t pipe_num, const RF24NetworkHeader &header, uint8_t *frame_buffer) { + printf_P(PSTR("%lu: MAC Received on %u "),millis(),pipe_num); + header.toString(); + const uint16_t* i = reinterpret_cast(frame_buffer + sizeof(RF24NetworkHeader)); + printf_P(PSTR("%lu: NET message %04x\r\n"),millis(), *i); +} + +void NetworkSerialDebug::on_enqueue(size_t frame, bool result) { + printf_P(PSTR("%lu: NET Enqueue @%x "), millis(), frame); + if (result) + printf_P(PSTR("ok\r\n")); + else + printf_P(PSTR("failed\r\n")); +} + +void NetworkSerialDebug::on_receive(const RF24NetworkHeader& header) { + printf_P(PSTR("%lu: NET Received "), millis()); + header.toString(); + printf_P(PSTR("\r\n")); +} + +void NetworkSerialDebug::on_send(const RF24NetworkHeader& header, const void *message, size_t len) { + printf_P(PSTR("%lu: NET Sending "), millis()); + header.toString(); + if (len) { + const uint16_t* i = reinterpret_cast(message); + printf_P(PSTR(" message %04x"), *i); + } + printf_P(PSTR("\r\n")); +} + +void NetworkSerialDebug::on_write(uint16_t to_node, uint16_t send_node, uint8_t send_pipe) { + printf_P(PSTR("%lu: MAC Sending to 0%o via 0%o on %x\r\n"), millis(), to_node, send_node, (uint32_t)send_pipe); +} + +void NetworkSerialDebug::on_setup_address(uint16_t node_address, uint16_t node_mask, uint16_t parent_node, uint16_t parent_pipe) { + printf_P(PSTR("setup_address node=0%o mask=0%o parent=0%o pipe=0%o\r\n"), node_address, node_mask, parent_node, (uint32_t)parent_pipe); +} diff --git a/RF24NetworkSerialDebug.h b/RF24NetworkSerialDebug.h new file mode 100644 index 0000000..0c22030 --- /dev/null +++ b/RF24NetworkSerialDebug.h @@ -0,0 +1,24 @@ +#ifndef __RF24NETWORK_SERIAL_DEBUG_H +#define __RF24NETWORK_SERIAL_DEBUG_H + +class NetworkSerialDebug: public RF24NetworkDebug +{ +public: + void on_header(uint8_t pipe_num, const RF24NetworkHeader &header, uint8_t *frame_buffer); + + void on_enqueue(size_t frame, bool result); + + void on_receive(const RF24NetworkHeader& header); + + virtual void on_send(const RF24NetworkHeader& header, const void *message, size_t len); + + void on_write(uint16_t to_node, uint16_t send_node, uint8_t send_pipe); + + void wrote_pipe(uint8_t out_pipe, bool ok); + + void on_setup_address(uint16_t node_address, uint16_t node_mask, uint16_t parent_node, uint16_t parent_pipe); + + NetworkSerialDebug(RF24Network &network) { network.setDebug(this); } +}; + +#endif diff --git a/RF24Network_config.h b/RF24Network_config.h index a1ca1cd..1863178 100644 --- a/RF24Network_config.h +++ b/RF24Network_config.h @@ -28,34 +28,21 @@ #define _BV(x) (1<<(x)) #endif -#undef SERIAL_DEBUG -#ifdef SERIAL_DEBUG -#define IF_SERIAL_DEBUG(x) ({x;}) -#else -#define IF_SERIAL_DEBUG(x) -#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny85__) -#define printf_P(...) -#endif -#endif - -// Avoid spurious warnings -#if ! defined( NATIVE ) && defined( ARDUINO ) -#undef PROGMEM -#define PROGMEM __attribute__(( section(".progmem.data") )) -#undef PSTR -#define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];})) -#endif +#if defined(ENERGIA) +#define printf_P printf +#define PSTR(x) (x) +#define PRIPSTR "%s" +#elif defined(ARDUINO) // Progmem is Arduino-specific -#ifdef ARDUINO #include #define PRIPSTR "%S" + #else typedef char const prog_char; typedef uint16_t prog_uint16_t; #define PSTR(x) (x) #define printf_P printf -#define snprintf_P snprintf #define strlen_P strlen #define PROGMEM #define pgm_read_word(p) (*(p)) diff --git a/Sync.cpp b/Sync.cpp index 375f0d9..1d023c3 100644 --- a/Sync.cpp +++ b/Sync.cpp @@ -17,6 +17,8 @@ #include "Sync.h" /****************************************************************************/ +// FIXME +#define IF_SERIAL_DEBUG(...) void Sync::update(void) { From b68793a8111c7f442e623ce664202979e55ca384 Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Thu, 31 Jul 2014 09:19:51 +0100 Subject: [PATCH 06/11] - improve debugging - make helloworld examples cross-platform --- RF24Network.cpp | 18 +++++-------- RF24Network.h | 25 +++++++------------ ...orkSerialDebug.cpp => RF24NetworkDebug.cpp | 15 ++++++----- ...NetworkSerialDebug.h => RF24NetworkDebug.h | 13 ++++++---- .../{helloworld_rx.pde => helloworld_rx.ino} | 19 ++++++++++---- .../{helloworld_tx.pde => helloworld_tx.ino} | 15 ++++++++--- 6 files changed, 56 insertions(+), 49 deletions(-) rename RF24NetworkSerialDebug.cpp => RF24NetworkDebug.cpp (66%) rename RF24NetworkSerialDebug.h => RF24NetworkDebug.h (72%) rename examples/helloworld_rx/{helloworld_rx.pde => helloworld_rx.ino} (80%) rename examples/helloworld_tx/{helloworld_tx.pde => helloworld_tx.ino} (86%) diff --git a/RF24Network.cpp b/RF24Network.cpp index e890028..548c188 100644 --- a/RF24Network.cpp +++ b/RF24Network.cpp @@ -69,8 +69,7 @@ void RF24Network::update(void) // Read the beginning of the frame as the header const RF24NetworkHeader& header = * reinterpret_cast(frame_buffer); - if (dbg) - dbg->on_header(pipe_num, header, frame_buffer); + on_header(pipe_num, header, frame_buffer); // Throw it away if it's not a valid address if ( !is_valid_address(header.to_node) ) @@ -116,8 +115,7 @@ bool RF24Network::enqueue(void) next_frame += frame_size; result = true; } - if (dbg) - dbg->on_enqueue(next_frame - frame_queue, result); + on_enqueue(next_frame - frame_queue, result); return result; } @@ -174,8 +172,7 @@ size_t RF24Network::read(RF24NetworkHeader& header,void* message, size_t maxlen) memcpy(message,frame+sizeof(RF24NetworkHeader),bufsize); } - if (dbg) - dbg->on_receive(header); + on_receive(header); } return bufsize; @@ -193,8 +190,7 @@ bool RF24Network::write(RF24NetworkHeader& header,const void* message, size_t le if (len) memcpy(frame_buffer + sizeof(RF24NetworkHeader),message,min(frame_size-sizeof(RF24NetworkHeader),len)); - if (dbg) - dbg->on_send(header, message, len); + on_send(header, message, len); // If the user is trying to send it to himself if ( header.to_node == node_address ) @@ -241,8 +237,7 @@ bool RF24Network::write(uint16_t to_node) send_pipe = 0; } - if (dbg) - dbg->on_write(to_node, send_node, send_pipe); + on_write(to_node, send_node, send_pipe); // First, stop listening so we can talk radio.stopListening(); @@ -350,8 +345,7 @@ void RF24Network::setup_address(void) } parent_pipe = i; - if (dbg) - dbg->on_setup_address(node_address, node_mask, parent_node, parent_pipe); + on_setup_address(node_address, node_mask, parent_node, parent_pipe); } /******************************************************************/ diff --git a/RF24Network.h b/RF24Network.h index 0f3c469..e953a14 100644 --- a/RF24Network.h +++ b/RF24Network.h @@ -19,7 +19,6 @@ #include class RF24; -class RF24NetworkDebug; /** * Header which is sent with each message @@ -66,17 +65,6 @@ struct RF24NetworkHeader void toString(void) const; }; -class RF24NetworkDebug -{ -public: - virtual void on_header(uint8_t pipe_num, const RF24NetworkHeader &header, uint8_t *frame_buffer) {} - virtual void on_enqueue(size_t frame, bool result) {} - virtual void on_receive(const RF24NetworkHeader& header) {} - virtual void on_send(const RF24NetworkHeader& header, const void *message, size_t len) {} - virtual void on_write(uint16_t to_node, uint16_t send_node, uint8_t send_pipe) {} - virtual void on_setup_address(uint16_t node_address, uint16_t node_mask, uint16_t parent_node, uint16_t parent_pipe) {} -}; - /** * Network Layer for RF24 Radios * @@ -86,6 +74,15 @@ class RF24NetworkDebug class RF24Network { +protected: + // debugging: by default does nothing + virtual void on_header(uint8_t pipe_num, const RF24NetworkHeader &header, uint8_t *frame_buffer) {} + virtual void on_enqueue(size_t frame, bool result) {} + virtual void on_receive(const RF24NetworkHeader& header) {} + virtual void on_send(const RF24NetworkHeader& header, const void *message, size_t len) {} + virtual void on_write(uint16_t to_node, uint16_t send_node, uint8_t send_pipe) {} + virtual void on_setup_address(uint16_t node_address, uint16_t node_mask, uint16_t parent_node, uint16_t parent_pipe) {} + public: /** * Construct the network @@ -95,8 +92,6 @@ class RF24Network */ RF24Network( RF24& _radio ); - void setDebug(RF24NetworkDebug *dbg) { this->dbg = dbg; } - /** * Bring up the network * @@ -187,8 +182,6 @@ class RF24Network uint16_t parent_node; /**< Our parent's node address */ uint8_t parent_pipe; /**< The pipe our parent uses to listen to us */ uint16_t node_mask; /**< The bits which contain signfificant node address information */ - - RF24NetworkDebug *dbg; }; /** diff --git a/RF24NetworkSerialDebug.cpp b/RF24NetworkDebug.cpp similarity index 66% rename from RF24NetworkSerialDebug.cpp rename to RF24NetworkDebug.cpp index 42fea88..151e815 100644 --- a/RF24NetworkSerialDebug.cpp +++ b/RF24NetworkDebug.cpp @@ -1,6 +1,5 @@ #include "RF24Network_config.h" -#include "RF24Network.h" -#include "RF24NetworkSerialDebug.h" +#include "RF24NetworkDebug.h" #ifdef ENERGIA extern "C" { @@ -16,14 +15,14 @@ void RF24NetworkHeader::toString() const printf_P(PSTR("id %04x from 0%o to 0%o type %c"),id,from_node,to_node,type); } -void NetworkSerialDebug::on_header(uint8_t pipe_num, const RF24NetworkHeader &header, uint8_t *frame_buffer) { +void RF24NetworkDebug::on_header(uint8_t pipe_num, const RF24NetworkHeader &header, uint8_t *frame_buffer) { printf_P(PSTR("%lu: MAC Received on %u "),millis(),pipe_num); header.toString(); const uint16_t* i = reinterpret_cast(frame_buffer + sizeof(RF24NetworkHeader)); printf_P(PSTR("%lu: NET message %04x\r\n"),millis(), *i); } -void NetworkSerialDebug::on_enqueue(size_t frame, bool result) { +void RF24NetworkDebug::on_enqueue(size_t frame, bool result) { printf_P(PSTR("%lu: NET Enqueue @%x "), millis(), frame); if (result) printf_P(PSTR("ok\r\n")); @@ -31,13 +30,13 @@ void NetworkSerialDebug::on_enqueue(size_t frame, bool result) { printf_P(PSTR("failed\r\n")); } -void NetworkSerialDebug::on_receive(const RF24NetworkHeader& header) { +void RF24NetworkDebug::on_receive(const RF24NetworkHeader& header) { printf_P(PSTR("%lu: NET Received "), millis()); header.toString(); printf_P(PSTR("\r\n")); } -void NetworkSerialDebug::on_send(const RF24NetworkHeader& header, const void *message, size_t len) { +void RF24NetworkDebug::on_send(const RF24NetworkHeader& header, const void *message, size_t len) { printf_P(PSTR("%lu: NET Sending "), millis()); header.toString(); if (len) { @@ -47,10 +46,10 @@ void NetworkSerialDebug::on_send(const RF24NetworkHeader& header, const void *me printf_P(PSTR("\r\n")); } -void NetworkSerialDebug::on_write(uint16_t to_node, uint16_t send_node, uint8_t send_pipe) { +void RF24NetworkDebug::on_write(uint16_t to_node, uint16_t send_node, uint8_t send_pipe) { printf_P(PSTR("%lu: MAC Sending to 0%o via 0%o on %x\r\n"), millis(), to_node, send_node, (uint32_t)send_pipe); } -void NetworkSerialDebug::on_setup_address(uint16_t node_address, uint16_t node_mask, uint16_t parent_node, uint16_t parent_pipe) { +void RF24NetworkDebug::on_setup_address(uint16_t node_address, uint16_t node_mask, uint16_t parent_node, uint16_t parent_pipe) { printf_P(PSTR("setup_address node=0%o mask=0%o parent=0%o pipe=0%o\r\n"), node_address, node_mask, parent_node, (uint32_t)parent_pipe); } diff --git a/RF24NetworkSerialDebug.h b/RF24NetworkDebug.h similarity index 72% rename from RF24NetworkSerialDebug.h rename to RF24NetworkDebug.h index 0c22030..bbd40fd 100644 --- a/RF24NetworkSerialDebug.h +++ b/RF24NetworkDebug.h @@ -1,9 +1,11 @@ -#ifndef __RF24NETWORK_SERIAL_DEBUG_H -#define __RF24NETWORK_SERIAL_DEBUG_H +#ifndef __RF24NETWORK_DEBUG_H +#define __RF24NETWORK_DEBUG_H -class NetworkSerialDebug: public RF24NetworkDebug +#include "RF24Network.h" + +class RF24NetworkDebug: public RF24Network { -public: +protected: void on_header(uint8_t pipe_num, const RF24NetworkHeader &header, uint8_t *frame_buffer); void on_enqueue(size_t frame, bool result); @@ -18,7 +20,8 @@ class NetworkSerialDebug: public RF24NetworkDebug void on_setup_address(uint16_t node_address, uint16_t node_mask, uint16_t parent_node, uint16_t parent_pipe); - NetworkSerialDebug(RF24Network &network) { network.setDebug(this); } +public: + RF24NetworkDebug(class RF24 &radio): RF24Network(radio) {} }; #endif diff --git a/examples/helloworld_rx/helloworld_rx.pde b/examples/helloworld_rx/helloworld_rx.ino similarity index 80% rename from examples/helloworld_rx/helloworld_rx.pde rename to examples/helloworld_rx/helloworld_rx.ino index 8097462..96d430d 100644 --- a/examples/helloworld_rx/helloworld_rx.pde +++ b/examples/helloworld_rx/helloworld_rx.ino @@ -13,15 +13,24 @@ * Listens for messages from the transmitter and prints them out. */ -#include #include #include +#include -// nRF24L01(+) radio attached using Getting Started board -RF24 radio(9,10); +#if defined(ENERGIA) +# define CE P2_1 +# define CS P2_0 +# define BAUD 9600 +#else +# define CE 9 +# define CS 10 +# define BAUD 57600 +#endif + +RF24 radio(CE, CS); // Network uses that radio -RF24Network network(radio); +RF24NetworkDebug network(radio); // Address of our node const uint16_t this_node = 0; @@ -38,7 +47,7 @@ struct payload_t void setup(void) { - Serial.begin(57600); + Serial.begin(BAUD); Serial.println("RF24Network/examples/helloworld_rx/"); SPI.begin(); diff --git a/examples/helloworld_tx/helloworld_tx.pde b/examples/helloworld_tx/helloworld_tx.ino similarity index 86% rename from examples/helloworld_tx/helloworld_tx.pde rename to examples/helloworld_tx/helloworld_tx.ino index 34e1b9a..c01b38e 100644 --- a/examples/helloworld_tx/helloworld_tx.pde +++ b/examples/helloworld_tx/helloworld_tx.ino @@ -17,8 +17,17 @@ #include #include -// nRF24L01(+) radio attached using Getting Started board -RF24 radio(9,10); +#if defined(ENERGIA) +# define CE P2_1 +# define CS P2_0 +# define BAUD 9600 +#else +# define CE 9 +# define CS 10 +# define BAUD 57600 +#endif + +RF24 radio(CE, CS); // Network uses that radio RF24Network network(radio); @@ -47,7 +56,7 @@ struct payload_t void setup(void) { - Serial.begin(57600); + Serial.begin(BAUD); Serial.println("RF24Network/examples/helloworld_tx/"); SPI.begin(); From 24ec87a18c0d7f522531167f1758fe9e77af2ffb Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Thu, 31 Jul 2014 13:44:09 +0100 Subject: [PATCH 07/11] - move RF24NetworkDebug.h into RF24Network.h - replace printf with calls to Print. --- RF24Network.h | 32 ++++++++-- RF24NetworkDebug.cpp | 80 ++++++++++++++++-------- RF24NetworkDebug.h | 27 -------- RF24Network_config.h | 22 ++----- Sync.cpp | 1 + examples/helloworld_rx/helloworld_rx.ino | 2 +- examples/helloworld_tx/helloworld_tx.ino | 6 +- 7 files changed, 90 insertions(+), 80 deletions(-) delete mode 100644 RF24NetworkDebug.h diff --git a/RF24Network.h b/RF24Network.h index e953a14..e2bfead 100644 --- a/RF24Network.h +++ b/RF24Network.h @@ -58,11 +58,6 @@ struct RF24NetworkHeader * user messages. */ RF24NetworkHeader(uint16_t _to, unsigned char _type = 0): to_node(_to), id(next_id++), type(_type&0x7f) {} - - /** - * Prints debugging string - */ - void toString(void) const; }; /** @@ -184,6 +179,33 @@ class RF24Network uint16_t node_mask; /**< The bits which contain signfificant node address information */ }; +class RF24NetworkDebug: public RF24Network +{ +private: + class Print &_out; + + void print_timed(const prog_char *str); + void print_header(const RF24NetworkHeader &h); + +protected: + void on_header(uint8_t pipe_num, const RF24NetworkHeader &header, uint8_t *frame_buffer); + + void on_enqueue(size_t frame, bool result); + + void on_receive(const RF24NetworkHeader& header); + + virtual void on_send(const RF24NetworkHeader& header, const void *message, size_t len); + + void on_write(uint16_t to_node, uint16_t send_node, uint8_t send_pipe); + + void wrote_pipe(uint8_t out_pipe, bool ok); + + void on_setup_address(uint16_t node_address, uint16_t node_mask, uint16_t parent_node, uint16_t parent_pipe); + +public: + RF24NetworkDebug(class RF24 &radio, Print &out = Serial): RF24Network(radio), _out(out) {} +}; + /** * @example helloworld_tx.pde * diff --git a/RF24NetworkDebug.cpp b/RF24NetworkDebug.cpp index 151e815..2a83a93 100644 --- a/RF24NetworkDebug.cpp +++ b/RF24NetworkDebug.cpp @@ -1,55 +1,81 @@ #include "RF24Network_config.h" -#include "RF24NetworkDebug.h" +#include "RF24Network.h" -#ifdef ENERGIA -extern "C" { - int putchar(int c) { - Serial.print((char)c); - return c; - } -} +#if defined(__AVR_ATtinyX4__) || defined(__AVR_ATtinyX5__) +# define FLASH_PTR(x) ((fstr_t *)x) +#else +# define FLASH_PTR(x) ((const __FlashStringHelper *)x) #endif -void RF24NetworkHeader::toString() const +void RF24NetworkDebug::print_timed(const prog_char *str) +{ + _out.print(millis()); + _out.print(F(": ")); + _out.print(FLASH_PTR(str)); +} + +void RF24NetworkDebug::print_header(const RF24NetworkHeader &h) { - printf_P(PSTR("id %04x from 0%o to 0%o type %c"),id,from_node,to_node,type); + _out.print(F("id ")); + _out.print(h.id, HEX); + _out.print(F(" from 0")); + _out.print(h.from_node, OCT); + _out.print(F(" to 0")); + _out.print(h.to_node, OCT); + _out.print(F(" type ")); + _out.print(h.type); } void RF24NetworkDebug::on_header(uint8_t pipe_num, const RF24NetworkHeader &header, uint8_t *frame_buffer) { - printf_P(PSTR("%lu: MAC Received on %u "),millis(),pipe_num); - header.toString(); + print_timed(PSTR("MAC Received on ")); + _out.print(pipe_num, DEC); + _out.print(' '); + print_header(header); + const uint16_t* i = reinterpret_cast(frame_buffer + sizeof(RF24NetworkHeader)); - printf_P(PSTR("%lu: NET message %04x\r\n"),millis(), *i); + print_timed(PSTR("NET message ")); + _out.println(*i, HEX); } void RF24NetworkDebug::on_enqueue(size_t frame, bool result) { - printf_P(PSTR("%lu: NET Enqueue @%x "), millis(), frame); - if (result) - printf_P(PSTR("ok\r\n")); - else - printf_P(PSTR("failed\r\n")); + print_timed(PSTR("NET Enqueue ")); + _out.print(frame, HEX); + _out.println(result? F("ok"): F("failed")); } void RF24NetworkDebug::on_receive(const RF24NetworkHeader& header) { - printf_P(PSTR("%lu: NET Received "), millis()); - header.toString(); - printf_P(PSTR("\r\n")); + print_timed(PSTR("NET Received ")); + print_header(header); + _out.println(); } void RF24NetworkDebug::on_send(const RF24NetworkHeader& header, const void *message, size_t len) { - printf_P(PSTR("%lu: NET Sending "), millis()); - header.toString(); + print_timed(PSTR("NET Sending ")); + print_header(header); if (len) { const uint16_t* i = reinterpret_cast(message); - printf_P(PSTR(" message %04x"), *i); + _out.print(F(" message ")); + _out.print(*i, HEX); } - printf_P(PSTR("\r\n")); + _out.println(); } void RF24NetworkDebug::on_write(uint16_t to_node, uint16_t send_node, uint8_t send_pipe) { - printf_P(PSTR("%lu: MAC Sending to 0%o via 0%o on %x\r\n"), millis(), to_node, send_node, (uint32_t)send_pipe); + print_timed(PSTR("MAC Sending to 0")); + _out.print(to_node, OCT); + _out.print(F(" via 0")); + _out.print(send_node, OCT); + _out.print(F(" on ")); + _out.println(send_pipe, HEX); } void RF24NetworkDebug::on_setup_address(uint16_t node_address, uint16_t node_mask, uint16_t parent_node, uint16_t parent_pipe) { - printf_P(PSTR("setup_address node=0%o mask=0%o parent=0%o pipe=0%o\r\n"), node_address, node_mask, parent_node, (uint32_t)parent_pipe); + _out.print(F("setup_address node=0")); + _out.print(node_address, OCT); + _out.print(F(" mask=0")); + _out.print(node_mask, OCT); + _out.print(F(" parent=0")); + _out.print(parent_node, OCT); + _out.print(F(" pipe=")); + _out.print(parent_pipe, HEX); } diff --git a/RF24NetworkDebug.h b/RF24NetworkDebug.h deleted file mode 100644 index bbd40fd..0000000 --- a/RF24NetworkDebug.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef __RF24NETWORK_DEBUG_H -#define __RF24NETWORK_DEBUG_H - -#include "RF24Network.h" - -class RF24NetworkDebug: public RF24Network -{ -protected: - void on_header(uint8_t pipe_num, const RF24NetworkHeader &header, uint8_t *frame_buffer); - - void on_enqueue(size_t frame, bool result); - - void on_receive(const RF24NetworkHeader& header); - - virtual void on_send(const RF24NetworkHeader& header, const void *message, size_t len); - - void on_write(uint16_t to_node, uint16_t send_node, uint8_t send_pipe); - - void wrote_pipe(uint8_t out_pipe, bool ok); - - void on_setup_address(uint16_t node_address, uint16_t node_mask, uint16_t parent_node, uint16_t parent_pipe); - -public: - RF24NetworkDebug(class RF24 &radio): RF24Network(radio) {} -}; - -#endif diff --git a/RF24Network_config.h b/RF24Network_config.h index 1863178..0353c58 100644 --- a/RF24Network_config.h +++ b/RF24Network_config.h @@ -20,33 +20,21 @@ #include -// Stuff that is normally provided by Arduino -#ifndef ARDUINO -#include -#include -#include -#define _BV(x) (1<<(x)) -#endif - -#if defined(ENERGIA) -#define printf_P printf -#define PSTR(x) (x) -#define PRIPSTR "%s" - -#elif defined(ARDUINO) +#if defined(ARDUINO) // Progmem is Arduino-specific #include -#define PRIPSTR "%S" #else +#include +#include +#include +#define _BV(x) (1<<(x)) typedef char const prog_char; typedef uint16_t prog_uint16_t; #define PSTR(x) (x) -#define printf_P printf #define strlen_P strlen #define PROGMEM #define pgm_read_word(p) (*(p)) -#define PRIPSTR "%s" #define min(a,b) (a // Framework headers // Library headers +#include "RF24Network_config.h" #include "RF24Network.h" // Project headers // This component's header diff --git a/examples/helloworld_rx/helloworld_rx.ino b/examples/helloworld_rx/helloworld_rx.ino index 96d430d..0e34dd2 100644 --- a/examples/helloworld_rx/helloworld_rx.ino +++ b/examples/helloworld_rx/helloworld_rx.ino @@ -15,7 +15,7 @@ #include #include -#include +#include #if defined(ENERGIA) # define CE P2_1 diff --git a/examples/helloworld_tx/helloworld_tx.ino b/examples/helloworld_tx/helloworld_tx.ino index c01b38e..85e08a6 100644 --- a/examples/helloworld_tx/helloworld_tx.ino +++ b/examples/helloworld_tx/helloworld_tx.ino @@ -13,9 +13,9 @@ * Every 2 seconds, send a payload to the receiver node. */ -#include -#include #include +#include +#include #if defined(ENERGIA) # define CE P2_1 @@ -24,7 +24,7 @@ #else # define CE 9 # define CS 10 -# define BAUD 57600 +# define BAUD 115200 #endif RF24 radio(CE, CS); From b3af527aa0578090cbef693e2ad0b84700559416 Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Thu, 31 Jul 2014 13:51:13 +0100 Subject: [PATCH 08/11] fixup for Energia --- RF24Network_config.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/RF24Network_config.h b/RF24Network_config.h index 0353c58..06b3a51 100644 --- a/RF24Network_config.h +++ b/RF24Network_config.h @@ -21,8 +21,15 @@ #include #if defined(ARDUINO) + +#if !defined(ENERGIA) // Progmem is Arduino-specific #include +#else +#define prog_char char +#define PSTR(s) (s) +#define __FlashStringHelper char +#endif #else #include From 661f985ec510c61febfffabccd74f890c785e3cd Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Fri, 1 Aug 2014 11:39:42 +0100 Subject: [PATCH 09/11] update for fraunchpad --- examples/helloworld_tx/helloworld_tx.ino | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/helloworld_tx/helloworld_tx.ino b/examples/helloworld_tx/helloworld_tx.ino index 85e08a6..215d1d2 100644 --- a/examples/helloworld_tx/helloworld_tx.ino +++ b/examples/helloworld_tx/helloworld_tx.ino @@ -18,8 +18,13 @@ #include #if defined(ENERGIA) -# define CE P2_1 -# define CS P2_0 +#if defined(__MSP430FR5739__) +# define CE P1_2 +# define CS P1_3 +#elif defined(__MSP430G2553__) +# define CE P2_1 +# define CS P2_0 +#endif # define BAUD 9600 #else # define CE 9 From 5778e6670eca5d7dc3977c0e15ed2f0418d2289f Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Wed, 25 Mar 2015 10:19:59 +0000 Subject: [PATCH 10/11] update for new avr toolchain --- RF24Network.h | 2 +- RF24NetworkDebug.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/RF24Network.h b/RF24Network.h index e2bfead..2be2aca 100644 --- a/RF24Network.h +++ b/RF24Network.h @@ -184,7 +184,7 @@ class RF24NetworkDebug: public RF24Network private: class Print &_out; - void print_timed(const prog_char *str); + void print_timed(const char *str); void print_header(const RF24NetworkHeader &h); protected: diff --git a/RF24NetworkDebug.cpp b/RF24NetworkDebug.cpp index 2a83a93..126eb10 100644 --- a/RF24NetworkDebug.cpp +++ b/RF24NetworkDebug.cpp @@ -7,7 +7,7 @@ # define FLASH_PTR(x) ((const __FlashStringHelper *)x) #endif -void RF24NetworkDebug::print_timed(const prog_char *str) +void RF24NetworkDebug::print_timed(const char *str) { _out.print(millis()); _out.print(F(": ")); From bcb4c06cd31480cd7c98b64c8c87adc6fbf81f71 Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Sat, 22 Jun 2019 08:20:59 +0100 Subject: [PATCH 11/11] don't set radion parameters --- RF24Network.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/RF24Network.cpp b/RF24Network.cpp index 548c188..7742bf5 100644 --- a/RF24Network.cpp +++ b/RF24Network.cpp @@ -35,8 +35,6 @@ void RF24Network::begin(uint8_t _channel, uint16_t _node_address ) // Set up the radio the way we want it to look radio.setChannel(_channel); - radio.setDataRate(RF24_1MBPS); - radio.setCRCLength(RF24_CRC_16); // Setup our address helper cache setup_address(); @@ -46,9 +44,6 @@ void RF24Network::begin(uint8_t _channel, uint16_t _node_address ) while (i--) radio.openReadingPipe(i,pipe_address(_node_address,i)); radio.startListening(); - - // Spew debugging state about the radio - radio.printDetails(); } /******************************************************************/