A library for talking to Multi-Tech's Cellular SocketModem Devices.
Dependents: M2X_dev axeda_wrapper_dev MTS_M2x_Example1 MTS_Cellular_Connect_Example ... more
cellular/Cellular.h@30:06c756af6c5c, 2013-12-18 (annotated)
- Committer:
- mfiore
- Date:
- Wed Dec 18 16:11:36 2013 +0000
- Revision:
- 30:06c756af6c5c
- Parent:
- 27:8e6188cbcfd4
- Parent:
- 29:7408b1bdad37
- Child:
- 33:e04aa7c013c9
merged; fixed conflicts in Cellular.h
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jengbrecht | 0:563b70517320 | 1 | #ifndef CELLULAR_H |
jengbrecht | 0:563b70517320 | 2 | #define CELLULAR_H |
jengbrecht | 0:563b70517320 | 3 | |
sgodinez | 11:134435d8a2d5 | 4 | #include "IPStack.h" |
sgodinez | 11:134435d8a2d5 | 5 | #include "MTSBufferedIO.h" |
jengbrecht | 0:563b70517320 | 6 | #include "mbed.h" |
jengbrecht | 0:563b70517320 | 7 | #include <string> |
sgodinez | 4:6561c9128c6f | 8 | #include <vector> |
jengbrecht | 0:563b70517320 | 9 | |
jengbrecht | 27:8e6188cbcfd4 | 10 | #define PINGDELAY 3 //Time to wait on each ping for a response before timimg out (seconds) |
jengbrecht | 27:8e6188cbcfd4 | 11 | #define PINGNUM 4 //Number of pings to try on ping command |
jengbrecht | 27:8e6188cbcfd4 | 12 | |
jengbrecht | 27:8e6188cbcfd4 | 13 | // An array of strings for printing the names of the Code enum. |
jengbrecht | 27:8e6188cbcfd4 | 14 | const string CodeNames[] = {"OK", "ERROR", "NO_RESPONSE", "FAILURE"}; |
jengbrecht | 27:8e6188cbcfd4 | 15 | |
jengbrecht | 27:8e6188cbcfd4 | 16 | // An array of strings for printing the names of the Registration enum. |
jengbrecht | 27:8e6188cbcfd4 | 17 | const string RegistrationNames[] = {"NOT_REGISTERED", "REGISTERED", "SEARCHING", "DENIED", "UNKNOWN", "ROAMING"}; |
jengbrecht | 27:8e6188cbcfd4 | 18 | |
jengbrecht | 27:8e6188cbcfd4 | 19 | |
jengbrecht | 27:8e6188cbcfd4 | 20 | /** This is a class for communicating with a Multi-Tech Systems SocketModem iCell. The |
jengbrecht | 27:8e6188cbcfd4 | 21 | * SocketModem iCell is a family of carrier certified embedded cellular radio modules with |
jengbrecht | 27:8e6188cbcfd4 | 22 | * a common hardware footprint and AT command set for built in IP-stack functionality. |
jengbrecht | 27:8e6188cbcfd4 | 23 | * This class supports three main types of cellular radio interactions including: |
jengbrecht | 27:8e6188cbcfd4 | 24 | * configuration and status AT command processing, SMS processing, and TCP/UDP Socket |
jengbrecht | 27:8e6188cbcfd4 | 25 | * data connections. It should be noted that the radio can not process commands or |
jengbrecht | 27:8e6188cbcfd4 | 26 | * SMS messages while having an open data connection at the same time. The concurrent |
jengbrecht | 27:8e6188cbcfd4 | 27 | * capability may be added in a future release. This class also inherits from IPStack |
jengbrecht | 27:8e6188cbcfd4 | 28 | * providing a common set of commands for communication devices that have an onboard |
jengbrecht | 27:8e6188cbcfd4 | 29 | * IP Stack. It is also integrated with the standard Mbed Sockets package and can therefore |
jengbrecht | 27:8e6188cbcfd4 | 30 | * be used seamlessly with clients and services built on top of this interface already within |
jengbrecht | 27:8e6188cbcfd4 | 31 | * the Mbed library. |
jengbrecht | 27:8e6188cbcfd4 | 32 | * |
jengbrecht | 27:8e6188cbcfd4 | 33 | * All of the following examples use the Pin Names for the Freedom KL46Z board coupled with |
jengbrecht | 27:8e6188cbcfd4 | 34 | * the SocketModem Shield Arduino compatible board. Please chage Pin Names accordingly to |
jengbrecht | 27:8e6188cbcfd4 | 35 | * match your hardware configuration. It also assumes the use of RTS/CTS hardware handshaking |
jengbrecht | 27:8e6188cbcfd4 | 36 | * using GPIOs. To disable this you will need to change settings on the radio module and |
jengbrecht | 27:8e6188cbcfd4 | 37 | * and use the MTSSerial class instead of MTSSerialFlowControl. The default baud rate for the |
jengbrecht | 27:8e6188cbcfd4 | 38 | * cellular radio is 115200 bps. |
jengbrecht | 27:8e6188cbcfd4 | 39 | * |
jengbrecht | 27:8e6188cbcfd4 | 40 | * The following set of example code demonstrates how to send and receive configuration and |
jengbrecht | 27:8e6188cbcfd4 | 41 | * status AT commands with the radio: |
jengbrecht | 27:8e6188cbcfd4 | 42 | * @code |
jengbrecht | 27:8e6188cbcfd4 | 43 | * #include "mbed.h" |
jengbrecht | 27:8e6188cbcfd4 | 44 | * #include "Cellular.h" |
jengbrecht | 27:8e6188cbcfd4 | 45 | * #include "MTSSerialFlowControl.h" |
jengbrecht | 27:8e6188cbcfd4 | 46 | * |
jengbrecht | 27:8e6188cbcfd4 | 47 | * main() { |
jengbrecht | 27:8e6188cbcfd4 | 48 | * //Wait for radio to boot up |
jengbrecht | 27:8e6188cbcfd4 | 49 | * wait(15); |
jengbrecht | 27:8e6188cbcfd4 | 50 | * |
jengbrecht | 27:8e6188cbcfd4 | 51 | * //Setup serial interface to radio |
jengbrecht | 27:8e6188cbcfd4 | 52 | * MTSSerialFlowControl* serial = new MTSSerialFlowControl(PTD3, PTD2, PTA12, PTC8); |
jengbrecht | 27:8e6188cbcfd4 | 53 | * serial->baud(115200); |
jengbrecht | 27:8e6188cbcfd4 | 54 | * |
jengbrecht | 27:8e6188cbcfd4 | 55 | * //Setup Cellular class |
jengbrecht | 27:8e6188cbcfd4 | 56 | * Cellular* cellular = Cellular::getInstance(serial); |
jengbrecht | 27:8e6188cbcfd4 | 57 | * |
jengbrecht | 27:8e6188cbcfd4 | 58 | * //Run status and configuration commands |
jengbrecht | 27:8e6188cbcfd4 | 59 | * printf("Start Status and Configuration Example\n\r"); |
jengbrecht | 27:8e6188cbcfd4 | 60 | * printf("test: %s\n\r", CodeNames[cellular->test()]); |
jengbrecht | 27:8e6188cbcfd4 | 61 | * printf("Phone Number: %s\n\r", cellular->getPhoneNumber()); |
jengbrecht | 27:8e6188cbcfd4 | 62 | * printf("Signal Strength: %d\n\r", cellular->getSignalStrength()); |
jengbrecht | 27:8e6188cbcfd4 | 63 | * printf("Registration State: %s\n\r", RegistrationNames[cellular->getRegistration()]); |
jengbrecht | 27:8e6188cbcfd4 | 64 | * printf("Send Basic Command (AT): %s\n\r", CodeNames[cellular->sendBasicCommand("AT", 1000)]); |
jengbrecht | 27:8e6188cbcfd4 | 65 | * printf("Send Command (AT+CSQ): %s\n\r", sendCommand("AT+CSQ", 1000)); |
jengbrecht | 27:8e6188cbcfd4 | 66 | * |
jengbrecht | 27:8e6188cbcfd4 | 67 | * printf("End Program\n\r"); |
jengbrecht | 27:8e6188cbcfd4 | 68 | * } |
jengbrecht | 27:8e6188cbcfd4 | 69 | * @endcode |
jengbrecht | 27:8e6188cbcfd4 | 70 | * |
jengbrecht | 27:8e6188cbcfd4 | 71 | * The following set of example code demonstrates how process SMS messages: |
jengbrecht | 27:8e6188cbcfd4 | 72 | * @code |
jengbrecht | 27:8e6188cbcfd4 | 73 | * #include "mbed.h" |
jengbrecht | 27:8e6188cbcfd4 | 74 | * @endcode |
jengbrecht | 27:8e6188cbcfd4 | 75 | * |
jengbrecht | 27:8e6188cbcfd4 | 76 | * The following set of example code demonstrates how to setup and verify a cellular data |
jengbrecht | 27:8e6188cbcfd4 | 77 | * connection: |
jengbrecht | 27:8e6188cbcfd4 | 78 | * @code |
jengbrecht | 27:8e6188cbcfd4 | 79 | * #include "mbed.h" |
jengbrecht | 27:8e6188cbcfd4 | 80 | * #include "Cellular.h" |
jengbrecht | 27:8e6188cbcfd4 | 81 | * #include "MTSSerialFlowControl.h" |
jengbrecht | 27:8e6188cbcfd4 | 82 | * |
jengbrecht | 27:8e6188cbcfd4 | 83 | * main() { |
jengbrecht | 27:8e6188cbcfd4 | 84 | * //Wait for radio to boot up |
jengbrecht | 27:8e6188cbcfd4 | 85 | * wait(20); |
jengbrecht | 27:8e6188cbcfd4 | 86 | * |
jengbrecht | 27:8e6188cbcfd4 | 87 | * //Setup serial interface to radio |
jengbrecht | 27:8e6188cbcfd4 | 88 | * MTSSerialFlowControl* serial = new MTSSerialFlowControl(PTD3, PTD2, PTA12, PTC8); |
jengbrecht | 27:8e6188cbcfd4 | 89 | * serial->baud(115200); |
jengbrecht | 27:8e6188cbcfd4 | 90 | * |
jengbrecht | 27:8e6188cbcfd4 | 91 | * //Setup Cellular class |
jengbrecht | 27:8e6188cbcfd4 | 92 | * Cellular* cellular = Cellular::getInstance(serial); |
jengbrecht | 27:8e6188cbcfd4 | 93 | * |
jengbrecht | 27:8e6188cbcfd4 | 94 | * //Start Test |
jengbrecht | 27:8e6188cbcfd4 | 95 | * printf("Start Network Connectivity Example\n\r"); |
jengbrecht | 27:8e6188cbcfd4 | 96 | * printf("test: %s\n\r", CodeNames[cellular->test()]); |
jengbrecht | 27:8e6188cbcfd4 | 97 | * printf("Set APN: %s\n\r", CodeNames[cellular->setApn("wap.cingular")]) //Use APN from service provider!!! |
jengbrecht | 27:8e6188cbcfd4 | 98 | * |
jengbrecht | 27:8e6188cbcfd4 | 99 | * //Setup a data connection |
jengbrecht | 27:8e6188cbcfd4 | 100 | * printf("Attempting to Connect\n\r"); |
jengbrecht | 27:8e6188cbcfd4 | 101 | * while (cellular->connect()) { |
jengbrecht | 27:8e6188cbcfd4 | 102 | * wait(1); |
jengbrecht | 27:8e6188cbcfd4 | 103 | * } |
jengbrecht | 27:8e6188cbcfd4 | 104 | * printf("Connected to Network!\n\r"); |
jengbrecht | 27:8e6188cbcfd4 | 105 | * |
jengbrecht | 27:8e6188cbcfd4 | 106 | * //Try pinging default server "8.8.8.8" |
jengbrecht | 27:8e6188cbcfd4 | 107 | * printf("Ping Valid: %s\n\r", cellular->ping() ? "true" : "false"); |
jengbrecht | 27:8e6188cbcfd4 | 108 | * |
jengbrecht | 27:8e6188cbcfd4 | 109 | * printf("End Program\n\r"); |
jengbrecht | 27:8e6188cbcfd4 | 110 | * } |
jengbrecht | 27:8e6188cbcfd4 | 111 | * @endcode |
jengbrecht | 27:8e6188cbcfd4 | 112 | * |
jengbrecht | 27:8e6188cbcfd4 | 113 | * The following set of example code demonstrates how to setup and use a TCP socket connection |
jengbrecht | 27:8e6188cbcfd4 | 114 | * using the native commands from this class: |
jengbrecht | 27:8e6188cbcfd4 | 115 | * @code |
jengbrecht | 27:8e6188cbcfd4 | 116 | * #include "mbed.h" |
jengbrecht | 27:8e6188cbcfd4 | 117 | * @endcode |
jengbrecht | 27:8e6188cbcfd4 | 118 | * |
jengbrecht | 27:8e6188cbcfd4 | 119 | * The following set of example code demonstrates how to setup and use a TCP socket connection |
jengbrecht | 27:8e6188cbcfd4 | 120 | * using the Mbed compatible Socket interfaces. |
jengbrecht | 27:8e6188cbcfd4 | 121 | * @code |
jengbrecht | 27:8e6188cbcfd4 | 122 | * #include "mbed.h" |
jengbrecht | 27:8e6188cbcfd4 | 123 | * @endcode |
jengbrecht | 27:8e6188cbcfd4 | 124 | */ |
jengbrecht | 23:bc6f98a1eb22 | 125 | |
sgodinez | 11:134435d8a2d5 | 126 | class Cellular : virtual IPStack |
jengbrecht | 0:563b70517320 | 127 | { |
jengbrecht | 0:563b70517320 | 128 | public: |
jengbrecht | 27:8e6188cbcfd4 | 129 | /// An enumeration for common responses to an AT command. |
jengbrecht | 0:563b70517320 | 130 | enum Code { |
jengbrecht | 0:563b70517320 | 131 | OK, ERROR, NO_RESPONSE, FAILURE |
jengbrecht | 0:563b70517320 | 132 | }; |
jengbrecht | 0:563b70517320 | 133 | |
jengbrecht | 27:8e6188cbcfd4 | 134 | /// An enumeration for escape characters at the end of AT commands. |
jengbrecht | 0:563b70517320 | 135 | enum ESC_CHAR { |
sgodinez | 13:0af863114629 | 136 | CR, CTRL_Z, NONE |
jengbrecht | 0:563b70517320 | 137 | }; |
jengbrecht | 0:563b70517320 | 138 | |
jengbrecht | 27:8e6188cbcfd4 | 139 | /// An enumeration of radio registration states with a cell tower. |
jengbrecht | 0:563b70517320 | 140 | enum Registration { |
jengbrecht | 0:563b70517320 | 141 | NOT_REGISTERED, REGISTERED, SEARCHING, DENIED, UNKNOWN, ROAMING |
jengbrecht | 0:563b70517320 | 142 | }; |
jengbrecht | 0:563b70517320 | 143 | |
sgodinez | 4:6561c9128c6f | 144 | struct Sms { |
jengbrecht | 27:8e6188cbcfd4 | 145 | std::string phoneNumber; |
jengbrecht | 27:8e6188cbcfd4 | 146 | std::string message; |
jengbrecht | 27:8e6188cbcfd4 | 147 | std::string timestamp; |
sgodinez | 4:6561c9128c6f | 148 | }; |
jengbrecht | 27:8e6188cbcfd4 | 149 | |
jengbrecht | 27:8e6188cbcfd4 | 150 | /** Destructs a Cellular object and frees all related resources. |
jengbrecht | 27:8e6188cbcfd4 | 151 | */ |
jengbrecht | 0:563b70517320 | 152 | ~Cellular(); |
jengbrecht | 27:8e6188cbcfd4 | 153 | |
sgodinez | 19:38794784e009 | 154 | static Cellular* getInstance(); |
sgodinez | 19:38794784e009 | 155 | static Cellular* getInstance(MTSBufferedIO* io); |
jengbrecht | 0:563b70517320 | 156 | |
jengbrecht | 27:8e6188cbcfd4 | 157 | /** This method establishes a data connection on the cellular radio. |
jengbrecht | 27:8e6188cbcfd4 | 158 | * Note that before calling you must have an activated radio and if |
jengbrecht | 27:8e6188cbcfd4 | 159 | * using a SIM card set the APN using the setApn method. The APN can |
jengbrecht | 27:8e6188cbcfd4 | 160 | * be obtained from your cellular service provider. |
jengbrecht | 27:8e6188cbcfd4 | 161 | * |
jengbrecht | 27:8e6188cbcfd4 | 162 | * @returns true if the connection was successfully established, otherwise |
jengbrecht | 27:8e6188cbcfd4 | 163 | * false on an error. |
jengbrecht | 27:8e6188cbcfd4 | 164 | */ |
jengbrecht | 27:8e6188cbcfd4 | 165 | virtual bool connect(); |
jengbrecht | 27:8e6188cbcfd4 | 166 | |
jengbrecht | 27:8e6188cbcfd4 | 167 | /** This method is used to stop a previously established cellular data connection. |
jengbrecht | 27:8e6188cbcfd4 | 168 | */ |
sgodinez | 11:134435d8a2d5 | 169 | virtual void disconnect(); |
jengbrecht | 27:8e6188cbcfd4 | 170 | |
jengbrecht | 27:8e6188cbcfd4 | 171 | /** This method is used to check if the radio currently has a data connection |
jengbrecht | 27:8e6188cbcfd4 | 172 | * established. |
jengbrecht | 27:8e6188cbcfd4 | 173 | * |
jengbrecht | 27:8e6188cbcfd4 | 174 | * @returns true if a data connection exists, otherwise false. |
jengbrecht | 27:8e6188cbcfd4 | 175 | */ |
sgodinez | 11:134435d8a2d5 | 176 | virtual bool isConnected(); |
jengbrecht | 0:563b70517320 | 177 | |
sgodinez | 11:134435d8a2d5 | 178 | // Used for TCPSocketConnection & UDPSocketConnection |
sgodinez | 11:134435d8a2d5 | 179 | virtual bool bind(unsigned int port); |
sgodinez | 11:134435d8a2d5 | 180 | virtual bool open(const std::string& address, unsigned int port, Mode mode); |
sgodinez | 11:134435d8a2d5 | 181 | virtual bool isOpen(); |
sgodinez | 17:2d7c4ea7491b | 182 | virtual bool close(); |
sgodinez | 11:134435d8a2d5 | 183 | virtual int read(char* data, int max, int timeout = -1); |
sgodinez | 11:134435d8a2d5 | 184 | virtual int write(char* data, int length, int timeout = -1); |
sgodinez | 11:134435d8a2d5 | 185 | virtual unsigned int readable(); |
sgodinez | 11:134435d8a2d5 | 186 | virtual unsigned int writeable(); |
jengbrecht | 27:8e6188cbcfd4 | 187 | |
sgodinez | 11:134435d8a2d5 | 188 | //Other |
mfiore | 29:7408b1bdad37 | 189 | /** A method to reset the Multi-Tech Socket Modem. This command brings down the |
mfiore | 29:7408b1bdad37 | 190 | * PPP link if it is up. After this function is called, at least 30 seconds should |
mfiore | 29:7408b1bdad37 | 191 | * be allowed for the cellular radio to come back up before any other Cellular |
mfiore | 29:7408b1bdad37 | 192 | * functions are called. |
mfiore | 29:7408b1bdad37 | 193 | */ |
mfiore | 29:7408b1bdad37 | 194 | /** this needs to be investigated. After we tell the radio to reset and wait 30 seconds, |
mfiore | 29:7408b1bdad37 | 195 | * we can't seem to get it to respond to even a simple signal strength query. |
mfiore | 29:7408b1bdad37 | 196 | */ |
jengbrecht | 27:8e6188cbcfd4 | 197 | virtual void reset(); |
sgodinez | 11:134435d8a2d5 | 198 | |
sgodinez | 11:134435d8a2d5 | 199 | //Cellular Radio Specific |
jengbrecht | 27:8e6188cbcfd4 | 200 | /** A method for sending a generic AT command to the radio. Note that you cannot |
jengbrecht | 27:8e6188cbcfd4 | 201 | * send commands and have a data connection at the same time. |
jengbrecht | 27:8e6188cbcfd4 | 202 | * |
jengbrecht | 27:8e6188cbcfd4 | 203 | * @param command the command to send to the radio without the escape character. |
jengbrecht | 27:8e6188cbcfd4 | 204 | * @param timeoutMillis the time in millis to wait for a response before returning. |
jengbrecht | 27:8e6188cbcfd4 | 205 | * @param esc escape character to add at the end of the command, defaults to |
jengbrecht | 27:8e6188cbcfd4 | 206 | * carriage return (CR). |
jengbrecht | 27:8e6188cbcfd4 | 207 | * @returns all data received from the radio after the command as a string. |
jengbrecht | 27:8e6188cbcfd4 | 208 | */ |
sgodinez | 11:134435d8a2d5 | 209 | std::string sendCommand(std::string command, int timeoutMillis, ESC_CHAR esc = CR); |
jengbrecht | 27:8e6188cbcfd4 | 210 | |
jengbrecht | 27:8e6188cbcfd4 | 211 | /** A method for sending a basic AT command to the radio. A basic AT command is |
jengbrecht | 27:8e6188cbcfd4 | 212 | * one that simply has a response of either OK or ERROR without any other information. |
jengbrecht | 27:8e6188cbcfd4 | 213 | * Note that you cannot send commands and have a data connection at the same time. |
jengbrecht | 27:8e6188cbcfd4 | 214 | * |
jengbrecht | 27:8e6188cbcfd4 | 215 | * @param command the command to send to the radio without the escape character. |
jengbrecht | 27:8e6188cbcfd4 | 216 | * @param timeoutMillis the time in millis to wait for a response before returning. |
jengbrecht | 27:8e6188cbcfd4 | 217 | * @param esc escape character to add at the end of the command, defaults to |
jengbrecht | 27:8e6188cbcfd4 | 218 | * carriage return (CR). |
jengbrecht | 27:8e6188cbcfd4 | 219 | * @returns the standard AT Code enumeration. |
jengbrecht | 27:8e6188cbcfd4 | 220 | */ |
sgodinez | 11:134435d8a2d5 | 221 | Code sendBasicCommand(std::string command, int timeoutMillis, ESC_CHAR esc = CR); |
sgodinez | 11:134435d8a2d5 | 222 | |
jengbrecht | 23:bc6f98a1eb22 | 223 | /** A method for testing command access to the radio. This method sends the |
jengbrecht | 27:8e6188cbcfd4 | 224 | * command "AT" to the radio, which is a standard radio test to see if you |
jengbrecht | 23:bc6f98a1eb22 | 225 | * have command access to the radio. |
jengbrecht | 23:bc6f98a1eb22 | 226 | * |
jengbrecht | 23:bc6f98a1eb22 | 227 | * @returns the standard AT Code enumeration. |
jengbrecht | 23:bc6f98a1eb22 | 228 | */ |
sgodinez | 11:134435d8a2d5 | 229 | Code test(); |
jengbrecht | 27:8e6188cbcfd4 | 230 | |
jengbrecht | 23:bc6f98a1eb22 | 231 | /** A method for configuring command ehco capability on the radio. This command |
jengbrecht | 23:bc6f98a1eb22 | 232 | * sets whether sent characters are echoed back from the radio, in which case you |
jengbrecht | 23:bc6f98a1eb22 | 233 | * will receive back every command you send. |
jengbrecht | 23:bc6f98a1eb22 | 234 | * |
jengbrecht | 23:bc6f98a1eb22 | 235 | * @param state if true echo will be turned off, otherwise it will be turned on. |
jengbrecht | 23:bc6f98a1eb22 | 236 | * @returns the standard AT Code enumeration. |
jengbrecht | 23:bc6f98a1eb22 | 237 | */ |
mfiore | 29:7408b1bdad37 | 238 | Code echo(bool state); |
jengbrecht | 23:bc6f98a1eb22 | 239 | |
jengbrecht | 23:bc6f98a1eb22 | 240 | /** A method for getting the signal strength of the radio. This method allows you to |
jengbrecht | 23:bc6f98a1eb22 | 241 | * get a value that maps to signal strength in dBm. Here 0-1 is Poor, 2-9 is Marginal, |
jengbrecht | 23:bc6f98a1eb22 | 242 | * 10-14 is Ok, 15-19 is Good, and 20+ is Excellent. If you get a result of 99 the |
jengbrecht | 27:8e6188cbcfd4 | 243 | * signal strength is not known or not detectable. |
jengbrecht | 23:bc6f98a1eb22 | 244 | * |
jengbrecht | 23:bc6f98a1eb22 | 245 | * @returns an integer representing the signal strength. |
jengbrecht | 23:bc6f98a1eb22 | 246 | */ |
jengbrecht | 0:563b70517320 | 247 | int getSignalStrength(); |
jengbrecht | 27:8e6188cbcfd4 | 248 | |
jengbrecht | 27:8e6188cbcfd4 | 249 | /** This method is used to get the phone number of the cellular radio if one exists. |
jengbrecht | 27:8e6188cbcfd4 | 250 | * |
jengbrecht | 27:8e6188cbcfd4 | 251 | * @returns the phone number as a string, otherwise "unknown" if it does not exist. |
jengbrecht | 27:8e6188cbcfd4 | 252 | */ |
sgodinez | 5:93e889a5abc6 | 253 | std::string getPhoneNumber(); |
jengbrecht | 27:8e6188cbcfd4 | 254 | |
jengbrecht | 27:8e6188cbcfd4 | 255 | /** This method is used to check the registration state of the radio with the cell tower. |
jengbrecht | 27:8e6188cbcfd4 | 256 | * If not appropriatley registered with the tower you cannot make a cellular connection. |
jengbrecht | 27:8e6188cbcfd4 | 257 | * |
jengbrecht | 27:8e6188cbcfd4 | 258 | * @returns the registration state as an enumeration type. |
jengbrecht | 27:8e6188cbcfd4 | 259 | */ |
sgodinez | 5:93e889a5abc6 | 260 | Registration getRegistration(); |
jengbrecht | 27:8e6188cbcfd4 | 261 | |
jengbrecht | 27:8e6188cbcfd4 | 262 | /** This method is used to set the radios APN if using a SIM card. Note that the APN |
jengbrecht | 27:8e6188cbcfd4 | 263 | * must be set correctly before you can make a data connection. The APN for your SIM |
jengbrecht | 27:8e6188cbcfd4 | 264 | * can be obtained by contacting your cellular service provider. |
jengbrecht | 27:8e6188cbcfd4 | 265 | * |
jengbrecht | 27:8e6188cbcfd4 | 266 | * @param the APN as a string. |
jengbrecht | 27:8e6188cbcfd4 | 267 | * @returns the standard AT Code enumeration. |
jengbrecht | 27:8e6188cbcfd4 | 268 | */ |
sgodinez | 11:134435d8a2d5 | 269 | Code setApn(const std::string& apn); |
jengbrecht | 27:8e6188cbcfd4 | 270 | |
jengbrecht | 27:8e6188cbcfd4 | 271 | /** This method is used to set the DNS which enables the use of URLs instead |
jengbrecht | 27:8e6188cbcfd4 | 272 | * of IP addresses when making a socket connection. |
jengbrecht | 27:8e6188cbcfd4 | 273 | * |
jengbrecht | 27:8e6188cbcfd4 | 274 | * @param the DNS server address as a string in form xxx.xxx.xxx.xxx. |
jengbrecht | 27:8e6188cbcfd4 | 275 | * @returns the standard AT Code enumeration. |
jengbrecht | 27:8e6188cbcfd4 | 276 | */ |
jengbrecht | 27:8e6188cbcfd4 | 277 | Code setDns(const std::string& address); |
jengbrecht | 27:8e6188cbcfd4 | 278 | |
jengbrecht | 27:8e6188cbcfd4 | 279 | /** This method is used test network connectivity by pinging a server. |
jengbrecht | 27:8e6188cbcfd4 | 280 | * |
jengbrecht | 27:8e6188cbcfd4 | 281 | * @param address the address of the server in format xxx.xxx.xxx.xxx. |
jengbrecht | 27:8e6188cbcfd4 | 282 | * @returns true if the ping was successful, otherwise false. |
jengbrecht | 27:8e6188cbcfd4 | 283 | */ |
jengbrecht | 23:bc6f98a1eb22 | 284 | bool ping(const std::string& address = "8.8.8.8"); |
sgodinez | 17:2d7c4ea7491b | 285 | Code setSocketCloseable(bool enabled = true); //ETX closes socket (ETX and DLE in payload are escaped with DLE) |
jengbrecht | 27:8e6188cbcfd4 | 286 | |
jengbrecht | 27:8e6188cbcfd4 | 287 | /** This method is used to send an SMS message. Note that you cannot send an |
jengbrecht | 27:8e6188cbcfd4 | 288 | * SMS message and have a data connection open at the same time. |
jengbrecht | 27:8e6188cbcfd4 | 289 | * |
jengbrecht | 27:8e6188cbcfd4 | 290 | * @param phoneNumber the phone number to send the message to as a string. |
jengbrecht | 27:8e6188cbcfd4 | 291 | * @param message the text message to be sent. |
jengbrecht | 27:8e6188cbcfd4 | 292 | * @returns the standard AT Code enumeration. |
jengbrecht | 27:8e6188cbcfd4 | 293 | */ |
jengbrecht | 27:8e6188cbcfd4 | 294 | Code sendSMS(const std::string& phoneNumber, const std::string& message); |
sgodinez | 4:6561c9128c6f | 295 | |
jengbrecht | 27:8e6188cbcfd4 | 296 | /** This method is used to send an SMS message. Note that you cannot send an |
jengbrecht | 27:8e6188cbcfd4 | 297 | * SMS message and have a data connection open at the same time. |
jengbrecht | 27:8e6188cbcfd4 | 298 | * |
jengbrecht | 27:8e6188cbcfd4 | 299 | * @param sms an Sms struct that contains all SMS transaction information. |
jengbrecht | 27:8e6188cbcfd4 | 300 | * @returns the standard AT Code enumeration. |
jengbrecht | 27:8e6188cbcfd4 | 301 | */ |
sgodinez | 4:6561c9128c6f | 302 | Code sendSMS(const Sms& sms); |
jengbrecht | 27:8e6188cbcfd4 | 303 | |
jengbrecht | 27:8e6188cbcfd4 | 304 | /** |
jengbrecht | 27:8e6188cbcfd4 | 305 | * |
jengbrecht | 27:8e6188cbcfd4 | 306 | */ |
sgodinez | 4:6561c9128c6f | 307 | std::vector<Cellular::Sms> getReceivedSms(); |
sgodinez | 4:6561c9128c6f | 308 | Code deleteAllReceivedSms(); |
sgodinez | 4:6561c9128c6f | 309 | Code deleteOnlyReceivedReadSms(); |
sgodinez | 19:38794784e009 | 310 | |
jengbrecht | 27:8e6188cbcfd4 | 311 | |
jengbrecht | 0:563b70517320 | 312 | private: |
jengbrecht | 23:bc6f98a1eb22 | 313 | static Cellular* instance; //Static pointer to the single Cellular object. |
sgodinez | 19:38794784e009 | 314 | |
jengbrecht | 23:bc6f98a1eb22 | 315 | MTSBufferedIO* io; //IO interface obect that the radio is accessed through. |
jengbrecht | 23:bc6f98a1eb22 | 316 | bool echoMode; //Specifies if the echo mode is currently enabled. |
jengbrecht | 27:8e6188cbcfd4 | 317 | |
jengbrecht | 23:bc6f98a1eb22 | 318 | bool pppConnected; //Specifies if a PPP session is currently connected. |
jengbrecht | 23:bc6f98a1eb22 | 319 | std::string apn; //A string that holds the APN for the radio. |
jengbrecht | 27:8e6188cbcfd4 | 320 | |
jengbrecht | 27:8e6188cbcfd4 | 321 | Mode mode; |
jengbrecht | 23:bc6f98a1eb22 | 322 | bool socketOpened; //Specifies if a Socket is presently opened. |
jengbrecht | 23:bc6f98a1eb22 | 323 | bool socketCloseable; //Specifies is a Socket can be closed. |
jengbrecht | 27:8e6188cbcfd4 | 324 | unsigned int local_port; //Holds the local port for socket connections. |
jengbrecht | 27:8e6188cbcfd4 | 325 | std::string local_address; //Holds the local address for socket connections. |
jengbrecht | 27:8e6188cbcfd4 | 326 | unsigned int host_port; //Holds the remote port for socket connections. |
jengbrecht | 27:8e6188cbcfd4 | 327 | std::string host_address; //Holds the remote address for socket connections. |
mfiore | 29:7408b1bdad37 | 328 | DigitalIn* dcd; |
mfiore | 29:7408b1bdad37 | 329 | DigitalOut* dtr; |
sgodinez | 11:134435d8a2d5 | 330 | |
jengbrecht | 23:bc6f98a1eb22 | 331 | Cellular(); //Private constructor, use the getInstance() method. |
mfiore | 29:7408b1bdad37 | 332 | Cellular(MTSBufferedIO* io); //Private constructor, use the getInstance() method. |
jengbrecht | 0:563b70517320 | 333 | }; |
jengbrecht | 0:563b70517320 | 334 | |
jengbrecht | 0:563b70517320 | 335 | #endif /* CELLULAR_H */ |