RF22
|
RF22 subclass for sending addressed, acknowledged, retransmitted datagrams. More...
#include <RF22ReliableDatagram.h>
Public Member Functions | |
RF22ReliableDatagram (uint8_t thisAddress=0, uint8_t slaveSelectPin=SS, uint8_t interrupt=0) | |
void | setTimeout (uint16_t timeout) |
void | setRetries (uint8_t retries) |
boolean | sendtoWait (uint8_t *buf, uint8_t len, uint8_t address) |
boolean | recvfromAck (uint8_t *buf, uint8_t *len, uint8_t *from=NULL, uint8_t *to=NULL, uint8_t *id=NULL, uint8_t *flags=NULL) |
boolean | recvfromAckTimeout (uint8_t *buf, uint8_t *len, uint16_t timeout, uint8_t *from=NULL, uint8_t *to=NULL, uint8_t *id=NULL, uint8_t *flags=NULL) |
uint16_t | retransmissions () |
Public Member Functions inherited from RF22Datagram | |
RF22Datagram (uint8_t thisAddress=0, uint8_t slaveSelectPin=SS, uint8_t interrupt=0) | |
boolean | init () |
void | setThisAddress (uint8_t thisAddress) |
boolean | sendto (uint8_t *buf, uint8_t len, uint8_t address) |
boolean | recvfrom (uint8_t *buf, uint8_t *len, uint8_t *from=NULL, uint8_t *to=NULL, uint8_t *id=NULL, uint8_t *flags=NULL) |
Public Member Functions inherited from RF22 | |
RF22 (uint8_t slaveSelectPin=SS, uint8_t interrupt=0, GenericSPIClass *spi=&Hardware_spi) | |
boolean | init () |
void | reset () |
uint8_t | spiRead (uint8_t reg) |
void | spiWrite (uint8_t reg, uint8_t val) |
void | spiBurstRead (uint8_t reg, uint8_t *dest, uint8_t len) |
void | spiBurstWrite (uint8_t reg, const uint8_t *src, uint8_t len) |
uint8_t | statusRead () |
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) |
uint8_t | temperatureRead (uint8_t tsrange=RF22_TSRANGE_M64_64C, uint8_t tvoffs=0) |
uint16_t | wutRead () |
void | setWutPeriod (uint16_t wtm, uint8_t wtr=0, uint8_t wtd=0) |
boolean | setFrequency (float centre, float afcPullInRange=0.05) |
boolean | setFHStepSize (uint8_t fhs) |
boolean | setFHChannel (uint8_t fhch) |
uint8_t | rssiRead () |
uint8_t | ezmacStatusRead () |
void | setMode (uint8_t mode) |
void | setModeIdle () |
void | setModeRx () |
void | setModeTx () |
uint8_t | mode () |
void | setTxPower (uint8_t power) |
void | setModemRegisters (const ModemConfig *config) |
boolean | setModemConfig (ModemConfigChoice index) |
boolean | available () |
void | waitAvailable () |
bool | waitAvailableTimeout (uint16_t timeout) |
boolean | recv (uint8_t *buf, uint8_t *len) |
boolean | send (const uint8_t *data, uint8_t len) |
void | waitPacketSent () |
bool | waitPacketSent (uint16_t timeout) |
void | setPromiscuous (boolean promiscuous) |
uint8_t | headerTo () |
uint8_t | headerFrom () |
uint8_t | headerId () |
uint8_t | headerFlags () |
uint8_t | lastRssi () |
void | setPreambleLength (uint8_t nibbles) |
void | setSyncWords (const uint8_t *syncWords, uint8_t len) |
boolean | setCRCPolynomial (CRCPolynomial polynomial) |
Protected Member Functions | |
void | acknowledge (uint8_t id, uint8_t from) |
boolean | haveNewMessage () |
Protected Member Functions inherited from RF22 | |
void | handleInterrupt () |
void | clearRxBuf () |
void | clearTxBuf () |
boolean | fillTxBuf (const uint8_t *data, uint8_t len) |
boolean | appendTxBuf (const uint8_t *data, uint8_t len) |
void | sendNextFragment () |
void | readNextFragment () |
void | resetFifos () |
void | resetRxFifo () |
void | resetTxFifo () |
virtual void | handleExternalInterrupt () |
virtual void | handleWakeupTimerInterrupt () |
void | setHeaderTo (uint8_t to) |
void | setHeaderFrom (uint8_t from) |
void | setHeaderId (uint8_t id) |
void | setHeaderFlags (uint8_t flags) |
void | startTransmit () |
void | restartTransmit () |
Additional Inherited Members | |
Public Types inherited from RF22 | |
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, FSK_Rb_512Fd2_5, FSK_Rb_512Fd4_5, 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 } |
enum | CRCPolynomial { CRC_CCITT = 0, CRC_16_IBM = 1, CRC_IEC_16 = 2, CRC_Biacheva = 3 } |
Defines the available choices for CRC Types of permitted CRC polynomials, to be passed to setCRCPolynomial() They deliberately have the same numeric values as the crc[1:0] field of Register RF22_REG_30_DATA_ACCESS_CONTROL. More... | |
Static Public Member Functions inherited from RF22 | |
static void | printBuffer (const char *prompt, const uint8_t *buf, uint8_t len) |
Static Protected Member Functions inherited from RF22 | |
static void | isr0 () |
Low level interrupt service routine for RF22 connected to interrupt 0. | |
static void | isr1 () |
Low level interrupt service routine for RF22 connected to interrupt 1. | |
static void | isr2 () |
Low level interrupt service routine for RF22 connected to interrupt 1. | |
Protected Attributes inherited from RF22Datagram | |
uint8_t | _thisAddress |
The address of this node. Defaults to 0. | |
Protected Attributes inherited from RF22 | |
GenericSPIClass * | _spi |
volatile uint8_t | _mode |
uint8_t | _idleMode |
uint8_t | _slaveSelectPin |
uint8_t | _interrupt |
uint8_t | _deviceType |
CRCPolynomial | _polynomial |
volatile uint8_t | _bufLen |
uint8_t | _buf [RF22_MAX_MESSAGE_LEN] |
volatile boolean | _rxBufValid |
volatile uint8_t | _txBufSentIndex |
volatile uint16_t | _rxBad |
volatile uint16_t | _rxGood |
volatile uint16_t | _txGood |
volatile uint8_t | _lastRssi |
Static Protected Attributes inherited from RF22 | |
static RF22 * | _RF22ForInterrupt [] = {0, 0, 0} |
Array of instances connected to interrupts 0 and 1. | |
RF22 subclass for sending addressed, acknowledged, retransmitted datagrams.
Extends RF22Datagram to define addressed, reliable datagrams with acknowledgement and retransmission. Based on RF22Datagram, adds flags and sequence numbers. RF22ReliableDatagram is reliable in the sense that messages are acknowledged, and unacknowledged messages are retransmitted until acknowledged or the retries are exhausted. When addressed messages are sent (by sendtoWait()), it will wait for an ack, and retransmit after timeout until an ack is received or retries are exhausted. When addressed messages are collected by the application (by recvfromAck()), an acknowledgement is automatically sent.
The retransmit timeout is randomly varied between timeout and timeout*2 to prevent collisions on all retries when 2 nodes happen to start sending at the same time .
Each new message sent by sendtoWait() has its ID incremented.
An ack consists of a message with:
Part of the Arduino RF22 library for operating with HopeRF RF22 compatible transceivers (see http://www.hoperf.com)
RF22ReliableDatagram::RF22ReliableDatagram | ( | uint8_t | thisAddress = 0 , |
uint8_t | slaveSelectPin = SS , |
||
uint8_t | interrupt = 0 |
||
) |
Constructor.
[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) |
|
protected |
Send an ACK for the message id to the given from address Blocks until the ACK has been sent
References RF22Datagram::sendto(), RF22::setHeaderFlags(), RF22::setHeaderId(), and RF22::waitPacketSent().
Referenced by recvfromAck(), and sendtoWait().
|
protected |
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
boolean RF22ReliableDatagram::recvfromAck | ( | uint8_t * | buf, |
uint8_t * | len, | ||
uint8_t * | from = NULL , |
||
uint8_t * | to = NULL , |
||
uint8_t * | id = NULL , |
||
uint8_t * | flags = NULL |
||
) |
If there is a valid message available for this node, send an acknowledgement to the SRC address (blocking until this is complete), then copy the message 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 SRC address is placed in *from. If to is not NULL, the DEST address is placed in *to. 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. 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.
[in] | buf | Location to copy the received message |
[in,out] | len | 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 SRC address |
[in] | to | 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). |
References acknowledge(), RF22::available(), and RF22Datagram::recvfrom().
Referenced by RF22Router::recvfromAck(), and recvfromAckTimeout().
boolean RF22ReliableDatagram::recvfromAckTimeout | ( | uint8_t * | buf, |
uint8_t * | len, | ||
uint16_t | timeout, | ||
uint8_t * | from = NULL , |
||
uint8_t * | to = NULL , |
||
uint8_t * | id = NULL , |
||
uint8_t * | flags = NULL |
||
) |
Similar to recvfromAck(), this will block until either a valid message available for this node or the timeout expires. Starts the receiver automatically. 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.
[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] | from | If present and not NULL, the referenced uint8_t will be set to the SRC address |
[in] | to | 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). |
References recvfromAck().
uint16_t RF22ReliableDatagram::retransmissions | ( | ) |
Returns the number of retransmissions we have had to send
boolean RF22ReliableDatagram::sendtoWait | ( | uint8_t * | buf, |
uint8_t | len, | ||
uint8_t | address | ||
) |
Send the message 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).
[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 |
References RF22Datagram::_thisAddress, acknowledge(), RF22::available(), RF22::clearRxBuf(), RF22::headerFlags(), RF22::headerFrom(), RF22::headerId(), RF22::headerTo(), RF22Datagram::sendto(), RF22::setHeaderFlags(), RF22::setHeaderId(), and RF22::waitPacketSent().
Referenced by RF22Router::route().
void RF22ReliableDatagram::setRetries | ( | uint8_t | retries | ) |
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.
void RF22ReliableDatagram::setTimeout | ( | uint16_t | timeout | ) |
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.
[in] | timeout | The new timeout period in milliseconds |