A library for talking to Multi-Tech's Cellular SocketModem Devices.
Dependents: M2X_dev axeda_wrapper_dev MTS_M2x_Example1 MTS_Cellular_Connect_Example ... more
io/IPStack.h@39:6e94520a3217, 2013-12-19 (annotated)
- Committer:
- mfiore
- Date:
- Thu Dec 19 19:49:58 2013 +0000
- Revision:
- 39:6e94520a3217
- Parent:
- 27:8e6188cbcfd4
- Child:
- 40:14342c4de476
add mts namespace to files in cellular/, io/, and utils/ directories; prepend CELL_ to some enums in cellular.h to avoid conflict with HTTPClient class; added AxedaWrapper class for sending data to Axeda backend
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sgodinez | 11:134435d8a2d5 | 1 | #ifndef IPSTACK_H |
sgodinez | 11:134435d8a2d5 | 2 | #define IPSTACK_H |
sgodinez | 11:134435d8a2d5 | 3 | |
sgodinez | 11:134435d8a2d5 | 4 | #include <string> |
sgodinez | 11:134435d8a2d5 | 5 | |
mfiore | 39:6e94520a3217 | 6 | namespace mts { |
mfiore | 39:6e94520a3217 | 7 | |
jengbrecht | 27:8e6188cbcfd4 | 8 | /** IP Stack... //TODO |
jengbrecht | 27:8e6188cbcfd4 | 9 | * |
jengbrecht | 27:8e6188cbcfd4 | 10 | */ |
sgodinez | 11:134435d8a2d5 | 11 | class IPStack |
sgodinez | 11:134435d8a2d5 | 12 | { |
sgodinez | 11:134435d8a2d5 | 13 | public: |
sgodinez | 11:134435d8a2d5 | 14 | enum Mode { |
sgodinez | 11:134435d8a2d5 | 15 | TCP, UDP |
sgodinez | 11:134435d8a2d5 | 16 | }; |
sgodinez | 11:134435d8a2d5 | 17 | |
jengbrecht | 27:8e6188cbcfd4 | 18 | /** This method is used to connect the physical layer of the interface. Required |
jengbrecht | 27:8e6188cbcfd4 | 19 | * configurations and settings should be done in other calls or an init function. |
jengbrecht | 27:8e6188cbcfd4 | 20 | * |
jengbrecht | 27:8e6188cbcfd4 | 21 | * @returns true if the physical connection was successfully established, otherwise false. |
jengbrecht | 27:8e6188cbcfd4 | 22 | */ |
jengbrecht | 27:8e6188cbcfd4 | 23 | virtual bool connect() = 0; |
jengbrecht | 27:8e6188cbcfd4 | 24 | |
jengbrecht | 27:8e6188cbcfd4 | 25 | /** This method is used to disconnect the physical layer of the interface. This includes |
jengbrecht | 27:8e6188cbcfd4 | 26 | * any cleanup required before another connection can be made. |
jengbrecht | 27:8e6188cbcfd4 | 27 | */ |
sgodinez | 11:134435d8a2d5 | 28 | virtual void disconnect() = 0; |
jengbrecht | 27:8e6188cbcfd4 | 29 | |
jengbrecht | 27:8e6188cbcfd4 | 30 | /** This method is used to check if the physical layer of the interface is currently connected. |
jengbrecht | 27:8e6188cbcfd4 | 31 | * |
jengbrecht | 27:8e6188cbcfd4 | 32 | * @returns true if currently connected, otherwise false. |
jengbrecht | 27:8e6188cbcfd4 | 33 | */ |
sgodinez | 11:134435d8a2d5 | 34 | virtual bool isConnected() = 0; |
sgodinez | 11:134435d8a2d5 | 35 | |
jengbrecht | 27:8e6188cbcfd4 | 36 | /** This method is used to set the local port for the UDP or TCP socket connection. |
jengbrecht | 27:8e6188cbcfd4 | 37 | * The connection can be made using the open method. |
jengbrecht | 27:8e6188cbcfd4 | 38 | * |
jengbrecht | 27:8e6188cbcfd4 | 39 | * @param port the local port of the socket as an int. |
jengbrecht | 27:8e6188cbcfd4 | 40 | */ |
sgodinez | 11:134435d8a2d5 | 41 | virtual bool bind(unsigned int port) = 0; |
jengbrecht | 27:8e6188cbcfd4 | 42 | |
jengbrecht | 27:8e6188cbcfd4 | 43 | /** This method is used to open a socket connection with the given parameters. |
jengbrecht | 27:8e6188cbcfd4 | 44 | * This socket connection is established using the devices built in IP stack. |
jengbrecht | 27:8e6188cbcfd4 | 45 | * |
jengbrecht | 27:8e6188cbcfd4 | 46 | * @param address is the address you want to connect to in the form of xxx.xxx.xxx.xxx. |
jengbrecht | 27:8e6188cbcfd4 | 47 | * @param port the remote port you want to connect to. |
jengbrecht | 27:8e6188cbcfd4 | 48 | * @param mode an enum that specifies whether this socket connection is TCP or UDP type. |
jengbrecht | 27:8e6188cbcfd4 | 49 | * @returns true if the connection was successfully opened, otherwise false. |
jengbrecht | 27:8e6188cbcfd4 | 50 | */ |
sgodinez | 11:134435d8a2d5 | 51 | virtual bool open(const std::string& address, unsigned int port, Mode mode) = 0; |
jengbrecht | 27:8e6188cbcfd4 | 52 | |
jengbrecht | 27:8e6188cbcfd4 | 53 | /** This method is used to determine is a socket connection is currently open. |
jengbrecht | 27:8e6188cbcfd4 | 54 | * |
jengbrecht | 27:8e6188cbcfd4 | 55 | * @returns true if the socket is currently open, otherwise false. |
jengbrecht | 27:8e6188cbcfd4 | 56 | */ |
sgodinez | 11:134435d8a2d5 | 57 | virtual bool isOpen() = 0; |
jengbrecht | 27:8e6188cbcfd4 | 58 | |
jengbrecht | 27:8e6188cbcfd4 | 59 | /** This method is used to close a socket connection that is currently open. |
jengbrecht | 27:8e6188cbcfd4 | 60 | * |
jengbrecht | 27:8e6188cbcfd4 | 61 | * @returns true if successfully closed, otherwise returns false on an error. |
jengbrecht | 27:8e6188cbcfd4 | 62 | */ |
sgodinez | 17:2d7c4ea7491b | 63 | virtual bool close() = 0; |
jengbrecht | 27:8e6188cbcfd4 | 64 | |
sgodinez | 11:134435d8a2d5 | 65 | //Error code => -1, Timeout == -1 for blocking |
sgodinez | 11:134435d8a2d5 | 66 | virtual int read(char* data, int max, int timeout = -1) = 0; |
sgodinez | 11:134435d8a2d5 | 67 | virtual int write(char* data, int length, int timeout = -1) = 0; |
jengbrecht | 27:8e6188cbcfd4 | 68 | |
jengbrecht | 27:8e6188cbcfd4 | 69 | /** This method is used to get the number of bytes available to read off the |
jengbrecht | 27:8e6188cbcfd4 | 70 | * socket. |
jengbrecht | 27:8e6188cbcfd4 | 71 | * |
jengbrecht | 27:8e6188cbcfd4 | 72 | * @returns the number of bytes available, 0 if there are no bytes to read. |
jengbrecht | 27:8e6188cbcfd4 | 73 | */ |
sgodinez | 11:134435d8a2d5 | 74 | virtual unsigned int readable() = 0; |
jengbrecht | 27:8e6188cbcfd4 | 75 | |
jengbrecht | 27:8e6188cbcfd4 | 76 | /** This method is used to get the space available to write bytes to the socket. |
jengbrecht | 27:8e6188cbcfd4 | 77 | * |
jengbrecht | 27:8e6188cbcfd4 | 78 | * @returns the number of bytes that can be written, 0 if write buffer is full. |
jengbrecht | 27:8e6188cbcfd4 | 79 | */ |
sgodinez | 11:134435d8a2d5 | 80 | virtual unsigned int writeable() = 0; |
jengbrecht | 27:8e6188cbcfd4 | 81 | |
jengbrecht | 27:8e6188cbcfd4 | 82 | /** This method is used to reset the physical device that provides the physical |
jengbrecht | 27:8e6188cbcfd4 | 83 | * connection and IP stack. This call blocks until the device has returned to |
jengbrecht | 27:8e6188cbcfd4 | 84 | * an operational state from being reset. |
jengbrecht | 27:8e6188cbcfd4 | 85 | */ |
sgodinez | 11:134435d8a2d5 | 86 | virtual void reset() = 0; |
sgodinez | 11:134435d8a2d5 | 87 | }; |
sgodinez | 11:134435d8a2d5 | 88 | |
mfiore | 39:6e94520a3217 | 89 | } |
mfiore | 39:6e94520a3217 | 90 | |
sgodinez | 11:134435d8a2d5 | 91 | #endif /* IPSTACK_H */ |