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.

mapbar_track.cc 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. China mapbar navigation track reader for sonim xp3300
  3. it's maybe can used in other demo devices of mapbar navigation
  4. Copyright (C) 2013 xiao jian cheng, azuresky.xjc@gmail.com
  5. Copyright (C) 2001-2013 Robert Lipe, robertlipe+source@gpsbabel.org
  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 <QtCore/QDebug>
  20. #define MYNAME "mapbar_track"
  21. static gbfile* fin;
  22. static
  23. arglist_t mapbar_track_args[] = {
  24. ARG_TERMINATOR
  25. };
  26. /*******************************************************************************
  27. * %%% global callbacks called by gpsbabel main process %%% *
  28. *******************************************************************************/
  29. static void
  30. mapbar_track_rd_init(const QString& fname)
  31. {
  32. fin = gbfopen(fname, "r", MYNAME);
  33. }
  34. static void
  35. mapbar_track_rd_deinit(void)
  36. {
  37. gbfclose(fin);
  38. }
  39. static gpsbabel::DateTime
  40. read_datetime(void)
  41. {
  42. int hour = gbfgetint16(fin);
  43. int min = gbfgetint16(fin);
  44. int sec = gbfgetint16(fin);
  45. int year = gbfgetint16(fin);
  46. int mon = gbfgetint16(fin);
  47. int mday = gbfgetint16(fin);
  48. gpsbabel::DateTime t(QDate(year, mon, mday), QTime(hour, min, sec));
  49. // qDebug() << t;
  50. return t;
  51. }
  52. static const double DIV_RATE = 100000.0f;
  53. static Waypoint*
  54. read_waypoint(void)
  55. {
  56. int longitude = gbfgetint32(fin);
  57. int latitude = gbfgetint32(fin);
  58. Waypoint* ret = new Waypoint;
  59. ret->latitude = double(latitude)/DIV_RATE;
  60. ret->longitude = double(longitude)/DIV_RATE;
  61. return ret;
  62. }
  63. static void
  64. mapbar_track_read(void)
  65. {
  66. route_head* track = route_head_alloc();
  67. is_fatal((track == NULL), MYNAME ": memory non-enough");
  68. track_add_head(track);
  69. (void) read_datetime(); // start_time currently unused
  70. (void) read_datetime(); // end_time currently unused
  71. ushort name[200] = {0};
  72. gbfread((void*)name, 1, 200, fin);
  73. // At this point, name is a UCS-16 encoded, zero terminated string.
  74. // All our internals use Qt encoding, so convert now.
  75. track->rte_name = QString().fromUtf16(name);
  76. // skip two pair waypoint
  77. gbfseek(fin, 8*4, SEEK_CUR);
  78. // skip way length
  79. gbfseek(fin, 8, SEEK_CUR);
  80. // skip fixed value
  81. gbfseek(fin, 4, SEEK_CUR);
  82. int end_flag = gbfgetint32(fin);
  83. for (;;) {
  84. if (end_flag) {
  85. break;
  86. }
  87. int length = gbfgetint32(fin);
  88. is_fatal((length < 1) || (length > 1600), MYNAME ": get bad buffer length");
  89. is_fatal((length % 8 != 0), MYNAME ": bad buffer size");
  90. gbfseek(fin, 16, SEEK_CUR);
  91. const int amount = length/8;
  92. for (int i = 0; i < amount; ++i) {
  93. Waypoint* tmp = read_waypoint();
  94. track_add_wpt(track, tmp);
  95. }
  96. end_flag = gbfgetint32(fin);
  97. }
  98. }
  99. // capabilities below means: we can only read trackpoints.
  100. ff_vecs_t mapbar_track_vecs = {
  101. ff_type_file,
  102. { ff_cap_none, (ff_cap)(ff_cap_read), ff_cap_none },
  103. mapbar_track_rd_init,
  104. NULL,
  105. mapbar_track_rd_deinit,
  106. NULL,
  107. mapbar_track_read,
  108. NULL,
  109. NULL,
  110. mapbar_track_args,
  111. CET_CHARSET_UTF8, 0
  112. /* not fixed, can be changed through command line parameter */
  113. };