upm  1.3.0
Sensor/Actuator repository for libmraa (v1.7.0)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Public Member Functions | Protected Attributes
NMEAGPS Class Reference

API for the NMEA GPS Module. More...

Detailed Description

This driver was tested with a number of GPS devices that emit NMEA data via a serial interface of some sort (typically a UART).

The I2C capablity was tested with a UBLOX LEA-6H based GPS shield from DFRobot. Currently, the I2C capability is only supported for UBLOX devices (or compatibles) that conform to the specifications outlined in the u-blox6 Receiver Description Protocol Specification, Chapter 4, DDC Port.

An example using the UART.

// Instantiate a NMEA_GPS sensor on uart 0 at 9600 baud with enable
// pin on D3. If you do not need an enable pin, you can specify -1.
upm::NMEAGPS *sensor = new upm::NMEAGPS(0, 9600, 3);
// loop, dumping NMEA data out as fast as it comes in
while (shouldRun && sensor->dataAvailable(5000))
cout << sensor->readStr(bufferLength);
if (shouldRun)
cerr << "Timed out" << endl;

An example using I2C.

// Instantiate a NMEA_GPS UBLOX based i2c sensor on i2c bus 0 at
// address 0x42
upm::NMEAGPS *sensor = new upm::NMEAGPS(0, 0x42);
// loop, dumping NMEA data out as fast as it comes in
while (shouldRun)
if (sensor->dataAvailable(0))
cout << sensor->readStr(bufferLength);

Public Member Functions

 NMEAGPS (unsigned int uart, unsigned int baudrate, int enable_pin)
 NMEAGPS (unsigned int bus, uint8_t addr)
std::string readStr (size_t size)
int writeStr (std::string buffer)
void enable (bool enable)
void setBaudrate (unsigned int baudrate)
bool dataAvailable (unsigned int millis)

Protected Attributes

nmea_gps_context m_nmea_gps

Constructor & Destructor Documentation

NMEAGPS ( unsigned int  uart,
unsigned int  baudrate,
int  enable_pin 

NMEAGPS object constructor for a UART

uartSpecify which uart to use.
baudrateSpecify the baudrate to use. The device defaults to 9600 baud.
enable_pinSpecify the GPIO pin to use for the enable pin, -1 to not use an enable pin.
NMEAGPS ( unsigned int  bus,
uint8_t  addr 

NMEAGPS object constructor for a UBLOX I2C interface

busSpecify which the I2C bus to use.
addrSpecify the I2C address to use. For UBLOX devices, this typically defaults to 0x42.

NMEAGPS object destructor

Member Function Documentation

std::string readStr ( size_t  size)

Read character data from the device.

sizeThe maximum number of characters to read.
string containing the data read.
int writeStr ( std::string  buffer)

Write character data to the device. This is only valid for a UART device.

bufferThe string containing the data to write.
The number of bytes written.
void enable ( bool  enable)

Enable or disable the device. When disabled, the device enters a low power mode and does not emit NMEA data. It will still maintain location data however.

enabletrue to enable the device, false otherwise.
void setBaudrate ( unsigned int  baudrate)

Set the baudrate of the device. By default, the constructor will set the baudrate to 9600. This is only valid for UART devices.

baudrateThe baud rate to set for the device.
bool dataAvailable ( unsigned int  millis)

Determine whether there is data available to be read. In the case of a UART, this function will wait up to "millis" milliseconds for data to become available. In the case of an I2C device, the millis argument is ignored and the function will return immediately, indicating whether data is available.

millisThe number of milliseconds to wait for data to become available.
true if data is available to be read, false otherwise.
Collaboration diagram for NMEAGPS:
Collaboration graph

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