Skip to content

Commit

Permalink
Added type and time fields to header
Browse files Browse the repository at this point in the history
  • Loading branch information
maniacbug committed Jun 14, 2011
1 parent 59c6296 commit 550bf11
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions RF24Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ uint16_t RF24Network::find_node( uint16_t current_node, uint16_t target_node )

const char* RF24NetworkHeader::toString(void) const
{
static char buffer[28];
snprintf(buffer,sizeof(buffer),"id %04x from %04x to %04x",id,from_node,to_node);
static char buffer[45];
snprintf(buffer,sizeof(buffer),"id %04x from %04x to %04x type %c time %04x",id,from_node,to_node,type,time);
return buffer;
}

Expand Down
7 changes: 5 additions & 2 deletions RF24Network.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ struct RF24NetworkHeader
uint16_t from_node; /**< Logical address where the message was generated */
uint16_t to_node; /**< Logical address where the message is going */
uint16_t id; /**< Sequential message ID, incremented every message */
uint16_t time; /**< Time of the sending machine when sent. */
unsigned char type; /**< Type of the packet. 0-127 are user-defined types, 128-255 are reserved for system */

static uint16_t next_id; /**< The message ID of the next message to be sent */

/**
Expand All @@ -67,13 +70,13 @@ struct RF24NetworkHeader
* Use this constructor to create a header and then send a message
*
* @code
* RF24NetworkHeader header(recipient_address);
* RF24NetworkHeader header(recipient_address,'t');
* network.write(header,&message,sizeof(message));
* @endcode
*
* @param _to The logical node address where the message is going
*/
RF24NetworkHeader(uint16_t _to): to_node(_to), id(next_id++) {}
RF24NetworkHeader(uint16_t _to, unsigned char _type = 0): to_node(_to), id(next_id++), time(millis()&0xffff), type(_type&0x7f) {}

/**
* Create debugging string
Expand Down
2 changes: 1 addition & 1 deletion examples/meshping/meshping.pde
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void loop(void)
printf_P(PSTR("%lu: APP Sending %lu to %u...\n\r"),millis(),now,next_node_to);

message = now;
RF24NetworkHeader header(/*to node*/ next_node_to);
RF24NetworkHeader header(/*to node*/ next_node_to, /*type*/ 'T');
bool ok = network.write(header,&message,sizeof(unsigned long));
if (ok)
{
Expand Down
2 changes: 1 addition & 1 deletion examples/sensornet/sensornet.pde
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void loop(void)
printf_P(PSTR("%lu: APP Sending %lu to %u...\n\r"),millis(),message,1);

// Send it to the base
RF24NetworkHeader header(/*to node*/ 1);
RF24NetworkHeader header(/*to node*/ 1, /*type*/ 'S');
bool ok = network.write(header,&message,sizeof(unsigned long));
if (ok)
printf_P(PSTR("%lu: APP Send ok\n\r"),millis());
Expand Down

0 comments on commit 550bf11

Please sign in to comment.