RadioHead
Public Member Functions | List of all members
RH_TCP Class Reference

Driver to send and receive unaddressed, unreliable datagrams via sockets on a Linux simulator. More...

#include <RH_TCP.h>

Inheritance diagram for RH_TCP:
RHGenericDriver

Public Member Functions

 RH_TCP (const char *server="localhost:4000")
 
virtual bool init ()
 
virtual bool available ()
 
virtual void waitAvailable (uint16_t polldelay=0)
 
virtual bool waitAvailableTimeout (uint16_t timeout, uint16_t polldelay=0)
 
virtual bool recv (uint8_t *buf, uint8_t *len)
 
virtual bool send (const uint8_t *data, uint8_t len)
 
virtual uint8_t maxMessageLength ()
 
void setThisAddress (uint8_t address)
 
- Public Member Functions inherited from RHGenericDriver
 RHGenericDriver ()
 Constructor.
 
virtual ~RHGenericDriver ()
 Generic destructor to prevent warnings when objects are dynamically allocated.
 
virtual bool init ()
 
virtual bool available ()=0
 
virtual bool recv (uint8_t *buf, uint8_t *len)=0
 
virtual bool send (const uint8_t *data, uint8_t len)=0
 
virtual uint8_t maxMessageLength ()=0
 
virtual void waitAvailable (uint16_t polldelay=0)
 
virtual bool waitPacketSent ()
 
virtual bool waitPacketSent (uint16_t timeout)
 
virtual bool waitAvailableTimeout (uint16_t timeout, uint16_t polldelay=0)
 
virtual bool waitCAD ()
 
void setCADTimeout (unsigned long cad_timeout)
 
virtual bool isChannelActive ()
 
virtual void setThisAddress (uint8_t thisAddress)
 
virtual void setHeaderTo (uint8_t to)
 
virtual void setHeaderFrom (uint8_t from)
 
virtual void setHeaderId (uint8_t id)
 
virtual void setHeaderFlags (uint8_t set, uint8_t clear=RH_FLAGS_APPLICATION_SPECIFIC)
 
virtual void setPromiscuous (bool promiscuous)
 
virtual uint8_t headerTo ()
 
virtual uint8_t headerFrom ()
 
virtual uint8_t headerId ()
 
virtual uint8_t headerFlags ()
 
virtual int16_t lastRssi ()
 
virtual RHMode mode ()
 
virtual void setMode (RHMode mode)
 Sets the operating mode of the transport. More...
 
virtual bool sleep ()
 
virtual uint16_t rxBad ()
 
virtual uint16_t rxGood ()
 
virtual uint16_t txGood ()
 

Additional Inherited Members

- Public Types inherited from RHGenericDriver
enum  RHMode {
  RHModeInitialising = 0 , RHModeSleep , RHModeIdle , RHModeTx ,
  RHModeRx , RHModeCad
}
 Defines different operating modes for the transport hardware. More...
 
- Static Public Member Functions inherited from RHGenericDriver
static void printBuffer (const char *prompt, const uint8_t *buf, uint8_t len)
 
- Protected Attributes inherited from RHGenericDriver
volatile RHMode _mode
 The current transport operating mode.
 
uint8_t _thisAddress
 This node id.
 
bool _promiscuous
 Whether the transport is in promiscuous mode.
 
volatile uint8_t _rxHeaderTo
 TO header in the last received mesasge.
 
volatile uint8_t _rxHeaderFrom
 FROM header in the last received mesasge.
 
volatile uint8_t _rxHeaderId
 ID header in the last received mesasge.
 
volatile uint8_t _rxHeaderFlags
 FLAGS header in the last received mesasge.
 
uint8_t _txHeaderTo
 TO header to send in all messages.
 
uint8_t _txHeaderFrom
 FROM header to send in all messages.
 
uint8_t _txHeaderId
 ID header to send in all messages.
 
uint8_t _txHeaderFlags
 FLAGS header to send in all messages.
 
volatile int16_t _lastRssi
 The value of the last received RSSI value, in some transport specific units.
 
volatile uint16_t _rxBad
 Count of the number of bad messages (eg bad checksum etc) received.
 
volatile uint16_t _rxGood
 Count of the number of successfully transmitted messaged.
 
volatile uint16_t _txGood
 Count of the number of bad messages (correct checksum etc) received.
 
volatile bool _cad
 Channel activity detected.
 
unsigned int _cad_timeout
 Channel activity timeout in ms.
 

Detailed Description

Driver to send and receive unaddressed, unreliable datagrams via sockets on a Linux simulator.

Overview

This class is intended to support the testing of RadioHead manager classes and simulated sketches on a Linux host. RH_TCP class sends messages to and from other simulator sketches via sockets to a 'Luminiferous Ether' simulator server (provided). Multiple instances of simulated clients and servers can run on a single Linux server, passing messages to each other via the etherSimulator.pl server.

Simple RadioHead sketches can be compiled and run on Linux using a build script and some support files.

