Allows for a GPS module to be connected to a serial port and exposes an easy to use API to get the GPS data. New feature, added Mbed/LPC17xx RTC synchronisation

Dependents:   SatGPS AntiTheftGPS FLIGHT_CONTROL_AND_COMMUNICATIONS_SYSTEM GPS-Lora ... more

Embed: (wiki syntax)

« Back to documentation index

The MODGPS API

The MODGPS API

Functions

bool isTimeValid (void)
 Is the time reported by the GPS valid.
int getGPSquality (void)
 Is the positional fix reported by the GPS valid.
int numOfSats (void)
 How many satellites were used in the last fix.
double latitude (void)
 What was the last reported latitude (in degrees)
double longitude (void)
 What was the last reported longitude (in degrees)
double altitude (void)
 What was the last reported altitude (in kilometers)
double height (void)
 What was the last reported altitude/height (in kilometers)
GPS_VTGvtg (GPS_VTG *g)
 Get all vector parameters together.
GPS_VTGvtg (void)
 Get all vector parameters together.
GPS_Geodeticgeodetic (GPS_Geodetic *g)
 Get all three geodetic parameters together.
GPS_Geodeticgeodetic (void)
 Get all three geodetic parameters together.
GPS_TimetimeNow (GPS_Time *n)
 Take a snap shot of the current time.
GPS_TimetimeNow (void)
 Take a snap shot of the current time.
double julianDayNumber (void)
 Return the curent day.
double julianDate (void)
 Return the curent date/time as a Julian date.
double siderealDegrees (void)
 Get the current sidereal degree angle.
double siderealHA (void)
 Get the current sidereal hour angle.
void ppsAttach (PinName irq, ppsEdgeType type=ppsRise)
 Optionally, connect a 1PPS single to an Mbed pin.
template<typename T >
void attach_pps (T *tptr, void(T::*mptr)(void))
 Attach a user object/method callback function to the PPS signal.
void attach_pps (void(*fptr)(void))
 Attach a user callback function to the PPS signal.
template<typename T >
void attach_rmc (T *tptr, void(T::*mptr)(void))
 Attach a user callback function to the NMEA RMC message processed signal.
void attach_rmc (void(*fptr)(void))
 Attach a user callback function to the NMEA RMC message processed signal.
template<typename T >
void attach_gga (T *tptr, void(T::*mptr)(void))
 Attach a user callback function to the NMEA GGA message processed signal.
void attach_gga (void(*fptr)(void))
 Attach a user callback function to the NMEA GGA message processed signal.
template<typename T >
void attach_vtg (T *tptr, void(T::*mptr)(void))
 Attach a user callback function to the NMEA VTG message processed signal.
void attach_vtg (void(*fptr)(void))
 Attach a user callback function to the NMEA VTG message processed signal.
template<typename T >
void attach_ukn (T *tptr, void(T::*mptr)(void))
 Attach a user callback function to the unknown NMEA message.
void attach_ukn (void(*fptr)(void))
 Attach a user callback function to the unknown NMEA message.
void baud (int baudrate)
 Set the baud rate the GPS module is using.
void format (int bits, Parity parity, int stop_bits)
 Set the serial port format the GPS module is using.
void NmeaOnUart0 (bool b)
 Send incoming GPS bytes to Uart0.

Function Documentation

double altitude ( void   ) [inherited]

What was the last reported altitude (in kilometers)

Method returns a double in kilometers.

     // Assuming we have a GPS object previously created...
     GPS gps(NC, p9); 

     double altitude = gps.altitude();
Returns:
double Kilometers

Definition at line 87 of file GPS.cpp.

void attach_gga ( T *  tptr,
void(T::*)(void)  mptr 
) [inherited]

Attach a user callback function to the NMEA GGA message processed signal.

Attach a user callback object/method to call when an NMEA GGA packet has been processed.

     class FOO {
     public:
         void myCallback(void);
     };

     GPS gps(NC, p9); 
     Foo foo;

     gps.attach_gga(foo, &FOO::myCallback);
Parameters:
tptrpointer to the object to call the member function on
mptrpointer to the member function to be called

Definition at line 629 of file GPS.h.

void attach_gga ( void(*)(void)  fptr ) [inherited]

Attach a user callback function to the NMEA GGA message processed signal.

Attach a user callback function pointer to call when an NMEA GGA packet has been processed.

     void myCallback(void) { ... }

     GPS gps(NC, p9); 
     Foo foo;

     gps.attach_gga(&myCallback);
Parameters:
fptrCallback function pointer.

Definition at line 648 of file GPS.h.

