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.

navitel.cc 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. Support for Navitel binary tracks (.bin),
  3. copyright (C) 2008 Olaf.Klein@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. #include "gbfile.h"
  18. #include "jeeps/gpsmath.h"
  19. #define MYNAME "navitel"
  20. static gbfile* fin, *fout;
  21. static char new_track;
  22. static int trkpts;
  23. /*******************************************************************************
  24. * %%% global callbacks called by gpsbabel main process %%% *
  25. *******************************************************************************/
  26. static void
  27. navitel_rd_init(const QString& fname)
  28. {
  29. fin = gbfopen(fname, "rb", MYNAME);
  30. }
  31. static void
  32. navitel_rd_deinit(void)
  33. {
  34. gbfclose(fin);
  35. }
  36. static void
  37. navitel_read_track(void)
  38. {
  39. int points, i;
  40. route_head* trk = NULL;
  41. points = gbfgetint32(fin);
  42. (void) gbfgetint32(fin); /* unknown */
  43. for (i = 0; i < points; i++) {
  44. int lat, lon;
  45. Waypoint* wpt;
  46. lon = gbfgetint32(fin);
  47. lat = gbfgetint32(fin);
  48. wpt = new Waypoint;
  49. wpt->latitude = GPS_Math_Semi_To_Deg(lat & 0x7FFFFFFF);
  50. wpt->longitude = GPS_Math_Semi_To_Deg(lon);
  51. if ((lat >> 31) || (trk == NULL)) {
  52. trk = route_head_alloc();
  53. track_add_head(trk);
  54. }
  55. track_add_wpt(trk, wpt);
  56. }
  57. }
  58. static void
  59. navitel_wr_init(const QString& fname)
  60. {
  61. fout = gbfopen(fname, "wb", MYNAME);
  62. }
  63. static void
  64. navitel_wr_deinit(void)
  65. {
  66. gbfclose(fout);
  67. }
  68. static void
  69. navitel_enum_trkpts(const Waypoint* wpt)
  70. {
  71. trkpts++;
  72. }
  73. static void
  74. navitel_disp_trk_head(const route_head* trk)
  75. {
  76. new_track = 1;
  77. }
  78. static void
  79. navitel_disp_trkpts(const Waypoint* wpt)
  80. {
  81. int lat, lon;
  82. lat = GPS_Math_Deg_To_Semi(wpt->latitude);
  83. lon = GPS_Math_Deg_To_Semi(wpt->longitude);
  84. if (new_track) {
  85. lat |= (1 << 31);
  86. new_track = 0;
  87. }
  88. gbfputint32(lon, fout);
  89. gbfputint32(lat, fout);
  90. }
  91. static void
  92. navitel_write_track(void)
  93. {
  94. trkpts = 0;
  95. track_disp_all(NULL, NULL, navitel_enum_trkpts);
  96. if (trkpts > 10000) {
  97. trkpts = 10000;
  98. warning(MYNAME ": Can store only 10000 points per file!\n");
  99. }
  100. gbfputint32(trkpts, fout);
  101. gbfputint32(1, fout); /* ? */
  102. track_disp_all(navitel_disp_trk_head, NULL, navitel_disp_trkpts);
  103. }
  104. /**************************************************************************/
  105. ff_vecs_t navitel_trk_vecs = {
  106. ff_type_file,
  107. {
  108. ff_cap_none /* waypoints */,
  109. (ff_cap)(ff_cap_read | ff_cap_write) /* tracks */,
  110. ff_cap_none /* routes */
  111. },
  112. navitel_rd_init,
  113. navitel_wr_init,
  114. navitel_rd_deinit,
  115. navitel_wr_deinit,
  116. navitel_read_track,
  117. navitel_write_track,
  118. NULL,
  119. NULL,
  120. CET_CHARSET_UTF8, 1 /* Nothing to convert */
  121. };
  122. /**************************************************************************/