program to test exporting mbed-dev
Fork of FONA_CellPhone by
Adafruit_FONA.h@18:d52017f1d087, 2017-01-25 (annotated)
- Committer:
- michaelVisimid
- Date:
- Wed Jan 25 12:56:31 2017 +0000
- Revision:
- 18:d52017f1d087
- Parent:
- 16:18750ad91289
Update to work with latest mBed
Who changed what in which revision?
User | Revision | Line number | New 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 | |
michaelVisimid | 18:d52017f1d087 | 52 | #define FONA_CALL_READY 0 |
michaelVisimid | 18:d52017f1d087 | 53 | #define FONA_CALL_FAILED 1 |
michaelVisimid | 18:d52017f1d087 | 54 | #define FONA_CALL_UNKNOWN 2 |
michaelVisimid | 18:d52017f1d087 | 55 | #define FONA_CALL_RINGING 3 |
michaelVisimid | 18:d52017f1d087 | 56 | #define FONA_CALL_INPROGRESS 4 |
michaelVisimid | 18:d52017f1d087 | 57 | |
gtzintzarov3 | 0:851248a56628 | 58 | #define RX_BUFFER_SIZE 255 |
gtzintzarov3 | 0:851248a56628 | 59 | |
michaelVisimid | 18:d52017f1d087 | 60 | #define CIPSHUT_DELAY (uint16_t)65000 |
michaelVisimid | 18:d52017f1d087 | 61 | #define CGATT_DELAY (uint16_t)10000 |
michaelVisimid | 18:d52017f1d087 | 62 | #define SAPBR_DELAY (uint16_t)85000 |
michaelVisimid | 18:d52017f1d087 | 63 | #define CIICR_DELAY (uint16_t)85000 |
michaelVisimid | 18:d52017f1d087 | 64 | #define CGATT_DELAY (uint16_t)10000 |
michaelVisimid | 18:d52017f1d087 | 65 | #define CIPGSMLOC_DELAY (uint16_t)60000 |
michaelVisimid | 18:d52017f1d087 | 66 | #define CPIMUX_DELAY (uint16_t)160000 |
michaelVisimid | 18:d52017f1d087 | 67 | |
gtzintzarov3 | 9:06eca688f2a3 | 68 | /** Adafruit FONA 800H Class |
gtzintzarov3 | 9:06eca688f2a3 | 69 | * Modified by George Tzintzarov & Jesse Baker 03/14/2016 for use in mbed LPC1768 |
gtzintzarov3 | 9:06eca688f2a3 | 70 | */ |
gtzintzarov3 | 9:06eca688f2a3 | 71 | |
gtzintzarov3 | 0:851248a56628 | 72 | class Adafruit_FONA : public Stream { |
gtzintzarov3 | 0:851248a56628 | 73 | public: |
gtzintzarov3 | 9:06eca688f2a3 | 74 | |
gtzintzarov3 | 0:851248a56628 | 75 | class EventListener { |
gtzintzarov3 | 0:851248a56628 | 76 | public: |
gtzintzarov3 | 0:851248a56628 | 77 | /** |
gtzintzarov3 | 0:851248a56628 | 78 | * Method called when somebody call the FONA. |
gtzintzarov3 | 0:851248a56628 | 79 | */ |
gtzintzarov3 | 0:851248a56628 | 80 | virtual void onRing() = 0; |
gtzintzarov3 | 0:851248a56628 | 81 | |
gtzintzarov3 | 0:851248a56628 | 82 | /** |
gtzintzarov3 | 0:851248a56628 | 83 | * Method called when the calling person stop his call. |
gtzintzarov3 | 0:851248a56628 | 84 | */ |
gtzintzarov3 | 0:851248a56628 | 85 | virtual void onNoCarrier() = 0; |
gtzintzarov3 | 0:851248a56628 | 86 | }; |
gtzintzarov3 | 0:851248a56628 | 87 | |
gtzintzarov3 | 0:851248a56628 | 88 | public: |
michaelVisimid | 18:d52017f1d087 | 89 | Serial mySerial; |
gtzintzarov3 | 9:06eca688f2a3 | 90 | |
gtzintzarov3 | 0:851248a56628 | 91 | Adafruit_FONA(PinName tx, PinName rx, PinName rst, PinName ringIndicator) : |
michaelVisimid | 18:d52017f1d087 | 92 | mySerial(tx, rx),_rstpin(rst, false), _ringIndicatorInterruptIn(ringIndicator), |
gtzintzarov3 | 0:851248a56628 | 93 | apn("FONAnet"), apnusername(NULL), apnpassword(NULL), httpsredirect(false), useragent("FONA"), |
michaelVisimid | 18:d52017f1d087 | 94 | _incomingCall(false), eventListener(NULL), rxBufferInIndex(0), rxBufferOutIndex(0), |
gtzintzarov3 | 0:851248a56628 | 95 | currentReceivedLineSize(0) {} |
gtzintzarov3 | 9:06eca688f2a3 | 96 | |
michaelVisimid | 18:d52017f1d087 | 97 | |
gtzintzarov3 | 0:851248a56628 | 98 | bool begin(int baudrate); |
gtzintzarov3 | 9:06eca688f2a3 | 99 | |
gtzintzarov3 | 9:06eca688f2a3 | 100 | /** Set the event listener for incoming calls |
gtzintzarov3 | 9:06eca688f2a3 | 101 | @param eventListener A pointer to the event listener |
gtzintzarov3 | 9:06eca688f2a3 | 102 | @see Adafruit_FONA::EventListener for specific example |
gtzintzarov3 | 9:06eca688f2a3 | 103 | */ |
gtzintzarov3 | 9:06eca688f2a3 | 104 | |
gtzintzarov3 | 0:851248a56628 | 105 | void setEventListener(EventListener *eventListener); |
michaelVisimid | 18:d52017f1d087 | 106 | bool setBaudrate(uint16_t baud); |
michaelVisimid | 18:d52017f1d087 | 107 | bool readRTC(uint8_t *year, uint8_t *month, uint8_t *date, uint8_t *hr, uint8_t *min, uint8_t *sec); |
gtzintzarov3 | 9:06eca688f2a3 | 108 | // Stream---------------------------------------------------------------------- |
gtzintzarov3 | 0:851248a56628 | 109 | virtual int _putc(int value); |
gtzintzarov3 | 0:851248a56628 | 110 | virtual int _getc(); |
gtzintzarov3 | 0:851248a56628 | 111 | |
gtzintzarov3 | 9:06eca688f2a3 | 112 | /** Check if FONA has anything in its output buffer |
gtzintzarov3 | 9:06eca688f2a3 | 113 | @return 0 if nothing |
gtzintzarov3 | 9:06eca688f2a3 | 114 | */ |
gtzintzarov3 | 9:06eca688f2a3 | 115 | int readable(void); |
gtzintzarov3 | 9:06eca688f2a3 | 116 | |
gtzintzarov3 | 9:06eca688f2a3 | 117 | // RTC---------------------------------------------------------------------- |
gtzintzarov3 | 0:851248a56628 | 118 | bool enableRTC(uint8_t i); // i = 0 <=> disable, i = 1 <=> enable |
gtzintzarov3 | 0:851248a56628 | 119 | |
michaelVisimid | 18:d52017f1d087 | 120 | |
gtzintzarov3 | 0:851248a56628 | 121 | bool getADCVoltage(uint16_t *v); |
michaelVisimid | 18:d52017f1d087 | 122 | |
gtzintzarov3 | 9:06eca688f2a3 | 123 | |
gtzintzarov3 | 0:851248a56628 | 124 | bool getBattPercent(uint16_t *p); |
michaelVisimid | 18:d52017f1d087 | 125 | |
gtzintzarov3 | 0:851248a56628 | 126 | bool getBattVoltage(uint16_t *v); |
gtzintzarov3 | 0:851248a56628 | 127 | |
michaelVisimid | 18:d52017f1d087 | 128 | |
gtzintzarov3 | 0:851248a56628 | 129 | bool unlockSIM(char *pin); |
michaelVisimid | 18:d52017f1d087 | 130 | |
gtzintzarov3 | 0:851248a56628 | 131 | uint8_t getSIMCCID(char *ccid); |
gtzintzarov3 | 10:9dd3e49dec97 | 132 | |
michaelVisimid | 18:d52017f1d087 | 133 | uint8_t getNetworkStatus(void); |
gtzintzarov3 | 10:9dd3e49dec97 | 134 | |
gtzintzarov3 | 0:851248a56628 | 135 | uint8_t getRSSI(void); |
michaelVisimid | 18:d52017f1d087 | 136 | |
gtzintzarov3 | 0:851248a56628 | 137 | uint8_t getIMEI(char *imei); |
gtzintzarov3 | 0:851248a56628 | 138 | |
gtzintzarov3 | 10:9dd3e49dec97 | 139 | // set Audio output---------------------------------------------------------------------- |
George windoge T |
16:18750ad91289 | 140 | /** Set the Audio Output interface |
George windoge T |
16:18750ad91289 | 141 | @param a 0 is headset, 1 is external audio |
George windoge T |
16:18750ad91289 | 142 | @return TRUE if successful |
George windoge T |
16:18750ad91289 | 143 | */ |
gtzintzarov3 | 0:851248a56628 | 144 | bool setAudio(uint8_t a); |
George windoge T |
16:18750ad91289 | 145 | |
George windoge T |
16:18750ad91289 | 146 | /** Set the Audio Volume |
George windoge T |
16:18750ad91289 | 147 | @param i a unit8_t volume number |
George windoge T |
16:18750ad91289 | 148 | @return TRUE if successful |
George windoge T |
16:18750ad91289 | 149 | */ |
gtzintzarov3 | 0:851248a56628 | 150 | bool setVolume(uint8_t i); |
George windoge T |
16:18750ad91289 | 151 | |
George windoge T |
16:18750ad91289 | 152 | /** Get the Audio Volume |
George windoge T |
16:18750ad91289 | 153 | @return the current volume |
George windoge T |
16:18750ad91289 | 154 | */ |
gtzintzarov3 | 0:851248a56628 | 155 | uint8_t getVolume(void); |
gtzintzarov3 | 0:851248a56628 | 156 | bool playToolkitTone(uint8_t t, uint16_t len); |
gtzintzarov3 | 0:851248a56628 | 157 | bool setMicVolume(uint8_t a, uint8_t level); |
gtzintzarov3 | 0:851248a56628 | 158 | bool playDTMF(char tone); |
gtzintzarov3 | 0:851248a56628 | 159 | |
gtzintzarov3 | 10:9dd3e49dec97 | 160 | // FM radio functions---------------------------------------------------------------------- |
George windoge T |
16:18750ad91289 | 161 | /** Tune the FM radio |
George windoge T |
16:18750ad91289 | 162 | @param station frequency, for example 107.9 MHz -> 1079 |
George windoge T |
16:18750ad91289 | 163 | @return TRUE if successful |
George windoge T |
16:18750ad91289 | 164 | */ |
gtzintzarov3 | 0:851248a56628 | 165 | bool tuneFMradio(uint16_t station); |
George windoge T |
16:18750ad91289 | 166 | |
George windoge T |
16:18750ad91289 | 167 | /** FM radio set output |
George windoge T |
16:18750ad91289 | 168 | @param onoff bool to turn on if TRUE |
George windoge T |
16:18750ad91289 | 169 | @param a 0 (default) is headset, 1 is external audio |
George windoge T |
16:18750ad91289 | 170 | @return TRUE if successful |
George windoge T |
16:18750ad91289 | 171 | */ |
gtzintzarov3 | 0:851248a56628 | 172 | bool FMradio(bool onoff, uint8_t a = FONA_HEADSETAUDIO); |
George windoge T |
16:18750ad91289 | 173 | |
George windoge T |
16:18750ad91289 | 174 | /** Set the FM Radio Volume |
George windoge T |
16:18750ad91289 | 175 | @param i a unit8_t volume number |
George windoge T |
16:18750ad91289 | 176 | @return TRUE if successful |
George windoge T |
16:18750ad91289 | 177 | */ |
gtzintzarov3 | 0:851248a56628 | 178 | bool setFMVolume(uint8_t i); |
George windoge T |
16:18750ad91289 | 179 | |
George windoge T |
16:18750ad91289 | 180 | /** Get the FM Volume |
George windoge T |
16:18750ad91289 | 181 | @return the current FM volume |
George windoge T |
16:18750ad91289 | 182 | */ |
gtzintzarov3 | 0:851248a56628 | 183 | int8_t getFMVolume(); |
George windoge T |
16:18750ad91289 | 184 | |
George windoge T |
16:18750ad91289 | 185 | /** Get the FM signal strength |
George windoge T |
16:18750ad91289 | 186 | @param station a unit8_t volume number |
George windoge T |
16:18750ad91289 | 187 | @return TRUE if successful |
George windoge T |
16:18750ad91289 | 188 | */ |
gtzintzarov3 | 0:851248a56628 | 189 | int8_t getFMSignalLevel(uint16_t station); |
gtzintzarov3 | 0:851248a56628 | 190 | |
gtzintzarov3 | 10:9dd3e49dec97 | 191 | // SMS handling---------------------------------------------------------------------- |
George windoge T |
16:18750ad91289 | 192 | /** Set the SMS Interrupt |
George windoge T |
16:18750ad91289 | 193 | @param i 0 = OFF, 1 = ON with TCPIP, FTP, and URC control Ring Indicator Pin, 2 = ON with only TCPIP control |
George windoge T |
16:18750ad91289 | 194 | @return TRUE if successful |
George windoge T |
16:18750ad91289 | 195 | @see https://www.adafruit.com/datasheets/sim800_series_at_command_manual_v1.01.pdf page 152 |
George windoge T |
16:18750ad91289 | 196 | */ |
gtzintzarov3 | 0:851248a56628 | 197 | bool setSMSInterrupt(uint8_t i); |
George windoge T |
16:18750ad91289 | 198 | |
George windoge T |
16:18750ad91289 | 199 | /** Get SMS Interrupt Setting |
George windoge T |
16:18750ad91289 | 200 | @return setting |
George windoge T |
16:18750ad91289 | 201 | @see https://www.adafruit.com/datasheets/sim800_series_at_command_manual_v1.01.pdf page 152 |
George windoge T |
16:18750ad91289 | 202 | */ |
gtzintzarov3 | 0:851248a56628 | 203 | uint8_t getSMSInterrupt(void); |
George windoge T |
16:18750ad91289 | 204 | |
George windoge T |
16:18750ad91289 | 205 | /** Set the SMS Interrupt |
George windoge T |
16:18750ad91289 | 206 | @return number of SMS messages in inbox |
George windoge T |
16:18750ad91289 | 207 | */ |
gtzintzarov3 | 0:851248a56628 | 208 | int8_t getNumSMS(void); |
George windoge T |
16:18750ad91289 | 209 | |
George windoge T |
16:18750ad91289 | 210 | /** Read SMS |
George windoge T |
16:18750ad91289 | 211 | @param i sms number in memory |
George windoge T |
16:18750ad91289 | 212 | @param smsbuff char pointer to char array |
George windoge T |
16:18750ad91289 | 213 | @param max Maximum length of smsbuff |
George windoge T |
16:18750ad91289 | 214 | @param readsize the size in bytes of the SMS |
George windoge T |
16:18750ad91289 | 215 | @return TRUE if successful |
George windoge T |
16:18750ad91289 | 216 | */ |
gtzintzarov3 | 0:851248a56628 | 217 | bool readSMS(uint8_t i, char *smsbuff, uint16_t max, uint16_t *readsize); |
George windoge T |
16:18750ad91289 | 218 | |
George windoge T |
16:18750ad91289 | 219 | /** Send SMS |
George windoge T |
16:18750ad91289 | 220 | @param smsaddr Phone number to send out |
George windoge T |
16:18750ad91289 | 221 | @param smsmsg Char array containing message |
George windoge T |
16:18750ad91289 | 222 | @return TRUE if successful |
George windoge T |
16:18750ad91289 | 223 | */ |
gtzintzarov3 | 0:851248a56628 | 224 | bool sendSMS(char *smsaddr, char *smsmsg); |
George windoge T |
16:18750ad91289 | 225 | |
George windoge T |
16:18750ad91289 | 226 | /** Delete SMS |
George windoge T |
16:18750ad91289 | 227 | @param i number of SMS in memory |
George windoge T |
16:18750ad91289 | 228 | @return TRUE if successful |
George windoge T |
16:18750ad91289 | 229 | */ |
gtzintzarov3 | 0:851248a56628 | 230 | bool deleteSMS(uint8_t i); |
George windoge T |
16:18750ad91289 | 231 | |
George windoge T |
16:18750ad91289 | 232 | /** Send SMS |
George windoge T |
16:18750ad91289 | 233 | @param i Number of SMS in memory |
George windoge T |
16:18750ad91289 | 234 | @param sender Char array to store the sender number |
George windoge T |
16:18750ad91289 | 235 | @param senderlen length of sender |
George windoge T |
16:18750ad91289 | 236 | @return TRUE if successful |
George windoge T |
16:18750ad91289 | 237 | */ |
gtzintzarov3 | 0:851248a56628 | 238 | bool getSMSSender(uint8_t i, char *sender, int senderlen); |
gtzintzarov3 | 0:851248a56628 | 239 | |
gtzintzarov3 | 10:9dd3e49dec97 | 240 | // Time---------------------------------------------------------------------- |
jbaker66 | 15:19a02a88836a | 241 | /** Enable FONA to sync time with the cellular network |
jbaker66 | 15:19a02a88836a | 242 | @param onoff on = true, off = false |
jbaker66 | 15:19a02a88836a | 243 | @return TRUE if successful |
jbaker66 | 15:19a02a88836a | 244 | */ |
gtzintzarov3 | 0:851248a56628 | 245 | bool enableNetworkTimeSync(bool onoff); |
jbaker66 | 15:19a02a88836a | 246 | |
jbaker66 | 15:19a02a88836a | 247 | /** Enable FONA to sync time with the time server |
jbaker66 | 15:19a02a88836a | 248 | @param onoff true = on, false = off |
jbaker66 | 15:19a02a88836a | 249 | @return TRUE if successful |
jbaker66 | 15:19a02a88836a | 250 | */ |
gtzintzarov3 | 0:851248a56628 | 251 | bool enableNTPTimeSync(bool onoff, const char* ntpserver=0); |
jbaker66 | 15:19a02a88836a | 252 | |
jbaker66 | 15:19a02a88836a | 253 | /** Retrieve the current time from the enabled server |
jbaker66 | 15:19a02a88836a | 254 | @param buff char array to store time value. Given as "yy/MM/dd,hh:mm:ss+zz" |
jbaker66 | 15:19a02a88836a | 255 | @param maxlen Maximum length of the char array |
jbaker66 | 15:19a02a88836a | 256 | @return TRUE if successful |
jbaker66 | 15:19a02a88836a | 257 | */ |
gtzintzarov3 | 0:851248a56628 | 258 | bool getTime(char* buff, uint16_t maxlen); |
jbaker66 | 15:19a02a88836a | 259 | |
gtzintzarov3 | 10:9dd3e49dec97 | 260 | // GPRS handling---------------------------------------------------------------------- |
gtzintzarov3 | 0:851248a56628 | 261 | bool enableGPRS(bool onoff); |
gtzintzarov3 | 0:851248a56628 | 262 | uint8_t GPRSstate(void); |
gtzintzarov3 | 0:851248a56628 | 263 | bool getGSMLoc(uint16_t *replycode, char *buff, uint16_t maxlen); |
gtzintzarov3 | 0:851248a56628 | 264 | bool getGSMLoc(float *lat, float *lon); |
gtzintzarov3 | 0:851248a56628 | 265 | void setGPRSNetworkSettings(const char* apn, const char* username=0, const char* password=0); |
gtzintzarov3 | 0:851248a56628 | 266 | |
gtzintzarov3 | 10:9dd3e49dec97 | 267 | // GPS handling---------------------------------------------------------------------- |
gtzintzarov3 | 0:851248a56628 | 268 | bool enableGPS(bool onoff); |
gtzintzarov3 | 0:851248a56628 | 269 | int8_t GPSstatus(void); |
gtzintzarov3 | 0:851248a56628 | 270 | uint8_t getGPS(uint8_t arg, char *buffer, uint8_t maxbuff); |
gtzintzarov3 | 0:851248a56628 | 271 | bool getGPS(float *lat, float *lon, float *speed_kph=0, float *heading=0, float *altitude=0); |
gtzintzarov3 | 0:851248a56628 | 272 | bool enableGPSNMEA(uint8_t nmea); |
jbaker66 | 15:19a02a88836a | 273 | |
gtzintzarov3 | 10:9dd3e49dec97 | 274 | // TCP raw connections---------------------------------------------------------------------- |
gtzintzarov3 | 0:851248a56628 | 275 | bool TCPconnect(char *server, uint16_t port); |
gtzintzarov3 | 0:851248a56628 | 276 | bool TCPclose(void); |
gtzintzarov3 | 0:851248a56628 | 277 | bool TCPconnected(void); |
gtzintzarov3 | 0:851248a56628 | 278 | bool TCPsend(char *packet, uint8_t len); |
gtzintzarov3 | 0:851248a56628 | 279 | uint16_t TCPavailable(void); |
gtzintzarov3 | 0:851248a56628 | 280 | uint16_t TCPread(uint8_t *buff, uint8_t len); |
jbaker66 | 15:19a02a88836a | 281 | |
gtzintzarov3 | 10:9dd3e49dec97 | 282 | // HTTP low level interface (maps directly to SIM800 commands).---------------------------------------------------------------------- |
gtzintzarov3 | 0:851248a56628 | 283 | bool HTTP_init(); |
gtzintzarov3 | 0:851248a56628 | 284 | bool HTTP_term(); |
gtzintzarov3 | 0:851248a56628 | 285 | void HTTP_para_start(const char* parameter, bool quoted = true); |
gtzintzarov3 | 0:851248a56628 | 286 | bool HTTP_para_end(bool quoted = true); |
gtzintzarov3 | 0:851248a56628 | 287 | bool HTTP_para(const char* parameter, const char *value); |
gtzintzarov3 | 0:851248a56628 | 288 | bool HTTP_para(const char* parameter, int32_t value); |
gtzintzarov3 | 0:851248a56628 | 289 | bool HTTP_data(uint32_t size, uint32_t maxTime=10000); |
michaelVisimid | 18:d52017f1d087 | 290 | bool HTTP_action(uint8_t method, uint16_t *status, uint16_t *datalen, int32_t timeout = 30000); |
gtzintzarov3 | 0:851248a56628 | 291 | bool HTTP_readall(uint16_t *datalen); |
gtzintzarov3 | 0:851248a56628 | 292 | bool HTTP_ssl(bool onoff); |
jbaker66 | 15:19a02a88836a | 293 | |
gtzintzarov3 | 10:9dd3e49dec97 | 294 | // HTTP high level interface (easier to use, less flexible).---------------------------------------------------------------------- |
gtzintzarov3 | 0:851248a56628 | 295 | bool HTTP_GET_start(char *url, uint16_t *status, uint16_t *datalen); |
gtzintzarov3 | 0:851248a56628 | 296 | void HTTP_GET_end(void); |
gtzintzarov3 | 0:851248a56628 | 297 | 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 | 298 | void HTTP_POST_end(void); |
gtzintzarov3 | 0:851248a56628 | 299 | void setUserAgent(const char* useragent); |
jbaker66 | 15:19a02a88836a | 300 | |
gtzintzarov3 | 10:9dd3e49dec97 | 301 | // HTTPS---------------------------------------------------------------------- |
gtzintzarov3 | 0:851248a56628 | 302 | void setHTTPSRedirect(bool onoff); |
jbaker66 | 15:19a02a88836a | 303 | |
gtzintzarov3 | 10:9dd3e49dec97 | 304 | // PWM (buzzer)---------------------------------------------------------------------- |
jbaker66 | 15:19a02a88836a | 305 | /** Control the buzzer capability of the PWM out on the FONA |
jbaker66 | 15:19a02a88836a | 306 | @param period of the buzzing cycle (max 2000) |
jbaker66 | 15:19a02a88836a | 307 | @param duty the duty cycle of the buzzer (0 to 100) |
jbaker66 | 15:19a02a88836a | 308 | @return TRUE if successful |
jbaker66 | 15:19a02a88836a | 309 | */ |
gtzintzarov3 | 0:851248a56628 | 310 | bool setPWM(uint16_t period, uint8_t duty = 50); |
jbaker66 | 15:19a02a88836a | 311 | |
gtzintzarov3 | 10:9dd3e49dec97 | 312 | // Phone calls---------------------------------------------------------------------- |
jbaker66 | 15:19a02a88836a | 313 | /** Call a phone |
jbaker66 | 15:19a02a88836a | 314 | @param phonenum a character array of the phone number |
jbaker66 | 15:19a02a88836a | 315 | @return TRUE if successful |
jbaker66 | 15:19a02a88836a | 316 | */ |
gtzintzarov3 | 0:851248a56628 | 317 | bool callPhone(char *phonenum); |
michaelVisimid | 18:d52017f1d087 | 318 | uint8_t getCallStatus(void); |
jbaker66 | 15:19a02a88836a | 319 | /** Hang up a phone call |
jbaker66 | 15:19a02a88836a | 320 | */ |
gtzintzarov3 | 0:851248a56628 | 321 | bool hangUp(void); |
jbaker66 | 15:19a02a88836a | 322 | |
jbaker66 | 15:19a02a88836a | 323 | /** Answer a phone call |
jbaker66 | 15:19a02a88836a | 324 | */ |
gtzintzarov3 | 0:851248a56628 | 325 | bool pickUp(void); |
jbaker66 | 15:19a02a88836a | 326 | |
jbaker66 | 15:19a02a88836a | 327 | /** Enable/disable caller ID |
jbaker66 | 15:19a02a88836a | 328 | @param enable true to enable, false to disable |
jbaker66 | 15:19a02a88836a | 329 | @return TRUE if successful |
jbaker66 | 15:19a02a88836a | 330 | */ |
gtzintzarov3 | 0:851248a56628 | 331 | bool callerIdNotification(bool enable); |
jbaker66 | 15:19a02a88836a | 332 | |
jbaker66 | 15:19a02a88836a | 333 | /** Retrieve the incoming call number |
jbaker66 | 15:19a02a88836a | 334 | @param phonenum a character array of the phone number calling |
jbaker66 | 15:19a02a88836a | 335 | @return TRUE if successful |
jbaker66 | 15:19a02a88836a | 336 | */ |
gtzintzarov3 | 0:851248a56628 | 337 | bool incomingCallNumber(char* phonenum); |
jbaker66 | 15:19a02a88836a | 338 | |
gtzintzarov3 | 0:851248a56628 | 339 | // Helper functions to verify responses. |
gtzintzarov3 | 0:851248a56628 | 340 | bool expectReply(const char* reply, uint16_t timeout = 10000); |
michaelVisimid | 18:d52017f1d087 | 341 | bool sendUSSD(char *ussdmsg, char *ussdbuff, uint16_t maxlen, uint16_t *readlen); |
gtzintzarov3 | 0:851248a56628 | 342 | private: |
gtzintzarov3 | 0:851248a56628 | 343 | DigitalOut _rstpin; |
gtzintzarov3 | 0:851248a56628 | 344 | InterruptIn _ringIndicatorInterruptIn; |
jbaker66 | 15:19a02a88836a | 345 | |
George windoge T |
2:aaef20ac9044 | 346 | char replybuffer[255]; // the output of getreply(), readline() is the function that changes the replybuffer |
gtzintzarov3 | 0:851248a56628 | 347 | char* apn; |
gtzintzarov3 | 0:851248a56628 | 348 | char* apnusername; |
gtzintzarov3 | 0:851248a56628 | 349 | char* apnpassword; |
gtzintzarov3 | 0:851248a56628 | 350 | bool httpsredirect; |
gtzintzarov3 | 0:851248a56628 | 351 | char* useragent; |
jbaker66 | 15:19a02a88836a | 352 | |
gtzintzarov3 | 0:851248a56628 | 353 | volatile bool _incomingCall; |
gtzintzarov3 | 0:851248a56628 | 354 | EventListener *eventListener; |
michaelVisimid | 18:d52017f1d087 | 355 | |
jbaker66 | 15:19a02a88836a | 356 | |
gtzintzarov3 | 0:851248a56628 | 357 | // Circular buffer used to receive serial data from an interruption |
gtzintzarov3 | 0:851248a56628 | 358 | int rxBuffer[RX_BUFFER_SIZE + 1]; |
gtzintzarov3 | 0:851248a56628 | 359 | volatile int rxBufferInIndex; // Index where new data is added to the buffer |
gtzintzarov3 | 0:851248a56628 | 360 | volatile int rxBufferOutIndex; // Index where data is removed from the buffer |
gtzintzarov3 | 0:851248a56628 | 361 | char currentReceivedLine[RX_BUFFER_SIZE]; // Array containing the current received line |
gtzintzarov3 | 0:851248a56628 | 362 | int currentReceivedLineSize; |
jbaker66 | 15:19a02a88836a | 363 | |
gtzintzarov3 | 0:851248a56628 | 364 | inline bool isRxBufferFull() { |
gtzintzarov3 | 0:851248a56628 | 365 | return ((rxBufferInIndex + 1) % RX_BUFFER_SIZE) == rxBufferOutIndex; |
gtzintzarov3 | 0:851248a56628 | 366 | } |
jbaker66 | 15:19a02a88836a | 367 | |
gtzintzarov3 | 0:851248a56628 | 368 | inline bool isRxBufferEmpty() { |
gtzintzarov3 | 0:851248a56628 | 369 | return rxBufferInIndex == rxBufferOutIndex; |
gtzintzarov3 | 0:851248a56628 | 370 | } |
jbaker66 | 15:19a02a88836a | 371 | |
gtzintzarov3 | 0:851248a56628 | 372 | inline void incrementRxBufferInIndex() { |
gtzintzarov3 | 0:851248a56628 | 373 | rxBufferInIndex = (rxBufferInIndex + 1) % RX_BUFFER_SIZE; |
gtzintzarov3 | 0:851248a56628 | 374 | } |
jbaker66 | 15:19a02a88836a | 375 | |
gtzintzarov3 | 0:851248a56628 | 376 | inline void incrementRxBufferOutIndex() { |
gtzintzarov3 | 0:851248a56628 | 377 | rxBufferOutIndex = (rxBufferOutIndex + 1) % RX_BUFFER_SIZE; |
gtzintzarov3 | 0:851248a56628 | 378 | } |
jbaker66 | 15:19a02a88836a | 379 | |
gtzintzarov3 | 0:851248a56628 | 380 | /** |
gtzintzarov3 | 0:851248a56628 | 381 | * Method called when Serial data is received (interrupt routine). |
gtzintzarov3 | 0:851248a56628 | 382 | */ |
gtzintzarov3 | 0:851248a56628 | 383 | void onSerialDataReceived(); |
jbaker66 | 15:19a02a88836a | 384 | |
gtzintzarov3 | 0:851248a56628 | 385 | // HTTP helpers |
gtzintzarov3 | 0:851248a56628 | 386 | bool HTTP_setup(char *url); |
jbaker66 | 15:19a02a88836a | 387 | |
gtzintzarov3 | 0:851248a56628 | 388 | void flushInput(); |
gtzintzarov3 | 0:851248a56628 | 389 | uint16_t readRaw(uint16_t b); |
gtzintzarov3 | 0:851248a56628 | 390 | uint8_t readline(uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS, bool multiline = false); |
gtzintzarov3 | 0:851248a56628 | 391 | uint8_t getReply(const char* send, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); |
gtzintzarov3 | 0:851248a56628 | 392 | uint8_t getReply(const char* prefix, char *suffix, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); |
gtzintzarov3 | 0:851248a56628 | 393 | uint8_t getReply(const char* prefix, int32_t suffix, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); |
gtzintzarov3 | 0:851248a56628 | 394 | 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 | 395 | uint8_t getReplyQuoted(const char* prefix, const char* suffix, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); |
jbaker66 | 15:19a02a88836a | 396 | |
gtzintzarov3 | 0:851248a56628 | 397 | bool sendCheckReply(const char* send, const char* reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); |
gtzintzarov3 | 0:851248a56628 | 398 | bool sendCheckReply(const char* prefix, char *suffix, const char* reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); |
gtzintzarov3 | 0:851248a56628 | 399 | bool sendCheckReply(const char* prefix, int32_t suffix, const char* reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); |
gtzintzarov3 | 0:851248a56628 | 400 | bool sendCheckReply(const char* prefix, int32_t suffix, int32_t suffix2, const char* reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); |
gtzintzarov3 | 0:851248a56628 | 401 | bool sendCheckReplyQuoted(const char* prefix, const char* suffix, const char* reply, uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS); |
jbaker66 | 15:19a02a88836a | 402 | |
gtzintzarov3 | 0:851248a56628 | 403 | bool parseReply(const char* toreply, uint16_t *v, char divider = ',', uint8_t index=0); |
gtzintzarov3 | 0:851248a56628 | 404 | bool parseReply(const char* toreply, char *v, char divider = ',', uint8_t index=0); |
gtzintzarov3 | 0:851248a56628 | 405 | bool parseReplyQuoted(const char* toreply, char* v, int maxlen, char divider, uint8_t index); |
jbaker66 | 15:19a02a88836a | 406 | |
gtzintzarov3 | 0:851248a56628 | 407 | bool sendParseReply(const char* tosend, const char* toreply, uint16_t *v, char divider = ',', uint8_t index = 0); |
jbaker66 | 15:19a02a88836a | 408 | |
gtzintzarov3 | 0:851248a56628 | 409 | void onIncomingCall(); |
gtzintzarov3 | 0:851248a56628 | 410 | }; |
gtzintzarov3 | 0:851248a56628 | 411 | |
michaelVisimid | 18:d52017f1d087 | 412 | #endif |