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

Dependents:   mtsas mtsas mtsas mtsas

Committer:
Mike Fiore
Date:
Mon May 19 12:34:32 2014 -0500
Revision:
1:f155d94d6f3a
Parent:
0:830c436480e3
add all cellular code, remove MBEDCellularRadioInterface

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Mike Fiore 1:f155d94d6f3a 1 #ifndef SMCIP_H
Mike Fiore 1:f155d94d6f3a 2 #define SMCIP_H
Mike Fiore 1:f155d94d6f3a 3
Mike Fiore 1:f155d94d6f3a 4 #include <string>
Mike Fiore 1:f155d94d6f3a 5 #include <vector>
Mike Fiore 1:f155d94d6f3a 6
Mike Fiore 1:f155d94d6f3a 7 #include "mbed.h"
Mike Fiore 1:f155d94d6f3a 8 #include "MTSBufferedIO.h"
Mike Fiore 1:f155d94d6f3a 9 #include "Cellular.h"
Mike Fiore 1:f155d94d6f3a 10
Mike Fiore 1:f155d94d6f3a 11 namespace mts
Mike Fiore 1:f155d94d6f3a 12 {
Mike Fiore 1:f155d94d6f3a 13
Mike Fiore 1:f155d94d6f3a 14 /** This is a class for communicating with a Multi-Tech Systems SocketModem iCell. The
Mike Fiore 1:f155d94d6f3a 15 * SocketModem iCell is a family of carrier certified embedded cellular radio modules with
Mike Fiore 1:f155d94d6f3a 16 * a common hardware footprint and AT command set for built in IP-stack functionality.
Mike Fiore 1:f155d94d6f3a 17 * This class supports three main types of cellular radio interactions including:
Mike Fiore 1:f155d94d6f3a 18 * configuration and status AT command processing, SMS processing, and TCP Socket
Mike Fiore 1:f155d94d6f3a 19 * data connections. It should be noted that the radio can not process commands or
Mike Fiore 1:f155d94d6f3a 20 * SMS messages while having an open data connection at the same time. The concurrent
Mike Fiore 1:f155d94d6f3a 21 * capability may be added in a future release. This class also inherits from IPStack
Mike Fiore 1:f155d94d6f3a 22 * providing a common set of commands for communication devices that have an onboard
Mike Fiore 1:f155d94d6f3a 23 * IP Stack. It is also integrated with the standard mbed Sockets package and can therefore
Mike Fiore 1:f155d94d6f3a 24 * be used seamlessly with clients and services built on top of this interface already within
Mike Fiore 1:f155d94d6f3a 25 * the mbed library.
Mike Fiore 1:f155d94d6f3a 26 *
Mike Fiore 1:f155d94d6f3a 27 * All of the following examples use the Pin Names for the Freedom KL46Z board coupled with
Mike Fiore 1:f155d94d6f3a 28 * the SocketModem Shield Arduino compatible board. Please chage Pin Names accordingly to
Mike Fiore 1:f155d94d6f3a 29 * match your hardware configuration. It also assumes the use of RTS/CTS hardware handshaking
Mike Fiore 1:f155d94d6f3a 30 * using GPIOs. To disable this you will need to change settings on the radio module and
Mike Fiore 1:f155d94d6f3a 31 * and use the MTSSerial class instead of MTSSerialFlowControl. The default baud rate for the
Mike Fiore 1:f155d94d6f3a 32 * cellular radio is 115200 bps.
Mike Fiore 1:f155d94d6f3a 33 */
Mike Fiore 1:f155d94d6f3a 34
Mike Fiore 1:f155d94d6f3a 35 class SMCIP : public Cellular
Mike Fiore 1:f155d94d6f3a 36 {
Mike Fiore 1:f155d94d6f3a 37 public:
Mike Fiore 1:f155d94d6f3a 38 /** This static function is used to create or get a reference to a
Mike Fiore 1:f155d94d6f3a 39 * Cellular object. Cellular uses the singleton pattern, which means
Mike Fiore 1:f155d94d6f3a 40 * that you can only have one existing at a time. The first time you
Mike Fiore 1:f155d94d6f3a 41 * call getInstance this method creates a new uninitialized Cellular
Mike Fiore 1:f155d94d6f3a 42 * object and returns it. All future calls to this method will return
Mike Fiore 1:f155d94d6f3a 43 * a reference to the instance created during the first call. Note that
Mike Fiore 1:f155d94d6f3a 44 * you must call init on the returned instance before mnaking any other
Mike Fiore 1:f155d94d6f3a 45 * calls. If using this class's bindings to any of the Socket package
Mike Fiore 1:f155d94d6f3a 46 * classes like TCPSocketConnection, you must call this method and the
Mike Fiore 1:f155d94d6f3a 47 * init method on the returned object first, before even creating the
Mike Fiore 1:f155d94d6f3a 48 * other objects.
Mike Fiore 1:f155d94d6f3a 49 *
Mike Fiore 1:f155d94d6f3a 50 * @returns a reference to the single Cellular obect that has been created.
Mike Fiore 1:f155d94d6f3a 51 */
Mike Fiore 1:f155d94d6f3a 52 SMCIP();
Mike Fiore 1:f155d94d6f3a 53
Mike Fiore 1:f155d94d6f3a 54 /** Destructs a Cellular object and frees all related resources.
Mike Fiore 1:f155d94d6f3a 55 */
Mike Fiore 1:f155d94d6f3a 56 ~SMCIP();
Mike Fiore 1:f155d94d6f3a 57
Mike Fiore 1:f155d94d6f3a 58 virtual bool init(MTSBufferedIO* io);
Mike Fiore 1:f155d94d6f3a 59
Mike Fiore 1:f155d94d6f3a 60 /**
Mike Fiore 1:f155d94d6f3a 61 *
Mike Fiore 1:f155d94d6f3a 62 */
Mike Fiore 1:f155d94d6f3a 63 bool configureSignals(PinName DCD = NC, PinName DTR = NC, PinName RESET = NC);
Mike Fiore 1:f155d94d6f3a 64
Mike Fiore 1:f155d94d6f3a 65 // Wifi connection based commands derived from CommInterface.h
Mike Fiore 1:f155d94d6f3a 66 virtual bool connect();
Mike Fiore 1:f155d94d6f3a 67 virtual void disconnect();
Mike Fiore 1:f155d94d6f3a 68 virtual bool isConnected();
Mike Fiore 1:f155d94d6f3a 69 virtual void reset();
Mike Fiore 1:f155d94d6f3a 70
Mike Fiore 1:f155d94d6f3a 71 // TCP and UDP Socket related commands
Mike Fiore 1:f155d94d6f3a 72 // For behavior of the following methods refer to IPStack.h documentation
Mike Fiore 1:f155d94d6f3a 73 virtual bool bind(unsigned int port);
Mike Fiore 1:f155d94d6f3a 74 virtual bool open(const std::string& address, unsigned int port, Mode mode);
Mike Fiore 1:f155d94d6f3a 75 virtual bool isOpen();
Mike Fiore 1:f155d94d6f3a 76 virtual bool close();
Mike Fiore 1:f155d94d6f3a 77 virtual int read(char* data, int max, int timeout = -1);
Mike Fiore 1:f155d94d6f3a 78 virtual int write(const char* data, int length, int timeout = -1);
Mike Fiore 1:f155d94d6f3a 79 virtual unsigned int readable();
Mike Fiore 1:f155d94d6f3a 80 virtual unsigned int writeable();
Mike Fiore 1:f155d94d6f3a 81 virtual bool ping(const std::string& address = "8.8.8.8");
Mike Fiore 1:f155d94d6f3a 82 virtual std::string getDeviceIP();
Mike Fiore 1:f155d94d6f3a 83 virtual bool setDeviceIP(std::string address = "DHCP");
Mike Fiore 1:f155d94d6f3a 84
Mike Fiore 1:f155d94d6f3a 85 //Cellular functions that derive from Cellular.h
Mike Fiore 1:f155d94d6f3a 86 virtual std::string sendCommand(const std::string& command, unsigned int timeoutMillis, char esc = CR);
Mike Fiore 1:f155d94d6f3a 87 virtual Code sendBasicCommand(const std::string& command, unsigned int timeoutMillis, char esc = CR);
Mike Fiore 1:f155d94d6f3a 88 virtual Code setApn(const std::string& apn);
Mike Fiore 1:f155d94d6f3a 89 virtual Code setDns(const std::string& primary, const std::string& secondary = "0.0.0.0");
Mike Fiore 1:f155d94d6f3a 90
Mike Fiore 1:f155d94d6f3a 91 /** A method for configuring command ehco capability on the radio. This command
Mike Fiore 1:f155d94d6f3a 92 * sets whether sent characters are echoed back from the radio, in which case you
Mike Fiore 1:f155d94d6f3a 93 * will receive back every command you send.
Mike Fiore 1:f155d94d6f3a 94 *
Mike Fiore 1:f155d94d6f3a 95 * @param state if true echo will be turned off, otherwise it will be turned on.
Mike Fiore 1:f155d94d6f3a 96 * @returns the standard AT Code enumeration.
Mike Fiore 1:f155d94d6f3a 97 */
Mike Fiore 1:f155d94d6f3a 98 Code echo(bool state);
Mike Fiore 1:f155d94d6f3a 99
Mike Fiore 1:f155d94d6f3a 100 /** This method can be used to trade socket functionality for performance.
Mike Fiore 1:f155d94d6f3a 101 * In order to enable a socket connection to be closed by the client side programtically,
Mike Fiore 1:f155d94d6f3a 102 * this class must process all read and write data on the socket to guard the special
Mike Fiore 1:f155d94d6f3a 103 * escape character used to close an open socket connection. It is recommened that you
Mike Fiore 1:f155d94d6f3a 104 * use the default of true unless the overhead of these operations is too significant.
Mike Fiore 1:f155d94d6f3a 105 *
Mike Fiore 1:f155d94d6f3a 106 * @param enabled set to true if you want the socket closeable, otherwise false. The default
Mike Fiore 1:f155d94d6f3a 107 * is true.
Mike Fiore 1:f155d94d6f3a 108 * @returns the standard AT Code enumeration.
Mike Fiore 1:f155d94d6f3a 109 */
Mike Fiore 1:f155d94d6f3a 110 Code setSocketCloseable(bool enabled = true); //ETX closes socket (ETX and DLE in payload are escaped with DLE)
Mike Fiore 1:f155d94d6f3a 111
Mike Fiore 1:f155d94d6f3a 112 private:
Mike Fiore 1:f155d94d6f3a 113 MTSBufferedIO* io; //IO interface obect that the radio is accessed through.
Mike Fiore 1:f155d94d6f3a 114 bool echoMode; //Specifies if the echo mode is currently enabled.
Mike Fiore 1:f155d94d6f3a 115
Mike Fiore 1:f155d94d6f3a 116 bool pppConnected; //Specifies if a PPP session is currently connected.
Mike Fiore 1:f155d94d6f3a 117 std::string apn; //A string that holds the APN for the radio.
Mike Fiore 1:f155d94d6f3a 118
Mike Fiore 1:f155d94d6f3a 119 Mode mode; //The current socket Mode.
Mike Fiore 1:f155d94d6f3a 120 bool socketOpened; //Specifies if a Socket is presently opened.
Mike Fiore 1:f155d94d6f3a 121 bool socketCloseable; //Specifies is a Socket can be closed.
Mike Fiore 1:f155d94d6f3a 122 unsigned int local_port; //Holds the local port for socket connections.
Mike Fiore 1:f155d94d6f3a 123 std::string local_address; //Holds the local address for socket connections.
Mike Fiore 1:f155d94d6f3a 124 unsigned int host_port; //Holds the remote port for socket connections.
Mike Fiore 1:f155d94d6f3a 125 std::string host_address; //Holds the remote address for socket connections.
Mike Fiore 1:f155d94d6f3a 126 DigitalIn* dcd; //Maps to the radio's dcd signal
Mike Fiore 1:f155d94d6f3a 127 DigitalOut* dtr; //Maps to the radio's dtr signal
Mike Fiore 1:f155d94d6f3a 128 DigitalOut* resetLine; //Maps to the radio's reset signal
Mike Fiore 1:f155d94d6f3a 129 };
Mike Fiore 1:f155d94d6f3a 130
Mike Fiore 1:f155d94d6f3a 131 }
Mike Fiore 1:f155d94d6f3a 132
Mike Fiore 1:f155d94d6f3a 133 #endif