Running simulated sketches
cd whatever/RadioHead
# build the client for Linux:
tools/simBuild examples/simulator/simulator_reliable_datagram_client/simulator_reliable_datagram_client.ino
# build the server for Linux:
tools/simBuild examples/simulator/simulator_reliable_datagram_server/simulator_reliable_datagram_server.ino
# in one window, run the simulator server:
tools/etherSimulator.pl
# in another window, run the server
./simulator_reliable_datagram_server
# in another window, run the client:
./simulator_reliable_datagram_client
# see output:
Sending to simulator_reliable_datagram_server
got reply from : 0x02: And hello back to you
Sending to simulator_reliable_datagram_server
got reply from : 0x02: And hello back to you
Sending to simulator_reliable_datagram_server
got reply from : 0x02: And hello back to you
...

You can change the listen port and the simulated baud rate with command line arguments passed to etherSimulator.pl

Implementation

etherServer.pl is a conventional server written in Perl. listens on a TCP socket (defaults to port 4000) for connections from sketch simulators using RH_TCP as theur driver. The simulated sketches send messages out to the 'ether' over the TCP connection to the etherServer. etherServer manages the delivery of each message to any other RH_TCP sketches that are running.

Prerequisites

g++ compiler installed and in your $PATH Perl Perl POE library

Constructor & Destructor Documentation

◆ RH_TCP()

RH_TCP::RH_TCP ( const char *  server = "localhost:4000")

Constructor

Parameters
[in]serverName and optionally the port number of the ether simulator server to contact. Format is "name[:port]", where name can be any valid host name or address (IPV4 or IPV6). The trailing :port is optional, and port can be any valid port name or port number.

Member Function Documentation

◆ available()

virtual bool RH_TCP::available ( )
virtual

Tests whether a new message is available from the Driver. On most drivers, this will also put the Driver into RHModeRx mode until a message is actually received by the transport, when it will be returned to RHModeIdle. This can be called multiple times in a timeout loop

Returns
true if a new, complete, error-free uncollected message is available to be retreived by recv()

Implements RHGenericDriver.

◆ init()

virtual bool RH_TCP::init ( )
virtual

Initialise the Driver transport hardware and software. Make sure the Driver is properly configured before calling init().

Returns
true if initialisation succeeded.

Reimplemented from RHGenericDriver.

◆ maxMessageLength()

virtual uint8_t RH_TCP::maxMessageLength ( )
virtual

Returns the maximum message length available in this Driver.

Returns
The maximum legal message length

Implements RHGenericDriver.

◆ recv()

virtual bool RH_TCP::recv ( uint8_t *  buf,
uint8_t *  len 
)
virtual

Turns the receiver on if it not already on. If there is a valid message available, copy it to buf and return true else return false. If a message is copied, *len is set to the length (Caution, 0 length messages are permitted). 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.

Parameters
[in]bufLocation to copy the received message
[in,out]lenPointer to the number of octets available in buf. The number be reset to the actual number of octets copied.
Returns
true if a valid message was copied to buf

Implements RHGenericDriver.

◆ send()

virtual bool RH_TCP::send ( const uint8_t *  data,
uint8_t  len 
)
virtual

Waits until any previous transmit packet is finished being transmitted with waitPacketSent(). Then loads a message into the transmitter and starts the transmitter. Note that a message length of 0 is NOT permitted. If the message is too long for the underlying radio technology, send() will return false and will not send the message.

Parameters
[in]dataArray of data to be sent
[in]lenNumber of bytes of data to send (> 0)
Returns
true if the message length was valid and it was correctly queued for transmit

Implements RHGenericDriver.

◆ setThisAddress()

void RH_TCP::setThisAddress ( uint8_t  address)
virtual

Sets the address of this node. Defaults to 0xFF. Subclasses or the user may want to change this. This will be used to test the adddress in incoming messages. In non-promiscuous mode, only messages with a TO header the same as thisAddress or the broadcast addess (0xFF) will be accepted. In promiscuous mode, all messages will be accepted regardless of the TO header. In a conventional multinode system, all nodes will have a unique address (which you could store in EEPROM). You would normally set the header FROM address to be the same as thisAddress (though you dont have to, allowing the possibilty of address spoofing).

Parameters
[in]addressThe address of this node.

Reimplemented from RHGenericDriver.

◆ waitAvailable()

virtual void RH_TCP::waitAvailable ( uint16_t  polldelay = 0)
virtual

Wait until a new message is available from the driver. Blocks until a complete message is received as reported by available()

Parameters
[in]polldelayTime between polling available() in milliseconds. This can be useful in multitaking environment like Linux to prevent waitAvailableTimeout using all the CPU while polling for receiver activity

Reimplemented from RHGenericDriver.

◆ waitAvailableTimeout()

virtual bool RH_TCP::waitAvailableTimeout ( uint16_t  timeout,
uint16_t  polldelay = 0 
)
virtual

Wait until a new message is available from the driver or the timeout expires Blocks until a complete message is received as reported by available()

Parameters
[in]timeoutThe maximum time to wait in milliseconds
[in]polldelayTime between polling available() in milliseconds. This can be useful in multitaking environment like Linux to prevent waitAvailableTimeout using all the CPU while polling for receiver activity
Returns
true if a message is available as reported by available()

Reimplemented from RHGenericDriver.


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