Skip to content

Process GSA sentence data #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode/
85 changes: 70 additions & 15 deletions README.rst → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,34 @@ MicroNMEA
=========

MicroNMEA is a compact Arduino library to parse a subset of NMEA
sentences, which can originate from either GPS or GNSS receivers. Only
two types of messages are parsed, ``$GPGGA`` (and its GNSS
sentences, which can originate from either GPS or GNSS receivers.
This fork extends the original library by stevemarple with additional features.

Changes from Original
-------------------

This fork adds the following enhancements:

* Support for GSA sentences to obtain additional fix information:
* Fix type (None/2D/3D)
* Selection mode (Auto/Manual)
* Position/Vertical/Horizontal Dilution of Precision (PDOP/VDOP/HDOP)

* Enhanced GGA sentence processing:
* Added geoid height support
* Added callback when time is received (onTimeReceived)

* Additional convenience methods:
* getSpeedMS() to get speed in meters per second
* getFix() to get the fix type (None/2D/3D)
* getAutofix() to get fix selection mode (Auto/Manual)
* getVDOP() and getPDOP() for additional dilution of precision values
* getGeoidHeight() to get height above WGS84 geoid

Original Description
------------------

MicroNMEA parses NMEA sentences, specifically ``$GPGGA`` (and its GNSS
versions ``$GNGGA``, ``$GLGGA``, and ``$GAGGA``) and ``$GPRMC`` (and
its GNSS versions ``$GNRMC``, ``$GLRMC``, and ``$GARMC``). From these
two NMEA sentences MicroNMEA can output date, time, latitude,
Expand All @@ -20,8 +46,8 @@ as well as the correct ``<CR><LF>`` terminators.
License
-------

The MicroNMEA library is released under the GNU Lesser General Public License, version 2.1.
http://www.gnu.org/licenses/lgpl-2.1.html
The MicroNMEA library is released under the GNU Lesser General Public License, version 2.1.
<http://www.gnu.org/licenses/lgpl-2.1.html>

Initialization and basic usage
------------------------------
Expand All @@ -46,7 +72,8 @@ Output data from the GPS/GNSS device must be passed to the library for processin
In the code fragment above ``gps`` is the output stream of the GPS/GNSS device.

Retrieving information from MicroNMEA
-------------------------------------
------------------------------------

Location, date, time and various status information can be requested using the appropriate member functions which are described below. To obtain all of the information listed below MicroNMEA must process both ``GxGGA`` and ``GxRMC`` sentences::

char getNavSystem() const
Expand All @@ -70,7 +97,7 @@ Returns a single character indicating the navigation system in use:
uint8_t getHDOP(void) const

Horizontal dilution of precision in tenths (i.e., divide by 10 to get true HDOP). ::

bool isValid(void) const

Validity of latest fix. ::
Expand Down Expand Up @@ -113,8 +140,33 @@ Speed over ground, in thousandths of a knot. ::

Clear all stored values. ``isValid()`` will return false. Year, month and day will all be zero. Hour, minute and second time will be set to 99. Speed, course and altitude will be set to ``LONG_MIN``; the altitude validity flag will be false. Latitude and longitude will be set to 999 degrees.

Additional Methods in Fork
-------------------------

::

fixType_t getFix(void) const

Returns the fix type (None/2D/3D). ::

char getAutofix(void) const

Returns fix selection mode (Auto/Manual). ::

long getSpeedMS(void) const

Speed over ground in thousandths of a meter per second. ::

uint8_t getPDOP(void) const

Position dilution of precision in tenths. ::

uint8_t getVDOP(void) const

Vertical dilution of precision in tenths.

Callback and associated functions
---------------------------------
--------------------------------

::

Expand All @@ -124,9 +176,13 @@ Callback and associated functions

void setUnknownSentenceHandler(void (*handler)(MicroNMEA& nmea))

``setUnknownSentenceHandler()`` enables MicroNMEA to call a function when a valid but unknown NMEA command is
``setUnknownSentenceHandler()`` enables MicroNMEA to call a function when a valid but unknown NMEA command is
received. The callback function should accept a single parameter (a ``MicroNMEA`` object passed by reference) and return ``void``. ::

void onTimeReceived(void (*handler)(MicroNMEA& nmea))

Register a callback function to be called when valid time information is received. ::

const char* getSentence(void) const

Return the current NMEA sentence. Useful when using callback functions. ::
Expand All @@ -139,17 +195,16 @@ Return the talker ID from the last processed NMEA sentence. The meaning is the s

Return the message ID from the last processed NMEA sentence, e.g, ``RMC``, ``GGA``. Useful when using callback functions.


Contributors
------------

- Steve Marple
- Christopher Liebman
- per1234
- Noah-Jonathan Rosa
- Philipp Tölke
* Steve Marple
* Christopher Liebman
* per1234
* Noah-Jonathan Rosa
* Philipp Tölke

Documentation
-------------

For documentation please see Read The Docs, https://micronmea.readthedocs.io/en/latest/.
For documentation please see Read The Docs, <https://micronmea.readthedocs.io/en/latest/>.
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,11 @@ void loop(void)
ledState = !ledState;
digitalWrite(LED_BUILTIN, ledState);

// Output GPS information from previous second
console.print("Valid fix: ");
console.println(nmea.isValid() ? "yes" : "no");
// Output GPS information from previous second
console.print ("Valid fix: ");
console.print (nmea.isValid () ? "yes " : "no ");
console.print (nmea.getFix () == nmea.FIX_NONE ? "No Fix" : nmea.getFix () == nmea.FIX_2D ? "2D" : "3D");
console.println (nmea.getAutofix () == 'A' ? " Auto" : " Manual");

console.print("Nav. system: ");
if (nmea.getNavSystem())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,11 @@ void loop(void)
ledState = !ledState;
digitalWrite(LED_BUILTIN, ledState);

// Output GPS information from previous second
console.print("Valid fix: ");
console.println(nmea.isValid() ? "yes" : "no");
// Output GPS information from previous second
console.print ("Valid fix: ");
console.print (nmea.isValid () ? "yes " : "no ");
console.print (nmea.getFix () == nmea.FIX_NONE ? "No Fix" : nmea.getFix () == nmea.FIX_2D ? "2D" : "3D");
console.println (nmea.getAutofix () == 'A' ? " Auto" : " Manual");

console.print("Nav. system: ");
if (nmea.getNavSystem())
Expand Down
8 changes: 5 additions & 3 deletions examples/demo/demo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ void loop(void)
ledState = !ledState;
digitalWrite(LED_BUILTIN, ledState);

// Output GPS information from previous second
console.print("Valid fix: ");
console.println(nmea.isValid() ? "yes" : "no");
// Output GPS information from previous second
console.print ("Valid fix: ");
console.print (nmea.isValid () ? "yes " : "no ");
console.print (nmea.getFix () == nmea.FIX_NONE ? "No Fix" : nmea.getFix () == nmea.FIX_2D ? "2D" : "3D");
console.println (nmea.getAutofix () == 'A' ? " Auto" : " Manual");

console.print("Nav. system: ");
if (nmea.getNavSystem())
Expand Down
43 changes: 41 additions & 2 deletions src/MicroNMEA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ bool MicroNMEA::process(char c)
if (data != nullptr && strcmp(&_messageID[0], "GGA") == 0)
return processGGA(data);
else if (data != nullptr && strcmp(&_messageID[0], "RMC") == 0)
return processRMC(data);
return processRMC (data);
else if (strcmp (&_messageID[0], "GSA") == 0)
return processGSA (data);
else if (_unknownSentenceHandler)
(*_unknownSentenceHandler)(*this);
}
Expand Down Expand Up @@ -294,6 +296,38 @@ const char* MicroNMEA::parseDate(const char* s)
return skipField(s + 6);
}

