W5500 from SeeedStudio on NUCLEO-L476RG
Dependents: coap-example Borsch coap-example
Fork of W5500Interface by
W5500Interface Class Reference
W5500Interface class Implementation of the NetworkStack for the W5500. More...
#include <W5500Interface.h>
Inherits WIZnet_Chip.
Public Member Functions | |
virtual int | connect () |
Start the interface. | |
virtual int | disconnect () |
Stop the interface. | |
virtual const char * | get_ip_address () |
Get the internally stored IP address. | |
void | get_mac (uint8_t mac[6]) |
Get MAC address and fill mac with it. | |
virtual const char * | get_mac_address () |
Get the internally stored MAC address. | |
Protected Member Functions | |
virtual nsapi_error_t | socket_open (nsapi_socket_t *handle, nsapi_protocol_t proto) |
Opens a socket. | |
virtual nsapi_error_t | socket_close (nsapi_socket_t handle) |
Close the socket. | |
virtual nsapi_error_t | socket_bind (nsapi_socket_t handle, const SocketAddress &address) |
Bind a specific address to a socket. | |
virtual nsapi_error_t | socket_listen (nsapi_socket_t handle, int backlog) |
Listen for connections on a TCP socket. | |
virtual nsapi_error_t | socket_connect (nsapi_socket_t handle, const SocketAddress &address) |
Connects TCP socket to a remote host. | |
virtual nsapi_error_t | socket_accept (nsapi_socket_t server, nsapi_socket_t *handle, SocketAddress *address=0) |
Accepts a connection on a TCP socket. | |
virtual nsapi_size_or_error_t | socket_send (nsapi_socket_t handle, const void *data, nsapi_size_t size) |
Send data over a TCP socket. | |
virtual nsapi_size_or_error_t | socket_recv (nsapi_socket_t handle, void *data, nsapi_size_t size) |
Receive data over a TCP socket. | |
virtual nsapi_size_or_error_t | socket_sendto (nsapi_socket_t handle, const SocketAddress &address, const void *data, nsapi_size_t size) |
Send a packet over a UDP socket. | |
virtual nsapi_size_or_error_t | socket_recvfrom (nsapi_socket_t handle, SocketAddress *address, void *buffer, nsapi_size_t size) |
Receive a packet over a UDP socket. | |
virtual void | socket_attach (nsapi_socket_t handle, void(*callback)(void *), void *data) |
Register a callback on state change of the socket. |
Detailed Description
W5500Interface class Implementation of the NetworkStack for the W5500.
Definition at line 42 of file W5500Interface.h.
Member Function Documentation
int connect | ( | ) | [virtual] |
Start the interface.
- Returns:
- 0 on success, negative on failure
Definition at line 164 of file W5500Interface.cpp.
int disconnect | ( | ) | [virtual] |
Stop the interface.
- Returns:
- 0 on success, negative on failure
Definition at line 170 of file W5500Interface.cpp.
const char * get_ip_address | ( | ) | [virtual] |
Get the internally stored IP address.
- Returns:
- IP address of the interface or null if not yet connected
Definition at line 176 of file W5500Interface.cpp.
void get_mac | ( | uint8_t | mac[6] ) |
Get MAC address and fill mac with it.
Definition at line 191 of file W5500Interface.cpp.
const char * get_mac_address | ( | ) | [virtual] |
Get the internally stored MAC address.
- Returns:
- MAC address of the interface
Definition at line 183 of file W5500Interface.cpp.
nsapi_error_t socket_accept | ( | nsapi_socket_t | server, |
nsapi_socket_t * | handle, | ||
SocketAddress * | address = 0 |
||
) | [protected, virtual] |
Accepts a connection on a TCP socket.
The server socket must be bound and set to listen for connections. On a new connection, creates a network socket and stores it in the specified handle. The handle must be passed to following calls on the socket.
A stack may have a finite number of sockets, in this case NSAPI_ERROR_NO_SOCKET is returned if no socket is available.
This call is non-blocking. If accept would block, NSAPI_ERROR_WOULD_BLOCK is returned immediately.
- Parameters:
-
server Socket handle to server to accept from handle Destination for a handle to the newly created socket address Destination for the remote address or NULL
- Returns:
- 0 on success, negative error code on failure
Definition at line 309 of file W5500Interface.cpp.
virtual void socket_attach | ( | nsapi_socket_t | handle, |
void(*)(void *) | callback, | ||
void * | data | ||
) | [protected, virtual] |
Register a callback on state change of the socket.
The specified callback will be called on state changes such as when the socket can recv/send/accept successfully and on when an error occurs. The callback may also be called spuriously without reason.
The callback may be called in an interrupt context and should not perform expensive operations such as recv/send calls.
- Parameters:
-
handle Socket handle callback Function to call on state change data Argument to pass to callback
nsapi_error_t socket_bind | ( | nsapi_socket_t | handle, |
const SocketAddress & | address | ||
) | [protected, virtual] |
Bind a specific address to a socket.
Binding a socket specifies the address and port on which to recieve data. If the IP address is zeroed, only the port is bound.
- Parameters:
-
handle Socket handle address Local address to bind
- Returns:
- 0 on success, negative error code on failure.
Definition at line 240 of file W5500Interface.cpp.
nsapi_error_t socket_close | ( | nsapi_socket_t | handle ) | [protected, virtual] |
Close the socket.
Closes any open connection and deallocates any memory associated with the socket.
- Parameters:
-
handle Socket handle
- Returns:
- 0 on success, negative error code on failure
Definition at line 229 of file W5500Interface.cpp.
nsapi_size_or_error_t socket_connect | ( | nsapi_socket_t | handle, |
const SocketAddress & | address | ||
) | [protected, virtual] |
Connects TCP socket to a remote host.
Initiates a connection to a remote server specified by the indicated address.
- Parameters:
-
handle Socket handle address The SocketAddress of the remote host
- Returns:
- 0 on success, negative error code on failure
Definition at line 287 of file W5500Interface.cpp.
nsapi_error_t socket_listen | ( | nsapi_socket_t | handle, |
int | backlog | ||
) | [protected, virtual] |
Listen for connections on a TCP socket.
Marks the socket as a passive socket that can be used to accept incoming connections.
- Parameters:
-
handle Socket handle backlog Number of pending connections that can be queued simultaneously
- Returns:
- 0 on success, negative error code on failure
Definition at line 274 of file W5500Interface.cpp.
nsapi_error_t socket_open | ( | nsapi_socket_t * | handle, |
nsapi_protocol_t | proto | ||
) | [protected, virtual] |
Opens a socket.
Creates a network socket and stores it in the specified handle. The handle must be passed to following calls on the socket.
A stack may have a finite number of sockets, in this case NSAPI_ERROR_NO_SOCKET is returned if no socket is available.
- Parameters:
-
handle Destination for the handle to a newly created socket proto Protocol of socket to open, NSAPI_TCP or NSAPI_UDP
- Returns:
- 0 on success, negative error code on failure
Definition at line 196 of file W5500Interface.cpp.
nsapi_size_or_error_t socket_recv | ( | nsapi_socket_t | handle, |
void * | data, | ||
nsapi_size_t | size | ||
) | [protected, virtual] |
Receive data over a TCP socket.
The socket must be connected to a remote host. Returns the number of bytes received into the buffer.
This call is non-blocking. If recv would block, NSAPI_ERROR_WOULD_BLOCK is returned immediately.
- Parameters:
-
handle Socket handle data Destination buffer for data received from the host size Size of the buffer in bytes
- Returns:
- Number of received bytes on success, negative error code on failure
Definition at line 406 of file W5500Interface.cpp.
nsapi_size_or_error_t socket_recvfrom | ( | nsapi_socket_t | handle, |
SocketAddress * | address, | ||
void * | buffer, | ||
nsapi_size_t | size | ||
) | [protected, virtual] |
Receive a packet over a UDP socket.
Receives data and stores the source address in address if address is not NULL. Returns the number of bytes received into the buffer.
This call is non-blocking. If recvfrom would block, NSAPI_ERROR_WOULD_BLOCK is returned immediately.
- Parameters:
-
handle Socket handle address Destination for the source address or NULL data Destination buffer for data received from the host size Size of the buffer in bytes
- Returns:
- Number of received bytes on success, negative error code on failure
Definition at line 468 of file W5500Interface.cpp.
nsapi_size_or_error_t socket_send | ( | nsapi_socket_t | handle, |
const void * | data, | ||
nsapi_size_t | size | ||
) | [protected, virtual] |
Send data over a TCP socket.
The socket must be connected to a remote host. Returns the number of bytes sent from the buffer.
This call is non-blocking. If send would block, NSAPI_ERROR_WOULD_BLOCK is returned immediately.
- Parameters:
-
handle Socket handle data Buffer of data to send to the host size Size of the buffer in bytes
- Returns:
- Number of sent bytes on success, negative error code on failure
Definition at line 384 of file W5500Interface.cpp.
nsapi_size_or_error_t socket_sendto | ( | nsapi_socket_t | handle, |
const SocketAddress & | address, | ||
const void * | data, | ||
nsapi_size_t | size | ||
) | [protected, virtual] |
Send a packet over a UDP socket.
Sends data to the specified address. Returns the number of bytes sent from the buffer.
This call is non-blocking. If sendto would block, NSAPI_ERROR_WOULD_BLOCK is returned immediately.
- Parameters:
-
handle Socket handle address The SocketAddress of the remote host data Buffer of data to send to the host size Size of the buffer in bytes
- Returns:
- Number of sent bytes on success, negative error code on failure
Definition at line 426 of file W5500Interface.cpp.
Generated on Fri Jul 15 2022 13:32:25 by 1.7.2