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.

wintec_tes.cc 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. Wintec tes support.
  3. Copyright (C) 2010 Robert Lipe, robertlipe+source@gpsbabel.org
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
  15. */
  16. #include "defs.h"
  17. #define MYNAME "wintec_tes"
  18. static gbfile* fin;
  19. static void
  20. wintec_tes_rd_init(const QString& fname)
  21. {
  22. fin = gbfopen(fname, "r", MYNAME);
  23. }
  24. static void
  25. wintec_tes_rd_deinit(void)
  26. {
  27. gbfclose(fin);
  28. }
  29. static time_t
  30. wintec_date_to_time(uint32_t w)
  31. {
  32. struct tm tm;
  33. memset(&tm, 0, sizeof(tm));
  34. tm.tm_sec = ((w & 0x0000003f));
  35. tm.tm_min = ((w & 0x00000fc0) >> 6);
  36. tm.tm_hour = ((w & 0x0001f000) >> 12);
  37. tm.tm_mday = ((w & 0x003f0000) >> 17);
  38. tm.tm_mon = ((w & 0x03c00000) >> 22) - 1;
  39. tm.tm_year = ((w & 0xfc000000) >> 26) + 100;
  40. return mkgmtime(&tm);
  41. }
  42. static void
  43. wintec_tes_read(void)
  44. {
  45. route_head* trk = route_head_alloc();
  46. track_add_head(trk);
  47. while (!gbfeof(fin)) {
  48. Waypoint* wpt;
  49. uint16_t flags = gbfgetuint16(fin);
  50. uint32_t date = gbfgetuint32(fin);
  51. int32_t latitude = gbfgetint32(fin);
  52. int32_t longitude = gbfgetint32(fin);
  53. int16_t alt = gbfgetint16(fin); // Signed. Meters.
  54. (void) flags; // Silence 'unused' warning until we use flags.
  55. wpt = new Waypoint;
  56. wpt->latitude = latitude / 1.0e7;
  57. wpt->longitude = longitude / 1.0e7;
  58. wpt->SetCreationTime(wintec_date_to_time(date));
  59. // The unit of altitude isn't clear and we have a lot of
  60. // samples with wildly negative values, so ignore those for now.
  61. wpt->altitude = alt;
  62. // The description given to us says this is a bitmask with
  63. // 0x01 "split mark" (not at all clear what that is)
  64. // 0x02 interest point
  65. // 0x04 track point
  66. // But of the files we've seen, none have had > 1 bit set
  67. // and none have had 0x04 set.
  68. // Wintec's software puts a waypoint in the track, so we
  69. // mock that.
  70. if (flags & 0x02) {
  71. Waypoint* temp = new Waypoint(*wpt);
  72. waypt_add(temp);
  73. }
  74. track_add_wpt(trk, wpt);
  75. }
  76. }
  77. static
  78. arglist_t wintec_tes_args[] = {
  79. ARG_TERMINATOR
  80. };
  81. ff_vecs_t wintec_tes_vecs = {
  82. ff_type_file,
  83. {
  84. ff_cap_read /* waypoints */,
  85. ff_cap_read /* tracks */,
  86. ff_cap_none /* routes */
  87. },
  88. wintec_tes_rd_init,
  89. NULL,
  90. wintec_tes_rd_deinit,
  91. NULL,
  92. wintec_tes_read,
  93. NULL,
  94. NULL,
  95. wintec_tes_args,
  96. CET_CHARSET_ASCII, 0 /* ascii is the expected character set */
  97. /* not fixed, can be changed through command line parameter */
  98. };