HopeRF
|
Class for sending addressed, acknowledged, retransmitted datagrams. More...
#include <HRFReliableDatagram.h>
Public Member Functions | |
HRFReliableDatagram (HardwareSerial *serial=&Serial, uint8_t thisAddress=0) | |
virtual void | setTimeout (long timeout) |
virtual void | setRetries (uint8_t retries) |
virtual uint8_t | sendtoWait (uint8_t address, uint8_t *buf, uint8_t len) |
virtual uint8_t | recvfromAck (uint8_t *buf, uint8_t *len, uint8_t *from=NULL, uint8_t *to=NULL) |
Class for sending addressed, acknowledged, retransmitted datagrams.
Extends HRFDatagram to define addressed, reliable datagrams with acknowledgement and retransmission. Based on HRFDatagram, adds flags and sequence numbers. HRFReliableDatagram 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 collected by the application (recvfromAck), an acknowledgement is automatically sent. 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 ReliableDatagrams have format LEN DEST SRC FLAG/SQN payload FCS-LO FCS-HI Low 7 bits of FLAG/SQN is the sequence number. Most significant bit is the ACK flag.
Part of the Arduino HopeRF library for operating with HopeRF HM-TR transceivers (see http://www.hoperf.com)
HRFReliableDatagram::HRFReliableDatagram | ( | HardwareSerial * | serial = &Serial , |
uint8_t | thisAddress = 0 |
||
) |
[in] | serial | The instance of HardwareSerial to use for IO. Defaults to &Serial, |
[in] | thisAddress | The address to assign to this node. Defaults to 0 |
uint8_t HRFReliableDatagram::recvfromAck | ( | uint8_t * | buf, |
uint8_t * | len, | ||
uint8_t * | from = NULL , |
||
uint8_t * | to = NULL |
||
) | [virtual] |
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.
[in] | buf | Location to copy the received message |
[in] | 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 |
References HRFDatagram::recvfrom(), and HRFDatagram::sendto().
uint8_t HRFReliableDatagram::sendtoWait | ( | uint8_t | address, |
uint8_t * | buf, | ||
uint8_t | len | ||
) | [virtual] |
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 HRFDatagram::_thisAddress, HRFDatagram::recvfrom(), and HRFDatagram::sendto().
void HRFReliableDatagram::setRetries | ( | uint8_t | retries | ) | [virtual] |
Sets the max number of retries. Defaults to 3. If set to 0, the message will only be sent once. sendtoWait will give up if there is no ack received after all transmissions time out. param[in] retries The maximum number a retries.
void HRFReliableDatagram::setTimeout | ( | long | timeout | ) | [virtual] |
Sets the retransmit timeout. If sendtoWait is waiting for an ack longer than this time (in milliseconds), it will retransmit the message. Defaults to 1000ms. The timeout is measured from the beginning of transmission of the message. It must be longer than the transmit time of the request plus the transmit time of the acknowledgement (6 octets) plus the latency of the receiver.
[in] | timeout | The new timeout period in milliseconds |