clanged files
This commit is contained in:
parent
a41cbce062
commit
c8d4e037e7
|
|
@ -205,12 +205,21 @@ boolean Adafruit_GPS::parse(char *nmea) {
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef NMEA_EXTENSIONS //********************************************Sentences not required for basic GPS functionality
|
||||
else if (!strcmp(thisSentence,"TXT")){ //********************************************TXT
|
||||
if (!isEmpty(p)) txtTot = atoi(p); p = strchr(p, ',')+1;
|
||||
if (!isEmpty(p)) txtN = atoi(p); p = strchr(p, ',')+1;
|
||||
if (!isEmpty(p)) txtID = atoi(p); p = strchr(p, ',')+1;
|
||||
if (!isEmpty(p)) parseStr(txtTXT,p,61); // copy the text to NMEA TXT max of 61 characters
|
||||
#ifdef NMEA_EXTENSIONS //********************************************Sentences
|
||||
//not required for basic GPS functionality
|
||||
else if (!strcmp(thisSentence,
|
||||
"TXT")) { //********************************************TXT
|
||||
if (!isEmpty(p))
|
||||
txtTot = atoi(p);
|
||||
p = strchr(p, ',') + 1;
|
||||
if (!isEmpty(p))
|
||||
txtN = atoi(p);
|
||||
p = strchr(p, ',') + 1;
|
||||
if (!isEmpty(p))
|
||||
txtID = atoi(p);
|
||||
p = strchr(p, ',') + 1;
|
||||
if (!isEmpty(p))
|
||||
parseStr(txtTXT, p, 61); // copy the text to NMEA TXT max of 61 characters
|
||||
}
|
||||
#endif // NMEA_EXTENSIONS
|
||||
|
||||
|
|
@ -346,8 +355,10 @@ char * Adafruit_GPS::parseStr(char * buff, char *p, int n) {
|
|||
*/
|
||||
/**************************************************************************/
|
||||
bool Adafruit_GPS::isEmpty(char *pStart) {
|
||||
if (',' != *pStart && '*' != *pStart && pStart != NULL) return false;
|
||||
else return true;
|
||||
if (',' != *pStart && '*' != *pStart && pStart != NULL)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
|
|
@ -1044,9 +1055,7 @@ static boolean strStartsWith(const char *str, const char *prefix) {
|
|||
to make the timing look like the sentence arrived from the GPS.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_GPS::resetSentTime(){
|
||||
sentTime = millis();
|
||||
}
|
||||
void Adafruit_GPS::resetSentTime() { sentTime = millis(); }
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
|
|
@ -1081,20 +1090,28 @@ void Adafruit_GPS::resetSentTime(){
|
|||
@return Pointer to sentence if successful, NULL if fails
|
||||
*/
|
||||
/**************************************************************************/
|
||||
char * Adafruit_GPS::build(char *nmea, const char *thisSource, const char *thisSentence, char ref) {
|
||||
char *Adafruit_GPS::build(char *nmea, const char *thisSource,
|
||||
const char *thisSentence, char ref) {
|
||||
sprintf(nmea, "%6.2f", 123.45); // fail if sprintf() doesn't handle floats
|
||||
if(strcmp(nmea,"123.45")) return NULL;
|
||||
if (strcmp(nmea, "123.45"))
|
||||
return NULL;
|
||||
*nmea = '$';
|
||||
char *p = nmea + 1; // Pointer to move through the sentence
|
||||
strncpy(p,thisSource,strlen(thisSource)); p += strlen(thisSource);
|
||||
strncpy(p,thisSentence,strlen(thisSentence)); p += strlen(thisSentence);
|
||||
*p = ','; p += 1; //Now $XXSSS, and need to add argument fields
|
||||
// This may look inefficient, but an M0 will get down the list in about 1 us / strcmp()!
|
||||
// Put the GPS sentences from Adafruit_GPS at the top to make pruning excess code easier.
|
||||
// Otherwise, keep them alphabetical for ease of reading.
|
||||
strncpy(p, thisSource, strlen(thisSource));
|
||||
p += strlen(thisSource);
|
||||
strncpy(p, thisSentence, strlen(thisSentence));
|
||||
p += strlen(thisSentence);
|
||||
*p = ',';
|
||||
p += 1; // Now $XXSSS, and need to add argument fields
|
||||
// This may look inefficient, but an M0 will get down the list in about 1 us /
|
||||
// strcmp()! Put the GPS sentences from Adafruit_GPS at the top to make
|
||||
// pruning excess code easier. Otherwise, keep them alphabetical for ease of
|
||||
// reading.
|
||||
|
||||
if (!strcmp(thisSentence,"GGA")){ //********************************************GGA
|
||||
//GGA Global Positioning System Fix Data. Time, Position and fix related data for a GPS receiver
|
||||
if (!strcmp(thisSentence,
|
||||
"GGA")) { //********************************************GGA
|
||||
// GGA Global Positioning System Fix Data. Time, Position and fix related
|
||||
// data for a GPS receiver
|
||||
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
||||
// | | | | | | | | | | | | | | |
|
||||
//$--GGA,hhmmss.ss,ddmm.mm,a,dddmm.mm,a,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx*hh
|
||||
|
|
@ -1103,22 +1120,25 @@ char * Adafruit_GPS::build(char *nmea, const char *thisSource, const char *thisS
|
|||
// 3) N or S (North or South)
|
||||
// 4) Longitude
|
||||
// 5) E or W (East or West)
|
||||
//6) GPS Quality Indicator, 0 - fix not available, 1 - GPS fix, 2 - Differential GPS fix
|
||||
//7) Number of satellites in view, 00 - 12
|
||||
//8) Horizontal Dilution of precision
|
||||
//9) Antenna Altitude above/below mean-sea-level (geoid)
|
||||
//10) Units of antenna altitude, meters
|
||||
//11) Geoidal separation, the difference between the WGS-84 earth
|
||||
// ellipsoid and mean-sea-level (geoid), "-" means mean-sea-level below ellipsoid
|
||||
// 6) GPS Quality Indicator, 0 - fix not available, 1 - GPS fix, 2 -
|
||||
// Differential GPS fix 7) Number of satellites in view, 00 - 12 8)
|
||||
// Horizontal Dilution of precision 9) Antenna Altitude above/below
|
||||
// mean-sea-level (geoid) 10) Units of antenna altitude, meters 11) Geoidal
|
||||
// separation, the difference between the WGS-84 earth
|
||||
// ellipsoid and mean-sea-level (geoid), "-" means mean-sea-level below
|
||||
// ellipsoid
|
||||
// 12) Units of geoidal separation, meters
|
||||
// 13) Age of differential GPS data, time in seconds since last SC104
|
||||
// type 1 or 9 update, null field when DGPS is not used
|
||||
// 14) Differential reference station ID, 0000-1023
|
||||
// 15) Checksum
|
||||
sprintf(p,"%09.2f,%09.4f,%c,%010.4f,%c,%d,%02d,%f,%f,M,%f,M,,",hour*10000L + minute*100L + seconds + milliseconds/1000.,
|
||||
latitude,lat,longitude,lon,fixquality,satellites,HDOP,altitude,geoidheight);
|
||||
sprintf(p, "%09.2f,%09.4f,%c,%010.4f,%c,%d,%02d,%f,%f,M,%f,M,,",
|
||||
hour * 10000L + minute * 100L + seconds + milliseconds / 1000.,
|
||||
latitude, lat, longitude, lon, fixquality, satellites, HDOP,
|
||||
altitude, geoidheight);
|
||||
|
||||
} else if (!strcmp(thisSentence,"GLL")){ //********************************************GLL
|
||||
} else if (!strcmp(thisSentence,
|
||||
"GLL")) { //********************************************GLL
|
||||
// GLL Geographic Position – Latitude/Longitude
|
||||
// 1 2 3 4 5 6 7
|
||||
// | | | | | | |
|
||||
|
|
@ -1130,9 +1150,11 @@ char * Adafruit_GPS::build(char *nmea, const char *thisSource, const char *thisS
|
|||
// 5) Time (UTC)
|
||||
// 6) Status A - Data Valid, V - Data Invalid
|
||||
// 7) Checksum
|
||||
sprintf(p,"%09.4f,%c,%010.4f,%c,%09.2f,A",latitude,lat,longitude,lon,hour*10000L + minute*100L + seconds + milliseconds/1000.);
|
||||
sprintf(p, "%09.4f,%c,%010.4f,%c,%09.2f,A", latitude, lat, longitude, lon,
|
||||
hour * 10000L + minute * 100L + seconds + milliseconds / 1000.);
|
||||
|
||||
} else if (!strcmp(thisSentence,"GSA")){ //********************************************
|
||||
} else if (!strcmp(thisSentence,
|
||||
"GSA")) { //********************************************
|
||||
// GSA GPS DOP and active satellites
|
||||
// 1 2 3 14 15 16 17 18
|
||||
// | | | | | | | |
|
||||
|
|
@ -1149,7 +1171,8 @@ char * Adafruit_GPS::build(char *nmea, const char *thisSource, const char *thisS
|
|||
// 18) Checksum
|
||||
return NULL;
|
||||
|
||||
} else if (!strcmp(thisSentence,"RMC")){ //********************************************RMC
|
||||
} else if (!strcmp(thisSentence,
|
||||
"RMC")) { //********************************************RMC
|
||||
// RMC Recommended Minimum Navigation Information
|
||||
// 12
|
||||
// 1 2 3 4 5 6 7 8 9 10 11 |
|
||||
|
|
@ -1167,10 +1190,13 @@ char * Adafruit_GPS::build(char *nmea, const char *thisSource, const char *thisS
|
|||
// 10) Magnetic Variation, degrees
|
||||
// 11) E or W
|
||||
// 12) Checksum
|
||||
sprintf(p,"%09.2f,A,%09.4f,%c,%010.4f,%c,%f,%f,%06d,%f,%c",hour*10000L + minute*100L + seconds + milliseconds/1000.,
|
||||
latitude,lat,longitude,lon,speed,angle,day*10000+month*100+year,magvariation,mag);
|
||||
sprintf(p, "%09.2f,A,%09.4f,%c,%010.4f,%c,%f,%f,%06d,%f,%c",
|
||||
hour * 10000L + minute * 100L + seconds + milliseconds / 1000.,
|
||||
latitude, lat, longitude, lon, speed, angle,
|
||||
day * 10000 + month * 100 + year, magvariation, mag);
|
||||
|
||||
} else if (!strcmp(thisSentence,"TXT")){ //********************************************TXT
|
||||
} else if (!strcmp(thisSentence,
|
||||
"TXT")) { //********************************************TXT
|
||||
// as mentioned in https://github.com/adafruit/Adafruit_GPS/issues/95
|
||||
// TXT Text Transmission
|
||||
// 1 2 3 4 5
|
||||
|
|
@ -1188,7 +1214,8 @@ char * Adafruit_GPS::build(char *nmea, const char *thisSource, const char *thisS
|
|||
}
|
||||
|
||||
addChecksum(nmea); // Successful completion
|
||||
sprintf(nmea,"%s\r\n",nmea); // Add Carriage Return and Line Feed to comply with NMEA-183
|
||||
sprintf(nmea, "%s\r\n",
|
||||
nmea); // Add Carriage Return and Line Feed to comply with NMEA-183
|
||||
return nmea; // return pointer to finished product
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -268,7 +268,8 @@ public:
|
|||
|
||||
#ifdef NMEA_EXTENSIONS
|
||||
// NMEA additional public functions
|
||||
char * build(char *nmea, const char *thisSource, const char *thisSentence, char ref = 'R');
|
||||
char *build(char *nmea, const char *thisSource, const char *thisSentence,
|
||||
char ref = 'R');
|
||||
void resetSentTime();
|
||||
|
||||
// NMEA additional public variables
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
// Test code for Ultimate GPS Using Hardware Serial (e.g. GPS Flora or FeatherWing)
|
||||
// Test code for Ultimate GPS Using Hardware Serial (e.g. GPS Flora or
|
||||
// FeatherWing)
|
||||
//
|
||||
// This code is similar to GPS_HardwareSerial_Parsing, except for the additional
|
||||
// elements to keep track of how long it has been since time and fix data have been
|
||||
// received. This approach lets you keep an up to date clock based on GPS time at
|
||||
// any time in between GPS fixes.
|
||||
// elements to keep track of how long it has been since time and fix data have
|
||||
// been received. This approach lets you keep an up to date clock based on GPS
|
||||
// time at any time in between GPS fixes.
|
||||
//
|
||||
// It also shows how to take advantage of the build() function to generate test sentences.
|
||||
// The additional code is within #ifdef NMEA_EXTENSIONS and #endif tags.
|
||||
// It also shows how to take advantage of the build() function to generate test
|
||||
// sentences. The additional code is within #ifdef NMEA_EXTENSIONS and #endif
|
||||
// tags.
|
||||
//
|
||||
// This code shows how to listen to the GPS module via polling. Best used with
|
||||
// Feathers or Flora where you have hardware Serial and no interrupt
|
||||
|
|
@ -31,9 +33,9 @@
|
|||
Adafruit_GPS GPS(&GPSSerial);
|
||||
|
||||
#ifdef NMEA_EXTENSIONS
|
||||
// Create another GPS object to hold the state of the boat, with no communications,
|
||||
// so don't call Boat.begin() in setup.
|
||||
// We will build some fake sentences from the Boat data to feed to GPS for testing.
|
||||
// Create another GPS object to hold the state of the boat, with no
|
||||
// communications, so don't call Boat.begin() in setup. We will build some fake
|
||||
// sentences from the Boat data to feed to GPS for testing.
|
||||
Adafruit_GPS Boat(&GPSSerial);
|
||||
#endif
|
||||
|
||||
|
|
@ -43,30 +45,31 @@ Adafruit_GPS Boat(&GPSSerial);
|
|||
|
||||
uint32_t timer = millis();
|
||||
|
||||
void setup() {
|
||||
// while (!Serial); // uncomment to have the sketch wait until Serial is
|
||||
// ready
|
||||
|
||||
void setup()
|
||||
{
|
||||
//while (!Serial); // uncomment to have the sketch wait until Serial is ready
|
||||
|
||||
// connect at 115200 so we can read the GPS fast enough and echo without dropping chars
|
||||
// also spit it out
|
||||
// connect at 115200 so we can read the GPS fast enough and echo without
|
||||
// dropping chars also spit it out
|
||||
Serial.begin(115200);
|
||||
Serial.println("Adafruit GPS library basic test!");
|
||||
|
||||
// 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
|
||||
GPS.begin(9600);
|
||||
// uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
|
||||
// uncomment this line to turn on RMC (recommended minimum) and GGA (fix data)
|
||||
// including altitude
|
||||
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
|
||||
// uncomment this line to turn on only the "minimum recommended" data
|
||||
// GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
|
||||
// For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
|
||||
// the parser doesn't care about other sentences at this time
|
||||
// For parsing data, we don't suggest using anything but either RMC only or
|
||||
// RMC+GGA since the parser doesn't care about other sentences at this time
|
||||
// Set the update rate (uncomment the one you want.)
|
||||
// GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
|
||||
//GPS.sendCommand(PMTK_SET_NMEA_UPDATE_200_MILLIHERTZ); // 5 second update time
|
||||
// GPS.sendCommand(PMTK_SET_NMEA_UPDATE_200_MILLIHERTZ); // 5 second update
|
||||
// time
|
||||
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_100_MILLIHERTZ); // 10 second update time
|
||||
// For the parsing code to work nicely and have time to sort thru the data, and
|
||||
// print it out we don't suggest using anything higher than 1 Hz
|
||||
// For the parsing code to work nicely and have time to sort thru the data,
|
||||
// and print it out we don't suggest using anything higher than 1 Hz
|
||||
|
||||
// Request updates on antenna status, comment out to keep quiet
|
||||
GPS.sendCommand(PGCMD_ANTENNA);
|
||||
|
|
@ -83,20 +86,26 @@ void loop() // run over and over again
|
|||
char c = GPS.read();
|
||||
// if you want to debug, this is a good time to do it!
|
||||
if (GPSECHO)
|
||||
if (c) Serial.print(c);
|
||||
if (c)
|
||||
Serial.print(c);
|
||||
// if a sentence is received, we can check the checksum, parse it...
|
||||
if (GPS.newNMEAreceived()) {
|
||||
// a tricky thing here is if we print the NMEA sentence, or data
|
||||
// we end up not listening and catching other sentences!
|
||||
// so be very wary if using OUTPUT_ALLDATA and trytng to print out data
|
||||
//Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
|
||||
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
|
||||
return; // we can fail to parse a sentence in which case we should just wait for another
|
||||
// Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived()
|
||||
// flag to false
|
||||
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag
|
||||
// to false
|
||||
return; // we can fail to parse a sentence in which case we should just
|
||||
// wait for another
|
||||
}
|
||||
// if millis() or timer wraps around, we'll just reset it
|
||||
if (timer > millis()) timer = millis();
|
||||
if (timer > millis())
|
||||
timer = millis();
|
||||
|
||||
// approximately every 2 seconds or so, random intervals, print out the current stats
|
||||
// approximately every 2 seconds or so, random intervals, print out the
|
||||
// current stats
|
||||
static unsigned nextInterval = 2000;
|
||||
if (millis() - timer > nextInterval) {
|
||||
timer = millis(); // reset the timer
|
||||
|
|
@ -109,38 +118,68 @@ void loop() // run over and over again
|
|||
int h = GPS.hour;
|
||||
int d = GPS.day;
|
||||
// Adjust time and day forward to account for elapsed time.
|
||||
// This will break at month boundaries!!! Humans will have to cope with April 31,32 etc.
|
||||
while(s > 60){ s -= 60; m++; }
|
||||
while(m > 60){ m -= 60; h++; }
|
||||
while(h > 24){ h -= 24; d++; }
|
||||
// This will break at month boundaries!!! Humans will have to cope with
|
||||
// April 31,32 etc.
|
||||
while (s > 60) {
|
||||
s -= 60;
|
||||
m++;
|
||||
}
|
||||
while (m > 60) {
|
||||
m -= 60;
|
||||
h++;
|
||||
}
|
||||
while (h > 24) {
|
||||
h -= 24;
|
||||
d++;
|
||||
}
|
||||
// ISO Standard Date Format, with leading zeros https://xkcd.com/1179/
|
||||
Serial.print("\nDate: ");
|
||||
Serial.print(GPS.year+2000, DEC); Serial.print("-");
|
||||
if(GPS.month < 10) Serial.print("0");
|
||||
Serial.print(GPS.month, DEC); Serial.print("-");
|
||||
if(d < 10) Serial.print("0");
|
||||
Serial.print(GPS.year + 2000, DEC);
|
||||
Serial.print("-");
|
||||
if (GPS.month < 10)
|
||||
Serial.print("0");
|
||||
Serial.print(GPS.month, DEC);
|
||||
Serial.print("-");
|
||||
if (d < 10)
|
||||
Serial.print("0");
|
||||
Serial.print(d, DEC);
|
||||
Serial.print(" Time: ");
|
||||
if(h < 10) Serial.print("0");
|
||||
Serial.print(h, DEC); Serial.print(':');
|
||||
if(m < 10) Serial.print("0");
|
||||
Serial.print(m, DEC); Serial.print(':');
|
||||
if(s < 10) Serial.print("0");
|
||||
if (h < 10)
|
||||
Serial.print("0");
|
||||
Serial.print(h, DEC);
|
||||
Serial.print(':');
|
||||
if (m < 10)
|
||||
Serial.print("0");
|
||||
Serial.print(m, DEC);
|
||||
Serial.print(':');
|
||||
if (s < 10)
|
||||
Serial.print("0");
|
||||
Serial.println(s, 3);
|
||||
Serial.print("Fix: "); Serial.print((int)GPS.fix);
|
||||
Serial.print(" quality: "); Serial.println((int)GPS.fixquality);
|
||||
Serial.print("Time [s] since last fix: "); Serial.println(GPS.secondsSinceFix(),3);
|
||||
Serial.print(" since last GPS time: "); Serial.println(GPS.secondsSinceTime(),3);
|
||||
Serial.print(" since last GPS date: "); Serial.println(GPS.secondsSinceDate(),3);
|
||||
Serial.print("Fix: ");
|
||||
Serial.print((int)GPS.fix);
|
||||
Serial.print(" quality: ");
|
||||
Serial.println((int)GPS.fixquality);
|
||||
Serial.print("Time [s] since last fix: ");
|
||||
Serial.println(GPS.secondsSinceFix(), 3);
|
||||
Serial.print(" since last GPS time: ");
|
||||
Serial.println(GPS.secondsSinceTime(), 3);
|
||||
Serial.print(" since last GPS date: ");
|
||||
Serial.println(GPS.secondsSinceDate(), 3);
|
||||
if (GPS.fix) {
|
||||
Serial.print("Location: ");
|
||||
Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
|
||||
Serial.print(GPS.latitude, 4);
|
||||
Serial.print(GPS.lat);
|
||||
Serial.print(", ");
|
||||
Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
|
||||
Serial.print("Speed (knots): "); Serial.println(GPS.speed);
|
||||
Serial.print("Angle: "); Serial.println(GPS.angle);
|
||||
Serial.print("Altitude: "); Serial.println(GPS.altitude);
|
||||
Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
|
||||
Serial.print(GPS.longitude, 4);
|
||||
Serial.println(GPS.lon);
|
||||
Serial.print("Speed (knots): ");
|
||||
Serial.println(GPS.speed);
|
||||
Serial.print("Angle: ");
|
||||
Serial.println(GPS.angle);
|
||||
Serial.print("Altitude: ");
|
||||
Serial.println(GPS.altitude);
|
||||
Serial.print("Satellites: ");
|
||||
Serial.println((int)GPS.satellites);
|
||||
}
|
||||
#ifdef NMEA_EXTENSIONS
|
||||
char latestBoat[200] = "";
|
||||
|
|
@ -155,7 +194,8 @@ void loop() // run over and over again
|
|||
}
|
||||
|
||||
#ifdef NMEA_EXTENSIONS
|
||||
void updateBoat(){ //fill up the boat values with some test data to use in build()
|
||||
void updateBoat() { // fill up the boat values with some test data to use in
|
||||
// build()
|
||||
double t = millis() / 1000.;
|
||||
double theta = t / 100.; // slow
|
||||
double gamma = theta * 10; // faster
|
||||
|
|
|
|||
Loading…
Reference in New Issue