This class provides an API to communicate with a u-blox GNSS chip. The files here were originally part of the C027_Support library (https://developer.mbed.org/teams/ublox/code/C027_Support/ at revision 138:dafbbf31bf76) but have been separated out, primarily for use on the u-blox C030 board where the cellular interace portion of the C027_Support library will instead be provided through the new mbed Cellular API.

Dependents:   example-ublox-at-cellular-interface-ext example-low-power-sleep example-C030-out-of-box-demo example-C030-out-of-box-demo ... more

Embed: (wiki syntax)

« Back to documentation index

GnssSerial Class Reference

GNSS class which uses a serial port as physical interface. More...

#include <gnss.h>

Inherits SerialPipe, and GnssParser.

Inherited by GnssOperations.

Public Types

enum  { WAIT = -1, NOT_FOUND = 0 }

Public Member Functions

 GnssSerial (PinName tx GNSS_IF(=GNSSTXD,=D8), PinName rx GNSS_IF(=GNSSRXD,=D9), int baudrate GNSS_IF(=GNSSBAUD,=9600), int rxSize=512, int txSize=512)
 Constructor.
virtual ~GnssSerial (void)
 Destructor.
virtual bool init (PinName pn=NC)
 Initialise the GNSS device.
virtual int getMessage (char *buf, int len)
 Get a line from the physical interface.
int writeable (void)
 check if writable return the number of free bytes
int putc (int c)
 send a character (blocking)
int put (const void *buffer, int length, bool blocking)
 send a buffer
int readable (void)
 check if readable
int getc (void)
 receive one character from the serial port (blocking)
int get (void *buffer, int length, bool blocking)
 read a buffer from the serial port
virtual int send (const char *buf, int len)
 Send a buffer.
virtual int sendNmea (const char *buf, int len)
 send a NMEA message, this function just takes the payload and calculates and adds checksum.
virtual int sendUbx (unsigned char cls, unsigned char id, const void *buf=NULL, int len=0)
 Send a UBX message, this function just takes the payload and calculates and adds checksum.
void powerOff (void)
 Power off the GNSS, it can be again woken up by an edge on the serial port on the external interrupt pin.
void cutOffPower (void)
 Cuts off the power supply of GNSS by disabling gnssEnable pin Backup supply is provided, can turn it on again by enabling PA15.
int enable_ubx ()
 Enable UBX messages.
eUBX_MESSAGE get_ubx_message (char *)
 GET Message type of receiver UBX message.
tUBX_ACK_ACK decode_ubx_cfg_ack_nak_msg (char *)
 Method to parse contents of UBX ACK-ACK/NAK and return messageid amd class for which ACK is received.
tUBX_NAV_ODO decode_ubx_nav_odo_msg (char *)
 Method to parse contents of UBX_NAV_ODO and return decoded msg.
tUBX_NAV_PVT decode_ubx_nav_pvt_msg (char *)
 Method to parse contents of UBX_NAV_PVT and return decoded msg.
tUBX_LOG_BATCH decode_ubx_log_batch_msg (char *)
 Method to parse contents of UBX_LOG_BATCH and return decoded msg.
tUBX_NAV_STATUS decode_ubx_nav_status_msg (char *)
 Method to parse contents of UBX_NAV_STATUS and return decoded msg.
tUBX_NAV_SAT decode_ubx_nav_sat_msg (char *, int)
 Method to parse contents of UBX_NAV_SAT and return decoded msg.
int ubx_request_batched_data (bool sendMonFirst=false)
 Method to send UBX LOG-RETRIEVEBATCH msg.

Static Public Member Functions

static const char * findNmeaItemPos (int ix, const char *start, const char *end)
 get the first character of a NMEA field.
static bool getNmeaItem (int ix, char *buf, int len, double &val)
 Extract a double value from a buffer containing a NMEA message.
static bool getNmeaItem (int ix, char *buf, int len, int &val, int base)
 Extract a interger value from a buffer containing a NMEA message.
static bool getNmeaItem (int ix, char *buf, int len, char &val)
 Extract a char value from a buffer containing a NMEA message.
static bool getNmeaAngle (int ix, char *buf, int len, double &val)
 Extract a latitude/longitude value from a buffer containing a NMEA message.

Protected Member Functions

virtual int _send (const void *buf, int len)
 Write bytes to the physical interface.
void rxIrqBuf (void)
 receive interrupt routine
void txIrqBuf (void)
 transmit interrupt woutine
void txStart (void)
 start transmission helper
void txCopy (void)
 move bytes to hardware
void _powerOn (void)
 Power on the GNSS module.

Static Protected Member Functions

static int _getMessage (Pipe< char > *pipe, char *buf, int len)
 Get a line from the physical interface.
static int _parseNmea (Pipe< char > *pipe, int len)
 Check if the current offset of the pipe contains a NMEA message.
static int _parseUbx (Pipe< char > *pipe, int len)
 Check if the current offset of the pipe contains a UBX message.

Protected Attributes

Pipe< char > _pipeRx
 receive pipe
Pipe< char > _pipeTx
 transmit pipe
DigitalInOut * _gnssEnable
 IO pin that enables GNSS.

Static Protected Attributes

static const char _toHex [16] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' }
 num to hex conversion

Detailed Description

GNSS class which uses a serial port as physical interface.

Definition at line 340 of file gnss.h.


Member Enumeration Documentation

anonymous enum [inherited]
Enumerator:
WAIT 

wait for more incoming data (the start of a message was found, or no data available)

NOT_FOUND 

a parser concluded the the current offset of the pipe doe not contain a valid message

Definition at line 135 of file gnss.h.


Constructor & Destructor Documentation

GnssSerial ( PinName tx   GNSS_IF=GNSSTXD,=D8,
PinName rx   GNSS_IF=GNSSRXD,=D9,
int baudrate   GNSS_IF=GNSSBAUD,=9600,
int  rxSize = 512,
int  txSize = 512 
)

Constructor.

Parameters:
txis the serial ports transmit pin (GNSS to CPU).
rxis the serial ports receive pin (CPU to GNSS).
baudratethe baudrate of the GNSS use 9600.
rxSizethe size of the serial rx buffer.
txSizethe size of the serial tx buffer.
~GnssSerial ( void   ) [virtual]

Destructor.

Definition at line 631 of file gnss.cpp.


Member Function Documentation

int _getMessage ( Pipe< char > *  pipe,
char *  buf,
int  len 
) [static, protected, inherited]

Get a line from the physical interface.

Parameters:
pipethe receiveing pipe to parse messages .
bufthe buffer to store it.
lensize of the buffer.
Returns:
type and length if something was found, WAIT if not enough data is available, NOT_FOUND if nothing was found.

Definition at line 78 of file gnss.cpp.

int _parseNmea ( Pipe< char > *  pipe,
int  len 
) [static, protected, inherited]

Check if the current offset of the pipe contains a NMEA message.

Parameters:
pipethe receiveing pipe to parse messages.
lennumer of bytes to parse at maximum.
Returns:
length if something was found (including the NMEA frame), WAIT if not enough data is available, NOT_FOUND if nothing was found.

Definition at line 116 of file gnss.cpp.

int _parseUbx ( Pipe< char > *  pipe,
int  len 
) [static, protected, inherited]

Check if the current offset of the pipe contains a UBX message.

Parameters:
pipethe receiveing pipe to parse messages.
lennumer of bytes to parse at maximum.
Returns:
length if something was found (including the UBX frame), WAIT if not enough data is available, NOT_FOUND if nothing was found.

Definition at line 145 of file gnss.cpp.

void _powerOn ( void   ) [protected, inherited]

Power on the GNSS module.

Definition at line 70 of file gnss.cpp.

int _send ( const void *  buf,
int  len 
) [protected, virtual]

Write bytes to the physical interface.

Parameters:
bufthe buffer to write.
lensize of the buffer to write.
Returns:
bytes written.

Implements GnssParser.

Definition at line 680 of file gnss.cpp.

void cutOffPower ( void   ) [inherited]

Cuts off the power supply of GNSS by disabling gnssEnable pin Backup supply is provided, can turn it on again by enabling PA15.

Definition at line 62 of file gnss.cpp.

tUBX_ACK_ACK decode_ubx_cfg_ack_nak_msg ( char *  buf ) [inherited]

Method to parse contents of UBX ACK-ACK/NAK and return messageid amd class for which ACK is received.

Parameters:
buffthe UXB message
Returns:
tUBX_ACK_ACK

Definition at line 403 of file gnss.cpp.

tUBX_LOG_BATCH decode_ubx_log_batch_msg ( char *  buf ) [inherited]

Method to parse contents of UBX_LOG_BATCH and return decoded msg.

Parameters:
buffthe UXB message
Returns:
tUBX_LOG_BATCH

Definition at line 492 of file gnss.cpp.

tUBX_NAV_ODO decode_ubx_nav_odo_msg ( char *  buf ) [inherited]

Method to parse contents of UBX_NAV_ODO and return decoded msg.

Parameters:
buffthe UXB message
Returns:
tUBX_NAV_ODO

Definition at line 413 of file gnss.cpp.

tUBX_NAV_PVT decode_ubx_nav_pvt_msg ( char *  buf ) [inherited]

Method to parse contents of UBX_NAV_PVT and return decoded msg.

Parameters:
buffthe UXB message
Returns:
tUBX_NAV_PVT

Definition at line 443 of file gnss.cpp.

tUBX_NAV_SAT decode_ubx_nav_sat_msg ( char *  buf,
int  length 
) [inherited]

Method to parse contents of UBX_NAV_SAT and return decoded msg.

Parameters:
buffthe UXB message, int length
Returns:
tUBX_NAV_SAT

Definition at line 575 of file gnss.cpp.

tUBX_NAV_STATUS decode_ubx_nav_status_msg ( char *  buf ) [inherited]

Method to parse contents of UBX_NAV_STATUS and return decoded msg.

Parameters:
buffthe UXB message
Returns:
tUBX_NAV_STATUS

Definition at line 543 of file gnss.cpp.

int enable_ubx (  ) [inherited]

Enable UBX messages.

Parameters:
none
Returns:
1 if successful, false otherwise.

Definition at line 305 of file gnss.cpp.

const char * findNmeaItemPos ( int  ix,
const char *  start,
const char *  end 
) [static, inherited]

get the first character of a NMEA field.

Parameters:
ixthe index of the field to find.
startthe start of the buffer.
endthe end of the buffer.
Returns:
the pointer to the first character of the field.

Definition at line 230 of file gnss.cpp.

int get ( void *  buffer,
int  length,
bool  blocking 
) [inherited]

read a buffer from the serial port

Parameters:
pointerto the buffer to read.
lengthnumber of bytes to read
blockingtrue if all bytes shall be read. false if only the available bytes.
Returns:
the number of bytes read.

Definition at line 113 of file serial_pipe.cpp.

eUBX_MESSAGE get_ubx_message ( char *  buff ) [inherited]

GET Message type of receiver UBX message.

Parameters:
buffthe UXB message
Returns:
eUBX_MESSAGE

Definition at line 327 of file gnss.cpp.

int getc ( void   ) [inherited]

receive one character from the serial port (blocking)

Parameters:
thecharacter received

Definition at line 104 of file serial_pipe.cpp.

int getMessage ( char *  buf,
int  len 
) [virtual]

Get a line from the physical interface.

Parameters:
bufthe buffer to store it.
lensize of the buffer.
Returns:
type and length if something was found, WAIT if not enough data is available, NOT_FOUND if nothing was found.

Implements GnssParser.

Definition at line 675 of file gnss.cpp.

bool getNmeaAngle ( int  ix,
char *  buf,
int  len,
double &  val 
) [static, inherited]

Extract a latitude/longitude value from a buffer containing a NMEA message.

Parameters:
ixthe index of the field to extract (will extract ix and ix + 1),
bufthe NMEA message,
lenthe size of the NMEA message,
valthe extracted latitude or longitude,
Returns:
true if successful, false otherwise.

Definition at line 289 of file gnss.cpp.

bool getNmeaItem ( int  ix,
char *  buf,
int  len,
char &  val 
) [static, inherited]

Extract a char value from a buffer containing a NMEA message.

Parameters:
ixthe index of the field to extract.
bufthe NMEA message.
lenthe size of the NMEA message.
valthe extracted value.
Returns:
true if successful, false otherwise.

Definition at line 269 of file gnss.cpp.

bool getNmeaItem ( int  ix,
char *  buf,
int  len,
int &  val,
int  base 
) [static, inherited]

Extract a interger value from a buffer containing a NMEA message.

Parameters:
ixthe index of the field to extract.
bufthe NMEA message.
lenthe size of the NMEA message.
valthe extracted value.
basethe numeric base to be used (e.g. 8, 10 or 16).
Returns:
true if successful, false otherwise.

Definition at line 258 of file gnss.cpp.

bool getNmeaItem ( int  ix,
char *  buf,
int  len,
double &  val 
) [static, inherited]

Extract a double value from a buffer containing a NMEA message.

Parameters:
ixthe index of the field to extract.
bufthe NMEA message.
lenthe size of the NMEA message.
valthe extracted value.
Returns:
true if successful, false otherwise.

Definition at line 246 of file gnss.cpp.

bool init ( PinName  pn = NC ) [virtual]

Initialise the GNSS device.

Parameters:
pnNOT USED.
baudrate
Returns:
true if successful, otherwise false.

Implements GnssParser.

Definition at line 636 of file gnss.cpp.

void powerOff ( void   ) [inherited]

Power off the GNSS, it can be again woken up by an edge on the serial port on the external interrupt pin.

Definition at line 52 of file gnss.cpp.

int put ( const void *  buffer,
int  length,
bool  blocking 
) [inherited]

send a buffer

Parameters:
bufferthe buffer to send
lengththe size of the buffer to send
blocking,iftrue this function will block until all bytes placed in the buffer.
Returns:
the number of bytes written

Definition at line 47 of file serial_pipe.cpp.

int putc ( int  c ) [inherited]

send a character (blocking)

Parameters:
cthe character to send
Returns:
c

Definition at line 40 of file serial_pipe.cpp.

int readable ( void   ) [inherited]

check if readable

Returns:
the size available in the buffer.

Definition at line 99 of file serial_pipe.cpp.

void rxIrqBuf ( void   ) [protected, inherited]

receive interrupt routine

Definition at line 118 of file serial_pipe.cpp.

int send ( const char *  buf,
int  len 
) [virtual, inherited]

Send a buffer.

Parameters:
bufthe buffer to write.
lensize of the buffer to write.
Returns:
bytes written.

Reimplemented in GnssI2C.

Definition at line 184 of file gnss.cpp.

int sendNmea ( const char *  buf,
int  len 
) [virtual, inherited]

send a NMEA message, this function just takes the payload and calculates and adds checksum.

($ and *XX
will be added).

Parameters:
bufthe message payload to write.
lensize of the message payload to write.
Returns:
total bytes written.

Reimplemented in GnssI2C.

Definition at line 189 of file gnss.cpp.

int sendUbx ( unsigned char  cls,
unsigned char  id,
const void *  buf = NULL,
int  len = 0 
) [virtual, inherited]

Send a UBX message, this function just takes the payload and calculates and adds checksum.

Parameters:
clsthe UBX class id.
idthe UBX message id.
bufthe message payload to write.
lensize of the message payload to write.
Returns:
total bytes written.

Reimplemented in GnssI2C.

Definition at line 205 of file gnss.cpp.

void txCopy ( void   ) [protected, inherited]

move bytes to hardware

Definition at line 70 of file serial_pipe.cpp.

void txIrqBuf ( void   ) [protected, inherited]

transmit interrupt woutine

Definition at line 78 of file serial_pipe.cpp.

void txStart ( void   ) [protected, inherited]

start transmission helper

Definition at line 87 of file serial_pipe.cpp.

int ubx_request_batched_data ( bool  sendMonFirst = false ) [inherited]

Method to send UBX LOG-RETRIEVEBATCH msg.

This message is used to request batched data.

Parameters:
bool
Returns:
int

Definition at line 590 of file gnss.cpp.

int writeable ( void   ) [inherited]

check if writable return the number of free bytes

Definition at line 35 of file serial_pipe.cpp.


Field Documentation

DigitalInOut* _gnssEnable [protected, inherited]

IO pin that enables GNSS.

Definition at line 335 of file gnss.h.

Pipe<char> _pipeRx [protected, inherited]

receive pipe

Definition at line 96 of file serial_pipe.h.

Pipe<char> _pipeTx [protected, inherited]

transmit pipe

Definition at line 97 of file serial_pipe.h.

const char _toHex = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' } [static, protected, inherited]

num to hex conversion

Definition at line 334 of file gnss.h.