Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
RHMesh Class Reference
RHRouter subclass for sending addressed, optionally acknowledged datagrams multi-hop routed across a network, with automatic route discovery. More...
#include <RHMesh.h>
Inherits RHRouter.
Data Structures | |
struct | MeshApplicationMessage |
Signals an application layer message for the caller of RHMesh. More... | |
struct | MeshMessageHeader |
Structure of the basic RHMesh header. More... | |
struct | MeshRouteDiscoveryMessage |
Signals a route discovery request or reply (At present only supports physical dest addresses of length 1 octet) More... | |
struct | MeshRouteFailureMessage |
Signals a route failure. More... | |
Public Types | |
enum | RouteState { Invalid = 0, Discovering, Valid } |
Values for the possible states for routes. More... | |
Public Member Functions | |
RHMesh (RHGenericDriver &driver, uint8_t thisAddress=0) | |
Constructor. | |
uint8_t | sendtoWait (uint8_t *buf, uint8_t len, uint8_t dest, uint8_t flags=0) |
Sends a message to the destination node. | |
bool | recvfromAck (uint8_t *buf, uint8_t *len, uint8_t *source=NULL, uint8_t *dest=NULL, uint8_t *id=NULL, uint8_t *flags=NULL) |
Starts the receiver if it is not running already, processes and possibly routes any received messages addressed to other nodes and delivers any messages addressed to this node. | |
bool | 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) |
Starts the receiver if it is not running already. | |
bool | init () |
Initialises this instance and the radio module connected to it. | |
void | setMaxHops (uint8_t max_hops) |
Sets the max_hops to the given value This controls the maximum number of hops allowed between source and destination nodes Messages that are not delivered by the time their HOPS field exceeds max_hops on a routing node will be dropped and ignored. | |
void | addRouteTo (uint8_t dest, uint8_t next_hop, uint8_t state=Valid) |
Adds a route to the local routing table, or updates it if already present. | |
RoutingTableEntry * | getRouteTo (uint8_t dest) |
Finds and returns a RoutingTableEntry for the given destination node. | |
bool | deleteRouteTo (uint8_t dest) |
Deletes from the local routing table any route for the destination node. | |
void | retireOldestRoute () |
Deletes the oldest (first) route from the local routing table. | |
void | clearRoutingTable () |
Clears all entries from the local routing table. | |
void | printRoutingTable () |
If RH_HAVE_SERIAL is defined, this will print out the contents of the local routing table using Serial. | |
bool | sendtoWait (uint8_t *buf, uint8_t len, uint8_t address) |
Send the message (with retries) and waits for an ack. | |
uint8_t | sendtoFromSourceWait (uint8_t *buf, uint8_t len, uint8_t dest, uint8_t source, uint8_t flags=0) |
Similar to sendtoWait() above, but spoofs the source address. | |
void | setTimeout (uint16_t timeout) |
Sets the minimum retransmit timeout. | |
void | setRetries (uint8_t retries) |
Sets the maximum number of retries. | |
uint8_t | retries () |
Returns the currently configured maximum retries count. | |
uint32_t | retransmissions () |
Returns the number of retransmissions we have had to send since starting or since the last call to resetRetransmissions(). | |
void | resetRetransmissions () |
Resets the count of the number of retransmissions to 0. | |
void | setThisAddress (uint8_t thisAddress) |
Sets the address of this node. | |
bool | sendto (uint8_t *buf, uint8_t len, uint8_t address) |
Sends a message to the node(s) with the given address RH_BROADCAST_ADDRESS is a valid address which will cause the message to be accepted by all RHDatagram nodes within range. | |
bool | recvfrom (uint8_t *buf, uint8_t *len, uint8_t *from=NULL, uint8_t *to=NULL, uint8_t *id=NULL, uint8_t *flags=NULL) |
Turns the receiver on if it not already on. | |
bool | available () |
Tests whether a new message is available from the Driver. | |
void | waitAvailable () |
Starts the Driver receiver and blocks until a valid received message is available. | |
bool | waitPacketSent () |
Blocks until the transmitter is no longer transmitting. | |
bool | waitPacketSent (uint16_t timeout) |
Blocks until the transmitter is no longer transmitting. | |
bool | waitAvailableTimeout (uint16_t timeout) |
Starts the Driver receiver and blocks until a received message is available or a timeout. | |
void | setHeaderTo (uint8_t to) |
Sets the TO header to be sent in all subsequent messages. | |
void | setHeaderFrom (uint8_t from) |
Sets the FROM header to be sent in all subsequent messages. | |
void | setHeaderId (uint8_t id) |
Sets the ID header to be sent in all subsequent messages. | |
void | setHeaderFlags (uint8_t set, uint8_t clear=RH_FLAGS_NONE) |
Sets and clears bits in the FLAGS header to be sent in all subsequent messages. | |
uint8_t | headerTo () |
Returns the TO header of the last received message. | |
uint8_t | headerFrom () |
Returns the FROM header of the last received message. | |
uint8_t | headerId () |
Returns the ID header of the last received message. | |
uint8_t | headerFlags () |
Returns the FLAGS header of the last received message. | |
uint8_t | thisAddress () |
Returns the address of this node. | |
Protected Member Functions | |
virtual void | peekAtMessage (RoutedMessage *message, uint8_t messageLen) |
Internal function that inspects messages being received and adjusts the routing table if necessary. | |
virtual uint8_t | route (RoutedMessage *message, uint8_t messageLen) |
Internal function that inspects messages being received and adjusts the routing table if necessary. | |
virtual bool | doArp (uint8_t address) |
Try to resolve a route for the given address. | |
virtual bool | isPhysicalAddress (uint8_t *address, uint8_t addresslen) |
Tests if the given address of length addresslen is indentical to the physical address of this node. | |
void | deleteRoute (uint8_t index) |
Deletes a specific rout entry from therouting table. | |
void | acknowledge (uint8_t id, uint8_t from) |
Send an ACK for the message id to the given from address Blocks until the ACK has been sent. | |
bool | haveNewMessage () |
Checks whether the message currently in the Rx buffer is a new message, not previously received based on the from address and the sequence. | |
Protected Attributes | |
uint8_t | _lastE2ESequenceNumber |
The last end-to-end sequence number to be used Defaults to 0. | |
uint8_t | _max_hops |
The maximum number of hops permitted in routed messages. | |
RHGenericDriver & | _driver |
The Driver we are to use. | |
uint8_t | _thisAddress |
The address of this node. |
Detailed Description
RHRouter subclass for sending addressed, optionally acknowledged datagrams multi-hop routed across a network, with automatic route discovery.
Manager class that extends RHRouter to add automatic route discovery within a mesh of adjacent nodes, and route signalling.
Unlike RHRouter, RHMesh can be used in networks where the network topology is fluid, or unknown, or if nodes can mode around or go in or out of service. When a node wants to send a message to another node, it will automatically discover a route to the destination node and use it. If the route becomes unavailable, a new route will be discovered.
- Route Discovery
When a RHMesh mesh node is initialised, it doe not know any routes to any other nodes (see RHRouter for details on route and the routing table). When you attempt to send a message with sendtoWait, will first check to see if there is a route to the destinastion node in the routing tabl;e. If not, it wil initialite 'Route Discovery'. When a node needs to discover a route to another node, it broadcasts MeshRouteDiscoveryMessage with a message type of RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_REQUEST. Any node that receives such a request checks to see if it is a request for a route to itself (in which case it makes a unicast reply to the originating node with a MeshRouteDiscoveryMessage with a message type of RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_RESPONSE) otherwise it rebroadcasts the request, after adding itself to the list of nodes visited so far by the request.
If a node receives a RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_REQUEST that already has itself listed in the visited nodes, it knows it has already seen and rebroadcast this request, and threfore ignores it. This prevents broadcast storms. When a node receives a RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_REQUEST it can use the list of nodes aready visited to deduce routes back towards the originating (requesting node). This also means that when the destination node of the request is reached, it (and all the previous nodes the request visited) will have a route back to the originating node. This means the unicast RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_RESPONSE reply will be routed successfully back to the original route requester.
The RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_RESPONSE sent back by the destination node contains the full list of nodes that were visited on the way to the destination. Therefore, intermediate nodes that route the reply back towards the originating node can use the node list in the reply to deduce routes to all the nodes between it and the destination node.
Therefore, RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_REQUEST and RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_RESPONSE together ensure the original requester and all the intermediate nodes know how to route to the source and destination nodes and every node along the path.
Note that there is a race condition here that can effect routing on multipath routes. For example, if the route to the destination can traverse several paths, last reply from the destination will be the one used.
- Route Failure
RHRouter (and therefore RHMesh) use reliable hop-to-hop delivery of messages using hop-to-hop acknowledgements, but not end-to-end acknowledgements. When sendtoWait() returns, you know that the message has been delivered to the next hop, but not if it is (or even if it can be) delivered to the destination node. If during the course of hop-to-hop routing of a message, one of the intermediate RHMesh nodes finds it cannot deliver to the next hop (say due to a lost route or no acknwledgement from the next hop), it replies to the originator with a unicast MeshRouteFailureMessage RH_MESH_MESSAGE_TYPE_ROUTE_FAILURE message. Intermediate nodes (on the way beack to the originator) and the originating node use this message to delete the route to the destination node of the original message. This means that if a route to a destination becomes unusable (either because an intermediate node is off the air, or has moved out of range) a new route will be established the next time a message is to be sent.
- Message Format
RHMesh uses a number of message formats layered on top of RHRouter:
- MeshApplicationMessage (message type RH_MESH_MESSAGE_TYPE_APPLICATION). Carries an application layer message for the caller of RHMesh
- MeshRouteDiscoveryMessage (message types RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_REQUEST and RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_RESPONSE). Carries Route Discovery messages (broadcast) and replies (unicast).
- MeshRouteFailureMessage (message type RH_MESH_MESSAGE_TYPE_ROUTE_FAILURE) Informs nodes of route failures.
Part of the Arduino RH library for operating with HopeRF RH compatible transceivers (see http://www.hoperf.com)
- Memory
RHMesh programs require significant amount of SRAM, often approaching 2kbytes, which is beyond or at the limits of some Arduinos and other processors. Programs with additional software besides basic RHMesh programs may well require even more. If you have insufficient SRAM for your program, it may result in failure to run, or wierd crashes and other hard to trace behaviour. In this event you should consider a processor with more SRAM, such as the MotienoMEGA with 16k (https://lowpowerlab.com/shop/moteinomega) or others.
- Performance
- This class (in the interests of simple implemtenation and low memory use) does not have message queueing. This means that only one message at a time can be handled. Message transmission failures can have a severe impact on network performance. If you need high performance mesh networking under all conditions consider XBee or similar.
Definition at line 115 of file RHMesh.h.
Member Enumeration Documentation
enum RouteState [inherited] |
Values for the possible states for routes.
- Enumerator:
Invalid No valid route is known.
Discovering Discovering a route (not currently used)
Valid Route is valid.
Definition at line 155 of file RHRouter.h.
Constructor & Destructor Documentation
RHMesh | ( | RHGenericDriver & | driver, |
uint8_t | thisAddress = 0 |
||
) |
Constructor.
- Parameters:
-
[in] driver The RadioHead driver to use to transport messages. [in] thisAddress The address to assign to this node. Defaults to 0
Definition at line 20 of file RHMesh.cpp.
Member Function Documentation
void acknowledge | ( | uint8_t | id, |
uint8_t | from | ||
) | [protected, inherited] |
Send an ACK for the message id to the given from address Blocks until the ACK has been sent.
Definition at line 176 of file RHReliableDatagram.cpp.
void addRouteTo | ( | uint8_t | dest, |
uint8_t | next_hop, | ||
uint8_t | state = Valid |
||
) | [inherited] |
Adds a route to the local routing table, or updates it if already present.
If there is not enough room the oldest (first) route will be deleted by calling retireOldestRoute().
- Parameters:
-
[in] dest The destination node address. RH_BROADCAST_ADDRESS is permitted. [in] next_hop The address of the next hop to send messages destined for dest [in] state The satte of the route. Defaults to Valid
Definition at line 44 of file RHRouter.cpp.
bool available | ( | ) | [inherited] |
Tests whether a new message is available from the Driver.
On most drivers, this will also put the Driver into RHModeRx mode until a message is actually received bythe transport, when it will be returned to RHModeIdle. This can be called multiple times in a timeout loop.
- Returns:
- true if a new, complete, error-free uncollected message is available to be retreived by recv()
Definition at line 52 of file RHDatagram.cpp.
void clearRoutingTable | ( | ) | [inherited] |
Clears all entries from the local routing table.
Definition at line 146 of file RHRouter.cpp.
void deleteRoute | ( | uint8_t | index ) | [protected, inherited] |
Deletes a specific rout entry from therouting table.
- Parameters:
-
[in] index The 0 based index of the routing table entry to delete
Definition at line 97 of file RHRouter.cpp.
bool deleteRouteTo | ( | uint8_t | dest ) | [inherited] |
Deletes from the local routing table any route for the destination node.
- Parameters:
-
[in] dest The destination node address
- Returns:
- true if the route was present
Definition at line 124 of file RHRouter.cpp.
bool doArp | ( | uint8_t | address ) | [protected, virtual] |
Try to resolve a route for the given address.
Blocks while discovering the route which may take up to 4000 msec. Virtual so subclasses can override.
- Parameters:
-
[in] address The physical address to resolve
- Returns:
- true if the address was resolved and added to the local routing table
Definition at line 51 of file RHMesh.cpp.
RHRouter::RoutingTableEntry * getRouteTo | ( | uint8_t | dest ) | [inherited] |
Finds and returns a RoutingTableEntry for the given destination node.
- Parameters:
-
[in] dest The desired destination node address.
- Returns:
- pointer to a RoutingTableEntry for dest
Definition at line 87 of file RHRouter.cpp.
bool haveNewMessage | ( | ) | [protected, inherited] |
Checks whether the message currently in the Rx buffer is a new message, not previously received based on the from address and the sequence.
If it is new, it is acknowledged and returns true
- Returns:
- true if there is a message received and it is a new message
uint8_t headerFlags | ( | ) | [inherited] |
Returns the FLAGS header of the last received message.
- Returns:
- The FLAGS header of the most recently received message.
Definition at line 117 of file RHDatagram.cpp.
uint8_t headerFrom | ( | ) | [inherited] |
Returns the FROM header of the last received message.
- Returns:
- The FROM header of the most recently received message.
Definition at line 107 of file RHDatagram.cpp.
uint8_t headerId | ( | ) | [inherited] |
Returns the ID header of the last received message.
- Returns:
- The ID header of the most recently received message.
Definition at line 112 of file RHDatagram.cpp.
uint8_t headerTo | ( | ) | [inherited] |
Returns the TO header of the last received message.
- Returns:
- The TO header of the most recently received message.
Definition at line 102 of file RHDatagram.cpp.
bool init | ( | ) | [inherited] |
Initialises this instance and the radio module connected to it.
Overrides the init() function in RH. Sets max_hops to the default of RH_DEFAULT_MAX_HOPS (30)
Reimplemented from RHDatagram.
Definition at line 29 of file RHRouter.cpp.
bool isPhysicalAddress | ( | uint8_t * | address, |
uint8_t | addresslen | ||
) | [protected, virtual] |
Tests if the given address of length addresslen is indentical to the physical address of this node.
RHMesh always implements physical addresses as the 1 octet address of the node given by _thisAddress Called by recvfromAck() to test whether a RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_REQUEST is for this node. Subclasses may want to override to implement more complicated or longer physical addresses
- Parameters:
-
[in] address Address of the pyysical addres being tested [in] addresslen Lengthof the address in bytes
- Returns:
- true if the physical address of this node is identical to address
Definition at line 148 of file RHMesh.cpp.
void peekAtMessage | ( | RoutedMessage * | message, |
uint8_t | messageLen | ||
) | [protected, virtual] |
Internal function that inspects messages being received and adjusts the routing table if necessary.
Called by recvfromAck() immediately after it gets the message from RHReliableDatagram
- Parameters:
-
[in] message Pointer to the RHRouter message that was received. [in] messageLen Length of message in octets
Reimplemented from RHRouter.
Definition at line 92 of file RHMesh.cpp.
void printRoutingTable | ( | ) | [inherited] |
If RH_HAVE_SERIAL is defined, this will print out the contents of the local routing table using Serial.
Definition at line 106 of file RHRouter.cpp.
bool recvfrom | ( | uint8_t * | buf, |
uint8_t * | len, | ||
uint8_t * | from = NULL , |
||
uint8_t * | to = NULL , |
||
uint8_t * | id = NULL , |
||
uint8_t * | flags = NULL |
||
) | [inherited] |
Turns the receiver on if it not already on.
If there is a valid message available for this node, copy it to buf and return true The SRC address is placed in *from if present and not NULL. The DEST address is placed in *to if present and not NULL. If a message is copied, *len is set to the length. You should be sure to call this function frequently enough to not miss any messages It is recommended that you call it in your main loop.
- Parameters:
-
[in] buf Location to copy the received message [in,out] len Pointer to available space in buf. Set to the actual number of octets copied. [in] from If present and not NULL, the referenced uint8_t will be set to the FROM address [in] to If present and not NULL, the referenced uint8_t will be set to the TO address [in] id If present and not NULL, the referenced uint8_t will be set to the ID [in] flags If present and not NULL, the referenced uint8_t will be set to the FLAGS (not just those addressed to this node).
- Returns:
- true if a valid message was copied to buf
Definition at line 39 of file RHDatagram.cpp.
bool recvfromAck | ( | uint8_t * | buf, |
uint8_t * | len, | ||
uint8_t * | source = NULL , |
||
uint8_t * | dest = NULL , |
||
uint8_t * | id = NULL , |
||
uint8_t * | flags = NULL |
||
) |
Starts the receiver if it is not running already, processes and possibly routes any received messages addressed to other nodes and delivers any messages addressed to this node.
If there is a valid application layer message available for this node (or RH_BROADCAST_ADDRESS), send an acknowledgement to the last hop address (blocking until this is complete), then copy the application message payload data to buf and return true else return false. If a message is copied, *len is set to the length.. If from is not NULL, the originator SOURCE address is placed in *source. If to is not NULL, the DEST address is placed in *dest. This might be this nodes address or RH_BROADCAST_ADDRESS. This is the preferred function for getting messages addressed to this node. If the message is not a broadcast, acknowledge to the sender before returning.
- Parameters:
-
[in] buf Location to copy the received message [in,out] len Available space in buf. Set to the actual number of octets copied. [in] source If present and not NULL, the referenced uint8_t will be set to the SOURCE address [in] dest If present and not NULL, the referenced uint8_t will be set to the DEST address [in] id If present and not NULL, the referenced uint8_t will be set to the ID [in] flags If present and not NULL, the referenced uint8_t will be set to the FLAGS (not just those addressed to this node).
- Returns:
- true if a valid message was received for this node and copied to buf
Reimplemented from RHRouter.
Definition at line 155 of file RHMesh.cpp.
bool 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 |
||
) |
Starts the receiver if it is not running already.
Similar to recvfromAck(), this will block until either a valid application layer message available for this node or the timeout expires.
- Parameters:
-
[in] buf Location to copy the received message [in,out] len Available space in buf. Set to the actual number of octets copied. [in] timeout Maximum time to wait in milliseconds [in] source If present and not NULL, the referenced uint8_t will be set to the SOURCE address [in] dest If present and not NULL, the referenced uint8_t will be set to the DEST address [in] id If present and not NULL, the referenced uint8_t will be set to the ID [in] flags If present and not NULL, the referenced uint8_t will be set to the FLAGS (not just those addressed to this node).
- Returns:
- true if a valid message was copied to buf
Reimplemented from RHRouter.
Definition at line 227 of file RHMesh.cpp.
void resetRetransmissions | ( | ) | [inherited] |
Resets the count of the number of retransmissions to 0.
Definition at line 171 of file RHReliableDatagram.cpp.
void retireOldestRoute | ( | ) | [inherited] |
Deletes the oldest (first) route from the local routing table.
Definition at line 139 of file RHRouter.cpp.
uint32_t retransmissions | ( | ) | [inherited] |
Returns the number of retransmissions we have had to send since starting or since the last call to resetRetransmissions().
- Returns:
- The number of retransmissions since initialisation.
Definition at line 166 of file RHReliableDatagram.cpp.
uint8_t retries | ( | ) | [inherited] |
Returns the currently configured maximum retries count.
Can be changed with setRetries().
- Returns:
- The currently configured maximum number of retries.
Definition at line 41 of file RHReliableDatagram.cpp.
uint8_t route | ( | RoutedMessage * | message, |
uint8_t | messageLen | ||
) | [protected, virtual] |
Internal function that inspects messages being received and adjusts the routing table if necessary.
This is virtual, which lets subclasses override or intercept the route() function. Called by sendtoWait after the message header has been filled in.
- Parameters:
-
[in] message Pointer to the RHRouter message to be sent. [in] messageLen Length of message in octets
Reimplemented from RHRouter.
Definition at line 123 of file RHMesh.cpp.
bool sendto | ( | uint8_t * | buf, |
uint8_t | len, | ||
uint8_t | address | ||
) | [inherited] |
Sends a message to the node(s) with the given address RH_BROADCAST_ADDRESS is a valid address which will cause the message to be accepted by all RHDatagram nodes within range.
- Parameters:
-
[in] buf Pointer to the binary message to send [in] len Number of octets to send (> 0) [in] address The address to send the message to.
- Returns:
- true if the message not too loing fot eh driver, and the message was transmitted.
Definition at line 33 of file RHDatagram.cpp.
uint8_t sendtoFromSourceWait | ( | uint8_t * | buf, |
uint8_t | len, | ||
uint8_t | dest, | ||
uint8_t | source, | ||
uint8_t | flags = 0 |
||
) | [inherited] |
Similar to sendtoWait() above, but spoofs the source address.
For internal use only during routing
- Parameters:
-
[in] buf The application message data. [in] len Number of octets in the application message data. 0 is permitted. [in] dest The destination node address. [in] source The (fake) originating node address. [in] flags Optional flags for use by subclasses or application layer, delivered end-to-end to the dest address. The receiver can recover the flags with recvFromAck().
- Returns:
- The result code:
- RH_ROUTER_ERROR_NONE Message was routed and deliverd to the next hop (not necessarily to the final dest address)
- RH_ROUTER_ERROR_NO_ROUTE There was no route for dest in the local routing table
- RH_ROUTER_ERROR_UNABLE_TO_DELIVER Noyt able to deliver to the next hop (usually because it dod not acknowledge due to being off the air or out of range
Definition at line 161 of file RHRouter.cpp.
bool sendtoWait | ( | uint8_t * | buf, |
uint8_t | len, | ||
uint8_t | address | ||
) | [inherited] |
Send the message (with retries) and waits for an ack.
Returns true if an acknowledgement is received. Synchronous: any message other than the desired ACK received while waiting is discarded. Blocks until an ACK is received or all retries are exhausted (ie up to retries*timeout milliseconds). If the destination address is the broadcast address RH_BROADCAST_ADDRESS (255), the message will be sent as a broadcast, but receiving nodes do not acknowledge, and sendtoWait() returns true immediately without waiting for any acknowledgements.
- Parameters:
-
[in] address The address to send the message to. [in] buf Pointer to the binary message to send [in] len Number of octets to send
- Returns:
- true if the message was transmitted and an acknowledgement was received.
Definition at line 47 of file RHReliableDatagram.cpp.
uint8_t sendtoWait | ( | uint8_t * | buf, |
uint8_t | len, | ||
uint8_t | dest, | ||
uint8_t | flags = 0 |
||
) |
Sends a message to the destination node.
Initialises the RHRouter message header (the SOURCE address is set to the address of this node, HOPS to 0) and calls route() which looks up in the routing table the next hop to deliver to. If no route is known, initiates route discovery and waits for a reply. Then sends the message to the next hop Then waits for an acknowledgement from the next hop (but not from the destination node (if that is different).
- Parameters:
-
[in] buf The application message data [in] len Number of octets in the application message data. 0 is permitted [in] dest The destination node address. If the address is RH_BROADCAST_ADDRESS (255) the message will be broadcast to all the nearby nodes, but not routed or relayed. [in] flags Optional flags for use by subclasses or application layer, delivered end-to-end to the dest address. The receiver can recover the flags with recvFromAck().
- Returns:
- The result code:
- RH_ROUTER_ERROR_NONE Message was routed and delivered to the next hop (not necessarily to the final dest address)
- RH_ROUTER_ERROR_NO_ROUTE There was no route for dest in the local routing table
- RH_ROUTER_ERROR_UNABLE_TO_DELIVER Not able to deliver to the next hop (usually because it dod not acknowledge due to being off the air or out of range
Reimplemented from RHRouter.
Definition at line 31 of file RHMesh.cpp.
void setHeaderFlags | ( | uint8_t | set, |
uint8_t | clear = RH_FLAGS_NONE |
||
) | [inherited] |
Sets and clears bits in the FLAGS header to be sent in all subsequent messages.
- Parameters:
-
[in] set bitmask of bits to be set [in] clear bitmask of flags to clear
Definition at line 97 of file RHDatagram.cpp.
void setHeaderFrom | ( | uint8_t | from ) | [inherited] |
Sets the FROM header to be sent in all subsequent messages.
- Parameters:
-
[in] from The new FROM header value
Definition at line 87 of file RHDatagram.cpp.
void setHeaderId | ( | uint8_t | id ) | [inherited] |
Sets the ID header to be sent in all subsequent messages.
- Parameters:
-
[in] id The new ID header value
Definition at line 92 of file RHDatagram.cpp.
void setHeaderTo | ( | uint8_t | to ) | [inherited] |
Sets the TO header to be sent in all subsequent messages.
- Parameters:
-
[in] to The new TO header value
Definition at line 82 of file RHDatagram.cpp.
void setMaxHops | ( | uint8_t | max_hops ) | [inherited] |
Sets the max_hops to the given value This controls the maximum number of hops allowed between source and destination nodes Messages that are not delivered by the time their HOPS field exceeds max_hops on a routing node will be dropped and ignored.
- Parameters:
-
[in] max_hops The new value for max_hops
Definition at line 38 of file RHRouter.cpp.
void setRetries | ( | uint8_t | retries ) | [inherited] |
Sets the maximum number of retries.
Defaults to 3 at construction time. If set to 0, each message will only ever be sent once. sendtoWait will give up and return false if there is no ack received after all transmissions time out and the retries count is exhausted. param[in] retries The maximum number a retries.
Definition at line 35 of file RHReliableDatagram.cpp.
void setThisAddress | ( | uint8_t | thisAddress ) | [inherited] |
Sets the address of this node.
Defaults to 0. This will be used to set the FROM address of all messages sent by this node. In a conventional multinode system, all nodes will have a unique address (which you could store in EEPROM).
- Parameters:
-
[in] thisAddress The address of this node
Definition at line 25 of file RHDatagram.cpp.
void setTimeout | ( | uint16_t | timeout ) | [inherited] |
Sets the minimum retransmit timeout.
If sendtoWait is waiting for an ack longer than this time (in milliseconds), it will retransmit the message. Defaults to 200ms. The timeout is measured from the end of transmission of the message. It must be at least longer than the the transmit time of the acknowledgement (preamble+6 octets) plus the latency/poll time of the receiver. For fast modulation schemes you can considerably shorten this time. The actual timeout is randomly varied between timeout and timeout*2.
- Parameters:
-
[in] timeout The new timeout period in milliseconds
Definition at line 29 of file RHReliableDatagram.cpp.
uint8_t thisAddress | ( | ) | [inherited] |
Returns the address of this node.
- Returns:
- The address of this node
Definition at line 77 of file RHDatagram.cpp.
void waitAvailable | ( | ) | [inherited] |
Starts the Driver receiver and blocks until a valid received message is available.
Definition at line 57 of file RHDatagram.cpp.
bool waitAvailableTimeout | ( | uint16_t | timeout ) | [inherited] |
Starts the Driver receiver and blocks until a received message is available or a timeout.
- Parameters:
-
[in] timeout Maximum time to wait in milliseconds.
- Returns:
- true if a message is available
Definition at line 72 of file RHDatagram.cpp.
bool waitPacketSent | ( | ) | [inherited] |
Blocks until the transmitter is no longer transmitting.
Definition at line 62 of file RHDatagram.cpp.
bool waitPacketSent | ( | uint16_t | timeout ) | [inherited] |
Blocks until the transmitter is no longer transmitting.
or until the timeout occuers, whichever happens first
- Parameters:
-
[in] timeout Maximum time to wait in milliseconds.
- Returns:
- true if the radio completed transmission within the timeout period. False if it timed out.
Definition at line 67 of file RHDatagram.cpp.
Field Documentation
RHGenericDriver& _driver [protected, inherited] |
The Driver we are to use.
Definition at line 156 of file RHDatagram.h.
uint8_t _lastE2ESequenceNumber [protected, inherited] |
The last end-to-end sequence number to be used Defaults to 0.
Definition at line 308 of file RHRouter.h.
uint8_t _max_hops [protected, inherited] |
The maximum number of hops permitted in routed messages.
If a routed message would exceed this number of hops it is dropped and ignored.
Definition at line 312 of file RHRouter.h.
uint8_t _thisAddress [protected, inherited] |
The address of this node.
Definition at line 159 of file RHDatagram.h.
Generated on Tue Jul 12 2022 18:05:56 by
