Adafruit GPS Library
Public Member Functions | Static Public Member Functions | List of all members
Adafruit_GNSS Class Reference

#include <Adafruit_GNSS.h>

Inheritance diagram for Adafruit_GNSS:
Adafruit_NMEA

Public Member Functions

 Adafruit_GNSS (volatile char *firstBuffer=NULL, volatile char *secondBuffer=NULL, size_t capacity=0)
 Create a GNSS receiver using the shared bounded NMEA framer. More...
 
gnss_position_t lastPosition () const
 Decode the latest complete line into an independent position result. More...
 
- Public Member Functions inherited from Adafruit_NMEA
 Adafruit_NMEA (volatile char *firstBuffer, volatile char *secondBuffer, size_t capacity)
 Create a receiver using two caller-owned buffers. More...
 
 Adafruit_NMEA (const Adafruit_NMEA &other)=delete
 Copying is disabled to prevent sharing writable receive buffers. More...
 
Adafruit_NMEA & operator= (const Adafruit_NMEA &other)=delete
 Assignment is disabled to prevent sharing writable receive buffers. More...
 
void reset ()
 Discard partial and completed lines and clear all timestamps. More...
 
nmea_frame_status_t feed (uint8_t byte, uint32_t receivedAtMs)
 Feed one byte into this receiver's bounded sentence buffer. More...
 
nmea_span_t lastText () const
 Get the latest complete raw line without validating it again. More...
 
nmea_sentence_t lastSentence () const
 Get views of the latest complete line, including invalid raw text. More...
 
uint32_t sentenceStartedAt () const
 Get the start-marker timestamp of the latest complete line. More...
 
uint32_t sentenceReceivedAt () const
 Get the LF timestamp of the latest complete line. More...
 

Static Public Member Functions

static gnss_coordinate_t parseCoordinate (nmea_span_t coordinate, nmea_span_t hemisphere)
 Decode a latitude or longitude field and its hemisphere. More...
 
static size_t formatCoordinate (char *output, size_t capacity, const gnss_coordinate_t &coordinate)
 Format exact coordinate components as signed decimal degrees. More...
 
static gnss_position_t parsePosition (nmea_span_t type, nmea_span_t fields)
 Decode a GGA, RMC, or GLL position without retaining receiver state. More...
 
static gnss_position_t parsePosition (const nmea_sentence_t &sentence)
 Route a validated standard NMEA sentence to the position decoder. More...
 
static gnss_time_t parseTime (nmea_span_t field)
 Decode a complete UTC hhmmss[.fraction] field. More...
 
static gnss_date_t parseDate (nmea_span_t field)
 Decode a complete ddmmyy date field. More...
 
static gnss_validation_t validateNavigation (nmea_span_t type, nmea_span_t fields)
 Validate standard fields before updating navigation data. More...
 
- Static Public Member Functions inherited from Adafruit_NMEA
static nmea_sentence_t validate (const char *data, size_t length)
 Validate a complete, length-bounded NMEA sentence without copying it. More...
 
static nmea_span_t nextField (nmea_span_t &remaining)
 Return the next field and advance a bounded field cursor. More...
 
static nmea_decimal_t parseDecimal (nmea_span_t field)
 Convert a complete field to an exact signed decimal value. More...
 
static nmea_number_status_t validateDecimal (nmea_span_t field, bool allowNegative=true)
 Check an exact decimal without constructing its numeric value. More...
 
static size_t buildCommand (char *output, size_t capacity, const char *body, size_t bodyLength)
 Build a checksummed command in caller-provided storage. More...
 

Detailed Description

Standard GNSS receiver and decoding shared by receiver implementations. Inherits bounded framing with caller-owned buffers and per-instance times. Position decoding is stateless: no fix is cached or merged across lines. Static decoding does not require receive storage. No heap or transport I/O.

Constructor & Destructor Documentation

◆ Adafruit_GNSS()

Adafruit_GNSS::Adafruit_GNSS ( volatile char *  firstBuffer = NULL,
volatile char *  secondBuffer = NULL,
size_t  capacity = 0 
)

Create a GNSS receiver using the shared bounded NMEA framer.

Parameters
firstBufferFirst caller-owned writable receive buffer.
secondBufferSecond buffer, disjoint from the first.
capacityBytes per buffer, including NUL space.

Storage must outlive the receiver. The default or invalid storage disables feed() as described by Adafruit_NMEA; static decoding remains available. Supply incoming bytes and their timestamps with the inherited feed(). No position cache, transport, command handling, or allocation is added.

Member Function Documentation

◆ lastPosition()

gnss_position_t Adafruit_GNSS::lastPosition ( ) const

Decode the latest complete line into an independent position result.

Returns
Exact GGA/RMC/GLL measurements, or validation diagnostics.

Call after feed() reports a complete line, and synchronize with feed() if using interrupts. Each call validates and decodes the current line; it does not consume it. Before a line or after reset(), the result is INVALID_FRAME. Invalid completed lines replace earlier positions; proprietary replies and other sentences return UNSUPPORTED and remain accessible via lastSentence(). Partial/overflowing input preserves the previous complete line, just as the framer does. Use sentenceStartedAt() and sentenceReceivedAt() for this line. Returned values own their data and survive later input or reset().

◆ parseCoordinate()

gnss_coordinate_t Adafruit_GNSS::parseCoordinate ( nmea_span_t  coordinate,
nmea_span_t  hemisphere 
)
static

Decode a latitude or longitude field and its hemisphere.

Parameters
coordinateDDMM[.fraction] latitude or DDDMM[.fraction] longitude.
hemisphereExactly one N/S for latitude or E/W for longitude.
Returns
Validated components and signed decimal degrees times 10000000.

