HopeRF
Public Member Functions | Protected Attributes | List of all members
HRFDatagram Class Reference

Class for addressed, unreliable messages. More...

#include <HRFDatagram.h>

Inheritance diagram for HRFDatagram:
HRFMessage HRFReliableDatagram

Public Member Functions

 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)
 

Protected Attributes

uint8_t _thisAddress
 The address of this node. Defaults to 0.
 

Detailed Description

Class for addressed, unreliable messages.

Extends HRFMessage to define addressed, unreliable datagrams. Every node has an 8 bit address (defaults to 0). Datagrams have format LEN DEST SRC payload FCS-LO FCS-HI. Addresses (DEST and SRC) are 8 bit integers with an address of HRF_BROADCAST_ADDRESS (0xff) reserved for broadcast.

Part of the Arduino HopeRF library for operating with HopeRF HM-TR transceivers (see http://www.hoperf.com).

Constructor & Destructor Documentation

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

References setThisAddress().

Member Function Documentation

uint8_t HRFDatagram::recv ( uint8_t *  buf,
uint8_t *  len 
)
virtual

If there is a valid message available for this node, copy it to buf and return true else return false. You can't recover the SRC or DEST address with this call, so you would only use it if you do not intend to reply. If a message is copied, *len is set to the length.

Parameters
[in]bufLocation to copy the received message
[in]lenAvailable space in buf. Set to the actual number of octets copied.
Returns
true if a valid message was copied to buf

Reimplemented from HRFMessage.

References recvfrom().

uint8_t HRFDatagram::recvfrom ( uint8_t *  buf,
uint8_t *  len,
uint8_t *  from = NULL,
uint8_t *  to = NULL,
uint8_t  promiscuous = 0 
)
virtual

If there is a message available for this node, copy it to buf and return true If the message was valid (ie good FCS), return true else return false. 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 promiscuous is present and true, all messages will be returned, not just those addressed to this node. If a message is copied, *len is set to the length.

Parameters
[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
[in]promiscuousIf present and true, return all received messages (not just those addressed to this node).
Returns
true if a valid (good FCS) message was copied to buf

References _thisAddress, and HRFMessage::recv().

Referenced by recv(), HRFReliableDatagram::recvfromAck(), and HRFReliableDatagram::sendtoWait().

uint8_t HRFDatagram::sendto ( uint8_t  address,
uint8_t *  buf,
uint8_t  len 
)
virtual

Sends a message to the node(s) with the given address HRF_BROADCAST_ADDRESS is a valid address which will cause the message to be accepted by all HRFDatagram nodes within range.

Parameters
[in]addressThe address to send the message to.
[in]bufPointer to the binary message to send
[in]lenNumber of octets to send
Returns
true if the message was transmitted.
false if the message is too long (>HRF_MAX_DATAGRAM_PAYLOAD).

References _thisAddress, and HRFMessage::send().

Referenced by HRFReliableDatagram::recvfromAck(), and HRFReliableDatagram::sendtoWait().

void HRFDatagram::setThisAddress ( uint8_t  thisAddress)
virtual

Sets the address of this node. Defaults to 0. If all the nodes leave the address unset (ie 0), HRFDatagram acts much the same as HRFMessage (with a bit more overhead). In a conventional multinode system, all nodes will have a unique address (which you could store in EEPROM). However, if you only have 2 nodes in the network, you can leave the addresses of each set to the default of 0.

Parameters
[in]thisAddressThe address of this node

References _thisAddress.

Referenced by HRFDatagram().


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