This commit is contained in:
Rick Sellens 2020-01-29 12:57:20 -05:00
parent 7d889e3a9d
commit 8ae6a7b75a
4 changed files with 60 additions and 50 deletions

View File

@ -65,7 +65,8 @@
/// type for resulting code from running check()
typedef enum {
NMEA_BAD = 0, ///< passed none of the checks
NMEA_HAS_DOLLAR = 1, ///< has a dollar sign or exclamation mark in the first position
NMEA_HAS_DOLLAR =
1, ///< has a dollar sign or exclamation mark in the first position
NMEA_HAS_CHECKSUM = 2, ///< has a valid checksum at the end
NMEA_HAS_NAME = 4, ///< there is a token after the $ followed by a comma
NMEA_HAS_SOURCE = 10, ///< has a recognized source ID
@ -246,8 +247,8 @@ private:
bool isEmpty(char *pStart);
// used by check() for validity tests, room for future expansion
const char *sources[6] = {"II", "WI", "GP", "GN",
"P", "ZZZ"}; ///< valid source ids
const char *sources[6] = {"II", "WI", "GP",
"GN", "P", "ZZZ"}; ///< valid source ids
#ifdef NMEA_EXTENSIONS
const char
*sentences_parsed[20] =
@ -260,11 +261,10 @@ private:
"RPM", "RSA", "VDR", "VTG", "ZDA", "ZZZ"}; ///< known, but not parseable
#else // make the lists short to save memory
const char
*sentences_parsed[5] =
{
"GGA", "GLL", "GSA", "RMC", "ZZZ"}; ///< parseable sentence ids
const char *sentences_known[4] = {
"DBT", "HDM", "HDT", "ZZZ"}; ///< known, but not parseable
*sentences_parsed[5] = {"GGA", "GLL", "GSA", "RMC",
"ZZZ"}; ///< parseable sentence ids
const char *sentences_known[4] = {"DBT", "HDM", "HDT",
"ZZZ"}; ///< known, but not parseable
#endif
// Make all of these times far in the past by setting them near the middle of

View File

@ -72,7 +72,8 @@
/**************************************************************************/
char *Adafruit_GPS::build(char *nmea, const char *thisSource,
const char *thisSentence, char ref) {
sprintf(nmea, "%6.2f", (double)123.45); // fail if sprintf() doesn't handle floats
sprintf(nmea, "%6.2f",
(double)123.45); // fail if sprintf() doesn't handle floats
if (strcmp(nmea, "123.45"))
return NULL;
*nmea = '$';
@ -112,9 +113,10 @@ char *Adafruit_GPS::build(char *nmea, const char *thisSource,
// 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,,",
(double)hour * 10000L + minute * 100L + seconds + milliseconds / 1000.,
(double)latitude, lat, (double)longitude, lon, fixquality, satellites,
(double)HDOP, (double)altitude, (double)geoidheight);
(double)hour * 10000L + minute * 100L + seconds +
milliseconds / 1000.,
(double)latitude, lat, (double)longitude, lon, fixquality,
satellites, (double)HDOP, (double)altitude, (double)geoidheight);
} else if (!strcmp(thisSentence, "GLL")) { //*****************************GLL
// GLL Geographic Position Latitude/Longitude
@ -129,8 +131,9 @@ char *Adafruit_GPS::build(char *nmea, const char *thisSource,
// 6) Status A - Data Valid, V - Data Invalid
// 7) Checksum
sprintf(p, "%09.4f,%c,%010.4f,%c,%09.2f,A", (double)latitude, lat,
(double)longitude, lon, (double)hour * 10000L + minute * 100L +
seconds + milliseconds / 1000.);
(double)longitude, lon,
(double)hour * 10000L + minute * 100L + seconds +
milliseconds / 1000.);
} else if (!strcmp(thisSentence, "GSA")) { //*****************************GSA
// GSA GPS DOP and active satellites
@ -168,9 +171,11 @@ char *Adafruit_GPS::build(char *nmea, const char *thisSource,
// 11) E or W
// 12) Checksum
sprintf(p, "%09.2f,A,%09.4f,%c,%010.4f,%c,%f,%f,%06d,%f,%c",
(double)hour * 10000L + minute * 100L + seconds + milliseconds / 1000.,
(double)hour * 10000L + minute * 100L + seconds +
milliseconds / 1000.,
(double)latitude, lat, (double)longitude, lon, (double)speed,
(double)angle, day * 10000 + month * 100 + year, (double)magvariation, mag);
(double)angle, day * 10000 + month * 100 + year,
(double)magvariation, mag);
} else if (!strcmp(thisSentence, "APB")) { //*****************************APB
// APB Autopilot Sentence "B"

View File

@ -58,8 +58,9 @@ void Adafruit_GPS::newDataValue(nmea_index_t idx, nmea_float_t v) {
newDataValue((nmea_index_t)(idx + 2), cos(v / RAD_TO_DEG));
}
// weighting factor for smoothing depends on delta t / tau
nmea_float_t w = min((nmea_float_t)1.0, ((nmea_float_t)millis() - val[idx].lastUpdate) /
val[idx].response);
nmea_float_t w =
min((nmea_float_t)1.0,
((nmea_float_t)millis() - val[idx].lastUpdate) / val[idx].response);
// default smoothing
val[idx].smoothed = (1.0 - w) * val[idx].smoothed + w * v;
// special smoothing for some angle types
@ -437,7 +438,8 @@ void Adafruit_GPS::removeHistory(nmea_index_t idx) {
/**************************************************************************/
void Adafruit_GPS::showDataValue(nmea_index_t idx, int n) {
Serial.print("idx: ");
if(idx < 10) Serial.print(" ");
if(idx < 10)
Serial.print(" ");
Serial.print(idx);
Serial.print(", ");
Serial.print(val[idx].label);
@ -458,7 +460,8 @@ void Adafruit_GPS::showDataValue(nmea_index_t idx, int n) {
Serial.print(val[idx].hist->historyInterval);
Serial.print(" second intervals: ");
Serial.print(val[idx].hist->data[val[idx].hist->n - 1]);
for (unsigned i = val[idx].hist->n - 2; i >= max(val[idx].hist->n - n, (unsigned)0);
for (unsigned i = val[idx].hist->n - 2;
i >= max(val[idx].hist->n - n, (unsigned)0);
i--) { // most recent first
Serial.print(", ");
Serial.print(val[idx].hist->data[i]);

View File

@ -700,8 +700,10 @@ bool Adafruit_GPS::parseCoord(char *pStart, nmea_float_t *angleDegrees,
// reject angles that are out of range
if (nsew == 'N' || nsew == 'S')
if(abs(deg) > 90) return false;
if(abs(deg) > 180) return false;
if(abs(deg) > 90)
return false;
if(abs(deg) > 180)
return false;
// store in locations passed as args
if (angle != NULL)