Update to work with latest mBed
Fork of FONA_CellPhone by
Diff: Adafruit_FONA.h
- Revision:
- 18:d52017f1d087
- Parent:
- 16:18750ad91289
--- a/Adafruit_FONA.h Wed Mar 30 16:19:51 2016 +0000 +++ b/Adafruit_FONA.h Wed Jan 25 12:56:31 2017 +0000 @@ -49,37 +49,28 @@ #define FONA_HTTP_POST 1 #define FONA_HTTP_HEAD 2 +#define FONA_CALL_READY 0 +#define FONA_CALL_FAILED 1 +#define FONA_CALL_UNKNOWN 2 +#define FONA_CALL_RINGING 3 +#define FONA_CALL_INPROGRESS 4 + #define RX_BUFFER_SIZE 255 +#define CIPSHUT_DELAY (uint16_t)65000 +#define CGATT_DELAY (uint16_t)10000 +#define SAPBR_DELAY (uint16_t)85000 +#define CIICR_DELAY (uint16_t)85000 +#define CGATT_DELAY (uint16_t)10000 +#define CIPGSMLOC_DELAY (uint16_t)60000 +#define CPIMUX_DELAY (uint16_t)160000 + /** Adafruit FONA 800H Class * Modified by George Tzintzarov & Jesse Baker 03/14/2016 for use in mbed LPC1768 */ class Adafruit_FONA : public Stream { public: -/** -Listener for FONA events. Inherit this class to customize. -@code -#define FONA_RST p12 -#define FONA_TX p13 -#define FONA_RX p14 -#define FONA_RI p11 - -Adafruit_FONA my_fona(FONA_TX, FONA_RX, FONA_RST, FONA_RI); -DigitalOut led1(LED1); -class FonaEventListener : public Adafruit_FONA::EventListener { - virtual void onRing() { - led1 = 1; -} - - virtual void onNoCarrier() { - led1 = 0; - } -}; -FonaEventListener fonaEventListener; -my_fona.setEventListener(&fonaEventListener); -@endcode -*/ class EventListener { public: @@ -95,34 +86,15 @@ }; public: - /** Create instance of the Adafruit_FONA - @param tx Set mbed TX - @param rx Set mbed RX - @param rst Set reset pin - @param ringIndicator Set ring indicator pin. This is to let mbed know if there is an incoming call - */ + Serial mySerial; Adafruit_FONA(PinName tx, PinName rx, PinName rst, PinName ringIndicator) : - _rstpin(rst, false), _ringIndicatorInterruptIn(ringIndicator), + mySerial(tx, rx),_rstpin(rst, false), _ringIndicatorInterruptIn(ringIndicator), apn("FONAnet"), apnusername(NULL), apnpassword(NULL), httpsredirect(false), useragent("FONA"), - _incomingCall(false), eventListener(NULL), mySerial(tx, rx), rxBufferInIndex(0), rxBufferOutIndex(0), + _incomingCall(false), eventListener(NULL), rxBufferInIndex(0), rxBufferOutIndex(0), currentReceivedLineSize(0) {} - /** Built-in Test to see if FONA is connected - @param baudrate test and set at baudrate - @return true upon success - @return false upon failure. Most likely something is not hooked up. - -EXAMPLE CODE: - @code -// See if the FONA is responding -// fona is an instance of Adafruit_FONA -if (! fona.begin(9600)) { - printf("Couldn't find FONA\r\n"); - while (1); -} - @endcode - */ + bool begin(int baudrate); /** Set the event listener for incoming calls @@ -131,7 +103,8 @@ */ void setEventListener(EventListener *eventListener); - + bool setBaudrate(uint16_t baud); + bool readRTC(uint8_t *year, uint8_t *month, uint8_t *date, uint8_t *hr, uint8_t *min, uint8_t *sec); // Stream---------------------------------------------------------------------- virtual int _putc(int value); virtual int _getc(); @@ -144,126 +117,23 @@ // RTC---------------------------------------------------------------------- bool enableRTC(uint8_t i); // i = 0 <=> disable, i = 1 <=> enable - // Battery and ADC---------------------------------------------------------------------- - /** Get ADC voltage from external pin - @param v uint16_t pointer to insert ADC voltage data - @return TRUE if successful - -EXAMPLE CODE: - @code -// read the ADC -// fona is an instance of Adafruit_FONA -uint16_t adc; -if (! fona.getADCVoltage(&adc)) { - printf("Failed to read ADC\r\n"); -} -else { - printf("ADC = %d mV\r\n", adc); -} - @endcode - */ + bool getADCVoltage(uint16_t *v); - - /** Get battery percentage level - @param p uint16_t pointer to insert battery percent data - @return TRUE if successful - -EXAMPLE CODE: - @code -// read the battery percent level -// fona is an instance of Adafruit_FONA -uint16_t vbatPer; -if (! fona.getBattPercent(&vbatPer)) { - printf("Failed to read Batt\r\n"); -} -else { - printf("VPct = %d%%\r\n", vbatPer); -} - @endcode - */ + bool getBattPercent(uint16_t *p); - - /** Get battery voltage level - @param v uint16_t pointer to insert battery voltage data - @return TRUE if successful - -EXAMPLE CODE: - @code -// read the battery voltage -// fona is an instance of Adafruit_FONA -uint16_t vbat; -if (! fona.getBattPercent(&vbat)) { - printf("Failed to read Batt\r\n"); -} -else { - printf("Vbat = %d%%\r\n", vbat); -} - @endcode - */ + bool getBattVoltage(uint16_t *v); - // SIM query---------------------------------------------------------------------- - /** Unlock SIM if needed - @param pin 4 digit char arrary - @return TRUE if successful - */ + bool unlockSIM(char *pin); - /** Get the SIM chip card interface device (CCID) - @param ccid make sure it is at least 21 bytes long - @return length of CCID - */ - + uint8_t getSIMCCID(char *ccid); - /** Get the Network Status of FONA - @return Code 0-5 - @see https://www.adafruit.com/datasheets/sim800_series_at_command_manual_v1.01.pdf page 80 - */ - uint8_t getNetworkStatus(void); - - /** Get the RSSI of the network signal - @return RSSI value in dBm per below reference - - EXAMPLE - @code -// read the RSSI -uint8_t n = fona.getRSSI(); -int8_t r = 0; -pcSerial.printf("RSSI = %d: ", n); -if (n == 0) r = -115; -if (n == 1) r = -111; -if (n == 31) r = -52; -if ((n >= 2) && (n <= 30)) { - r = map(n, 2, 30, -110, -54); -} -printf("%d dBm\r\n", r); + uint8_t getNetworkStatus(void); -// helper function MAP to do calculations -long MAP(long x, long in_min, long in_max, long out_min, long out_max) -{ - return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; -} - @endcode - @see https://www.adafruit.com/datasheets/sim800_series_at_command_manual_v1.01.pdf page 82 - */ uint8_t getRSSI(void); - - // IMEI---------------------------------------------------------------------- - /** Get the International Mobile Station Equipment Identity (IMEI) - @param imei A char array with minimum length 16 - @return The IMEI of the device - -EXAMPLE CODE: - @code -// Print SIM card IMEI number. -char imei[15] = {0}; // MUST use a 16 character buffer for IMEI! -uint8_t imeiLen = fona.getIMEI(imei); //fona is an instance of Adafruit_FONA -if (imeiLen > 0) { - pcSerial.printf("SIM card IMEI: %s\r\n", imei); -} - @endcode - */ + uint8_t getIMEI(char *imei); // set Audio output---------------------------------------------------------------------- @@ -417,7 +287,7 @@ bool HTTP_para(const char* parameter, const char *value); bool HTTP_para(const char* parameter, int32_t value); bool HTTP_data(uint32_t size, uint32_t maxTime=10000); - bool HTTP_action(uint8_t method, uint16_t *status, uint16_t *datalen, int32_t timeout = 10000); + bool HTTP_action(uint8_t method, uint16_t *status, uint16_t *datalen, int32_t timeout = 30000); bool HTTP_readall(uint16_t *datalen); bool HTTP_ssl(bool onoff); @@ -445,7 +315,7 @@ @return TRUE if successful */ bool callPhone(char *phonenum); - + uint8_t getCallStatus(void); /** Hang up a phone call */ bool hangUp(void); @@ -468,7 +338,7 @@ // Helper functions to verify responses. bool expectReply(const char* reply, uint16_t timeout = 10000); - + bool sendUSSD(char *ussdmsg, char *ussdbuff, uint16_t maxlen, uint16_t *readlen); private: DigitalOut _rstpin; InterruptIn _ringIndicatorInterruptIn; @@ -482,7 +352,7 @@ volatile bool _incomingCall; EventListener *eventListener; - Serial mySerial; + // Circular buffer used to receive serial data from an interruption int rxBuffer[RX_BUFFER_SIZE + 1]; @@ -539,4 +409,4 @@ void onIncomingCall(); }; -#endif \ No newline at end of file +#endif