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.
Fork of RF22 by
RF22Router Class Reference
RF22 subclass for sending addressed, optionally acknowledged datagrams multi-hop routed across a network. More...
#include <RF22Router.h>
Inherits RF22ReliableDatagram.
Inherited by RF22Mesh.
Data Structures | |
struct | RoutedMessage |
Defines the structure of a RF22Router message. More... | |
struct | RoutedMessageHeader |
Defines the structure of the RF22Router message header, used to keep track of end-to-end delivery parameters. More... | |
struct | RoutingTableEntry |
Defines an entry in the routing table. More... | |
Public Types | |
enum | RouteState { Invalid = 0, Discovering, Valid } |
Values for the possible states for routes. More... | |
enum | ModemConfigChoice { UnmodulatedCarrier = 0, FSK_PN9_Rb2Fd5, FSK_Rb2Fd5, FSK_Rb2_4Fd36, FSK_Rb4_8Fd45, FSK_Rb9_6Fd45, FSK_Rb19_2Fd9_6, FSK_Rb38_4Fd19_6, FSK_Rb57_6Fd28_8, FSK_Rb125Fd125, GFSK_Rb2Fd5, GFSK_Rb2_4Fd36, GFSK_Rb4_8Fd45, GFSK_Rb9_6Fd45, GFSK_Rb19_2Fd9_6, GFSK_Rb38_4Fd19_6, GFSK_Rb57_6Fd28_8, GFSK_Rb125Fd125, OOK_Rb1_2Bw75, OOK_Rb2_4Bw335, OOK_Rb4_8Bw335, OOK_Rb9_6Bw335, OOK_Rb19_2Bw335, OOK_Rb38_4Bw335, OOK_Rb40Bw335 } |
Choices for setModemConfig() for a selected subset of common modulation types, and data rates. More... | |
Public Member Functions | |
RF22Router (uint8_t thisAddress, PinName slaveSelectPin, PinName mosi, PinName miso, PinName sclk, PinName interrupt) | |
Constructor. | |
boolean | 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. | |
boolean | 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 RF22_HAVE_SERIAL is defined, this will print out the contents of the local routing table using Serial. | |
uint8_t | sendtoWait (uint8_t *buf, uint8_t len, uint8_t dest) |
Sends a message to the destination node. | |
uint8_t | sendtoWait (uint8_t *buf, uint8_t len, uint8_t dest, uint8_t source) |
Similar to sendtoWait() above, but spoofs the source address. | |
boolean | 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. | |
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) |
Starts the receiver if it is not running already. | |
void | setTimeout (uint16_t timeout) |
Sets the minimum retransmit timeout. | |
void | setRetries (uint8_t retries) |
Sets the max number of retries. | |
uint16_t | retransmissions () |
Returns the number of retransmissions we have had to send. | |
void | setThisAddress (uint8_t thisAddress) |
Sets the address of this node. | |
boolean | sendto (uint8_t *buf, uint8_t len, uint8_t address) |
Sends a message to the node(s) with the given address RF22_BROADCAST_ADDRESS is a valid address which will cause the message to be accepted by all RF22Datagram nodes within range. | |
boolean | 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. | |
void | reset () |
Issues a software reset to the RF22 module. | |
uint8_t | spiRead (uint8_t reg) |
Reads a single register from the RF22. | |
void | spiWrite (uint8_t reg, uint8_t val) |
Writes a single byte to the RF22. | |
void | spiBurstRead (uint8_t reg, uint8_t *dest, uint8_t len) |
Reads a number of consecutive registers from the RF22 using burst read mode. | |
void | spiBurstWrite (uint8_t reg, const uint8_t *src, uint8_t len) |
Write a number of consecutive registers using burst write mode. | |
uint8_t | statusRead () |
Reads and returns the device status register RF22_REG_02_DEVICE_STATUS. | |
uint8_t | adcRead (uint8_t adcsel=RF22_ADCSEL_INTERNAL_TEMPERATURE_SENSOR, uint8_t adcref=RF22_ADCREF_BANDGAP_VOLTAGE, uint8_t adcgain=0, uint8_t adcoffs=0) |
Reads a value from the on-chip analog-digital converter. | |
uint8_t | temperatureRead (uint8_t tsrange=RF22_TSRANGE_M64_64C, uint8_t tvoffs=0) |
Reads the on-chip temperature sensoer. | |
uint16_t | wutRead () |
Reads the wakeup timer value in registers RF22_REG_17_WAKEUP_TIMER_VALUE1 and RF22_REG_18_WAKEUP_TIMER_VALUE2. | |
void | setWutPeriod (uint16_t wtm, uint8_t wtr=0, uint8_t wtd=0) |
Sets the wakeup timer period registers RF22_REG_14_WAKEUP_TIMER_PERIOD1, RF22_REG_15_WAKEUP_TIMER_PERIOD2 and RF22_R<EG_16_WAKEUP_TIMER_PERIOD3. | |
boolean | setFrequency (float centre, float afcPullInRange=0.05) |
Sets the transmitter and receiver centre frequency. | |
boolean | setFHStepSize (uint8_t fhs) |
Sets the frequency hopping step size. | |
boolean | setFHChannel (uint8_t fhch) |
Sets the frequncy hopping channel. | |
uint8_t | rssiRead () |
Reads and returns the current RSSI value from register RF22_REG_26_RSSI. | |
uint8_t | ezmacStatusRead () |
Reads and returns the current EZMAC value from register RF22_REG_31_EZMAC_STATUS. | |
void | setMode (uint8_t mode) |
Sets the parameters for the RF22 Idle mode in register RF22_REG_07_OPERATING_MODE. | |
void | setModeIdle () |
If current mode is Rx or Tx changes it to Idle. | |
void | setModeRx () |
If current mode is Tx or Idle, changes it to Rx. | |
void | setModeTx () |
If current mode is Rx or Idle, changes it to Rx. | |
uint8_t | mode () |
Returns the operating mode of the library. | |
void | setTxPower (uint8_t power) |
Sets the transmitter power output level in register RF22_REG_6D_TX_POWER. | |
void | setModemRegisters (const ModemConfig *config) |
Sets all the registered required to configure the data modem in the RF22, including the data rate, bandwidths etc. | |
boolean | setModemConfig (ModemConfigChoice index) |
Select one of the predefined modem configurations. | |
boolean | available () |
Starts the receiver and checks whether a received message is available. | |
void | waitAvailable () |
Starts the receiver and blocks until a valid received message is available. | |
bool | waitAvailableTimeout (uint16_t timeout) |
Starts the receiver and blocks until a received message is available or a timeout. | |
boolean | recv (uint8_t *buf, uint8_t *len) |
Turns the receiver on if it not already on. | |
boolean | send (const uint8_t *data, uint8_t len) |
Waits until any previous transmit packet is finished being transmitted with waitPacketSent(). | |
void | waitPacketSent () |
Blocks until the RF22 is not in mode RF22_MODE_TX (ie until the RF22 is not transmitting). | |
void | setPromiscuous (boolean promiscuous) |
Tells the receiver to accept messages with any TO address, not just messages addressed to this node or the broadcast address. | |
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 | lastRssi () |
Returns the RSSI (Receiver Signal Strength Indicator) of the last received message. | |
void | setPreambleLength (uint8_t nibbles) |
Sets the length of the preamble in 4-bit nibbles. | |
void | setSyncWords (const uint8_t *syncWords, uint8_t len) |
Sets the sync words for transmit and receive in registers RF22_REG_36_SYNC_WORD3 to RF22_REG_39_SYNC_WORD0 Caution: this should be set to the same value on all nodes in your network. | |
Static Public Member Functions | |
static void | printBuffer (const char *prompt, const uint8_t *buf, uint8_t len) |
Prints a data buffer in HEX. | |
Protected Member Functions | |
virtual void | peekAtMessage (RoutedMessage *message, uint8_t messageLen) |
Lets sublasses peek at messages going past before routing or local delivery. | |
virtual uint8_t | route (RoutedMessage *message, uint8_t messageLen) |
Finds the next-hop route and sends the message via RF22ReliableDatagram::sendtoWait(). | |
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. | |
boolean | 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. | |
void | handleInterrupt () |
This is a low level function to handle the interrupts for one instance of RF22. | |
void | clearRxBuf () |
Clears the receiver buffer. | |
void | clearTxBuf () |
Clears the transmitter buffer Internal use only. | |
boolean | fillTxBuf (const uint8_t *data, uint8_t len) |
Fills the transmitter buffer with the data of a mesage to be sent. | |
boolean | appendTxBuf (const uint8_t *data, uint8_t len) |
Appends the transmitter buffer with the data of a mesage to be sent. | |
void | sendNextFragment () |
Internal function to load the next fragment of the current message into the transmitter FIFO Internal use only. | |
void | readNextFragment () |
function to copy the next fragment from the receiver FIF) into the receiver buffer | |
void | resetFifos () |
Clears the RF22 Rx and Tx FIFOs Internal use only. | |
void | resetRxFifo () |
Clears the RF22 Rx FIFO Internal use only. | |
void | resetTxFifo () |
Clears the RF22 Tx FIFO Internal use only. | |
virtual void | handleExternalInterrupt () |
This function will be called by handleInterrupt() if an RF22 external interrupt occurs. | |
virtual void | handleWakeupTimerInterrupt () |
This function will be called by handleInterrupt() if an RF22 wakeup timer interrupt occurs. | |
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 flags) |
Sets the FLAGS header to be sent in all subsequent messages. | |
void | startTransmit () |
Start the transmission of the contents of the Tx buffer. | |
void | restartTransmit () |
ReStart the transmission of the contents of the Tx buffer after a atransmission failure. | |
void | isr0 () |
Low level interrupt service routine for RF22 connected to interrupt 0. | |
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. | |
uint8_t | _thisAddress |
The address of this node. Defaults to 0. |
Detailed Description
RF22 subclass for sending addressed, optionally acknowledged datagrams multi-hop routed across a network.
Extends RF22ReliableDatagram to define addressed messages That are reliably transmitted and routed across a network. Each message is transmitted reliably between each hop in order to get from the source node to the destination node.
With RF22Router, routes are hard wired. This means that each node must have programmed in it how to reach each of the other nodes it will be trying to communicate with. This means you must specify the next-hop node address for each of the destination nodes, using the addRouteTo() function.
When sendtoWait() is called with a new message to deliver, and the destination address, RF22Router looks up the next hop node for the destination node. It then uses RF22ReliableDatagram to (reliably) deliver the message to the next hop (which is expected also to be running an RF22Router). If that next-hop node is not the final destination, it will also look up the next hop for the destination node and (reliably) deliver the message to the next hop. By this method, messages can be delivered across a network of nodes, even if each node cannot hear all of the others in the network. Each time a message is received for another node and retransmitted to the next hop, the HOPS filed in teh header is incremented. If a message is received for routing to another node which has exceed the routers max_hops, the message wioll be dropped and ignored. This helps prevent infinite routing loops.
RF22Router supports messages with a dest of RF22_BROADCAST_ADDRESS. Such messages are not routed, and are broadcast (once) to all nodes within range.
The recvfromAck() function is responsible not just for receiving and delivering messages addressed to this node (or RF22_BROADCAST_ADDRESS), but it is also responsible for routing other message to their next hop. This means that it is important to call recvfromAck() or recvfromAckTimeout() frequently in your main loop. recvfromAck() will return false if it receives a message but it is not for this node.
RF22Router does not provide reliable end-to-end delivery, but uses reliable hop-to-hop delivery. If a message is unable to be delivered to an end node during to a delivery failure between 2 hops, the source node will not be told about it.
Note: This class is most useful for networks of nodes that are essentially static (i.e. the nodes dont move around), and for which the routing never changes. If that is not the case for your proposed network, see RF22Mesh instead.
- The Routing Table
The routing table is a local table in RF22Router that holds the information about the next hop node address for each destination address you may want to send a message to. It is your responsibility to make sure every node in an RF22Router network has been configured with a unique address and the routing information so that messages are correctly routed across the network from source node to destination node. This is usually done once in setup() by calling addRouteTo(). The hardwired routing will in general be different on each node, and will depend on the physical topololgy of the network. You can also use addRouteTo() to change a route and deleteRouteTo() to delete a route at run time. Youcan also clear the entire routing table
The Routing Table has limited capacity for entries (defined by RF22_ROUTING_TABLE_SIZE, which is 10) if more than RF22_ROUTING_TABLE_SIZE are added, the oldest (first) one will be removed by calling retireOldestRoute()
- Message Format
RF22Router add to the lower level RF22ReliableDatagram (and even lower level RF22) class mesage formats. In those lower level classes, the hop-to-hop message headers are in the RF22 message headers, and are handled automcatically by tyhe RF22 hardware. RF22Router and its subclasses add an end-to-end addressing header in the payload of the RF22 message, and before the RF22Router application data.
- 1 octet DEST, the destination node address (ie the address of the final destination node for this message)
- 1 octet SOURCE, the source node address (ie the address of the originating node that first sent the message).
- 1 octet HOPS, the number of hops this message has traversed so far.
- 1 octet ID, an incrementing message ID for end-to-end message tracking for use by subclasses. Not used by RF22Router.
- 1 octet FLAGS, a bitmask for use by subclasses. Not used by RF22Router.
- 0 or more octets DATA, the application payload data. The length of this data is implicit in the length of the entire message.
You should be careful to note that there are ID and FLAGS fields in the low level per-hop message header too. These are used only for hop-to-hop, and in general will be different to the ones at the RF22Router level.
- Testing
Bench testing of such networks is notoriously difficult, especially simulating limited radio connectivity between some nodes. To assist testing (both during RF22 development and for your own networks) RF22Router.cpp has the ability to simulate a number of different small network topologies. Each simulated network supports 4 nodes with addresses 1 to 4. It operates by pretending to not hear RF22 messages from certain other nodes. You can enable testing with a #define TEST_NETWORK in RF22Router.h The sample programs rf22_mesh_* rely on this feature.
Part of the Arduino RF22 library for operating with HopeRF RF22 compatible transceivers (see http://www.hoperf.com)
Definition at line 133 of file RF22Router.h.
Member Enumeration Documentation
enum ModemConfigChoice [inherited] |
Choices for setModemConfig() for a selected subset of common modulation types, and data rates.
If you need another configuration, use the register calculator. and call setModemRegisters() with your desired settings These are indexes into _modemConfig
- Enumerator:
enum RouteState |
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 157 of file RF22Router.h.
Constructor & Destructor Documentation
RF22Router | ( | uint8_t | thisAddress, |
PinName | slaveSelectPin, | ||
PinName | mosi, | ||
PinName | miso, | ||
PinName | sclk, | ||
PinName | interrupt | ||
) |
Constructor.
- Parameters:
-
[in] thisAddress The address to assign to this node. Defaults to 0 [in] slaveSelectPin the Arduino pin number of the output to use to select the RF22 before accessing it. Defaults to the normal SS pin for your Arduino (D10 for Diecimila, Uno etc, D53 for Mega) [in] interrupt The interrupt number to use. Default is interrupt 0 (Arduino input pin 2)
Definition at line 24 of file RF22Router.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 155 of file RF22ReliableDatagram.cpp.
uint8_t adcRead | ( | uint8_t | adcsel = RF22_ADCSEL_INTERNAL_TEMPERATURE_SENSOR , |
uint8_t | adcref = RF22_ADCREF_BANDGAP_VOLTAGE , |
||
uint8_t | adcgain = 0 , |
||
uint8_t | adcoffs = 0 |
||
) | [inherited] |
Reads a value from the on-chip analog-digital converter.
- Parameters:
-
[in] adcsel Selects the ADC input to measure. One of RF22_ADCSEL_*. Defaults to the internal temperature sensor [in] adcref Specifies the refernce voltage to use. One of RF22_ADCREF_*. Defaults to the internal bandgap voltage. [in] adcgain Amplifier gain selection. [in] adcoffs Amplifier offseet (0 to 15).
- Returns:
- The analog value. 0 to 255.
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.
If there is not enough room the oldest (first) route will be deleted by calling retireOldestRoute().
- Parameters:
-
[in] dest The destination node address. RF22_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 48 of file RF22Router.cpp.
boolean appendTxBuf | ( | const uint8_t * | data, |
uint8_t | len | ||
) | [protected, inherited] |
boolean available | ( | ) | [inherited] |
void clearRoutingTable | ( | ) |
Clears all entries from the local routing table.
Definition at line 150 of file RF22Router.cpp.
void clearRxBuf | ( | ) | [protected, inherited] |
void clearTxBuf | ( | ) | [protected, inherited] |
void deleteRoute | ( | uint8_t | index ) | [protected] |
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 101 of file RF22Router.cpp.
boolean deleteRouteTo | ( | uint8_t | dest ) |
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 128 of file RF22Router.cpp.
uint8_t ezmacStatusRead | ( | ) | [inherited] |
boolean fillTxBuf | ( | const uint8_t * | data, |
uint8_t | len | ||
) | [protected, inherited] |
RF22Router::RoutingTableEntry * getRouteTo | ( | uint8_t | dest ) |
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 91 of file RF22Router.cpp.
void handleExternalInterrupt | ( | ) | [protected, virtual, inherited] |
This function will be called by handleInterrupt() if an RF22 external interrupt occurs.
This can only happen if external interrupts are enabled in the RF22 (which they are not by default). Subclasses may override this function to get control when an RF22 external interrupt occurs.
void handleInterrupt | ( | ) | [protected, inherited] |
void handleWakeupTimerInterrupt | ( | ) | [protected, virtual, inherited] |
This function will be called by handleInterrupt() if an RF22 wakeup timer interrupt occurs.
This can only happen if wakeup timer interrupts are enabled in the RF22 (which they are not by default). Subclasses may override this function to get control when an RF22 wakeup timer interrupt occurs.
boolean 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] |
uint8_t headerFrom | ( | ) | [inherited] |
uint8_t headerId | ( | ) | [inherited] |
uint8_t headerTo | ( | ) | [inherited] |
boolean init | ( | ) |
Initialises this instance and the radio module connected to it.
Overrides the init() function in RF22. Sets max_hops to the default of RF22_DEFAULT_MAX_HOPS (30)
Reimplemented from RF22Datagram.
Definition at line 33 of file RF22Router.cpp.
void isr0 | ( | ) | [protected, inherited] |
uint8_t lastRssi | ( | ) | [inherited] |
uint8_t mode | ( | ) | [inherited] |
void peekAtMessage | ( | RoutedMessage * | message, |
uint8_t | messageLen | ||
) | [protected, virtual] |
Lets sublasses peek at messages going past before routing or local delivery.
Called by recvfromAck() immediately after it gets the message from RF22ReliableDatagram
- Parameters:
-
[in] message Pointer to the RF22Router message that was received. [in] messageLen Length of message in octets
Reimplemented in RF22Mesh.
Definition at line 202 of file RF22Router.cpp.
void printBuffer | ( | const char * | prompt, |
const uint8_t * | buf, | ||
uint8_t | len | ||
) | [static, inherited] |
void printRoutingTable | ( | ) |
If RF22_HAVE_SERIAL is defined, this will print out the contents of the local routing table using Serial.
Definition at line 110 of file RF22Router.cpp.
void readNextFragment | ( | ) | [protected, inherited] |
boolean recv | ( | uint8_t * | buf, |
uint8_t * | len | ||
) | [inherited] |
Turns the receiver on if it not already on.
If there is a valid message available, copy it to buf and return true else return false. If a message is copied, *len is set to the length (Caution, 0 length messages are permitted). 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.
- Returns:
- true if a valid message was copied to buf
boolean 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 41 of file RF22Datagram.cpp.
boolean 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.
If there is a valid message available for this node (or RF22_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 RF22_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 recvived for this node copied to buf
Reimplemented from RF22ReliableDatagram.
Reimplemented in RF22Mesh.
Definition at line 208 of file RF22Router.cpp.
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 |
||
) |
Starts the receiver if it is not running already.
Similar to recvfromAck(), this will block until either a valid 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 RF22ReliableDatagram.
Reimplemented in RF22Mesh.
Definition at line 295 of file RF22Router.cpp.
void reset | ( | ) | [inherited] |
void resetFifos | ( | ) | [protected, inherited] |
void resetRxFifo | ( | ) | [protected, inherited] |
void resetTxFifo | ( | ) | [protected, inherited] |
void restartTransmit | ( | ) | [protected, inherited] |
void retireOldestRoute | ( | ) |
Deletes the oldest (first) route from the local routing table.
Definition at line 143 of file RF22Router.cpp.
uint16_t retransmissions | ( | ) | [inherited] |
Returns the number of retransmissions we have had to send.
- Returns:
- The number of retransmissions since initialisation.
Definition at line 150 of file RF22ReliableDatagram.cpp.
uint8_t route | ( | RoutedMessage * | message, |
uint8_t | messageLen | ||
) | [protected, virtual] |
Finds the next-hop route and sends the message via RF22ReliableDatagram::sendtoWait().
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 RF22Router message to be sent. [in] messageLen Length of message in octets
Reimplemented in RF22Mesh.
Definition at line 182 of file RF22Router.cpp.
uint8_t rssiRead | ( | ) | [inherited] |
Reads and returns the current RSSI value from register RF22_REG_26_RSSI.
If you want to find the RSSI of the last received message, use lastRssi() instead.
- Returns:
- The current RSSI value
boolean send | ( | const uint8_t * | data, |
uint8_t | len | ||
) | [inherited] |
Waits until any previous transmit packet is finished being transmitted with waitPacketSent().
Then loads a message into the transmitter and starts the transmitter. Note that a message length of 0 is NOT permitted.
- Parameters:
-
[in] data Array of data to be sent [in] len Number of bytes of data to send (> 0)
- Returns:
- true if the message length was valid and it was correctly queued for transmit
void sendNextFragment | ( | ) | [protected, inherited] |
boolean sendto | ( | uint8_t * | buf, |
uint8_t | len, | ||
uint8_t | address | ||
) | [inherited] |
Sends a message to the node(s) with the given address RF22_BROADCAST_ADDRESS is a valid address which will cause the message to be accepted by all RF22Datagram 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 was transmitted.
Definition at line 35 of file RF22Datagram.cpp.
uint8_t sendtoWait | ( | uint8_t * | buf, |
uint8_t | len, | ||
uint8_t | dest | ||
) |
Sends a message to the destination node.
Initialises the RF22Router 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 and sends the message to the next hop. 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
- Returns:
- The result code:
- RF22_ROUTER_ERROR_NONE Message was routed and deliverd to the next hop (not necessarily to the final dest address)
- RF22_ROUTER_ERROR_NO_ROUTE There was no route for dest in the local routing table
- RF22_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
Reimplemented from RF22ReliableDatagram.
Reimplemented in RF22Mesh.
Definition at line 158 of file RF22Router.cpp.
uint8_t sendtoWait | ( | uint8_t * | buf, |
uint8_t | len, | ||
uint8_t | dest, | ||
uint8_t | source | ||
) |
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) originatong node address.
- Returns:
- The result code:
- RF22_ROUTER_ERROR_NONE Message was routed and deliverd to the next hop (not necessarily to the final dest address)
- RF22_ROUTER_ERROR_NO_ROUTE There was no route for dest in the local routing table
- RF22_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 165 of file RF22Router.cpp.
boolean setFHChannel | ( | uint8_t | fhch ) | [inherited] |
boolean setFHStepSize | ( | uint8_t | fhs ) | [inherited] |
boolean setFrequency | ( | float | centre, |
float | afcPullInRange = 0.05 |
||
) | [inherited] |
Sets the transmitter and receiver centre frequency.
- Parameters:
-
[in] centre Frequency in MHz. 240.0 to 960.0. Caution, some versions of RF22 and derivatives implemented more restricted frequency ranges. [in] afcPullInRange Sets the AF Pull In Range in MHz. Defaults to 0.05MHz (50kHz). Range is 0.0 to 0.159375 for frequencies 240.0 to 480MHz, and 0.0 to 0.318750MHz for frequencies 480.0 to 960MHz,
- Returns:
- true if the selected frquency centre + (fhch * fhs) is within range and the afcPullInRange is within range
void setHeaderFlags | ( | uint8_t | flags ) | [protected, inherited] |
void setHeaderFrom | ( | uint8_t | from ) | [protected, inherited] |
void setHeaderId | ( | uint8_t | id ) | [protected, inherited] |
void setHeaderTo | ( | uint8_t | to ) | [protected, inherited] |
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.
- Parameters:
-
[in] max_hops The new value for max_hops
Definition at line 42 of file RF22Router.cpp.
void setMode | ( | uint8_t | mode ) | [inherited] |
Sets the parameters for the RF22 Idle mode in register RF22_REG_07_OPERATING_MODE.
Idle mode is the mode the RF22 will be in when not transmitting or receiving. The default idle mode is RF22_XTON ie READY mode.
- Parameters:
-
[in] mode Mask of mode bits, using RF22_SWRES, RF22_ENLBD, RF22_ENWT, RF22_X32KSEL, RF22_PLLON, RF22_XTON.
void setModeIdle | ( | ) | [inherited] |
boolean setModemConfig | ( | ModemConfigChoice | index ) | [inherited] |
Select one of the predefined modem configurations.
If you need a modem configuration not provided here, use setModemRegisters() with your own ModemConfig.
- Parameters:
-
[in] index The configuration choice.
- Returns:
- true if index is a valid choice.
void setModemRegisters | ( | const ModemConfig * | config ) | [inherited] |
Sets all the registered required to configure the data modem in the RF22, including the data rate, bandwidths etc.
You cas use this to configure the modem with custom configuraitons if none of the canned configurations in ModemConfigChoice suit you.
- Parameters:
-
[in] config A ModemConfig structure containing values for the modem configuration registers.
void setModeRx | ( | ) | [inherited] |
void setModeTx | ( | ) | [inherited] |
void setPreambleLength | ( | uint8_t | nibbles ) | [inherited] |
Sets the length of the preamble in 4-bit nibbles.
Caution: this should be set to the same value on all nodes in your network. Default is 8. Sets the message preamble length in RF22_REG_34_PREAMBLE_LENGTH
- Parameters:
-
[in] nibbles Preamble length in nibbles of 4 bits each.
void setPromiscuous | ( | boolean | promiscuous ) | [inherited] |
void setRetries | ( | uint8_t | retries ) | [inherited] |
Sets the max number of retries.
Defaults to 3. If set to 0, the message will only be sent once. sendtoWait will give up and return false if there is no ack received after all transmissions time out. param[in] retries The maximum number a retries.
Definition at line 37 of file RF22ReliableDatagram.cpp.
void setSyncWords | ( | const uint8_t * | syncWords, |
uint8_t | len | ||
) | [inherited] |
Sets the sync words for transmit and receive in registers RF22_REG_36_SYNC_WORD3 to RF22_REG_39_SYNC_WORD0 Caution: this should be set to the same value on all nodes in your network.
Default is { 0x2d, 0xd4 }
- Parameters:
-
[in] syncWords Array of sync words [in] len Number of sync words to set
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. If all the nodes leave the address unset (ie 0), 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 26 of file RF22Datagram.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 31 of file RF22ReliableDatagram.cpp.
void setTxPower | ( | uint8_t | power ) | [inherited] |
Sets the transmitter power output level in register RF22_REG_6D_TX_POWER.
Be a good neighbour and set the lowest power level you need. After init(), the power wil be set to RF22_TXPOW_8DBM. Caution: In some countries you may only select RF22_TXPOW_17DBM if you are also using frequency hopping.
- Parameters:
-
[in] power Transmitter power level, one of RF22_TXPOW_*
void setWutPeriod | ( | uint16_t | wtm, |
uint8_t | wtr = 0 , |
||
uint8_t | wtd = 0 |
||
) | [inherited] |
Sets the wakeup timer period registers RF22_REG_14_WAKEUP_TIMER_PERIOD1, RF22_REG_15_WAKEUP_TIMER_PERIOD2 and RF22_R<EG_16_WAKEUP_TIMER_PERIOD3.
- Parameters:
-
[in] wtm Wakeup timer mantissa value [in] wtr Wakeup timer exponent R value [in] wtd Wakeup timer exponent D value
void spiBurstRead | ( | uint8_t | reg, |
uint8_t * | dest, | ||
uint8_t | len | ||
) | [inherited] |
void spiBurstWrite | ( | uint8_t | reg, |
const uint8_t * | src, | ||
uint8_t | len | ||
) | [inherited] |
uint8_t spiRead | ( | uint8_t | reg ) | [inherited] |
void spiWrite | ( | uint8_t | reg, |
uint8_t | val | ||
) | [inherited] |
void startTransmit | ( | ) | [protected, inherited] |
uint8_t statusRead | ( | ) | [inherited] |
uint8_t temperatureRead | ( | uint8_t | tsrange = RF22_TSRANGE_M64_64C , |
uint8_t | tvoffs = 0 |
||
) | [inherited] |
Reads the on-chip temperature sensoer.
- Parameters:
-
[in] tsrange Specifies the temperature range to use. One of RF22_TSRANGE_* [in] tvoffs Specifies the temperature value offset. This is actually signed value added to the measured temperature value
- Returns:
- The measured temperature.
void waitAvailable | ( | ) | [inherited] |
bool waitAvailableTimeout | ( | uint16_t | timeout ) | [inherited] |
void waitPacketSent | ( | ) | [inherited] |
uint16_t wutRead | ( | ) | [inherited] |
Field Documentation
uint8_t _lastE2ESequenceNumber [protected] |
The last end-to-end sequence number to be used Defaults to 0.
Definition at line 308 of file RF22Router.h.
uint8_t _max_hops [protected] |
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 RF22Router.h.
uint8_t _thisAddress [protected, inherited] |
The address of this node. Defaults to 0.
Definition at line 73 of file RF22Datagram.h.
Generated on Wed Jul 13 2022 22:24:22 by
