Added support for the GSA sentence
This commit is contained in:
parent
5c2ddda5c2
commit
ebde856657
152
Adafruit_GPS.cpp
152
Adafruit_GPS.cpp
|
|
@ -204,6 +204,136 @@ boolean Adafruit_GPS::parse(char *nmea) {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (strStartsWith(nmea, "$GPRMC") || strStartsWith(nmea, "$GNRMC")) {
|
||||
// found RMC
|
||||
// get time
|
||||
p = strchr(p, ',')+1;
|
||||
parseTime(p);
|
||||
|
||||
// fix or no fix
|
||||
p = strchr(p, ',')+1;
|
||||
if(!parseFix(p)) return false;
|
||||
|
||||
// parse out latitude
|
||||
p = strchr(p, ',')+1;
|
||||
parseLat(p);
|
||||
p = strchr(p, ',')+1;
|
||||
if(!parseLatDir(p)) return false;
|
||||
|
||||
// parse out longitude
|
||||
p = strchr(p, ',')+1;
|
||||
parseLon(p);
|
||||
p = strchr(p, ',')+1;
|
||||
if(!parseLonDir(p)) return false;
|
||||
|
||||
// speed
|
||||
p = strchr(p, ',')+1;
|
||||
if (',' != *p)
|
||||
{
|
||||
speed = atof(p);
|
||||
}
|
||||
|
||||
// angle
|
||||
p = strchr(p, ',')+1;
|
||||
if (',' != *p)
|
||||
{
|
||||
angle = atof(p);
|
||||
}
|
||||
|
||||
p = strchr(p, ',')+1;
|
||||
if (',' != *p)
|
||||
{
|
||||
uint32_t fulldate = atof(p);
|
||||
day = fulldate / 10000;
|
||||
month = (fulldate % 10000) / 100;
|
||||
year = (fulldate % 100);
|
||||
lastDate = sentTime;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strStartsWith(nmea, "$GPGLL") || strStartsWith(nmea, "$GNGLL")) {
|
||||
// found GLL
|
||||
// parse out latitude
|
||||
p = strchr(p, ',')+1;
|
||||
parseLat(p);
|
||||
p = strchr(p, ',')+1;
|
||||
if(!parseLatDir(p)) return false;
|
||||
|
||||
// parse out longitude
|
||||
p = strchr(p, ',')+1;
|
||||
parseLon(p);
|
||||
p = strchr(p, ',')+1;
|
||||
if(!parseLonDir(p)) return false;
|
||||
|
||||
// get time
|
||||
p = strchr(p, ',')+1;
|
||||
parseTime(p);
|
||||
|
||||
// fix or no fix
|
||||
p = strchr(p, ',')+1;
|
||||
if(!parseFix(p)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strStartsWith(nmea, "$GPGSA")) {
|
||||
// found GSA
|
||||
// parse out Auto selection, but ignore them
|
||||
p = strchr(p, ',')+1;
|
||||
// parse out 3d fixquality
|
||||
p = strchr(p, ',')+1;
|
||||
if (',' != *p)
|
||||
{
|
||||
fixquality_3d = atoi(p);
|
||||
}
|
||||
// parse out Satellite PDNs, but ignore them
|
||||
p = strchr(p, ',')+1;
|
||||
|
||||
p = strchr(p, ',')+1;
|
||||
|
||||
p = strchr(p, ',')+1;
|
||||
|
||||
p = strchr(p, ',')+1;
|
||||
|
||||
p = strchr(p, ',')+1;
|
||||
|
||||
p = strchr(p, ',')+1;
|
||||
|
||||
p = strchr(p, ',')+1;
|
||||
|
||||
p = strchr(p, ',')+1;
|
||||
|
||||
p = strchr(p, ',')+1;
|
||||
|
||||
p = strchr(p, ',')+1;
|
||||
|
||||
p = strchr(p, ',')+1;
|
||||
|
||||
p = strchr(p, ',')+1;
|
||||
|
||||
//parse out PDOP
|
||||
p = strchr(p, ',')+1;
|
||||
if (',' != *p)
|
||||
{
|
||||
PDOP = atof(p);
|
||||
}
|
||||
// parse out HDOP, we also parse this from the GGA sentence. Chipset should report the same for both
|
||||
p = strchr(p, ',')+1;
|
||||
if (',' != *p)
|
||||
{
|
||||
HDOP = atof(p);
|
||||
}
|
||||
// parse out VDOP
|
||||
p = strchr(p, ',')+1;
|
||||
if (',' != *p)
|
||||
{
|
||||
VDOP = atof(p);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// we dont parse the remaining, yet!
|
||||
return false;
|
||||
}
|
||||
|
|
@ -393,7 +523,7 @@ size_t Adafruit_GPS::available(void) {
|
|||
#if (defined(__AVR__) || defined(ESP8266)) && defined(USE_SW_SERIAL)
|
||||
if (gpsSwSerial) {
|
||||
return gpsSwSerial->available();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (gpsHwSerial) {
|
||||
return gpsHwSerial->available();
|
||||
|
|
@ -415,7 +545,7 @@ size_t Adafruit_GPS::write(uint8_t c) {
|
|||
#if (defined(__AVR__) || defined(ESP8266)) && defined(USE_SW_SERIAL)
|
||||
if (gpsSwSerial) {
|
||||
return gpsSwSerial->write(c);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (gpsHwSerial) {
|
||||
return gpsHwSerial->write(c);
|
||||
|
|
@ -447,13 +577,13 @@ char Adafruit_GPS::read(void) {
|
|||
|
||||
#if (defined(__AVR__) || defined(ESP8266)) && defined(USE_SW_SERIAL)
|
||||
if(gpsSwSerial) {
|
||||
if (!gpsSwSerial->available())
|
||||
if (!gpsSwSerial->available())
|
||||
return c;
|
||||
c = gpsSwSerial->read();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (gpsHwSerial) {
|
||||
if (!gpsHwSerial->available())
|
||||
if (!gpsHwSerial->available())
|
||||
return c;
|
||||
c = gpsHwSerial->read();
|
||||
}
|
||||
|
|
@ -469,7 +599,7 @@ char Adafruit_GPS::read(void) {
|
|||
char curr_char = 0;
|
||||
for (int i=0; i<GPS_MAX_I2C_TRANSFER; i++) {
|
||||
curr_char = Wire.read();
|
||||
if ((curr_char == 0x0A) && (last_char != 0x0D)) {
|
||||
if ((curr_char == 0x0A) && (last_char != 0x0D)) {
|
||||
// skip duplicate 0x0A's - but keep as part of a CRLF
|
||||
continue;
|
||||
}
|
||||
|
|
@ -486,9 +616,9 @@ char Adafruit_GPS::read(void) {
|
|||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Serial.print(c);
|
||||
|
||||
|
||||
currentline[lineidx++] = c;
|
||||
if (lineidx >= MAXLINELENGTH)
|
||||
lineidx = MAXLINELENGTH-1; // ensure there is someplace to put the next received character
|
||||
|
|
@ -573,12 +703,12 @@ void Adafruit_GPS::common_init(void) {
|
|||
lastline = line2;
|
||||
|
||||
hour = minute = seconds = year = month = day =
|
||||
fixquality = satellites = 0; // uint8_t
|
||||
fixquality = fixquality_3d = satellites = 0; // uint8_t
|
||||
lat = lon = mag = 0; // char
|
||||
fix = false; // boolean
|
||||
milliseconds = 0; // uint16_t
|
||||
latitude = longitude = geoidheight = altitude =
|
||||
speed = angle = magvariation = HDOP = 0.0; // float
|
||||
speed = angle = magvariation = HDOP = VDOP = PDOP = 0.0; // float
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
|
|
@ -593,7 +723,7 @@ bool Adafruit_GPS::begin(uint32_t baud_or_i2caddr)
|
|||
#if (defined(__AVR__) || defined(ESP8266)) && defined(USE_SW_SERIAL)
|
||||
if(gpsSwSerial) {
|
||||
gpsSwSerial->begin(baud_or_i2caddr);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (gpsHwSerial) {
|
||||
gpsHwSerial->begin(baud_or_i2caddr);
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@
|
|||
#define PMTK_SET_NMEA_OUTPUT_GSAONLY "$PMTK314,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29" ///< turn on just the GPGSA
|
||||
#define PMTK_SET_NMEA_OUTPUT_GSVONLY "$PMTK314,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0*29" ///< turn on just the GPGSV
|
||||
#define PMTK_SET_NMEA_OUTPUT_RMCGGA "$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28" ///< turn on GPRMC and GPGGA
|
||||
#define PMTK_SET_NMEA_OUTPUT_RMCGGAGSA "$PMTK314,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29" ///< turn on GPRMC, GPGGA and GPGSA
|
||||
#define PMTK_SET_NMEA_OUTPUT_ALLDATA "$PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0*28" ///< turn on ALL THE DATA
|
||||
#define PMTK_SET_NMEA_OUTPUT_OFF "$PMTK314,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28" ///< turn off output
|
||||
|
||||
|
|
@ -159,11 +160,14 @@ class Adafruit_GPS : public Print{
|
|||
float angle; ///< Course in degrees from true north
|
||||
float magvariation; ///< Magnetic variation in degrees (vs. true north)
|
||||
float HDOP; ///< Horizontal Dilution of Precision - relative accuracy of horizontal position
|
||||
float VDOP; ///< Vertical Dilution of Precision - relative accuracy of vertical position
|
||||
float PDOP; ///< Position Dilution of Precision - Complex maths derives a simple, single number for each kind of DOP
|
||||
char lat; ///< N/S
|
||||
char lon; ///< E/W
|
||||
char mag; ///< Magnetic variation direction
|
||||
boolean fix; ///< Have a fix?
|
||||
uint8_t fixquality; ///< Fix quality (0, 1, 2 = Invalid, GPS, DGPS)
|
||||
uint8_t fixquality_3d; ///< 3D fix quality (1, 3, 3 = Nofix, 2D fix, 3D fix)
|
||||
uint8_t satellites; ///< Number of satellites in use
|
||||
|
||||
boolean waitForSentence(const char *wait, uint8_t max = MAXWAITSENTENCE, boolean usingInterrupts = false);
|
||||
|
|
@ -189,8 +193,8 @@ class Adafruit_GPS : public Print{
|
|||
void parseLon(char *);
|
||||
boolean parseLonDir(char *);
|
||||
boolean parseFix(char *);
|
||||
// Make all of these times far in the past by setting them near the middle of the
|
||||
// millis() range. Timing assumes that sentences are parsed promptly.
|
||||
// Make all of these times far in the past by setting them near the middle of the
|
||||
// millis() range. Timing assumes that sentences are parsed promptly.
|
||||
uint32_t lastFix = 2000000000L; // millis() when last fix received
|
||||
uint32_t lastTime = 2000000000L; // millis() when last time received
|
||||
uint32_t lastDate = 2000000000L; // millis() when last date received
|
||||
|
|
|
|||
Loading…
Reference in New Issue