example.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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_type(line)) {
  18. case MINMEA_GPRMC: {
  19. struct minmea_gprmc frame;
  20. if (minmea_parse_gprmc(&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_GPGGA: {
  36. struct minmea_gpgga frame;
  37. if (minmea_parse_gpgga(&frame, line)) {
  38. printf("$GPGGA: fix quality: %d\n", frame.fix_quality);
  39. }
  40. } break;
  41. default: {
  42. } break;
  43. }
  44. }
  45. return 0;
  46. }
  47. /* vim: set ts=4 sw=4 et: */