bool MicroNMEA::processGSA (const char* s) {
_autofix = *s;
s=s+2; // Skip fix and comma
long fixType = parseFloat (s, 0, &s);
_isValid = (fixType > 1);

switch(fixType) {
case 1:
_fix = FIX_NONE;
break;
case 2:
_fix = FIX_2D;
break;
case 3:
_fix = FIX_3D;
break;
default:
_fix = FIX_NONE;
break;
}

// Skip 12 satellite ID fields
for (int i = 0; i < 12; i++) {
// Skip 12 satellite ID fields
s = skipField (s);
}
_pdop = parseFloat (s, 1, &s);
_hdop = parseFloat (s, 1, &s);
_vdop = parseFloat (s, 1, &s);

return true;
}

bool MicroNMEA::processGGA(const char *s)
{
Expand Down Expand Up @@ -327,8 +361,13 @@ bool MicroNMEA::processGGA(const char *s)
s += 2; // Skip E/W and comma
}
_isValid = (*s >= '1' && *s <= '5');
// Notify time has been obtained
if (_timeHandler && _isValid) {
(*_timeHandler)(*this);
}

s += 2; // Skip position fix flag and comma
long tmp = parseFloat(s, 0, &s);
long tmp = parseFloat (s, 0, &s);
_numSat = (tmp > 255 ? 255 : (tmp < 0 ? 0 : tmp));
if (s == nullptr)
return false;
Expand Down
Loading