increased chunk size

Dependencies:   HTTPClient-SSL

Fork of MTS-Socket by MultiTech

Embed: (wiki syntax)

« Back to documentation index

IPStack Class Reference

IPStack Class Reference

This class is a pure virtual class that should be inherited from when implementing a communications device with an onboard IP stack. More...

#include <IPStack.h>

Inherits CommInterface.

Public Types

enum  Mode
 

An enumeration for selecting the Socket Mode of TCP or UDP.

More...

Public Member Functions

virtual bool bind (unsigned int port)=0
 This method is used to set the local port for the UDP or TCP socket connection.
virtual bool open (const std::string &address, unsigned int port, Mode mode)=0
 This method is used to open a socket connection with the given parameters.
virtual bool isOpen ()=0
 This method is used to determine if a socket connection is currently open.
virtual bool close (bool clearBuffer)=0
 This method is used to close a socket connection that is currently open.
virtual int read (char *data, int max, int timeout=-1)=0
 This method is used to read data off of a socket, assuming a valid socket connection is already open.
virtual int write (const char *data, int length, int timeout=-1)=0
 This method is used to write data to a socket, assuming a valid socket connection is already open.
virtual unsigned int readable ()=0
 This method is used to get the number of bytes available to read off the socket.
virtual unsigned int writeable ()=0
 This method is used to get the space available to write bytes to the socket.
virtual bool ping (const std::string &address="8.8.8.8")=0
 This method is used test network connectivity by pinging a server.
virtual std::string getDeviceIP ()=0
 This method is used to get the IP address of the device, which can be set either statically or via DHCP after connecting to a network.
virtual bool setDeviceIP (std::string address="DHCP")=0
 This method is used to set the IP address or puts the module in DHCP mode.
virtual bool connect ()=0
 This method is used to establish a connection on a communications link.
virtual void disconnect ()=0
 This method is used to disconnect a communications like.
virtual bool isConnected ()=0
 This method is used to check if the link is currently connected.
virtual void reset ()=0
 This method is used to reset the device that provides the communications capability.

Detailed Description

This class is a pure virtual class that should be inherited from when implementing a communications device with an onboard IP stack.

Examples of this would be a Wi-Fi or Cellular radio. The inheriting class should map the device commands and functionality to the pure virtual methods provided here. There should also be at least one or more calls to setup the communication link specific paramters as an init method for example. This would do things like configure the APN in a cellular radio or set the ssid for a WiFi device, which cannot be accounted for in an abstract class like this one. Note that to provide physical connection management methods this class inherits from CommInterface.

Definition at line 16 of file IPStack.h.


Member Enumeration Documentation

enum Mode

An enumeration for selecting the Socket Mode of TCP or UDP.

Definition at line 20 of file IPStack.h.


Member Function Documentation

virtual bool bind ( unsigned int  port ) [pure virtual]

This method is used to set the local port for the UDP or TCP socket connection.

The connection can be made using the open method.

Parameters:
portthe local port of the socket as an int.
virtual bool close ( bool  clearBuffer ) [pure virtual]

This method is used to close a socket connection that is currently open.

Returns:
true if successfully closed, otherwise returns false on an error.
virtual bool connect (  ) [pure virtual, inherited]

This method is used to establish a connection on a communications link.

Required configurations and settings should be done in other calls or an init function.

Returns:
true if the connection was successfully established, otherwise false.
virtual void disconnect (  ) [pure virtual, inherited]

This method is used to disconnect a communications like.

This includes any cleanup required before another connection can be made.

virtual std::string getDeviceIP (  ) [pure virtual]

This method is used to get the IP address of the device, which can be set either statically or via DHCP after connecting to a network.

Returns:
the devices IP address.
virtual bool isConnected (  ) [pure virtual, inherited]

This method is used to check if the link is currently connected.

Returns:
true if currently connected, otherwise false.
virtual bool isOpen (  ) [pure virtual]

This method is used to determine if a socket connection is currently open.

Returns:
true if the socket is currently open, otherwise false.
virtual bool open ( const std::string &  address,
unsigned int  port,
Mode  mode 
) [pure virtual]

This method is used to open a socket connection with the given parameters.

Parameters:
addressis the address you want to connect to in the form of xxx.xxx.xxx.xxx or a URL. If using a URL make sure the device supports DNS and is properly configured for that mode.
portthe remote port you want to connect to.
modean enum that specifies whether this socket connection is type TCP or UDP.
Returns:
true if the connection was successfully opened, otherwise false.
virtual bool ping ( const std::string &  address = "8.8.8.8" ) [pure virtual]

This method is used test network connectivity by pinging a server.

Parameters:
addressthe address of the server in format xxx.xxx.xxx.xxx. The default 8.8.8.8 which is Google's DNS Server.
Returns:
true if the ping was successful, otherwise false.
virtual int read ( char *  data,
int  max,
int  timeout = -1 
) [pure virtual]

This method is used to read data off of a socket, assuming a valid socket connection is already open.

Parameters:
dataa pointer to the data buffer that will be filled with the read data.
maxthe maximum number of bytes to attempt to read, typically the same as the size of the passed in data buffer.
timeoutthe amount of time in milliseconds to wait in trying to read the max number of bytes. If set to -1 the call blocks until it receives the max number of bytes or encounters and error.
Returns:
the number of bytes read and stored in the passed in data buffer. Returns -1 if there was an error in reading.
virtual unsigned int readable (  ) [pure virtual]

This method is used to get the number of bytes available to read off the socket.

Returns:
the number of bytes available, 0 if there are no bytes to read.
virtual void reset (  ) [pure virtual, inherited]

This method is used to reset the device that provides the communications capability.

Note that this call should block until the commincations device is ready for use.

virtual bool setDeviceIP ( std::string  address = "DHCP" ) [pure virtual]

This method is used to set the IP address or puts the module in DHCP mode.

Parameters:
addressthe IP address you want to use in the form of xxx.xxx.xxx.xxx or DHCP if you want to use DHCP. The default is DHCP.
Returns:
true if successful, otherwise returns false.
virtual int write ( const char *  data,
int  length,
int  timeout = -1 
) [pure virtual]

This method is used to write data to a socket, assuming a valid socket connection is already open.

Parameters:
dataa pointer to the data buffer that will be written to the socket.
lengththe size of the data buffer to be written.
timeoutthe amount of time in milliseconds to wait in trying to write the entire number of bytes. If set to -1 the call blocks until it writes all of the bytes or encounters and error.
Returns:
the number of bytes written to the socket's write buffer. Returns -1 if there was an error in writing.
virtual unsigned int writeable (  ) [pure virtual]

This method is used to get the space available to write bytes to the socket.

Returns:
the number of bytes that can be written, 0 if unable to write.