|
|
il y a 11 ans | |
|---|---|---|
| .gitignore | il y a 12 ans | |
| COPYING | il y a 12 ans | |
| Makefile | il y a 11 ans | |
| README.md | il y a 11 ans | |
| example.c | il y a 11 ans | |
| minmea.c | il y a 11 ans | |
| minmea.h | il y a 11 ans | |
| tests.c | il y a 11 ans |
Minmea is a minimalistic GPS parser library written in pure C intended for resource-constrained platforms, especially microcontrollers and other embedded systems.
$GPRMC$GPGGA$GPGSAAdding support for more sentences is trivial; see minmea.c source.
Internally, minmea stores fractional numbers as pairs of two integers: (value, scale).
For example, a value of "-123.456" would be parsed as (-123456, 1000). As this
format is quite unwieldy, minmea provides the following convenience macros for converting
to either fixed-point or floating-point format:
minmea_rescale(-123456, 1000, 10) => -1235minmea_float(-123456, 1000) => -123.456NMEA uses the clunky DDMM.MMMM format which, honestly, is not good in the internet era.
Internally, minmea stores it as a fractional number (see above); for practical uses,
the value should be probably converted to the DD.DDDDD floating point format using the
following macro:
minmea_coord(-375165, 100) => -37.860832The library doesn't perform this conversion automatically for the following reasons:
char line[MINMEA_MAX_LENGTH];
while (fgets(line, sizeof(line), stdin) != NULL) {
printf("%s", line);
switch (minmea_sentence_id(line)) {
case MINMEA_SENTENCE_RMC: {
struct minmea_sentence_rmc frame;
if (minmea_parse_rmc(&frame, line)) {
printf("+++ raw coordinates and speed: (%d/%d,%d/%d) %d/%d\n",
frame.latitude, frame.latitude_scale,
frame.longitude, frame.longitude_scale,
frame.speed, frame.speed_scale);
printf("+++ fixed-point coordinates and speed scaled to three decimal places: (%d,%d) %d\n",
minmea_rescale(frame.latitude, frame.latitude_scale, 1000),
minmea_rescale(frame.longitude, frame.longitude_scale, 1000),
minmea_rescale(frame.speed, frame.speed_scale, 1000));
printf("+++ floating point degree coordinates and speed: (%f,%f) %f\n",
minmea_coord(frame.latitude, frame.latitude_scale),
minmea_coord(frame.longitude, frame.longitude_scale),
minmea_float(frame.speed, frame.speed_scale));
}
} break;
case MINMEA_SENTENCE_GGA: {
struct minmea_sentence_gga frame;
if (minmea_parse_gga(&frame, line)) {
printf("$GPGGA: fix quality: %d\n", frame.fix_quality);
}
} break;
}
}
Simply add minmea.[ch] to your project, #include "minmea.h" and you're
good to go.
Building and running the tests requires the following:
If you have both in your $PATH, running the tests should be as simple as
typing make.
int internally, which is 32 bits on
most embedded platforms. Therefore, the maximum supported coordinate precision
is [+-]DDDMM.MMMMM. The library does not check for integer overflow at the
moment; coordinates with more precision will not parse correctly.-ffunction-sections -Wl,--gc-sections linker flags
(or equivalent) to remove the unused functions (parsers) from the final image.timegm. On these systems, the recommended course of
action is to build with -Dtimegm=mktime - assuming the system runs in the
default UTC timezone.There are plenty. Report them on GitHub, or - even better - open a pull request. Please write unit tests for any new functions you add - it's fun!
Minmea is open source software; see COPYING for amusement. Email me if the
license bothers you and I'll happily re-license under anything else under the sun.
Minmea was written by Kosma Moczek <kosma@cloudyourcar.com> at Cloud Your Car.