void attach_pps ( T *  tptr,
void(T::*)(void)  mptr 
) [inherited]

Attach a user object/method callback function to the PPS signal.

Attach a user callback object/method to call when the 1PPS signal activates.

     class FOO {
     public:
         void myCallback(void);
     };

     GPS gps(NC, p9); 
     Foo foo;

     gps.attach_pps(foo, &FOO::myCallback);
Parameters:
tptrpointer to the object to call the member function on
mptrpointer to the member function to be called

Definition at line 537 of file GPS.h.

void attach_pps ( void(*)(void)  fptr ) [inherited]

Attach a user callback function to the PPS signal.

Attach a user callback function pointer to call when the 1PPS signal activates.

     void myCallback(void) { ... }

     GPS gps(NC, p9); 
     Foo foo;

     gps.attach_pps(&myCallback);
Parameters:
fptrCallback function pointer

Definition at line 556 of file GPS.h.

void attach_rmc ( T *  tptr,
void(T::*)(void)  mptr 
) [inherited]

Attach a user callback function to the NMEA RMC message processed signal.

Attach a user callback object/method to call when an NMEA RMC packet has been processed.

     class FOO {
     public:
         void myCallback(void);
     };

     GPS gps(NC, p9); 
     Foo foo;

     gps.attach_rmc(foo, &FOO::myCallback);
Parameters:
tptrpointer to the object to call the member function on
mptrpointer to the member function to be called

Definition at line 583 of file GPS.h.

void attach_rmc ( void(*)(void)  fptr ) [inherited]

Attach a user callback function to the NMEA RMC message processed signal.

Attach a user callback function pointer to call when an NMEA RMC packet has been processed.

     void myCallback(void) { ... }

     GPS gps(NC, p9); 
     Foo foo;

     gps.attach_rmc(&myCallback);
Parameters:
fptrCallback function pointer.

Definition at line 602 of file GPS.h.

void attach_ukn ( T *  tptr,
void(T::*)(void)  mptr 
) [inherited]

Attach a user callback function to the unknown NMEA message.

Attach a user callback object/method to call when an unknown NMEA packet.

     class FOO {
     public:
         void myCallback(void);
     };

     GPS gps(NC, p9); 
     Foo foo;

     gps.attach_ukn(foo, &FOO::myCallback);
Parameters:
tptrpointer to the object to call the member function on
mptrpointer to the member function to be called

Definition at line 722 of file GPS.h.

void attach_ukn ( void(*)(void)  fptr ) [inherited]

Attach a user callback function to the unknown NMEA message.

Attach a user callback function pointer to call when an unknown NMEA.

     void myCallback(void) { ... }

     GPS gps(NC, p9); 
     Foo foo;

     gps.attach_ukn(&myCallback);
Parameters:
fptrCallback function pointer.

Definition at line 741 of file GPS.h.

void attach_vtg ( T *  tptr,
void(T::*)(void)  mptr 
) [inherited]

Attach a user callback function to the NMEA VTG message processed signal.

Attach a user callback object/method to call when an NMEA VTG packet has been processed.

     class FOO {
     public:
         void myCallback(void);
     };

     GPS gps(NC, p9); 
     Foo foo;

     gps.attach_vtg(foo, &FOO::myCallback);
Parameters:
tptrpointer to the object to call the member function on
mptrpointer to the member function to be called

Definition at line 676 of file GPS.h.

void attach_vtg ( void(*)(void)  fptr ) [inherited]

Attach a user callback function to the NMEA VTG message processed signal.

Attach a user callback function pointer to call when an NMEA VTG packet has been processed.

     void myCallback(void) { ... }

     GPS gps(NC, p9); 
     Foo foo;

     gps.attach_vtg(&myCallback);
Parameters:
fptrCallback function pointer.

Definition at line 695 of file GPS.h.

void baud ( int  baudrate ) [inherited]

Set the baud rate the GPS module is using.

Set the baud rate of the serial port

See also:
http://mbed.org/projects/libraries/api/mbed/trunk/Serial#Serial.baud
Parameters:
baudrateThe baudrate to set.

Definition at line 783 of file GPS.h.

void format ( int  bits,
Parity  parity,
int  stop_bits 
) [inherited]

Set the serial port format the GPS module is using.

Set the transmission format used by the Serial port

See also:
http://mbed.org/projects/libraries/api/mbed/trunk/Serial#Serial.format
Parameters:
bits- The number of bits in a word (5-8; default = 8)
parity- The parity used (GPS::None, GPS::Odd, GPS::Even, GPS::Forced1, GPS::Forced0; default = GPS::None)
stop_bits- The number of stop bits (1 or 2; default = 1)

