Cellular library for MTS Socket Modem Arduino Shield devices from Multi-Tech Systems
Dependents: mtsas mtsas mtsas mtsas
Diff: Cellular/SMCIP.h
- Revision:
- 1:f155d94d6f3a
- Parent:
- 0:830c436480e3
--- a/Cellular/SMCIP.h Thu May 15 22:16:46 2014 +0000 +++ b/Cellular/SMCIP.h Mon May 19 12:34:32 2014 -0500 @@ -1,4 +1,133 @@ -#ifndef SMCIP_H -#define SMCIP_H - -#endif \ No newline at end of file +#ifndef SMCIP_H +#define SMCIP_H + +#include <string> +#include <vector> + +#include "mbed.h" +#include "MTSBufferedIO.h" +#include "Cellular.h" + +namespace mts +{ + +/** This is a class for communicating with a Multi-Tech Systems SocketModem iCell. The +* SocketModem iCell is a family of carrier certified embedded cellular radio modules with +* a common hardware footprint and AT command set for built in IP-stack functionality. +* This class supports three main types of cellular radio interactions including: +* configuration and status AT command processing, SMS processing, and TCP Socket +* data connections. It should be noted that the radio can not process commands or +* SMS messages while having an open data connection at the same time. The concurrent +* capability may be added in a future release. This class also inherits from IPStack +* providing a common set of commands for communication devices that have an onboard +* IP Stack. It is also integrated with the standard mbed Sockets package and can therefore +* be used seamlessly with clients and services built on top of this interface already within +* the mbed library. +* +* All of the following examples use the Pin Names for the Freedom KL46Z board coupled with +* the SocketModem Shield Arduino compatible board. Please chage Pin Names accordingly to +* match your hardware configuration. It also assumes the use of RTS/CTS hardware handshaking +* using GPIOs. To disable this you will need to change settings on the radio module and +* and use the MTSSerial class instead of MTSSerialFlowControl. The default baud rate for the +* cellular radio is 115200 bps. +*/ + +class SMCIP : public Cellular +{ +public: + /** This static function is used to create or get a reference to a + * Cellular object. Cellular uses the singleton pattern, which means + * that you can only have one existing at a time. The first time you + * call getInstance this method creates a new uninitialized Cellular + * object and returns it. All future calls to this method will return + * a reference to the instance created during the first call. Note that + * you must call init on the returned instance before mnaking any other + * calls. If using this class's bindings to any of the Socket package + * classes like TCPSocketConnection, you must call this method and the + * init method on the returned object first, before even creating the + * other objects. + * + * @returns a reference to the single Cellular obect that has been created. + */ + SMCIP(); + + /** Destructs a Cellular object and frees all related resources. + */ + ~SMCIP(); + + virtual bool init(MTSBufferedIO* io); + + /** + * + */ + bool configureSignals(PinName DCD = NC, PinName DTR = NC, PinName RESET = NC); + + // Wifi connection based commands derived from CommInterface.h + virtual bool connect(); + virtual void disconnect(); + virtual bool isConnected(); + virtual void reset(); + + // TCP and UDP Socket related commands + // For behavior of the following methods refer to IPStack.h documentation + virtual bool bind(unsigned int port); + virtual bool open(const std::string& address, unsigned int port, Mode mode); + virtual bool isOpen(); + virtual bool close(); + virtual int read(char* data, int max, int timeout = -1); + virtual int write(const char* data, int length, int timeout = -1); + virtual unsigned int readable(); + virtual unsigned int writeable(); + virtual bool ping(const std::string& address = "8.8.8.8"); + virtual std::string getDeviceIP(); + virtual bool setDeviceIP(std::string address = "DHCP"); + + //Cellular functions that derive from Cellular.h + virtual std::string sendCommand(const std::string& command, unsigned int timeoutMillis, char esc = CR); + virtual Code sendBasicCommand(const std::string& command, unsigned int timeoutMillis, char esc = CR); + virtual Code setApn(const std::string& apn); + virtual Code setDns(const std::string& primary, const std::string& secondary = "0.0.0.0"); + + /** A method for configuring command ehco capability on the radio. This command + * sets whether sent characters are echoed back from the radio, in which case you + * will receive back every command you send. + * + * @param state if true echo will be turned off, otherwise it will be turned on. + * @returns the standard AT Code enumeration. + */ + Code echo(bool state); + + /** This method can be used to trade socket functionality for performance. + * In order to enable a socket connection to be closed by the client side programtically, + * this class must process all read and write data on the socket to guard the special + * escape character used to close an open socket connection. It is recommened that you + * use the default of true unless the overhead of these operations is too significant. + * + * @param enabled set to true if you want the socket closeable, otherwise false. The default + * is true. + * @returns the standard AT Code enumeration. + */ + Code setSocketCloseable(bool enabled = true); //ETX closes socket (ETX and DLE in payload are escaped with DLE) + +private: + MTSBufferedIO* io; //IO interface obect that the radio is accessed through. + bool echoMode; //Specifies if the echo mode is currently enabled. + + bool pppConnected; //Specifies if a PPP session is currently connected. + std::string apn; //A string that holds the APN for the radio. + + Mode mode; //The current socket Mode. + bool socketOpened; //Specifies if a Socket is presently opened. + bool socketCloseable; //Specifies is a Socket can be closed. + unsigned int local_port; //Holds the local port for socket connections. + std::string local_address; //Holds the local address for socket connections. + unsigned int host_port; //Holds the remote port for socket connections. + std::string host_address; //Holds the remote address for socket connections. + DigitalIn* dcd; //Maps to the radio's dcd signal + DigitalOut* dtr; //Maps to the radio's dtr signal + DigitalOut* resetLine; //Maps to the radio's reset signal +}; + +} + +#endif