diff --git a/Adafruit_GPS.cpp b/Adafruit_GPS.cpp index 7d057c5..b87722c 100755 --- a/Adafruit_GPS.cpp +++ b/Adafruit_GPS.cpp @@ -9,7 +9,7 @@ Written by Limor Fried/Ladyada for Adafruit Industries. BSD license, check license.txt for more information All text above must be included in any redistribution ****************************************/ - +#include #include // how long are max NMEA lines to parse? @@ -44,7 +44,7 @@ boolean Adafruit_GPS::parse(char *nmea) { //return false; } } - + char degreebuff[10]; // look for a few common sentences if (strstr(nmea, "$GPGGA")) { // found GGA @@ -61,7 +61,17 @@ boolean Adafruit_GPS::parse(char *nmea) { // parse out latitude p = strchr(p, ',')+1; - latitude = atof(p); + strncpy(degreebuff, p, 2); + p += 2; + degreebuff[2] = '\0'; + int32_t degree = atol(degreebuff) * 10000000; + strncpy(degreebuff, p, 2); // minutes + p += 3; // skip decimal point + strncpy(degreebuff + 2, p, 4); + degreebuff[6] = '\0'; + long minutes = 50 * atol(degreebuff) / 3; + latitude_fixed = degree + minutes; + latitude = latitude_fixed / 100000.0F; p = strchr(p, ',')+1; if (p[0] == 'N') lat = 'N'; @@ -71,7 +81,17 @@ boolean Adafruit_GPS::parse(char *nmea) { // parse out longitude p = strchr(p, ',')+1; - longitude = atof(p); + strncpy(degreebuff, p, 3); + p += 3; + degreebuff[3] = '\0'; + degree = atol(degreebuff) * 10000000; + strncpy(degreebuff, p, 2); // minutes + p += 3; // skip decimal point + strncpy(degreebuff + 2, p, 4); + degreebuff[6] = '\0'; + minutes = 50 * atol(degreebuff) / 3; + longitude_fixed = degree + minutes; + longitude = longitude_fixed / 100000.0F; p = strchr(p, ',')+1; if (p[0] == 'W') lon = 'W'; @@ -120,7 +140,17 @@ boolean Adafruit_GPS::parse(char *nmea) { // parse out latitude p = strchr(p, ',')+1; - latitude = atof(p); + strncpy(degreebuff, p, 2); + p += 2; + degreebuff[2] = '\0'; + long degree = atol(degreebuff) * 10000000; + strncpy(degreebuff, p, 2); // minutes + p += 3; // skip decimal point + strncpy(degreebuff + 2, p, 4); + degreebuff[6] = '\0'; + long minutes = 50 * atol(degreebuff) / 3; + latitude_fixed = degree + minutes; + latitude = latitude_fixed / 100000.0F; p = strchr(p, ',')+1; if (p[0] == 'N') lat = 'N'; @@ -130,7 +160,17 @@ boolean Adafruit_GPS::parse(char *nmea) { // parse out longitude p = strchr(p, ',')+1; - longitude = atof(p); + strncpy(degreebuff, p, 3); + p += 3; + degreebuff[3] = '\0'; + degree = atol(degreebuff) * 10000000; + strncpy(degreebuff, p, 2); // minutes + p += 3; // skip decimal point + strncpy(degreebuff + 2, p, 4); + degreebuff[6] = '\0'; + minutes = 50 * atol(degreebuff) / 3; + longitude_fixed = degree + minutes; + longitude = longitude_fixed / 100000.0F; p = strchr(p, ',')+1; if (p[0] == 'W') lon = 'W'; diff --git a/Adafruit_GPS.h b/Adafruit_GPS.h index 93d3824..4788133 100755 --- a/Adafruit_GPS.h +++ b/Adafruit_GPS.h @@ -57,6 +57,9 @@ All text above must be included in any redistribution #define LOCUS_OVERLAP 0 #define LOCUS_FULLSTOP 1 +#define PMTK_ENABLE_SBAS "$PMTK313,1*2E" +#define PMTK_ENABLE_WAAS "$PMTK301,2*2E" + // standby command & boot successful message #define PMTK_STANDBY "$PMTK161,0*28" #define PMTK_STANDBY_SUCCESS "$PMTK001,161,3*36" // Not needed currently @@ -116,7 +119,13 @@ class Adafruit_GPS { uint8_t hour, minute, seconds, year, month, day; uint16_t milliseconds; - float latitude, longitude, geoidheight, altitude; + // Floating point latitude and longitude value in degrees. + float latitude, longitude; + // Fixed point latitude and longitude value in 1/100000 degrees. + // For example a latitude of 4,767.99916 degrees would have a value of 476799916. + // More precise than the floating point value, but a little more difficult to use. + int32_t latitude_fixed, longitude_fixed; + float geoidheight, altitude; float speed, angle, magvariation, HDOP; char lat, lon, mag; boolean fix;