group LWGPS

Lightweight GPS NMEA parser.



Check if current GPS data contain valid signal.


LWGPS_CFG_STATEMENT_GPRMC must be enabled and GPRMC statement must be sent from GPS receiver


1 on success, 0 otherwise

  • [in] _gh: GPS handle


typedef double lwgps_float_t

GPS float definition, can be either float or double


Check for LWGPS_CFG_DOUBLE configuration

typedef void (*lwgps_process_fn)(lwgps_statement_t res)

Signature for caller-suplied callback function from gps_process.

  • [in] res: statement type of recently parsed statement


enum lwgps_statement_t

ENUM of possible GPS statements parsed.


enumerator STAT_UNKNOWN

Unknown NMEA statement

enumerator STAT_GGA

GPGGA statement

enumerator STAT_GSA

GPGSA statement

enumerator STAT_GSV

GPGSV statement

enumerator STAT_RMC

GPRMC statement

enumerator STAT_UBX

UBX statement (uBlox specific)

enumerator STAT_UBX_TIME

UBX TIME statement (uBlox specific)


Special case, used when checksum fails

enum lwgps_speed_t

List of optional speed transformation from GPS values (in knots)


enumerator lwgps_speed_kps

Kilometers per second

enumerator lwgps_speed_kph

Kilometers per hour

enumerator lwgps_speed_mps

Meters per second

enumerator lwgps_speed_mpm

Meters per minute

enumerator lwgps_speed_mips

Miles per second

enumerator lwgps_speed_mph

Miles per hour

enumerator lwgps_speed_fps

Foots per second

enumerator lwgps_speed_fpm

Foots per minute

enumerator lwgps_speed_mpk

Minutes per kilometer

enumerator lwgps_speed_spk

Seconds per kilometer

enumerator lwgps_speed_sp100m

Seconds per 100 meters

enumerator lwgps_speed_mipm

Minutes per mile

enumerator lwgps_speed_spm

Seconds per mile

enumerator lwgps_speed_sp100y

Seconds per 100 yards

enumerator lwgps_speed_smph

Sea miles per hour


uint8_t lwgps_init(lwgps_t *gh)

Init GPS handle.


1 on success, 0 otherwise

  • [in] gh: GPS handle structure

uint8_t lwgps_process(lwgps_t *gh, const void *data, size_t len, lwgps_process_fn evt_fn)

Process NMEA data from GPS receiver.


1 on success, 0 otherwise

  • [in] gh: GPS handle structure

  • [in] data: Received data

  • [in] len: Number of bytes to process

  • [in] evt_fn: Event function to notify application layer. This parameter is available only if LWGPS_CFG_STATUS is enabled

uint8_t lwgps_distance_bearing(lwgps_float_t las, lwgps_float_t los, lwgps_float_t lae, lwgps_float_t loe, lwgps_float_t *d, lwgps_float_t *b)

Calculate distance and bearing between 2 latitude and longitude coordinates.


1 on success, 0 otherwise

  • [in] las: Latitude start coordinate, in units of degrees

  • [in] los: Longitude start coordinate, in units of degrees

  • [in] lae: Latitude end coordinate, in units of degrees

  • [in] loe: Longitude end coordinate, in units of degrees

  • [out] d: Pointer to output distance in units of meters

  • [out] b: Pointer to output bearing between start and end coordinate in relation to north in units of degrees

lwgps_float_t lwgps_to_speed(lwgps_float_t sik, lwgps_speed_t ts)

Convert NMEA GPS speed (in knots = nautical mile per hour) to different speed format.


Speed calculated from knots

  • [in] sik: Speed in knots, received from GPS NMEA statement

  • [in] ts: Target speed to convert to from knots

struct lwgps_sat_t
#include <lwgps.h>

Satellite descriptor.

Public Members

uint8_t num

Satellite number

uint8_t elevation

Elevation value

uint16_t azimuth

Azimuth in degrees

uint8_t snr

Signal-to-noise ratio

struct lwgps_t
#include <lwgps.h>

GPS main structure.

Public Members

lwgps_float_t latitude

Latitude in units of degrees

lwgps_float_t longitude

Longitude in units of degrees

lwgps_float_t altitude

Altitude in units of meters

lwgps_float_t geo_sep

Geoid separation in units of meters

uint8_t sats_in_use

Number of satellites in use

uint8_t fix

Fix status. 0 = invalid, 1 = GPS fix, 2 = DGPS fix, 3 = PPS fix

uint8_t hours

Hours in UTC

uint8_t minutes

Minutes in UTC

uint8_t seconds

Seconds in UTC

lwgps_float_t dop_h

Dolution of precision, horizontal

lwgps_float_t dop_v

Dolution of precision, vertical

lwgps_float_t dop_p

Dolution of precision, position

uint8_t fix_mode

Fix mode. 1 = NO fix, 2 = 2D fix, 3 = 3D fix

uint8_t satellites_ids[12]

List of satellite IDs in use. Valid range is 0 to sats_in_use

uint8_t sats_in_view

Number of satellites in view

lwgps_sat_t sats_in_view_desc[12]
uint8_t is_valid

GPS valid status

lwgps_float_t speed

Ground speed in knots

lwgps_float_t course

Ground coarse

lwgps_float_t variation

Magnetic variation

uint8_t date

Fix date

uint8_t month

Fix month

uint8_t year

Fix year

lwgps_float_t utc_tow

UTC TimeOfWeek, eg 113851.00

uint16_t utc_wk

UTC week number, continues beyond 1023

uint8_t leap_sec

UTC leap seconds; UTC + leap_sec = TAI

uint32_t clk_bias

Receiver clock bias, eg 1930035

lwgps_float_t clk_drift

Receiver clock drift, eg -2660.664

uint32_t tp_gran

Time pulse granularity, eg 43