fd

Dependents:   xtoff3 CYS_Receiver

Fork of RF24Network by Akash Vibhute

Committer:
akashvibhute
Date:
Thu Apr 21 03:43:13 2016 +0000
Revision:
4:75c5aa56411f
Parent:
3:dfc8da7ac18c
Child:
5:b1110d26a900
Library re-ported with all the latest and greatest stuff from Manicbug; Synced with TMRh20's RF24 library on Apr/18/2015 from https://github.com/TMRh20

Who changed what in which revision?

UserRevisionLine numberNew contents of line
akashvibhute 0:c3db0798d9aa 1 /*
akashvibhute 0:c3db0798d9aa 2 Copyright (C) 2011 James Coliz, Jr. <maniacbug@ymail.com>
akashvibhute 0:c3db0798d9aa 3
akashvibhute 0:c3db0798d9aa 4 This program is free software; you can redistribute it and/or
akashvibhute 0:c3db0798d9aa 5 modify it under the terms of the GNU General Public License
akashvibhute 0:c3db0798d9aa 6 version 2 as published by the Free Software Foundation.
akashvibhute 0:c3db0798d9aa 7 */
akashvibhute 4:75c5aa56411f 8
akashvibhute 3:dfc8da7ac18c 9 /*
akashvibhute 4:75c5aa56411f 10 * Mbed support added by Akash Vibhute <akash.roboticist@gmail.com>
akashvibhute 4:75c5aa56411f 11 * Porting completed on Nov/05/2015
akashvibhute 4:75c5aa56411f 12 *
akashvibhute 4:75c5aa56411f 13 * Updated 1: Synced with TMRh20's RF24 library on Nov/04/2015 from https://github.com/TMRh20
akashvibhute 4:75c5aa56411f 14 * Updated 2: Synced with TMRh20's RF24 library on Apr/18/2015 from https://github.com/TMRh20
akashvibhute 4:75c5aa56411f 15 *
akashvibhute 4:75c5aa56411f 16 */
akashvibhute 4:75c5aa56411f 17
akashvibhute 0:c3db0798d9aa 18 #ifndef __RF24NETWORK_H__
akashvibhute 0:c3db0798d9aa 19 #define __RF24NETWORK_H__
akashvibhute 0:c3db0798d9aa 20
akashvibhute 0:c3db0798d9aa 21 /**
akashvibhute 0:c3db0798d9aa 22 * @file RF24Network.h
akashvibhute 0:c3db0798d9aa 23 *
akashvibhute 0:c3db0798d9aa 24 * Class declaration for RF24Network
akashvibhute 0:c3db0798d9aa 25 */
akashvibhute 4:75c5aa56411f 26
akashvibhute 4:75c5aa56411f 27 #include "mbed.h"
akashvibhute 0:c3db0798d9aa 28 #include <stddef.h>
akashvibhute 0:c3db0798d9aa 29 #include <stdint.h>
akashvibhute 4:75c5aa56411f 30 //#include <stdio.h>
akashvibhute 4:75c5aa56411f 31 //#include <string.h>
akashvibhute 2:a5f8e04bd02b 32 #include "RF24Network_config.h"
akashvibhute 2:a5f8e04bd02b 33
akashvibhute 4:75c5aa56411f 34
akashvibhute 4:75c5aa56411f 35
akashvibhute 4:75c5aa56411f 36 /**
akashvibhute 4:75c5aa56411f 37
akashvibhute 4:75c5aa56411f 38 */
akashvibhute 4:75c5aa56411f 39
akashvibhute 2:a5f8e04bd02b 40 /* Header types range */
akashvibhute 2:a5f8e04bd02b 41 #define MIN_USER_DEFINED_HEADER_TYPE 0
akashvibhute 2:a5f8e04bd02b 42 #define MAX_USER_DEFINED_HEADER_TYPE 127
akashvibhute 2:a5f8e04bd02b 43
akashvibhute 4:75c5aa56411f 44 /**
akashvibhute 2:a5f8e04bd02b 45
akashvibhute 2:a5f8e04bd02b 46 */
akashvibhute 4:75c5aa56411f 47
akashvibhute 2:a5f8e04bd02b 48 // ACK Response Types
akashvibhute 2:a5f8e04bd02b 49 /**
akashvibhute 2:a5f8e04bd02b 50 * **Reserved network message types**
akashvibhute 2:a5f8e04bd02b 51 *
akashvibhute 2:a5f8e04bd02b 52 * The network will determine whether to automatically acknowledge payloads based on their general type <br>
akashvibhute 4:75c5aa56411f 53 *
akashvibhute 2:a5f8e04bd02b 54 * **User types** (1-127) 1-64 will NOT be acknowledged <br>
akashvibhute 2:a5f8e04bd02b 55 * **System types** (128-255) 192 through 255 will NOT be acknowledged<br>
akashvibhute 2:a5f8e04bd02b 56 *
akashvibhute 2:a5f8e04bd02b 57 * @defgroup DEFINED_TYPES Reserved System Message Types
akashvibhute 2:a5f8e04bd02b 58 *
akashvibhute 2:a5f8e04bd02b 59 * System types can also contain message data.
akashvibhute 2:a5f8e04bd02b 60 *
akashvibhute 2:a5f8e04bd02b 61 * @{
akashvibhute 2:a5f8e04bd02b 62 */
akashvibhute 2:a5f8e04bd02b 63
akashvibhute 2:a5f8e04bd02b 64 /**
akashvibhute 2:a5f8e04bd02b 65 * A NETWORK_ADDR_RESPONSE type is utilized to manually route custom messages containing a single RF24Network address
akashvibhute 4:75c5aa56411f 66 *
akashvibhute 2:a5f8e04bd02b 67 * Used by RF24Mesh
akashvibhute 4:75c5aa56411f 68 *
akashvibhute 2:a5f8e04bd02b 69 * If a node receives a message of this type that is directly addressed to it, it will read the included message, and forward the payload
akashvibhute 2:a5f8e04bd02b 70 * on to the proper recipient. <br>
akashvibhute 2:a5f8e04bd02b 71 * This allows nodes to forward multicast messages to the master node, receive a response, and forward it back to the requester.
akashvibhute 2:a5f8e04bd02b 72 */
akashvibhute 4:75c5aa56411f 73 #define NETWORK_ADDR_RESPONSE 128
akashvibhute 2:a5f8e04bd02b 74 //#define NETWORK_ADDR_CONFIRM 129
akashvibhute 2:a5f8e04bd02b 75
akashvibhute 2:a5f8e04bd02b 76 /**
akashvibhute 4:75c5aa56411f 77 * Messages of type NETWORK_PING will be dropped automatically by the recipient. A NETWORK_ACK or automatic radio-ack will indicate to the sender whether the
akashvibhute 2:a5f8e04bd02b 78 * payload was successful. The time it takes to successfully send a NETWORK_PING is the round-trip-time.
akashvibhute 2:a5f8e04bd02b 79 */
akashvibhute 2:a5f8e04bd02b 80 #define NETWORK_PING 130
akashvibhute 2:a5f8e04bd02b 81
akashvibhute 2:a5f8e04bd02b 82 /**
akashvibhute 4:75c5aa56411f 83 * External data types are used to define messages that will be passed to an external data system. This allows RF24Network to route and pass any type of data, such
akashvibhute 2:a5f8e04bd02b 84 * as TCP/IP frames, while still being able to utilize standard RF24Network messages etc.
akashvibhute 2:a5f8e04bd02b 85 *
akashvibhute 2:a5f8e04bd02b 86 * **Linux**
akashvibhute 4:75c5aa56411f 87 * Linux devices (defined RF24_LINUX) will buffer all data types in the user cache.
akashvibhute 2:a5f8e04bd02b 88 *
akashvibhute 2:a5f8e04bd02b 89 * **Arduino/AVR/Etc:** Data transmitted with the type set to EXTERNAL_DATA_TYPE will not be loaded into the user cache. <br>
akashvibhute 2:a5f8e04bd02b 90 * External systems can extract external data using the following process, while internal data types are cached in the user buffer, and accessed using network.read() :
akashvibhute 2:a5f8e04bd02b 91 * @code
akashvibhute 2:a5f8e04bd02b 92 * uint8_t return_type = network.update();
akashvibhute 2:a5f8e04bd02b 93 * if(return_type == EXTERNAL_DATA_TYPE){
akashvibhute 4:75c5aa56411f 94 * uint16_t size = network.frag_ptr->message_size;
akashvibhute 2:a5f8e04bd02b 95 * memcpy(&myDataBuffer,network.frag_ptr->message_buffer,network.frag_ptr->message_size);
akashvibhute 4:75c5aa56411f 96 * }
akashvibhute 2:a5f8e04bd02b 97 * @endcode
akashvibhute 2:a5f8e04bd02b 98 */
akashvibhute 2:a5f8e04bd02b 99 #define EXTERNAL_DATA_TYPE 131
akashvibhute 2:a5f8e04bd02b 100
akashvibhute 2:a5f8e04bd02b 101 /**
akashvibhute 2:a5f8e04bd02b 102 * Messages of this type designate the first of two or more message fragments, and will be re-assembled automatically.
akashvibhute 2:a5f8e04bd02b 103 */
akashvibhute 2:a5f8e04bd02b 104 #define NETWORK_FIRST_FRAGMENT 148
akashvibhute 2:a5f8e04bd02b 105
akashvibhute 2:a5f8e04bd02b 106 /**
akashvibhute 2:a5f8e04bd02b 107 * Messages of this type indicate a fragmented payload with two or more message fragments.
akashvibhute 2:a5f8e04bd02b 108 */
akashvibhute 2:a5f8e04bd02b 109 #define NETWORK_MORE_FRAGMENTS 149
akashvibhute 2:a5f8e04bd02b 110
akashvibhute 2:a5f8e04bd02b 111 /**
akashvibhute 2:a5f8e04bd02b 112 * Messages of this type indicate the last fragment in a sequence of message fragments.
akashvibhute 2:a5f8e04bd02b 113 * Messages of this type do not receive a NETWORK_ACK
akashvibhute 2:a5f8e04bd02b 114 */
akashvibhute 4:75c5aa56411f 115 #define NETWORK_LAST_FRAGMENT 150
akashvibhute 2:a5f8e04bd02b 116 //#define NETWORK_LAST_FRAGMENT 201
akashvibhute 2:a5f8e04bd02b 117
akashvibhute 2:a5f8e04bd02b 118 // NO ACK Response Types
akashvibhute 2:a5f8e04bd02b 119 //#define NETWORK_ACK_REQUEST 192
akashvibhute 2:a5f8e04bd02b 120
akashvibhute 2:a5f8e04bd02b 121 /**
akashvibhute 2:a5f8e04bd02b 122 * Messages of this type are used internally, to signal the sender that a transmission has been completed.
akashvibhute 2:a5f8e04bd02b 123 * RF24Network does not directly have a built-in transport layer protocol, so message delivery is not 100% guaranteed.<br>
akashvibhute 2:a5f8e04bd02b 124 * Messages can be lost via corrupted dynamic payloads, or a NETWORK_ACK can fail, while the message was actually successful.
akashvibhute 4:75c5aa56411f 125 *
akashvibhute 2:a5f8e04bd02b 126 * NETWORK_ACK messages can be utilized as a traffic/flow control mechanism, since transmitting nodes will be forced to wait until
akashvibhute 4:75c5aa56411f 127 * the payload is transmitted across the network and acknowledged, before sending additional data.
akashvibhute 2:a5f8e04bd02b 128 *
akashvibhute 2:a5f8e04bd02b 129 * In the event that the transmitting device will be waiting for a direct response, manually sent by the recipient, a NETWORK_ACK is not required. <br>
akashvibhute 2:a5f8e04bd02b 130 * User messages utilizing a 'type' with a decimal value of 64 or less will not be acknowledged across the network via NETWORK_ACK messages.
akashvibhute 2:a5f8e04bd02b 131 */
akashvibhute 2:a5f8e04bd02b 132 #define NETWORK_ACK 193
akashvibhute 2:a5f8e04bd02b 133
akashvibhute 2:a5f8e04bd02b 134 /**
akashvibhute 2:a5f8e04bd02b 135 * Used by RF24Mesh
akashvibhute 2:a5f8e04bd02b 136 *
akashvibhute 2:a5f8e04bd02b 137 * Messages of this type are used with multi-casting , to find active/available nodes.
akashvibhute 2:a5f8e04bd02b 138 * Any node receiving a NETWORK_POLL sent to a multicast address will respond directly to the sender with a blank message, indicating the
akashvibhute 2:a5f8e04bd02b 139 * address of the available node via the header.
akashvibhute 4:75c5aa56411f 140 */
akashvibhute 2:a5f8e04bd02b 141 #define NETWORK_POLL 194
akashvibhute 2:a5f8e04bd02b 142
akashvibhute 2:a5f8e04bd02b 143 /**
akashvibhute 2:a5f8e04bd02b 144 * Used by RF24Mesh
akashvibhute 2:a5f8e04bd02b 145 *
akashvibhute 2:a5f8e04bd02b 146 * Messages of this type are used to request information from the master node, generally via a unicast (direct) write.
akashvibhute 2:a5f8e04bd02b 147 * Any (non-master) node receiving a message of this type will manually forward it to the master node using an normal network write.
akashvibhute 2:a5f8e04bd02b 148 */
akashvibhute 2:a5f8e04bd02b 149 #define NETWORK_REQ_ADDRESS 195
akashvibhute 2:a5f8e04bd02b 150 //#define NETWORK_ADDR_LOOKUP 196
akashvibhute 2:a5f8e04bd02b 151 //#define NETWORK_ADDR_RELEASE 197
akashvibhute 2:a5f8e04bd02b 152 /** @} */
akashvibhute 2:a5f8e04bd02b 153
akashvibhute 2:a5f8e04bd02b 154 #define NETWORK_MORE_FRAGMENTS_NACK 200
akashvibhute 2:a5f8e04bd02b 155
akashvibhute 4:75c5aa56411f 156
akashvibhute 2:a5f8e04bd02b 157 /** Internal defines for handling written payloads */
akashvibhute 2:a5f8e04bd02b 158 #define TX_NORMAL 0
akashvibhute 2:a5f8e04bd02b 159 #define TX_ROUTED 1
akashvibhute 2:a5f8e04bd02b 160 #define USER_TX_TO_PHYSICAL_ADDRESS 2 //no network ACK
akashvibhute 2:a5f8e04bd02b 161 #define USER_TX_TO_LOGICAL_ADDRESS 3 // network ACK
akashvibhute 2:a5f8e04bd02b 162 #define USER_TX_MULTICAST 4
akashvibhute 2:a5f8e04bd02b 163
akashvibhute 2:a5f8e04bd02b 164 #define MAX_FRAME_SIZE 32 //Size of individual radio frames
akashvibhute 2:a5f8e04bd02b 165 #define FRAME_HEADER_SIZE 10 //Size of RF24Network frames - data
akashvibhute 2:a5f8e04bd02b 166
akashvibhute 2:a5f8e04bd02b 167 #define USE_CURRENT_CHANNEL 255 // Use current radio channel when setting up the network
akashvibhute 2:a5f8e04bd02b 168
akashvibhute 2:a5f8e04bd02b 169 /** Internal defines for handling internal payloads - prevents reading additional data from the radio
akashvibhute 2:a5f8e04bd02b 170 * when buffers are full */
akashvibhute 4:75c5aa56411f 171 #define FLAG_HOLD_INCOMING 1
akashvibhute 4:75c5aa56411f 172 /** FLAG_BYPASS_HOLDS is mainly for use with RF24Mesh as follows:
akashvibhute 4:75c5aa56411f 173 * a: Ensure no data in radio buffers, else exit
akashvibhute 4:75c5aa56411f 174 * b: Address is changed to multicast address for renewal
akashvibhute 4:75c5aa56411f 175 * c: Holds Cleared (bypass flag is set)
akashvibhute 4:75c5aa56411f 176 * d: Address renewal takes place and is set
akashvibhute 4:75c5aa56411f 177 * e: Holds Enabled (bypass flag off)
akashvibhute 4:75c5aa56411f 178 */
akashvibhute 4:75c5aa56411f 179 #define FLAG_BYPASS_HOLDS 2
akashvibhute 4:75c5aa56411f 180
akashvibhute 4:75c5aa56411f 181 #define FLAG_FAST_FRAG 4
akashvibhute 4:75c5aa56411f 182
akashvibhute 4:75c5aa56411f 183 #define FLAG_NO_POLL 8
akashvibhute 0:c3db0798d9aa 184
akashvibhute 0:c3db0798d9aa 185 class RF24;
akashvibhute 0:c3db0798d9aa 186
akashvibhute 0:c3db0798d9aa 187 /**
akashvibhute 0:c3db0798d9aa 188 * Header which is sent with each message
akashvibhute 0:c3db0798d9aa 189 *
akashvibhute 0:c3db0798d9aa 190 * The frame put over the air consists of this header and a message
akashvibhute 2:a5f8e04bd02b 191 *
akashvibhute 2:a5f8e04bd02b 192 * Headers are addressed to the appropriate node, and the network forwards them on to their final destination.
akashvibhute 0:c3db0798d9aa 193 */
akashvibhute 4:75c5aa56411f 194 struct RF24NetworkHeader
akashvibhute 4:75c5aa56411f 195 {
akashvibhute 4:75c5aa56411f 196 uint16_t from_node; /**< Logical address where the message was generated */
akashvibhute 4:75c5aa56411f 197 uint16_t to_node; /**< Logical address where the message is going */
akashvibhute 4:75c5aa56411f 198 uint16_t id; /**< Sequential message ID, incremented every time a new frame is constructed */
akashvibhute 4:75c5aa56411f 199 /**
akashvibhute 4:75c5aa56411f 200 * Message Types:
akashvibhute 4:75c5aa56411f 201 * User message types 1 through 64 will NOT be acknowledged by the network, while message types 65 through 127 will receive a network ACK.
akashvibhute 4:75c5aa56411f 202 * System message types 192 through 255 will NOT be acknowledged by the network. Message types 128 through 192 will receive a network ACK. <br>
akashvibhute 4:75c5aa56411f 203 * <br><br>
akashvibhute 4:75c5aa56411f 204 */
akashvibhute 4:75c5aa56411f 205 unsigned char type; /**< <b>Type of the packet. </b> 0-127 are user-defined types, 128-255 are reserved for system */
akashvibhute 4:75c5aa56411f 206
akashvibhute 4:75c5aa56411f 207 /**
akashvibhute 4:75c5aa56411f 208 * During fragmentation, it carries the fragment_id, and on the last fragment
akashvibhute 4:75c5aa56411f 209 * it carries the header_type.<br>
akashvibhute 4:75c5aa56411f 210 */
akashvibhute 4:75c5aa56411f 211 unsigned char reserved; /**< *Reserved for system use* */
akashvibhute 0:c3db0798d9aa 212
akashvibhute 4:75c5aa56411f 213 static uint16_t next_id; /**< The message ID of the next message to be sent (unused)*/
akashvibhute 0:c3db0798d9aa 214
akashvibhute 4:75c5aa56411f 215 /**
akashvibhute 4:75c5aa56411f 216 * Default constructor
akashvibhute 4:75c5aa56411f 217 *
akashvibhute 2:a5f8e04bd02b 218
akashvibhute 4:75c5aa56411f 219 * Simply constructs a blank header
akashvibhute 4:75c5aa56411f 220 */
akashvibhute 4:75c5aa56411f 221 RF24NetworkHeader() {}
akashvibhute 0:c3db0798d9aa 222
akashvibhute 4:75c5aa56411f 223 /**
akashvibhute 4:75c5aa56411f 224 * Send constructor
akashvibhute 4:75c5aa56411f 225 *
akashvibhute 4:75c5aa56411f 226 * @note Now supports automatic fragmentation for very long messages, which can be sent as usual if fragmentation is enabled.
akashvibhute 4:75c5aa56411f 227 *
akashvibhute 4:75c5aa56411f 228 * Fragmentation is enabled by default for all devices except ATTiny <br>
akashvibhute 4:75c5aa56411f 229 * Configure fragmentation and max payload size in RF24Network_config.h
akashvibhute 4:75c5aa56411f 230 *
akashvibhute 4:75c5aa56411f 231 * Use this constructor to create a header and then send a message
akashvibhute 4:75c5aa56411f 232 *
akashvibhute 4:75c5aa56411f 233 * @code
akashvibhute 4:75c5aa56411f 234 * uint16_t recipient_address = 011;
akashvibhute 4:75c5aa56411f 235 *
akashvibhute 4:75c5aa56411f 236 * RF24NetworkHeader header(recipient_address,'t');
akashvibhute 4:75c5aa56411f 237 *
akashvibhute 4:75c5aa56411f 238 * network.write(header,&message,sizeof(message));
akashvibhute 4:75c5aa56411f 239 * @endcode
akashvibhute 4:75c5aa56411f 240 *
akashvibhute 4:75c5aa56411f 241 * @param _to The Octal format, logical node address where the message is going
akashvibhute 4:75c5aa56411f 242 * @param _type The type of message which follows. Only 0-127 are allowed for
akashvibhute 4:75c5aa56411f 243 * user messages. Types 1-64 will not receive a network acknowledgement.
akashvibhute 4:75c5aa56411f 244 */
akashvibhute 0:c3db0798d9aa 245
akashvibhute 4:75c5aa56411f 246 RF24NetworkHeader(uint16_t _to, unsigned char _type = 0): to_node(_to), id(next_id++), type(_type) {}
akashvibhute 4:75c5aa56411f 247 /**
akashvibhute 4:75c5aa56411f 248 * Create debugging string
akashvibhute 4:75c5aa56411f 249 *
akashvibhute 4:75c5aa56411f 250 * Useful for debugging. Dumps all members into a single string, using
akashvibhute 4:75c5aa56411f 251 * internal static memory. This memory will get overridden next time
akashvibhute 4:75c5aa56411f 252 * you call the method.
akashvibhute 4:75c5aa56411f 253 *
akashvibhute 4:75c5aa56411f 254 * @return String representation of this object
akashvibhute 4:75c5aa56411f 255 */
akashvibhute 4:75c5aa56411f 256 const char* toString(void) const;
akashvibhute 0:c3db0798d9aa 257 };
akashvibhute 0:c3db0798d9aa 258
akashvibhute 2:a5f8e04bd02b 259
akashvibhute 0:c3db0798d9aa 260 /**
akashvibhute 2:a5f8e04bd02b 261 * Frame structure for internal message handling, and for use by external applications
akashvibhute 2:a5f8e04bd02b 262 *
akashvibhute 2:a5f8e04bd02b 263 * The actual frame put over the air consists of a header (8-bytes) and a message payload (Up to 24-bytes)<br>
akashvibhute 2:a5f8e04bd02b 264 * When data is received, it is stored using the RF24NetworkFrame structure, which includes:
akashvibhute 4:75c5aa56411f 265 * 1. The header
akashvibhute 4:75c5aa56411f 266 * 2. The size of the included message
akashvibhute 2:a5f8e04bd02b 267 * 3. The 'message' or data being received
akashvibhute 4:75c5aa56411f 268 *
akashvibhute 2:a5f8e04bd02b 269 *
akashvibhute 2:a5f8e04bd02b 270 */
akashvibhute 2:a5f8e04bd02b 271
akashvibhute 2:a5f8e04bd02b 272
akashvibhute 4:75c5aa56411f 273 struct RF24NetworkFrame
akashvibhute 4:75c5aa56411f 274 {
akashvibhute 4:75c5aa56411f 275 RF24NetworkHeader header; /**< Header which is sent with each message */
akashvibhute 4:75c5aa56411f 276 uint16_t message_size; /**< The size in bytes of the payload length */
akashvibhute 4:75c5aa56411f 277
akashvibhute 4:75c5aa56411f 278 /**
akashvibhute 4:75c5aa56411f 279 * On Arduino, the message buffer is just a pointer, and can be pointed to any memory location.
akashvibhute 4:75c5aa56411f 280 * On Linux the message buffer is a standard byte array, equal in size to the defined MAX_PAYLOAD_SIZE
akashvibhute 4:75c5aa56411f 281 */
akashvibhute 4:75c5aa56411f 282
akashvibhute 4:75c5aa56411f 283
akashvibhute 4:75c5aa56411f 284
akashvibhute 4:75c5aa56411f 285 uint8_t *message_buffer; //< Pointer to the buffer storing the actual message
akashvibhute 2:a5f8e04bd02b 286
akashvibhute 4:75c5aa56411f 287 /**
akashvibhute 4:75c5aa56411f 288 * Default constructor
akashvibhute 4:75c5aa56411f 289 *
akashvibhute 4:75c5aa56411f 290 * Simply constructs a blank frame. Frames are generally used internally. See RF24NetworkHeader.
akashvibhute 4:75c5aa56411f 291 */
akashvibhute 4:75c5aa56411f 292 //RF24NetworkFrame() {}
akashvibhute 4:75c5aa56411f 293
akashvibhute 4:75c5aa56411f 294 RF24NetworkFrame() {}
akashvibhute 4:75c5aa56411f 295 /**
akashvibhute 4:75c5aa56411f 296 * Constructor - create a network frame with data
akashvibhute 4:75c5aa56411f 297 * Frames are constructed and handled differently on Arduino/AVR and Linux devices (defined RF24_LINUX)
akashvibhute 4:75c5aa56411f 298 *
akashvibhute 4:75c5aa56411f 299 * <br>
akashvibhute 4:75c5aa56411f 300 * **Linux:**
akashvibhute 4:75c5aa56411f 301 * @param _header The RF24Network header to be stored in the frame
akashvibhute 4:75c5aa56411f 302 * @param _message The 'message' or data.
akashvibhute 4:75c5aa56411f 303 * @param _len The size of the 'message' or data.
akashvibhute 4:75c5aa56411f 304 *
akashvibhute 4:75c5aa56411f 305 * <br>
akashvibhute 4:75c5aa56411f 306 * **Arduino/AVR/Etc.**
akashvibhute 4:75c5aa56411f 307 * @see RF24Network.frag_ptr
akashvibhute 4:75c5aa56411f 308 * @param _header The RF24Network header to be stored in the frame
akashvibhute 4:75c5aa56411f 309 * @param _message_size The size of the 'message' or data
akashvibhute 4:75c5aa56411f 310 *
akashvibhute 4:75c5aa56411f 311 *
akashvibhute 4:75c5aa56411f 312 * Frames are used internally and by external systems. See RF24NetworkHeader.
akashvibhute 4:75c5aa56411f 313 */
akashvibhute 4:75c5aa56411f 314
akashvibhute 4:75c5aa56411f 315 RF24NetworkFrame(RF24NetworkHeader &_header, uint16_t _message_size):
akashvibhute 4:75c5aa56411f 316 header(_header), message_size(_message_size){
akashvibhute 4:75c5aa56411f 317 }
akashvibhute 2:a5f8e04bd02b 318
akashvibhute 3:dfc8da7ac18c 319
akashvibhute 2:a5f8e04bd02b 320
akashvibhute 4:75c5aa56411f 321 /**
akashvibhute 4:75c5aa56411f 322 * Create debugging string
akashvibhute 4:75c5aa56411f 323 *
akashvibhute 4:75c5aa56411f 324 * Useful for debugging. Dumps all members into a single string, using
akashvibhute 4:75c5aa56411f 325 * internal static memory. This memory will get overridden next time
akashvibhute 4:75c5aa56411f 326 * you call the method.
akashvibhute 4:75c5aa56411f 327 *
akashvibhute 4:75c5aa56411f 328 * @return String representation of this object
akashvibhute 4:75c5aa56411f 329 */
akashvibhute 4:75c5aa56411f 330 const char* toString(void) const;
akashvibhute 2:a5f8e04bd02b 331
akashvibhute 2:a5f8e04bd02b 332 };
akashvibhute 2:a5f8e04bd02b 333
akashvibhute 4:75c5aa56411f 334
akashvibhute 2:a5f8e04bd02b 335
akashvibhute 2:a5f8e04bd02b 336 /**
akashvibhute 2:a5f8e04bd02b 337 * 2014-2015 - Optimized Network Layer for RF24 Radios
akashvibhute 0:c3db0798d9aa 338 *
akashvibhute 0:c3db0798d9aa 339 * This class implements an OSI Network Layer using nRF24L01(+) radios driven
akashvibhute 0:c3db0798d9aa 340 * by RF24 library.
akashvibhute 0:c3db0798d9aa 341 */
akashvibhute 0:c3db0798d9aa 342
akashvibhute 0:c3db0798d9aa 343 class RF24Network
akashvibhute 0:c3db0798d9aa 344 {
akashvibhute 4:75c5aa56411f 345
akashvibhute 4:75c5aa56411f 346 /**@}*/
akashvibhute 4:75c5aa56411f 347 /**
akashvibhute 4:75c5aa56411f 348 * @name Primary Interface
akashvibhute 4:75c5aa56411f 349 *
akashvibhute 4:75c5aa56411f 350 * These are the main methods you need to operate the network
akashvibhute 4:75c5aa56411f 351 */
akashvibhute 4:75c5aa56411f 352 /**@{*/
akashvibhute 4:75c5aa56411f 353
akashvibhute 0:c3db0798d9aa 354 public:
akashvibhute 4:75c5aa56411f 355 /**
akashvibhute 4:75c5aa56411f 356 * Construct the network
akashvibhute 4:75c5aa56411f 357 *
akashvibhute 4:75c5aa56411f 358 * @param _radio The underlying radio driver instance
akashvibhute 4:75c5aa56411f 359 *
akashvibhute 4:75c5aa56411f 360 */
akashvibhute 2:a5f8e04bd02b 361
akashvibhute 4:75c5aa56411f 362 RF24Network( RF24& _radio );
akashvibhute 0:c3db0798d9aa 363
akashvibhute 4:75c5aa56411f 364 /**
akashvibhute 4:75c5aa56411f 365 * Bring up the network using the current radio frequency/channel.
akashvibhute 4:75c5aa56411f 366 * Calling begin brings up the network, and configures the address, which designates the location of the node within RF24Network topology.
akashvibhute 4:75c5aa56411f 367 * @note Node addresses are specified in Octal format, see <a href=Addressing.html>RF24Network Addressing</a> for more information.
akashvibhute 4:75c5aa56411f 368 * @warning Be sure to 'begin' the radio first.
akashvibhute 4:75c5aa56411f 369 *
akashvibhute 4:75c5aa56411f 370 * **Example 1:** Begin on current radio channel with address 0 (master node)
akashvibhute 4:75c5aa56411f 371 * @code
akashvibhute 4:75c5aa56411f 372 * network.begin(00);
akashvibhute 4:75c5aa56411f 373 * @endcode
akashvibhute 4:75c5aa56411f 374 * **Example 2:** Begin with address 01 (child of master)
akashvibhute 4:75c5aa56411f 375 * @code
akashvibhute 4:75c5aa56411f 376 * network.begin(01);
akashvibhute 4:75c5aa56411f 377 * @endcode
akashvibhute 4:75c5aa56411f 378 * **Example 3:** Begin with address 011 (child of 01, grandchild of master)
akashvibhute 4:75c5aa56411f 379 * @code
akashvibhute 4:75c5aa56411f 380 * network.begin(011);
akashvibhute 4:75c5aa56411f 381 * @endcode
akashvibhute 4:75c5aa56411f 382 *
akashvibhute 4:75c5aa56411f 383 * @see begin(uint8_t _channel, uint16_t _node_address )
akashvibhute 4:75c5aa56411f 384 * @param _node_address The logical address of this node
akashvibhute 4:75c5aa56411f 385 *
akashvibhute 4:75c5aa56411f 386 */
akashvibhute 4:75c5aa56411f 387
akashvibhute 4:75c5aa56411f 388 inline void begin(uint16_t _node_address){
akashvibhute 4:75c5aa56411f 389 begin(USE_CURRENT_CHANNEL,_node_address);
akashvibhute 4:75c5aa56411f 390 }
akashvibhute 2:a5f8e04bd02b 391
akashvibhute 4:75c5aa56411f 392 /**
akashvibhute 4:75c5aa56411f 393 * Main layer loop
akashvibhute 4:75c5aa56411f 394 *
akashvibhute 4:75c5aa56411f 395 * This function must be called regularly to keep the layer going. This is where payloads are
akashvibhute 4:75c5aa56411f 396 * re-routed, received, and all the action happens.
akashvibhute 4:75c5aa56411f 397 *
akashvibhute 4:75c5aa56411f 398 * @see
akashvibhute 4:75c5aa56411f 399 *
akashvibhute 4:75c5aa56411f 400 * @return Returns the type of the last received payload.
akashvibhute 4:75c5aa56411f 401 */
akashvibhute 4:75c5aa56411f 402 uint8_t update(void);
akashvibhute 4:75c5aa56411f 403
akashvibhute 4:75c5aa56411f 404 /**
akashvibhute 4:75c5aa56411f 405 * Test whether there is a message available for this node
akashvibhute 4:75c5aa56411f 406 *
akashvibhute 4:75c5aa56411f 407 * @return Whether there is a message available for this node
akashvibhute 4:75c5aa56411f 408 */
akashvibhute 4:75c5aa56411f 409 bool available(void);
akashvibhute 4:75c5aa56411f 410
akashvibhute 4:75c5aa56411f 411 /**
akashvibhute 4:75c5aa56411f 412 * Read the next available header
akashvibhute 4:75c5aa56411f 413 *
akashvibhute 4:75c5aa56411f 414 * Reads the next available header without advancing to the next
akashvibhute 4:75c5aa56411f 415 * incoming message. Useful for doing a switch on the message type
akashvibhute 4:75c5aa56411f 416 *
akashvibhute 4:75c5aa56411f 417 * If there is no message available, the header is not touched
akashvibhute 4:75c5aa56411f 418 *
akashvibhute 4:75c5aa56411f 419 * @param[out] header The header (envelope) of the next message
akashvibhute 4:75c5aa56411f 420 */
akashvibhute 4:75c5aa56411f 421 uint16_t peek(RF24NetworkHeader& header);
akashvibhute 0:c3db0798d9aa 422
akashvibhute 4:75c5aa56411f 423 /**
akashvibhute 4:75c5aa56411f 424 * Read a message
akashvibhute 4:75c5aa56411f 425 *
akashvibhute 4:75c5aa56411f 426 * @code
akashvibhute 4:75c5aa56411f 427 * while ( network.available() ) {
akashvibhute 4:75c5aa56411f 428 * RF24NetworkHeader header;
akashvibhute 4:75c5aa56411f 429 * uint32_t time;
akashvibhute 4:75c5aa56411f 430 * network.peek(header);
akashvibhute 4:75c5aa56411f 431 * if(header.type == 'T'){
akashvibhute 4:75c5aa56411f 432 * network.read(header,&time,sizeof(time));
akashvibhute 4:75c5aa56411f 433 * Serial.print("Got time: ");
akashvibhute 4:75c5aa56411f 434 * Serial.println(time);
akashvibhute 4:75c5aa56411f 435 * }
akashvibhute 4:75c5aa56411f 436 * }
akashvibhute 4:75c5aa56411f 437 * @endcode
akashvibhute 4:75c5aa56411f 438 * @param[out] header The header (envelope) of this message
akashvibhute 4:75c5aa56411f 439 * @param[out] message Pointer to memory where the message should be placed
akashvibhute 4:75c5aa56411f 440 * @param maxlen The largest message size which can be held in @p message
akashvibhute 4:75c5aa56411f 441 * @return The total number of bytes copied into @p message
akashvibhute 4:75c5aa56411f 442 */
akashvibhute 4:75c5aa56411f 443 uint16_t read(RF24NetworkHeader& header, void* message, uint16_t maxlen);
akashvibhute 3:dfc8da7ac18c 444
akashvibhute 4:75c5aa56411f 445 /**
akashvibhute 4:75c5aa56411f 446 * Send a message
akashvibhute 4:75c5aa56411f 447 *
akashvibhute 4:75c5aa56411f 448 * @note RF24Network now supports fragmentation for very long messages, send as normal. Fragmentation
akashvibhute 4:75c5aa56411f 449 * may need to be enabled or configured by editing the RF24Network_config.h file. Default max payload size is 120 bytes.
akashvibhute 4:75c5aa56411f 450 *
akashvibhute 4:75c5aa56411f 451 * @code
akashvibhute 4:75c5aa56411f 452 * uint32_t time = millis();
akashvibhute 4:75c5aa56411f 453 * uint16_t to = 00; // Send to master
akashvibhute 4:75c5aa56411f 454 * RF24NetworkHeader header(to, 'T'); // Send header type 'T'
akashvibhute 4:75c5aa56411f 455 * network.write(header,&time,sizeof(time));
akashvibhute 4:75c5aa56411f 456 * @endcode
akashvibhute 4:75c5aa56411f 457 * @param[in,out] header The header (envelope) of this message. The critical
akashvibhute 4:75c5aa56411f 458 * thing to fill in is the @p to_node field so we know where to send the
akashvibhute 4:75c5aa56411f 459 * message. It is then updated with the details of the actual header sent.
akashvibhute 4:75c5aa56411f 460 * @param message Pointer to memory where the message is located
akashvibhute 4:75c5aa56411f 461 * @param len The size of the message
akashvibhute 4:75c5aa56411f 462 * @return Whether the message was successfully received
akashvibhute 4:75c5aa56411f 463 */
akashvibhute 4:75c5aa56411f 464 bool write(RF24NetworkHeader& header,const void* message, uint16_t len);
akashvibhute 2:a5f8e04bd02b 465
akashvibhute 4:75c5aa56411f 466 /**@}*/
akashvibhute 4:75c5aa56411f 467 /**
akashvibhute 4:75c5aa56411f 468 * @name Advanced Configuration
akashvibhute 4:75c5aa56411f 469 *
akashvibhute 4:75c5aa56411f 470 * For advanced configuration of the network
akashvibhute 4:75c5aa56411f 471 */
akashvibhute 4:75c5aa56411f 472 /**@{*/
akashvibhute 4:75c5aa56411f 473
akashvibhute 0:c3db0798d9aa 474
akashvibhute 4:75c5aa56411f 475 /**
akashvibhute 4:75c5aa56411f 476 * Construct the network in dual head mode using two radio modules.
akashvibhute 4:75c5aa56411f 477 * @note Not working on RPi. Radios will share MISO, MOSI and SCK pins, but require separate CE,CS pins.
akashvibhute 4:75c5aa56411f 478 * @code
akashvibhute 4:75c5aa56411f 479 * RF24 radio(7,8);
akashvibhute 4:75c5aa56411f 480 * RF24 radio1(4,5);
akashvibhute 4:75c5aa56411f 481 * RF24Network(radio.radio1);
akashvibhute 4:75c5aa56411f 482 * @endcode
akashvibhute 4:75c5aa56411f 483 * @param _radio The underlying radio driver instance
akashvibhute 4:75c5aa56411f 484 * @param _radio1 The second underlying radio driver instance
akashvibhute 4:75c5aa56411f 485 */
akashvibhute 4:75c5aa56411f 486
akashvibhute 4:75c5aa56411f 487 RF24Network( RF24& _radio, RF24& _radio1);
akashvibhute 4:75c5aa56411f 488
akashvibhute 4:75c5aa56411f 489 /**
akashvibhute 4:75c5aa56411f 490 * By default, multicast addresses are divided into levels.
akashvibhute 4:75c5aa56411f 491 *
akashvibhute 4:75c5aa56411f 492 * Nodes 1-5 share a multicast address, nodes n1-n5 share a multicast address, and nodes n11-n55 share a multicast address.<br>
akashvibhute 4:75c5aa56411f 493 *
akashvibhute 4:75c5aa56411f 494 * This option is used to override the defaults, and create custom multicast groups that all share a single
akashvibhute 4:75c5aa56411f 495 * address. <br>
akashvibhute 4:75c5aa56411f 496 * The level should be specified in decimal format 1-6 <br>
akashvibhute 4:75c5aa56411f 497 * @see multicastRelay
akashvibhute 4:75c5aa56411f 498 * @param level Levels 1 to 6 are available. All nodes at the same level will receive the same
akashvibhute 4:75c5aa56411f 499 * messages if in range. Messages will be routed in order of level, low to high by default, with the
akashvibhute 4:75c5aa56411f 500 * master node (00) at multicast Level 0
akashvibhute 4:75c5aa56411f 501 */
akashvibhute 4:75c5aa56411f 502
akashvibhute 4:75c5aa56411f 503 void multicastLevel(uint8_t level);
akashvibhute 4:75c5aa56411f 504
akashvibhute 4:75c5aa56411f 505 /**
akashvibhute 4:75c5aa56411f 506 * Enabling this will allow this node to automatically forward received multicast frames to the next highest
akashvibhute 4:75c5aa56411f 507 * multicast level. Duplicate frames are filtered out, so multiple forwarding nodes at the same level should
akashvibhute 4:75c5aa56411f 508 * not interfere. Forwarded payloads will also be received.
akashvibhute 4:75c5aa56411f 509 * @see multicastLevel
akashvibhute 4:75c5aa56411f 510 */
akashvibhute 4:75c5aa56411f 511
akashvibhute 4:75c5aa56411f 512 bool multicastRelay;
akashvibhute 4:75c5aa56411f 513
akashvibhute 4:75c5aa56411f 514 /**
akashvibhute 4:75c5aa56411f 515 * Set up the watchdog timer for sleep mode using the number 0 through 10 to represent the following time periods:<br>
akashvibhute 4:75c5aa56411f 516 * wdt_16ms = 0, wdt_32ms, wdt_64ms, wdt_128ms, wdt_250ms, wdt_500ms, wdt_1s, wdt_2s, wdt_4s, wdt_8s
akashvibhute 4:75c5aa56411f 517 * @code
akashvibhute 4:75c5aa56411f 518 * setup_watchdog(7); // Sets the WDT to trigger every second
akashvibhute 4:75c5aa56411f 519 * @endcode
akashvibhute 4:75c5aa56411f 520 * @param prescalar The WDT prescaler to define how often the node will wake up. When defining sleep mode cycles, this time period is 1 cycle.
akashvibhute 4:75c5aa56411f 521 */
akashvibhute 4:75c5aa56411f 522 void setup_watchdog(uint8_t prescalar);
akashvibhute 2:a5f8e04bd02b 523
akashvibhute 3:dfc8da7ac18c 524 /**
akashvibhute 4:75c5aa56411f 525 * @note: This value is automatically assigned based on the node address
akashvibhute 4:75c5aa56411f 526 * to reduce errors and increase throughput of the network.
akashvibhute 4:75c5aa56411f 527 *
akashvibhute 4:75c5aa56411f 528 * Sets the timeout period for individual payloads in milliseconds at staggered intervals.
akashvibhute 4:75c5aa56411f 529 * Payloads will be retried automatically until success or timeout
akashvibhute 4:75c5aa56411f 530 * Set to 0 to use the normal auto retry period defined by radio.setRetries()
akashvibhute 4:75c5aa56411f 531 *
akashvibhute 4:75c5aa56411f 532 */
akashvibhute 2:a5f8e04bd02b 533
akashvibhute 4:75c5aa56411f 534 uint32_t txTimeout; /**< Network timeout value */
akashvibhute 4:75c5aa56411f 535
akashvibhute 4:75c5aa56411f 536 /**
akashvibhute 4:75c5aa56411f 537 * This only affects payloads that are routed by one or more nodes.
akashvibhute 4:75c5aa56411f 538 * This specifies how long to wait for an ack from across the network.
akashvibhute 4:75c5aa56411f 539 * Radios sending directly to their parent or children nodes do not
akashvibhute 4:75c5aa56411f 540 * utilize this value.
akashvibhute 4:75c5aa56411f 541 */
akashvibhute 4:75c5aa56411f 542
akashvibhute 4:75c5aa56411f 543 uint16_t routeTimeout; /**< Timeout for routed payloads */
akashvibhute 4:75c5aa56411f 544
akashvibhute 4:75c5aa56411f 545
akashvibhute 4:75c5aa56411f 546 /**@}*/
akashvibhute 4:75c5aa56411f 547 /**
akashvibhute 4:75c5aa56411f 548 * @name Advanced Operation
akashvibhute 4:75c5aa56411f 549 *
akashvibhute 4:75c5aa56411f 550 * For advanced operation of the network
akashvibhute 4:75c5aa56411f 551 */
akashvibhute 4:75c5aa56411f 552 /**@{*/
akashvibhute 2:a5f8e04bd02b 553
akashvibhute 4:75c5aa56411f 554 /**
akashvibhute 4:75c5aa56411f 555 * Return the number of failures and successes for all transmitted payloads, routed or sent directly
akashvibhute 4:75c5aa56411f 556 * @note This needs to be enabled via #define ENABLE_NETWORK_STATS in RF24Network_config.h
akashvibhute 4:75c5aa56411f 557 *
akashvibhute 4:75c5aa56411f 558 * @code
akashvibhute 4:75c5aa56411f 559 * bool fails, success;
akashvibhute 4:75c5aa56411f 560 * network.failures(&fails,&success);
akashvibhute 4:75c5aa56411f 561 * @endcode
akashvibhute 4:75c5aa56411f 562 *
akashvibhute 4:75c5aa56411f 563 */
akashvibhute 4:75c5aa56411f 564 void failures(uint32_t *_fails, uint32_t *_ok);
akashvibhute 4:75c5aa56411f 565
akashvibhute 4:75c5aa56411f 566 #if defined (RF24NetworkMulticast)
akashvibhute 4:75c5aa56411f 567
akashvibhute 4:75c5aa56411f 568 /**
akashvibhute 4:75c5aa56411f 569 * Send a multicast message to multiple nodes at once
akashvibhute 4:75c5aa56411f 570 * Allows messages to be rapidly broadcast through the network
akashvibhute 4:75c5aa56411f 571 *
akashvibhute 4:75c5aa56411f 572 * Multicasting is arranged in levels, with all nodes on the same level listening to the same address
akashvibhute 4:75c5aa56411f 573 * Levels are assigned by network level ie: nodes 01-05: Level 1, nodes 011-055: Level 2
akashvibhute 4:75c5aa56411f 574 * @see multicastLevel
akashvibhute 4:75c5aa56411f 575 * @see multicastRelay
akashvibhute 4:75c5aa56411f 576 * @param message Pointer to memory where the message is located
akashvibhute 4:75c5aa56411f 577 * @param len The size of the message
akashvibhute 4:75c5aa56411f 578 * @param level Multicast level to broadcast to
akashvibhute 4:75c5aa56411f 579 * @return Whether the message was successfully sent
akashvibhute 4:75c5aa56411f 580 */
akashvibhute 4:75c5aa56411f 581
akashvibhute 4:75c5aa56411f 582 bool multicast(RF24NetworkHeader& header,const void* message, uint16_t len, uint8_t level);
akashvibhute 4:75c5aa56411f 583
akashvibhute 4:75c5aa56411f 584
akashvibhute 4:75c5aa56411f 585 #endif
akashvibhute 4:75c5aa56411f 586
akashvibhute 4:75c5aa56411f 587 /**
akashvibhute 4:75c5aa56411f 588 * Writes a direct (unicast) payload. This allows routing or sending messages outside of the usual routing paths.
akashvibhute 4:75c5aa56411f 589 * The same as write, but a physical address is specified as the last option.
akashvibhute 4:75c5aa56411f 590 * The payload will be written to the physical address, and routed as necessary by the recipient
akashvibhute 4:75c5aa56411f 591 */
akashvibhute 4:75c5aa56411f 592 bool write(RF24NetworkHeader& header,const void* message, uint16_t len, uint16_t writeDirect);
akashvibhute 3:dfc8da7ac18c 593
akashvibhute 4:75c5aa56411f 594 /**
akashvibhute 4:75c5aa56411f 595 * Sleep this node - For AVR devices only
akashvibhute 4:75c5aa56411f 596 * @note NEW - Nodes can now be slept while the radio is not actively transmitting. This must be manually enabled by uncommenting
akashvibhute 4:75c5aa56411f 597 * the #define ENABLE_SLEEP_MODE in RF24Network_config.h
akashvibhute 4:75c5aa56411f 598 * @note Setting the interruptPin to 255 will disable interrupt wake-ups
akashvibhute 4:75c5aa56411f 599 * @note The watchdog timer should be configured in setup() if using sleep mode.
akashvibhute 4:75c5aa56411f 600 * This function will sleep the node, with the radio still active in receive mode.
akashvibhute 4:75c5aa56411f 601 *
akashvibhute 4:75c5aa56411f 602 * The node can be awoken in two ways, both of which can be enabled simultaneously:
akashvibhute 4:75c5aa56411f 603 * 1. An interrupt - usually triggered by the radio receiving a payload. Must use pin 2 (interrupt 0) or 3 (interrupt 1) on Uno, Nano, etc.
akashvibhute 4:75c5aa56411f 604 * 2. The watchdog timer waking the MCU after a designated period of time, can also be used instead of delays to control transmission intervals.
akashvibhute 4:75c5aa56411f 605 * @code
akashvibhute 4:75c5aa56411f 606 * if(!network.available()){ network.sleepNode(1,0); } //Sleeps the node for 1 second or a payload is received
akashvibhute 4:75c5aa56411f 607 *
akashvibhute 4:75c5aa56411f 608 * Other options:
akashvibhute 4:75c5aa56411f 609 * network.sleepNode(0,0); // Sleep this node for the designated time period, or a payload is received.
akashvibhute 4:75c5aa56411f 610 * network.sleepNode(1,255); // Sleep this node for 1 cycle. Do not wake up until then, even if a payload is received ( no interrupt )
akashvibhute 4:75c5aa56411f 611 * @endcode
akashvibhute 4:75c5aa56411f 612 * @see setup_watchdog()
akashvibhute 4:75c5aa56411f 613 * @param cycles: The node will sleep in cycles of 1s. Using 2 will sleep 2 WDT cycles, 3 sleeps 3WDT cycles...
akashvibhute 4:75c5aa56411f 614 * @param interruptPin: The interrupt number to use (0,1) for pins two and three on Uno,Nano. More available on Mega etc.
akashvibhute 4:75c5aa56411f 615 * @return True if sleepNode completed normally, after the specified number of cycles. False if sleep was interrupted
akashvibhute 4:75c5aa56411f 616 */
akashvibhute 4:75c5aa56411f 617 bool sleepNode( unsigned int cycles, int interruptPin );
akashvibhute 3:dfc8da7ac18c 618
akashvibhute 3:dfc8da7ac18c 619
akashvibhute 4:75c5aa56411f 620 /**
akashvibhute 4:75c5aa56411f 621 * This node's parent address
akashvibhute 4:75c5aa56411f 622 *
akashvibhute 4:75c5aa56411f 623 * @return This node's parent address, or -1 if this is the base
akashvibhute 4:75c5aa56411f 624 */
akashvibhute 4:75c5aa56411f 625 uint16_t parent() const;
akashvibhute 4:75c5aa56411f 626
akashvibhute 4:75c5aa56411f 627 /**
akashvibhute 4:75c5aa56411f 628 * Provided a node address and a pipe number, will return the RF24Network address of that child pipe for that node
akashvibhute 4:75c5aa56411f 629 */
akashvibhute 4:75c5aa56411f 630 uint16_t addressOfPipe( uint16_t node,uint8_t pipeNo );
akashvibhute 4:75c5aa56411f 631
akashvibhute 4:75c5aa56411f 632 /**
akashvibhute 4:75c5aa56411f 633 * @note Addresses are specified in octal: 011, 034
akashvibhute 4:75c5aa56411f 634 * @return True if a supplied address is valid
akashvibhute 4:75c5aa56411f 635 */
akashvibhute 4:75c5aa56411f 636 bool is_valid_address( uint16_t node );
akashvibhute 2:a5f8e04bd02b 637
akashvibhute 4:75c5aa56411f 638 /**@}*/
akashvibhute 4:75c5aa56411f 639 /**
akashvibhute 4:75c5aa56411f 640 * @name Deprecated
akashvibhute 4:75c5aa56411f 641 *
akashvibhute 4:75c5aa56411f 642 * Maintained for backwards compatibility
akashvibhute 4:75c5aa56411f 643 */
akashvibhute 4:75c5aa56411f 644 /**@{*/
akashvibhute 4:75c5aa56411f 645
akashvibhute 4:75c5aa56411f 646 /**
akashvibhute 4:75c5aa56411f 647 * Bring up the network on a specific radio frequency/channel.
akashvibhute 4:75c5aa56411f 648 * @note Use radio.setChannel() to configure the radio channel
akashvibhute 4:75c5aa56411f 649 *
akashvibhute 4:75c5aa56411f 650 * **Example 1:** Begin on channel 90 with address 0 (master node)
akashvibhute 4:75c5aa56411f 651 * @code
akashvibhute 4:75c5aa56411f 652 * network.begin(90,0);
akashvibhute 4:75c5aa56411f 653 * @endcode
akashvibhute 4:75c5aa56411f 654 * **Example 2:** Begin on channel 90 with address 01 (child of master)
akashvibhute 4:75c5aa56411f 655 * @code
akashvibhute 4:75c5aa56411f 656 * network.begin(90,01);
akashvibhute 4:75c5aa56411f 657 * @endcode
akashvibhute 4:75c5aa56411f 658 * **Example 3:** Begin on channel 90 with address 011 (child of 01, grandchild of master)
akashvibhute 4:75c5aa56411f 659 * @code
akashvibhute 4:75c5aa56411f 660 * network.begin(90,011);
akashvibhute 4:75c5aa56411f 661 * @endcode
akashvibhute 4:75c5aa56411f 662 *
akashvibhute 4:75c5aa56411f 663 * @param _channel The RF channel to operate on
akashvibhute 4:75c5aa56411f 664 * @param _node_address The logical address of this node
akashvibhute 4:75c5aa56411f 665 *
akashvibhute 4:75c5aa56411f 666 */
akashvibhute 4:75c5aa56411f 667 void begin(uint8_t _channel, uint16_t _node_address );
akashvibhute 4:75c5aa56411f 668
akashvibhute 4:75c5aa56411f 669 /**@}*/
akashvibhute 4:75c5aa56411f 670 /**
akashvibhute 4:75c5aa56411f 671 * @name External Applications/Systems
akashvibhute 4:75c5aa56411f 672 *
akashvibhute 4:75c5aa56411f 673 * Interface for External Applications and Systems ( RF24Mesh, RF24Ethernet )
akashvibhute 4:75c5aa56411f 674 */
akashvibhute 4:75c5aa56411f 675 /**@{*/
akashvibhute 4:75c5aa56411f 676
akashvibhute 4:75c5aa56411f 677 /** The raw system frame buffer of received data. */
akashvibhute 4:75c5aa56411f 678
akashvibhute 4:75c5aa56411f 679 uint8_t frame_buffer[MAX_FRAME_SIZE];
akashvibhute 2:a5f8e04bd02b 680
akashvibhute 4:75c5aa56411f 681 /**
akashvibhute 4:75c5aa56411f 682 * **Linux** <br>
akashvibhute 4:75c5aa56411f 683 * Data with a header type of EXTERNAL_DATA_TYPE will be loaded into a separate queue.
akashvibhute 4:75c5aa56411f 684 * The data can be accessed as follows:
akashvibhute 4:75c5aa56411f 685 * @code
akashvibhute 4:75c5aa56411f 686 * RF24NetworkFrame f;
akashvibhute 4:75c5aa56411f 687 * while(network.external_queue.size() > 0){
akashvibhute 4:75c5aa56411f 688 * f = network.external_queue.front();
akashvibhute 4:75c5aa56411f 689 * uint16_t dataSize = f.message_size;
akashvibhute 4:75c5aa56411f 690 * //read the frame message buffer
akashvibhute 4:75c5aa56411f 691 * memcpy(&myBuffer,&f.message_buffer,dataSize);
akashvibhute 4:75c5aa56411f 692 * network.external_queue.pop();
akashvibhute 4:75c5aa56411f 693 * }
akashvibhute 4:75c5aa56411f 694 * @endcode
akashvibhute 4:75c5aa56411f 695 */
akashvibhute 4:75c5aa56411f 696
akashvibhute 4:75c5aa56411f 697
akashvibhute 4:75c5aa56411f 698
akashvibhute 4:75c5aa56411f 699
akashvibhute 4:75c5aa56411f 700 #if !defined ( DISABLE_FRAGMENTATION )
akashvibhute 4:75c5aa56411f 701 /**
akashvibhute 4:75c5aa56411f 702 * **ARDUINO** <br>
akashvibhute 4:75c5aa56411f 703 * The frag_ptr is only used with Arduino (not RPi/Linux) and is mainly used for external data systems like RF24Ethernet. When
akashvibhute 4:75c5aa56411f 704 * an EXTERNAL_DATA payload type is received, and returned from network.update(), the frag_ptr will always point to the starting
akashvibhute 4:75c5aa56411f 705 * memory location of the received frame. <br>This is used by external data systems (RF24Ethernet) to immediately copy the received
akashvibhute 4:75c5aa56411f 706 * data to a buffer, without using the user-cache.
akashvibhute 4:75c5aa56411f 707 *
akashvibhute 4:75c5aa56411f 708 * @see RF24NetworkFrame
akashvibhute 4:75c5aa56411f 709 *
akashvibhute 4:75c5aa56411f 710 * @code
akashvibhute 4:75c5aa56411f 711 * uint8_t return_type = network.update();
akashvibhute 4:75c5aa56411f 712 * if(return_type == EXTERNAL_DATA_TYPE){
akashvibhute 4:75c5aa56411f 713 * uint16_t size = network.frag_ptr->message_size;
akashvibhute 4:75c5aa56411f 714 * memcpy(&myDataBuffer,network.frag_ptr->message_buffer,network.frag_ptr->message_size);
akashvibhute 4:75c5aa56411f 715 * }
akashvibhute 4:75c5aa56411f 716 * @endcode
akashvibhute 4:75c5aa56411f 717 * Linux devices (defined as RF24_LINUX) currently cache all payload types, and do not utilize frag_ptr.
akashvibhute 4:75c5aa56411f 718 */
akashvibhute 4:75c5aa56411f 719 RF24NetworkFrame* frag_ptr;
akashvibhute 4:75c5aa56411f 720 #endif
akashvibhute 0:c3db0798d9aa 721
akashvibhute 4:75c5aa56411f 722 /**
akashvibhute 4:75c5aa56411f 723 * Variable to determine whether update() will return after the radio buffers have been emptied (DEFAULT), or
akashvibhute 4:75c5aa56411f 724 * whether to return immediately when (most) system types are received.
akashvibhute 4:75c5aa56411f 725 *
akashvibhute 4:75c5aa56411f 726 * As an example, this is used with RF24Mesh to catch and handle system messages without loading them into the user cache.
akashvibhute 4:75c5aa56411f 727 *
akashvibhute 4:75c5aa56411f 728 * The following reserved/system message types are handled automatically, and not returned.
akashvibhute 4:75c5aa56411f 729 *
akashvibhute 4:75c5aa56411f 730 * | System Message Types <br> (Not Returned) |
akashvibhute 4:75c5aa56411f 731 * |-----------------------|
akashvibhute 4:75c5aa56411f 732 * | NETWORK_ADDR_RESPONSE |
akashvibhute 4:75c5aa56411f 733 * | NETWORK_ACK |
akashvibhute 4:75c5aa56411f 734 * | NETWORK_PING |
akashvibhute 4:75c5aa56411f 735 * | NETWORK_POLL <br>(With multicast enabled) |
akashvibhute 4:75c5aa56411f 736 * | NETWORK_REQ_ADDRESS |
akashvibhute 4:75c5aa56411f 737 *
akashvibhute 4:75c5aa56411f 738 */
akashvibhute 4:75c5aa56411f 739 bool returnSysMsgs;
akashvibhute 3:dfc8da7ac18c 740
akashvibhute 4:75c5aa56411f 741 /**
akashvibhute 4:75c5aa56411f 742 * Network Flags allow control of data flow
akashvibhute 4:75c5aa56411f 743 *
akashvibhute 4:75c5aa56411f 744 * Incoming Blocking: If the network user-cache is full, lets radio cache fill up. Radio ACKs are not sent when radio internal cache is full.<br>
akashvibhute 4:75c5aa56411f 745 * This behaviour may seem to result in more failed sends, but the payloads would have otherwise been dropped due to the cache being full.<br>
akashvibhute 4:75c5aa56411f 746 *
akashvibhute 4:75c5aa56411f 747 * | FLAGS | Value | Description |
akashvibhute 4:75c5aa56411f 748 * |-------|-------|-------------|
akashvibhute 4:75c5aa56411f 749 * |FLAG_HOLD_INCOMING| 1(bit_1) | INTERNAL: Set automatically when a fragmented payload will exceed the available cache |
akashvibhute 4:75c5aa56411f 750 * |FLAG_BYPASS_HOLDS| 2(bit_2) | EXTERNAL: Can be used to prevent holds from blocking. Note: Holds are disabled & re-enabled by RF24Mesh when renewing addresses. This will cause data loss if incoming data exceeds the available cache space|
akashvibhute 4:75c5aa56411f 751 * |FLAG_FAST_FRAG| 4(bit_3) | INTERNAL: Replaces the fastFragTransfer variable, and allows for faster transfers between directly connected nodes. |
akashvibhute 4:75c5aa56411f 752 * |FLAG_NO_POLL| 8(bit_4) | EXTERNAL/USER: Disables NETWORK_POLL responses on a node-by-node basis. |
akashvibhute 4:75c5aa56411f 753 *
akashvibhute 4:75c5aa56411f 754 */
akashvibhute 4:75c5aa56411f 755 uint8_t networkFlags;
akashvibhute 4:75c5aa56411f 756
akashvibhute 4:75c5aa56411f 757 private:
akashvibhute 3:dfc8da7ac18c 758
akashvibhute 4:75c5aa56411f 759 uint32_t txTime;
akashvibhute 4:75c5aa56411f 760 Timer mainTimer;
akashvibhute 4:75c5aa56411f 761
akashvibhute 4:75c5aa56411f 762 bool write(uint16_t, uint8_t directTo);
akashvibhute 4:75c5aa56411f 763 bool write_to_pipe( uint16_t node, uint8_t pipe, bool multicast );
akashvibhute 4:75c5aa56411f 764 uint8_t enqueue(RF24NetworkHeader *header);
akashvibhute 3:dfc8da7ac18c 765
akashvibhute 4:75c5aa56411f 766 bool is_direct_child( uint16_t node );
akashvibhute 4:75c5aa56411f 767 bool is_descendant( uint16_t node );
akashvibhute 4:75c5aa56411f 768
akashvibhute 4:75c5aa56411f 769 uint16_t direct_child_route_to( uint16_t node );
akashvibhute 4:75c5aa56411f 770 //uint8_t pipe_to_descendant( uint16_t node );
akashvibhute 4:75c5aa56411f 771 void setup_address(void);
akashvibhute 4:75c5aa56411f 772 bool _write(RF24NetworkHeader& header,const void* message, uint16_t len, uint16_t writeDirect);
akashvibhute 4:75c5aa56411f 773
akashvibhute 4:75c5aa56411f 774 struct logicalToPhysicalStruct{
akashvibhute 4:75c5aa56411f 775 uint16_t send_node;
akashvibhute 4:75c5aa56411f 776 uint8_t send_pipe;
akashvibhute 4:75c5aa56411f 777 bool multicast;
akashvibhute 4:75c5aa56411f 778 };
akashvibhute 4:75c5aa56411f 779
akashvibhute 4:75c5aa56411f 780 bool logicalToPhysicalAddress(logicalToPhysicalStruct *conversionInfo);
akashvibhute 4:75c5aa56411f 781
akashvibhute 4:75c5aa56411f 782
akashvibhute 4:75c5aa56411f 783 RF24& radio; /**< Underlying radio driver, provides link/physical layers */
akashvibhute 3:dfc8da7ac18c 784 #if defined (DUAL_HEAD_RADIO)
akashvibhute 4:75c5aa56411f 785 RF24& radio1;
akashvibhute 3:dfc8da7ac18c 786 #endif
akashvibhute 4:75c5aa56411f 787 #if defined (RF24NetworkMulticast)
akashvibhute 4:75c5aa56411f 788 uint8_t multicast_level;
akashvibhute 3:dfc8da7ac18c 789 #endif
akashvibhute 4:75c5aa56411f 790 uint16_t node_address; /**< Logical node address of this unit, 1 .. UINT_MAX */
akashvibhute 4:75c5aa56411f 791 //const static int frame_size = 32; /**< How large is each frame over the air */
akashvibhute 4:75c5aa56411f 792 uint8_t frame_size;
akashvibhute 4:75c5aa56411f 793 const static unsigned int max_frame_payload_size = MAX_FRAME_SIZE-sizeof(RF24NetworkHeader);
akashvibhute 3:dfc8da7ac18c 794
akashvibhute 4:75c5aa56411f 795
akashvibhute 4:75c5aa56411f 796 #if !defined (NUM_USER_PAYLOADS)
akashvibhute 4:75c5aa56411f 797 #define NUM_USER_PAYLOADS 5
akashvibhute 4:75c5aa56411f 798 #endif
akashvibhute 4:75c5aa56411f 799
akashvibhute 4:75c5aa56411f 800 #if defined (DISABLE_USER_PAYLOADS)
akashvibhute 4:75c5aa56411f 801 uint8_t frame_queue[1]; /**< Space for a small set of frames that need to be delivered to the app layer */
akashvibhute 4:75c5aa56411f 802 #else
akashvibhute 4:75c5aa56411f 803 uint8_t frame_queue[MAIN_BUFFER_SIZE]; /**< Space for a small set of frames that need to be delivered to the app layer */
akashvibhute 4:75c5aa56411f 804 #endif
akashvibhute 4:75c5aa56411f 805
akashvibhute 4:75c5aa56411f 806 uint8_t* next_frame; /**< Pointer into the @p frame_queue where we should place the next received frame */
akashvibhute 4:75c5aa56411f 807
akashvibhute 4:75c5aa56411f 808 #if !defined ( DISABLE_FRAGMENTATION )
akashvibhute 4:75c5aa56411f 809 RF24NetworkFrame frag_queue;
akashvibhute 4:75c5aa56411f 810 uint8_t frag_queue_message_buffer[MAX_PAYLOAD_SIZE]; //frame size + 1
akashvibhute 4:75c5aa56411f 811 #endif
akashvibhute 0:c3db0798d9aa 812
akashvibhute 4:75c5aa56411f 813
akashvibhute 4:75c5aa56411f 814 //uint8_t frag_queue[MAX_PAYLOAD_SIZE + 11];
akashvibhute 4:75c5aa56411f 815 //RF24NetworkFrame frag_queue;
akashvibhute 4:75c5aa56411f 816
akashvibhute 4:75c5aa56411f 817 uint16_t parent_node; /**< Our parent's node address */
akashvibhute 4:75c5aa56411f 818 uint8_t parent_pipe; /**< The pipe our parent uses to listen to us */
akashvibhute 4:75c5aa56411f 819 uint16_t node_mask; /**< The bits which contain signfificant node address information */
akashvibhute 4:75c5aa56411f 820
akashvibhute 4:75c5aa56411f 821 #if defined ENABLE_NETWORK_STATS
akashvibhute 4:75c5aa56411f 822 static uint32_t nFails;
akashvibhute 4:75c5aa56411f 823 static uint32_t nOK;
akashvibhute 4:75c5aa56411f 824 #endif
akashvibhute 4:75c5aa56411f 825
akashvibhute 2:a5f8e04bd02b 826 public:
akashvibhute 2:a5f8e04bd02b 827
akashvibhute 4:75c5aa56411f 828
akashvibhute 2:a5f8e04bd02b 829
akashvibhute 0:c3db0798d9aa 830 };
akashvibhute 0:c3db0798d9aa 831
akashvibhute 0:c3db0798d9aa 832 /**
akashvibhute 2:a5f8e04bd02b 833 * @example helloworld_tx.ino
akashvibhute 0:c3db0798d9aa 834 *
akashvibhute 0:c3db0798d9aa 835 * Simplest possible example of using RF24Network. Put this sketch
akashvibhute 0:c3db0798d9aa 836 * on one node, and helloworld_rx.pde on the other. Tx will send
akashvibhute 0:c3db0798d9aa 837 * Rx a nice message every 2 seconds which rx will print out for us.
akashvibhute 0:c3db0798d9aa 838 */
akashvibhute 0:c3db0798d9aa 839
akashvibhute 0:c3db0798d9aa 840 /**
akashvibhute 2:a5f8e04bd02b 841 * @example helloworld_rx.ino
akashvibhute 0:c3db0798d9aa 842 *
akashvibhute 0:c3db0798d9aa 843 * Simplest possible example of using RF24Network. Put this sketch
akashvibhute 0:c3db0798d9aa 844 * on one node, and helloworld_tx.pde on the other. Tx will send
akashvibhute 0:c3db0798d9aa 845 * Rx a nice message every 2 seconds which rx will print out for us.
akashvibhute 0:c3db0798d9aa 846 */
akashvibhute 0:c3db0798d9aa 847
akashvibhute 0:c3db0798d9aa 848 /**
akashvibhute 2:a5f8e04bd02b 849 * @example Network_Ping.ino
akashvibhute 0:c3db0798d9aa 850 *
akashvibhute 2:a5f8e04bd02b 851 * Example to give users an understanding of addressing and topology in the mesh network
akashvibhute 0:c3db0798d9aa 852 * Using this sketch, each node will send a ping to the base every
akashvibhute 0:c3db0798d9aa 853 * few seconds. The RF24Network library will route the message across
akashvibhute 0:c3db0798d9aa 854 * the mesh to the correct node.
akashvibhute 2:a5f8e04bd02b 855 *
akashvibhute 2:a5f8e04bd02b 856 */
akashvibhute 2:a5f8e04bd02b 857
akashvibhute 2:a5f8e04bd02b 858 /**
akashvibhute 2:a5f8e04bd02b 859 * @example Network_Ping_Sleep.ino
akashvibhute 2:a5f8e04bd02b 860 *
akashvibhute 2:a5f8e04bd02b 861 * Example: This is almost exactly the same as the Network_Ping example, but with use
akashvibhute 2:a5f8e04bd02b 862 * of the integrated sleep mode.
akashvibhute 2:a5f8e04bd02b 863 *
akashvibhute 2:a5f8e04bd02b 864 * This example demonstrates how nodes on the network utilize sleep mode to conserve power. For example,
akashvibhute 2:a5f8e04bd02b 865 * the radio itself will draw about 13.5mA in receive mode. In sleep mode, it will use as little as 22ua (.000022mA)
akashvibhute 2:a5f8e04bd02b 866 * of power when not actively transmitting or receiving data. In addition, the Arduino is powered down as well,
akashvibhute 2:a5f8e04bd02b 867 * dropping network power consumption dramatically compared to previous capabilities. <br>
akashvibhute 2:a5f8e04bd02b 868 * Note: Sleeping nodes generate traffic that will wake other nodes up. This may be mitigated with further modifications. Sleep
akashvibhute 2:a5f8e04bd02b 869 * payloads are currently always routed to the master node, which will wake up intermediary nodes. Routing nodes can be configured
akashvibhute 2:a5f8e04bd02b 870 * to go back to sleep immediately.
akashvibhute 2:a5f8e04bd02b 871 * The displayed millis() count will give an indication of how much a node has been sleeping compared to the others, as millis() will
akashvibhute 2:a5f8e04bd02b 872 * not increment while a node sleeps.
akashvibhute 2:a5f8e04bd02b 873 *<br>
akashvibhute 2:a5f8e04bd02b 874 * - Using this sketch, each node will send a ping to every other node in the network every few seconds.<br>
akashvibhute 2:a5f8e04bd02b 875 * - The RF24Network library will route the message across the mesh to the correct node.<br>
akashvibhute 2:a5f8e04bd02b 876 *
akashvibhute 0:c3db0798d9aa 877 */
akashvibhute 0:c3db0798d9aa 878
akashvibhute 0:c3db0798d9aa 879 /**
akashvibhute 0:c3db0798d9aa 880 * @example sensornet.pde
akashvibhute 0:c3db0798d9aa 881 *
akashvibhute 0:c3db0798d9aa 882 * Example of a sensor network.
akashvibhute 0:c3db0798d9aa 883 * This sketch demonstrates how to use the RF24Network library to
akashvibhute 0:c3db0798d9aa 884 * manage a set of low-power sensor nodes which mostly sleep but
akashvibhute 0:c3db0798d9aa 885 * awake regularly to send readings to the base.
akashvibhute 0:c3db0798d9aa 886 */
akashvibhute 0:c3db0798d9aa 887 /**
akashvibhute 0:c3db0798d9aa 888 * @mainpage Network Layer for RF24 Radios
akashvibhute 0:c3db0798d9aa 889 *
akashvibhute 0:c3db0798d9aa 890 * This class implements an <a href="http://en.wikipedia.org/wiki/Network_layer">OSI Network Layer</a> using nRF24L01(+) radios driven
akashvibhute 2:a5f8e04bd02b 891 * by the newly optimized <a href="http://tmrh20.github.com/RF24/">RF24</a> library fork.
akashvibhute 0:c3db0798d9aa 892 *
akashvibhute 0:c3db0798d9aa 893 * @section Purpose Purpose/Goal
akashvibhute 0:c3db0798d9aa 894 *
akashvibhute 2:a5f8e04bd02b 895 * Original: Create an alternative to ZigBee radios for Arduino communication.
akashvibhute 4:75c5aa56411f 896 *
akashvibhute 2:a5f8e04bd02b 897 * New: Enhance the current functionality for maximum efficiency, reliability, and speed
akashvibhute 0:c3db0798d9aa 898 *
akashvibhute 2:a5f8e04bd02b 899 * Xbees are excellent little radios, backed up by a mature and robust standard
akashvibhute 0:c3db0798d9aa 900 * protocol stack. They are also expensive.
akashvibhute 0:c3db0798d9aa 901 *
akashvibhute 2:a5f8e04bd02b 902 * For many Arduino uses, they seem like overkill. So I am working to improve the current
akashvibhute 2:a5f8e04bd02b 903 * standard for nRF24L01 radios. The best RF24 modules are available for less than
akashvibhute 0:c3db0798d9aa 904 * $6 from many sources. With the RF24Network layer, I hope to cover many
akashvibhute 0:c3db0798d9aa 905 * common communication scenarios.
akashvibhute 0:c3db0798d9aa 906 *
akashvibhute 0:c3db0798d9aa 907 * Please see the @ref Zigbee page for a comparison against the ZigBee protocols
akashvibhute 0:c3db0798d9aa 908 *
akashvibhute 0:c3db0798d9aa 909 * @section Features Features
akashvibhute 0:c3db0798d9aa 910 *
akashvibhute 4:75c5aa56411f 911 * <b>Whats new? </b><br>
akashvibhute 2:a5f8e04bd02b 912 * @li New: (Dec 8) Merge of RPi and Arduino code. Finally moving closer to a stable release. Report issues at https://github.com/TMRh20/RF24Network/issues
akashvibhute 2:a5f8e04bd02b 913 * @li New functionality: (Dec 8) Support for fragmented multicast payloads on both RPi and Arduino
akashvibhute 4:75c5aa56411f 914 * @li New functionality: (Nov 24) Fragmentation & reassembly supported on both RPi and Arduino
akashvibhute 2:a5f8e04bd02b 915 * @li Note: structure of network frames is changed, these are only used by external applications like RF24Ethernet and RF24toTUN, and for fragmentation
akashvibhute 2:a5f8e04bd02b 916 * @li New functionality: User message types 1 through 64 will not receive a network ack
akashvibhute 2:a5f8e04bd02b 917 *
akashvibhute 0:c3db0798d9aa 918 * The layer provides:
akashvibhute 2:a5f8e04bd02b 919 * @li <b>New</b> (2014): Network ACKs: Efficient acknowledgement of network-wide transmissions, via dynamic radio acks and network protocol acks.
akashvibhute 2:a5f8e04bd02b 920 * @li <b>New</b> (2014): Updated addressing standard for optimal radio transmission.
akashvibhute 2:a5f8e04bd02b 921 * @li <b>New</b> (2014): Extended timeouts and staggered timeout intervals. The new txTimeout variable allows fully automated extended timeout periods via auto-retry/auto-reUse of payloads.
akashvibhute 2:a5f8e04bd02b 922 * @li <b>New</b> (2014): Optimization to the core library provides improvements to reliability, speed and efficiency. See https://tmrh20.github.io/RF24 for more info.
akashvibhute 2:a5f8e04bd02b 923 * @li <b>New</b> (2014): Built in sleep mode using interrupts. (Still under development. (Enable via RF24Network_config.h))
akashvibhute 2:a5f8e04bd02b 924 * @li <b>New</b> (2014): Dual headed operation: The use of dual radios for busy routing nodes or the master node enhances throughput and decreases errors. See the <a href="Tuning.html">Tuning</a> section.
akashvibhute 0:c3db0798d9aa 925 * @li Host Addressing. Each node has a logical address on the local network.
akashvibhute 0:c3db0798d9aa 926 * @li Message Forwarding. Messages can be sent from one node to any other, and
akashvibhute 0:c3db0798d9aa 927 * this layer will get them there no matter how many hops it takes.
akashvibhute 0:c3db0798d9aa 928 * @li Ad-hoc Joining. A node can join a network without any changes to any
akashvibhute 0:c3db0798d9aa 929 * existing nodes.
akashvibhute 0:c3db0798d9aa 930 *
akashvibhute 2:a5f8e04bd02b 931 * The layer does not provide:
akashvibhute 2:a5f8e04bd02b 932 * @li Dynamic address assignment. (See RF24Mesh)
akashvibhute 2:a5f8e04bd02b 933 * @li Layer 4 protocols (TCP/IP - See RF24Ethernet and RF24toTUN)
akashvibhute 0:c3db0798d9aa 934 *
akashvibhute 0:c3db0798d9aa 935 * @section More How to learn more
akashvibhute 0:c3db0798d9aa 936 *
akashvibhute 0:c3db0798d9aa 937 * @li <a href="classRF24Network.html">RF24Network Class Documentation</a>
akashvibhute 2:a5f8e04bd02b 938 * @li <a href="AdvancedConfig.html"> Advanced Configuration Options</a>
akashvibhute 2:a5f8e04bd02b 939 * @li <a href="Addressing.html"> Addressing format</a>
akashvibhute 2:a5f8e04bd02b 940 * @li <a href="Tuning.html"> Topology and Overview</a>
akashvibhute 2:a5f8e04bd02b 941 * @li <a href="https://github.com/TMRh20/RF24Network/archive/Development.zip">Download Current Development Package</a>
akashvibhute 2:a5f8e04bd02b 942 * @li <a href="examples.html">Examples Page</a>. Start with <a href="helloworld_rx_8ino-example.html">helloworld_rx</a> and <a href="helloworld_tx_8ino-example.html">helloworld_tx</a>.
akashvibhute 0:c3db0798d9aa 943 *
akashvibhute 4:75c5aa56411f 944 * <b> Additional Information & Add-ons </b>
akashvibhute 2:a5f8e04bd02b 945 * @li <a href="https://github.com/TMRh20/RF24Mesh">RF24Mesh: Dynamic Mesh Layer for RF24Network Dev</a>
akashvibhute 2:a5f8e04bd02b 946 * @li <a href="https://github.com/TMRh20/RF24Ethernet">RF24Ethernet: TCP/IP over RF24Network</a>
akashvibhute 2:a5f8e04bd02b 947 * @li <a href="http://tmrh20.blogspot.com/2014/03/high-speed-data-transfers-and-wireless.html">My Blog: RF24 Optimization Overview</a>
akashvibhute 2:a5f8e04bd02b 948 * @li <a href="http://tmrh20.blogspot.com/2014/03/arduino-radiointercomwireless-audio.html">My Blog: RF24 Wireless Audio</a>
akashvibhute 2:a5f8e04bd02b 949 * @li <a href="http://maniacbug.github.com/RF24/">RF24: Original Author</a>
akashvibhute 0:c3db0798d9aa 950 * @section Topology Topology for Mesh Networks using nRF24L01(+)
akashvibhute 0:c3db0798d9aa 951 *
akashvibhute 0:c3db0798d9aa 952 * This network layer takes advantage of the fundamental capability of the nRF24L01(+) radio to
akashvibhute 2:a5f8e04bd02b 953 * listen actively to up to 6 other radios at once. The network is arranged in a
akashvibhute 0:c3db0798d9aa 954 * <a href="http://en.wikipedia.org/wiki/Network_Topology#Tree">Tree Topology</a>, where
akashvibhute 0:c3db0798d9aa 955 * one node is the base, and all other nodes are children either of that node, or of another.
akashvibhute 0:c3db0798d9aa 956 * Unlike a true mesh network, multiple nodes are not connected together, so there is only one
akashvibhute 0:c3db0798d9aa 957 * path to any given node.
akashvibhute 0:c3db0798d9aa 958 *
akashvibhute 2:a5f8e04bd02b 959 * @section Octal Octal Addressing and Topology
akashvibhute 0:c3db0798d9aa 960 *
akashvibhute 0:c3db0798d9aa 961 * Each node must be assigned an 15-bit address by the administrator. This address exactly
akashvibhute 0:c3db0798d9aa 962 * describes the position of the node within the tree. The address is an octal number. Each
akashvibhute 0:c3db0798d9aa 963 * digit in the address represents a position in the tree further from the base.
akashvibhute 0:c3db0798d9aa 964 *
akashvibhute 0:c3db0798d9aa 965 * @li Node 00 is the base node.
akashvibhute 0:c3db0798d9aa 966 * @li Nodes 01-05 are nodes whose parent is the base.
akashvibhute 0:c3db0798d9aa 967 * @li Node 021 is the second child of node 01.
akashvibhute 0:c3db0798d9aa 968 * @li Node 0321 is the third child of node 021, an so on.
akashvibhute 0:c3db0798d9aa 969 * @li The largest node address is 05555, so 3,125 nodes are allowed on a single channel.
akashvibhute 2:a5f8e04bd02b 970 * An example topology is shown below, with 5 nodes in direct communication with the master node,
akashvibhute 2:a5f8e04bd02b 971 * and multiple leaf nodes spread out at a distance, using intermediate nodes to reach other nodes.
akashvibhute 2:a5f8e04bd02b 972 *
akashvibhute 2:a5f8e04bd02b 973 *| | | 00 | | | 00 | | | | Master Node (00) |
akashvibhute 2:a5f8e04bd02b 974 *|---|----|----|----|----|----|----|----|----|-----------------------------------------------------|
akashvibhute 2:a5f8e04bd02b 975 *| | | 01 | | | 04 | | | | 1st level children of master (00) |
akashvibhute 2:a5f8e04bd02b 976 *| | 011| | 021| | |014 | | | 2nd level children of master. Children of 1st level.|
akashvibhute 2:a5f8e04bd02b 977 *|111| | | 121| 221| | | 114| | 3rd level children of master. Children of 2nd level.|
akashvibhute 2:a5f8e04bd02b 978 *| | | | |1221| |1114|2114|3114| 4th level children of master. Children of 3rd level.|
akashvibhute 0:c3db0798d9aa 979 *
akashvibhute 0:c3db0798d9aa 980 * @section Routing How routing is handled
akashvibhute 0:c3db0798d9aa 981 *
akashvibhute 0:c3db0798d9aa 982 * When sending a message using RF24Network::write(), you fill in the header with the logical
akashvibhute 0:c3db0798d9aa 983 * node address. The network layer figures out the right path to find that node, and sends
akashvibhute 0:c3db0798d9aa 984 * it through the system until it gets to the right place. This works even if the two nodes
akashvibhute 0:c3db0798d9aa 985 * are far separated, as it will send the message down to the base node, and then back out
akashvibhute 0:c3db0798d9aa 986 * to the final destination.
akashvibhute 0:c3db0798d9aa 987 *
akashvibhute 0:c3db0798d9aa 988 * All of this work is handled by the RF24Network::update() method, so be sure to call it
akashvibhute 0:c3db0798d9aa 989 * regularly or your network will miss packets.
akashvibhute 0:c3db0798d9aa 990 *
akashvibhute 0:c3db0798d9aa 991 * @section Startup Starting up a node
akashvibhute 0:c3db0798d9aa 992 *
akashvibhute 0:c3db0798d9aa 993 * When a node starts up, it only has to contact its parent to establish communication.
akashvibhute 0:c3db0798d9aa 994 * No direct connection to the Base node is needed. This is useful in situations where
akashvibhute 0:c3db0798d9aa 995 * relay nodes are being used to bridge the distance to the base, so leaf nodes are out
akashvibhute 0:c3db0798d9aa 996 * of range of the base.
akashvibhute 0:c3db0798d9aa 997 *
akashvibhute 2:a5f8e04bd02b 998 * @section Directionality Directionality
akashvibhute 0:c3db0798d9aa 999 *
akashvibhute 0:c3db0798d9aa 1000 * By default all nodes are always listening, so messages will quickly reach
akashvibhute 2:a5f8e04bd02b 1001 * their destination.
akashvibhute 2:a5f8e04bd02b 1002 *
akashvibhute 2:a5f8e04bd02b 1003 * You may choose to sleep any nodes on the network if using interrupts. This is useful in a
akashvibhute 2:a5f8e04bd02b 1004 * case where the nodes are operating on batteries and need to sleep. This greatly decreases
akashvibhute 2:a5f8e04bd02b 1005 * the power requirements for a sensor network. The leaf nodes can sleep most of the time,
akashvibhute 2:a5f8e04bd02b 1006 * and wake every few minutes to send in a reading. Routing nodes can be triggered to wake up
akashvibhute 2:a5f8e04bd02b 1007 * whenever a payload is received See sleepNode() in the class documentation, and RFNetwork_config.h
akashvibhute 2:a5f8e04bd02b 1008 * to enable sleep mode.
akashvibhute 2:a5f8e04bd02b 1009 *
akashvibhute 2:a5f8e04bd02b 1010 *
akashvibhute 2:a5f8e04bd02b 1011 * @page Addressing Addressing Format: Understanding Addressing and Topology
akashvibhute 2:a5f8e04bd02b 1012 * An overview of addressing in RF24Network
akashvibhute 2:a5f8e04bd02b 1013 *
akashvibhute 2:a5f8e04bd02b 1014 * @section Overview Overview
akashvibhute 2:a5f8e04bd02b 1015 * The nrf24 radio modules typically use a 40-bit address format, requiring 5-bytes of storage space per address, and allowing a wide
akashvibhute 4:75c5aa56411f 1016 * array of addresses to be utilized. In addition, the radios are limited to direct communication with 6 other nodes while using the
akashvibhute 4:75c5aa56411f 1017 * Enhanced-Shock-Burst (ESB) functionality of the radios.
akashvibhute 2:a5f8e04bd02b 1018 *
akashvibhute 2:a5f8e04bd02b 1019 * RF24Network uses a simple method of data compression to store the addresses using only 2 bytes, in a format designed to represent the
akashvibhute 2:a5f8e04bd02b 1020 * network topology in an intuitive way.
akashvibhute 2:a5f8e04bd02b 1021 * See the <a href="Tuning.html"> Topology and Overview</a> page for more info regarding topology.
akashvibhute 2:a5f8e04bd02b 1022 *
akashvibhute 2:a5f8e04bd02b 1023 * @section Octal_Binary Decimal, Octal and Binary formats
akashvibhute 4:75c5aa56411f 1024 *
akashvibhute 2:a5f8e04bd02b 1025 * Say we want to designate a logical address to a node, using a tree topology as defined by the manufacturer.
akashvibhute 4:75c5aa56411f 1026 * In the simplest format, we could assign the first node the address of 1, the second 2 and so on.
akashvibhute 2:a5f8e04bd02b 1027 * Since a single node can only connect to 6 other nodes (1 parent and 5 children) subnets need to be created if using more than 6 nodes.<br>
akashvibhute 2:a5f8e04bd02b 1028 * In this case the children of node 1 could simply be designated as 11,21,31,41, and 51<br>
akashvibhute 4:75c5aa56411f 1029 * Children of node 2 could be designated as 12,22,32,42, and 52
akashvibhute 4:75c5aa56411f 1030 *
akashvibhute 2:a5f8e04bd02b 1031 * The above example is exactly how RF24Network manages the addresses, but they are represented in Octal format.
akashvibhute 4:75c5aa56411f 1032 *
akashvibhute 4:75c5aa56411f 1033 * <b>Decimal, Octal and Binary</b>
akashvibhute 4:75c5aa56411f 1034 * <table>
akashvibhute 2:a5f8e04bd02b 1035 * <tr bgcolor="#a3b4d7" >
akashvibhute 2:a5f8e04bd02b 1036 * <td> Decimal </td> <td> Binary </td><td> Decimal </td> <td> Binary </td><td> Decimal </td> <td> Binary </td>
akashvibhute 2:a5f8e04bd02b 1037 * </tr><tr>
akashvibhute 2:a5f8e04bd02b 1038 * <td> 1 </td> <td> 00000001 </td><td> 11 </td> <td> 00001011 </td><td> 111 </td> <td> 01101111 </td>
akashvibhute 2:a5f8e04bd02b 1039 * </tr><tr bgcolor="#a3b4d7" >
akashvibhute 2:a5f8e04bd02b 1040 * <td> Octal </td> <td> Binary </td><td> Octal </td> <td> Binary </td><td> Octal </td> <td> Binary </td>
akashvibhute 2:a5f8e04bd02b 1041 * </tr><tr>
akashvibhute 2:a5f8e04bd02b 1042 * <td> 1 </td> <td> 00000001 </td><td> 011 </td> <td> 00001001 </td><td> 0111 </td> <td> 1001001 </td>
akashvibhute 2:a5f8e04bd02b 1043 * </tr>
akashvibhute 2:a5f8e04bd02b 1044 * </table>
akashvibhute 2:a5f8e04bd02b 1045 *
akashvibhute 4:75c5aa56411f 1046 *
akashvibhute 4:75c5aa56411f 1047 * Since the numbers 0-7 can be represented in exactly three bits, each digit is represented by exactly 3 bits when viewed in octal format.
akashvibhute 4:75c5aa56411f 1048 * This allows a very simple method of managing addresses via masking and bit shifting.
akashvibhute 4:75c5aa56411f 1049 *
akashvibhute 2:a5f8e04bd02b 1050 * @section DisplayAddresses Displaying Addresses
akashvibhute 2:a5f8e04bd02b 1051 *
akashvibhute 2:a5f8e04bd02b 1052 * When using Arduino devices, octal addresses can be printed in the following manner:
akashvibhute 2:a5f8e04bd02b 1053 * @code
akashvibhute 4:75c5aa56411f 1054 * uint16_t address = 0111;
akashvibhute 2:a5f8e04bd02b 1055 * Serial.println(address,OCT);
akashvibhute 2:a5f8e04bd02b 1056 * @endcode
akashvibhute 2:a5f8e04bd02b 1057 *
akashvibhute 2:a5f8e04bd02b 1058 * Printf can also be used, if enabled, or if using linux/RPi
akashvibhute 2:a5f8e04bd02b 1059 * @code
akashvibhute 2:a5f8e04bd02b 1060 * uint16_t address = 0111;
akashvibhute 2:a5f8e04bd02b 1061 * printf("0%o\n",address);
akashvibhute 2:a5f8e04bd02b 1062 * @endcode
akashvibhute 2:a5f8e04bd02b 1063 *
akashvibhute 2:a5f8e04bd02b 1064 * See http://www.cplusplus.com/doc/hex/ for more information<br>
akashvibhute 4:75c5aa56411f 1065 * See the <a href="Tuning.html"> Topology and Overview</a> page for more info regarding topology.
akashvibhute 2:a5f8e04bd02b 1066 *
akashvibhute 2:a5f8e04bd02b 1067 * @page AdvancedConfig Advanced Configuration
akashvibhute 2:a5f8e04bd02b 1068 *
akashvibhute 2:a5f8e04bd02b 1069 * RF24Network offers many features, some of which can be configured by editing the RF24Network_config.h file
akashvibhute 2:a5f8e04bd02b 1070 *
akashvibhute 2:a5f8e04bd02b 1071 * | Configuration Option | Description |
akashvibhute 2:a5f8e04bd02b 1072 * |----------------------|-------------|
akashvibhute 2:a5f8e04bd02b 1073 * |<b> #define RF24NetworkMulticast </b> | This option allows nodes to send and receive multicast payloads. Nodes with multicast enabled can also be configured to relay multicast payloads on to further multicast levels. See multicastRelay |
akashvibhute 2:a5f8e04bd02b 1074 * | <b> #define DISABLE_FRAGMENTATION </b> | Fragmentation is enabled by default, and uses an additional 144 bytes of memory. |
akashvibhute 2:a5f8e04bd02b 1075 * | <b> #define MAX_PAYLOAD_SIZE 144 </b> | The maximum size of payloads defaults to 144 bytes. If used with RF24toTUN and two Raspberry Pi, set this to 1514 (TAP) or 1500 (TUN) |
akashvibhute 2:a5f8e04bd02b 1076 * | <b> #define NUM_USER_PAYLOADS 5 </b> | This is the number of 24-byte payloads the network layer will cache for the user. If using fragmentation, this number * 24 must be larger than MAX_PAYLOAD_SIZE |
akashvibhute 2:a5f8e04bd02b 1077 * | <b> #define DISABLE_USER_PAYLOADS </b> | This option will disable user-caching of payloads entirely. Use with RF24Ethernet to reduce memory usage. (TCP/IP is an external data type, and not cached) |
akashvibhute 2:a5f8e04bd02b 1078 * | <b> #define ENABLE_SLEEP_MODE </b> | Uncomment this option to enable sleep mode for AVR devices. (ATTiny,Uno, etc) |
akashvibhute 2:a5f8e04bd02b 1079 * | <b> #define DUAL_HEAD_RADIO </b> | Uncomment this option to enable use of dual radios |
akashvibhute 2:a5f8e04bd02b 1080 * | **#define ENABLE_NETWORK_STATS** | Enable counting of all successful or failed transmissions, routed or sent directly |
akashvibhute 2:a5f8e04bd02b 1081 *
akashvibhute 2:a5f8e04bd02b 1082 ** @page Tuning Performance and Data Loss: Tuning the Network
akashvibhute 2:a5f8e04bd02b 1083 * Tips and examples for tuning the network and general operation.
akashvibhute 2:a5f8e04bd02b 1084 *
akashvibhute 2:a5f8e04bd02b 1085 * <img src="tmrh20/topologyImage.jpg" alt="Topology" height="75%" width="75%">
akashvibhute 2:a5f8e04bd02b 1086 *
akashvibhute 2:a5f8e04bd02b 1087 * @section General Understanding Radio Communication and Topology
akashvibhute 2:a5f8e04bd02b 1088 * When a transmission takes place from one radio module to another, the receiving radio will communicate
akashvibhute 2:a5f8e04bd02b 1089 * back to the sender with an acknowledgement (ACK) packet, to indicate success. If the sender does not
akashvibhute 4:75c5aa56411f 1090 * receive an ACK, the radio automatically engages in a series of timed retries, at set intervals. The
akashvibhute 4:75c5aa56411f 1091 * radios use techniques like addressing and numbering of payloads to manage this, but it is all done
akashvibhute 2:a5f8e04bd02b 1092 * automatically by the nrf chip, out of sight from the user.
akashvibhute 2:a5f8e04bd02b 1093 *
akashvibhute 2:a5f8e04bd02b 1094 * When working over a radio network, some of these automated techniques can actually hinder data transmission to a degree.
akashvibhute 4:75c5aa56411f 1095 * Retrying failed payloads over and over on a radio network can hinder communication for nearby nodes, or
akashvibhute 2:a5f8e04bd02b 1096 * reduce throughput and errors on routing nodes.
akashvibhute 2:a5f8e04bd02b 1097 *
akashvibhute 2:a5f8e04bd02b 1098 * Radios in this network are linked by <b>addresses</b> assigned to <b>pipes</b>. Each radio can listen
akashvibhute 2:a5f8e04bd02b 1099 * to 6 addresses on 6 pipes, therefore each radio has a parent pipe and 5 child pipes, which are used
akashvibhute 2:a5f8e04bd02b 1100 * to form a tree structure. Nodes communicate directly with their parent and children nodes. Any other
akashvibhute 2:a5f8e04bd02b 1101 * traffic to or from a node must be routed through the network.
akashvibhute 2:a5f8e04bd02b 1102 *
akashvibhute 2:a5f8e04bd02b 1103 * @section Topology Topology of RF24Network
akashvibhute 2:a5f8e04bd02b 1104 *
akashvibhute 2:a5f8e04bd02b 1105 * Anybody who is familiar at all with IP networking should be able to easily understand RF24Network topology. The
akashvibhute 2:a5f8e04bd02b 1106 * master node can be seen as the gateway, with up to 4 directly connected nodes. Each of those nodes creates a
akashvibhute 2:a5f8e04bd02b 1107 * subnet below it, with up to 4 additional child nodes. The numbering scheme can also be related to IP addresses,
akashvibhute 2:a5f8e04bd02b 1108 * for purposes of understanding the topology via subnetting. Nodes can have 5 children if multicast is disabled.
akashvibhute 2:a5f8e04bd02b 1109 *
akashvibhute 4:75c5aa56411f 1110 * Expressing RF24Network addresses in IP format:
akashvibhute 2:a5f8e04bd02b 1111 *
akashvibhute 4:75c5aa56411f 1112 * As an example, we could designate the master node in theory, as Address 10.10.10.10 <br>
akashvibhute 4:75c5aa56411f 1113 * The children nodes of the master would be 10.10.10.1, 10.10.10.2, 10.10.10.3, 10.10.10.4 and 10.10.10.5 <br>
akashvibhute 4:75c5aa56411f 1114 * The children nodes of 10.10.10.1 would be 10.10.1.1, 10.10.2.1, 10.10.3.1, 10.10.4.1 and 10.10.5.1 <br>
akashvibhute 4:75c5aa56411f 1115 *
akashvibhute 2:a5f8e04bd02b 1116 * In RF24Network, the master is just 00 <br>
akashvibhute 2:a5f8e04bd02b 1117 * Children of master are 01,02,03,04,05 <br>
akashvibhute 2:a5f8e04bd02b 1118 * Children of 01 are 011,021,031,041,051 <br>
akashvibhute 4:75c5aa56411f 1119 *
akashvibhute 2:a5f8e04bd02b 1120 * @section Network Routing
akashvibhute 2:a5f8e04bd02b 1121 *
akashvibhute 2:a5f8e04bd02b 1122 * Routing of traffic is handled invisibly to the user, by the network layer. If the network addresses are
akashvibhute 2:a5f8e04bd02b 1123 * assigned in accordance with the physical layout of the network, nodes will route traffic automatically
akashvibhute 2:a5f8e04bd02b 1124 * as required. Users simply constuct a header containing the appropriate destination address, and the network
akashvibhute 2:a5f8e04bd02b 1125 * will forward it through to the correct node. Individual nodes only route individual fragments, so if using
akashvibhute 2:a5f8e04bd02b 1126 * fragmentation, routing nodes do not need it enabled, unless sending or receiving fragmented payloads themselves.
akashvibhute 2:a5f8e04bd02b 1127 *
akashvibhute 2:a5f8e04bd02b 1128 * If routing data between parent and child nodes (marked by direct links on the topology image above) the network
akashvibhute 2:a5f8e04bd02b 1129 * uses built-in acknowledgement and retry functions of the chip to prevent data loss. When payloads are sent to
akashvibhute 2:a5f8e04bd02b 1130 * other nodes, they need to be routed. Routing is managed using a combination of built in ACK requests, and
akashvibhute 2:a5f8e04bd02b 1131 * software driven network ACKs. This allows all routing nodes to forward data very quickly, with only the final
akashvibhute 2:a5f8e04bd02b 1132 * routing node confirming delivery and sending back an
akashvibhute 2:a5f8e04bd02b 1133 * acknowledgement.
akashvibhute 2:a5f8e04bd02b 1134 *
akashvibhute 2:a5f8e04bd02b 1135 * Example: Node 00 sends to node 01. The nodes will use the built in auto-retry and auto-ack functions.<br>
akashvibhute 2:a5f8e04bd02b 1136 * Example: Node 00 sends to node 011. Node 00 will send to node 01 as before. Node 01 will forward the message to
akashvibhute 2:a5f8e04bd02b 1137 * 011. If delivery was successful, node 01 will also forward a message back to node 00, indicating success.
akashvibhute 2:a5f8e04bd02b 1138 *
akashvibhute 2:a5f8e04bd02b 1139 * Old Functionality: Node 00 sends to node 011 using auto-ack. Node 00 first sends to 01, 01 acknowledges.
akashvibhute 2:a5f8e04bd02b 1140 * Node 01 forwards the payload to 011 using auto-ack. If the payload fails between 01 and 011, node 00 has
akashvibhute 4:75c5aa56411f 1141 * no way of knowing.
akashvibhute 4:75c5aa56411f 1142 *
akashvibhute 2:a5f8e04bd02b 1143 * @note When retrying failed payloads that have been routed, there is a chance of duplicate payloads if the network-ack
akashvibhute 2:a5f8e04bd02b 1144 * is not successful. In this case, it is left up to the user to manage retries and filtering of duplicate payloads.
akashvibhute 2:a5f8e04bd02b 1145 *
akashvibhute 2:a5f8e04bd02b 1146 * Acknowledgements can and should be managed by the application or user. If requesting a response from another node,
akashvibhute 2:a5f8e04bd02b 1147 * an acknowledgement is not required, so a user defined type of 0-64 should be used, to prevent the network from
akashvibhute 2:a5f8e04bd02b 1148 * responding with an acknowledgement. If not requesting a response, and wanting to know if the payload was successful
akashvibhute 2:a5f8e04bd02b 1149 * or not, users can utilize header types 65-127.
akashvibhute 4:75c5aa56411f 1150 *
akashvibhute 2:a5f8e04bd02b 1151 * @section TuningOverview Tuning Overview
akashvibhute 2:a5f8e04bd02b 1152 * The RF24 radio modules are generally only capable of either sending or receiving data at any given
akashvibhute 2:a5f8e04bd02b 1153 * time, but have built-in auto-retry mechanisms to prevent the loss of data. These values are adjusted
akashvibhute 2:a5f8e04bd02b 1154 * automatically by the library on startup, but can be further adjusted to reduce data loss, and
akashvibhute 2:a5f8e04bd02b 1155 * thus increase throughput of the network. This page is intended to provide a general overview of its
akashvibhute 2:a5f8e04bd02b 1156 * operation within the context of the network library, and provide guidance for adjusting these values.
akashvibhute 2:a5f8e04bd02b 1157 *
akashvibhute 2:a5f8e04bd02b 1158 * @section RetryTiming Auto-Retry Timing
akashvibhute 2:a5f8e04bd02b 1159 *
akashvibhute 2:a5f8e04bd02b 1160 * The core radio library provides the functionality of adjusting the internal auto-retry interval of the
akashvibhute 2:a5f8e04bd02b 1161 * radio modules. In the network configuration, the radios can be set to automatically retry failed
akashvibhute 2:a5f8e04bd02b 1162 * transmissions at intervals ranging anywhere from 500us (.5ms) up to 4000us (4ms). When operating any
akashvibhute 2:a5f8e04bd02b 1163 * number of radios larger than two, it is important to stagger the assigned intervals, to prevent the
akashvibhute 2:a5f8e04bd02b 1164 * radios from interfering with each other at the radio frequency (RF) layer.
akashvibhute 2:a5f8e04bd02b 1165 *
akashvibhute 2:a5f8e04bd02b 1166 * The library should provide fairly good working values, as it simply staggers the assigned values within
akashvibhute 2:a5f8e04bd02b 1167 * groups of radios in direct communication. This value can be set manually by calling radio.setRetries(X,15);
akashvibhute 2:a5f8e04bd02b 1168 * and adjusting the value of X from 1 to 15 (steps of 250us).
akashvibhute 2:a5f8e04bd02b 1169 *
akashvibhute 2:a5f8e04bd02b 1170 * @section AutoRetry Auto-Retry Count and Extended Timeouts
akashvibhute 2:a5f8e04bd02b 1171 *
akashvibhute 2:a5f8e04bd02b 1172 * The core radio library also provides the ability to adjust the internal auto-retry count of the radio
akashvibhute 2:a5f8e04bd02b 1173 * modules. The default setting is 15 automatic retries per payload, and can be extended by configuring
akashvibhute 2:a5f8e04bd02b 1174 * the network.txTimeout variable. This default retry count should generally be left at 15, as per the
akashvibhute 2:a5f8e04bd02b 1175 * example in the above section. An interval/retry setting of (15,15) will provide 15 retrys at intervals of
akashvibhute 2:a5f8e04bd02b 1176 * 4ms, taking up to 60ms per payload. The library now provides staggered timeout periods by default, but
akashvibhute 2:a5f8e04bd02b 1177 * they can also be adjusted on a per-node basis.
akashvibhute 0:c3db0798d9aa 1178 *
akashvibhute 2:a5f8e04bd02b 1179 * The txTimeout variable is used to extend the retry count to a defined duration in milliseconds. See the
akashvibhute 2:a5f8e04bd02b 1180 * network.txTimeout variable. Timeout periods of extended duration (500+) will generally not help when payloads
akashvibhute 2:a5f8e04bd02b 1181 * are failing due to data collisions, it will only extend the duration of the errors. Extended duration timeouts
akashvibhute 2:a5f8e04bd02b 1182 * should generally only be configured on leaf nodes that do not receive data, or on a dual-headed node.
akashvibhute 2:a5f8e04bd02b 1183 *
akashvibhute 2:a5f8e04bd02b 1184 * @section Examples
akashvibhute 2:a5f8e04bd02b 1185 *
akashvibhute 2:a5f8e04bd02b 1186 * <b>Example 1:</b> Network with master node and three leaf nodes that send data to the master node. None of the leaf
akashvibhute 2:a5f8e04bd02b 1187 * nodes need to receive data.
akashvibhute 2:a5f8e04bd02b 1188 *
akashvibhute 2:a5f8e04bd02b 1189 * a: Master node uses default configuration<br>
akashvibhute 2:a5f8e04bd02b 1190 * b: Leaf nodes can be configured with extended timeout periods to ensure reception by the master.<br>
akashvibhute 2:a5f8e04bd02b 1191 * c:
akashvibhute 2:a5f8e04bd02b 1192 * @code
akashvibhute 2:a5f8e04bd02b 1193 * Leaf 01: network.txTimeout = 500; Leaf 02: network.txTimeout = 573; Leaf 03: network.txTimeout = 653;
akashvibhute 2:a5f8e04bd02b 1194 * @endcode
akashvibhute 2:a5f8e04bd02b 1195 * This configuration will provide a reduction in errors, as the timeouts have been extended, and are staggered
akashvibhute 2:a5f8e04bd02b 1196 * between devices.
akashvibhute 2:a5f8e04bd02b 1197 *
akashvibhute 2:a5f8e04bd02b 1198 *
akashvibhute 2:a5f8e04bd02b 1199 * <b>Example 2:</b> Network with master node and three leaf nodes that send data to the master node. The second leaf
akashvibhute 2:a5f8e04bd02b 1200 * node needs to receive configuration data from the master at set intervals of 1 second, and send data back to the
akashvibhute 2:a5f8e04bd02b 1201 * master node. The other leaf nodes will send basic sensor information every few seconds, and a few dropped payloads
akashvibhute 2:a5f8e04bd02b 1202 * will not affect the operation greatly.
akashvibhute 2:a5f8e04bd02b 1203 *
akashvibhute 2:a5f8e04bd02b 1204 * a: Master node configured with extended timeouts of .5 seconds, and increased retry delay:
akashvibhute 2:a5f8e04bd02b 1205 * @code
akashvibhute 4:75c5aa56411f 1206 * radio.setRetries(11,15);
akashvibhute 4:75c5aa56411f 1207 * network.txTimeout = 500;
akashvibhute 4:75c5aa56411f 1208 * @endcode
akashvibhute 2:a5f8e04bd02b 1209 * b: Second leaf node configured with a similar timeout period and retry delay:
akashvibhute 2:a5f8e04bd02b 1210 * @code
akashvibhute 4:75c5aa56411f 1211 * radio.setRetries(8,15);
akashvibhute 4:75c5aa56411f 1212 * network.txTimeout = 553;
akashvibhute 2:a5f8e04bd02b 1213 * @endcode
akashvibhute 2:a5f8e04bd02b 1214 * c: First and third leaf nodes configured with default timeout periods or slightly increased timout periods.
akashvibhute 2:a5f8e04bd02b 1215 *
akashvibhute 2:a5f8e04bd02b 1216 * @section DualHead Dual Headed Operation
akashvibhute 2:a5f8e04bd02b 1217 *
akashvibhute 2:a5f8e04bd02b 1218 * The library now supports a dual radio configuration to further enhance network performance, while reducing errors on
akashvibhute 2:a5f8e04bd02b 1219 * busy networks. Master nodes or relay nodes with a large number of child nodes can benefit somewhat from a dual headed
akashvibhute 2:a5f8e04bd02b 1220 * configuration, since one radio is used for receiving, and the other entirely for transmission.
akashvibhute 2:a5f8e04bd02b 1221 *
akashvibhute 2:a5f8e04bd02b 1222 * To configure a dual headed node:
akashvibhute 2:a5f8e04bd02b 1223 * 1. Edit the RF24Network_config.h file, and uncomment #define DUAL_HEAD_RADIO
akashvibhute 2:a5f8e04bd02b 1224 * 2. Connect another radio, using the same MOSI, MISO, and SCK lines.
akashvibhute 2:a5f8e04bd02b 1225 * 3. Choose another two pins to use for CE and CS on the second radio. Connect them.
akashvibhute 2:a5f8e04bd02b 1226 * 4. Setup the radio and network like so:
akashvibhute 2:a5f8e04bd02b 1227 *
akashvibhute 2:a5f8e04bd02b 1228 * @code
akashvibhute 4:75c5aa56411f 1229 * RF24 radio(7,8); // Using CE (7) and CS (8) for first radio
akashvibhute 4:75c5aa56411f 1230 * RF24 radio1(4,5); // Using CE (4) and CS (5) for second radio
akashvibhute 4:75c5aa56411f 1231 * RF24Network network(radio,radio1); // Set up the network using both radios
akashvibhute 2:a5f8e04bd02b 1232 *
akashvibhute 2:a5f8e04bd02b 1233 * Then in setup(), call radio.begin(); and radio1.begin(); before network.begin();
akashvibhute 2:a5f8e04bd02b 1234 * @endcode
akashvibhute 2:a5f8e04bd02b 1235 *
akashvibhute 2:a5f8e04bd02b 1236 * 5. Upload to MCU. The node will now use the first radio to receive data, and radio1 to transmit, preventing data loss on a busy network.
akashvibhute 2:a5f8e04bd02b 1237 * 6. Re-comment the #define in the config file as required if configuring other single-headed radios.
akashvibhute 2:a5f8e04bd02b 1238 *
akashvibhute 2:a5f8e04bd02b 1239 *
akashvibhute 2:a5f8e04bd02b 1240 * Any node can be configured in dual-head mode.
akashvibhute 2:a5f8e04bd02b 1241 *
akashvibhute 2:a5f8e04bd02b 1242 *
akashvibhute 2:a5f8e04bd02b 1243 *
akashvibhute 0:c3db0798d9aa 1244 *
akashvibhute 0:c3db0798d9aa 1245 * @page Zigbee Comparison to ZigBee
akashvibhute 0:c3db0798d9aa 1246 *
akashvibhute 0:c3db0798d9aa 1247 * This network layer is influenced by the design of ZigBee, but does not implement it
akashvibhute 2:a5f8e04bd02b 1248 * directly.
akashvibhute 0:c3db0798d9aa 1249 *
akashvibhute 0:c3db0798d9aa 1250 * @section Advantage Which is better?
akashvibhute 0:c3db0798d9aa 1251 *
akashvibhute 0:c3db0798d9aa 1252 * ZigBee is a much more robust, feature-rich set of protocols, with many different vendors
akashvibhute 0:c3db0798d9aa 1253 * providing compatible chips.
akashvibhute 0:c3db0798d9aa 1254 *
akashvibhute 0:c3db0798d9aa 1255 * RF24Network is cheap. While ZigBee radios are well over $20, nRF24L01 modules can be found
akashvibhute 2:a5f8e04bd02b 1256 * for under $2. My personal favorite is
akashvibhute 0:c3db0798d9aa 1257 * <a href="http://www.mdfly.com/index.php?main_page=product_info&products_id=82">MDFly RF-IS2401</a>.
akashvibhute 0:c3db0798d9aa 1258 *
akashvibhute 0:c3db0798d9aa 1259 * @section Contrast Similiarities & Differences
akashvibhute 0:c3db0798d9aa 1260 *
akashvibhute 0:c3db0798d9aa 1261 * Here are some comparisons between RF24Network and ZigBee.
akashvibhute 0:c3db0798d9aa 1262 *
akashvibhute 0:c3db0798d9aa 1263 * @li Both networks support Star and Tree topologies. Only Zigbee supports a true mesh.
akashvibhute 2:a5f8e04bd02b 1264 * @li In ZigBee networks, only leaf nodes can sleep
akashvibhute 2:a5f8e04bd02b 1265 * @li ZigBee nodes are configured using AT commands, or a separate Windows application.
akashvibhute 0:c3db0798d9aa 1266 * RF24 nodes are configured by recompiliing the firmware or writing to EEPROM.
akashvibhute 0:c3db0798d9aa 1267 *
akashvibhute 0:c3db0798d9aa 1268 * @section NodeNames Node Naming
akashvibhute 0:c3db0798d9aa 1269 *
akashvibhute 0:c3db0798d9aa 1270 * @li Leaf node: A node at the outer edge of the network with no children. ZigBee calls it
akashvibhute 0:c3db0798d9aa 1271 * an End Device node.
akashvibhute 0:c3db0798d9aa 1272 * @li Relay node: A node which has both parents and children, and relays messages from one
akashvibhute 0:c3db0798d9aa 1273 * to the other. ZigBee calls it a Router.
akashvibhute 0:c3db0798d9aa 1274 * @li Base node. The top of the tree node with no parents, only children. Typically this node
akashvibhute 0:c3db0798d9aa 1275 * will bridge to another kind of network like Ethernet. ZigBee calls it a Co-ordinator node.
akashvibhute 2:a5f8e04bd02b 1276 *
akashvibhute 4:75c5aa56411f 1277 *
akashvibhute 2:a5f8e04bd02b 1278 *
akashvibhute 2:a5f8e04bd02b 1279 *
akashvibhute 0:c3db0798d9aa 1280 */
akashvibhute 0:c3db0798d9aa 1281
akashvibhute 0:c3db0798d9aa 1282 #endif // __RF24NETWORK_H__
akashvibhute 2:a5f8e04bd02b 1283
akashvibhute 4:75c5aa56411f 1284
akashvibhute 4:75c5aa56411f 1285