Definition at line 796 of file GPS.h.

GPS_Geodetic * geodetic ( GPS_Geodetic g ) [inherited]

Get all three geodetic parameters together.

Pass a pointer to a GPS_Geodetic object and the current GPS data will be copied into it.

     // Assuming we have a GPS object previously created...
     GPS gps(NC, p9); 

     // Then get the data...
     GPS_Geodetic p;
     gps.geodetic(&p);
     printf("Latitude  = %.4f", p.lat);
     printf("Longitude = %.4f", p.lon);
     printf("Altitude  = %.4f", p.alt);
Parameters:
gA GSP_Geodetic pointer to an existing GPS_Geodetic object.
Returns:
GPS_Geodetic * The pointer passed in.

Definition at line 95 of file GPS.cpp.

GPS_Geodetic* geodetic ( void   ) [inherited]

Get all three geodetic parameters together.

Get all the geodetic data at once. For example:-

     // Assuming we have a GPS object previously created...
     GPS gps(NC, p9); 

     // Then get the data...
     GPS_Geodetic *p = gps.geodetic();
     printf("Latitude = %.4f", p->lat);
     delete(p); // then remember to delete the object to prevent memory leaks.
Returns:
GPS_Geodetic * A pointer to the data.

Definition at line 352 of file GPS.h.

int getGPSquality ( void   ) [inherited]

Is the positional fix reported by the GPS valid.

Method used to check the validity of the positional data. This method returns the GGA field, 0 is "bad, 1 is "ok", etc. See the NMEA GGA description for more details.

     // Assuming we have a GPS object previously created...
     GPS gps(NC, p9); 

     if (gps.getGPSquality() == 0) {
         // The location fix is no good/not accurate :(
     }
     else {
         // All good, can use last fix data.
     )
Returns:
int 0 on no fix, 1... (see NMEA GGA for more details).

Definition at line 172 of file GPS.h.

double height ( void   ) [inherited]

What was the last reported altitude/height (in kilometers)

See also:
altitude()
     // Assuming we have a GPS object previously created...
     GPS gps(NC, p9); 

     double height = gps.height();

Note, this is identical to altitude()

See also:
altitude()
Returns:
double Kilometers

Definition at line 260 of file GPS.h.

bool isTimeValid ( void   ) [inherited]

Is the time reported by the GPS valid.

Method used to check the validity of the time the GPS module is reporting.

     // Assuming we have a GPS object previously created...
     GPS gps(NC, p9); 

     if (gps.isTimeValid()) {
         // Time is valid :)
     }
     else {
         // Doh, time is not valid :(
     )
Returns:
bool true if valid, false otherwise

Definition at line 148 of file GPS.h.

double julianDate ( void   ) [inherited]

Return the curent date/time as a Julian date.

     // Assuming we have a GPS object previously created...
     GPS gps(NC, p9); 

     // Then get the Julian Date.
     double julianDate = gps.julianDate();
Returns:
double The Julian Date as a double.

Definition at line 427 of file GPS.h.

double julianDayNumber ( void   ) [inherited]

Return the curent day.

     // Assuming we have a GPS object previously created...
     GPS gps(NC, p9); 

     // Then get the Julain Day Number.
     double julianDayNumber = gps.julianDayNumber();
Returns:
double The Julian Date as a double.

Definition at line 411 of file GPS.h.

double latitude ( void   ) [inherited]

What was the last reported latitude (in degrees)

Method returns a double in degrees, positive being North, negative being South.

     // Assuming we have a GPS object previously created...
     GPS gps(NC, p9); 

     double latitude = gps.latitude();
Returns:
double Degrees

Definition at line 71 of file GPS.cpp.

double longitude ( void   ) [inherited]

What was the last reported longitude (in degrees)

Method returns a double in degrees, positive being East, negative being West.

     // Assuming we have a GPS object previously created...
     GPS gps(NC, p9); 

     double logitude = gps.logitude();
Returns:
double Degrees

Definition at line 79 of file GPS.cpp.

void NmeaOnUart0 ( bool  b ) [inherited]

Send incoming GPS bytes to Uart0.

Send incoming GPS bytes to Uart0

This can be useful for printing out the bytes from the GPS onto a the common debug port Uart0. Note, Uart0 should have been setup and initialised before switching this on. Also, realistically, you should ensure Uart0 has a higher baud rate than that being used by the GPS. Sending of bytes to Uart0 is "raw" and should only be used to initially gather data and should NOT be used as part of the application design. If you need to forward on the data you should come up with a proper strategy.

Parameters:
b- True to send to Uart0, false otherwise

Definition at line 814 of file GPS.h.

int numOfSats ( void   ) [inherited]

How many satellites were used in the last fix.

Method returns the number of GPS satellites used on the last fix.

     // Assuming we have a GPS object previously created...
     GPS gps(NC, p9); 

     int sats = gps.numOfSats();
Returns:
int The number of satellites.

Definition at line 189 of file GPS.h.

void ppsAttach ( PinName  irq,
ppsEdgeType  type = ppsRise 
) [inherited]

Optionally, connect a 1PPS single to an Mbed pin.

Optional: If the GPS unit has a 1PPS output, use this to connect that to our internal ISR. Using the 1PPS increases the GPS_Time time accuracy from +/-0.25s to +/-0.001s

     // Assuming we have a GPS object previously created...
     GPS gps(NC, p9); 

     gps.ppsAttach(p29); // default to GPS::ppsRise, rising edge. 

     // Or...
     gps.ppsAttach(p29, GPS::ppsRise ); // The default.

     // Or...
     gps.ppsAttach(p29, GPS::ppsFall ); // If a falling edge.

Note, before using this function you should attach an actual callback function using attach_pps()

See also:
attach_pps()
Parameters:
irqA PinName to attach
typeThe type of edge, MAX7456::ppsRise OR MAX7456::ppsFall

Definition at line 54 of file GPS.cpp.

double siderealDegrees ( void   ) [inherited]

Get the current sidereal degree angle.

     // Assuming we have a GPS object previously created...
     GPS gps(NC, p9); 
     double sidereal = gps.siderealDegrees();
Returns:
double Sidereal degree angle..

Definition at line 441 of file GPS.h.

double siderealHA ( void   ) [inherited]

Get the current sidereal hour angle.

     // Assuming we have a GPS object previously created...
     GPS gps(NC, p9); 
     double sidereal = gps.siderealHA();
Returns:
double Sidereal degree angle..

Definition at line 455 of file GPS.h.

GPS_Time* timeNow ( void   ) [inherited]

Take a snap shot of the current time.

Pass a pointer to a GPS_Time object to get a copy of the current time and date as reported by the GPS.

     // Assuming we have a GPS object previously created...
     GPS gps(NC, p9); 

     // Then get the data...
     GPS_Time *t = gps.timeNow();
     printf("Year = %d", t->year);
     delete(t); // Avoid memory leaks.
Returns:
GPS_Time * The pointer passed in.

Definition at line 395 of file GPS.h.

GPS_Time* timeNow ( GPS_Time n ) [inherited]

Take a snap shot of the current time.

Pass a pointer to a GPS_Time object to get a copy of the current time and date as reported by the GPS.

     // Assuming we have a GPS object previously created...
     GPS gps(NC, p9); 

     // Then get the data...
     GPS_Time t;
     gps.timeNow(&t);
     printf("Year = %d", t.year);
Parameters:
nA GPS_Time * pointer to an existing GPS_Time object.
Returns:
GPS_Time * The pointer passed in.

Definition at line 374 of file GPS.h.

GPS_VTG* vtg ( void   ) [inherited]

Get all vector parameters together.

Get all the vector data at once. For example:-

     // Assuming we have a GPS object previously created...
     GPS gps(NC, p9); 

     // Then get the data...
     GPS_VTG *p = gps.vtg();
     printf("Speed (knots)  = %.4f", p->velocity_knots);
     printf("Speed (kps)    = %.4f", p->velocity_kps);
     printf("Track (true)  = %.4f", p->track_true);
     printf("Track (mag)    = %.4f", p->track_mag);     
     delete(p); // then remember to delete the object to prevent memory leaks.
Returns:
GPS_Geodetic * A pointer to the data.

Definition at line 308 of file GPS.h.

GPS_VTG * vtg ( GPS_VTG g ) [inherited]

Get all vector parameters together.

Pass a pointer to a GPS_VTG object and the current GPS data will be copied into it.

     // Assuming we have a GPS object previously created...
     GPS gps(NC, p9); 

     // Then get the data...
     GPS_VTG p;
     gps.vtg(&p);
     printf("Speed (knots)  = %.4f", p.velocity_knots);
     printf("Speed (kps)    = %.4f", p.velocity_kps);
     printf("Track (true)  = %.4f", p.track_true);
     printf("Track (mag)    = %.4f", p.track_mag);
Parameters:
gA GSP_VTG pointer to an existing GPS_VTG object.
Returns:
GPS_VTG * The pointer passed in.

Definition at line 111 of file GPS.cpp.