Cellular library for MTS Socket Modem Arduino Shield devices from Multi-Tech Systems
Dependents: mtsas mtsas mtsas mtsas
Cellular/EasyIP.h@31:529db15abda7, 2014-07-14 (annotated)
- Committer:
- Vanger
- Date:
- Mon Jul 14 21:11:50 2014 +0000
- Revision:
- 31:529db15abda7
- Parent:
- 30:1326b623919a
- Child:
- 33:3b6f3904dde0
Pulled MTS-Cellular changes into MTS-Cellular-dev branch.; Also implemented setSocketCloseable(); Modified read(),write(), and sendEscapeCommand() to account for socketCloseable boolean flag.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mike Fiore |
1:f155d94d6f3a | 1 | #ifndef SMC_H |
Mike Fiore |
1:f155d94d6f3a | 2 | #define SMC_H |
Mike Fiore |
1:f155d94d6f3a | 3 | |
Vanger | 26:2b769ed8de4f | 4 | #include <string> |
Vanger | 26:2b769ed8de4f | 5 | #include <vector> |
Vanger | 26:2b769ed8de4f | 6 | |
Vanger | 26:2b769ed8de4f | 7 | #include "MTSBufferedIO.h" |
Vanger | 26:2b769ed8de4f | 8 | #include "Cellular.h" |
Vanger | 26:2b769ed8de4f | 9 | |
Vanger | 26:2b769ed8de4f | 10 | namespace mts |
Vanger | 26:2b769ed8de4f | 11 | { |
Vanger | 26:2b769ed8de4f | 12 | /** This is a class for communicating without a Multi-Tech Systems SocketModem iCell. Instead, |
Vanger | 26:2b769ed8de4f | 13 | * it uses the hayes command set to implement the same commands and functions as the UIP class. |
Vanger | 26:2b769ed8de4f | 14 | * (See the UIP class and documentation, "UIP.h") |
Vanger | 26:2b769ed8de4f | 15 | * This class supports three main types of cellular radio interactions including: |
Vanger | 26:2b769ed8de4f | 16 | * configuration and status AT command processing, SMS processing, and TCP Socket |
Vanger | 26:2b769ed8de4f | 17 | * data connections. It should be noted that the radio can not process commands or |
Vanger | 26:2b769ed8de4f | 18 | * SMS messages while having an open data connection at the same time. The concurrent |
Vanger | 26:2b769ed8de4f | 19 | * capability may be added in a future release. This class also inherits from IPStack |
Vanger | 26:2b769ed8de4f | 20 | * providing a common set of commands for communication devices that have an onboard |
Vanger | 26:2b769ed8de4f | 21 | * IP Stack. It is also integrated with the standard mbed Sockets package and can therefore |
Vanger | 26:2b769ed8de4f | 22 | * be used seamlessly with clients and services built on top of this interface already within |
Vanger | 26:2b769ed8de4f | 23 | * the mbed library. |
Vanger | 26:2b769ed8de4f | 24 | * The default baud rate for the cellular radio is 115200 bps. |
Vanger | 26:2b769ed8de4f | 25 | */ |
Vanger | 26:2b769ed8de4f | 26 | class EasyIP : public Cellular //Inherits from Cellular. |
Vanger | 26:2b769ed8de4f | 27 | { |
Vanger | 30:1326b623919a | 28 | private: |
Vanger | 30:1326b623919a | 29 | /*Function that sends +++ to radio to exit data mode |
Vanger | 30:1326b623919a | 30 | returns true if successful exit from online mode, else false |
Vanger | 30:1326b623919a | 31 | */ |
Vanger | 30:1326b623919a | 32 | virtual bool sendEscapeCommand(); |
Vanger | 30:1326b623919a | 33 | /*Switches to command mode, queries socket connection status, |
Vanger | 30:1326b623919a | 34 | then returns true if there is an active socket connection, |
Vanger | 30:1326b623919a | 35 | else it returns false.*/ |
Vanger | 30:1326b623919a | 36 | virtual bool socketCheck(); |
Vanger | 26:2b769ed8de4f | 37 | public: |
Vanger | 26:2b769ed8de4f | 38 | /** This static function is used to create or get a reference to a |
Vanger | 26:2b769ed8de4f | 39 | * Cellular object. Cellular uses the singleton pattern, which means |
Vanger | 26:2b769ed8de4f | 40 | * that you can only have one existing at a time. The first time you |
Vanger | 26:2b769ed8de4f | 41 | * call getInstance this method creates a new uninitialized Cellular |
Vanger | 26:2b769ed8de4f | 42 | * object and returns it. All future calls to this method will return |
Vanger | 26:2b769ed8de4f | 43 | * a reference to the instance created during the first call. Note that |
Vanger | 26:2b769ed8de4f | 44 | * you must call init on the returned instance before mnaking any other |
Vanger | 26:2b769ed8de4f | 45 | * calls. If using this class's bindings to any of the Socket package |
Vanger | 26:2b769ed8de4f | 46 | * classes like TCPSocketConnection, you must call this method and the |
Vanger | 26:2b769ed8de4f | 47 | * init method on the returned object first, before even creating the |
Vanger | 26:2b769ed8de4f | 48 | * other objects. |
Vanger | 26:2b769ed8de4f | 49 | * |
Vanger | 26:2b769ed8de4f | 50 | * @returns a reference to the single Cellular obect that has been created. |
Vanger | 26:2b769ed8de4f | 51 | */ |
Vanger | 26:2b769ed8de4f | 52 | EasyIP(Radio type); |
Vanger | 26:2b769ed8de4f | 53 | /** Destructs a Cellular object and frees all related resources. |
Vanger | 26:2b769ed8de4f | 54 | */ |
Vanger | 26:2b769ed8de4f | 55 | ~EasyIP(); |
Vanger | 26:2b769ed8de4f | 56 | |
Vanger | 26:2b769ed8de4f | 57 | virtual bool init(MTSBufferedIO* io); |
Vanger | 26:2b769ed8de4f | 58 | |
Vanger | 26:2b769ed8de4f | 59 | // Wifi connection based commands derived from CommInterface.h |
Vanger | 26:2b769ed8de4f | 60 | virtual bool connect(); |
Vanger | 26:2b769ed8de4f | 61 | virtual void disconnect(); |
Vanger | 26:2b769ed8de4f | 62 | virtual bool isConnected(); |
Vanger | 26:2b769ed8de4f | 63 | virtual void reset(); |
Vanger | 26:2b769ed8de4f | 64 | |
Vanger | 26:2b769ed8de4f | 65 | // TCP and UDP Socket related commands |
Vanger | 26:2b769ed8de4f | 66 | // For behavior of the following methods refer to IPStack.h documentation |
Vanger | 26:2b769ed8de4f | 67 | virtual bool bind(unsigned int port); |
Vanger | 26:2b769ed8de4f | 68 | virtual bool open(const std::string& address, unsigned int port, Mode mode); |
Vanger | 26:2b769ed8de4f | 69 | virtual bool isOpen(); |
Vanger | 26:2b769ed8de4f | 70 | virtual bool close(); |
Vanger | 31:529db15abda7 | 71 | virtual int read(char* data, int max, int timeout = -1); |
Vanger | 26:2b769ed8de4f | 72 | virtual int write(const char* data, int length, int timeout = -1); |
Vanger | 26:2b769ed8de4f | 73 | virtual unsigned int readable(); |
Vanger | 26:2b769ed8de4f | 74 | virtual unsigned int writeable(); |
Vanger | 30:1326b623919a | 75 | virtual bool ping(const std::string& address = "8.8.8.8"); //Google DNS server |
Vanger | 26:2b769ed8de4f | 76 | virtual std::string getDeviceIP(); |
Vanger | 31:529db15abda7 | 77 | virtual bool setDeviceIP(std::string address = "DHCP");//Runs DHCP to configure the IP |
Vanger | 26:2b769ed8de4f | 78 | |
Vanger | 26:2b769ed8de4f | 79 | //Sets the APN, also sets mode to IP, might need to change |
Vanger | 26:2b769ed8de4f | 80 | virtual Code setApn(const std::string& apn); |
Vanger | 26:2b769ed8de4f | 81 | /** A method for configuring command ehco capability on the radio. This command |
Vanger | 26:2b769ed8de4f | 82 | * sets whether sent characters are echoed back from the radio, in which case you |
Vanger | 26:2b769ed8de4f | 83 | * will receive back every command you send. |
Vanger | 26:2b769ed8de4f | 84 | * |
Vanger | 26:2b769ed8de4f | 85 | * @param state if true echo will be turned off, otherwise it will be turned on. |
Vanger | 26:2b769ed8de4f | 86 | * @returns the standard AT Code enumeration. |
Vanger | 26:2b769ed8de4f | 87 | */ |
Vanger | 27:ec44d5a9544f | 88 | virtual Code echo(bool state); |
Vanger | 26:2b769ed8de4f | 89 | |
Vanger | 26:2b769ed8de4f | 90 | /** This method can be used to trade socket functionality for performance. |
Vanger | 26:2b769ed8de4f | 91 | * In order to enable a socket connection to be closed by the client side programtically, |
Vanger | 26:2b769ed8de4f | 92 | * this class must process all read and write data on the socket to guard the special |
Vanger | 26:2b769ed8de4f | 93 | * escape character used to close an open socket connection. It is recommened that you |
Vanger | 26:2b769ed8de4f | 94 | * use the default of true unless the overhead of these operations is too significant. |
Vanger | 26:2b769ed8de4f | 95 | * |
Vanger | 26:2b769ed8de4f | 96 | * @param enabled set to true if you want the socket closeable, otherwise false. The default |
Vanger | 26:2b769ed8de4f | 97 | * is true. |
Vanger | 26:2b769ed8de4f | 98 | * @returns the standard AT Code enumeration. |
Vanger | 26:2b769ed8de4f | 99 | */ |
Vanger | 31:529db15abda7 | 100 | virtual Code setSocketCloseable(bool enabled = true); //ETX closes socket (ETX and DLE in payload are escaped with DLE) |
Vanger | 26:2b769ed8de4f | 101 | }; |
Vanger | 26:2b769ed8de4f | 102 | |
Vanger | 26:2b769ed8de4f | 103 | } |
Vanger | 26:2b769ed8de4f | 104 | |
Mike Fiore |
1:f155d94d6f3a | 105 | #endif |