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

Dependents:   mtsas mtsas mtsas mtsas

Committer:
Vanger
Date:
Tue Oct 21 17:26:05 2014 +0000
Revision:
66:8c55e2bf7270
Parent:
56:43205bd2752a
Child:
67:7c705fe2acec
Added a flag for close() calls to support closing the connection without clearing the buffer data.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Vanger 52:2cb58398a4f9 1 #ifndef EASYIP_H
Vanger 52:2cb58398a4f9 2 #define EASYIP_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 49:1fc51c53cebf 12 /** This class implements the same interface used for UIP version radios on an Easy IP radio
Vanger 49:1fc51c53cebf 13 * using the Hayes AT command set.
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 43:91c5e53f508f 25 *
Vanger 52:2cb58398a4f9 26 * Example code is found under Cellular.h
Vanger 33:3b6f3904dde0 27 */
Vanger 33:3b6f3904dde0 28 class EasyIP : public Cellular
Vanger 26:2b769ed8de4f 29 {
Vanger 26:2b769ed8de4f 30 public:
Vanger 33:3b6f3904dde0 31 /** This static function is used to create or get a reference to a
Vanger 26:2b769ed8de4f 32 * Cellular object. Cellular uses the singleton pattern, which means
Vanger 26:2b769ed8de4f 33 * that you can only have one existing at a time. The first time you
Vanger 26:2b769ed8de4f 34 * call getInstance this method creates a new uninitialized Cellular
Vanger 26:2b769ed8de4f 35 * object and returns it. All future calls to this method will return
Vanger 26:2b769ed8de4f 36 * a reference to the instance created during the first call. Note that
Vanger 26:2b769ed8de4f 37 * you must call init on the returned instance before mnaking any other
Vanger 26:2b769ed8de4f 38 * calls. If using this class's bindings to any of the Socket package
Vanger 26:2b769ed8de4f 39 * classes like TCPSocketConnection, you must call this method and the
Vanger 26:2b769ed8de4f 40 * init method on the returned object first, before even creating the
Vanger 26:2b769ed8de4f 41 * other objects.
Vanger 26:2b769ed8de4f 42 *
Vanger 26:2b769ed8de4f 43 * @returns a reference to the single Cellular obect that has been created.
Vanger 26:2b769ed8de4f 44 */
Vanger 26:2b769ed8de4f 45 EasyIP(Radio type);
Vanger 34:7d412c989964 46
Vanger 26:2b769ed8de4f 47 /** Destructs a Cellular object and frees all related resources.
Vanger 26:2b769ed8de4f 48 */
Vanger 26:2b769ed8de4f 49 ~EasyIP();
Vanger 34:7d412c989964 50
Vanger 33:3b6f3904dde0 51 /** Initializes the MTS IO buffer
Vanger 33:3b6f3904dde0 52 */
Vanger 26:2b769ed8de4f 53 virtual bool init(MTSBufferedIO* io);
Vanger 33:3b6f3904dde0 54
Vanger 33:3b6f3904dde0 55 /** PPP connect command.
Vanger 33:3b6f3904dde0 56 * Connects the radio to the cellular network.
Vanger 33:3b6f3904dde0 57 *
Vanger 33:3b6f3904dde0 58 * @returns true if PPP connection to the network succeeded,
Vanger 33:3b6f3904dde0 59 * false if the PPP connection failed.
Vanger 33:3b6f3904dde0 60 */
Vanger 26:2b769ed8de4f 61 virtual bool connect();
Vanger 33:3b6f3904dde0 62
Vanger 33:3b6f3904dde0 63 /** PPP disconnect command.
Vanger 33:3b6f3904dde0 64 * Disconnects from the PPP network, and will also close active socket
Vanger 33:3b6f3904dde0 65 * connection if open.
Vanger 33:3b6f3904dde0 66 */
Vanger 26:2b769ed8de4f 67 virtual void disconnect();
Vanger 33:3b6f3904dde0 68
Vanger 33:3b6f3904dde0 69 /** Checks if the radio is connected to the cell network.
Vanger 33:3b6f3904dde0 70 * Checks antenna signal, cell tower registration, and context activation
Vanger 33:3b6f3904dde0 71 * before finally pinging (4 pings, 32 bytes each) to confirm PPP connection
Vanger 33:3b6f3904dde0 72 * to network. Will return true if there is an open socket connection as well.
Vanger 33:3b6f3904dde0 73 *
Vanger 33:3b6f3904dde0 74 * @returns true if there is a PPP connection to the cell network, false
Vanger 33:3b6f3904dde0 75 * if there is no PPP connection to the cell network.
Vanger 33:3b6f3904dde0 76 */
Vanger 26:2b769ed8de4f 77 virtual bool isConnected();
Vanger 33:3b6f3904dde0 78
Vanger 33:3b6f3904dde0 79 /** Resets the radio/modem.
Vanger 33:3b6f3904dde0 80 * Disconnects all active PPP and socket connections to do so.
Vanger 33:3b6f3904dde0 81 */
Vanger 26:2b769ed8de4f 82 virtual void reset();
Vanger 26:2b769ed8de4f 83
Vanger 26:2b769ed8de4f 84 // TCP and UDP Socket related commands
Vanger 26:2b769ed8de4f 85 // For behavior of the following methods refer to IPStack.h documentation
Vanger 56:43205bd2752a 86
Vanger 26:2b769ed8de4f 87 virtual bool open(const std::string& address, unsigned int port, Mode mode);
Vanger 66:8c55e2bf7270 88 virtual bool close(bool clearBuffer);
Vanger 31:529db15abda7 89 virtual int read(char* data, int max, int timeout = -1);
Vanger 26:2b769ed8de4f 90 virtual int write(const char* data, int length, int timeout = -1);
Vanger 52:2cb58398a4f9 91
Vanger 52:2cb58398a4f9 92 /** Pings specified DNS or IP address
Vanger 52:2cb58398a4f9 93 * Google DNS server used as default ping address
Vanger 52:2cb58398a4f9 94 * @returns true if ping received alive response else false
Vanger 52:2cb58398a4f9 95 */
Vanger 52:2cb58398a4f9 96 virtual bool ping(const std::string& address = "8.8.8.8");
Vanger 26:2b769ed8de4f 97
Vanger 33:3b6f3904dde0 98 /** Sets the APN
Vanger 33:3b6f3904dde0 99 *
Vanger 33:3b6f3904dde0 100 * @param apn c-string of the APN to use
Vanger 33:3b6f3904dde0 101 *
Vanger 33:3b6f3904dde0 102 * @returns MTS_SUCCESS if the APN was set, or is not needed, else it
Vanger 33:3b6f3904dde0 103 * returns the result of the AT command sent to the radio to set the APN
Vanger 33:3b6f3904dde0 104 */
Vanger 26:2b769ed8de4f 105 virtual Code setApn(const std::string& apn);
Vanger 33:3b6f3904dde0 106
Vanger 33:3b6f3904dde0 107 private:
Vanger 33:3b6f3904dde0 108 /** Function that sends +++ to the radio to exit data mode
Vanger 33:3b6f3904dde0 109 * returns true if it successfully exits from online mode, else
Vanger 33:3b6f3904dde0 110 * it returns false. Used due to the fact that AT commands
Vanger 33:3b6f3904dde0 111 * cannot be sent while in data mode.
Vanger 33:3b6f3904dde0 112 *
Vanger 33:3b6f3904dde0 113 * @returns true if the radio dropped from data mode to commande mode
Vanger 33:3b6f3904dde0 114 * or is already in command mode (socket is still open in the background),
Vanger 33:3b6f3904dde0 115 * and false if the radio failed to switch to command mode.
Vanger 33:3b6f3904dde0 116 */
Vanger 33:3b6f3904dde0 117 virtual bool sendEscapeCommand();
Vanger 33:3b6f3904dde0 118
Vanger 33:3b6f3904dde0 119 /** Switches to command mode, queries the status of the socket connection,
Vanger 33:3b6f3904dde0 120 * and then returns back to the active socket connection (if still open)
Vanger 33:3b6f3904dde0 121 *
Vanger 33:3b6f3904dde0 122 * @returns true if a socket is currently open, otherwise it returns false
Vanger 33:3b6f3904dde0 123 */
Vanger 33:3b6f3904dde0 124 virtual bool socketCheck();
Vanger 26:2b769ed8de4f 125 };
Vanger 26:2b769ed8de4f 126
Vanger 26:2b769ed8de4f 127 }
Vanger 26:2b769ed8de4f 128
Vanger 52:2cb58398a4f9 129 #endif /* EASYIP_H */