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

API for the U-BLOX 6 and SIM28 GPS Modules. More...

Detailed Description

UPM support for the U-BLOX 6 GPS module. It is also compatible with the SIM28 GPS module.

ublox6.jpg
// Instantiate a Ublox6 GPS device on uart 0.
upm::Ublox6* nmea = new upm::Ublox6(0);
// make sure port is initialized properly. 9600 baud is the default.
if (!nmea->setupTty(B9600))
{
cerr << "Failed to setup tty port parameters" << endl;
return 1;
}
// Collect and output NMEA data. There are various libraries out on
// the Internet, such as tinyGPS or tinyGPS++ that can handle
// decoding NMEA data and presenting it in a more easily accessible
// format. This example will just check for, and read raw NMEA data
// from the device and output it on stdout.
// This device also supports numerous configuration options, which
// you can set with writeData(). Please refer to the Ublox-6 data
// sheet for further information on the formats of the data sent and
// received, and the various operating modes available.
char nmeaBuffer[bufferLength];
while (shouldRun)
{
// we don't want the read to block in this example, so always
// check to see if data is available first.
if (nmea->dataAvailable())
{
int rv = nmea->readData(nmeaBuffer, bufferLength);
if (rv > 0)
write(1, nmeaBuffer, rv);
if (rv < 0) // some sort of read error occurred
{
cerr << "Port read error." << endl;
break;
}
continue;
}
usleep(100000); // 100ms
}

Public Member Functions

 Ublox6 (int uart)
 
 ~Ublox6 ()
 
bool dataAvailable ()
 
int readData (char *buffer, int len)
 
int writeData (char *buffer, int len)
 
bool setupTty (speed_t baud=B9600)
 

Protected Member Functions

int ttyFd ()
 

Constructor & Destructor Documentation

Ublox6 ( int  uart)

Ublox6 object constructor

Parameters
uartDefault UART to use (0 or 1)
~Ublox6 ( )

Ublox6 object destructor

Member Function Documentation

bool dataAvailable ( )

Checks to see if there is data available for reading

Returns
True if there is data available for reading
int readData ( char *  buffer,
int  len 
)

Reads any available data in a user-supplied buffer. Note: the call blocks until data is available to be read. Use dataAvailable() to determine whether there is data available beforehand, to avoid blocking.

Parameters
bufferBuffer to hold the data read
lenLength of the buffer
Returns
the Number of bytes read
int writeData ( char *  buffer,
int  len 
)

Writes the data in the buffer to the device

Parameters
bufferBuffer to hold the data read
lenLength of the buffer
Returns
Number of bytes written
bool setupTty ( speed_t  baud = B9600)

Sets up proper tty I/O modes and the baud rate. The default baud rate is 9,600 (B9600).

Parameters
baudDesired baud rate
Returns
True if successful

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