example.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright © 2014 Kosma Moczek <kosma@cloudyourcar.com>
  3. * This program is free software. It comes without any warranty, to the extent
  4. * permitted by applicable law. You can redistribute it and/or modify it under
  5. * the terms of the Do What The Fuck You Want To Public License, Version 2, as
  6. * published by Sam Hocevar. See the COPYING file for more details.
  7. */
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <ctype.h>
  11. #include "minmea.h"
  12. int main()
  13. {
  14. char line[MINMEA_MAX_LENGTH];
  15. while (fgets(line, sizeof(line), stdin) != NULL) {
  16. printf("%s", line);
  17. switch (minmea_sentence_id(line)) {
  18. case MINMEA_SENTENCE_RMC: {
  19. struct minmea_sentence_rmc frame;
  20. if (minmea_parse_rmc(&frame, line)) {
  21. printf("+++ raw coordinates and speed: (%d/%d,%d/%d) %d/%d\n",
  22. frame.latitude.value, frame.latitude.scale,
  23. frame.longitude.value, frame.longitude.scale,
  24. frame.speed.value, frame.speed.scale);
  25. printf("+++ fixed-point coordinates and speed scaled to three decimal places: (%d,%d) %d\n",
  26. minmea_rescale(&frame.latitude, 1000),
  27. minmea_rescale(&frame.longitude, 1000),
  28. minmea_rescale(&frame.speed, 1000));
  29. printf("+++ floating point degree coordinates and speed: (%f,%f) %f\n",
  30. minmea_tocoord(&frame.latitude),
  31. minmea_tocoord(&frame.longitude),
  32. minmea_tofloat(&frame.speed));
  33. }
  34. } break;
  35. case MINMEA_SENTENCE_GGA: {
  36. struct minmea_sentence_gga frame;
  37. if (minmea_parse_gga(&frame, line)) {
  38. printf("$GPGGA: fix quality: %d\n", frame.fix_quality);
  39. }
  40. } break;
  41. case MINMEA_SENTENCE_GST: {
  42. struct minmea_sentence_gst frame;
  43. if (minmea_parse_gst(&frame, line)) {
  44. printf("+++ raw latitude,longitude and altitude error deviation: (%d/%d,%d/%d,%d/%d)\n",
  45. frame.latitude_error_deviation.value, frame.latitude_error_deviation.scale,
  46. frame.longitude_error_deviation.value, frame.longitude_error_deviation.scale,
  47. frame.altitude_error_deviation.value, frame.altitude_error_deviation.scale);
  48. printf("+++ fixed point latitude,longitude and altitude error deviation \
  49. scaled to one decimal place: (%d,%d,%d)\n",
  50. minmea_rescale(&frame.latitude_error_deviation, 10),
  51. minmea_rescale(&frame.longitude_error_deviation, 10),
  52. minmea_rescale(&frame.altitude_error_deviation, 10));
  53. printf("+++ floating point degree latitude, longitude and altitude error deviation: (%f,%f,%f)",
  54. minmea_tofloat(&frame.latitude_error_deviation),
  55. minmea_tofloat(&frame.longitude_error_deviation),
  56. minmea_tofloat(&frame.altitude_error_deviation));
  57. }
  58. } break;
  59. case MINMEA_SENTENCE_GSV: {
  60. struct minmea_sentence_gsv frame;
  61. if (minmea_parse_gsv(&frame, line)) {
  62. printf("$GPGSV: message %d of %d\n", frame.msg_nr, frame.total_msgs);
  63. printf("$GPGSV: sattelites in view: %d\n", frame.total_sats);
  64. for (int i = 0; i < 4; i++)
  65. printf("$GPGSV: sat nr %d, elevation: %d, azimuth: %d, snr: %d dbm\n",
  66. frame.sats[i].nr,
  67. frame.sats[i].elevation,
  68. frame.sats[i].azimuth,
  69. frame.sats[i].snr);
  70. }
  71. } break;
  72. default: {
  73. } break;
  74. }
  75. }
  76. return 0;
  77. }
  78. /* vim: set ts=4 sw=4 et: */