Update to work with latest mBed

Dependencies:   mbed-dev

Fork of FONA_CellPhone by Dream Team

Committer:
gtzintzarov3
Date:
Tue Mar 15 02:35:55 2016 +0000
Revision:
10:9dd3e49dec97
Parent:
9:06eca688f2a3
Child:
15:19a02a88836a
GT: adding more documentatiom

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gtzintzarov3 0:851248a56628 1 /***************************************************
gtzintzarov3 0:851248a56628 2 This is a library for our Adafruit FONA Cellular Module
gtzintzarov3 0:851248a56628 3
gtzintzarov3 0:851248a56628 4 Designed specifically to work with the Adafruit FONA
gtzintzarov3 0:851248a56628 5 ----> http://www.adafruit.com/products/1946
gtzintzarov3 0:851248a56628 6 ----> http://www.adafruit.com/products/1963
gtzintzarov3 0:851248a56628 7
gtzintzarov3 0:851248a56628 8 These displays use TTL Serial to communicate, 2 pins are required to
gtzintzarov3 0:851248a56628 9 interface
gtzintzarov3 0:851248a56628 10 Adafruit invests time and resources providing this open source code,
gtzintzarov3 0:851248a56628 11 please support Adafruit and open-source hardware by purchasing
gtzintzarov3 0:851248a56628 12 products from Adafruit!
gtzintzarov3 0:851248a56628 13
gtzintzarov3 0:851248a56628 14 Written by Limor Fried/Ladyada for Adafruit Industries.
gtzintzarov3 0:851248a56628 15 BSD license, all text above must be included in any redistribution
gtzintzarov3 0:851248a56628 16 ****************************************************/
gtzintzarov3 0:851248a56628 17
gtzintzarov3 0:851248a56628 18 /*
gtzintzarov3 9:06eca688f2a3 19 * Modified by George Tzintzarov & Jesse Baker 03/14/2016 for use in mbed LPC1768
gtzintzarov3 0:851248a56628 20 */
gtzintzarov3 0:851248a56628 21
gtzintzarov3 0:851248a56628 22 #ifndef ADAFRUIT_FONA_H
gtzintzarov3 0:851248a56628 23 #define ADAFRUIT_FONA_H
gtzintzarov3 0:851248a56628 24
gtzintzarov3 0:851248a56628 25 #include "mbed.h"
gtzintzarov3 0:851248a56628 26
gtzintzarov3 0:851248a56628 27 //#define ADAFRUIT_FONA_DEBUG
gtzintzarov3 0:851248a56628 28
gtzintzarov3 0:851248a56628 29 #define FONA_HEADSETAUDIO 0
gtzintzarov3 0:851248a56628 30 #define FONA_EXTAUDIO 1
gtzintzarov3 0:851248a56628 31
gtzintzarov3 0:851248a56628 32 #define FONA_STTONE_DIALTONE 1
gtzintzarov3 0:851248a56628 33 #define FONA_STTONE_BUSY 2
gtzintzarov3 0:851248a56628 34 #define FONA_STTONE_CONGESTION 3
gtzintzarov3 0:851248a56628 35 #define FONA_STTONE_PATHACK 4
gtzintzarov3 0:851248a56628 36 #define FONA_STTONE_DROPPED 5
gtzintzarov3 0:851248a56628 37 #define FONA_STTONE_ERROR 6
gtzintzarov3 0:851248a56628 38 #define FONA_STTONE_CALLWAIT 7
gtzintzarov3 0:851248a56628 39 #define FONA_STTONE_RINGING 8
gtzintzarov3 0:851248a56628 40 #define FONA_STTONE_BEEP 16
gtzintzarov3 0:851248a56628 41 #define FONA_STTONE_POSTONE 17
gtzintzarov3 0:851248a56628 42 #define FONA_STTONE_ERRTONE 18
gtzintzarov3 0:851248a56628 43 #define FONA_STTONE_INDIANDIALTONE 19
gtzintzarov3 0:851248a56628 44 #define FONA_STTONE_USADIALTONE 20
gtzintzarov3 0:851248a56628 45
George windoge T 2:aaef20ac9044 46 #define FONA_DEFAULT_TIMEOUT_MS 500 //timeout between send AT and reply from FONA
gtzintzarov3 0:851248a56628 47
gtzintzarov3 0:851248a56628 48 #define FONA_HTTP_GET 0
gtzintzarov3 0:851248a56628 49 #define FONA_HTTP_POST 1
gtzintzarov3 0:851248a56628 50 #define FONA_HTTP_HEAD 2
gtzintzarov3 0:851248a56628 51
gtzintzarov3 0:851248a56628 52 #define RX_BUFFER_SIZE 255
gtzintzarov3 0:851248a56628 53
gtzintzarov3 9:06eca688f2a3 54 /** Adafruit FONA 800H Class
gtzintzarov3 9:06eca688f2a3 55 * Modified by George Tzintzarov & Jesse Baker 03/14/2016 for use in mbed LPC1768
gtzintzarov3 9:06eca688f2a3 56 */
gtzintzarov3 9:06eca688f2a3 57
gtzintzarov3 0:851248a56628 58 class Adafruit_FONA : public Stream {
gtzintzarov3 0:851248a56628 59 public:
gtzintzarov3 9:06eca688f2a3 60 /**
gtzintzarov3 9:06eca688f2a3 61 Listener for FONA events. Inherit this class to customize.
gtzintzarov3 9:06eca688f2a3 62 @code
gtzintzarov3 9:06eca688f2a3 63 #define FONA_RST p12
gtzintzarov3 9:06eca688f2a3 64 #define FONA_TX p13
gtzintzarov3 9:06eca688f2a3 65 #define FONA_RX p14
gtzintzarov3 9:06eca688f2a3 66 #define FONA_RI p11
gtzintzarov3 9:06eca688f2a3 67
gtzintzarov3 9:06eca688f2a3 68 Adafruit_FONA my_fona(FONA_TX, FONA_RX, FONA_RST, FONA_RI);
gtzintzarov3 9:06eca688f2a3 69 DigitalOut led1(LED1);
gtzintzarov3 9:06eca688f2a3 70 class FonaEventListener : public Adafruit_FONA::EventListener {
gtzintzarov3 9:06eca688f2a3 71 virtual void onRing() {
gtzintzarov3 9:06eca688f2a3 72 led1 = 1;
gtzintzarov3 9:06eca688f2a3 73 }
gtzintzarov3 9:06eca688f2a3 74
gtzintzarov3 9:06eca688f2a3 75 virtual void onNoCarrier() {
gtzintzarov3 9:06eca688f2a3 76 led1 = 0;
gtzintzarov3 9:06eca688f2a3 77 }
gtzintzarov3 9:06eca688f2a3 78 };
gtzintzarov3 9:06eca688f2a3 79 FonaEventListener fonaEventListener;
gtzintzarov3 9:06eca688f2a3 80 my_fona.setEventListener(&fonaEventListener);
gtzintzarov3 9:06eca688f2a3 81 @endcode
gtzintzarov3 9:06eca688f2a3 82 */
gtzintzarov3 9:06eca688f2a3 83
gtzintzarov3 0:851248a56628 84 class EventListener {
gtzintzarov3 0:851248a56628 85 public:
gtzintzarov3 0:851248a56628 86 /**
gtzintzarov3 0:851248a56628 87 * Method called when somebody call the FONA.
gtzintzarov3 0:851248a56628 88 */
gtzintzarov3 0:851248a56628 89 virtual void onRing() = 0;
gtzintzarov3 0:851248a56628 90
gtzintzarov3 0:851248a56628 91 /**
gtzintzarov3 0:851248a56628 92 * Method called when the calling person stop his call.
gtzintzarov3 0:851248a56628 93 */
gtzintzarov3 0:851248a56628 94 virtual void onNoCarrier() = 0;
gtzintzarov3 0:851248a56628 95 };
gtzintzarov3 0:851248a56628 96
gtzintzarov3 0:851248a56628 97 public:
gtzintzarov3 9:06eca688f2a3 98 /** Create instance of the Adafruit_FONA
gtzintzarov3 9:06eca688f2a3 99 @param tx Set mbed TX
gtzintzarov3 9:06eca688f2a3 100 @param rx Set mbed RX
gtzintzarov3 9:06eca688f2a3 101 @param rst Set reset pin
gtzintzarov3 9:06eca688f2a3 102 @param ringIndicator Set ring indicator pin. This is to let mbed know if there is an incoming call
gtzintzarov3 9:06eca688f2a3 103 */
gtzintzarov3 9:06eca688f2a3 104
gtzintzarov3 0:851248a56628 105 Adafruit_FONA(PinName tx, PinName rx, PinName rst, PinName ringIndicator) :
gtzintzarov3 0:851248a56628 106 _rstpin(rst, false), _ringIndicatorInterruptIn(ringIndicator),
gtzintzarov3 0:851248a56628 107 apn("FONAnet"), apnusername(NULL), apnpassword(NULL), httpsredirect(false), useragent("FONA"),
gtzintzarov3 0:851248a56628 108 _incomingCall(false), eventListener(NULL), mySerial(tx, rx), rxBufferInIndex(0), rxBufferOutIndex(0),
gtzintzarov3 0:851248a56628 109 currentReceivedLineSize(0) {}
gtzintzarov3 9:06eca688f2a3 110
gtzintzarov3 9:06eca688f2a3 111 /** Built-in Test to see if FONA is connected
gtzintzarov3 9:06eca688f2a3 112 @param baudrate test and set at baudrate
gtzintzarov3 9:06eca688f2a3 113 @return true upon success
gtzintzarov3 9:06eca688f2a3 114 @return false upon failure. Most likely something is not hooked up.
gtzintzarov3 9:06eca688f2a3 115
gtzintzarov3 9:06eca688f2a3 116 EXAMPLE CODE:
gtzintzarov3 9:06eca688f2a3 117 @code
gtzintzarov3 9:06eca688f2a3 118 // See if the FONA is responding
gtzintzarov3 9:06eca688f2a3 119 // fona is an instance of Adafruit_FONA
gtzintzarov3 9:06eca688f2a3 120 if (! fona.begin(9600)) {
gtzintzarov3 9:06eca688f2a3 121 printf("Couldn't find FONA\r\n");
gtzintzarov3 9:06eca688f2a3 122 while (1);
gtzintzarov3 9:06eca688f2a3 123 }
gtzintzarov3 9:06eca688f2a3 124 @endcode
gtzintzarov3 9:06eca688f2a3 125 */
gtzintzarov3 0:851248a56628 126 bool begin(int baudrate);
gtzintzarov3 9:06eca688f2a3 127
gtzintzarov3 9:06eca688f2a3 128 /** Set the event listener for incoming calls
gtzintzarov3 9:06eca688f2a3 129 @param eventListener A pointer to the event listener
gtzintzarov3 9:06eca688f2a3 130 @see Adafruit_FONA::EventListener for specific example
gtzintzarov3 9:06eca688f2a3 131 */
gtzintzarov3 9:06eca688f2a3 132
gtzintzarov3 0:851248a56628 133 void setEventListener(EventListener *eventListener);
gtzintzarov3 0:851248a56628 134
gtzintzarov3 9:06eca688f2a3 135 // Stream----------------------------------------------------------------------
gtzintzarov3 0:851248a56628 136 virtual int _putc(int value);
gtzintzarov3 0:851248a56628 137 virtual int _getc();
gtzintzarov3 0:851248a56628 138
gtzintzarov3 9:06eca688f2a3 139 /** Check if FONA has anything in its output buffer
gtzintzarov3 9:06eca688f2a3 140 @return 0 if nothing
gtzintzarov3 9:06eca688f2a3 141 */
gtzintzarov3 9:06eca688f2a3 142 int readable(void);
gtzintzarov3 9:06eca688f2a3 143
gtzintzarov3 9:06eca688f2a3 144 // RTC----------------------------------------------------------------------
gtzintzarov3 0:851248a56628 145 bool enableRTC(uint8_t i); // i = 0 <=> disable, i = 1 <=> enable
gtzintzarov3 0:851248a56628 146
gtzintzarov3 9:06eca688f2a3 147 // Battery and ADC----------------------------------------------------------------------
gtzintzarov3 9:06eca688f2a3 148 /** Get ADC voltage from external pin
gtzintzarov3 9:06eca688f2a3 149 @param v uint16_t pointer to insert ADC voltage data
gtzintzarov3 9:06eca688f2a3 150 @return TRUE if successful
gtzintzarov3 9:06eca688f2a3 151
gtzintzarov3 9:06eca688f2a3 152 EXAMPLE CODE:
gtzintzarov3 9:06eca688f2a3 153 @code
gtzintzarov3 9:06eca688f2a3 154 // read the ADC
gtzintzarov3 9:06eca688f2a3 155 // fona is an instance of Adafruit_FONA
gtzintzarov3 9:06eca688f2a3 156 uint16_t adc;
gtzintzarov3 9:06eca688f2a3 157 if (! fona.getADCVoltage(&adc)) {
gtzintzarov3 9:06eca688f2a3 158 printf("Failed to read ADC\r\n");
gtzintzarov3 9:06eca688f2a3 159 }
gtzintzarov3 9:06eca688f2a3 160 else {
gtzintzarov3 9:06eca688f2a3 161 printf("ADC = %d mV\r\n", adc);
gtzintzarov3 9:06eca688f2a3 162 }
gtzintzarov3 9:06eca688f2a3 163 @endcode
gtzintzarov3 9:06eca688f2a3 164 */
gtzintzarov3 0:851248a56628 165 bool getADCVoltage(uint16_t *v);
gtzintzarov3 9:06eca688f2a3 166
gtzintzarov3 9:06eca688f2a3 167 /** Get battery percentage level
gtzintzarov3 9:06eca688f2a3 168 @param p uint16_t pointer to insert battery percent data
gtzintzarov3 9:06eca688f2a3 169 @return TRUE if successful
gtzintzarov3 9:06eca688f2a3 170
gtzintzarov3 9:06eca688f2a3 171 EXAMPLE CODE:
gtzintzarov3 9:06eca688f2a3 172 @code
gtzintzarov3 9:06eca688f2a3 173 // read the battery percent level
gtzintzarov3 9:06eca688f2a3 174 // fona is an instance of Adafruit_FONA
gtzintzarov3 9:06eca688f2a3 175 uint16_t vbatPer;
gtzintzarov3 9:06eca688f2a3 176 if (! fona.getBattPercent(&vbatPer)) {
gtzintzarov3 9:06eca688f2a3 177 printf("Failed to read Batt\r\n");
gtzintzarov3 9:06eca688f2a3 178 }
gtzintzarov3 9:06eca688f2a3 179 else {
gtzintzarov3 9:06eca688f2a3 180 printf("VPct = %d%%\r\n", vbatPer);
gtzintzarov3 9:06eca688f2a3 181 }
gtzintzarov3 9:06eca688f2a3 182 @endcode
gtzintzarov3 9:06eca688f2a3 183 */
gtzintzarov3 9:06eca688f2a3 184
gtzintzarov3 0:851248a56628 185 bool getBattPercent(uint16_t *p);
gtzintzarov3 9:06eca688f2a3 186
gtzintzarov3 9:06eca688f2a3 187 /** Get battery voltage level
gtzintzarov3 9:06eca688f2a3 188 @param v uint16_t pointer to insert battery voltage data
gtzintzarov3 9:06eca688f2a3 189 @return TRUE if successful
gtzintzarov3 9:06eca688f2a3 190
gtzintzarov3 9:06eca688f2a3 191 EXAMPLE CODE:
gtzintzarov3 9:06eca688f2a3 192 @code
gtzintzarov3 9:06eca688f2a3 193 // read the battery voltage
gtzintzarov3 9:06eca688f2a3 194 // fona is an instance of Adafruit_FONA
gtzintzarov3 9:06eca688f2a3 195 uint16_t vbat;
gtzintzarov3 9:06eca688f2a3 196 if (! fona.getBattPercent(&vbat)) {
gtzintzarov3 9:06eca688f2a3 197 printf("Failed to read Batt\r\n");
gtzintzarov3 9:06eca688f2a3 198 }
gtzintzarov3 9:06eca688f2a3 199 else {
gtzintzarov3 9:06eca688f2a3 200 printf("Vbat = %d%%\r\n", vbat);
gtzintzarov3 9:06eca688f2a3 201 }
gtzintzarov3 9:06eca688f2a3 202 @endcode
gtzintzarov3 9:06eca688f2a3 203 */
gtzintzarov3 0:851248a56628 204 bool getBattVoltage(uint16_t *v);
gtzintzarov3 0:851248a56628 205
gtzintzarov3 9:06eca688f2a3 206 // SIM query----------------------------------------------------------------------
gtzintzarov3 9:06eca688f2a3 207 /** Unlock SIM if needed
gtzintzarov3 9:06eca688f2a3 208 @param pin 4 digit char arrary
gtzintzarov3 9:06eca688f2a3 209 @return TRUE if successful
gtzintzarov3 9:06eca688f2a3 210 */
gtzintzarov3 0:851248a56628 211 bool unlockSIM(char *pin);
gtzintzarov3 9:06eca688f2a3 212 /** Get the SIM chip card interface device (CCID)
gtzintzarov3 9:06eca688f2a3 213 @param ccid make sure it is at least 21 bytes long
gtzintzarov3 9:06eca688f2a3 214 @return length of CCID
gtzintzarov3 9:06eca688f2a3 215 */
gtzintzarov3 10:9dd3e49dec97 216
gtzintzarov3 0:851248a56628 217 uint8_t getSIMCCID(char *ccid);
gtzintzarov3 9:06eca688f2a3 218 /** Get the Network Status of FONA
gtzintzarov3 9:06eca688f2a3 219 @return Code 0-5
gtzintzarov3 10:9dd3e49dec97 220 @see https://www.adafruit.com/datasheets/sim800_series_at_command_manual_v1.01.pdf page 80
gtzintzarov3 9:06eca688f2a3 221 */
gtzintzarov3 0:851248a56628 222 uint8_t getNetworkStatus(void);
gtzintzarov3 10:9dd3e49dec97 223
gtzintzarov3 10:9dd3e49dec97 224 /** Get the RSSI of the network signal
gtzintzarov3 10:9dd3e49dec97 225 @return RSSI value in dBm per below reference
gtzintzarov3 10:9dd3e49dec97 226
gtzintzarov3 10:9dd3e49dec97 227 EXAMPLE
gtzintzarov3 10:9dd3e49dec97 228 @code
gtzintzarov3 10:9dd3e49dec97 229 // read the RSSI
gtzintzarov3 10:9dd3e49dec97 230 uint8_t n = fona.getRSSI();
gtzintzarov3 10:9dd3e49dec97 231 int8_t r = 0;
gtzintzarov3 10:9dd3e49dec97 232
gtzintzarov3 10:9dd3e49dec97 233 pcSerial.printf("RSSI = %d: ", n);
gtzintzarov3 10:9dd3e49dec97 234 if (n == 0) r = -115;
gtzintzarov3 10:9dd3e49dec97 235 if (n == 1) r = -111;
gtzintzarov3 10:9dd3e49dec97 236 if (n == 31) r = -52;
gtzintzarov3 10:9dd3e49dec97 237 if ((n >= 2) && (n <= 30)) {
gtzintzarov3 10:9dd3e49dec97 238 r = map(n, 2, 30, -110, -54);
gtzintzarov3 10:9dd3e49dec97 239 }
gtzintzarov3 10:9dd3e49dec97 240 printf("%d dBm\r\n", r);
gtzintzarov3 10:9dd3e49dec97 241
gtzintzarov3 10:9dd3e49dec97 242 // helper function MAP to do calculations
gtzintzarov3 10:9dd3e49dec97 243 long MAP(long x, long in_min, long in_max, long out_min, long out_max)
gtzintzarov3 10:9dd3e49dec97 244 {
gtzintzarov3 10:9dd3e49dec97 245 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
gtzintzarov3 10:9dd3e49dec97 246 }
gtzintzarov3 10:9dd3e49dec97 247 @endcode
gtzintzarov3 10:9dd3e49dec97 248 @see https://www.adafruit.com/datasheets/sim800_series_at_command_manual_v1.01.pdf page 82
gtzintzarov3 10:9dd3e49dec97 249 */
gtzintzarov3 0:851248a56628 250 uint8_t getRSSI(void);
gtzintzarov3 0:851248a56628 251
gtzintzarov3 9:06eca688f2a3 252 // IMEI----------------------------------------------------------------------
gtzintzarov3 9:06eca688f2a3 253 /** Get the International Mobile Station Equipment Identity (IMEI)
gtzintzarov3 9:06eca688f2a3 254 @param imei A char array with minimum length 16
gtzintzarov3 9:06eca688f2a3 255 @return The IMEI of the device
gtzintzarov3 10:9dd3e49dec97 256
gtzintzarov3 9:06eca688f2a3 257 EXAMPLE CODE:
gtzintzarov3 9:06eca688f2a3 258 @code
gtzintzarov3 9:06eca688f2a3 259 // Print SIM card IMEI number.
gtzintzarov3 9:06eca688f2a3 260 char imei[15] = {0}; // MUST use a 16 character buffer for IMEI!
gtzintzarov3 9:06eca688f2a3 261 uint8_t imeiLen = fona.getIMEI(imei); //fona is an instance of Adafruit_FONA
gtzintzarov3 9:06eca688f2a3 262 if (imeiLen > 0) {
gtzintzarov3 9:06eca688f2a3 263 pcSerial.printf("SIM card IMEI: %s\r\n", imei);
gtzintzarov3 9:06eca688f2a3 264 }
gtzintzarov3 9:06eca688f2a3 265 @endcode
gtzintzarov3 9:06eca688f2a3 266 */
gtzintzarov3 0:851248a56628 267 uint8_t getIMEI(char *imei);
gtzintzarov3 0:851248a56628 268
gtzintzarov3 10:9dd3e49dec97 269 // set Audio output----------------------------------------------------------------------
gtzintzarov3 0:851248a56628 270 bool setAudio(uint8_t a);
gtzintzarov3 0:851248a56628 271 bool setVolume(uint8_t i);
gtzintzarov3 0:851248a56628 272 uint8_t getVolume(void);
gtzintzarov3 0:851248a56628 273 bool playToolkitTone(uint8_t t, uint16_t len);
gtzintzarov3 0:851248a56628 274 bool setMicVolume(uint8_t a, uint8_t level);
gtzintzarov3 0:851248a56628 275 bool playDTMF(char tone);
gtzintzarov3 0:851248a56628 276
gtzintzarov3 10:9dd3e49dec97 277 // FM radio functions----------------------------------------------------------------------
gtzintzarov3 0:851248a56628 278 bool tuneFMradio(uint16_t station);
gtzintzarov3 0:851248a56628 279 bool FMradio(bool onoff, uint8_t a = FONA_HEADSETAUDIO);
gtzintzarov3 0:851248a56628 280 bool setFMVolume(uint8_t i);
gtzintzarov3 0:851248a56628 281 int8_t getFMVolume();
gtzintzarov3 0:851248a56628 282 int8_t getFMSignalLevel(uint16_t station);
gtzintzarov3 0:851248a56628 283
gtzintzarov3 10:9dd3e49dec97 284 // SMS handling----------------------------------------------------------------------
gtzintzarov3 0:851248a56628 285 bool setSMSInterrupt(uint8_t i);
gtzintzarov3 0:851248a56628 286 uint8_t getSMSInterrupt(void);
gtzintzarov3 0:851248a56628 287 int8_t getNumSMS(void);
gtzintzarov3 0:851248a56628 288 bool readSMS(uint8_t i, char *smsbuff, uint16_t max, uint16_t *readsize);
gtzintzarov3 0:851248a56628 289 bool sendSMS(char *smsaddr, char *smsmsg);
gtzintzarov3 0:851248a56628 290 bool deleteSMS(uint8_t i);
gtzintzarov3 0:851248a56628 291 bool getSMSSender(uint8_t i, char *sender, int senderlen);
gtzintzarov3 0:851248a56628 292
gtzintzarov3 10:9dd3e49dec97 293 // Time----------------------------------------------------------------------
gtzintzarov3 0:851248a56628 294 bool enableNetworkTimeSync(bool onoff);
gtzintzarov3 0:851248a56628 295 bool enableNTPTimeSync(bool onoff, const char* ntpserver=0);
gtzintzarov3 0:851248a56628 296 bool getTime(char* buff, uint16_t maxlen);
gtzintzarov3 0:851248a56628 297
gtzintzarov3 10:9dd3e49dec97 298 // GPRS handling----------------------------------------------------------------------
gtzintzarov3 0:851248a56628 299 bool enableGPRS(bool onoff);
gtzintzarov3 0:851248a56628 300 uint8_t GPRSstate(void);
gtzintzarov3 0:851248a56628 301 bool getGSMLoc(uint16_t *replycode, char *buff, uint16_t maxlen);
gtzintzarov3 0:851248a56628 302 bool getGSMLoc(float *lat, float *lon);
gtzintzarov3 0:851248a56628 303 void setGPRSNetworkSettings(const char* apn, const char* username=0, const char* password=0);
gtzintzarov3 0:851248a56628 304
gtzintzarov3 10:9dd3e49dec97 305 // GPS handling----------------------------------------------------------------------
gtzintzarov3 0:851248a56628 306 bool enableGPS(bool onoff);
gtzintzarov3 0:851248a56628 307 int8_t GPSstatus(void);
gtzintzarov3 0:851248a56628 308 uint8_t getGPS(uint8_t arg, char *buffer, uint8_t maxbuff);
gtzintzarov3 0:851248a56628 309 bool getGPS(float *lat, float *lon, float *speed_kph=0, float *heading=0, float *altitude=0);
gtzintzarov3 0:851248a56628 310 bool enableGPSNMEA(uint8_t nmea);
gtzintzarov3 0:851248a56628 311
gtzintzarov3 10:9dd3e49dec97 312 // TCP raw connections----------------------------------------------------------------------
gtzintzarov3 0:851248a56628 313 bool TCPconnect(char *server, uint16_t port);
gtzintzarov3 0:851248a56628 314 bool TCPclose(void);
gtzintzarov3 0:851248a56628 315 bool TCPconnected(void);
gtzintzarov3 0:851248a56628 316 bool TCPsend(char *packet, uint8_t len);
gtzintzarov3 0:851248a56628 317 uint16_t TCPavailable(void);
gtzintzarov3 0:851248a56628 318 uint16_t TCPread(uint8_t *buff, uint8_t len);
gtzintzarov3 0:851248a56628 319
gtzintzarov3 10:9dd3e49dec97 320 // HTTP low level interface (maps directly to SIM800 commands).----------------------------------------------------------------------
gtzintzarov3 0:851248a56628 321 bool HTTP_init();
gtzintzarov3 0:851248a56628 322 bool HTTP_term();
gtzintzarov3 0:851248a56628 323 void HTTP_para_start(const char* parameter, bool quoted = true);
gtzintzarov3 0:851248a56628 324 bool HTTP_para_end(bool quoted = true);
gtzintzarov3 0:851248a56628 325 bool HTTP_para(const char* parameter, const char *value);
gtzintzarov3 0:851248a56628 326 bool HTTP_para(const char* parameter, int32_t value);
gtzintzarov3 0:851248a56628 327 bool HTTP_data(uint32_t size, uint32_t maxTime=10000);
gtzintzarov3 0:851248a56628 328 bool HTTP_action(uint8_t method, uint16_t *status, uint16_t *datalen, int32_t timeout = 10000);
gtzintzarov3 0:851248a56628 329 bool HTTP_readall(uint16_t *datalen);
gtzintzarov3 0:851248a56628 330 bool HTTP_ssl(bool onoff);
gtzintzarov3 0:851248a56628 331
gtzintzarov3 10:9dd3e49dec97 332 // HTTP high level interface (easier to use, less flexible).----------------------------------------------------------------------
gtzintzarov3 0:851248a56628 333 bool HTTP_GET_start(char *url, uint16_t *status, uint16_t *datalen);
gtzintzarov3 0:851248a56628 334 void HTTP_GET_end(void);
gtzintzarov3 0:851248a56628 335 bool HTTP_POST_start(char *url, const char* contenttype, const uint8_t *postdata, uint16_t postdatalen, uint16_t *status, uint16_t *datalen);
gtzintzarov3 0:851248a56628 336 void HTTP_POST_end(void);
gtzintzarov3 0:851248a56628 337 void setUserAgent(const char* useragent);
gtzintzarov3 0:851248a56628 338
gtzintzarov3 10:9dd3e49dec97 339 // HTTPS----------------------------------------------------------------------
gtzintzarov3 0:851248a56628 340 void setHTTPSRedirect(bool onoff);
gtzintzarov3 0:851248a56628 341
gtzintzarov3 10:9dd3e49dec97 342 // PWM (buzzer)----------------------------------------------------------------------
gtzintzarov3 0:851248a56628 343 bool setPWM(uint16_t period, uint8_t duty = 50);
gtzintzarov3 0:851248a56628 344
gtzintzarov3 10:9dd3e49dec97 345 // Phone calls----------------------------------------------------------------------
gtzintzarov3 0:851248a56628 346 bool callPhone(char *phonenum);
gtzintzarov3 0:851248a56628 347 bool hangUp(void);
gtzintzarov3 0:851248a56628 348 bool pickUp(void);
gtzintzarov3 0:851248a56628 349 bool callerIdNotification(bool enable);
gtzintzarov3 0:851248a56628 350 bool incomingCallNumber(char* phonenum);
gtzintzarov3 0:851248a56628 351
gtzintzarov3 0:851248a56628 352 // Helper functions to verify responses.
gtzintzarov3 0:851248a56628 353 bool expectReply(const char* reply, uint16_t timeout = 10000);
gtzintzarov3 0:851248a56628 354
gtzintzarov3 0:851248a56628 355 private:
gtzintzarov3 0:851248a56628 356 DigitalOut _rstpin;
gtzintzarov3 0:851248a56628 357 InterruptIn _ringIndicatorInterruptIn;
gtzintzarov3 0:851248a56628 358
George windoge T 2:aaef20ac9044 359 char replybuffer[255]; // the output of getreply(), readline() is the function that changes the replybuffer
gtzintzarov3 0:851248a56628 360 char* apn;
gtzintzarov3 0:851248a56628 361 char* apnusername;
gtzintzarov3 0:851248a56628 362 char* apnpassword;
gtzintzarov3 0:851248a56628 363 bool httpsredirect;
gtzintzarov3 0:851248a56628 364 char* useragent;
gtzintzarov3 0:851248a56628 365
gtzintzarov3 0:851248a56628 366 volatile bool _incomingCall;
gtzintzarov3 0:851248a56628 367 EventListener *eventListener;
gtzintzarov3 0:851248a56628 368 Serial mySerial;
gtzintzarov3 0:851248a56628 369
gtzintzarov3 0:851248a56628 370 // Circular buffer used to receive serial data from an interruption
gtzintzarov3 0:851248a56628 371 int rxBuffer[RX_BUFFER_SIZE + 1];
gtzintzarov3 0:851248a56628 372 volatile int rxBufferInIndex; // Index where new data is added to the buffer
gtzintzarov3 0:851248a56628 373 volatile int rxBufferOutIndex; // Index where data is removed from the buffer
gtzintzarov3 0:851248a56628 374 char currentReceivedLine[RX_BUFFER_SIZE]; // Array containing the current received line
gtzintzarov3 0:851248a56628 375 int currentReceivedLineSize;
gtzintzarov3 0:851248a56628 376
gtzintzarov3 0:851248a56628 377 inline bool isRxBufferFull() {
gtzintzarov3 0:851248a56628 378 return ((rxBufferInIndex + 1) % RX_BUFFER_SIZE) == rxBufferOutIndex;
gtzintzarov3 0:851248a56628 379 }
gtzintzarov3 0:851248a56628 380
gtzintzarov3 0:851248a56628 381 inline bool isRxBufferEmpty() {
gtzintzarov3 0:851248a56628 382 return rxBufferInIndex == rxBufferOutIndex;
gtzintzarov3 0:851248a56628 383 }
gtzintzarov3 0:851248a56628 384
gtzintzarov3 0:851248a56628 385 inline void incrementRxBufferInIndex() {
gtzintzarov3 0:851248a56628 386 rxBufferInIndex = (rxBufferInIndex + 1) % RX_BUFFER_SIZE;
gtzintzarov3 0:851248a56628 387 }
gtzintzarov3 0:851248a56628 388
gtzintzarov3 0:851248a56628 389 inline void incrementRxBufferOutIndex() {
gtzintzarov3 0:851248a56628 390 rxBufferOutIndex = (rxBufferOutIndex + 1) % RX_BUFFER_SIZE;
gtzintzarov3 0:851248a56628 391 }
gtzintzarov3 0:851248a56628 392
gtzintzarov3 0:851248a56628 393 /**
gtzintzarov3 0:851248a56628 394 * Method called when Serial data is received (interrupt routine).
gtzintzarov3 0:851248a56628 395 */
gtzintzarov3 0:851248a56628 396 void onSerialDataReceived();
gtzintzarov3 0:851248a56628 397
gtzintzarov3 0:851248a56628 398 // HTTP helpers
gtzintzarov3 0:851248a56628 399 bool HTTP_setup(char *url);
gtzintzarov3 0:851248a56628 400
gtzintzarov3 0:851248a56628 401 void flushInput();
gtzintzarov3 0:851248a56628 402 uint16_t readRaw(uint16_t b);
gtzintzarov3 0:851248a56628 403 uint8_t readline(uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS, bool multiline = false);
gtzintzarov3 0:851248a56628 404 uint8_t getReply(const char* send, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
gtzintzarov3 0:851248a56628 405 uint8_t getReply(const char* prefix, char *suffix, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
gtzintzarov3 0:851248a56628 406 uint8_t getReply(const char* prefix, int32_t suffix, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
gtzintzarov3 0:851248a56628 407 uint8_t getReply(const char* prefix, int32_t suffix1, int32_t suffix2, uint16_t timeout); // Don't set default value or else function call is ambiguous.
gtzintzarov3 0:851248a56628 408 uint8_t getReplyQuoted(const char* prefix, const char* suffix, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
gtzintzarov3 0:851248a56628 409
gtzintzarov3 0:851248a56628 410 bool sendCheckReply(const char* send, const char* reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
gtzintzarov3 0:851248a56628 411 bool sendCheckReply(const char* prefix, char *suffix, const char* reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
gtzintzarov3 0:851248a56628 412 bool sendCheckReply(const char* prefix, int32_t suffix, const char* reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
gtzintzarov3 0:851248a56628 413 bool sendCheckReply(const char* prefix, int32_t suffix, int32_t suffix2, const char* reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
gtzintzarov3 0:851248a56628 414 bool sendCheckReplyQuoted(const char* prefix, const char* suffix, const char* reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS);
gtzintzarov3 0:851248a56628 415
gtzintzarov3 0:851248a56628 416 bool parseReply(const char* toreply, uint16_t *v, char divider = ',', uint8_t index=0);
gtzintzarov3 0:851248a56628 417 bool parseReply(const char* toreply, char *v, char divider = ',', uint8_t index=0);
gtzintzarov3 0:851248a56628 418 bool parseReplyQuoted(const char* toreply, char* v, int maxlen, char divider, uint8_t index);
gtzintzarov3 0:851248a56628 419
gtzintzarov3 0:851248a56628 420 bool sendParseReply(const char* tosend, const char* toreply, uint16_t *v, char divider = ',', uint8_t index = 0);
gtzintzarov3 0:851248a56628 421
gtzintzarov3 0:851248a56628 422 void onIncomingCall();
gtzintzarov3 0:851248a56628 423 };
gtzintzarov3 0:851248a56628 424
gtzintzarov3 0:851248a56628 425 #endif