Simple detection for LE910-NA1 modules
Fork of MTS-Cellular by
Cellular/EasyIP.h@81:87c20e68b7e7, 2017-09-26 (annotated)
- Committer:
- pferland
- Date:
- Tue Sep 26 04:52:47 2017 +0000
- Revision:
- 81:87c20e68b7e7
- Parent:
- 78:fc9d2b983744
Changed LE910-NA detection to recognize cat 1 modules
Who changed what in which revision?
User | Revision | Line number | New 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 | 67:7c705fe2acec | 88 | virtual bool close(bool shutdown); |
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 | |
mfiore | 78:fc9d2b983744 | 107 | /** Enables GPS. |
mfiore | 78:fc9d2b983744 | 108 | * @returns true if GPS gets or is enabled, false if GPS is not supported. |
mfiore | 78:fc9d2b983744 | 109 | */ |
mfiore | 78:fc9d2b983744 | 110 | virtual bool GPSenable(); |
mfiore | 78:fc9d2b983744 | 111 | |
mfiore | 78:fc9d2b983744 | 112 | /** Disables GPS. |
mfiore | 78:fc9d2b983744 | 113 | * @returns true if GPS gets or is disabled, false if GPS failed to disable. |
mfiore | 78:fc9d2b983744 | 114 | */ |
mfiore | 78:fc9d2b983744 | 115 | virtual bool GPSdisable(); |
mfiore | 78:fc9d2b983744 | 116 | |
mfiore | 78:fc9d2b983744 | 117 | /** Checks if GPS is enabled. |
mfiore | 78:fc9d2b983744 | 118 | * @returns true if GPS is enabled, false if GPS is disabled. |
mfiore | 78:fc9d2b983744 | 119 | */ |
mfiore | 78:fc9d2b983744 | 120 | virtual bool GPSenabled(); |
mfiore | 78:fc9d2b983744 | 121 | |
mfiore | 78:fc9d2b983744 | 122 | /** Get GPS position. |
mfiore | 78:fc9d2b983744 | 123 | * @returns a string containing the GPS position. |
mfiore | 78:fc9d2b983744 | 124 | */ |
mfiore | 78:fc9d2b983744 | 125 | virtual Cellular::gpsData GPSgetPosition(); |
mfiore | 78:fc9d2b983744 | 126 | |
mfiore | 78:fc9d2b983744 | 127 | /** Check for GPS fix. |
mfiore | 78:fc9d2b983744 | 128 | * @returns true if there is a fix and false otherwise. |
mfiore | 78:fc9d2b983744 | 129 | */ |
mfiore | 78:fc9d2b983744 | 130 | virtual bool GPSgotFix(); |
mfiore | 78:fc9d2b983744 | 131 | |
Vanger | 33:3b6f3904dde0 | 132 | private: |
Vanger | 33:3b6f3904dde0 | 133 | /** Function that sends +++ to the radio to exit data mode |
Vanger | 33:3b6f3904dde0 | 134 | * returns true if it successfully exits from online mode, else |
Vanger | 33:3b6f3904dde0 | 135 | * it returns false. Used due to the fact that AT commands |
Vanger | 33:3b6f3904dde0 | 136 | * cannot be sent while in data mode. |
Vanger | 33:3b6f3904dde0 | 137 | * |
Vanger | 33:3b6f3904dde0 | 138 | * @returns true if the radio dropped from data mode to commande mode |
Vanger | 33:3b6f3904dde0 | 139 | * or is already in command mode (socket is still open in the background), |
Vanger | 33:3b6f3904dde0 | 140 | * and false if the radio failed to switch to command mode. |
Vanger | 33:3b6f3904dde0 | 141 | */ |
Vanger | 33:3b6f3904dde0 | 142 | virtual bool sendEscapeCommand(); |
Vanger | 33:3b6f3904dde0 | 143 | |
Vanger | 33:3b6f3904dde0 | 144 | /** Switches to command mode, queries the status of the socket connection, |
Vanger | 33:3b6f3904dde0 | 145 | * and then returns back to the active socket connection (if still open) |
Vanger | 33:3b6f3904dde0 | 146 | * |
Vanger | 33:3b6f3904dde0 | 147 | * @returns true if a socket is currently open, otherwise it returns false |
Vanger | 33:3b6f3904dde0 | 148 | */ |
Vanger | 33:3b6f3904dde0 | 149 | virtual bool socketCheck(); |
Vanger | 26:2b769ed8de4f | 150 | }; |
Vanger | 26:2b769ed8de4f | 151 | |
Vanger | 26:2b769ed8de4f | 152 | } |
Vanger | 26:2b769ed8de4f | 153 | |
mfiore | 78:fc9d2b983744 | 154 | #endif /* EASYIP_H */ |