Public Member Functions | List of all members
HRFReliableDatagram Class Reference

Class for sending addressed, acknowledged, retransmitted datagrams. More...

#include <HRFReliableDatagram.h>

Inheritance diagram for HRFReliableDatagram:
HRFDatagram HRFMessage

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)
- Public Member Functions inherited from HRFDatagram
 HRFDatagram (HardwareSerial *serial=&Serial, uint8_t thisAddress=0)
virtual void setThisAddress (uint8_t thisAddress)
virtual uint8_t sendto (uint8_t address, uint8_t *buf, uint8_t len)
virtual uint8_t recvfrom (uint8_t *buf, uint8_t *len, uint8_t *from=NULL, uint8_t *to=NULL, uint8_t promiscuous=0)
virtual uint8_t recv (uint8_t *buf, uint8_t *len)
- Public Member Functions inherited from HRFMessage
 HRFMessage (HardwareSerial *serial=&Serial)
virtual uint8_t send (uint8_t *buf, uint8_t len)
virtual uint8_t available ()
virtual uint8_t rx_bad (void)
virtual uint8_t rx_good (void)
virtual void waitAvailable (void)

Additional Inherited Members

- Protected Attributes inherited from HRFDatagram
uint8_t _thisAddress
 The address of this node. Defaults to 0.

Detailed Description

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)

Constructor & Destructor Documentation

HRFReliableDatagram::HRFReliableDatagram ( HardwareSerial *  serial = &Serial,
uint8_t  thisAddress = 0 
[in]serialThe instance of HardwareSerial to use for IO. Defaults to &Serial,
[in]thisAddressThe address to assign to this node. Defaults to 0

Member Function Documentation

uint8_t HRFReliableDatagram::recvfromAck ( uint8_t *  buf,
uint8_t *  len,
uint8_t *  from = NULL,
uint8_t *  to = 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.

[in]bufLocation to copy the received message
[in]lenAvailable space in buf. Set to the actual number of octets copied.
[in]fromIf present and not NULL, the referenced uint8_t will be set to the SRC address
[in]toIf 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 

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]addressThe address to send the message to.
[in]bufPointer to the binary message to send
[in]lenNumber of octets to send
true if the message was transmitted and an acknowledgement is received.
false if the message is too long (>HRF_MAX_DATAGRAM_PAYLOAD).

References HRFDatagram::_thisAddress, HRFDatagram::recvfrom(), and HRFDatagram::sendto().

void HRFReliableDatagram::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 if there is no ack received after all transmissions time out. param[in] retries The maximum number a retries.

void HRFReliableDatagram::setTimeout ( long  timeout)

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]timeoutThe new timeout period in milliseconds

The documentation for this class was generated from the following files: