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

GPS Class Reference

GPS module. More...

#include <GPS.h>

Public Types

enum  ppsEdgeType { ppsRise = 0, ppsFall }
 

The PPS edge type to interrupt on.

More...
enum  Parity
 

A copy of the Serial parity enum.

More...

Public Member Functions

 GPS (PinName tx, PinName rx, const char *name=NULL)
 GPS constructor.
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.
void ppsUnattach (void)
 Remove any 1PPS signal previously attached.
void rx_irq (void)
 GPS serial receive interrupt handler.
void pps_irq (void)
 GPS pps interrupt handler.
void ticktock (void)
 10ms Ticker callback.
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.
char * setGga (char *s)
 Set's the GGA string memory pointer.
char * setRmc (char *s)
 Set's the RMC string memory pointer.
char * setVtg (char *s)
 Set's the VTG string memory pointer.
char * setUkn (char *s)
 Set's the UKN string memory pointer.
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.

Data Fields

void * _base
 A pointer to the UART peripheral base address being used.
char buffer [2][GPS_BUFFER_LEN]
 The RX serial buffer.
int active_buffer
 The current "active" buffer, i.e. the buffer the ISR is writing to.
int rx_buffer_in
 The active buffer "in" pointer.
bool process_required
 Boolean flag set when the "passive" buffer is full and needs processing.
FunctionPointer cb_pps
 A callback object for the 1PPS user API.
FunctionPointer cb_rmc
 A callback object for the NMEA RMS message processed signal user API.
FunctionPointer cb_gga
 A callback object for the NMEA GGA message processed signal user API.
FunctionPointer cb_vtg
 A callback object for the NMEA RMS message processed signal user API.
FunctionPointer cb_ukn
 A callback object for the NMEA RMS message processed signal user API.

Protected Attributes

bool _ppsInUse
 Flag set true when a GPS PPS has been attached to a pin.
InterruptIn * _pps
 An InterruptIn object to "trigger" on the PPS edge.
Ticker * _second100
 A Ticker object called every 10ms.
GPS_Time theTime
 A GPS_Time object used to hold the last parsed time/date data.
GPS_Geodetic thePlace
 A GPS_Geodetic object used to hold the last parsed positional data.
GPS_VTG theVTG
 A GPS_VTG object used to hold vector data.
char _lastByte
 Used to record the previous byte received.
bool _nmeaOnUart0
 Used for debugging.

Detailed Description

GPS module.

Author:
Andy Kirkham
See also:
http://mbed.org/cookbook/MODGPS
example1.cpp
example2.cpp
The MODGPS API
gps_interfaces.png

Wiring up the GPS module

Example:

 #include "mbed.h"
 #include "GPS.h"

 DigitalOut led1(LED1);
 Serial pc(USBTX, USBRX);
 GPS gps(NC, p10); 

 int main() {
     GPS_Time t;

     // Wait for the GPS NMEA data to become valid.
     while (!gps.isTimeValid()) {
       led1 = !led1;
       wait(1);
     }

     gps.timeNow(&t);

     pc.printf("The time/date is %02d:%02d:%02d %02d/%02d/%04d\r\n",
        t.hour, t.minute, t.second, t.day, t.month, t.year);

     // Wait until at least four satellites produce a position fix and a valid quality.
     while (gps.numOfSats() < 4 && gps.getGPSquality != 0) {
       led1 = !led1;
       wait(1);
     }

     pc.printf("Lat = %.4f Lon = %.4f Alt = %.1fkm\r\n", 
         gps.latitude(), gps.longitude, gps.altitude());

     // Make the LED go steady to indicate we have finished.
     led1 = 1;
 
     while(1) {}
 }

Definition at line 100 of file GPS.h.


Member Enumeration Documentation

enum Parity

A copy of the Serial parity enum.

Definition at line 110 of file GPS.h.

The PPS edge type to interrupt on.

Enumerator:
ppsRise 

Use the rising edge (default).

ppsFall 

Use the falling edge.

Definition at line 104 of file GPS.h.


Constructor & Destructor Documentation

GPS ( PinName  tx,
PinName  rx,
const char *  name = NULL 
)

GPS constructor.

The GPS constructor is used to initialise the GPS object.

Parameters:
txUsually unused and set to NC
rxThe RX pin the GPS is connected to, p10, p14( OR p25), p27.
nameAn option name for RPC usage.

Definition at line 25 of file GPS.cpp.


Member Function Documentation

void pps_irq ( void   )

GPS pps interrupt handler.

Definition at line 190 of file GPS.cpp.

void ppsUnattach ( void   )

Remove any 1PPS signal previously attached.

Definition at line 64 of file GPS.cpp.

void rx_irq ( void   )

GPS serial receive interrupt handler.

Definition at line 198 of file GPS.cpp.

char* setGga ( char *  s )

Set's the GGA string memory pointer.

Parameters:
schar pointer ti string.
Returns:
char s passed in.

Definition at line 751 of file GPS.h.

char* setRmc ( char *  s )

Set's the RMC string memory pointer.

Parameters:
schar pointer ti string.
Returns:
char s passed in.

Definition at line 758 of file GPS.h.

char* setUkn ( char *  s )

Set's the UKN string memory pointer.

Parameters:
schar pointer ti string.
Returns:
char s passed in.

Definition at line 772 of file GPS.h.

char* setVtg ( char *  s )

Set's the VTG string memory pointer.

Parameters:
schar pointer ti string.
Returns:
char s passed in.

Definition at line 765 of file GPS.h.

void ticktock ( void   )

10ms Ticker callback.

Definition at line 127 of file GPS.cpp.


Field Documentation

void* _base

A pointer to the UART peripheral base address being used.

Definition at line 498 of file GPS.h.

char _lastByte [protected]

Used to record the previous byte received.

Definition at line 837 of file GPS.h.

bool _nmeaOnUart0 [protected]

Used for debugging.

Definition at line 845 of file GPS.h.

InterruptIn* _pps [protected]

An InterruptIn object to "trigger" on the PPS edge.

Definition at line 822 of file GPS.h.

bool _ppsInUse [protected]

Flag set true when a GPS PPS has been attached to a pin.

Definition at line 819 of file GPS.h.

Ticker* _second100 [protected]

A Ticker object called every 10ms.

Definition at line 825 of file GPS.h.

The current "active" buffer, i.e. the buffer the ISR is writing to.

Definition at line 504 of file GPS.h.

char buffer[2][GPS_BUFFER_LEN]

The RX serial buffer.

Definition at line 501 of file GPS.h.

FunctionPointer cb_gga

A callback object for the NMEA GGA message processed signal user API.

Definition at line 651 of file GPS.h.

FunctionPointer cb_pps

A callback object for the 1PPS user API.

Definition at line 559 of file GPS.h.

FunctionPointer cb_rmc

A callback object for the NMEA RMS message processed signal user API.

Definition at line 605 of file GPS.h.

FunctionPointer cb_ukn

A callback object for the NMEA RMS message processed signal user API.

Definition at line 744 of file GPS.h.

FunctionPointer cb_vtg

A callback object for the NMEA RMS message processed signal user API.

Definition at line 698 of file GPS.h.

Boolean flag set when the "passive" buffer is full and needs processing.

Definition at line 510 of file GPS.h.

The active buffer "in" pointer.

Definition at line 507 of file GPS.h.

GPS_Geodetic thePlace [protected]

A GPS_Geodetic object used to hold the last parsed positional data.

Definition at line 831 of file GPS.h.

GPS_Time theTime [protected]

A GPS_Time object used to hold the last parsed time/date data.

Definition at line 828 of file GPS.h.

GPS_VTG theVTG [protected]

A GPS_VTG object used to hold vector data.

Definition at line 834 of file GPS.h.