Library for HopeRF RFM22 / RFM22B transceiver module ported to mbed. Original Software from Mike McCauley (mikem@open.com.au) . See http://www.open.com.au/mikem/arduino/RF22/

Dependents:   RF22_MAX_test_Send Geofence_receiver Geofence_sender Geofence_sender ... more

More Info about RFM22-modules like connecting and a demo-program see RF22-Notebook

Committer:
charly
Date:
Mon Sep 02 20:32:54 2013 +0000
Revision:
9:4002a2c117cc
Parent:
5:0386600f3408
removed DEBUG-LEDs LED1 .. LED4 as they make problems on other platforms (KL25Z)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
charly 0:79c6d0071c4c 1 // RF22Router.h
charly 0:79c6d0071c4c 2 //
charly 0:79c6d0071c4c 3 // Author: Mike McCauley (mikem@open.com.au)
charly 0:79c6d0071c4c 4 // Copyright (C) 2011 Mike McCauley
charly 5:0386600f3408 5 // $Id: RF22Router.h,v 1.8 2012/05/30 01:51:25 mikem Exp $
charly 0:79c6d0071c4c 6 // ported to mbed by Karl Zweimueller
charly 0:79c6d0071c4c 7
charly 0:79c6d0071c4c 8 #ifndef RF22Router_h
charly 0:79c6d0071c4c 9 #define RF22Router_h
charly 0:79c6d0071c4c 10
charly 0:79c6d0071c4c 11 #include <RF22ReliableDatagram.h>
charly 0:79c6d0071c4c 12
charly 0:79c6d0071c4c 13 // Default max number of hops we will route
charly 0:79c6d0071c4c 14 #define RF22_DEFAULT_MAX_HOPS 30
charly 0:79c6d0071c4c 15
charly 0:79c6d0071c4c 16 // The default size of the routing table we keep
charly 0:79c6d0071c4c 17 #define RF22_ROUTING_TABLE_SIZE 10
charly 0:79c6d0071c4c 18
charly 0:79c6d0071c4c 19 // Error codes
charly 0:79c6d0071c4c 20 #define RF22_ROUTER_ERROR_NONE 0
charly 0:79c6d0071c4c 21 #define RF22_ROUTER_ERROR_INVALID_LENGTH 1
charly 0:79c6d0071c4c 22 #define RF22_ROUTER_ERROR_NO_ROUTE 2
charly 0:79c6d0071c4c 23 #define RF22_ROUTER_ERROR_TIMEOUT 3
charly 0:79c6d0071c4c 24 #define RF22_ROUTER_ERROR_NO_REPLY 4
charly 0:79c6d0071c4c 25 #define RF22_ROUTER_ERROR_UNABLE_TO_DELIVER 5
charly 0:79c6d0071c4c 26
charly 0:79c6d0071c4c 27 // This size of RF22_ROUTER_MAX_MESSAGE_LEN is OK for Arduino Mega, but too big for
charly 0:79c6d0071c4c 28 // Duemilanova. Size of 50 works with the sample router programs on Duemilanova.
charly 0:79c6d0071c4c 29 #define RF22_ROUTER_MAX_MESSAGE_LEN (RF22_MAX_MESSAGE_LEN - sizeof(RF22Router::RoutedMessageHeader))
charly 0:79c6d0071c4c 30 //#define RF22_ROUTER_MAX_MESSAGE_LEN 50
charly 0:79c6d0071c4c 31
charly 0:79c6d0071c4c 32 // These allow us to define a simulated network topology for testing purposes
charly 0:79c6d0071c4c 33 // See RF22Router.cpp for details
charly 0:79c6d0071c4c 34 //#define RF22_TEST_NETWORK 1
charly 0:79c6d0071c4c 35 //#define RF22_TEST_NETWORK 2
charly 0:79c6d0071c4c 36 //#define RF22_TEST_NETWORK 3
charly 0:79c6d0071c4c 37 //#define RF22_TEST_NETWORK 4
charly 0:79c6d0071c4c 38
charly 0:79c6d0071c4c 39 /////////////////////////////////////////////////////////////////////
charly 0:79c6d0071c4c 40 /// \class RF22Router RF22Router.h <RF22Router.h>
charly 0:79c6d0071c4c 41 /// \brief RF22 subclass for sending addressed, optionally acknowledged datagrams
charly 0:79c6d0071c4c 42 /// multi-hop routed across a network.
charly 0:79c6d0071c4c 43 ///
charly 0:79c6d0071c4c 44 /// Extends RF22ReliableDatagram to define addressed messages
charly 0:79c6d0071c4c 45 /// That are reliably transmitted and routed across a network. Each message is transmitted reliably
charly 0:79c6d0071c4c 46 /// between each hop in order to get from the source node to the destination node.
charly 0:79c6d0071c4c 47 ///
charly 0:79c6d0071c4c 48 /// With RF22Router, routes are hard wired. This means that each node must have programmed
charly 0:79c6d0071c4c 49 /// in it how to reach each of the other nodes it will be trying to communicate with.
charly 0:79c6d0071c4c 50 /// This means you must specify the next-hop node address for each of the destination nodes,
charly 0:79c6d0071c4c 51 /// using the addRouteTo() function.
charly 0:79c6d0071c4c 52 ///
charly 0:79c6d0071c4c 53 /// When sendtoWait() is called with a new message to deliver, and the destination address,
charly 0:79c6d0071c4c 54 /// RF22Router looks up the next hop node for the destination node. It then uses
charly 0:79c6d0071c4c 55 /// RF22ReliableDatagram to (reliably) deliver the message to the next hop
charly 0:79c6d0071c4c 56 /// (which is expected also to be running an RF22Router). If that next-hop node is not
charly 0:79c6d0071c4c 57 /// the final destination, it will also look up the next hop for the destination node and
charly 0:79c6d0071c4c 58 /// (reliably) deliver the message to the next hop. By this method, messages can be delivered
charly 0:79c6d0071c4c 59 /// across a network of nodes, even if each node cannot hear all of the others in the network.
charly 0:79c6d0071c4c 60 /// Each time a message is received for another node and retransmitted to the next hop,
charly 0:79c6d0071c4c 61 /// the HOPS filed in teh header is incremented. If a message is received for routing to another node
charly 0:79c6d0071c4c 62 /// which has exceed the routers max_hops, the message wioll be dropped and ignored.
charly 0:79c6d0071c4c 63 /// This helps prevent infinite routing loops.
charly 0:79c6d0071c4c 64 ///
charly 0:79c6d0071c4c 65 /// RF22Router supports messages with a dest of RF22_BROADCAST_ADDRESS. Such messages are not routed,
charly 0:79c6d0071c4c 66 /// and are broadcast (once) to all nodes within range.
charly 0:79c6d0071c4c 67 ///
charly 0:79c6d0071c4c 68 /// The recvfromAck() function is responsible not just for receiving and delivering
charly 0:79c6d0071c4c 69 /// messages addressed to this node (or RF22_BROADCAST_ADDRESS), but
charly 0:79c6d0071c4c 70 /// it is also responsible for routing other message to their next hop. This means that it is important to
charly 0:79c6d0071c4c 71 /// call recvfromAck() or recvfromAckTimeout() frequently in your main loop. recvfromAck() will return
charly 0:79c6d0071c4c 72 /// false if it receives a message but it is not for this node.
charly 0:79c6d0071c4c 73 ///
charly 0:79c6d0071c4c 74 /// RF22Router does not provide reliable end-to-end delivery, but uses reliable hop-to-hop delivery.
charly 0:79c6d0071c4c 75 /// If a message is unable to be delivered to an end node during to a delivery failure between 2 hops,
charly 0:79c6d0071c4c 76 /// the source node will not be told about it.
charly 0:79c6d0071c4c 77 ///
charly 0:79c6d0071c4c 78 /// Note: This class is most useful for networks of nodes that are essentially static
charly 0:79c6d0071c4c 79 /// (i.e. the nodes dont move around), and for which the
charly 0:79c6d0071c4c 80 /// routing never changes. If that is not the case for your proposed network, see RF22Mesh instead.
charly 0:79c6d0071c4c 81 ///
charly 0:79c6d0071c4c 82 /// \par The Routing Table
charly 0:79c6d0071c4c 83 ///
charly 0:79c6d0071c4c 84 /// The routing table is a local table in RF22Router that holds the information about the next hop node
charly 0:79c6d0071c4c 85 /// address for each destination address you may want to send a message to. It is your responsibility
charly 0:79c6d0071c4c 86 /// to make sure every node in an RF22Router network has been configured with a unique address and the
charly 0:79c6d0071c4c 87 /// routing information so that messages are correctly routed across the network from source node to
charly 0:79c6d0071c4c 88 /// destination node. This is usually done once in setup() by calling addRouteTo().
charly 0:79c6d0071c4c 89 /// The hardwired routing will in general be different on each node, and will depend on the physical
charly 0:79c6d0071c4c 90 /// topololgy of the network.
charly 0:79c6d0071c4c 91 /// You can also use addRouteTo() to change a route and
charly 0:79c6d0071c4c 92 /// deleteRouteTo() to delete a route at run time. Youcan also clear the entire routing table
charly 0:79c6d0071c4c 93 ///
charly 0:79c6d0071c4c 94 /// The Routing Table has limited capacity for entries (defined by RF22_ROUTING_TABLE_SIZE, which is 10)
charly 0:79c6d0071c4c 95 /// if more than RF22_ROUTING_TABLE_SIZE are added, the oldest (first) one will be removed by calling
charly 0:79c6d0071c4c 96 /// retireOldestRoute()
charly 0:79c6d0071c4c 97 ///
charly 0:79c6d0071c4c 98 /// \par Message Format
charly 0:79c6d0071c4c 99 ///
charly 0:79c6d0071c4c 100 /// RF22Router add to the lower level RF22ReliableDatagram (and even lower level RF22) class mesage formats.
charly 0:79c6d0071c4c 101 /// In those lower level classes, the hop-to-hop message headers are in the RF22 message headers,
charly 0:79c6d0071c4c 102 /// and are handled automcatically by tyhe RF22 hardware.
charly 0:79c6d0071c4c 103 /// RF22Router and its subclasses add an end-to-end addressing header in the payload of the RF22 message,
charly 0:79c6d0071c4c 104 /// and before the RF22Router application data.
charly 0:79c6d0071c4c 105 /// - 1 octet DEST, the destination node address (ie the address of the final
charly 0:79c6d0071c4c 106 /// destination node for this message)
charly 0:79c6d0071c4c 107 /// - 1 octet SOURCE, the source node address (ie the address of the originating node that first sent
charly 0:79c6d0071c4c 108 /// the message).
charly 0:79c6d0071c4c 109 /// - 1 octet HOPS, the number of hops this message has traversed so far.
charly 0:79c6d0071c4c 110 /// - 1 octet ID, an incrementing message ID for end-to-end message tracking for use by subclasses.
charly 0:79c6d0071c4c 111 /// Not used by RF22Router.
charly 0:79c6d0071c4c 112 /// - 1 octet FLAGS, a bitmask for use by subclasses. Not used by RF22Router.
charly 0:79c6d0071c4c 113 /// - 0 or more octets DATA, the application payload data. The length of this data is implicit
charly 0:79c6d0071c4c 114 /// in the length of the entire message.
charly 0:79c6d0071c4c 115 ///
charly 0:79c6d0071c4c 116 /// You should be careful to note that there are ID and FLAGS fields in the low level per-hop
charly 0:79c6d0071c4c 117 /// message header too. These are used only for hop-to-hop, and in general will be different to
charly 0:79c6d0071c4c 118 /// the ones at the RF22Router level.
charly 0:79c6d0071c4c 119 ///
charly 0:79c6d0071c4c 120 /// \par Testing
charly 0:79c6d0071c4c 121 ///
charly 0:79c6d0071c4c 122 /// Bench testing of such networks is notoriously difficult, especially simulating limited radio
charly 0:79c6d0071c4c 123 /// connectivity between some nodes.
charly 0:79c6d0071c4c 124 /// To assist testing (both during RF22 development and for your own networks)
charly 0:79c6d0071c4c 125 /// RF22Router.cpp has the ability to
charly 0:79c6d0071c4c 126 /// simulate a number of different small network topologies. Each simulated network supports 4 nodes with
charly 0:79c6d0071c4c 127 /// addresses 1 to 4. It operates by pretending to not hear RF22 messages from certain other nodes.
charly 0:79c6d0071c4c 128 /// You can enable testing with a \#define TEST_NETWORK in RF22Router.h
charly 0:79c6d0071c4c 129 /// The sample programs rf22_mesh_* rely on this feature.
charly 0:79c6d0071c4c 130 ///
charly 0:79c6d0071c4c 131 /// Part of the Arduino RF22 library for operating with HopeRF RF22 compatible transceivers
charly 0:79c6d0071c4c 132 /// (see http://www.hoperf.com)
charly 0:79c6d0071c4c 133 class RF22Router : public RF22ReliableDatagram
charly 0:79c6d0071c4c 134 {
charly 0:79c6d0071c4c 135 public:
charly 0:79c6d0071c4c 136
charly 0:79c6d0071c4c 137 /// Defines the structure of the RF22Router message header, used to keep track of end-to-end delivery
charly 0:79c6d0071c4c 138 /// parameters
charly 0:79c6d0071c4c 139 typedef struct
charly 0:79c6d0071c4c 140 {
charly 0:79c6d0071c4c 141 uint8_t dest; ///< Destination node address
charly 0:79c6d0071c4c 142 uint8_t source; ///< Originator node address
charly 0:79c6d0071c4c 143 uint8_t hops; ///< Hops traversed so far
charly 0:79c6d0071c4c 144 uint8_t id; ///< Originator sequence number
charly 0:79c6d0071c4c 145 uint8_t flags; ///< Originator flags
charly 0:79c6d0071c4c 146 // Data follows, Length is implicit in the overall message length
charly 0:79c6d0071c4c 147 } RoutedMessageHeader;
charly 0:79c6d0071c4c 148
charly 0:79c6d0071c4c 149 /// Defines the structure of a RF22Router message
charly 0:79c6d0071c4c 150 typedef struct
charly 0:79c6d0071c4c 151 {
charly 0:79c6d0071c4c 152 RoutedMessageHeader header; ///< end-to-end delivery header
charly 0:79c6d0071c4c 153 uint8_t data[RF22_ROUTER_MAX_MESSAGE_LEN]; ///< Applicaiton payload data
charly 0:79c6d0071c4c 154 } RoutedMessage;
charly 0:79c6d0071c4c 155
charly 0:79c6d0071c4c 156 /// Values for the possible states for routes
charly 0:79c6d0071c4c 157 typedef enum
charly 0:79c6d0071c4c 158 {
charly 0:79c6d0071c4c 159 Invalid = 0, ///< No valid route is known
charly 0:79c6d0071c4c 160 Discovering, ///< Discovering a route (not currently used)
charly 0:79c6d0071c4c 161 Valid ///< Route is valid
charly 0:79c6d0071c4c 162 } RouteState;
charly 0:79c6d0071c4c 163
charly 0:79c6d0071c4c 164 /// Defines an entry in the routing table
charly 0:79c6d0071c4c 165 typedef struct
charly 0:79c6d0071c4c 166 {
charly 0:79c6d0071c4c 167 uint8_t dest; ///< Destination node address
charly 0:79c6d0071c4c 168 uint8_t next_hop; ///< Send via this next hop address
charly 0:79c6d0071c4c 169 uint8_t state; ///< State of this route, one of RouteState
charly 0:79c6d0071c4c 170 } RoutingTableEntry;
charly 0:79c6d0071c4c 171
charly 0:79c6d0071c4c 172 /// Constructor.
charly 0:79c6d0071c4c 173 /// \param[in] thisAddress The address to assign to this node. Defaults to 0
charly 0:79c6d0071c4c 174 /// \param[in] slaveSelectPin the Arduino pin number of the output to use to select the RF22 before
charly 5:0386600f3408 175 /// accessing it. Defaults to the normal SS pin for your Arduino (D10 for Diecimila, Uno etc, D53 for Mega)
charly 0:79c6d0071c4c 176 /// \param[in] interrupt The interrupt number to use. Default is interrupt 0 (Arduino input pin 2)
charly 0:79c6d0071c4c 177 //RF22Router(uint8_t thisAddress = 0, uint8_t slaveSelectPin = 10, uint8_t interrupt = 0);
charly 0:79c6d0071c4c 178 RF22Router(uint8_t thisAddress ,PinName slaveSelectPin , PinName mosi, PinName miso, PinName sclk, PinName interrupt );
charly 0:79c6d0071c4c 179 /// Initialises this instance and the radio module connected to it.
charly 0:79c6d0071c4c 180 /// Overrides the init() function in RF22.
charly 0:79c6d0071c4c 181 /// Sets max_hops to the default of RF22_DEFAULT_MAX_HOPS (30)
charly 0:79c6d0071c4c 182 boolean init();
charly 0:79c6d0071c4c 183
charly 0:79c6d0071c4c 184 /// Sets the max_hops to the given value
charly 0:79c6d0071c4c 185 /// This controls the maximum number of hops allowed between source and destination nodes
charly 0:79c6d0071c4c 186 /// Messages that are not delivered by the time their HOPS field exceeds max_hops on a
charly 0:79c6d0071c4c 187 /// routing node will be dropped and ignored.
charly 0:79c6d0071c4c 188 /// \param [in] max_hops The new value for max_hops
charly 0:79c6d0071c4c 189 void setMaxHops(uint8_t max_hops);
charly 0:79c6d0071c4c 190
charly 0:79c6d0071c4c 191 /// Adds a route to the local routing table, or updates it if already present.
charly 0:79c6d0071c4c 192 /// If there is not enough room the oldest (first) route will be deleted by calling retireOldestRoute().
charly 0:79c6d0071c4c 193 /// \param [in] dest The destination node address. RF22_BROADCAST_ADDRESS is permitted.
charly 0:79c6d0071c4c 194 /// \param [in] next_hop The address of the next hop to send messages destined for dest
charly 0:79c6d0071c4c 195 /// \param [in] state The satte of the route. Defaults to Valid
charly 0:79c6d0071c4c 196 void addRouteTo(uint8_t dest, uint8_t next_hop, uint8_t state = Valid);
charly 0:79c6d0071c4c 197
charly 0:79c6d0071c4c 198 /// Finds and returns a RoutingTableEntry for the given destination node
charly 0:79c6d0071c4c 199 /// \param [in] dest The desired destination node address.
charly 0:79c6d0071c4c 200 /// \return pointer to a RoutingTableEntry for dest
charly 0:79c6d0071c4c 201 RoutingTableEntry* getRouteTo(uint8_t dest);
charly 0:79c6d0071c4c 202
charly 0:79c6d0071c4c 203 /// Deletes from the local routing table any route for the destination node.
charly 0:79c6d0071c4c 204 /// \param [in] dest The destination node address
charly 0:79c6d0071c4c 205 /// \return true if the route was present
charly 0:79c6d0071c4c 206 boolean deleteRouteTo(uint8_t dest);
charly 0:79c6d0071c4c 207
charly 0:79c6d0071c4c 208 /// Deletes the oldest (first) route from the
charly 0:79c6d0071c4c 209 /// local routing table
charly 0:79c6d0071c4c 210 void retireOldestRoute();
charly 0:79c6d0071c4c 211
charly 0:79c6d0071c4c 212 /// Clears all entries from the
charly 0:79c6d0071c4c 213 /// local routing table
charly 0:79c6d0071c4c 214 void clearRoutingTable();
charly 0:79c6d0071c4c 215
charly 0:79c6d0071c4c 216 /// If RF22_HAVE_SERIAL is defined, this will print out the contents of the local
charly 0:79c6d0071c4c 217 /// routing table using Serial
charly 0:79c6d0071c4c 218 void printRoutingTable();
charly 0:79c6d0071c4c 219
charly 0:79c6d0071c4c 220 /// Sends a message to the destination node. Initialises the RF22Router message header
charly 0:79c6d0071c4c 221 /// (the SOURCE address is set to the address of this node, HOPS to 0) and calls
charly 0:79c6d0071c4c 222 /// route() which looks up in the routing table the next hop to deliver to and sends the
charly 0:79c6d0071c4c 223 /// message to the next hop. Waits for an acknowledgement from the next hop
charly 0:79c6d0071c4c 224 /// (but not from the destination node (if that is different).
charly 0:79c6d0071c4c 225 /// \param [in] buf The application message data
charly 0:79c6d0071c4c 226 /// \param [in] len Number of octets in the application message data. 0 is permitted
charly 0:79c6d0071c4c 227 /// \param [in] dest The destination node address
charly 0:79c6d0071c4c 228 /// \return The result code:
charly 0:79c6d0071c4c 229 /// - RF22_ROUTER_ERROR_NONE Message was routed and deliverd to the next hop
charly 0:79c6d0071c4c 230 /// (not necessarily to the final dest address)
charly 0:79c6d0071c4c 231 /// - RF22_ROUTER_ERROR_NO_ROUTE There was no route for dest in the local routing table
charly 0:79c6d0071c4c 232 /// - RF22_ROUTER_ERROR_UNABLE_TO_DELIVER Noyt able to deliver to the next hop
charly 0:79c6d0071c4c 233 /// (usually because it dod not acknowledge due to being off the air or out of range
charly 0:79c6d0071c4c 234 uint8_t sendtoWait(uint8_t* buf, uint8_t len, uint8_t dest);
charly 0:79c6d0071c4c 235
charly 0:79c6d0071c4c 236 /// Similar to sendtoWait() above, but spoofs the source address.
charly 0:79c6d0071c4c 237 /// For internal use only during routing
charly 0:79c6d0071c4c 238 /// \param [in] buf The application message data
charly 0:79c6d0071c4c 239 /// \param [in] len Number of octets in the application message data. 0 is permitted
charly 0:79c6d0071c4c 240 /// \param [in] dest The destination node address
charly 0:79c6d0071c4c 241 /// \param [in] source The (fake) originatong node address.
charly 0:79c6d0071c4c 242 /// \return The result code:
charly 0:79c6d0071c4c 243 /// - RF22_ROUTER_ERROR_NONE Message was routed and deliverd to the next hop
charly 0:79c6d0071c4c 244 /// (not necessarily to the final dest address)
charly 0:79c6d0071c4c 245 /// - RF22_ROUTER_ERROR_NO_ROUTE There was no route for dest in the local routing table
charly 0:79c6d0071c4c 246 /// - RF22_ROUTER_ERROR_UNABLE_TO_DELIVER Noyt able to deliver to the next hop
charly 0:79c6d0071c4c 247 /// (usually because it dod not acknowledge due to being off the air or out of range
charly 0:79c6d0071c4c 248 uint8_t sendtoWait(uint8_t* buf, uint8_t len, uint8_t dest, uint8_t source);
charly 0:79c6d0071c4c 249
charly 0:79c6d0071c4c 250 /// Starts the receiver if it is not running already.
charly 0:79c6d0071c4c 251 /// If there is a valid message available for this node (or RF22_BROADCAST_ADDRESS),
charly 0:79c6d0071c4c 252 /// send an acknowledgement to the last hop
charly 0:79c6d0071c4c 253 /// address (blocking until this is complete), then copy the application message payload data
charly 0:79c6d0071c4c 254 /// to buf and return true
charly 0:79c6d0071c4c 255 /// else return false.
charly 0:79c6d0071c4c 256 /// If a message is copied, *len is set to the length..
charly 0:79c6d0071c4c 257 /// If from is not NULL, the originator SOURCE address is placed in *source.
charly 0:79c6d0071c4c 258 /// If to is not NULL, the DEST address is placed in *dest. This might be this nodes address or
charly 0:79c6d0071c4c 259 /// RF22_BROADCAST_ADDRESS.
charly 0:79c6d0071c4c 260 /// This is the preferred function for getting messages addressed to this node.
charly 0:79c6d0071c4c 261 /// If the message is not a broadcast, acknowledge to the sender before returning.
charly 0:79c6d0071c4c 262 /// \param[in] buf Location to copy the received message
charly 0:79c6d0071c4c 263 /// \param[in,out] len Available space in buf. Set to the actual number of octets copied.
charly 0:79c6d0071c4c 264 /// \param[in] source If present and not NULL, the referenced uint8_t will be set to the SOURCE address
charly 0:79c6d0071c4c 265 /// \param[in] dest If present and not NULL, the referenced uint8_t will be set to the DEST address
charly 0:79c6d0071c4c 266 /// \param[in] id If present and not NULL, the referenced uint8_t will be set to the ID
charly 0:79c6d0071c4c 267 /// \param[in] flags If present and not NULL, the referenced uint8_t will be set to the FLAGS
charly 0:79c6d0071c4c 268 /// (not just those addressed to this node).
charly 0:79c6d0071c4c 269 /// \return true if a valid message was recvived for this node copied to buf
charly 0:79c6d0071c4c 270 boolean recvfromAck(uint8_t* buf, uint8_t* len, uint8_t* source = NULL, uint8_t* dest = NULL, uint8_t* id = NULL, uint8_t* flags = NULL);
charly 0:79c6d0071c4c 271
charly 0:79c6d0071c4c 272 /// Starts the receiver if it is not running already.
charly 0:79c6d0071c4c 273 /// Similar to recvfromAck(), this will block until either a valid message available for this node
charly 0:79c6d0071c4c 274 /// or the timeout expires.
charly 0:79c6d0071c4c 275 /// \param[in] buf Location to copy the received message
charly 0:79c6d0071c4c 276 /// \param[in,out] len Available space in buf. Set to the actual number of octets copied.
charly 0:79c6d0071c4c 277 /// \param[in] timeout Maximum time to wait in milliseconds
charly 0:79c6d0071c4c 278 /// \param[in] source If present and not NULL, the referenced uint8_t will be set to the SOURCE address
charly 0:79c6d0071c4c 279 /// \param[in] dest If present and not NULL, the referenced uint8_t will be set to the DEST address
charly 0:79c6d0071c4c 280 /// \param[in] id If present and not NULL, the referenced uint8_t will be set to the ID
charly 0:79c6d0071c4c 281 /// \param[in] flags If present and not NULL, the referenced uint8_t will be set to the FLAGS
charly 0:79c6d0071c4c 282 /// (not just those addressed to this node).
charly 0:79c6d0071c4c 283 /// \return true if a valid message was copied to buf
charly 0:79c6d0071c4c 284 boolean recvfromAckTimeout(uint8_t* buf, uint8_t* len, uint16_t timeout, uint8_t* source = NULL, uint8_t* dest = NULL, uint8_t* id = NULL, uint8_t* flags = NULL);
charly 0:79c6d0071c4c 285
charly 0:79c6d0071c4c 286 protected:
charly 0:79c6d0071c4c 287
charly 0:79c6d0071c4c 288 /// Lets sublasses peek at messages going
charly 0:79c6d0071c4c 289 /// past before routing or local delivery.
charly 0:79c6d0071c4c 290 /// Called by recvfromAck() immediately after it gets the message from RF22ReliableDatagram
charly 0:79c6d0071c4c 291 /// \param [in] message Pointer to the RF22Router message that was received.
charly 0:79c6d0071c4c 292 /// \param [in] messageLen Length of message in octets
charly 0:79c6d0071c4c 293 virtual void peekAtMessage(RoutedMessage* message, uint8_t messageLen);
charly 0:79c6d0071c4c 294
charly 0:79c6d0071c4c 295 /// Finds the next-hop route and sends the message via RF22ReliableDatagram::sendtoWait().
charly 0:79c6d0071c4c 296 /// This is virtual, which lets subclasses override or intercept the route() function.
charly 0:79c6d0071c4c 297 /// Called by sendtoWait after the message header has been filled in.
charly 0:79c6d0071c4c 298 /// \param [in] message Pointer to the RF22Router message to be sent.
charly 0:79c6d0071c4c 299 /// \param [in] messageLen Length of message in octets
charly 0:79c6d0071c4c 300 virtual uint8_t route(RoutedMessage* message, uint8_t messageLen);
charly 0:79c6d0071c4c 301
charly 0:79c6d0071c4c 302 /// Deletes a specific rout entry from therouting table
charly 0:79c6d0071c4c 303 /// \param [in] index The 0 based index of the routing table entry to delete
charly 0:79c6d0071c4c 304 void deleteRoute(uint8_t index);
charly 0:79c6d0071c4c 305
charly 0:79c6d0071c4c 306 /// The last end-to-end sequence number to be used
charly 0:79c6d0071c4c 307 /// Defaults to 0
charly 0:79c6d0071c4c 308 uint8_t _lastE2ESequenceNumber;
charly 0:79c6d0071c4c 309
charly 0:79c6d0071c4c 310 /// The maximum number of hops permitted in routed messages.
charly 0:79c6d0071c4c 311 /// If a routed message would exceed this number of hops it is dropped and ignored.
charly 0:79c6d0071c4c 312 uint8_t _max_hops;
charly 0:79c6d0071c4c 313
charly 0:79c6d0071c4c 314 private:
charly 0:79c6d0071c4c 315
charly 0:79c6d0071c4c 316 /// Temporary mesage buffer
charly 0:79c6d0071c4c 317 static RoutedMessage _tmpMessage;
charly 0:79c6d0071c4c 318
charly 0:79c6d0071c4c 319 /// Local routing table
charly 0:79c6d0071c4c 320 RoutingTableEntry _routes[RF22_ROUTING_TABLE_SIZE];
charly 0:79c6d0071c4c 321 };
charly 0:79c6d0071c4c 322
charly 0:79c6d0071c4c 323 #endif