You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
3.5KB

  1. /*
  2. Read Vito SmartMap .vtt tracks
  3. Copyright (C) 2007 Jeremy Ehrhardt, jeremye@caltech.edu
  4. based on vitostc.c, which is
  5. Copyright (C) 2005 Etienne TASSE
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
  17. */
  18. #include "defs.h"
  19. #include <cmath>
  20. #define MYNAME "vitovtt"
  21. #define TM_YEAR_ZERO 1900
  22. #define TM_MONTH_ZERO 1
  23. static gbfile* infile = 0;
  24. static int count = 0;
  25. static const int vitovtt_version = 3;
  26. // static const size_t vitovtt_headersize = 16;
  27. // static const size_t vitovtt_datasize = 32;
  28. static const double vitovtt_latitudescale = 20000000.0;
  29. static const double vitovtt_longitudescale = 10000000.0;
  30. static const int vitovtt_secondscale = 30000000;
  31. static const int vitovtt_microsecondscale = 30;
  32. static void
  33. rd_init(const QString& fname)
  34. {
  35. infile = gbfopen_le(fname, "rb", MYNAME);
  36. }
  37. static void
  38. rd_deinit(void)
  39. {
  40. gbfclose(infile);
  41. }
  42. static void
  43. vitovtt_read(void)
  44. {
  45. int version = 0;
  46. route_head* route_head = 0;
  47. Waypoint* wpt_tmp = 0;
  48. int scaled_lat = 0;
  49. int scaled_lon = 0;
  50. double altitude = 0;
  51. struct tm tmStruct;
  52. int scaled_sec = 0;
  53. double speed = 0;
  54. int course = 0;
  55. int status = 0;
  56. memset(&tmStruct, 0, sizeof(tmStruct));
  57. route_head = route_head_alloc();
  58. track_add_head(route_head);
  59. /* Read the header. */
  60. version = gbfgetint32(infile);
  61. count = gbfgetint32(infile);
  62. if (version!=vitovtt_version) {
  63. fatal("%s (%d) reading file. Unsupported version %d\n",
  64. MYNAME, __LINE__, version);
  65. }
  66. while (count) {
  67. /* Read an entry. */
  68. scaled_lat = gbfgetint32(infile);
  69. scaled_lon = gbfgetint32(infile);
  70. altitude = gbfgetflt(infile);
  71. tmStruct.tm_year = gbfgetint16(infile) - TM_YEAR_ZERO;
  72. tmStruct.tm_mon = gbfgetc(infile) - TM_MONTH_ZERO;
  73. tmStruct.tm_mday = gbfgetc(infile);
  74. tmStruct.tm_hour = gbfgetc(infile);
  75. tmStruct.tm_min = gbfgetc(infile);
  76. scaled_sec = gbfgetint32(infile);
  77. speed = gbfgetflt(infile);
  78. course = gbfgetint16(infile);
  79. status = gbfgetint32(infile);
  80. wpt_tmp = new Waypoint;
  81. wpt_tmp->latitude = scaled_lat / vitovtt_latitudescale;
  82. wpt_tmp->longitude = scaled_lon / vitovtt_longitudescale;
  83. wpt_tmp->altitude = altitude;
  84. tmStruct.tm_sec = scaled_sec / vitovtt_secondscale;
  85. int microseconds = (scaled_sec % vitovtt_secondscale) / vitovtt_microsecondscale;
  86. wpt_tmp->SetCreationTime(mkgmtime(&tmStruct), lround(microseconds/1000.0));
  87. /*
  88. * TODO: interpret speed, course, status
  89. */
  90. (void) speed;
  91. (void) course;
  92. (void) status;
  93. track_add_wpt(route_head, wpt_tmp);
  94. count--;
  95. }
  96. }
  97. ff_vecs_t vitovtt_vecs = {
  98. ff_type_file,
  99. { ff_cap_none, ff_cap_read, ff_cap_none },
  100. rd_init,
  101. NULL,
  102. rd_deinit,
  103. NULL,
  104. vitovtt_read,
  105. NULL,
  106. NULL,
  107. NULL,
  108. CET_CHARSET_UTF8, 1 /* do nothing | CET-REVIEW */
  109. };