RadioHead
|
Driver to send and receive unaddressed, unreliable datagrams via sockets on a Linux simulator. More...
#include <RH_TCP.h>
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 | waitPacketSent () |
virtual bool | waitPacketSent (uint16_t timeout) |
virtual bool | waitCAD () |
void | setCADTimeout (unsigned long cad_timeout) |
virtual bool | isChannelActive () |
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. | |
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. | |
Driver to send and receive unaddressed, unreliable datagrams via sockets on a Linux simulator.
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.
You can change the listen port and the simulated baud rate with command line arguments passed to etherSimulator.pl
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.
g++ compiler installed and in your $PATH Perl Perl POE library
RH_TCP::RH_TCP | ( | const char * | server = "localhost:4000" | ) |
Constructor
[in] | server | Name 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. |
|
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
Implements RHGenericDriver.
|
virtual |
Initialise the Driver transport hardware and software. Make sure the Driver is properly configured before calling init().
Reimplemented from RHGenericDriver.
|
virtual |
Returns the maximum message length available in this Driver.
Implements RHGenericDriver.
|
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.
[in] | buf | Location to copy the received message |
[in,out] | len | Pointer to the number of octets available in buf. The number be reset to the actual number of octets copied. |
Implements RHGenericDriver.
|
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.
[in] | data | Array of data to be sent |
[in] | len | Number of bytes of data to send (> 0) |
Implements RHGenericDriver.
|
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).
[in] | address | The address of this node. |
Reimplemented from RHGenericDriver.
|
virtual |
Wait until a new message is available from the driver. Blocks until a complete message is received as reported by available()
[in] | polldelay | Time 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.
|
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()
[in] | timeout | The maximum time to wait in milliseconds |
[in] | polldelay | Time 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.