Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MTS-Cellular by
EasyIP.h
00001 #ifndef EASYIP_H 00002 #define EASYIP_H 00003 00004 #include <string> 00005 #include <vector> 00006 00007 #include "MTSBufferedIO.h" 00008 #include "Cellular.h" 00009 00010 namespace mts 00011 { 00012 /** This class implements the same interface used for UIP version radios on an Easy IP radio 00013 * using the Hayes AT command set. 00014 * (See the UIP class and documentation, "UIP.h") 00015 * This class supports four main types of cellular radio interactions including: 00016 * configuration and status AT-command processing, SMS processing, TCP Socket data connections, 00017 * and UDP data connections. It should be noted that the radio can not process commands or 00018 * SMS messages while having an open data connection at the same time. The concurrent 00019 * capability may be added in a future release. This class also inherits from IPStack 00020 * providing a common set of commands for communication devices that have an onboard 00021 * IP Stack. It is also integrated with the standard mbed Sockets package and can therefore 00022 * be used seamlessly with clients and services built on top of this interface already within 00023 * the mbed library. 00024 * The default baud rate for the cellular radio is 115200 bps. 00025 * 00026 * Example code is found under Cellular.h 00027 */ 00028 class EasyIP : public Cellular 00029 { 00030 public: 00031 /** This static function is used to create or get a reference to a 00032 * Cellular object. Cellular uses the singleton pattern, which means 00033 * that you can only have one existing at a time. The first time you 00034 * call getInstance this method creates a new uninitialized Cellular 00035 * object and returns it. All future calls to this method will return 00036 * a reference to the instance created during the first call. Note that 00037 * you must call init on the returned instance before mnaking any other 00038 * calls. If using this class's bindings to any of the Socket package 00039 * classes like TCPSocketConnection, you must call this method and the 00040 * init method on the returned object first, before even creating the 00041 * other objects. 00042 * 00043 * @returns a reference to the single Cellular obect that has been created. 00044 */ 00045 EasyIP(Radio type); 00046 00047 /** Destructs a Cellular object and frees all related resources. 00048 */ 00049 ~EasyIP(); 00050 00051 /** Initializes the MTS IO buffer 00052 */ 00053 virtual bool init(MTSBufferedIO* io); 00054 00055 /** PPP connect command. 00056 * Connects the radio to the cellular network. 00057 * 00058 * @returns true if PPP connection to the network succeeded, 00059 * false if the PPP connection failed. 00060 */ 00061 virtual bool connect(); 00062 00063 /** PPP disconnect command. 00064 * Disconnects from the PPP network, and will also close active socket 00065 * connection if open. 00066 */ 00067 virtual void disconnect(); 00068 00069 /** Checks if the radio is connected to the cell network. 00070 * Checks antenna signal, cell tower registration, and context activation 00071 * before finally pinging (4 pings, 32 bytes each) to confirm PPP connection 00072 * to network. Will return true if there is an open socket connection as well. 00073 * 00074 * @returns true if there is a PPP connection to the cell network, false 00075 * if there is no PPP connection to the cell network. 00076 */ 00077 virtual bool isConnected(); 00078 00079 /** Resets the radio/modem. 00080 * Disconnects all active PPP and socket connections to do so. 00081 */ 00082 virtual void reset(); 00083 00084 // TCP and UDP Socket related commands 00085 // For behavior of the following methods refer to IPStack.h documentation 00086 00087 virtual bool open(const std::string& address, unsigned int port, Mode mode); 00088 virtual bool close(bool shutdown); 00089 virtual int read(char* data, int max, int timeout = -1); 00090 virtual int write(const char* data, int length, int timeout = -1); 00091 00092 /** Pings specified DNS or IP address 00093 * Google DNS server used as default ping address 00094 * @returns true if ping received alive response else false 00095 */ 00096 virtual bool ping(const std::string& address = "8.8.8.8"); 00097 00098 /** Sets the APN 00099 * 00100 * @param apn c-string of the APN to use 00101 * 00102 * @returns MTS_SUCCESS if the APN was set, or is not needed, else it 00103 * returns the result of the AT command sent to the radio to set the APN 00104 */ 00105 virtual Code setApn(const std::string& apn); 00106 00107 /** Enables GPS. 00108 * @returns true if GPS gets or is enabled, false if GPS is not supported. 00109 */ 00110 virtual bool GPSenable(); 00111 00112 /** Disables GPS. 00113 * @returns true if GPS gets or is disabled, false if GPS failed to disable. 00114 */ 00115 virtual bool GPSdisable(); 00116 00117 /** Checks if GPS is enabled. 00118 * @returns true if GPS is enabled, false if GPS is disabled. 00119 */ 00120 virtual bool GPSenabled(); 00121 00122 /** Get GPS position. 00123 * @returns a string containing the GPS position. 00124 */ 00125 virtual Cellular::gpsData GPSgetPosition(); 00126 00127 /** Check for GPS fix. 00128 * @returns true if there is a fix and false otherwise. 00129 */ 00130 virtual bool GPSgotFix(); 00131 00132 private: 00133 /** Function that sends +++ to the radio to exit data mode 00134 * returns true if it successfully exits from online mode, else 00135 * it returns false. Used due to the fact that AT commands 00136 * cannot be sent while in data mode. 00137 * 00138 * @returns true if the radio dropped from data mode to commande mode 00139 * or is already in command mode (socket is still open in the background), 00140 * and false if the radio failed to switch to command mode. 00141 */ 00142 virtual bool sendEscapeCommand(); 00143 00144 /** Switches to command mode, queries the status of the socket connection, 00145 * and then returns back to the active socket connection (if still open) 00146 * 00147 * @returns true if a socket is currently open, otherwise it returns false 00148 */ 00149 virtual bool socketCheck(); 00150 }; 00151 00152 } 00153 00154 #endif /* EASYIP_H */
Generated on Tue Jul 12 2022 19:53:40 by
1.7.2
