Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Adafruit_FONA_Library by
Revision 3:e04e0243fa54, committed 2018-09-28
- Comitter:
- 213468891
- Date:
- Fri Sep 28 08:24:23 2018 +0000
- Parent:
- 2:a47b72e3654e
- Commit message:
- Modified Adafruit_FONA_Library to be able to read GPS coordinates using SIMCOM's GSM/GPS/BT SIM808 module.
Changed in this revision
Adafruit_FONA.cpp | Show annotated file Show diff for this revision Revisions of this file |
Adafruit_FONA.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r a47b72e3654e -r e04e0243fa54 Adafruit_FONA.cpp --- a/Adafruit_FONA.cpp Mon Jun 29 20:48:25 2015 +0000 +++ b/Adafruit_FONA.cpp Fri Sep 28 08:24:23 2018 +0000 @@ -18,6 +18,11 @@ /* * Modified by Marc PLOUHINEC 27/06/2015 for use in mbed */ + + /* + * Modified by Crispin MUKALAY 31/08/2017 to read GPS coordinates using SIMCOM's GSM/GPS/BT SIM808 module + */ + #include <algorithm> #include "Adafruit_FONA.h" @@ -32,6 +37,7 @@ wait_ms(10); _rstpin = LOW; wait_ms(100); + _rstpin = HIGH; // give 3 seconds to reboot @@ -575,14 +581,14 @@ uint16_t state; // first check if its already on or off - if (! sendParseReply("AT+CGPSPWR?", "+CGPSPWR: ", &state) ) + if (! sendParseReply("AT+CGNSPWR?", "+CGNSPWR: ", &state) ) return false; if (onoff && !state) { - if (! sendCheckReply("AT+CGPSPWR=1", "OK")) + if (! sendCheckReply("AT+CGNSPWR=1", "OK")) return false; } else if (!onoff && state) { - if (! sendCheckReply("AT+CGPSPWR=0", "OK")) + if (! sendCheckReply("AT+CGNSPWR=0", "OK")) return false; } return true; @@ -608,12 +614,12 @@ return 0; } -uint8_t Adafruit_FONA::getGPS(uint8_t arg, char *buffer, uint8_t maxbuff) { +uint8_t Adafruit_FONA::getGPSInfo(uint8_t arg, char *buffer, uint8_t maxbuff) { int32_t x = arg; - getReply("AT+CGPSINF=", x); - - char *p = strstr(replybuffer, "CGPSINF: "); + getReply("AT+CGNSINF"); + + char *p = strstr(replybuffer, "+CGNSINF: "); if (p == 0){ buffer[0] = 0; return 0; @@ -627,16 +633,12 @@ return len; } -bool Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, float *heading, float *altitude) { +bool Adafruit_FONA::getGPS(float *fix, float *lat, float *lon,float *altitude, float *speed_kph, float *heading) { char gpsbuffer[120]; - - // we need at least a 2D fix - if (GPSstatus() < 2) - return false; - + // grab the mode 2^5 gps csv from the sim808 - uint8_t res_len = getGPS(32, gpsbuffer, 120); - + uint8_t res_len = getGPSInfo(32, gpsbuffer, 120); + // make sure we have a response if (res_len == 0) return false; @@ -645,54 +647,35 @@ char *tok = strtok(gpsbuffer, ","); if (! tok) return false; + // grab fix + char *fixp = strtok(NULL, ","); + if (! fixp) return false; + + *fix = atof(fixp); + // skip date tok = strtok(NULL, ","); if (! tok) return false; - // skip fix - tok = strtok(NULL, ","); - if (! tok) return false; - // grab the latitude char *latp = strtok(NULL, ","); if (! latp) return false; - // grab latitude direction - char *latdir = strtok(NULL, ","); - if (! latdir) return false; - // grab longitude char *longp = strtok(NULL, ","); if (! longp) return false; - - // grab longitude direction - char *longdir = strtok(NULL, ","); - if (! longdir) return false; - + double latitude = atof(latp); double longitude = atof(longp); - - // convert latitude from minutes to decimal - float degrees = floor(latitude / 100); - double minutes = latitude - (100 * degrees); - minutes /= 60; - degrees += minutes; - - // turn direction into + or - - if (latdir[0] == 'S') degrees *= -1; + + *lat = latitude; + *lon = longitude; - *lat = degrees; + // grab altitude + char *altp = strtok(NULL, ","); + if (! altp) return false; - // convert longitude from minutes to decimal - degrees = floor(longitude / 100); - minutes = longitude - (100 * degrees); - minutes /= 60; - degrees += minutes; - - // turn direction into + or - - if (longdir[0] == 'W') degrees *= -1; - - *lon = degrees; + *altitude = atof(altp); // only grab speed if needed if (speed_kph != NULL) { @@ -702,54 +685,18 @@ if (! speedp) return false; // convert to kph - *speed_kph = atof(speedp) * 1.852; + //*speed_kph = atof(speedp) * 1.852; + *speed_kph = atof(speedp); + + // grab heading + char *headingp = strtok(NULL, ","); + if (! headingp) return false; + + *heading = atof(headingp); + } - - // only grab heading if needed - if (heading != NULL) { - - // grab the speed in knots - char *coursep = strtok(NULL, ","); - if (! coursep) return false; - - *heading = atof(coursep); - - } - - // no need to continue - if (altitude == NULL) - return true; - - // we need at least a 3D fix for altitude - if (GPSstatus() < 3) - return false; - - // grab the mode 0 gps csv from the sim808 - res_len = getGPS(0, gpsbuffer, 120); - - // make sure we have a response - if (res_len == 0) - return false; - - // skip mode - tok = strtok(gpsbuffer, ","); - if (! tok) return false; - - // skip lat - tok = strtok(NULL, ","); - if (! tok) return false; - - // skip long - tok = strtok(NULL, ","); - if (! tok) return false; - - // grab altitude - char *altp = strtok(NULL, ","); - if (! altp) return false; - - *altitude = atof(altp); - + return true; }
diff -r a47b72e3654e -r e04e0243fa54 Adafruit_FONA.h --- a/Adafruit_FONA.h Mon Jun 29 20:48:25 2015 +0000 +++ b/Adafruit_FONA.h Fri Sep 28 08:24:23 2018 +0000 @@ -18,6 +18,10 @@ /* * Modified by Marc PLOUHINEC 27/06/2015 for use in mbed */ + + /* + * Modified by Crispin MUKALAY 31/08/2017 to read GPS coordinates using SIMCOM's GSM/GPS/BT SIM808 module + */ #ifndef ADAFRUIT_FONA_H #define ADAFRUIT_FONA_H @@ -139,8 +143,8 @@ // GPS handling bool enableGPS(bool onoff); int8_t GPSstatus(void); - uint8_t getGPS(uint8_t arg, char *buffer, uint8_t maxbuff); - bool getGPS(float *lat, float *lon, float *speed_kph=0, float *heading=0, float *altitude=0); + uint8_t getGPSInfo(uint8_t arg, char *buffer, uint8_t maxbuff); + bool getGPS(float *fix, float *lat, float *lon, float *altitude=0, float *speed_kph=0, float *heading=0); bool enableGPSNMEA(uint8_t nmea); // TCP raw connections