Missing spans take precedence over empty spans, then malformed syntax, then range errors. Signs, spaces, exponents, and a bare decimal point are invalid. Minutes must be below 60; latitude is limited to 90 degrees and longitude to 180, with zero minutes at either boundary. Fractional minutes retain the first nine digits, padded with zeros; further digits are validated and truncated. degreesE7 is exact at its stated resolution, without rounding or intermediate floating-point arithmetic.

◆ formatCoordinate()

size_t Adafruit_GNSS::formatCoordinate ( char *  output,
size_t  capacity,
const gnss_coordinate_t &  coordinate 
)
static

Format exact coordinate components as signed decimal degrees.

Parameters
outputWritable text buffer; must not overlap coordinate.
capacityBuffer size including the NUL terminator. Use GNSS_COORDINATE_TEXT_SIZE to fit every valid coordinate.
coordinateValidated components from parseCoordinate().
Returns
Characters written, excluding NUL, or zero for invalid components or insufficient storage. On failure output[0] is cleared when possible; no other output bytes are changed.

Writes exactly 11 fractional degree digits, truncated toward zero. This distinguishes every retained fractional-minute increment and introduces less than 0.00000000001 degree of formatting error (about 1.2 micrometers of latitude). Southern/western zero retains its minus sign. The components, not the lower-resolution degreesE7 member, supply the result.

Integer long division uses at most 32-bit arithmetic, with no heap or floating-point conversion. AVR output retains the same precision as other targets, regardless of NMEA_FLOAT_T or the platform's double size.

◆ parsePosition() [1/2]

gnss_position_t Adafruit_GNSS::parsePosition ( nmea_span_t  type,
nmea_span_t  fields 
)
static

Decode a GGA, RMC, or GLL position without retaining receiver state.

Parameters
typeThree-character sentence type without its talker prefix.
fieldsBorrowed fields after the address comma and before '*'.
Returns
Independent values and validation diagnostics. Invalid or unsupported input returns no partially decoded measurements.

Call after validating the enclosing frame with Adafruit_NMEA::validate(). Input storage must remain readable and unchanged throughout the call. Validate all consumed navigation fields before returning measurements, including fields this result does not expose (such as altitude). Optional tails retain validateNavigation()'s existing behavior.

Populated coordinates retain all nine fractional-minute digits and can be passed directly to formatCoordinate(). Empty fields have EMPTY status; fields absent from this sentence type have MISSING status. The fix boolean is meaningful only with VALID fixStatus and does not imply populated coordinates. GGA quality is independent of RMC/GLL fix validity.

Time/date and exact position components belong only to this sentence. No timestamps, previous-fix merging, allocation, or floating-point conversion occur here. GSA and other sentence types are UNSUPPORTED by this decoder.

◆ parsePosition() [2/2]

gnss_position_t Adafruit_GNSS::parsePosition ( const nmea_sentence_t &  sentence)
static

Route a validated standard NMEA sentence to the position decoder.

Parameters
sentenceUnmodified view returned by validate() or lastSentence().
Returns
Independent values; INVALID_FRAME for non-VALID input, UNSUPPORTED for a valid frame outside the supported standard position sentences.

Keep the borrowed storage readable and unchanged throughout the call. Trust the supplied frame status; use validate() first for arbitrary text. A standard position address has two uppercase talker letters followed by GGA, RMC, or GLL. Any such talker is accepted except the proprietary 'P' prefix. Encapsulated '!' messages and proprietary addresses are not routed. No receiver-specific address whitelist or command handling is imposed on the underlying framer. Invalid/unsupported input returns no measurements.

◆ parseTime()

gnss_time_t Adafruit_GNSS::parseTime ( nmea_span_t  field)
static

Decode a complete UTC hhmmss[.fraction] field.

Parameters
fieldBorrowed time field, with no terminator required.
Returns
Status and validated components, zeroed on failure.

Exactly six whole digits are required. A decimal point requires at least one fractional digit; all digits are checked, with the first three retained as milliseconds. Seconds may be 60 to represent a leap second. This checks field ranges, not whether a leap second occurred on a particular date.

◆ parseDate()

gnss_date_t Adafruit_GNSS::parseDate ( nmea_span_t  field)
static

Decode a complete ddmmyy date field.

Parameters
fieldBorrowed six-digit date, with no terminator required.
Returns
Status and validated components, zeroed on failure.

Validates month lengths and February 29 using year modulo four. The NMEA field has no century; year 00 is treated as a leap year, as in 2000. Applications requiring a full year must resolve the century separately.

◆ validateNavigation()

gnss_validation_t Adafruit_GNSS::validateNavigation ( nmea_span_t  type,
nmea_span_t  fields 
)
static

Validate standard fields before updating navigation data.

Parameters
typeThree-character sentence type, without its talker prefix.
fieldsFields after the address comma and before the checksum.
Returns
Status and the first invalid or missing one-based field position.

Call after validating the enclosing NMEA frame. Checks the fields consumed by the existing GPS decoders: GGA through geoid separation, RMC through date, GLL through status, and GSA fix type and dilution values. Optional tails and the satellite IDs skipped by the GPS parser are left to their decoders. Empty fields are permitted, but a coordinate and its hemisphere must either both be empty or both be valid for the appropriate axis. Numeric fields must be complete representable decimals; speed, course, and dilution values cannot be negative. Fix quality and satellite count must fit uint8_t. Valid does not imply a position fix or populated fields. No receiver state changes, field arrays, or heap allocation are involved.


The documentation for this class was generated from the following files: