COSA
An Object-Oriented Platform for Arduino Programming
W5200::Driver Class Reference

#include <W5200.hh>

Inheritance diagram for W5200::Driver:
Inheritance graph
Collaboration diagram for W5200::Driver:
Collaboration graph

Public Types

enum  Protocol {
  TCP = SOCK_STREAM, UDP = SOCK_DGRAM, IPRAW = SOCK_RAW, MACRAW = SOCK_RDM,
  PPPoE = SOCK_SEQPACKET
}
 

Public Member Functions

 Driver ()
 
virtual int available ()
 
virtual int room ()
 
virtual int read (void *buf, size_t size)
 
virtual int flush ()
 
virtual int open (Protocol proto, uint16_t port, uint8_t flag)
 
virtual int close ()
 
virtual int listen ()
 
virtual int accept ()
 
virtual int connect (uint8_t addr[4], uint16_t port)
 
virtual int connect (const char *hostname, uint16_t port)
 
virtual int is_connected ()
 
virtual int disconnect ()
 
virtual int datagram (uint8_t addr[4], uint16_t port)
 
virtual int recv (void *buf, size_t len)
 
virtual int recv (void *buf, size_t len, uint8_t src[4], uint16_t &port)
 
void src (INET::addr_t &addr) const
 
Protocol proto () const
 
uint16_t port () const
 
virtual int write (const void *buf, size_t size)
 
virtual int write (const iovec_t *vec)
 
virtual int write_P (const void *buf, size_t size)
 
virtual int getchar ()
 
virtual int read (iovec_t *vec)
 
int send (const void *buf, size_t len)
 
int send (const void *buf, size_t len, uint8_t dest[4], uint16_t port)
 
int send_P (const void *buf, size_t len)
 
int send_P (const void *buf, size_t len, uint8_t dest[4], uint16_t port)
 
void non_blocking ()
 
void blocking ()
 
bool is_blocking () const
 
void eol (Mode mode)
 
Mode eol () const
 
virtual int putchar (char c)
 
virtual int puts (const char *s)
 
virtual int puts (str_P s)
 
virtual int peekchar ()
 
virtual int peekchar (char c)
 
virtual char * gets (char *s, size_t count)
 
virtual void empty ()
 

Static Public Attributes

static const uint16_t DYNAMIC_PORT = 49152
 

Protected Member Functions

int dev_read (void *buf, size_t len)
 
int dev_write (const void *buf, size_t len, bool progmem)
 
void dev_flush ()
 
void dev_setup ()
 
virtual int write (const void *buf, size_t size, bool progmem)
 
virtual int send (const void *buf, size_t len, bool progmem)
 
virtual int send (const void *buf, size_t len, uint8_t dest[4], uint16_t port, bool progmem)
 

Protected Attributes

SocketRegisterm_sreg
 
W5200m_dev
 
uint16_t m_tx_buf
 
uint16_t m_tx_offset
 
uint16_t m_tx_len
 
uint16_t m_rx_buf
 
INET::addr_t m_src
 
uint8_t m_proto
 
uint16_t m_port
 
bool m_blocking
 
Mode m_eol
 

Friends

class W5200
 

Detailed Description

W5200 Single-Chip Internet-enable 10/100 Ethernet Controller Driver. Implements the Cosa/Socket interface.

Definition at line 370 of file W5200.hh.

Member Enumeration Documentation

enum Socket::Protocol
inherited

Socket type.

Enumerator
TCP 
UDP 
IPRAW 
MACRAW 
PPPoE 

Definition at line 37 of file Socket.hh.

Constructor & Destructor Documentation

W5200::Driver::Driver ( )
inline

Default constructor.

Definition at line 374 of file W5200.hh.

Member Function Documentation

virtual int W5200::Driver::accept ( )
virtual

