HopeRF
Public Member Functions | List of all members
HRFMessage Class Reference

Basic message class for HopeRF data transceivers. More...

#include <HRFMessage.h>

Inheritance diagram for HRFMessage:
HRFDatagram HRFReliableDatagram

Public Member Functions

 HRFMessage (HardwareSerial *serial=&Serial)
 
virtual uint8_t send (uint8_t *buf, uint8_t len)
 
virtual uint8_t available ()
 
virtual uint8_t recv (uint8_t *buf, uint8_t *len)
 
virtual uint8_t rx_bad (void)
 
virtual uint8_t rx_good (void)
 
virtual void waitAvailable (void)
 

Detailed Description

Basic message class for HopeRF data transceivers.

Define low level unaddressed, unreliable message. HRFMessage have the format LEN payload FCS-LO FCS-HI. LEN is the total number of octets in the message, including the LEN and FCS octets FCS (16 bits) is the complement of CCITT CRC-16 of all octets in the message, including the LEN HRFMessage is unaddressed, and will be received by all HRFMessage nodes within range.

This class and others in this library provide easy methods for sending and receiving messages using the HM-TR. Several layers of classes are provided above this to provide a range of features from unacknowledged broadcasts to acknowledged, reliable addressed messages.

Although HopeRF HM-TR transceivers have an enable pin, this library make no use of that. Enabling and disabling of the transceiver when it is not required should be done by other code.

Although HopeRF HM-TR transceivers have a Config pin, this library make no use of that, since it must be enabled when the transceiver powers up. This librray assumes the transceiver has already been configured, typically using the HopeRF configuration program.

Constructor & Destructor Documentation

HRFMessage::HRFMessage ( HardwareSerial *  serial = &Serial)

You can have multiple instances for HM-TR modules on multiple HardwareSerial ports.

Parameters
[in]serialThe instance of HardwareSerial to use for IO. Defaults to &Serial, the Arduino default serial port.

Member Function Documentation

uint8_t HRFMessage::available ( )
virtual
Returns
message length if a complete unread message is available
0 (false) if no message is available yet)

Referenced by recv().

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

If a message is available (good checksum or not), copies up to *len octets to buf. If a message is copied, *len is set to the length

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

Reimplemented in HRFDatagram.

References available().

Referenced by HRFDatagram::recvfrom().

uint8_t HRFMessage::rx_bad ( void  )
virtual

The bad message count starts at 0 at instantation time, and is incremented whenever a message with a bad length is received. This generally indicates a corrupt messages.

Returns
the number of corrupt messages received.
uint8_t HRFMessage::rx_good ( void  )
virtual

The good message count starts at 0 at instantation time, and is incremented whenever a complete message is received,

Returns
the number of good messages received.
uint8_t HRFMessage::send ( uint8_t *  buf,
uint8_t  len 
)
virtual

Send a message with the given length. Blocks and returns after the entire message has been sent. Any binary data is permitted.

Parameters
[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_PAYLOAD)

Referenced by HRFDatagram::sendto().

void HRFMessage::waitAvailable ( void  )
virtual

Wait until at least 1 octet is available on the serial device On Arduino, polls the device. On Linux, blocks


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