2019-03-12 21:21:45 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
|
|
|
|
@file Adafruit_GPS.cpp
|
2012-03-27 22:56:07 +01:00
|
|
|
|
2019-03-12 21:21:45 +00:00
|
|
|
@mainpage Adafruit Ultimate GPS Breakout
|
|
|
|
|
|
|
|
|
|
@section intro Introduction
|
|
|
|
|
|
|
|
|
|
This is the Adafruit GPS library - the ultimate GPS library
|
|
|
|
|
for the ultimate GPS module!
|
|
|
|
|
|
|
|
|
|
Tested and works great with the Adafruit Ultimate GPS module
|
|
|
|
|
using MTK33x9 chipset
|
|
|
|
|
------> http://www.adafruit.com/products/746
|
|
|
|
|
|
|
|
|
|
Adafruit invests time and resources providing this open source code,
|
|
|
|
|
please support Adafruit and open-source hardware by purchasing
|
|
|
|
|
products from Adafruit!
|
|
|
|
|
|
|
|
|
|
@section author Author
|
|
|
|
|
|
|
|
|
|
Written by Limor Fried/Ladyada for Adafruit Industries.
|
|
|
|
|
|
|
|
|
|
@section license License
|
|
|
|
|
|
|
|
|
|
BSD license, check license.txt for more information
|
|
|
|
|
All text above must be included in any redistribution
|
|
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
2012-03-27 22:56:07 +01:00
|
|
|
|
|
|
|
|
#include <Adafruit_GPS.h>
|
|
|
|
|
|
2020-01-19 20:10:10 +00:00
|
|
|
static bool strStartsWith(const char *str, const char *prefix);
|
2019-04-10 00:57:35 +01:00
|
|
|
|
2019-04-18 03:37:47 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
2020-01-29 17:03:25 +00:00
|
|
|
@brief Start the HW or SW serial port
|
|
|
|
|
@param baud_or_i2caddr Baud rate if using serial, I2C address if using I2C
|
|
|
|
|
@returns True on successful hardware init, False on failure
|
2019-04-18 03:37:47 +01:00
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
2020-01-29 17:03:25 +00:00
|
|
|
bool Adafruit_GPS::begin(uint32_t baud_or_i2caddr) {
|
2023-08-20 15:31:52 +01:00
|
|
|
#if (defined(__AVR__) || ((defined(ARDUINO_UNOR4_WIFI) || defined(ESP8266)) && !defined(NO_SW_SERIAL)))
|
2020-01-29 17:03:25 +00:00
|
|
|
if (gpsSwSerial) {
|
|
|
|
|
gpsSwSerial->begin(baud_or_i2caddr);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
if (gpsHwSerial) {
|
|
|
|
|
gpsHwSerial->begin(baud_or_i2caddr);
|
|
|
|
|
}
|
|
|
|
|
if (gpsI2C) {
|
|
|
|
|
gpsI2C->begin();
|
|
|
|
|
if (baud_or_i2caddr > 0x7F) {
|
|
|
|
|
_i2caddr = GPS_DEFAULT_I2C_ADDR;
|
|
|
|
|
} else {
|
|
|
|
|
_i2caddr = baud_or_i2caddr;
|
|
|
|
|
}
|
|
|
|
|
// A basic scanner, see if it ACK's
|
|
|
|
|
gpsI2C->beginTransmission(_i2caddr);
|
|
|
|
|
return (gpsI2C->endTransmission() == 0);
|
|
|
|
|
}
|
|
|
|
|
if (gpsSPI) {
|
|
|
|
|
gpsSPI->begin();
|
|
|
|
|
gpsSPI_settings = SPISettings(baud_or_i2caddr, MSBFIRST, SPI_MODE0);
|
|
|
|
|
if (gpsSPI_cs >= 0) {
|
|
|
|
|
pinMode(gpsSPI_cs, OUTPUT);
|
|
|
|
|
digitalWrite(gpsSPI_cs, HIGH);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delay(10);
|
|
|
|
|
return true;
|
2020-01-19 14:15:18 +00:00
|
|
|
}
|
2012-03-27 22:56:07 +01:00
|
|
|
|
2019-04-20 18:51:00 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
2020-01-29 17:03:25 +00:00
|
|
|
@brief Constructor when using SoftwareSerial
|
|
|
|
|
@param ser Pointer to SoftwareSerial device
|
2019-04-20 18:51:00 +01:00
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
2023-08-20 15:31:52 +01:00
|
|
|
#if (defined(__AVR__) || ((defined(ARDUINO_UNOR4_WIFI) || defined(ESP8266)) && !defined(NO_SW_SERIAL)))
|
2020-01-29 17:03:25 +00:00
|
|
|
Adafruit_GPS::Adafruit_GPS(SoftwareSerial *ser) {
|
|
|
|
|
common_init(); // Set everything to common state, then...
|
|
|
|
|
gpsSwSerial = ser; // ...override gpsSwSerial with value passed.
|
2020-01-19 14:15:18 +00:00
|
|
|
}
|
2020-01-29 17:03:25 +00:00
|
|
|
#endif
|
2019-04-20 18:51:00 +01:00
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
2020-01-29 17:03:25 +00:00
|
|
|
@brief Constructor when using HardwareSerial
|
|
|
|
|
@param ser Pointer to a HardwareSerial object
|
2019-04-20 18:51:00 +01:00
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
2020-01-29 17:03:25 +00:00
|
|
|
Adafruit_GPS::Adafruit_GPS(HardwareSerial *ser) {
|
|
|
|
|
common_init(); // Set everything to common state, then...
|
|
|
|
|
gpsHwSerial = ser; // ...override gpsHwSerial with value passed.
|
2020-01-19 14:15:18 +00:00
|
|
|
}
|
2019-04-20 18:51:00 +01:00
|
|
|
|
2020-06-28 16:04:52 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
|
|
|
|
@brief Constructor when using Stream
|
|
|
|
|
@param data Pointer to a Stream object
|
|
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
Adafruit_GPS::Adafruit_GPS(Stream *data) {
|
2021-11-20 19:55:34 +00:00
|
|
|
common_init(); // Set everything to common state, then...
|
|
|
|
|
gpsStream = data; // ...override gpsStream with value passed.
|
2020-06-28 16:04:52 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-19 13:06:26 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
2020-01-29 17:03:25 +00:00
|
|
|
@brief Constructor when using I2C
|
|
|
|
|
@param theWire Pointer to an I2C TwoWire object
|
2020-01-19 13:06:26 +00:00
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
2020-01-29 17:03:25 +00:00
|
|
|
Adafruit_GPS::Adafruit_GPS(TwoWire *theWire) {
|
|
|
|
|
common_init(); // Set everything to common state, then...
|
|
|
|
|
gpsI2C = theWire; // ...override gpsI2C
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
|
|
|
|
@brief Constructor when using SPI
|
|
|
|
|
@param theSPI Pointer to an SPI device object
|
|
|
|
|
@param cspin The pin connected to the GPS CS, can be -1 if unused
|
|
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
Adafruit_GPS::Adafruit_GPS(SPIClass *theSPI, int8_t cspin) {
|
|
|
|
|
common_init(); // Set everything to common state, then...
|
|
|
|
|
gpsSPI = theSPI; // ...override gpsSPI
|
|
|
|
|
gpsSPI_cs = cspin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
|
|
|
|
@brief Constructor when there are no communications attached
|
|
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
Adafruit_GPS::Adafruit_GPS() {
|
|
|
|
|
common_init(); // Set everything to common state, then...
|
|
|
|
|
noComms = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
|
|
|
|
@brief Initialization code used by all constructor types
|
|
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
void Adafruit_GPS::common_init(void) {
|
2023-08-20 15:31:52 +01:00
|
|
|
#if (defined(__AVR__) || ((defined(ARDUINO_UNOR4_WIFI) || defined(ESP8266)) && !defined(NO_SW_SERIAL)))
|
2020-01-29 17:03:25 +00:00
|
|
|
gpsSwSerial = NULL; // Set both to NULL, then override correct
|
|
|
|
|
#endif
|
|
|
|
|
gpsHwSerial = NULL; // port pointer in corresponding constructor
|
2020-06-28 16:04:52 +01:00
|
|
|
gpsStream = NULL; // port pointer in corresponding constructor
|
2020-01-29 17:03:25 +00:00
|
|
|
gpsI2C = NULL;
|
|
|
|
|
gpsSPI = NULL;
|
|
|
|
|
recvdflag = false;
|
|
|
|
|
paused = false;
|
|
|
|
|
lineidx = 0;
|
|
|
|
|
currentline = line1;
|
|
|
|
|
lastline = line2;
|
|
|
|
|
|
|
|
|
|
hour = minute = seconds = year = month = day = fixquality = fixquality_3d =
|
2021-02-05 00:02:44 +00:00
|
|
|
satellites = antenna = 0; // uint8_t
|
|
|
|
|
lat = lon = mag = 0; // char
|
|
|
|
|
fix = false; // bool
|
|
|
|
|
milliseconds = 0; // uint16_t
|
2020-01-29 17:03:25 +00:00
|
|
|
latitude = longitude = geoidheight = altitude = speed = angle = magvariation =
|
|
|
|
|
HDOP = VDOP = PDOP = 0.0; // nmea_float_t
|
|
|
|
|
#ifdef NMEA_EXTENSIONS
|
|
|
|
|
data_init();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
|
|
|
|
@brief Destroy the object.
|
|
|
|
|
@return none
|
|
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
Adafruit_GPS::~Adafruit_GPS() {
|
|
|
|
|
#ifdef NMEA_EXTENSIONS
|
|
|
|
|
for (int i = 0; i < (int)NMEA_MAX_INDEX; i++)
|
|
|
|
|
removeHistory((nmea_index_t)i); // to free any history mallocs
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2020-01-19 13:06:26 +00:00
|
|
|
|
2019-10-14 02:32:50 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
2020-01-17 21:18:09 +00:00
|
|
|
@brief How many bytes are available to read - part of 'Print'-class
|
|
|
|
|
functionality
|
2019-10-14 02:32:50 +01:00
|
|
|
@return Bytes available, 0 if none
|
|
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
2019-08-30 07:18:01 +01:00
|
|
|
size_t Adafruit_GPS::available(void) {
|
2020-01-17 21:18:09 +00:00
|
|
|
if (paused)
|
|
|
|
|
return 0;
|
2019-08-30 07:18:01 +01:00
|
|
|
|
2023-08-20 15:31:52 +01:00
|
|
|
#if (defined(__AVR__) || ((defined(ARDUINO_UNOR4_WIFI) || defined(ESP8266)) && !defined(NO_SW_SERIAL)))
|
2019-08-30 07:18:01 +01:00
|
|
|
if (gpsSwSerial) {
|
|
|
|
|
return gpsSwSerial->available();
|
2019-10-31 21:05:02 +00:00
|
|
|
}
|
2019-08-30 07:18:01 +01:00
|
|
|
#endif
|
|
|
|
|
if (gpsHwSerial) {
|
|
|
|
|
return gpsHwSerial->available();
|
|
|
|
|
}
|
2020-06-28 16:04:52 +01:00
|
|
|
if (gpsStream) {
|
|
|
|
|
return gpsStream->available();
|
|
|
|
|
}
|
2019-11-17 00:06:07 +00:00
|
|
|
if (gpsI2C || gpsSPI) {
|
2020-01-17 21:18:09 +00:00
|
|
|
return 1; // I2C/SPI doesnt have 'availability' so always has a byte at
|
|
|
|
|
// least to read!
|
2019-08-30 07:18:01 +01:00
|
|
|
}
|
2019-10-09 21:51:17 +01:00
|
|
|
return 0;
|
2019-08-30 07:18:01 +01:00
|
|
|
}
|
|
|
|
|
|
2019-10-14 02:32:50 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
2020-01-17 21:18:09 +00:00
|
|
|
@brief Write a byte to the underlying transport - part of 'Print'-class
|
|
|
|
|
functionality
|
2019-10-14 02:32:50 +01:00
|
|
|
@param c A single byte to send
|
|
|
|
|
@return Bytes written - 1 on success, 0 on failure
|
|
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
2019-08-30 07:18:01 +01:00
|
|
|
size_t Adafruit_GPS::write(uint8_t c) {
|
2023-08-20 15:31:52 +01:00
|
|
|
#if (defined(__AVR__) || ((defined(ARDUINO_UNOR4_WIFI) || defined(ESP8266)) && !defined(NO_SW_SERIAL)))
|
2019-08-30 07:18:01 +01:00
|
|
|
if (gpsSwSerial) {
|
|
|
|
|
return gpsSwSerial->write(c);
|
2019-10-31 21:05:02 +00:00
|
|
|
}
|
2019-08-30 07:18:01 +01:00
|
|
|
#endif
|
|
|
|
|
if (gpsHwSerial) {
|
|
|
|
|
return gpsHwSerial->write(c);
|
|
|
|
|
}
|
2020-06-28 16:04:52 +01:00
|
|
|
if (gpsStream) {
|
|
|
|
|
return gpsStream->write(c);
|
|
|
|
|
}
|
2019-08-30 07:18:01 +01:00
|
|
|
if (gpsI2C) {
|
|
|
|
|
gpsI2C->beginTransmission(_i2caddr);
|
|
|
|
|
if (gpsI2C->write(c) != 1) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (gpsI2C->endTransmission(true) == 0) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-17 00:06:07 +00:00
|
|
|
if (gpsSPI) {
|
2020-01-17 21:18:09 +00:00
|
|
|
gpsSPI->beginTransaction(gpsSPI_settings);
|
2019-11-17 00:06:07 +00:00
|
|
|
if (gpsSPI_cs >= 0) {
|
|
|
|
|
digitalWrite(gpsSPI_cs, LOW);
|
|
|
|
|
}
|
|
|
|
|
c = gpsSPI->transfer(c);
|
|
|
|
|
if (gpsSPI_cs >= 0) {
|
|
|
|
|
digitalWrite(gpsSPI_cs, HIGH);
|
|
|
|
|
}
|
|
|
|
|
gpsSPI->endTransaction();
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-30 07:18:01 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-12 21:21:45 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
2020-02-08 01:20:30 +00:00
|
|
|
@brief Read one character from the GPS device.
|
|
|
|
|
|
2020-01-30 19:29:17 +00:00
|
|
|
Call very frequently and multiple times per opportunity or the buffer
|
|
|
|
|
may overflow if there are frequent NMEA sentences. An 82 character NMEA
|
2020-02-08 01:20:30 +00:00
|
|
|
sentence 10 times per second will require 820 calls per second, and
|
2020-01-30 19:29:17 +00:00
|
|
|
once a loop() may not be enough. Check for newNMEAreceived() after at
|
|
|
|
|
least every 10 calls, or you may miss some short sentences.
|
2019-03-12 21:21:45 +00:00
|
|
|
@return The character that we received, or 0 if nothing was available
|
|
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
2012-03-28 17:20:38 +01:00
|
|
|
char Adafruit_GPS::read(void) {
|
2020-01-17 21:18:09 +00:00
|
|
|
static uint32_t firstChar = 0; // first character received in current sentence
|
|
|
|
|
uint32_t tStart = millis(); // as close as we can get to time char was sent
|
2012-03-28 17:20:38 +01:00
|
|
|
char c = 0;
|
2019-03-12 21:21:45 +00:00
|
|
|
|
2020-01-29 14:56:21 +00:00
|
|
|
if (paused || noComms)
|
2020-01-17 21:18:09 +00:00
|
|
|
return c;
|
2012-03-27 22:56:07 +01:00
|
|
|
|
2023-08-20 15:31:52 +01:00
|
|
|
#if (defined(__AVR__) || ((defined(ARDUINO_UNOR4_WIFI) || defined(ESP8266)) && !defined(NO_SW_SERIAL)))
|
2020-01-17 21:18:09 +00:00
|
|
|
if (gpsSwSerial) {
|
2019-10-31 21:05:02 +00:00
|
|
|
if (!gpsSwSerial->available())
|
2019-08-30 07:18:01 +01:00
|
|
|
return c;
|
2012-03-28 17:20:38 +01:00
|
|
|
c = gpsSwSerial->read();
|
2019-10-31 21:05:02 +00:00
|
|
|
}
|
2014-06-08 20:46:05 +01:00
|
|
|
#endif
|
2019-08-30 07:18:01 +01:00
|
|
|
if (gpsHwSerial) {
|
2019-10-31 21:05:02 +00:00
|
|
|
if (!gpsHwSerial->available())
|
2019-08-30 07:18:01 +01:00
|
|
|
return c;
|
2012-04-27 21:49:18 +01:00
|
|
|
c = gpsHwSerial->read();
|
|
|
|
|
}
|
2020-06-28 16:04:52 +01:00
|
|
|
if (gpsStream) {
|
|
|
|
|
if (!gpsStream->available())
|
|
|
|
|
return c;
|
|
|
|
|
c = gpsStream->read();
|
|
|
|
|
}
|
2019-08-30 07:18:01 +01:00
|
|
|
if (gpsI2C) {
|
2019-11-17 00:06:07 +00:00
|
|
|
if (_buff_idx <= _buff_max) {
|
|
|
|
|
c = _i2cbuffer[_buff_idx];
|
|
|
|
|
_buff_idx++;
|
2019-08-30 07:18:01 +01:00
|
|
|
} else {
|
|
|
|
|
// refill the buffer!
|
2020-02-08 01:20:30 +00:00
|
|
|
if (gpsI2C->requestFrom((uint8_t)0x10, (uint8_t)GPS_MAX_I2C_TRANSFER,
|
|
|
|
|
(uint8_t) true) == GPS_MAX_I2C_TRANSFER) {
|
2020-01-17 21:18:09 +00:00
|
|
|
// got data!
|
|
|
|
|
_buff_max = 0;
|
|
|
|
|
char curr_char = 0;
|
|
|
|
|
for (int i = 0; i < GPS_MAX_I2C_TRANSFER; i++) {
|
|
|
|
|
curr_char = gpsI2C->read();
|
|
|
|
|
if ((curr_char == 0x0A) && (last_char != 0x0D)) {
|
|
|
|
|
// skip duplicate 0x0A's - but keep as part of a CRLF
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
last_char = curr_char;
|
|
|
|
|
_i2cbuffer[_buff_max] = curr_char;
|
|
|
|
|
_buff_max++;
|
|
|
|
|
}
|
|
|
|
|
_buff_max--; // back up to the last valid slot
|
|
|
|
|
if ((_buff_max == 0) && (_i2cbuffer[0] == 0x0A)) {
|
|
|
|
|
_buff_max = -1; // ahh there was nothing to read after all
|
|
|
|
|
}
|
|
|
|
|
_buff_idx = 0;
|
2019-08-30 07:18:01 +01:00
|
|
|
}
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-31 21:05:02 +00:00
|
|
|
|
2019-11-17 00:06:07 +00:00
|
|
|
if (gpsSPI) {
|
|
|
|
|
do {
|
2020-01-17 21:18:09 +00:00
|
|
|
gpsSPI->beginTransaction(gpsSPI_settings);
|
2019-11-17 00:06:07 +00:00
|
|
|
if (gpsSPI_cs >= 0) {
|
2020-01-17 21:18:09 +00:00
|
|
|
digitalWrite(gpsSPI_cs, LOW);
|
2019-11-17 00:06:07 +00:00
|
|
|
}
|
|
|
|
|
c = gpsSPI->transfer(0xFF);
|
|
|
|
|
if (gpsSPI_cs >= 0) {
|
2020-01-17 21:18:09 +00:00
|
|
|
digitalWrite(gpsSPI_cs, HIGH);
|
2019-11-17 00:06:07 +00:00
|
|
|
}
|
|
|
|
|
gpsSPI->endTransaction();
|
|
|
|
|
// skip duplicate 0x0A's - but keep as part of a CRLF
|
2020-01-17 21:18:09 +00:00
|
|
|
} while (((c == 0x0A) && (last_char != 0x0D)) ||
|
|
|
|
|
(!isprint(c) && !isspace(c)));
|
2019-11-17 00:06:07 +00:00
|
|
|
last_char = c;
|
|
|
|
|
}
|
2020-01-17 21:18:09 +00:00
|
|
|
// Serial.print(c);
|
2019-10-31 21:05:02 +00:00
|
|
|
|
2019-04-10 00:57:35 +01:00
|
|
|
currentline[lineidx++] = c;
|
|
|
|
|
if (lineidx >= MAXLINELENGTH)
|
2020-01-17 21:18:09 +00:00
|
|
|
lineidx = MAXLINELENGTH -
|
|
|
|
|
1; // ensure there is someplace to put the next received character
|
2019-04-10 00:57:35 +01:00
|
|
|
|
2012-04-27 21:49:18 +01:00
|
|
|
if (c == '\n') {
|
|
|
|
|
currentline[lineidx] = 0;
|
|
|
|
|
|
|
|
|
|
if (currentline == line1) {
|
|
|
|
|
currentline = line2;
|
|
|
|
|
lastline = line1;
|
|
|
|
|
} else {
|
|
|
|
|
currentline = line1;
|
|
|
|
|
lastline = line2;
|
2012-03-27 22:56:07 +01:00
|
|
|
}
|
2012-04-27 21:49:18 +01:00
|
|
|
|
2020-01-17 21:18:09 +00:00
|
|
|
// Serial.println("----");
|
|
|
|
|
// Serial.println((char *)lastline);
|
|
|
|
|
// Serial.println("----");
|
2012-04-27 21:49:18 +01:00
|
|
|
lineidx = 0;
|
|
|
|
|
recvdflag = true;
|
2020-01-17 21:18:09 +00:00
|
|
|
recvdTime = millis(); // time we got the end of the string
|
2019-09-29 17:26:01 +01:00
|
|
|
sentTime = firstChar;
|
2020-01-17 21:18:09 +00:00
|
|
|
firstChar = 0; // there are no characters yet
|
|
|
|
|
return c; // wait until next character to set time
|
2012-03-27 22:56:07 +01:00
|
|
|
}
|
2012-04-27 21:49:18 +01:00
|
|
|
|
2020-01-17 21:18:09 +00:00
|
|
|
if (firstChar == 0)
|
|
|
|
|
firstChar = tStart;
|
2012-03-28 17:20:38 +01:00
|
|
|
return c;
|
2012-03-27 22:56:07 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-12 21:21:45 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
|
|
|
|
@brief Send a command to the GPS device
|
|
|
|
|
@param str Pointer to a string holding the command to send
|
|
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
2020-01-17 21:18:09 +00:00
|
|
|
void Adafruit_GPS::sendCommand(const char *str) { println(str); }
|
2012-03-27 22:56:07 +01:00
|
|
|
|
2019-03-12 21:21:45 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
|
|
|
|
@brief Check to see if a new NMEA line has been received
|
|
|
|
|
@return True if received, false if not
|
|
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
2020-01-19 20:10:10 +00:00
|
|
|
bool Adafruit_GPS::newNMEAreceived(void) { return recvdflag; }
|
2012-03-27 22:56:07 +01:00
|
|
|
|
2019-03-12 21:21:45 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
|
|
|
|
@brief Pause/unpause receiving new data
|
|
|
|
|
@param p True = pause, false = unpause
|
|
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
2020-01-19 20:10:10 +00:00
|
|
|
void Adafruit_GPS::pause(bool p) { paused = p; }
|
2012-03-27 22:56:07 +01:00
|
|
|
|
2019-03-12 21:21:45 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
|
|
|
|
@brief Returns the last NMEA line received and unsets the received flag
|
|
|
|
|
@return Pointer to the last line string
|
|
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
2012-03-27 22:56:07 +01:00
|
|
|
char *Adafruit_GPS::lastNMEA(void) {
|
|
|
|
|
recvdflag = false;
|
|
|
|
|
return (char *)lastline;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-12 21:21:45 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
|
|
|
|
@brief Wait for a specified sentence from the device
|
|
|
|
|
@param wait4me Pointer to a string holding the desired response
|
|
|
|
|
@param max How long to wait, default is MAXWAITSENTENCE
|
2020-01-17 21:18:09 +00:00
|
|
|
@param usingInterrupts True if using interrupts to read from the GPS
|
|
|
|
|
(default is false)
|
2019-03-12 21:21:45 +00:00
|
|
|
@return True if we got what we wanted, false otherwise
|
|
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
2020-01-19 20:10:10 +00:00
|
|
|
bool Adafruit_GPS::waitForSentence(const char *wait4me, uint8_t max,
|
|
|
|
|
bool usingInterrupts) {
|
2020-01-17 21:18:09 +00:00
|
|
|
uint8_t i = 0;
|
2012-03-28 19:14:32 +01:00
|
|
|
while (i < max) {
|
2019-04-10 00:57:35 +01:00
|
|
|
if (!usingInterrupts)
|
|
|
|
|
read();
|
2017-08-02 04:27:56 +01:00
|
|
|
|
2019-03-12 21:21:45 +00:00
|
|
|
if (newNMEAreceived()) {
|
2012-03-28 19:14:32 +01:00
|
|
|
char *nmea = lastNMEA();
|
|
|
|
|
i++;
|
|
|
|
|
|
2019-04-10 00:57:35 +01:00
|
|
|
if (strStartsWith(nmea, wait4me))
|
2020-01-17 21:18:09 +00:00
|
|
|
return true;
|
2012-03-28 19:14:32 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-12 21:21:45 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
|
|
|
|
@brief Start the LOCUS logger
|
|
|
|
|
@return True on success, false if it failed
|
|
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
2020-01-19 20:10:10 +00:00
|
|
|
bool Adafruit_GPS::LOCUS_StartLogger(void) {
|
2012-03-28 19:14:32 +01:00
|
|
|
sendCommand(PMTK_LOCUS_STARTLOG);
|
|
|
|
|
recvdflag = false;
|
2013-10-27 16:15:00 +00:00
|
|
|
return waitForSentence(PMTK_LOCUS_STARTSTOPACK);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-12 21:21:45 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
|
|
|
|
@brief Stop the LOCUS logger
|
|
|
|
|
@return True on success, false if it failed
|
|
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
2020-01-19 20:10:10 +00:00
|
|
|
bool Adafruit_GPS::LOCUS_StopLogger(void) {
|
2013-10-27 16:15:00 +00:00
|
|
|
sendCommand(PMTK_LOCUS_STOPLOG);
|
|
|
|
|
recvdflag = false;
|
|
|
|
|
return waitForSentence(PMTK_LOCUS_STARTSTOPACK);
|
2012-03-28 19:14:32 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-12 21:21:45 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
|
|
|
|
@brief Read the logger status
|
|
|
|
|
@return True if we read the data, false if there was no response
|
|
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
2020-01-19 20:10:10 +00:00
|
|
|
bool Adafruit_GPS::LOCUS_ReadStatus(void) {
|
2012-03-28 19:14:32 +01:00
|
|
|
sendCommand(PMTK_LOCUS_QUERY_STATUS);
|
2019-03-12 21:21:45 +00:00
|
|
|
|
2020-01-17 21:18:09 +00:00
|
|
|
if (!waitForSentence("$PMTKLOG"))
|
2012-03-28 19:14:32 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
char *response = lastNMEA();
|
|
|
|
|
uint16_t parsed[10];
|
|
|
|
|
uint8_t i;
|
2019-03-12 21:21:45 +00:00
|
|
|
|
2020-01-17 21:18:09 +00:00
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
|
parsed[i] = -1;
|
2019-03-12 21:21:45 +00:00
|
|
|
|
2012-03-28 19:14:32 +01:00
|
|
|
response = strchr(response, ',');
|
2020-01-17 21:18:09 +00:00
|
|
|
for (i = 0; i < 10; i++) {
|
2019-03-12 21:21:45 +00:00
|
|
|
if (!response || (response[0] == 0) || (response[0] == '*'))
|
2012-03-28 19:14:32 +01:00
|
|
|
break;
|
|
|
|
|
response++;
|
2020-01-17 21:18:09 +00:00
|
|
|
parsed[i] = 0;
|
|
|
|
|
while ((response[0] != ',') && (response[0] != '*') && (response[0] != 0)) {
|
2012-03-28 19:14:32 +01:00
|
|
|
parsed[i] *= 10;
|
|
|
|
|
char c = response[0];
|
|
|
|
|
if (isDigit(c))
|
|
|
|
|
parsed[i] += c - '0';
|
|
|
|
|
else
|
|
|
|
|
parsed[i] = c;
|
|
|
|
|
response++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
LOCUS_serial = parsed[0];
|
|
|
|
|
LOCUS_type = parsed[1];
|
|
|
|
|
if (isAlpha(parsed[2])) {
|
2019-03-12 21:21:45 +00:00
|
|
|
parsed[2] = parsed[2] - 'a' + 10;
|
2012-03-28 19:14:32 +01:00
|
|
|
}
|
|
|
|
|
LOCUS_mode = parsed[2];
|
|
|
|
|
LOCUS_config = parsed[3];
|
|
|
|
|
LOCUS_interval = parsed[4];
|
|
|
|
|
LOCUS_distance = parsed[5];
|
|
|
|
|
LOCUS_speed = parsed[6];
|
|
|
|
|
LOCUS_status = !parsed[7];
|
|
|
|
|
LOCUS_records = parsed[8];
|
|
|
|
|
LOCUS_percent = parsed[9];
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2012-04-30 02:46:21 +01:00
|
|
|
|
2019-03-12 21:21:45 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
|
|
|
|
@brief Standby Mode Switches
|
|
|
|
|
@return False if already in standby, true if it entered standby
|
|
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
2020-01-19 20:10:10 +00:00
|
|
|
bool Adafruit_GPS::standby(void) {
|
2012-04-30 02:46:21 +01:00
|
|
|
if (inStandbyMode) {
|
2020-01-17 21:18:09 +00:00
|
|
|
return false; // Returns false if already in standby mode, so that you do
|
|
|
|
|
// not wake it up by sending commands to GPS
|
|
|
|
|
} else {
|
2012-04-30 02:46:21 +01:00
|
|
|
inStandbyMode = true;
|
|
|
|
|
sendCommand(PMTK_STANDBY);
|
2020-01-17 21:18:09 +00:00
|
|
|
// return waitForSentence(PMTK_STANDBY_SUCCESS); // don't seem to be fast
|
|
|
|
|
// enough to catch the message, or something else just is not working
|
2012-04-30 02:46:21 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-12 21:21:45 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
|
|
|
|
@brief Wake the sensor up
|
|
|
|
|
@return True if woken up, false if not in standby or failed to wake
|
|
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
2020-01-19 20:10:10 +00:00
|
|
|
bool Adafruit_GPS::wakeup(void) {
|
2012-04-30 02:46:21 +01:00
|
|
|
if (inStandbyMode) {
|
2020-01-17 21:18:09 +00:00
|
|
|
inStandbyMode = false;
|
|
|
|
|
sendCommand(""); // send byte to wake it up
|
2012-04-30 02:46:21 +01:00
|
|
|
return waitForSentence(PMTK_AWAKE);
|
2020-01-17 21:18:09 +00:00
|
|
|
} else {
|
|
|
|
|
return false; // Returns false if not in standby mode, nothing to wakeup
|
2012-04-30 02:46:21 +01:00
|
|
|
}
|
2012-12-04 16:20:10 +00:00
|
|
|
}
|
2020-01-08 17:05:07 +00:00
|
|
|
|
2020-01-29 17:03:25 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
2020-02-21 20:04:56 +00:00
|
|
|
@brief Time in seconds since the last position fix was obtained. The
|
|
|
|
|
time returned is limited to 2^32 milliseconds, which is about 49.7 days.
|
|
|
|
|
It will wrap around to zero if no position fix is received
|
|
|
|
|
for this long.
|
2020-01-29 17:03:25 +00:00
|
|
|
@return nmea_float_t value in seconds since last fix.
|
|
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
nmea_float_t Adafruit_GPS::secondsSinceFix() {
|
|
|
|
|
return (millis() - lastFix) / 1000.;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
2020-02-21 20:04:56 +00:00
|
|
|
@brief Time in seconds since the last GPS time was obtained. The time
|
|
|
|
|
returned is limited to 2^32 milliseconds, which is about 49.7 days. It
|
|
|
|
|
will wrap around to zero if no GPS time is received for this long.
|
2020-01-29 17:03:25 +00:00
|
|
|
@return nmea_float_t value in seconds since last GPS time.
|
|
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
nmea_float_t Adafruit_GPS::secondsSinceTime() {
|
|
|
|
|
return (millis() - lastTime) / 1000.;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
2020-02-21 20:04:56 +00:00
|
|
|
@brief Time in seconds since the last GPS date was obtained. The time
|
|
|
|
|
returned is limited to 2^32 milliseconds, which is about 49.7 days. It
|
|
|
|
|
will wrap around to zero if no GPS date is received for this long.
|
2020-01-29 17:03:25 +00:00
|
|
|
@return nmea_float_t value in seconds since last GPS date.
|
|
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
nmea_float_t Adafruit_GPS::secondsSinceDate() {
|
|
|
|
|
return (millis() - lastDate) / 1000.;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
|
|
|
|
@brief Fakes time of receipt of a sentence. Use between build() and parse()
|
|
|
|
|
to make the timing look like the sentence arrived from the GPS.
|
|
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
void Adafruit_GPS::resetSentTime() { sentTime = millis(); }
|
|
|
|
|
|
2020-01-08 17:05:07 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
|
/*!
|
|
|
|
|
@brief Checks whether a string starts with a specified prefix
|
|
|
|
|
@param str Pointer to a string
|
|
|
|
|
@param prefix Pointer to the prefix
|
|
|
|
|
@return True if str starts with prefix, false otherwise
|
|
|
|
|
*/
|
|
|
|
|
/**************************************************************************/
|
2020-01-19 20:10:10 +00:00
|
|
|
static bool strStartsWith(const char *str, const char *prefix) {
|
2020-01-08 17:05:07 +00:00
|
|
|
while (*prefix) {
|
|
|
|
|
if (*prefix++ != *str++)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2020-01-18 14:07:15 +00:00
|
|
|
}
|