Check for incoming requests from clients. Return zero if the socket has accepted a request and a connection is established, otherwise a negative error code; -3 listening or connection in progress, -2 illegal protocol, -1 illegal state (socket is closed).

Returns
zero if successful otherwise negative error code.

Implements Socket.

virtual int W5200::Driver::available ( )
virtual

Number of bytes available in receiver buffer.

Returns
bytes.

Reimplemented from IOStream::Device.

void IOStream::Device::blocking ( )
inlineinherited

Set blocking mode.

Definition at line 85 of file IOStream.hh.

virtual int W5200::Driver::close ( )
virtual

Close the socket. Returns zero if successful otherwise negative error code; -2 already closed.

Parameters
[in]protoprotocol.
[in]portsource port.
[in]flagsocket options.
Returns
zero if successful otherwise negative error code.

Implements Socket.

virtual int W5200::Driver::connect ( uint8_t  addr[4],
uint16_t  port 
)
virtual

Connect the socket to the given address and port; client mode. Returns a zero if successful otherwise a negative error code; -2 illegal protocol, -1 address/port not valid.

Parameters
[in]addrdestination address.
[in]portdestination port.
Returns
zero if successful otherwise negative error code.

Implements Socket.

virtual int W5200::Driver::connect ( const char *  hostname,
uint16_t  port 
)
virtual

Connect the socket to the given hostname and port; client mode. Returns zero if connection established otherwise negative error code.

Parameters
[in]hostnamestring.
[in]portdestination port.
Returns
zero if successful otherwise negative error code.

Implements Socket.

virtual int W5200::Driver::datagram ( uint8_t  addr[4],
uint16_t  port 
)
virtual

Start the construction of a datagram to the given address and port. Checks that the socket is connection-less (UDP). Returns zero or negative error code.

Parameters
[in]addrdestination address.
[in]portdestination port.
Returns
zero if successful otherwise negative error code.

Implements Socket.

void W5200::Driver::dev_flush ( )
protected

Flush any waiting data in the socket receiver buffer.

int W5200::Driver::dev_read ( void *  buf,
size_t  len 
)
protected

Read data from the socket receiver buffer to the given buffer with the given maximum size.

Parameters
[in]bufpointer to buffer for data.
[in]lenmaximum number of bytes in buffer.
Returns
number of bytes read if successful otherwise negative error code.
void W5200::Driver::dev_setup ( )
protected

Wait for given maximum message size in internal transmit buffer. Setup transmitter offset and initiate length for new message construction.

int W5200::Driver::dev_write ( const void *  buf,
size_t  len,
bool  progmem 
)
protected

Write data to the socket transmitter buffer from the given buffer with the given number of bytes.

Parameters
[in]bufpointer to buffer with data.
[in]lennumber of bytes in buffer.
[in]progmemprogram memory pointer flag.
Returns
number of bytes written if successful otherwise negative error code.
virtual int W5200::Driver::disconnect ( )
virtual

Disconnect socket from server. Returns zero if successful otherwise a negative error code; -2 illegal protocol.

Returns
zero if successful otherwise negative error code.

Implements Socket.

void IOStream::Device::empty ( )
virtualinherited

Empty internal device buffers.

Reimplemented in Soft::UART, UART, and IOBuffer< SIZE >.

Definition at line 175 of file IOStream_Device.cpp.

void IOStream::Device::eol ( Mode  mode)
inlineinherited

Set end of line mode.

Parameters
[in]modefor end of line.

Definition at line 103 of file IOStream.hh.

Mode IOStream::Device::eol ( ) const
inlineinherited

Get end of line mode.

Returns
mode.

Definition at line 112 of file IOStream.hh.

virtual int W5200::Driver::flush ( )
virtual

Flush internal device buffers. Wait for device to become idle.

Returns
zero(0) or negative error code.

Reimplemented from IOStream::Device.

virtual int Socket::getchar ( )
inlinevirtualinherited

Read character from device.

Returns
character or EOF(-1).

