RF24Ethernet - TCP/IP over RF24Network v2.0.3
TMRh20 - Pushing the practical limits of RF24 modules
Loading...
Searching...
No Matches
RF24Client Class Reference

#include <RF24Client.h>

Inheritance diagram for RF24Client:
Collaboration diagram for RF24Client:

Classes

struct  ConnectState

Public Member Functions

 RF24Client ()
int connect (IPAddress ip, uint16_t port)
int connect (const char *host, uint16_t port)
int read (uint8_t *buf, size_t size)
int read ()
void stop ()
uint8_t connected ()
size_t write (uint8_t)
size_t write (const uint8_t *buf, size_t size)
int available ()
int waitAvailable (uint32_t timeout=750)
int peek ()
void flush ()
 operator bool ()
virtual bool operator== (const EthernetClient &)
virtual bool operator!= (const EthernetClient &rhs)

Protected Member Functions

struct RF24Client::ConnectState __attribute__ ((packed))

Static Protected Member Functions

static err_t sent_callback (void *arg, struct tcp_pcb *tpcb, uint16_t len)
static err_t recv_callback (void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
static err_t srecv_callback (void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
static void error_callback (void *arg, err_t err)

Static Protected Attributes

static ConnectStategState [2]
static bool activeState

Friends

class RF24EthernetClass
class RF24Server

Detailed Description

Definition at line 95 of file RF24Client.h.

Constructor & Destructor Documentation

◆ RF24Client()

RF24Client::RF24Client ( )

Basic constructor

Definition at line 589 of file RF24Client.cpp.

Referenced by operator==().

Member Function Documentation

◆ connect() [1/2]

int RF24Client::connect ( IPAddress ip,
uint16_t port )

Establish a connection to a specified IP address and port

Definition at line 623 of file RF24Client.cpp.

References activeState, error_callback(), Ethernet, finished, gState, IF_RF24ETHERNET_DEBUG_CLIENT, recv_callback(), result, stop(), and UIP_CONNECTION_TIMEOUT.

Referenced by connect().

◆ connect() [2/2]

int RF24Client::connect ( const char * host,
uint16_t port )

Establish a connection to a given hostname and port

Note
With slower devices < 50Mhz, or if using the uIP stack, UDP must be enabled in uip-conf.h for DNS lookups to work
Tip: DNS lookups generally require a buffer size of 250-300 bytes or greater. Lookups will generally return responses with a single A record if using hostnames like "www.google.com" instead of "google.com" which works well with the default buffer size

Definition at line 780 of file RF24Client.cpp.

References DNSClient::begin(), connect(), and DNSClient::getHostByName().

◆ read() [1/2]

int RF24Client::read ( uint8_t * buf,
size_t size )

Read available data into a buffer

uint8_t buf[size];
client.read(buf,size);

Definition at line 1306 of file RF24Client.cpp.

References activeState, available(), and IF_ETH_DEBUG_L2.

◆ read() [2/2]

int RF24Client::read ( )

Read data one byte at a time

char c = client.read();

Definition at line 1376 of file RF24Client.cpp.

References read().

Referenced by flush(), and read().

◆ stop()

void RF24Client::stop ( )

Disconnects from the current active connection

Definition at line 832 of file RF24Client.cpp.

References IF_RF24ETHERNET_DEBUG_CLIENT, and RF24Ethernet.

Referenced by connect().

◆ connected()

uint8_t RF24Client::connected ( )

Indicates whether the client is connected or not When using slower devices < 50MHz (uIP stack) there is a default connection timeout of 45 seconds. If data is not received or sent successfully within that timeframe the client will be disconnected. With faster devices > 50Mhz (lwIP stack), there is NO default connection timeout. Use the clientConnectionTimeout functions to set the timeout on connect or disconnect, and utilize application side timeouts to disconnect as necessary after a connection has been established.

Definition at line 609 of file RF24Client.cpp.

References activeState, and gState.

◆ write() [1/2]

size_t RF24Client::write ( uint8_t c)

Write a single byte of data to the stream

Note
This will write an entire TCP payload with only 1 byte in it

Definition at line 926 of file RF24Client.cpp.

◆ write() [2/2]

size_t RF24Client::write ( const uint8_t * buf,
size_t size )

Write a buffer of data, to be sent in a single TCP packet

Definition at line 933 of file RF24Client.cpp.

◆ available()

int RF24Client::available ( )

Indicates whether data is available to be read by the client.

Returns
Returns the number of bytes available to be read
Note
Calling client or server available() keeps the IP stack and RF24Network layer running, so needs to be called regularly, even when disconnected or delaying for extended periods.

Definition at line 1272 of file RF24Client.cpp.

References RF24Ethernet.

Referenced by flush(), peek(), read(), and waitAvailable().

◆ waitAvailable()

int RF24Client::waitAvailable ( uint32_t timeout = 750)

Wait Available

Helps to ensure all incoming data has been received, prior to writing data back to the client, etc.

Indicates whether data is available to be read by the client, after waiting a maximum period of time.

Returns
Returns the number of bytes available to be read or 0 if timed out
Note
Calling client or server available() keeps the IP stack and RF24Network layer running, so needs to be called regularly, even when disconnected or delaying for extended periods.

Definition at line 1256 of file RF24Client.cpp.

References available(), and RF24Ethernet.

◆ peek()

int RF24Client::peek ( )

Read a byte from the incoming buffer without advancing the point of reading

Definition at line 1386 of file RF24Client.cpp.

References activeState, and available().

◆ flush()

void RF24Client::flush ( )

Flush all incoming client data from the current connection/buffer

Definition at line 1401 of file RF24Client.cpp.

References available(), and read().

◆ operator bool()

RF24Client::operator bool ( )

Definition at line 914 of file RF24Client.cpp.

References activeState, and Ethernet.

◆ operator==()

bool RF24Client::operator== ( const EthernetClient & )
virtual

Definition at line 903 of file RF24Client.cpp.

References activeState, and RF24Client().

Referenced by __attribute__().

◆ operator!=()

virtual bool RF24Client::operator!= ( const EthernetClient & rhs)
inlinevirtual

Definition at line 183 of file RF24Client.h.

◆ __attribute__()

struct RF24Client::ConnectState RF24Client::__attribute__ ( (packed) )
protected

References EthernetClient, and operator==().

◆ sent_callback()

err_t RF24Client::sent_callback ( void * arg,
struct tcp_pcb * tpcb,
uint16_t len )
staticprotected

Used internally when data is ACKed

◆ recv_callback()

err_t RF24Client::recv_callback ( void * arg,
struct tcp_pcb * tpcb,
struct pbuf * p,
err_t err )
staticprotected

Used internally for receiving data via the client functions

Referenced by connect().

◆ srecv_callback()

err_t RF24Client::srecv_callback ( void * arg,
struct tcp_pcb * tpcb,
struct pbuf * p,
err_t err )
staticprotected

Used internally for receiving data via the server functions

◆ error_callback()

void RF24Client::error_callback ( void * arg,
err_t err )
staticprotected

Used internally when there is an error

Referenced by RF24Server::begin(), connect(), and RF24EthernetClass::listen().

◆ RF24EthernetClass

friend class RF24EthernetClass
friend

Definition at line 281 of file RF24Client.h.

References RF24EthernetClass.

Referenced by RF24EthernetClass.

◆ RF24Server

friend class RF24Server
friend

Definition at line 282 of file RF24Client.h.

References RF24Server.

Referenced by RF24Server.

Member Data Documentation

◆ gState

ConnectState* RF24Client::gState[2]
staticprotected

◆ activeState

bool RF24Client::activeState
staticprotected

Used to set client timeouts. Whenever there is no data sent, received, or acked in the given timeout period (mS) the connection will be closed. Set to 0 to disable

Definition at line 233 of file RF24Client.h.

Referenced by connect(), connected(), operator bool(), operator==(), peek(), and read().