Interface with a GPS unit (tested with Garmin Geko 301) using NMEA 0183. More...
#include <Devices/GPS.H>
Public Member Functions | |
GPS (OptionManager &mgr, const std::string &descrName="GPS", const std::string &tagName="GPS") | |
Constructor. | |
void | setListener (rutz::shared_ptr< GPSlistener > &listener) |
setup a listener that will be called each time new data is received | |
virtual | ~GPS () |
destructor | |
bool | getData (GPSdata &data) |
Get current data from the GPS unit. | |
void | run () |
Running thread. | |
Protected Member Functions | |
void | start2 () |
get started | |
void | stop1 () |
This is called from within stop() before the subcomponents stop. | |
Protected Attributes | |
nub::soft_ref< Serial > | itsSerial |
get stopped |
Interface with a GPS unit (tested with Garmin Geko 301) using NMEA 0183.
This is a multi-threaded class which continuously polls the unit for data and updates an internal copy of a GPSdata struct. Users can get the most up-to-date data at any time using getData(), or can setup a GPSlistener that will be called each time new data is available. Note that communication with the GPS unit operates at 4800 bauds, so the actual rate of data refresh is quite low (2s) and querying for data more often than once every two seconds is useless.
The Geko 301 has a true compass and altimeter/barometer. These need to be queried separately from the standard GPS summary query. This driver achieves that.
The Geko 301 is stated to support the following NMEA 0183 sentences: GPGGA, GPGLL, GPGSA, GPGSV, GPRMB, GPRMC, GPTRE, GPVTG, GPWPL, GPBOD, PGRME, PGRMM, PGRMZ, PSLIB. Not all of the sentences may be used by this driver, however (in particular, waypoint functionality can be more easily achieved in the main C++ code than in the GPS unit).
Here is a typical sequence emitted by the Geko 301 when set in NMEA output mode:
$GPRMC,082158,A,3403.4155,N,11815.0936,W,0.0,13.9,211104,13.5,E,A*05 $GPRMB,A,,,,,,,,,,,,A,A*0B $GPGGA,082158,3403.4155,N,11815.0936,W,1,08,1.1,127.6,M,-31.8,M,,*7A $GPGSA,A,3,01,03,,14,15,18,19,21,22,,,,2.2,1.1,1.9*3B $GPGSV,3,1,10,01,27,216,36,03,40,254,41,09,19,058,00,14,75,207,39*7B $GPGSV,3,2,10,15,74,090,42,18,35,058,42,19,34,296,37,21,27,123,43*72 $GPGSV,3,3,10,22,60,020,35,25,02,184,00*72 $GPGLL,3403.4155,N,11815.0936,W,082158,A,A*52 $GPBOD,,T,,M,,*47 $PGRME,4.5,M,6.7,M,8.0,M*26 $PGRMZ,424,f*06 $HCHDG,92.6,,,13.5,E*23 $GPRTE,1,1,c,*37
Definition at line 138 of file GPS.H.
GPS::GPS | ( | OptionManager & | mgr, | |
const std::string & | descrName = "GPS" , |
|||
const std::string & | tagName = "GPS" | |||
) |
Constructor.
You can set which serial device to use by setting the ModelParameter GPSDevName
Definition at line 93 of file GPS.C.
References ModelComponent::addSubComponent(), and itsSerial.
bool GPS::getData | ( | GPSdata & | data | ) |
void GPS::run | ( | ) |
Running thread.
Do not call directly, this is called by our GPS polling thread
Definition at line 145 of file GPS.C.
References GPSdata::altitude, GPSdata::epe, GPSdata::fixda, GPSdata::fixho, GPSdata::fixmi, GPSdata::fixmo, GPSdata::fixse, GPSdata::fixtype, GPSdata::fixye, GPSdata::galtitude, rutz::shared_ptr< T >::get(), GPSdata::hdil, GPSdata::heading, GPSdata::hpe, itsSerial, GPSdata::latitude, GPSdata::longitude, GPSdata::magvar, GPSdata::nsat, GPSdata::pdil, GPSdata::speed, GPSdata::vdil, and GPSdata::vpe.
void GPS::setListener | ( | rutz::shared_ptr< GPSlistener > & | listener | ) |
void GPS::start2 | ( | ) | [protected, virtual] |
void GPS::stop1 | ( | ) | [protected, virtual] |
This is called from within stop() before the subcomponents stop.
Reimplemented from ModelComponent.
nub::soft_ref<Serial> GPS::itsSerial [protected] |