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

@ -30,13 +30,13 @@
little memory as possible for GPS functionality only. The ARDUINO_ARCH_AVR
test should leave it out of any compilations for the UNO and similar. */
#ifndef NMEA_EXTRAS // inject on the compile command line to force extensions
#ifndef ARDUINO_ARCH_AVR
#define NMEA_EXTENSIONS ///< if defined will include more NMEA sentences
#endif
#ifndef ARDUINO_ARCH_AVR
#define NMEA_EXTENSIONS ///< if defined will include more NMEA sentences
#endif
#else
#if(NMEA_EXTRAS > 0)
#define NMEA_EXTENSIONS ///< if defined will include more NMEA sentences
#endif
#if(NMEA_EXTRAS > 0)
#define NMEA_EXTENSIONS ///< if defined will include more NMEA sentences
#endif
#endif
#define USE_SW_SERIAL ///< comment this out if you don't want to include
@ -64,8 +64,9 @@
/// 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_BAD = 0, ///< passed none of the checks
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
@ -100,7 +101,7 @@ public:
void pause(bool b);
char *lastNMEA(void);
bool waitForSentence(const char *wait, uint8_t max = MAXWAITSENTENCE,
bool usingInterrupts = false);
bool usingInterrupts = false);
bool LOCUS_StartLogger(void);
bool LOCUS_StopLogger(void);
bool LOCUS_ReadStatus(void);
@ -229,10 +230,10 @@ public:
#endif // NMEA_EXTENSIONS
private:
// void parseLat(char *);
// bool parseLatDir(char *);
// void parseLon(char *);
// bool parseLonDir(char *);
// void parseLat(char *);
// bool parseLatDir(char *);
// void parseLon(char *);
// bool parseLonDir(char *);
// NMEA_data.cpp
void data_init();
// NMEA_parse.cpp
@ -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,8 +460,9 @@ 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);
i--) { // most recent first
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]);
}
@ -471,7 +474,7 @@ void Adafruit_GPS::showDataValue(nmea_index_t idx, int n) {
Serial.print(", lat: ");
Serial.print(lat);
Serial.print(", latitudeDegrees: ");
Serial.print(latitudeDegrees,8);
Serial.print(latitudeDegrees, 8);
Serial.print(", latitude_fixed: ");
Serial.println(latitude_fixed);
}
@ -481,7 +484,7 @@ void Adafruit_GPS::showDataValue(nmea_index_t idx, int n) {
Serial.print(", lon: ");
Serial.print(lon);
Serial.print(", longitudeDegrees: ");
Serial.print(longitudeDegrees,8);
Serial.print(longitudeDegrees, 8);
Serial.print(", longitude_fixed: ");
Serial.println(longitude_fixed);
}

View File

@ -674,7 +674,7 @@ bool Adafruit_GPS::parseCoord(char *pStart, nmea_float_t *angleDegrees,
long minutes = dddmm - degrees * 100; // remove the degrees
p = e; // start from the decimal point
nmea_float_t decminutes = atof(e); // the fraction after the decimal point
p = strchr(p, ',') + 1; // go to the next field
p = strchr(p, ',') + 1; // go to the next field
// get the NSEW direction as a character
char nsew = 'X';
@ -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)