RF24Network v1

RF24Network.h

Go to the documentation of this file.
00001 /*
00002  Copyright (C) 2011 James Coliz, Jr. <maniacbug@ymail.com>
00003 
00004  This program is free software; you can redistribute it and/or
00005  modify it under the terms of the GNU General Public License
00006  version 2 as published by the Free Software Foundation.
00007  */
00008 
00009 #ifndef __RF24NETWORK_H__
00010 #define __RF24NETWORK_H__
00011 
00018 #include <stddef.h>
00019 #include <stdint.h>
00020 
00021 class RF24;
00022 
00028 struct RF24NetworkHeader
00029 {
00030   uint16_t from_node; 
00031   uint16_t to_node; 
00032   uint16_t id; 
00033   unsigned char type; 
00034   unsigned char reserved; 
00036   static uint16_t next_id; 
00043   RF24NetworkHeader() {}
00044 
00059   RF24NetworkHeader(uint16_t _to, unsigned char _type = 0): to_node(_to), id(next_id++), type(_type&0x7f) {}
00060 
00070   const char* toString(void) const;
00071 };
00072 
00080 class RF24Network
00081 {
00082 public:
00089   RF24Network( RF24& _radio );
00090 
00099   void begin(uint8_t _channel, uint16_t _node_address );
00100   
00107   void update(void);
00108 
00114   bool available(void);
00115  
00126   void peek(RF24NetworkHeader& header);
00127 
00136   size_t read(RF24NetworkHeader& header, void* message, size_t maxlen);
00137   
00148   bool write(RF24NetworkHeader& header,const void* message, size_t len);
00149 
00150 protected:
00151   void open_pipes(void);
00152   uint16_t find_node( uint16_t current_node, uint16_t target_node );
00153   bool write(uint16_t);
00154   bool write_to_pipe( uint16_t node, uint8_t pipe );
00155   bool enqueue(void);
00156 
00157   bool is_direct_child( uint16_t node );
00158   bool is_descendant( uint16_t node );
00159   uint16_t direct_child_route_to( uint16_t node );
00160   uint8_t pipe_to_descendant( uint16_t node );
00161   void setup_address(void);
00162 
00163 private:
00164   RF24& radio; 
00165   uint16_t node_address; 
00166   uint16_t num_nodes; 
00167   const static short frame_size = 32; 
00168   uint8_t frame_buffer[frame_size]; 
00169   uint8_t frame_queue[5*frame_size]; 
00170   uint8_t* next_frame; 
00172   uint16_t parent_node; 
00173   uint8_t parent_pipe; 
00174   uint16_t node_mask; 
00175 };
00176 
00343 #endif // __RF24NETWORK_H__
00344 // vim:ai:cin:sts=2 sw=2 ft=cpp
 All Classes Files Functions Variables