3.6.2. gnss — Global Navigation Satellite System

GNSS is a set of global coverage satellite system, including GPS, GLONASS and Galileo.

This driver reads NMEA 0183 sentences from an input channel (often a UART driver), parses them and stores position, time and speed in the driver object.

This driver should be compatible with all GNSS devices sending and receiving NMEA sentences over a serial port.

Devices known to work with this driver:


Source code: src/drivers/various/gnss.h, src/drivers/various/gnss.c

Test code: tst/drivers/software/various/gnss/main.c

Example code: examples/gnss/main.c


Functions

int gnss_module_init(void)

Initialize the GNSS module. This function must be called before calling any other function in this module.

The module will only be initialized once even if this function is called multiple times.

Return
zero(0) or negative error code.

int gnss_init(struct gnss_driver_t *self_p, void *chin_p, void *chout_p)

Initialize given driver object from given configuration.

Return
zero(0) or negative error code.
Parameters
  • self_p: Driver object to be initialized.
  • chin_p: Incoming transport channel.
  • chout_p: Outgoing transport channel.

int gnss_read(struct gnss_driver_t *self_p)

Update the GNSS driver state by reading and parsing a NMEA sentence from the transport channel.

NOTE: NMEA sentences will be lost if this function is called too seldom (due to transport channel input overrun).

Return
zero(0) if an NEMA sentence was read, otherwise negative error code.
Parameters
  • self_p: Initialized driver object.

int gnss_write(struct gnss_driver_t *self_p, char *str_p)

Encode an NMEA sentence of given string by prepending a $ and appending a CRC and line termination, and write the sentence to the transport channel.

For example, the string GPGLL,4916.45,N,12311.12,W,225444,A, is encoded to $GPGLL,4916.45,N,12311.12,W,225444,A,*1D\r\n and then written to the transport channel.

Return
zero(0) if the NEMA sentence was written to the transport channel, otherwise negative error code.
Parameters
  • self_p: Initialized driver object.
  • str_p: String to write.

int gnss_get_date(struct gnss_driver_t *self_p, struct date_t *date_p)

Get most recently received date.

Return
Date age in seconds or negative error code.
Parameters
  • self_p: Initialized driver object.
  • date_p: Current date.

int gnss_get_position(struct gnss_driver_t *self_p, float *latitude_p, float *longitude_p)

Get most recently received position.

Return
Position age in seconds or negative error code.
Parameters
  • self_p: Initialized driver object.
  • latitude_p: Current latitude in degrees. Positive number for north, negative south.
  • longitude_p: Current longitude in degrees. Positive number for east, negative for west.

int gnss_get_speed(struct gnss_driver_t *self_p, float *speed_p)

Get most recently received speed.

Return
Speed age in seconds or negative error code.
Parameters
  • self_p: Initialized driver object.
  • speed_p: Current speed in meters per second.

int gnss_get_number_of_satellites(struct gnss_driver_t *self_p, int *number_of_satellites_p)

Get most recently received number of tracked satellites.

Return
Number of tracked satellites age in seconds or negative error code.
Parameters
  • self_p: Initialized driver object.
  • number_of_satellites_p: Current number of tracked satellites.

int gnss_get_altitude(struct gnss_driver_t *self_p, float *altitude_p)

Get most recently received altitude.

Return
Altitude age in seconds or negative error code.
Parameters
  • self_p: Initialized driver object.
  • altitude_p: Current altitude in meters.

int gnss_print(struct gnss_driver_t *self_p, void *chan_p)

Print the driver state as a human readable string to given channel.

Return
zero(0) or negative error code.
Parameters
  • self_p: Initialized driver object.
  • chan_p: Channel to print to.

struct gnss_driver_t

Public Members

void *chin_p
void *chout_p
struct time_t rmc_timestamp
struct time_t gga_timestamp
struct date_t date
long latitude_degrees
long longitude_degrees
struct time_t *timestamp_p
struct gnss_driver_t::@42 gnss_driver_t::position
long speed
int number_of_satellites
long altitude
char buf[NMEA_SENTENCE_SIZE_MAX]
size_t size
struct gnss_driver_t::@43::@44 gnss_driver_t::input
struct nmea_sentence_t decoded
struct gnss_driver_t::@43 gnss_driver_t::nmea
struct log_object_t log