11.3. nmea — NMEA encoding and decoding

Source code: src/encode/nmea.h, src/encode/nmea.c

Test code: tst/encode/nmea/main.c

Test coverage: src/encode/nmea.c


Defines

NMEA_SENTENCE_SIZE_MAX
NMEA_KNOTS_TO_METERS_PER_SECOND(knots)

Enums

enum nmea_sentence_type_t

Sentence types.

Values:

nmea_sentence_type_raw_t = 0
nmea_sentence_type_gga_t
nmea_sentence_type_gll_t
nmea_sentence_type_gsa_t
nmea_sentence_type_gsv_t
nmea_sentence_type_rmc_t
nmea_sentence_type_vtg_t
nmea_sentence_type_max_t

Functions

ssize_t nmea_encode(char *dst_p, struct nmea_sentence_t *src_p, size_t size)

Encode given NMEA sentence into given buffer.

Return
Number of bytes in the encoded string, not including the null-termination, or negative error code.
Parameters
  • dst_p: Null-terminated encoded sentence.
  • src_p: Sentence to encode.
  • size: Size of the destination buffer dst_p.

ssize_t nmea_decode(struct nmea_sentence_t *dst_p, char *src_p, size_t size)

Decode given NMEA sentence into given struct.

Return
zero(0) or negative error code.
Parameters
  • dst_p: Decoded NMEA sentence.
  • src_p: Sentence to decode, starting with a dollar sign and ending with <CR><LF>. This string is modified by this function and the decoded sentence has references to it.
  • size: Number of bytes in the sentence to decode, not including the null-termination.

int nmea_decode_fix_time(char *src_p, int *hour_p, int *minute_p, int *second_p)

Decode given NMEA fix time hhmmss. The output variables have not been modified if the decoding failed.

Return
zero(0) or negative error code.
Parameters
  • src_p: Fix time to decode.
  • hour_p: Decoded hour.
  • minute_p: Decoded minute.
  • second_p: Decoded second.

int nmea_decode_date(char *src_p, int *year_p, int *month_p, int *date_p)

Decode given NMEA date ddmmyy. The output variables have not been modified if the decoding failed.

Return
zero(0) or negative error code.
Parameters
  • src_p: Date to decode.
  • year_p: Decoded year.
  • month_p: Decoded month.
  • date_p: Decoded date.

int nmea_decode_position(struct nmea_position_t *src_p, long *degrees_p)

Decode given NMEA position angle d{2,3}mm.m+ and direction [NSEW], for example 4703.324 N, which is decoded as 47 degrees, 3.324 minutes, or 47055400 microdegrees.

The output variable has not been modified if the decoding failed.

Return
zero(0) or negative error code.
Parameters
  • src_p: Position to decode.
  • degrees_p: Decoded position in microdegrees (millions of degrees).

struct nmea_position_t

Public Members

char *angle_p
char *direction_p
struct nmea_value_t

Public Members

char *value_p
char *unit_p
struct nmea_track_made_good_t

Public Members

char *value_p
char *relative_to_p
struct nmea_sentence_raw_t
#include <nmea.h>

Raw string data.

Public Members

char *str_p
struct nmea_sentence_gga_t
#include <nmea.h>

Fix information.

Public Members

char *time_of_fix_p
struct nmea_position_t latitude
struct nmea_position_t longitude
char *fix_quality_p
char *number_of_tracked_satellites_p
char *horizontal_dilution_of_position_p
struct nmea_value_t altitude
struct nmea_value_t height_of_geoid
struct nmea_sentence_gll_t
#include <nmea.h>

Latitude and longitude data.

Public Members

char *time_of_fix_p
struct nmea_position_t latitude
struct nmea_position_t longitude
char *data_active_p
struct nmea_sentence_gsa_t
#include <nmea.h>

Overall satellite data.

Public Members

char *selection_p
char *fix_p
char *prns[12]
char *pdop_p
char *hdop_p
char *vdop_p
struct nmea_sentence_gsv_t
#include <nmea.h>

Detailed satellite data.

Public Members

char *number_of_sentences_p
char *sentence_p
char *number_of_satellites_p
char *prn_p
char *elevation_p
char *azimuth_p
char *snr_p
struct nmea_sentence_gsv_t::@45 nmea_sentence_gsv_t::satellites[4]
struct nmea_sentence_rmc_t
#include <nmea.h>

Recommended minimum data for GPS.

Public Members

char *time_of_fix_p
char *status_p
struct nmea_position_t latitude
struct nmea_position_t longitude
char *speed_knots_p
char *track_angle_p
char *date_p
struct nmea_position_t magnetic_variation
struct nmea_sentence_vtg_t
#include <nmea.h>

Track made good and speed over ground.

Public Members

struct nmea_track_made_good_t track_made_good_true
struct nmea_track_made_good_t track_made_good_magnetic
struct nmea_value_t ground_speed_knots
struct nmea_value_t ground_speed_kmph
struct nmea_sentence_t
#include <nmea.h>

A union of all sentences.

Public Members

nmea_sentence_type_t type
struct nmea_sentence_raw_t raw
struct nmea_sentence_gga_t gga
struct nmea_sentence_gll_t gll
struct nmea_sentence_gsa_t gsa
struct nmea_sentence_gsv_t gsv
struct nmea_sentence_rmc_t rmc
struct nmea_sentence_vtg_t vtg
union nmea_sentence_t::@46 nmea_sentence_t::@47