FFFF GitHub - MaJerle/lwgps: Lightweight GPS NMEA parser for embedded systems · GitHub
[go: up one dir, main page]

Skip to content
MaJerlePublic

About

Lightweight GPS NMEA parser for embedded systems

Topics

Resources

Stars

521 stars

Watchers

22 watching

Forks

Repository files navigation

LwGPS — Lightweight GNSS NMEA parser for embedded systems

Build & Test Release PlatformIO Registry License: MIT Documentation

LwGPS is a lightweight, platform independent, all-constellation GNSS NMEA parser library for embedded systems, written in C11. Feed it raw characters from any GPS/GNSS receiver, byte by byte or in chunks, and read position, altitude, speed, time, fix status and satellite information from a single structure. It needs no dynamic memory and is independent of the communication interface.

📖 Documentation · Changelog · Releases

Features

  • Written in C (C11), compatible with stdint.h data types
  • Platform independent, easy to use
  • Built-in support for all-constellation GNSS statements
    • GPGGA, G*GGA or GNGGA: GNSS fix data
    • GPGSA, G*GSA or GNGSA: Active satellites and dilution of precision
    • GPGSV, G*GSV or GNGSV: List of satellites in view zone
    • GPRMC, G*RMC or GNRMC: Recommended minimum specific GNSS/Transit data
  • Optional support for PUBX (uBlox proprietary) statements, including PUBX_TIME
  • Optional detailed per-satellite info (elevation, azimuth, SNR) for GSV statement
  • Optional NMEA checksum validation
  • Distance and bearing calculation between two coordinates
  • Speed conversion helper between many units: metric, imperial and pace
  • Optional per-statement processing callback
  • C++ wrapper class available
  • Optional float or double floating point units
  • Low-level layer is separated from application layer, thus allowing you to add custom communication with GPS device
  • Works with operating systems
  • Works with different communication interfaces
  • Can be used as an ESP-IDF component
  • User friendly MIT license

Quick start

#include <stdio.h>
#include <string.h>
#include "lwgps/lwgps.h"

/* GPS handle */
lwgps_t hgps;

/* Data received from the GPS receiver */
const char gps_rx_data[] = "$GPRMC,183729,A,3907.356,N,12102.482,W,000.0,360.0,080301,015.5,E*6F\r\n"
                           "$GPGGA,183730,3907.356,N,12102.482,W,1,05,1.6,646.4,M,-24.1,M,,*75\r\n";

int
main(void) {
    lwgps_init(&hgps);

    /* Process received data, can be called with any chunk size */
    lwgps_process(&hgps, gps_rx_data, strlen(gps_rx_data));

    printf("Valid status: %d\r\n", hgps.is_valid);
    printf("Latitude: %f degrees\r\n", hgps.latitude);
    printf("Longitude: %f degrees\r\n", hgps.longitude);
    printf("Altitude: %f meters\r\n", hgps.altitude);
    printf("Speed: %f km/h\r\n", lwgps_to_speed(hgps.speed, LWGPS_SPEED_KPH));
    return 0;
}

Distance and bearing

lwgps_float_t dist, bear;

/* From New York to Munich */
lwgps_distance_bearing(40.685721, -73.820465, 48.150906, 11.554176, &dist, &bear);
printf("Distance: %f meters, initial bearing: %f degrees\r\n", (float)dist, (float)bear);

More examples are in examples, including example_buff.c, which receives data in an interrupt through the LwRB ring buffer.

Configuration

Enabled statements, checksum validation, float or double precision and other settings are configured in the lwgps_opts.h file. Copy lwgps/src/include/lwgps/lwgps_opts_template.h to your project, rename it to lwgps_opts.h, and override the defaults listed in lwgps_opt.h. See Getting started in the documentation for details.

Add to your project

CMake

set(LWGPS_OPTS_FILE ${CMAKE_CURRENT_LIST_DIR}/lwgps_opts.h) # Optional, default options are used otherwise
add_subdirectory(path/to/lwgps/lwgps)
target_link_libraries(${PROJECT_NAME} PRIVATE lwgps)

Optional compiler options and definitions can be set with LWGPS_COMPILE_OPTIONS and LWGPS_COMPILE_DEFINITIONS, see lwgps/library.cmake.

ESP-IDF

Note: ESP-IDF integration is provided as-is and is not tested as part of the library's continuous integration.

The repository is an ESP-IDF component. Add it as a managed component in your project's idf_component.yml:

dependencies:
  lwgps:
    git: https://github.com/MaJerle/lwgps.git

or place it in your project's components folder. To use a custom lwgps_opts.h, set LWGPS_OPTS_FILE as described in ESP-IDF integration in the documentation.

Any other build system

  1. Copy the lwgps folder to your project
  2. Add lwgps/src/include to the include path
  3. Add the source files from lwgps/src/lwgps/ to the build
  4. Create lwgps_opts.h in a folder on the include path (see Configuration)

PlatformIO

LwGPS is available in the PlatformIO Registry. Add it to your platformio.ini:

lib_deps =
    majerle/LwGPS

Contribute

Fresh contributions are always welcome. Simple instructions to proceed:

  1. Fork Github repository
  2. Follow C style & coding rules and use clang-format to format the code
  3. Create a pull request to develop branch with new features or bug fixes

Alternatively you may:

  1. Report a bug
  2. Ask for a feature request

License

LwGPS is released under the MIT license.

About

Lightweight GPS NMEA parser for embedded systems

Topics

Resources

Stars

521 stars

Watchers

22 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages

0