minmea/example.c

88 lines
4.1 KiB
C
Raw Normal View History

/*
* Copyright © 2014 Kosma Moczek <kosma@cloudyourcar.com>
* This program is free software. It comes without any warranty, to the extent
* permitted by applicable law. You can redistribute it and/or modify it under
* the terms of the Do What The Fuck You Want To Public License, Version 2, as
* published by Sam Hocevar. See the COPYING file for more details.
*/
2014-02-14 22:22:18 +08:00
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "minmea.h"
int main(void)
2014-02-14 22:22:18 +08:00
{
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)) {
2014-04-27 22:38:06 +08:00
printf("$xxRMC: raw coordinates and speed: (%d/%d,%d/%d) %d/%d\n",
2014-04-27 22:36:40 +08:00
frame.latitude.value, frame.latitude.scale,
frame.longitude.value, frame.longitude.scale,
frame.speed.value, frame.speed.scale);
2014-04-27 22:38:06 +08:00
printf("$xxRMC fixed-point coordinates and speed scaled to three decimal places: (%d,%d) %d\n",
2014-04-27 22:36:40 +08:00
minmea_rescale(&frame.latitude, 1000),
minmea_rescale(&frame.longitude, 1000),
minmea_rescale(&frame.speed, 1000));
2014-04-27 22:38:06 +08:00
printf("$xxRMC floating point degree coordinates and speed: (%f,%f) %f\n",
2014-04-27 22:36:40 +08:00
minmea_tocoord(&frame.latitude),
minmea_tocoord(&frame.longitude),
minmea_tofloat(&frame.speed));
2014-02-14 22:22:18 +08:00
}
} break;
case MINMEA_SENTENCE_GGA: {
struct minmea_sentence_gga frame;
if (minmea_parse_gga(&frame, line)) {
2014-04-27 22:38:06 +08:00
printf("$xxGGA: fix quality: %d\n", frame.fix_quality);
2014-02-14 22:22:18 +08:00
}
} break;
2014-04-24 02:03:05 +08:00
case MINMEA_SENTENCE_GST: {
struct minmea_sentence_gst frame;
if (minmea_parse_gst(&frame, line)) {
2014-04-27 22:38:06 +08:00
printf("$xxGST: raw latitude,longitude and altitude error deviation: (%d/%d,%d/%d,%d/%d)\n",
2014-04-27 22:36:40 +08:00
frame.latitude_error_deviation.value, frame.latitude_error_deviation.scale,
frame.longitude_error_deviation.value, frame.longitude_error_deviation.scale,
frame.altitude_error_deviation.value, frame.altitude_error_deviation.scale);
2014-04-27 22:38:06 +08:00
printf("$xxGST fixed point latitude,longitude and altitude error deviation \
2014-04-24 01:57:30 +08:00
scaled to one decimal place: (%d,%d,%d)\n",
2014-04-27 22:36:40 +08:00
minmea_rescale(&frame.latitude_error_deviation, 10),
minmea_rescale(&frame.longitude_error_deviation, 10),
minmea_rescale(&frame.altitude_error_deviation, 10));
2014-04-27 22:38:06 +08:00
printf("$xxGST floating point degree latitude, longitude and altitude error deviation: (%f,%f,%f)",
2014-04-27 22:36:40 +08:00
minmea_tofloat(&frame.latitude_error_deviation),
minmea_tofloat(&frame.longitude_error_deviation),
minmea_tofloat(&frame.altitude_error_deviation));
}
} break;
2014-04-24 02:04:18 +08:00
case MINMEA_SENTENCE_GSV: {
struct minmea_sentence_gsv frame;
if (minmea_parse_gsv(&frame, line)) {
2014-04-27 22:38:06 +08:00
printf("$xxGSV: message %d of %d\n", frame.msg_nr, frame.total_msgs);
printf("$xxGSV: sattelites in view: %d\n", frame.total_sats);
for (int i = 0; i < 4; i++)
2014-04-27 22:38:06 +08:00
printf("$xxGSV: sat nr %d, elevation: %d, azimuth: %d, snr: %d dbm\n",
frame.sats[i].nr,
frame.sats[i].elevation,
frame.sats[i].azimuth,
frame.sats[i].snr);
}
} break;
2014-02-14 22:22:18 +08:00
default: {
} break;
}
}
return 0;
}
2014-03-25 05:35:03 +08:00
/* vim: set ts=4 sw=4 et: */