example.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright © 2014 Kosma Moczek <kosma@cloudyourcar.com>
  3. * This work is free. You can redistribute it and/or modify it under the
  4. * terms of the Do What The Fuck You Want To Public License, Version 2,
  5. * as published by Sam Hocevar. See the COPYING file for more details.
  6. */
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <ctype.h>
  10. #include "minmea.h"
  11. int main()
  12. {
  13. char line[MINMEA_MAX_LENGTH];
  14. while (fgets(line, sizeof(line), stdin) != NULL) {
  15. printf("%s", line);
  16. switch (minmea_type(line)) {
  17. case MINMEA_GPRMC: {
  18. struct minmea_gprmc frame;
  19. if (minmea_parse_gprmc(&frame, line)) {
  20. printf("+++ raw coordinates and speed: (%d/%d,%d/%d) %d/%d\n",
  21. frame.latitude, frame.latitude_scale,
  22. frame.longitude, frame.longitude_scale,
  23. frame.speed, frame.speed_scale);
  24. printf("+++ fixed-point coordinates and speed scaled to three decimal places: (%d,%d) %d\n",
  25. minmea_rescale(frame.latitude, frame.latitude_scale, 1000),
  26. minmea_rescale(frame.longitude, frame.longitude_scale, 1000),
  27. minmea_rescale(frame.speed, frame.speed_scale, 1000));
  28. printf("+++ floating point degree coordinates and speed: (%f,%f) %f\n",
  29. minmea_coord(frame.latitude, frame.latitude_scale),
  30. minmea_coord(frame.longitude, frame.longitude_scale),
  31. minmea_float(frame.speed, frame.speed_scale));
  32. }
  33. } break;
  34. case MINMEA_GPGGA: {
  35. struct minmea_gpgga frame;
  36. if (minmea_parse_gpgga(&frame, line)) {
  37. printf("$GPGGA: fix quality: %d\n", frame.fix_quality);
  38. }
  39. } break;
  40. default: {
  41. } break;
  42. }
  43. }
  44. return 0;
  45. }
  46. /* vim: ts=4 sw=4 et: */