SELKIELogger  1.0.0
u-blox GPS Device communication
Collaboration diagram for u-blox GPS Device communication:

Modules

 UBX Commands
 
 UBX Message handling
 

Files

file  GPSCommands.h
 
file  GPSMessages.h
 
file  GPSSerial.h
 
file  GPSTypes.h
 

Classes

struct  ubx_message
 Internal representation of a UBX message. More...
 
struct  ubx_message_name
 UBX Message descriptions. More...
 
struct  ubx_nav_pvt
 Represent decoded NAV-PVT message. More...
 

Macros

#define UBX_SERIAL_BUFF   4096
 Serial buffer size.
 
#define UBX_SYNC_BYTE1   0xB5
 UBX Serial synchronisation byte 1. More...
 
#define UBX_SYNC_BYTE2   0x62
 UBX Serial synchronisation byte 2. More...
 

Typedefs

typedef enum ubx_class ubx_class
 UBX Message class ID bytes.
 
typedef struct ubx_message ubx_message
 Internal representation of a UBX message. More...
 
typedef struct ubx_message_name ubx_message_name
 UBX Message descriptions.
 
typedef struct ubx_nav_pvt ubx_nav_pvt
 Represent decoded NAV-PVT message.
 

Enumerations

enum  ubx_class {
  UBXNAV = 0x01 , UBXRXM = 0x02 , UBXINF = 0x04 , UBXACK = 0x05 ,
  UBXCFG = 0x06 , UBXUPD = 0x09 , UBXMON = 0x0A , UBXAID = 0x0B ,
  UBXTIM = 0x0D , UBXESF = 0x10 , UBXMGA = 0x13 , UBXLOG = 0x21 ,
  UBXSEC = 0x27 , UBXHNR = 0x28
}
 UBX Message class ID bytes.
 

Functions

int ubx_openConnection (const char *port, const int initialBaud)
 Set up a connection to a UBlox module on a given port. More...
 
void ubx_closeConnection (int handle)
 Close a connection opened with ubx_openConnection() More...
 
bool ubx_readMessage (int handle, ubx_message *out)
 Static wrapper around ubx_readMessage_buf() More...
 
bool ubx_readMessage_buf (int handle, ubx_message *out, uint8_t buf[UBX_SERIAL_BUFF], int *index, int *hw)
 Read data from handle, and parse message if able. More...
 
bool ubx_waitForMessage (const int handle, const uint8_t msgClass, const uint8_t msgID, const int maxDelay, ubx_message *out)
 Read (and discard) messages until required message seen or timeout reached. More...
 
bool ubx_writeMessage (int handle, const ubx_message *out)
 Send message to attached device. More...
 

Detailed Description

Macro Definition Documentation

◆ UBX_SYNC_BYTE1

#define UBX_SYNC_BYTE1   0xB5

UBX Serial synchronisation byte 1.

0xB5 as defined in UBlox documentation.

Represents the UTF-8 ยต glyph

Definition at line 43 of file GPSTypes.h.

◆ UBX_SYNC_BYTE2

#define UBX_SYNC_BYTE2   0x62

UBX Serial synchronisation byte 2.

Defined as 0x62 in UBlox documentation. Represents a b in ASCII or UTF-8.

Definition at line 50 of file GPSTypes.h.

Typedef Documentation

◆ ubx_message

typedef struct ubx_message ubx_message

Internal representation of a UBX message.

All messages must start with two sync bytes: 0xB5 0x62

Short messages are stored in the data array, larger messages will be stored at the location pointed to by the extdata member.

If extdata is set, it must be explicitly freed when message is disposed of.

Function Documentation

◆ ubx_closeConnection()

void ubx_closeConnection ( int  handle)

Close a connection opened with ubx_openConnection()

Currently just closes the handle, but could deconfigure and reset the module or put it into a power saving mode in future.

Parameters
[in]handleFile descriptor from ubx_openConnection()

Definition at line 111 of file GPSSerial.c.

◆ ubx_openConnection()

int ubx_openConnection ( const char *  port,
const int  initialBaud 
)

Set up a connection to a UBlox module on a given port.

Uses openSerialConnection() from the base library to open an initial connection, then sends UBX commands to configure the module for 115200 baud UBX output.

If the module was already operating at 115200 then it will stop listening to serial commands when we transmit at the wrong rate, so this function will sleep for 1 second before configuring the protocols again.

Parameters
[in]portPath to character device connected to UBlox module
[in]initialBaudInitial baud rate for connection. Usually 9600, but may vary.
Returns
File descriptor for use with other commands

Definition at line 51 of file GPSSerial.c.

◆ ubx_readMessage()

bool ubx_readMessage ( int  handle,
ubx_message out 
)

Static wrapper around ubx_readMessage_buf()

For single threaded development and testing, uses static variables rather than requiring state to be tracked by caller.

See ubx_readMessage_buf() for full description.

Parameters
[in]handleFile descriptor from ubx_openConnection()
[out]outPointer to message structure to fill with data
Returns
True if out now contains a valid message, false otherwise.

Definition at line 125 of file GPSSerial.c.

◆ ubx_readMessage_buf()

bool ubx_readMessage_buf ( int  handle,
ubx_message out,
uint8_t  buf[UBX_SERIAL_BUFF],
int *  index,
int *  hw 
)

Read data from handle, and parse message if able.

Pulls data from handle and stores it in buf, tracking the current search position in index and the current fill level/buffer high water mark in hw

The source handle can be anything supported by read(), but would usually be a file or a serial port.

If a valid message is found then it is written to the structure provided as a parameter and the function returns true.

If a message cannot be read, the function returns false and the sync1 field is set to an error value:

  • 0xFF means no message found yet, and more data is required
  • 0xFD is a synonym for 0xFF, but indicates that zero bytes were read from source. This could indicate EOF if reading from file, but can be ignored when streaming from a device.
  • 0xAA means that an error occurred reading in data
  • 0XEE means a valid message header was found, but no valid message
Parameters
[in]handleFile descriptor from ubx_openConnection()
[out]outPointer to message structure to fill with data
[in,out]bufSerial data buffer
[in,out]indexCurrent search position within buf
[in,out]hwEnd of current valid data in buf
Returns
True if out now contains a valid message, false otherwise.

Definition at line 158 of file GPSSerial.c.

◆ ubx_waitForMessage()

bool ubx_waitForMessage ( const int  handle,
const uint8_t  msgClass,
const uint8_t  msgID,
const int  maxDelay,
ubx_message out 
)

Read (and discard) messages until required message seen or timeout reached.

Messages are read with ubx_readMessage() and discarded until either a message matches the supplied message class and ID values or the maximum delay time is reached.

Note that the function exits as soon as the time specified by maxDelay is exceeded. The maximum delay specified in this function is 50us, but no guarantees are given regarding time spent reading in messages.

Parameters
[in]handleFile descriptor from ubx_openConnection()
[in]msgClassMessage class to wait for
[in]msgIDMessage ID/Type to wait for
[in]maxDelayTimeout in seconds.
[out]outPointer to message structure to fill with data
Returns
True if required message found, false otherwise (timeout reached)

Definition at line 276 of file GPSSerial.c.

◆ ubx_writeMessage()

bool ubx_writeMessage ( int  handle,
const ubx_message out 
)

Send message to attached device.

Takes a ubx_message, validates the checksum and sync bytes and writes data to the device or file connected to handle.

Parameters
[in]handleFile descriptor from ubx_openConnection()
[in]outPointer to message structure to be sent.
Returns
True if data successfullt written to handle

Definition at line 298 of file GPSSerial.c.