Reimplemented from IOStream::Device.

Definition at line 115 of file Socket.hh.

char * IOStream::Device::gets ( char *  s,
size_t  count 
)
virtualinherited

Read string terminated by new-line or until size into given string buffer. Returns pointer to string or NULL if empty line.

Parameters
[in]sstring buffer to read into.
[in]countmax number of bytes to read.
Returns
string pointer or NULL.

Definition at line 118 of file IOStream_Device.cpp.

bool IOStream::Device::is_blocking ( ) const
inlineinherited

Is blocking mode?

Returns
bool.

Definition at line 94 of file IOStream.hh.

virtual int W5200::Driver::is_connected ( )
virtual

Returns positive integer if a connection is established, zero is not yet established, otherwise a negative error code.

Returns
positive integer connected, zero if not otherwise negative error code.

Implements Socket.

virtual int W5200::Driver::listen ( )
virtual

Mark socket for incoming requests; server mode. Returns zero if successful otherwise negative error code; -2 illegal protocol, -1 failed to mark socket for listen (socket is closed).

Returns
zero if successful otherwise negative error code.

Implements Socket.

void IOStream::Device::non_blocking ( )
inlineinherited

Set non-blocking mode.

Definition at line 77 of file IOStream.hh.

virtual int W5200::Driver::open ( Protocol  proto,
uint16_t  port,
uint8_t  flag 
)
virtual

Initiate socket to the given protocol and possible port. Returns zero if successful otherwise negative error code; -2 already open, -1 failed to open socket.

Parameters
[in]protoprotocol.
[in]portsource port.
[in]flagsocket options.
Returns
zero if successful otherwise negative error code.

Implements Socket.

int IOStream::Device::peekchar ( )
virtualinherited

Peek at the next character from device.

Returns
character or EOF(-1).

Reimplemented in Soft::UART, UART, and IOBuffer< SIZE >.

Definition at line 99 of file IOStream_Device.cpp.

int IOStream::Device::peekchar ( char  c)
virtualinherited

Peek for the given character in device buffer. Return number of characters or EOF(-1).

Parameters
[in]ccharacter to peek for.
Returns
available or EOF(-1).

Reimplemented in Soft::UART, UART, and IOBuffer< SIZE >.

Definition at line 105 of file IOStream_Device.cpp.

uint16_t Socket::port ( ) const
inlineinherited

Get socket port.

Returns
port.

Definition at line 78 of file Socket.hh.

Protocol Socket::proto ( ) const
inlineinherited

Get socket protocol.

Returns
protocol.

Definition at line 69 of file Socket.hh.

int IOStream::Device::putchar ( char  c)
virtualinherited

Write character to device.

Parameters
[in]ccharacter to write.
Returns
character written or EOF(-1).

Reimplemented in FAT16::File, HD44780, ST7565, PCD8544, MAX72XX, VLCD, UART, Textbox, IOBuffer< SIZE >, RS485, WIO, and Soft::UAT.

Definition at line 36 of file IOStream_Device.cpp.

int IOStream::Device::puts ( const char *  s)
virtualinherited

Write null terminated string to device. Terminating null is not written.

Parameters
[in]sstring to write.
Returns
zero(0) or negative error code.

Definition at line 43 of file IOStream_Device.cpp.

int IOStream::Device::puts ( str_P  s)
virtualinherited

Write null terminated string from program memory to device. Terminating null is not written.

Parameters
[in]sstring in program memory to write.
Returns
zero(0) or negative error code.

Definition at line 54 of file IOStream_Device.cpp.

int IOStream::Device::read ( iovec_t vec)
virtualinherited

Read data to given buffers in null terminated io vector.

Parameters
[in]vecio vector with buffers to read into.
Returns
number of bytes read or EOF(-1).

Definition at line 157 of file IOStream_Device.cpp.

virtual int W5200::Driver::read ( void *  buf,
size_t  size 
)
virtual

Read data to given buffer with given size from device.

Parameters
[in]bufbuffer to read into.
[in]sizenumber of bytes to read.
Returns
number of bytes read or EOF(-1).

Reimplemented from Socket.

virtual int W5200::Driver::recv ( void *  buf,
size_t  len 
)
virtual

Receive data from connection-oriented socket. The data is stored in given buffer with given maximum number of bytes. Return number of bytes or negative error code; -3 socket not established, -2 illegal protocol.

Parameters
[in]bufbuffer pointer.
[in]lennumber of bytes in buffer.
Returns
number of bytes sent if successful otherwise negative error code.

Implements Socket.

virtual int W5200::Driver::recv ( void *  buf,
size_t  len,
uint8_t  src[4],
uint16_t &  port 
)
virtual

Receive datagram on connectionless socket into given buffer with given maximum size. Returns zero(0) if successful with information in Datagram otherwise negative error code; -2 illegal protocol.

Parameters
[in]bufbuffer pointer.
[in]lennumber of bytes in buffer.
[in]srcsource address.
[in]portsource port.
Returns
number of bytes received if successful otherwise negative error code.

Implements Socket.

virtual int W5200::Driver::room ( )
virtual

Number of bytes room in transmitter buffer.

Returns
bytes.

Reimplemented from IOStream::Device.

int Socket::send ( const void *  buf,
size_t  len 
)
inlineinherited

Send given data in buffer on connection-oriented socket. Return number of bytes or negative error code.

Parameters
[in]bufbuffer pointer.
[in]lennumber of bytes in buffer.
Returns
number of bytes sent if successful otherwise negative error code.

Definition at line 222 of file Socket.hh.

int Socket::send ( const void *  buf,
size_t  len,
uint8_t  dest[4],
uint16_t  port 
)
inlineinherited

Send given data in buffer on connectionless socket as a datagram to given destination address (dest:port). Return number of bytes sent or negative error code.

Parameters
[in]bufbuffer pointer.
[in]lennumber of bytes in buffer.
[in]destdestination address.
[in]portdestination port.
Returns
number of bytes sent if successful otherwise negative error code.

Definition at line 264 of file Socket.hh.

virtual int W5200::Driver::send ( const void *  buf,
size_t  len,
bool  progmem 
)
protectedvirtual

Send given data in buffer on connection-oriented socket. Boolean flag progmem defined if the buffer is in program memory. Return number of bytes or negative error code; -4 socket closed by peer, -3 connection not estabilished, -2 illegal protocol.

Parameters
[in]bufbuffer pointer.
[in]lennumber of bytes in buffer.
[in]progmemprogram memory pointer flag.
Returns
number of bytes sent if successful otherwise negative error code.

Implements Socket.

virtual int W5200::Driver::send ( const void *  buf,
size_t  len,
uint8_t  dest[4],
uint16_t  port,
bool  progmem 
)
protectedvirtual

Send given data on connectionless socket as a datagram to given destination address (dest:port). Return number of bytes sent or negative error code; -2 illegal protocol, -1 illegal destination address or port.

Parameters
[in]bufbuffer pointer.
[in]lennumber of bytes in buffer.
[in]destdestination address.
[in]portdestination port.
[in]progmemprogram memory pointer flag.
Returns
number of bytes sent if successful otherwise negative error code.

Implements Socket.

int Socket::send_P ( const void *  buf,
size_t  len 
)
inlineinherited

Send given data in program memory buffer on connection-oriented socket. Return number of bytes or negative error code.

Parameters
[in]bufprogram memory pointer.
[in]lennumber of bytes in buffer.
Returns
number of bytes sent if successful otherwise negative error code.

Definition at line 236 of file Socket.hh.

int Socket::send_P ( const void *  buf,
size_t  len,
uint8_t  dest[4],
uint16_t  port 
)
inlineinherited

Send given data in program memory buffer on connectionless socket as a datagram to given destination address (dest:port). Return number of bytes sent or negative error code.

Parameters
[in]bufbuffer pointer.
[in]lennumber of bytes in buffer.
[in]destdestination address.
[in]portdestination port.
Returns
number of bytes sent if successful otherwise negative error code.

Definition at line 281 of file Socket.hh.

void Socket::src ( INET::addr_t addr) const
inlineinherited

Get source machine address, network address and port.

Parameters
[out]addrnetwork address.

Definition at line 60 of file Socket.hh.

virtual int Socket::write ( const void *  buf,
size_t  size 
)
inlinevirtualinherited

Write data from buffer with given size to device.

Parameters
[in]bufbuffer to write.
[in]sizenumber of bytes to write.
Returns
number of bytes written or EOF(-1).

Reimplemented from IOStream::Device.

Reimplemented in CC3000::Driver.

Definition at line 93 of file Socket.hh.

int IOStream::Device::write ( const iovec_t vec)
virtualinherited

Write data from buffers in null terminated io vector.

Parameters
[in]vecio vector with buffers to write.
Returns
number of bytes written or EOF(-1).

Definition at line 87 of file IOStream_Device.cpp.

virtual int W5200::Driver::write ( const void *  buf,
size_t  size,
bool  progmem 
)
protectedvirtual

Write data from buffer with given size to device. Boolean flag progmem defined if the buffer is in program memory. Return number of bytes or negative error code.

Parameters
[in]bufbuffer to write.
[in]sizenumber of bytes to write.
[in]progmemprogram memory pointer flag.
Returns
number of bytes written or EOF(-1).

Reimplemented from Socket.

virtual int Socket::write_P ( const void *  buf,
size_t  size 
)
inlinevirtualinherited

Write data from buffer in program memory with given size to device.

Parameters
[in]bufbuffer to write.
[in]sizenumber of bytes to write.
Returns
number of bytes written or EOF(-1).

Reimplemented from IOStream::Device.

Reimplemented in CC3000::Driver.

Definition at line 105 of file Socket.hh.

Friends And Related Function Documentation

friend class W5200
friend

Definition at line 371 of file W5200.hh.

Member Data Documentation

const uint16_t Socket::DYNAMIC_PORT = 49152
staticinherited

First dynamic, private or ephemeral port number.

Definition at line 34 of file Socket.hh.

bool IOStream::Device::m_blocking
protectedinherited

Blocking state

Definition at line 248 of file IOStream.hh.

W5200* W5200::Driver::m_dev
protected

Pointer to device context.

Definition at line 538 of file W5200.hh.

Mode IOStream::Device::m_eol
protectedinherited

End of line mode

Definition at line 251 of file IOStream.hh.

uint16_t Socket::m_port
protectedinherited

Socket port

Definition at line 308 of file Socket.hh.

uint8_t Socket::m_proto
protectedinherited

Socket protocol if open otherwise zero(0).

Definition at line 305 of file Socket.hh.

uint16_t W5200::Driver::m_rx_buf
protected

Pointer to socket receiver buffer.

Definition at line 550 of file W5200.hh.

INET::addr_t Socket::m_src
protectedinherited

Source address; MAC, IP and port.

Definition at line 302 of file Socket.hh.

SocketRegister* W5200::Driver::m_sreg
protected

Pointer to socket registers; symbolic address calculation.

Definition at line 535 of file W5200.hh.

uint16_t W5200::Driver::m_tx_buf
protected

Pointer to socket transmitter buffer.

Definition at line 541 of file W5200.hh.

uint16_t W5200::Driver::m_tx_len
protected

Length of message in socket transmitter buffer.

Definition at line 547 of file W5200.hh.

uint16_t W5200::Driver::m_tx_offset
protected

Offset in socket transmitter buffer.

Definition at line 544 of file W5200.hh.


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