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

Committer:
sgodinez
Date:
Thu Dec 19 21:27:25 2013 +0000
Revision:
43:3cacf019ed7d
Parent:
40:14342c4de476
Parent:
41:81d035fb0b6a
Child:
56:e5e5351f14b3
fixed merge conflict: setDns

Who changed what in which revision?

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