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

Dependents:   mtsas mtsas mtsas mtsas

Committer:
Vanger
Date:
Mon Aug 11 16:03:19 2014 +0000
Revision:
52:2cb58398a4f9
Parent:
46:56ab41157957
Child:
53:1aee5fe47adb
Removed parse response '>' from sendCommand() under Cellular.cpp, changed sendSMS() to verify sending SMS message under Cellular.cpp, changed disconnect() to have better flow under EasyIP.cpp, changed isConnected() to be simpler under EasyIP.cpp

Who changed what in which revision?

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