Cellular library for MTS Socket Modem Arduino Shield devices from Multi-Tech Systems

Dependents:   mtsas mtsas mtsas mtsas

Committer:
Vanger
Date:
Wed Jul 16 15:05:10 2014 +0000
Revision:
34:7d412c989964
Parent:
33:3b6f3904dde0
Child:
43:91c5e53f508f
Updated documentation for UIP.h and finished EasyIP.h documentation

Who changed what in which revision?

UserRevisionLine numberNew 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 33:3b6f3904dde0 12 /** This is a class for communicating without a Multi-Tech Systems SocketModem iCell. Instead,
Vanger 33:3b6f3904dde0 13 * it uses the hayes command set to directly implement the same UIP interface to the radio.
Vanger 33:3b6f3904dde0 14 * (See the UIP class and documentation, "UIP.h")
Vanger 33:3b6f3904dde0 15 * This class supports four main types of cellular radio interactions including:
Vanger 33:3b6f3904dde0 16 * configuration and status AT-command processing, SMS processing, TCP Socket data connections,
Vanger 33:3b6f3904dde0 17 * and UDP data connections. It should be noted that the radio can not process commands or
Vanger 33:3b6f3904dde0 18 * SMS messages while having an open data connection at the same time. The concurrent
Vanger 33:3b6f3904dde0 19 * capability may be added in a future release. This class also inherits from IPStack
Vanger 33:3b6f3904dde0 20 * providing a common set of commands for communication devices that have an onboard
Vanger 33:3b6f3904dde0 21 * IP Stack. It is also integrated with the standard mbed Sockets package and can therefore
Vanger 33:3b6f3904dde0 22 * be used seamlessly with clients and services built on top of this interface already within
Vanger 33:3b6f3904dde0 23 * the mbed library.
Vanger 33:3b6f3904dde0 24 * The default baud rate for the cellular radio is 115200 bps.
Vanger 33:3b6f3904dde0 25 */
Vanger 33:3b6f3904dde0 26 class EasyIP : public Cellular
Vanger 26:2b769ed8de4f 27 {
Vanger 26:2b769ed8de4f 28 public:
Vanger 33:3b6f3904dde0 29 /** This static function is used to create or get a reference to a
Vanger 26:2b769ed8de4f 30 * Cellular object. Cellular uses the singleton pattern, which means
Vanger 26:2b769ed8de4f 31 * that you can only have one existing at a time. The first time you
Vanger 26:2b769ed8de4f 32 * call getInstance this method creates a new uninitialized Cellular
Vanger 26:2b769ed8de4f 33 * object and returns it. All future calls to this method will return
Vanger 26:2b769ed8de4f 34 * a reference to the instance created during the first call. Note that
Vanger 26:2b769ed8de4f 35 * you must call init on the returned instance before mnaking any other
Vanger 26:2b769ed8de4f 36 * calls. If using this class's bindings to any of the Socket package
Vanger 26:2b769ed8de4f 37 * classes like TCPSocketConnection, you must call this method and the
Vanger 26:2b769ed8de4f 38 * init method on the returned object first, before even creating the
Vanger 26:2b769ed8de4f 39 * other objects.
Vanger 26:2b769ed8de4f 40 *
Vanger 26:2b769ed8de4f 41 * @returns a reference to the single Cellular obect that has been created.
Vanger 26:2b769ed8de4f 42 */
Vanger 26:2b769ed8de4f 43 EasyIP(Radio type);
Vanger 34:7d412c989964 44
Vanger 26:2b769ed8de4f 45 /** Destructs a Cellular object and frees all related resources.
Vanger 26:2b769ed8de4f 46 */
Vanger 26:2b769ed8de4f 47 ~EasyIP();
Vanger 34:7d412c989964 48
Vanger 33:3b6f3904dde0 49 /** Initializes the MTS IO buffer
Vanger 33:3b6f3904dde0 50 */
Vanger 26:2b769ed8de4f 51 virtual bool init(MTSBufferedIO* io);
Vanger 33:3b6f3904dde0 52
Vanger 33:3b6f3904dde0 53 /** PPP connect command.
Vanger 33:3b6f3904dde0 54 * Connects the radio to the cellular network.
Vanger 33:3b6f3904dde0 55 *
Vanger 33:3b6f3904dde0 56 * @returns true if PPP connection to the network succeeded,
Vanger 33:3b6f3904dde0 57 * false if the PPP connection failed.
Vanger 33:3b6f3904dde0 58 */
Vanger 26:2b769ed8de4f 59 virtual bool connect();
Vanger 33:3b6f3904dde0 60
Vanger 33:3b6f3904dde0 61 /** PPP disconnect command.
Vanger 33:3b6f3904dde0 62 * Disconnects from the PPP network, and will also close active socket
Vanger 33:3b6f3904dde0 63 * connection if open.
Vanger 33:3b6f3904dde0 64 */
Vanger 26:2b769ed8de4f 65 virtual void disconnect();
Vanger 33:3b6f3904dde0 66
Vanger 33:3b6f3904dde0 67 /** Checks if the radio is connected to the cell network.
Vanger 33:3b6f3904dde0 68 * Checks antenna signal, cell tower registration, and context activation
Vanger 33:3b6f3904dde0 69 * before finally pinging (4 pings, 32 bytes each) to confirm PPP connection
Vanger 33:3b6f3904dde0 70 * to network. Will return true if there is an open socket connection as well.
Vanger 33:3b6f3904dde0 71 *
Vanger 33:3b6f3904dde0 72 * @returns true if there is a PPP connection to the cell network, false
Vanger 33:3b6f3904dde0 73 * if there is no PPP connection to the cell network.
Vanger 33:3b6f3904dde0 74 */
Vanger 26:2b769ed8de4f 75 virtual bool isConnected();
Vanger 33:3b6f3904dde0 76
Vanger 33:3b6f3904dde0 77 /** Resets the radio/modem.
Vanger 33:3b6f3904dde0 78 * Disconnects all active PPP and socket connections to do so.
Vanger 33:3b6f3904dde0 79 */
Vanger 26:2b769ed8de4f 80 virtual void reset();
Vanger 26:2b769ed8de4f 81
Vanger 26:2b769ed8de4f 82 // TCP and UDP Socket related commands
Vanger 26:2b769ed8de4f 83 // For behavior of the following methods refer to IPStack.h documentation
Vanger 26:2b769ed8de4f 84 virtual bool bind(unsigned int port);
Vanger 26:2b769ed8de4f 85 virtual bool open(const std::string& address, unsigned int port, Mode mode);
Vanger 26:2b769ed8de4f 86 virtual bool isOpen();
Vanger 26:2b769ed8de4f 87 virtual bool close();
Vanger 31:529db15abda7 88 virtual int read(char* data, int max, int timeout = -1);
Vanger 26:2b769ed8de4f 89 virtual int write(const char* data, int length, int timeout = -1);
Vanger 26:2b769ed8de4f 90 virtual unsigned int readable();
Vanger 26:2b769ed8de4f 91 virtual unsigned int writeable();
Vanger 33:3b6f3904dde0 92 virtual bool ping(const std::string& address = "8.8.8.8"); //Google DNS server used as default ping address
Vanger 26:2b769ed8de4f 93 virtual std::string getDeviceIP();
Vanger 33:3b6f3904dde0 94 virtual bool setDeviceIP(std::string address = "DHCP");
Vanger 26:2b769ed8de4f 95
Vanger 33:3b6f3904dde0 96 /** Sets the APN
Vanger 33:3b6f3904dde0 97 *
Vanger 33:3b6f3904dde0 98 * @param apn c-string of the APN to use
Vanger 33:3b6f3904dde0 99 *
Vanger 33:3b6f3904dde0 100 * @returns MTS_SUCCESS if the APN was set, or is not needed, else it
Vanger 33:3b6f3904dde0 101 * returns the result of the AT command sent to the radio to set the APN
Vanger 33:3b6f3904dde0 102 */
Vanger 26:2b769ed8de4f 103 virtual Code setApn(const std::string& apn);
Vanger 33:3b6f3904dde0 104
Vanger 26:2b769ed8de4f 105 /** A method for configuring command ehco capability on the radio. This command
Vanger 26:2b769ed8de4f 106 * sets whether sent characters are echoed back from the radio, in which case you
Vanger 26:2b769ed8de4f 107 * will receive back every command you send.
Vanger 26:2b769ed8de4f 108 *
Vanger 26:2b769ed8de4f 109 * @param state if true echo will be turned off, otherwise it will be turned on.
Vanger 26:2b769ed8de4f 110 * @returns the standard AT Code enumeration.
Vanger 26:2b769ed8de4f 111 */
Vanger 27:ec44d5a9544f 112 virtual Code echo(bool state);
Vanger 26:2b769ed8de4f 113
Vanger 26:2b769ed8de4f 114 /** This method can be used to trade socket functionality for performance.
Vanger 33:3b6f3904dde0 115 * Can disable checking socket closed messages from the data socket, and thus the socket
Vanger 33:3b6f3904dde0 116 * will only be visibly closed to the local side if the radio is explicitly checked, or
Vanger 33:3b6f3904dde0 117 * the socket is closed by the local side through the use of physical pin manipulation.
Vanger 33:3b6f3904dde0 118 *
Vanger 33:3b6f3904dde0 119 * Uses the Hayes escape sequence (1 second pause, "+++", 1 second pause) to exit the socket
Vanger 33:3b6f3904dde0 120 * connection to check if a received "NO CARRIER" string is from the radio indicating the socket
Vanger 33:3b6f3904dde0 121 * has been closed, or is merely part of the data stream. Should not occur very often, however, if
Vanger 33:3b6f3904dde0 122 * data carrying the string "NO CARRIER" is going to be transmitted frequently, then the socket should
Vanger 33:3b6f3904dde0 123 * be set closeable and physical-socket-closing-means be used instead to reduce the large amount of
Vanger 33:3b6f3904dde0 124 * overhead switching from checking the validity of the "NO CARRIER" message being and indication of
Vanger 33:3b6f3904dde0 125 * the socket connection being closed.
Vanger 26:2b769ed8de4f 126 *
Vanger 26:2b769ed8de4f 127 * @param enabled set to true if you want the socket closeable, otherwise false. The default
Vanger 26:2b769ed8de4f 128 * is true.
Vanger 26:2b769ed8de4f 129 * @returns the standard AT Code enumeration.
Vanger 26:2b769ed8de4f 130 */
Vanger 33:3b6f3904dde0 131 virtual Code setSocketCloseable(bool enabled = true);
Vanger 33:3b6f3904dde0 132
Vanger 33:3b6f3904dde0 133 private:
Vanger 33:3b6f3904dde0 134 /** Function that sends +++ to the radio to exit data mode
Vanger 33:3b6f3904dde0 135 * returns true if it successfully exits from online mode, else
Vanger 33:3b6f3904dde0 136 * it returns false. Used due to the fact that AT commands
Vanger 33:3b6f3904dde0 137 * cannot be sent while in data mode.
Vanger 33:3b6f3904dde0 138 *
Vanger 33:3b6f3904dde0 139 * @returns true if the radio dropped from data mode to commande mode
Vanger 33:3b6f3904dde0 140 * or is already in command mode (socket is still open in the background),
Vanger 33:3b6f3904dde0 141 * and false if the radio failed to switch to command mode.
Vanger 33:3b6f3904dde0 142 */
Vanger 33:3b6f3904dde0 143 virtual bool sendEscapeCommand();
Vanger 33:3b6f3904dde0 144
Vanger 33:3b6f3904dde0 145 /** Switches to command mode, queries the status of the socket connection,
Vanger 33:3b6f3904dde0 146 * and then returns back to the active socket connection (if still open)
Vanger 33:3b6f3904dde0 147 *
Vanger 33:3b6f3904dde0 148 * @returns true if a socket is currently open, otherwise it returns false
Vanger 33:3b6f3904dde0 149 */
Vanger 33:3b6f3904dde0 150 virtual bool socketCheck();
Vanger 26:2b769ed8de4f 151 };
Vanger 26:2b769ed8de4f 152
Vanger 26:2b769ed8de4f 153 }
Vanger 26:2b769ed8de4f 154
Vanger 33:3b6f3904dde0 155 #endif /* SMC_H */