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

Dependents:   mtsas mtsas mtsas mtsas

Committer:
Vanger
Date:
Mon Aug 11 16:03:19 2014 +0000
Revision:
52:2cb58398a4f9
Parent:
31:529db15abda7
Child:
53:1aee5fe47adb
Removed parse response '>' from sendCommand() under Cellular.cpp, changed sendSMS() to verify sending SMS message under Cellular.cpp, changed disconnect() to have better flow under EasyIP.cpp, changed isConnected() to be simpler under EasyIP.cpp

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mfiore 0:830c436480e3 1 #ifndef CELLULAR_H
mfiore 0:830c436480e3 2 #define CELLULAR_H
mfiore 0:830c436480e3 3
Mike Fiore 1:f155d94d6f3a 4 #include <string>
Mike Fiore 1:f155d94d6f3a 5 #include <vector>
Mike Fiore 1:f155d94d6f3a 6
Mike Fiore 1:f155d94d6f3a 7 #include "IPStack.h"
Mike Fiore 1:f155d94d6f3a 8 #include "MTSBufferedIO.h"
Mike Fiore 2:10e72dce251d 9 #include "CellUtils.h"
Mike Fiore 1:f155d94d6f3a 10
Mike Fiore 1:f155d94d6f3a 11 namespace mts
Mike Fiore 1:f155d94d6f3a 12 {
Mike Fiore 1:f155d94d6f3a 13
Mike Fiore 1:f155d94d6f3a 14 /** This is a class for communicating with a Cellular radio device.
Mike Fiore 1:f155d94d6f3a 15 * This class supports three main types of cellular radio interactions including:
Mike Fiore 1:f155d94d6f3a 16 * configuration and status processing, SMS processing, and TCP/UDP Socket
Mike Fiore 1:f155d94d6f3a 17 * data connections. This class also inherits from IPStack providing a common set of commands
Mike Fiore 1:f155d94d6f3a 18 * for communication devices that support IP protocols. It is also integrated with the standard
Mike Fiore 1:f155d94d6f3a 19 * mbed Sockets package and can therefore be used seamlessly with clients and services built
Mike Fiore 1:f155d94d6f3a 20 * on top of this interface already within the mbed library.
Mike Fiore 1:f155d94d6f3a 21 *
Mike Fiore 1:f155d94d6f3a 22 * For all examples below please change Pin Names to match your hardware configuration.
Mike Fiore 1:f155d94d6f3a 23 * It also assumes the use of RTS/CTS hardware handshaking using GPIOs. To disable this
Mike Fiore 1:f155d94d6f3a 24 * you will need to change settings on the radio module and and use the MTSSerial class
Mike Fiore 1:f155d94d6f3a 25 * instead of MTSSerialFlowControl.
Mike Fiore 1:f155d94d6f3a 26 *
Mike Fiore 1:f155d94d6f3a 27 * The following set of example code demonstrates how to send and receive configuration and
Mike Fiore 1:f155d94d6f3a 28 * status AT commands with the radio, create a data connection and test it:
Mike Fiore 1:f155d94d6f3a 29 * @code
Mike Fiore 1:f155d94d6f3a 30 * #include "mbed.h"
Mike Fiore 1:f155d94d6f3a 31 * #include "mtech.h"
Mike Fiore 1:f155d94d6f3a 32 *
Mike Fiore 1:f155d94d6f3a 33 * using namespace mts;
Mike Fiore 1:f155d94d6f3a 34 *
Mike Fiore 1:f155d94d6f3a 35 * main() {
Mike Fiore 1:f155d94d6f3a 36 * //Setup serial interface to radio
Mike Fiore 1:f155d94d6f3a 37 * MTSSerialFlowControl* serial = new MTSSerialFlowControl(YOUR_TXD, YOUR_RXD, YOUR_RTS, YOUR_CTS);
Mike Fiore 1:f155d94d6f3a 38 * serial->baud(YOUR_BAUD);
Mike Fiore 1:f155d94d6f3a 39 *
Mike Fiore 1:f155d94d6f3a 40 * //Setup Cellular class - Select your radio type
Mike Fiore 1:f155d94d6f3a 41 * Cellular* cellular = new UniversalIP();
Mike Fiore 1:f155d94d6f3a 42 * //Cellular cellular = new TelitIP();
Mike Fiore 1:f155d94d6f3a 43 * cellular->init(serial);
Mike Fiore 1:f155d94d6f3a 44 *
Mike Fiore 1:f155d94d6f3a 45 * //Run status and configuration commands
Mike Fiore 1:f155d94d6f3a 46 * printf("\n\r////Start Status and Configuration Commands////\n\r");
Mike Fiore 1:f155d94d6f3a 47 * printf("Command Test: %s\n\r", getCodeNames(cellular->test()).c_str());
Mike Fiore 1:f155d94d6f3a 48 * wait(1);
Mike Fiore 1:f155d94d6f3a 49 * printf("Signal Strength: %d\n\r", cellular->getSignalStrength());
Mike Fiore 1:f155d94d6f3a 50 * wait(1);
Mike Fiore 1:f155d94d6f3a 51 * printf("Registration State: %s\n\r", Cellular::getRegistrationNames(cellular->getRegistration()).c_str());
Mike Fiore 1:f155d94d6f3a 52 * wait(1);
Mike Fiore 1:f155d94d6f3a 53 * printf("Send Basic Command (AT): %s\n\r", getCodeNames(cellular->sendBasicCommand("AT", 1000)).c_str());
Mike Fiore 1:f155d94d6f3a 54 * wait(1);
Mike Fiore 1:f155d94d6f3a 55 * printf("Send Command (AT+CSQ): %s\n\r", cellular->sendCommand("AT+CSQ", 1000).c_str());
Mike Fiore 1:f155d94d6f3a 56 * wait(1);
Mike Fiore 1:f155d94d6f3a 57 *
Mike Fiore 1:f155d94d6f3a 58 * //Start Test
Mike Fiore 1:f155d94d6f3a 59 * printf("\n\r////Start Network Connectivity Test////\n\r");
Mike Fiore 1:f155d94d6f3a 60 * printf("Set APN: %s\n\r", getCodeNames(cellular->setApn("wap.cingular")).c_str()); //Use APN from service provider!!!
Mike Fiore 1:f155d94d6f3a 61 *
Mike Fiore 1:f155d94d6f3a 62 * //Setup a data connection
Mike Fiore 1:f155d94d6f3a 63 * printf("Attempting to Connect, this may take some time...\n\r");
Mike Fiore 1:f155d94d6f3a 64 * while (!cellular->connect()) {
Mike Fiore 1:f155d94d6f3a 65 * printf("Failed to connect... Trying again.\n\r");
Mike Fiore 1:f155d94d6f3a 66 * wait(1);
Mike Fiore 1:f155d94d6f3a 67 * }
Mike Fiore 1:f155d94d6f3a 68 * printf("Connected to the Network!\n\r");
Mike Fiore 1:f155d94d6f3a 69 *
Mike Fiore 1:f155d94d6f3a 70 * //Try pinging default server "8.8.8.8"
Mike Fiore 1:f155d94d6f3a 71 * printf("Ping Valid: %s\n\r", cellular->ping() ? "true" : "false");
Mike Fiore 1:f155d94d6f3a 72 *
Mike Fiore 1:f155d94d6f3a 73 * //Perform HTTP transfer over TCP socket connection
Mike Fiore 1:f155d94d6f3a 74 * printf("Open Connection: %s\n\r", cellular->open("echo.200please.com", 80, IPStack::TCP) ? "Success" : "Failure");
Mike Fiore 1:f155d94d6f3a 75 * printf("Performing HTTP GET on echo.200please.com\n\r");
Mike Fiore 1:f155d94d6f3a 76 * string httpGET = "GET / HTTP/1.1\r\nHost: echo.200please.com\r\nConnection: keep-alive\r\n\r\n";
Mike Fiore 1:f155d94d6f3a 77 * printf("Wrote %d of %d bytes\n\r", cellular->write(httpGET.data(), httpGET.size(), 2000), httpGET.size());
Mike Fiore 1:f155d94d6f3a 78 * char buffer[256];
Mike Fiore 1:f155d94d6f3a 79 * buffer[255] = '\0';
Mike Fiore 1:f155d94d6f3a 80 * printf("Read %d bytes\n\r", cellular->read(buffer, 255, 2000));
Mike Fiore 1:f155d94d6f3a 81 * printf("HTTP Response:\n\r %s", buffer);
Mike Fiore 1:f155d94d6f3a 82 * wait(1);
Mike Fiore 1:f155d94d6f3a 83 * printf("Close Connection: %s\n\r", cellular->close() ? "Success" : "Failure");
Mike Fiore 1:f155d94d6f3a 84 *
Mike Fiore 1:f155d94d6f3a 85 * //Disconnect from network
Mike Fiore 1:f155d94d6f3a 86 * printf("Disconnecting...\n\r");
Mike Fiore 1:f155d94d6f3a 87 * cellular->disconnect();
Mike Fiore 1:f155d94d6f3a 88 * printf("Is Connected: %s\n\r", cellular->isConnected() ? "True" : "False");
Mike Fiore 1:f155d94d6f3a 89 *
Mike Fiore 1:f155d94d6f3a 90 * printf("End Program\n\r");
Mike Fiore 1:f155d94d6f3a 91 * }
Mike Fiore 1:f155d94d6f3a 92 * @endcode
Mike Fiore 1:f155d94d6f3a 93 *
Mike Fiore 1:f155d94d6f3a 94 * The following set of example code demonstrates how process SMS messages:
Mike Fiore 1:f155d94d6f3a 95 * @code
Mike Fiore 1:f155d94d6f3a 96 * #include "mbed.h"
Mike Fiore 1:f155d94d6f3a 97 * #include "mtech.h"
Mike Fiore 1:f155d94d6f3a 98 *
Mike Fiore 1:f155d94d6f3a 99 * using namespace mts;
Mike Fiore 1:f155d94d6f3a 100 *
Mike Fiore 1:f155d94d6f3a 101 * main() {
Mike Fiore 1:f155d94d6f3a 102 * //Setup serial interface to radio
Mike Fiore 1:f155d94d6f3a 103 * MTSSerialFlowControl* serial = new MTSSerialFlowControl(YOUR_TXD, YOUR_RXD, YOUR_RTS, YOUR_CTS);
Mike Fiore 1:f155d94d6f3a 104 * serial->baud(YOUR_BAUD);
Mike Fiore 1:f155d94d6f3a 105 *
Mike Fiore 1:f155d94d6f3a 106 * //Setup Cellular class
Mike Fiore 1:f155d94d6f3a 107 * //Setup Cellular class - Select your radio type
Mike Fiore 1:f155d94d6f3a 108 * Cellular* cellular = new UniversalIP();
Mike Fiore 1:f155d94d6f3a 109 * //Cellular cellular = new TelitIP();
Mike Fiore 1:f155d94d6f3a 110 * cellular->init(serial);
Mike Fiore 1:f155d94d6f3a 111 *
Mike Fiore 1:f155d94d6f3a 112 * //Start test
Mike Fiore 1:f155d94d6f3a 113 * printf("AT Test: %s\n\r", getCodeNames(cellular->test()).c_str());
Mike Fiore 1:f155d94d6f3a 114 *
Mike Fiore 1:f155d94d6f3a 115 * //Waiting for network registration
Mike Fiore 1:f155d94d6f3a 116 * printf("Checking Network Registration, this may take some time...\n\r");
Mike Fiore 1:f155d94d6f3a 117 * while (cellular->getRegistration() != Cellular::REGISTERED) {
Mike Fiore 1:f155d94d6f3a 118 * printf("Still waiting... Checking again.\n\r");
Mike Fiore 1:f155d94d6f3a 119 * wait(1);
Mike Fiore 1:f155d94d6f3a 120 * }
Mike Fiore 1:f155d94d6f3a 121 * printf("Connected to the Network!\n\r");
Mike Fiore 1:f155d94d6f3a 122 *
Mike Fiore 1:f155d94d6f3a 123 * //Send SMS Message
Mike Fiore 1:f155d94d6f3a 124 * Code code;
Mike Fiore 1:f155d94d6f3a 125 * std::string sMsg("Hello from Multi-Tech MBED!");
Mike Fiore 1:f155d94d6f3a 126 * std::string sPhoneNum("16128675309"); //Put your phone number here or leave Jenny's...
Mike Fiore 1:f155d94d6f3a 127 *
Mike Fiore 1:f155d94d6f3a 128 * printf("Sending message [%s] to [%s]\r\n", sMsg.c_str(), sPhoneNum.c_str());
Mike Fiore 1:f155d94d6f3a 129 * code = cellular->sendSMS(sPhoneNum, sMsg);
Mike Fiore 1:f155d94d6f3a 130 *
Mike Fiore 1:f155d94d6f3a 131 * if(code != SUCCESS) {
Mike Fiore 1:f155d94d6f3a 132 * printf("Error during SMS send [%s]\r\n", getCodeNames(code).c_str());
Mike Fiore 1:f155d94d6f3a 133 * } else {
Mike Fiore 1:f155d94d6f3a 134 * printf("Success!\r\n");
Mike Fiore 1:f155d94d6f3a 135 * }
Mike Fiore 1:f155d94d6f3a 136 *
Mike Fiore 1:f155d94d6f3a 137 * //Try and receive SMS messages
Mike Fiore 1:f155d94d6f3a 138 * //To determine your radio's phone number send yourself an SMS and check the received #
Mike Fiore 1:f155d94d6f3a 139 * printf("Checking Received Messages\r\n");
Mike Fiore 1:f155d94d6f3a 140 * while (true) {
Mike Fiore 1:f155d94d6f3a 141 * std::vector<Cellular::Sms> vSms = cellular->getReceivedSms();
Mike Fiore 1:f155d94d6f3a 142 * printf("\r\n");
Mike Fiore 1:f155d94d6f3a 143 * for(unsigned int i = 0; i < vSms.size(); i++) {
Mike Fiore 1:f155d94d6f3a 144 * printf("[%d][%s][%s][%s]\r\n", i, vSms[i].timestamp.c_str(),
Mike Fiore 1:f155d94d6f3a 145 * vSms[i].phoneNumber.c_str(), vSms[i].message.c_str());
Mike Fiore 1:f155d94d6f3a 146 * }
Mike Fiore 1:f155d94d6f3a 147 * wait(10);
Mike Fiore 1:f155d94d6f3a 148 * }
Mike Fiore 1:f155d94d6f3a 149 * }
Mike Fiore 1:f155d94d6f3a 150 * @endcode
Mike Fiore 1:f155d94d6f3a 151 */
Mike Fiore 1:f155d94d6f3a 152
Mike Fiore 1:f155d94d6f3a 153 class Cellular : public IPStack
Mike Fiore 1:f155d94d6f3a 154 {
Mike Fiore 1:f155d94d6f3a 155 public:
Mike Fiore 1:f155d94d6f3a 156 // Class ping paramter constants
Mike Fiore 1:f155d94d6f3a 157 static const unsigned int PINGDELAY = 3; //Time to wait on each ping for a response before timimg out (seconds)
Mike Fiore 1:f155d94d6f3a 158 static const unsigned int PINGNUM = 4; //Number of pings to try on ping command
Mike Fiore 1:f155d94d6f3a 159
Mike Fiore 1:f155d94d6f3a 160 /// Enumeration for different cellular radio types.
Mike Fiore 1:f155d94d6f3a 161 enum Radio {
Mike Fiore 7:0ee8e69a3e9c 162 NA, MTSMC_H5, MTSMC_EV3, MTSMC_G3, MTSMC_C2, MTSMC_H5_IP, MTSMC_EV3_IP, MTSMC_C2_IP
Mike Fiore 1:f155d94d6f3a 163 };
Mike Fiore 1:f155d94d6f3a 164
Mike Fiore 1:f155d94d6f3a 165 /// An enumeration of radio registration states with a cell tower.
Mike Fiore 1:f155d94d6f3a 166 enum Registration {
Mike Fiore 1:f155d94d6f3a 167 NOT_REGISTERED, REGISTERED, SEARCHING, DENIED, UNKNOWN, ROAMING
Mike Fiore 1:f155d94d6f3a 168 };
Mike Fiore 1:f155d94d6f3a 169
Mike Fiore 1:f155d94d6f3a 170 /** This structure contains the data for an SMS message.
Mike Fiore 1:f155d94d6f3a 171 */
Mike Fiore 1:f155d94d6f3a 172 struct Sms {
Mike Fiore 1:f155d94d6f3a 173 /// Message Phone Number
Mike Fiore 1:f155d94d6f3a 174 std::string phoneNumber;
Mike Fiore 1:f155d94d6f3a 175 /// Message Body
Mike Fiore 1:f155d94d6f3a 176 std::string message;
Mike Fiore 1:f155d94d6f3a 177 /// Message Timestamp
Mike Fiore 1:f155d94d6f3a 178 std::string timestamp;
Mike Fiore 1:f155d94d6f3a 179 };
Mike Fiore 1:f155d94d6f3a 180
Mike Fiore 1:f155d94d6f3a 181 /** This method initializes the object with the underlying radio
Mike Fiore 1:f155d94d6f3a 182 * interface to use. Note that this function MUST be called before
Mike Fiore 1:f155d94d6f3a 183 * any other calls will function correctly on a Cellular object. Also
Mike Fiore 1:f155d94d6f3a 184 * note that MTSBufferedIO is abstract, so you must use one of
Mike Fiore 3:04046eebaef5 185 * its inherited classes like MTSSerial, MTSSerialFlowControl or write a class
Mike Fiore 3:04046eebaef5 186 * similar to MTSSerialFlowControl which maps the MTSBufferedIO API
Mike Fiore 3:04046eebaef5 187 * to your favorite serial library.
Mike Fiore 1:f155d94d6f3a 188 *
Mike Fiore 3:04046eebaef5 189 * @param io the io interface that is attached to the cellular radio.
Mike Fiore 1:f155d94d6f3a 190 * The default is not connected.
Mike Fiore 1:f155d94d6f3a 191 * @returns true if the init was successful, otherwise false.
Mike Fiore 1:f155d94d6f3a 192 */
Mike Fiore 8:2d7259d244d1 193 virtual bool init(MTSBufferedIO* io);
Mike Fiore 9:1a03e3f3e7fe 194
Vanger 26:2b769ed8de4f 195 /** Sets up the physical connection pins
Vanger 52:2cb58398a4f9 196 * (DTR,DCD, and RESET)
Mike Fiore 9:1a03e3f3e7fe 197 */
Mike Fiore 9:1a03e3f3e7fe 198 bool configureSignals(unsigned int DCD = NC, unsigned int DTR = NC, unsigned int RESET = NC);
Mike Fiore 1:f155d94d6f3a 199
Mike Fiore 1:f155d94d6f3a 200 /** A method for testing command access to the radio. This method sends the
Mike Fiore 1:f155d94d6f3a 201 * command "AT" to the radio, which is a standard radio test to see if you
Mike Fiore 1:f155d94d6f3a 202 * have command access to the radio. The function returns when it receives
Mike Fiore 1:f155d94d6f3a 203 * the expected response from the radio.
Mike Fiore 1:f155d94d6f3a 204 *
Mike Fiore 1:f155d94d6f3a 205 * @returns the standard AT Code enumeration.
Mike Fiore 1:f155d94d6f3a 206 */
Mike Fiore 1:f155d94d6f3a 207 virtual Code test();
Mike Fiore 1:f155d94d6f3a 208
Mike Fiore 1:f155d94d6f3a 209 /** A method for getting the signal strength of the radio. This method allows you to
Mike Fiore 1:f155d94d6f3a 210 * get a value that maps to signal strength in dBm. Here 0-1 is Poor, 2-9 is Marginal,
Mike Fiore 1:f155d94d6f3a 211 * 10-14 is Ok, 15-19 is Good, and 20+ is Excellent. If you get a result of 99 the
Mike Fiore 1:f155d94d6f3a 212 * signal strength is not known or not detectable.
Mike Fiore 1:f155d94d6f3a 213 *
Mike Fiore 1:f155d94d6f3a 214 * @returns an integer representing the signal strength.
Mike Fiore 1:f155d94d6f3a 215 */
Mike Fiore 1:f155d94d6f3a 216 virtual int getSignalStrength();
Mike Fiore 1:f155d94d6f3a 217
Mike Fiore 1:f155d94d6f3a 218 /** This method is used to check the registration state of the radio with the cell tower.
Mike Fiore 1:f155d94d6f3a 219 * If not appropriatley registered with the tower you cannot make a cellular connection.
Mike Fiore 1:f155d94d6f3a 220 *
Mike Fiore 1:f155d94d6f3a 221 * @returns the registration state as an enumeration type.
Mike Fiore 1:f155d94d6f3a 222 */
Mike Fiore 1:f155d94d6f3a 223 virtual Registration getRegistration();
Mike Fiore 1:f155d94d6f3a 224
Mike Fiore 1:f155d94d6f3a 225 /** This method is used to set the radios APN if using a SIM card. Note that the APN
Mike Fiore 1:f155d94d6f3a 226 * must be set correctly before you can make a data connection. The APN for your SIM
Mike Fiore 1:f155d94d6f3a 227 * can be obtained by contacting your cellular service provider.
Mike Fiore 1:f155d94d6f3a 228 *
Mike Fiore 1:f155d94d6f3a 229 * @param the APN as a string.
Mike Fiore 1:f155d94d6f3a 230 * @returns the standard AT Code enumeration.
Mike Fiore 1:f155d94d6f3a 231 */
Vanger 52:2cb58398a4f9 232 virtual Code setApn(const std::string& apn) = 0;
Mike Fiore 1:f155d94d6f3a 233
Mike Fiore 1:f155d94d6f3a 234 /** This method is used to set the DNS which enables the use of URLs instead
Mike Fiore 1:f155d94d6f3a 235 * of IP addresses when making a socket connection.
Mike Fiore 1:f155d94d6f3a 236 *
Mike Fiore 1:f155d94d6f3a 237 * @param the DNS server address as a string in form xxx.xxx.xxx.xxx.
Mike Fiore 1:f155d94d6f3a 238 * @returns the standard AT Code enumeration.
Mike Fiore 1:f155d94d6f3a 239 */
Mike Fiore 8:2d7259d244d1 240 virtual Code setDns(const std::string& primary, const std::string& secondary = "0.0.0.0");
Mike Fiore 1:f155d94d6f3a 241
Mike Fiore 1:f155d94d6f3a 242 /** This method is used to send an SMS message. Note that you cannot send an
Mike Fiore 1:f155d94d6f3a 243 * SMS message and have a data connection open at the same time.
Mike Fiore 1:f155d94d6f3a 244 *
Mike Fiore 1:f155d94d6f3a 245 * @param phoneNumber the phone number to send the message to as a string.
Mike Fiore 1:f155d94d6f3a 246 * @param message the text message to be sent.
Mike Fiore 1:f155d94d6f3a 247 * @returns the standard AT Code enumeration.
Mike Fiore 1:f155d94d6f3a 248 */
Mike Fiore 7:0ee8e69a3e9c 249 virtual Code sendSMS(const std::string& phoneNumber, const std::string& message);
Mike Fiore 1:f155d94d6f3a 250
Mike Fiore 1:f155d94d6f3a 251 /** This method is used to send an SMS message. Note that you cannot send an
Mike Fiore 1:f155d94d6f3a 252 * SMS message and have a data connection open at the same time.
Mike Fiore 1:f155d94d6f3a 253 *
Mike Fiore 1:f155d94d6f3a 254 * @param sms an Sms struct that contains all SMS transaction information.
Mike Fiore 1:f155d94d6f3a 255 * @returns the standard AT Code enumeration.
Mike Fiore 1:f155d94d6f3a 256 */
Mike Fiore 7:0ee8e69a3e9c 257 virtual Code sendSMS(const Sms& sms);
Mike Fiore 1:f155d94d6f3a 258
Mike Fiore 1:f155d94d6f3a 259 /** This method retrieves all of the SMS messages currently available for
Mike Fiore 1:f155d94d6f3a 260 * this phone number.
Mike Fiore 1:f155d94d6f3a 261 *
Mike Fiore 1:f155d94d6f3a 262 * @returns a vector of existing SMS messages each as an Sms struct.
Mike Fiore 1:f155d94d6f3a 263 */
Mike Fiore 7:0ee8e69a3e9c 264 virtual std::vector<Cellular::Sms> getReceivedSms();
Mike Fiore 1:f155d94d6f3a 265
Mike Fiore 1:f155d94d6f3a 266 /** This method can be used to remove/delete all received SMS messages
Mike Fiore 1:f155d94d6f3a 267 * even if they have never been retrieved or read.
Mike Fiore 1:f155d94d6f3a 268 *
Mike Fiore 1:f155d94d6f3a 269 * @returns the standard AT Code enumeration.
Mike Fiore 1:f155d94d6f3a 270 */
Mike Fiore 7:0ee8e69a3e9c 271 virtual Code deleteAllReceivedSms();
Mike Fiore 1:f155d94d6f3a 272
Mike Fiore 1:f155d94d6f3a 273 /** This method can be used to remove/delete all received SMS messages
Mike Fiore 1:f155d94d6f3a 274 * that have been retrieved by the user through the getReceivedSms method.
Mike Fiore 1:f155d94d6f3a 275 * Messages that have not been retrieved yet will be unaffected.
Mike Fiore 1:f155d94d6f3a 276 *
Mike Fiore 1:f155d94d6f3a 277 * @returns the standard AT Code enumeration.
Mike Fiore 1:f155d94d6f3a 278 */
Mike Fiore 7:0ee8e69a3e9c 279 virtual Code deleteOnlyReceivedReadSms();
Mike Fiore 1:f155d94d6f3a 280
Mike Fiore 1:f155d94d6f3a 281 //Cellular Radio Specific
Mike Fiore 1:f155d94d6f3a 282 /** A method for sending a generic AT command to the radio. Note that you cannot
Mike Fiore 1:f155d94d6f3a 283 * send commands and have a data connection at the same time.
Mike Fiore 1:f155d94d6f3a 284 *
Mike Fiore 1:f155d94d6f3a 285 * @param command the command to send to the radio without the escape character.
Mike Fiore 1:f155d94d6f3a 286 * @param timeoutMillis the time in millis to wait for a response before returning.
Mike Fiore 1:f155d94d6f3a 287 * @param esc escape character to add at the end of the command, defaults to
Mike Fiore 1:f155d94d6f3a 288 * carriage return (CR). Does not append any character if esc == 0.
Mike Fiore 1:f155d94d6f3a 289 * @returns all data received from the radio after the command as a string.
Mike Fiore 1:f155d94d6f3a 290 */
Mike Fiore 10:c188cc05aed5 291 virtual std::string sendCommand(const std::string& command, unsigned int timeoutMillis, char esc = CR);
Mike Fiore 1:f155d94d6f3a 292
Mike Fiore 1:f155d94d6f3a 293 /** A method for sending a basic AT command to the radio. A basic AT command is
Mike Fiore 1:f155d94d6f3a 294 * one that simply has a response of either OK or ERROR without any other information.
Mike Fiore 1:f155d94d6f3a 295 * Note that you cannot send commands and have a data connection at the same time.
Mike Fiore 1:f155d94d6f3a 296 *
Mike Fiore 1:f155d94d6f3a 297 * @param command the command to send to the radio without the escape character.
Mike Fiore 1:f155d94d6f3a 298 * @param timeoutMillis the time in millis to wait for a response before returning.
Mike Fiore 1:f155d94d6f3a 299 * @param esc escape character to add at the end of the command, defaults to
Mike Fiore 1:f155d94d6f3a 300 * carriage return (CR).
Mike Fiore 1:f155d94d6f3a 301 * @returns the standard Code enumeration.
Mike Fiore 1:f155d94d6f3a 302 */
Mike Fiore 10:c188cc05aed5 303 virtual Code sendBasicCommand(const std::string& command, unsigned int timeoutMillis, char esc = CR);
Mike Fiore 1:f155d94d6f3a 304
Mike Fiore 1:f155d94d6f3a 305 /** A static method for getting a string representation for the Registration
Mike Fiore 1:f155d94d6f3a 306 * enumeration.
Mike Fiore 1:f155d94d6f3a 307 *
Mike Fiore 1:f155d94d6f3a 308 * @param code a Registration enumeration.
Mike Fiore 1:f155d94d6f3a 309 * @returns the enumeration name as a string.
Mike Fiore 1:f155d94d6f3a 310 */
Mike Fiore 1:f155d94d6f3a 311 static std::string getRegistrationNames(Registration registration);
Mike Fiore 3:04046eebaef5 312
Mike Fiore 11:4e428f689069 313 /** A static method for getting a string representation for the Radio
Mike Fiore 11:4e428f689069 314 * enumeration.
Mike Fiore 11:4e428f689069 315 *
Mike Fiore 11:4e428f689069 316 * @param type a Radio enumeration.
Mike Fiore 11:4e428f689069 317 * @returns the enumeration name as a string.
Mike Fiore 11:4e428f689069 318 */
Mike Fiore 11:4e428f689069 319 static std::string getRadioNames(Radio radio);
Vanger 27:ec44d5a9544f 320 /** A method for changing the echo commands from radio.
Vanger 27:ec44d5a9544f 321 * @param state Echo mode is off (an argument of 1 turns echos off, anything else turns echo on)
Vanger 27:ec44d5a9544f 322 * @returns standard Code enumeration
Vanger 27:ec44d5a9544f 323 */
Vanger 27:ec44d5a9544f 324 virtual Code echo(bool state)=0; //Implemented the same way in both UIP and EasyIP,
Vanger 27:ec44d5a9544f 325 //and thus could be moved to cellular class
Vanger 31:529db15abda7 326 virtual Code setSocketCloseable(bool enabled)=0;
Mike Fiore 11:4e428f689069 327
Mike Fiore 3:04046eebaef5 328 protected:
Mike Fiore 3:04046eebaef5 329 MTSBufferedIO* io; //IO interface obect that the radio is accessed through.
Mike Fiore 3:04046eebaef5 330 bool echoMode; //Specifies if the echo mode is currently enabled.
Mike Fiore 3:04046eebaef5 331
Mike Fiore 3:04046eebaef5 332 bool pppConnected; //Specifies if a PPP session is currently connected.
Mike Fiore 3:04046eebaef5 333 std::string apn; //A string that holds the APN for the radio.
Mike Fiore 3:04046eebaef5 334
Mike Fiore 9:1a03e3f3e7fe 335 Radio type; //The type of radio being used
Mike Fiore 9:1a03e3f3e7fe 336
mfiore 19:f6261f1c3dd4 337 Mode socketMode; //The current socket Mode.
Mike Fiore 3:04046eebaef5 338 bool socketOpened; //Specifies if a Socket is presently opened.
Mike Fiore 3:04046eebaef5 339 bool socketCloseable; //Specifies is a Socket can be closed.
Mike Fiore 3:04046eebaef5 340 unsigned int local_port; //Holds the local port for socket connections.
Mike Fiore 3:04046eebaef5 341 std::string local_address; //Holds the local address for socket connections.
Mike Fiore 3:04046eebaef5 342 unsigned int host_port; //Holds the remote port for socket connections.
Mike Fiore 3:04046eebaef5 343 std::string host_address; //Holds the remote address for socket connections.
Mike Fiore 9:1a03e3f3e7fe 344
Mike Fiore 9:1a03e3f3e7fe 345 DigitalIn* dcd; //Maps to the radio's dcd signal
Mike Fiore 9:1a03e3f3e7fe 346 DigitalOut* dtr; //Maps to the radio's dtr signal
Mike Fiore 9:1a03e3f3e7fe 347 DigitalOut* resetLine; //Maps to the radio's reset signal
Mike Fiore 1:f155d94d6f3a 348 };
Mike Fiore 1:f155d94d6f3a 349
Mike Fiore 1:f155d94d6f3a 350 }
Mike Fiore 1:f155d94d6f3a 351
Mike Fiore 2:10e72dce251d 352 #endif /* CELLULAR_H */