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@27:8e6188cbcfd4, 2013-12-17 (annotated)
- Committer:
- jengbrecht
- Date:
- Tue Dec 17 23:56:20 2013 +0000
- Revision:
- 27:8e6188cbcfd4
- Parent:
- 17:2d7c4ea7491b
- Child:
- 36:bb6b293c7495
- Child:
- 39:6e94520a3217
- Child:
- 41:81d035fb0b6a
Added a ton of documentation to Cellular.h and IPStack.h including some sample application code.
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 | |
jengbrecht | 27:8e6188cbcfd4 | 6 | /** IP Stack... //TODO |
jengbrecht | 27:8e6188cbcfd4 | 7 | * |
jengbrecht | 27:8e6188cbcfd4 | 8 | */ |
sgodinez | 11:134435d8a2d5 | 9 | class IPStack |
sgodinez | 11:134435d8a2d5 | 10 | { |
sgodinez | 11:134435d8a2d5 | 11 | public: |
sgodinez | 11:134435d8a2d5 | 12 | enum Mode { |
sgodinez | 11:134435d8a2d5 | 13 | TCP, UDP |
sgodinez | 11:134435d8a2d5 | 14 | }; |
sgodinez | 11:134435d8a2d5 | 15 | |
jengbrecht | 27:8e6188cbcfd4 | 16 | /** This method is used to connect the physical layer of the interface. Required |
jengbrecht | 27:8e6188cbcfd4 | 17 | * configurations and settings should be done in other calls or an init function. |
jengbrecht | 27:8e6188cbcfd4 | 18 | * |
jengbrecht | 27:8e6188cbcfd4 | 19 | * @returns true if the physical connection was successfully established, otherwise false. |
jengbrecht | 27:8e6188cbcfd4 | 20 | */ |
jengbrecht | 27:8e6188cbcfd4 | 21 | virtual bool connect() = 0; |
jengbrecht | 27:8e6188cbcfd4 | 22 | |
jengbrecht | 27:8e6188cbcfd4 | 23 | /** This method is used to disconnect the physical layer of the interface. This includes |
jengbrecht | 27:8e6188cbcfd4 | 24 | * any cleanup required before another connection can be made. |
jengbrecht | 27:8e6188cbcfd4 | 25 | */ |
sgodinez | 11:134435d8a2d5 | 26 | virtual void disconnect() = 0; |
jengbrecht | 27:8e6188cbcfd4 | 27 | |
jengbrecht | 27:8e6188cbcfd4 | 28 | /** This method is used to check if the physical layer of the interface is currently connected. |
jengbrecht | 27:8e6188cbcfd4 | 29 | * |
jengbrecht | 27:8e6188cbcfd4 | 30 | * @returns true if currently connected, otherwise false. |
jengbrecht | 27:8e6188cbcfd4 | 31 | */ |
sgodinez | 11:134435d8a2d5 | 32 | virtual bool isConnected() = 0; |
sgodinez | 11:134435d8a2d5 | 33 | |
jengbrecht | 27:8e6188cbcfd4 | 34 | /** This method is used to set the local port for the UDP or TCP socket connection. |
jengbrecht | 27:8e6188cbcfd4 | 35 | * The connection can be made using the open method. |
jengbrecht | 27:8e6188cbcfd4 | 36 | * |
jengbrecht | 27:8e6188cbcfd4 | 37 | * @param port the local port of the socket as an int. |
jengbrecht | 27:8e6188cbcfd4 | 38 | */ |
sgodinez | 11:134435d8a2d5 | 39 | virtual bool bind(unsigned int port) = 0; |
jengbrecht | 27:8e6188cbcfd4 | 40 | |
jengbrecht | 27:8e6188cbcfd4 | 41 | /** This method is used to open a socket connection with the given parameters. |
jengbrecht | 27:8e6188cbcfd4 | 42 | * This socket connection is established using the devices built in IP stack. |
jengbrecht | 27:8e6188cbcfd4 | 43 | * |
jengbrecht | 27:8e6188cbcfd4 | 44 | * @param address is the address you want to connect to in the form of xxx.xxx.xxx.xxx. |
jengbrecht | 27:8e6188cbcfd4 | 45 | * @param port the remote port you want to connect to. |
jengbrecht | 27:8e6188cbcfd4 | 46 | * @param mode an enum that specifies whether this socket connection is TCP or UDP type. |
jengbrecht | 27:8e6188cbcfd4 | 47 | * @returns true if the connection was successfully opened, otherwise false. |
jengbrecht | 27:8e6188cbcfd4 | 48 | */ |
sgodinez | 11:134435d8a2d5 | 49 | virtual bool open(const std::string& address, unsigned int port, Mode mode) = 0; |
jengbrecht | 27:8e6188cbcfd4 | 50 | |
jengbrecht | 27:8e6188cbcfd4 | 51 | /** This method is used to determine is a socket connection is currently open. |
jengbrecht | 27:8e6188cbcfd4 | 52 | * |
jengbrecht | 27:8e6188cbcfd4 | 53 | * @returns true if the socket is currently open, otherwise false. |
jengbrecht | 27:8e6188cbcfd4 | 54 | */ |
sgodinez | 11:134435d8a2d5 | 55 | virtual bool isOpen() = 0; |
jengbrecht | 27:8e6188cbcfd4 | 56 | |
jengbrecht | 27:8e6188cbcfd4 | 57 | /** This method is used to close a socket connection that is currently open. |
jengbrecht | 27:8e6188cbcfd4 | 58 | * |
jengbrecht | 27:8e6188cbcfd4 | 59 | * @returns true if successfully closed, otherwise returns false on an error. |
jengbrecht | 27:8e6188cbcfd4 | 60 | */ |
sgodinez | 17:2d7c4ea7491b | 61 | virtual bool close() = 0; |
jengbrecht | 27:8e6188cbcfd4 | 62 | |
sgodinez | 11:134435d8a2d5 | 63 | //Error code => -1, Timeout == -1 for blocking |
sgodinez | 11:134435d8a2d5 | 64 | virtual int read(char* data, int max, int timeout = -1) = 0; |
sgodinez | 11:134435d8a2d5 | 65 | virtual int write(char* data, int length, int timeout = -1) = 0; |
jengbrecht | 27:8e6188cbcfd4 | 66 | |
jengbrecht | 27:8e6188cbcfd4 | 67 | /** This method is used to get the number of bytes available to read off the |
jengbrecht | 27:8e6188cbcfd4 | 68 | * socket. |
jengbrecht | 27:8e6188cbcfd4 | 69 | * |
jengbrecht | 27:8e6188cbcfd4 | 70 | * @returns the number of bytes available, 0 if there are no bytes to read. |
jengbrecht | 27:8e6188cbcfd4 | 71 | */ |
sgodinez | 11:134435d8a2d5 | 72 | virtual unsigned int readable() = 0; |
jengbrecht | 27:8e6188cbcfd4 | 73 | |
jengbrecht | 27:8e6188cbcfd4 | 74 | /** This method is used to get the space available to write bytes to the socket. |
jengbrecht | 27:8e6188cbcfd4 | 75 | * |
jengbrecht | 27:8e6188cbcfd4 | 76 | * @returns the number of bytes that can be written, 0 if write buffer is full. |
jengbrecht | 27:8e6188cbcfd4 | 77 | */ |
sgodinez | 11:134435d8a2d5 | 78 | virtual unsigned int writeable() = 0; |
jengbrecht | 27:8e6188cbcfd4 | 79 | |
jengbrecht | 27:8e6188cbcfd4 | 80 | /** This method is used to reset the physical device that provides the physical |
jengbrecht | 27:8e6188cbcfd4 | 81 | * connection and IP stack. This call blocks until the device has returned to |
jengbrecht | 27:8e6188cbcfd4 | 82 | * an operational state from being reset. |
jengbrecht | 27:8e6188cbcfd4 | 83 | */ |
sgodinez | 11:134435d8a2d5 | 84 | virtual void reset() = 0; |
sgodinez | 11:134435d8a2d5 | 85 | }; |
sgodinez | 11:134435d8a2d5 | 86 | |
sgodinez | 11:134435d8a2d5 | 87 | #endif /* IPSTACK_H */ |