24 #ifndef _ADAFRUIT_GPS_H 25 #define _ADAFRUIT_GPS_H 32 #ifndef NMEA_EXTRAS // inject on the compile command line to force extensions 33 #ifndef ARDUINO_ARCH_AVR 34 #define NMEA_EXTENSIONS 38 #define NMEA_EXTENSIONS 42 #if (defined(__AVR__) || ((defined(ARDUINO_UNOR4_WIFI) || defined(ESP8266)) && \ 43 !defined(NO_SW_SERIAL))) 47 #define GPS_DEFAULT_I2C_ADDR \ 49 #define GPS_MAX_I2C_TRANSFER \ 51 #define GPS_MAX_SPI_TRANSFER \ 53 #define MAXLINELENGTH 120 54 #define NMEA_MAX_SENTENCE_ID \ 56 #define NMEA_MAX_SOURCE_ID \ 61 #include <SoftwareSerial.h> 87 bool begin(uint32_t baud_or_i2caddr);
101 size_t write(uint8_t);
108 bool usingInterrupts =
false);
121 bool check(
char *nmea);
122 bool onList(
char *nmea,
const char **list);
126 #ifdef NMEA_EXTENSIONS 128 char ref =
'R',
bool noCRLF =
false);
134 #ifdef NMEA_EXTENSIONS 138 char *unit = NULL,
unsigned long response = 0,
142 unsigned historyInterval = 20,
143 unsigned historyN = 192);
217 #ifdef NMEA_EXTENSIONS 236 #endif // NMEA_EXTENSIONS 246 const char *tokenOnList(
char *token,
const char **list);
247 bool parseCoord(
char *p,
nmea_float_t *angleDegrees = NULL,
248 nmea_float_t *angle = NULL, int32_t *angle_fixed = NULL,
250 char *parseStr(
char *buff,
char *p,
int n);
251 bool parseTime(
char *);
252 bool parseFix(
char *);
253 bool parseAntenna(
char *);
254 bool isEmpty(
char *pStart);
257 const char *sources[7] = {
"II",
"WI",
"GP",
"PG",
259 #ifdef NMEA_EXTENSIONS 260 const char *sentences_parsed[21] = {
"GGA",
"GLL",
"GSA",
"RMC",
"DBT",
"HDM",
261 "HDT",
"MDA",
"MTW",
"MWV",
"RMB",
"TOP",
262 "TXT",
"VHW",
"VLW",
"VPW",
"VWR",
"WCV",
264 const char *sentences_known[15] = {
265 "APB",
"DPT",
"GSV",
"HDG",
"MWD",
"ROT",
266 "RPM",
"RSA",
"VDR",
"VTG",
"ZDA",
"ZZZ"};
267 #else // make the lists short to save memory 268 const char *sentences_parsed[6] = {
"GGA",
"GLL",
"GSA",
"RMC",
270 const char *sentences_known[4] = {
"DBT",
"HDM",
"HDT",
276 uint32_t lastUpdate =
278 uint32_t lastFix = 2000000000L;
279 uint32_t lastTime = 2000000000L;
280 uint32_t lastDate = 2000000000L;
283 uint32_t sentTime = 2000000000L;
287 uint8_t parseResponse(
char *response);
289 SoftwareSerial *gpsSwSerial;
291 bool noComms =
false;
292 HardwareSerial *gpsHwSerial;
296 int8_t gpsSPI_cs = -1;
297 SPISettings gpsSPI_settings =
298 SPISettings(1000000, MSBFIRST, SPI_MODE0);
303 int8_t _buff_max = -1, _buff_idx = 0;
309 volatile uint8_t lineidx = 0;
310 volatile char *currentline;
311 volatile char *lastline;
312 volatile bool recvdflag;
313 volatile bool inStandbyMode;
nmea_float_t PDOP
Definition: Adafruit_GPS.h:195
Definition: NMEA_data.h:51
void showDataValue(nmea_index_t idx, int n=7)
Print out the current state of a data value. Primarily useful as a debugging aid. ...
Definition: NMEA_data.cpp:439
void pause(bool b)
Pause/unpause receiving new data.
Definition: Adafruit_GPS.cpp:409
#define NMEA_MAX_SENTENCE_ID
maximum length of a sentence ID name, including terminating 0
Definition: Adafruit_GPS.h:54
bool onList(char *nmea, const char **list)
Check if an NMEA string is valid and is on a list, perhaps to decide if it should be passed to a part...
Definition: NMEA_parse.cpp:645
nmea_float_t angle
Course in degrees from true north.
Definition: Adafruit_GPS.h:189
int txtN
the TXT sentence number
Definition: Adafruit_GPS.h:235
uint8_t day
GMT day.
Definition: Adafruit_GPS.h:169
nmea_float_t speed
Current speed over ground in knots.
Definition: Adafruit_GPS.h:188
uint8_t minute
GMT minutes.
Definition: Adafruit_GPS.h:164
nmea_float_t HDOP
Definition: Adafruit_GPS.h:191
void removeHistory(nmea_index_t idx)
Remove history from a data value table entry, if it has been added.
Definition: NMEA_data.cpp:420
has a recognized source ID
Definition: Adafruit_GPS.h:75
char txtTXT[63]
text content from most recent TXT sentence
Definition: Adafruit_GPS.h:232
uint8_t LOCUS_percent
Log life used percentage.
Definition: Adafruit_GPS.h:215
uint8_t year
GMT year.
Definition: Adafruit_GPS.h:167
bool fix
Have a fix?
Definition: Adafruit_GPS.h:200
char lat
N/S.
Definition: Adafruit_GPS.h:197
Definition: NMEA_data.h:96
void addChecksum(char *buff)
Add *CS where CS is the two character hex checksum for all but the first character in the string...
Definition: NMEA_build.cpp:594
uint8_t LOCUS_distance
Distance setting.
Definition: Adafruit_GPS.h:212
int32_t latitude_fixed
Definition: Adafruit_GPS.h:179
Adafruit_GPS()
Constructor when there are no communications attached.
Definition: Adafruit_GPS.cpp:141
uint8_t seconds
GMT seconds.
Definition: Adafruit_GPS.h:165
bool wakeup(void)
Wake the sensor up.
Definition: Adafruit_GPS.cpp:552
bool waitForSentence(const char *wait, uint8_t max=MAXWAITSENTENCE, bool usingInterrupts=false)
Wait for a specified sentence from the device.
Definition: Adafruit_GPS.cpp:432
passed none of the checks
Definition: Adafruit_GPS.h:70
char * lastNMEA(void)
Returns the last NMEA line received and unsets the received flag.
Definition: Adafruit_GPS.cpp:417
void common_init(void)
Initialization code used by all constructor types.
Definition: Adafruit_GPS.cpp:151
uint8_t LOCUS_config
Contents of configuration.
Definition: Adafruit_GPS.h:210
nmea_float_t depthToKeel
depth from surface to bottom of keel in metres
Definition: Adafruit_GPS.h:222
nmea_float_t boatAngle(nmea_float_t s, nmea_float_t c)
Estimate a direction in -180 to 180 degree range from the values of the sine and cosine of the compou...
Definition: NMEA_data.cpp:515
nmea_history_t * initHistory(nmea_index_t idx, nmea_float_t scale=10.0, nmea_float_t offset=0.0, unsigned historyInterval=20, unsigned historyN=192)
Attempt to add history to a data value table entry. If it fails to malloc the space, history will not be added. Test the pointer for a check if needed. Select scale and offset values carefully so that operations and results will fit inside 16 bit integer limits. For example a scale of 1.0 and an offset of 100000.0 would be a good choice for atmospheric pressure in Pa with values ranging ~ +/- 3500, while a scale of 10.0 would be pushing the integer limits.
Definition: NMEA_data.cpp:379
size_t available(void)
How many bytes are available to read - part of 'Print'-class functionality.
Definition: Adafruit_GPS.cpp:198
has a recognized sentence ID
Definition: Adafruit_GPS.h:76
char * build(char *nmea, const char *thisSource, const char *thisSentence, char ref='R', bool noCRLF=false)
Build an NMEA sentence string based on the relevant variables. Sentences start with a $...
Definition: NMEA_build.cpp:68
uint8_t LOCUS_type
Log type, 0: Overlap, 1: FullStop.
Definition: Adafruit_GPS.h:208
has a recognized parseable sentence ID
Definition: Adafruit_GPS.h:77
int thisCheck
the results of the check on the current sentence
Definition: Adafruit_GPS.h:151
char thisSource[NMEA_MAX_SOURCE_ID]
the first two letters of the current sentence, e.g. WI, GP
Definition: Adafruit_GPS.h:152
nmea_float_t secondsSinceFix()
Time in seconds since the last position fix was obtained. The time returned is limited to 2^32 millis...
Definition: Adafruit_GPS.cpp:571
bool LOCUS_StopLogger(void)
Stop the LOCUS logger.
Definition: Adafruit_GPS.cpp:469
bool isCompoundAngle(nmea_index_t idx)
Check if it is a compound angle.
Definition: NMEA_data.cpp:500
#define GPS_MAX_SPI_TRANSFER
The max number of bytes we'll try to read at once.
Definition: Adafruit_GPS.h:51
Definition: NMEA_data.h:190
uint8_t fixquality_3d
3D fix quality (1, 3, 3 = Nofix, 2D fix, 3D fix)
Definition: Adafruit_GPS.h:202
char mag
Magnetic variation direction.
Definition: Adafruit_GPS.h:199
uint8_t hour
GMT hours.
Definition: Adafruit_GPS.h:163
The GPS class.
Definition: Adafruit_GPS.h:84
nmea_float_t magvariation
Magnetic variation in degrees (vs. true north)
Definition: Adafruit_GPS.h:190
nmea_float_t depthToTransducer
depth of transducer below the surface in metres
Definition: Adafruit_GPS.h:224
int txtID
id of the text message
Definition: Adafruit_GPS.h:234
bool begin(uint32_t baud_or_i2caddr)
Start the HW or SW serial port.
Definition: Adafruit_GPS.cpp:42
nmea_float_t secondsSinceTime()
Time in seconds since the last GPS time was obtained. The time returned is limited to 2^32 millisecon...
Definition: Adafruit_GPS.cpp:583
int txtTot
total TXT sentences in group
Definition: Adafruit_GPS.h:233
uint8_t LOCUS_status
0: Logging, 1: Stop logging
Definition: Adafruit_GPS.h:214
nmea_float_t longitude
Definition: Adafruit_GPS.h:173
virtual ~Adafruit_GPS()
Destroy the object.
Definition: Adafruit_GPS.cpp:184
void newDataValue(nmea_index_t tag, nmea_float_t v)
Update the value and history information with a new value. Call whenever a new data value is received...
Definition: NMEA_data.cpp:44
nmea_float_t altitude
Altitude in meters above MSL.
Definition: Adafruit_GPS.h:187
uint8_t antenna
Antenna that is used (from PGTOP)
Definition: Adafruit_GPS.h:204
nmea_index_t
Definition: NMEA_data.h:121
uint8_t LOCUS_interval
Interval setting.
Definition: Adafruit_GPS.h:211
has a valid checksum at the end
Definition: Adafruit_GPS.h:73
bool standby(void)
Standby Mode Switches.
Definition: Adafruit_GPS.cpp:533
#define MAXWAITSENTENCE
how long to wait when we're looking for a response
Definition: Adafruit_PMTK.h:113
nmea_datavalue_t val[NMEA_MAX_INDEX]
Definition: Adafruit_GPS.h:220
uint8_t satellites
Number of satellites in use.
Definition: Adafruit_GPS.h:203
bool check(char *nmea)
Check an NMEA string for basic format, valid source ID and valid and valid sentence ID...
Definition: NMEA_parse.cpp:561
#define NMEA_MAX_SOURCE_ID
maximum length of a source ID name, including terminating 0
Definition: Adafruit_GPS.h:56
bool parse(char *)
Parse a standard NMEA string and update the relevant variables. Sentences start with a $...
Definition: NMEA_parse.cpp:51
nmea_float_t latitudeDegrees
Latitude in decimal degrees.
Definition: Adafruit_GPS.h:184
nmea_float_t secondsSinceDate()
Time in seconds since the last GPS date was obtained. The time returned is limited to 2^32 millisecon...
Definition: Adafruit_GPS.cpp:595
void resetSentTime()
Fakes time of receipt of a sentence. Use between build() and parse() to make the timing look like the...
Definition: Adafruit_GPS.cpp:605
bool newNMEAreceived()
Check to see if a new NMEA line has been received.
Definition: Adafruit_GPS.cpp:401
uint8_t LOCUS_speed
Speed setting.
Definition: Adafruit_GPS.h:213
#define MAXLINELENGTH
how long are max NMEA lines to parse?
Definition: Adafruit_GPS.h:53
uint8_t parseHex(char c)
Parse a hex character and return the appropriate decimal value.
Definition: NMEA_parse.cpp:866
bool LOCUS_ReadStatus(void)
Read the logger status.
Definition: Adafruit_GPS.cpp:481
size_t write(uint8_t)
Write a byte to the underlying transport - part of 'Print'-class functionality.
Definition: Adafruit_GPS.cpp:229
nmea_check_t
type for resulting code from running check()
Definition: Adafruit_GPS.h:69
nmea_float_t latitude
Definition: Adafruit_GPS.h:171
uint16_t LOCUS_records
Log number of data record.
Definition: Adafruit_GPS.h:207
char fromID[NMEA_MAX_WP_ID]
id of waypoint coming from on this segment of the route
Definition: Adafruit_GPS.h:229
uint8_t LOCUS_mode
Logging mode, 0x08 interval logger.
Definition: Adafruit_GPS.h:209
char thisSentence[NMEA_MAX_SENTENCE_ID]
the next three letters of the current sentence, e.g. GLL, RMC
Definition: Adafruit_GPS.h:154
has a dollar sign or exclamation mark in the first position
Definition: Adafruit_GPS.h:71
#define GPS_MAX_I2C_TRANSFER
The max number of bytes we'll try to read at once.
Definition: Adafruit_GPS.h:49
nmea_float_t compassAngle(nmea_float_t s, nmea_float_t c)
Estimate a direction in 0 to 360 degree range from the values of the sine and cosine of the compound ...
Definition: NMEA_data.cpp:556
nmea_float_t longitudeDegrees
Longitude in decimal degrees.
Definition: Adafruit_GPS.h:185
uint16_t milliseconds
GMT milliseconds.
Definition: Adafruit_GPS.h:166
uint8_t month
GMT month.
Definition: Adafruit_GPS.h:168
void initDataValue(nmea_index_t idx, char *label=NULL, char *fmt=NULL, char *unit=NULL, unsigned long response=0, nmea_value_type_t type=NMEA_SIMPLE_FLOAT)
Initialize the contents of a data value table entry.
Definition: NMEA_data.cpp:338
nmea_value_type_t
Definition: NMEA_data.h:71
char lon
E/W.
Definition: Adafruit_GPS.h:198
bool LOCUS_StartLogger(void)
Start the LOCUS logger.
Definition: Adafruit_GPS.cpp:457
nmea_float_t getSmoothed(nmea_index_t idx)
Clearer approach to retrieving NMEA values.
Definition: NMEA_data.cpp:317
uint8_t fixquality
Fix quality (0, 1, 2 = Invalid, GPS, DGPS)
Definition: Adafruit_GPS.h:201
nmea_float_t geoidheight
Diff between geoid height and WGS84 height.
Definition: Adafruit_GPS.h:186
uint16_t LOCUS_serial
Log serial number.
Definition: Adafruit_GPS.h:206
int32_t longitude_fixed
Definition: Adafruit_GPS.h:181
char lastSource[NMEA_MAX_SOURCE_ID]
Definition: Adafruit_GPS.h:156
char read(void)
Read one character from the GPS device.
Definition: Adafruit_GPS.cpp:279
char lastSentence[NMEA_MAX_SENTENCE_ID]
Definition: Adafruit_GPS.h:159
#define NMEA_MAX_WP_ID
maximum length of a waypoint ID name, including terminating 0
Definition: NMEA_data.h:10
void sendCommand(const char *)
Send a command to the GPS device.
Definition: Adafruit_GPS.cpp:393
A simple floating point number.
Definition: NMEA_data.h:72
nmea_float_t VDOP
Definition: Adafruit_GPS.h:193
NMEA_FLOAT_T nmea_float_t
the type of variables to use for floating point
Definition: NMEA_data.h:35
there is a token after the $ followed by a comma
Definition: Adafruit_GPS.h:74
char toID[NMEA_MAX_WP_ID]
id of waypoint going to on this segment of the route
Definition: Adafruit_GPS.h:227