example.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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, frame.latitude_scale,
  23. frame.longitude, frame.longitude_scale,
  24. frame.speed, frame.speed_scale);
  25. printf("+++ fixed-point coordinates and speed scaled to three decimal places: (%d,%d) %d\n",
  26. minmea_rescale(frame.latitude, frame.latitude_scale, 1000),
  27. minmea_rescale(frame.longitude, frame.longitude_scale, 1000),
  28. minmea_rescale(frame.speed, frame.speed_scale, 1000));
  29. printf("+++ floating point degree coordinates and speed: (%f,%f) %f\n",
  30. minmea_coord(frame.latitude, frame.latitude_scale),
  31. minmea_coord(frame.longitude, frame.longitude_scale),
  32. minmea_float(frame.speed, frame.speed_scale));
  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_GSV: {
  42. struct minmea_sentence_gsv frame;
  43. if (minmea_parse_gsv(&frame, line)) {
  44. printf("$GPGSV: message %d of %d\n", frame.msg_nr, frame.total_msgs);
  45. printf("$GPGSV: sattelites in view: %d\n", frame.total_sats);
  46. for (int i = 0; i < 4; i++)
  47. printf("$GPGSV: sat nr %d, elevation: %d, azimuth: %d, snr: %d dbm\n",
  48. frame.sats[i].nr,
  49. frame.sats[i].elevation,
  50. frame.sats[i].azimuth,
  51. frame.sats[i].snr);
  52. }
  53. } break;
  54. default: {
  55. } break;
  56. }
  57. }
  58. return 0;
  59. }
  60. /* vim: set ts=4 sw=4 et: */