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.

154 lines
3.2KB

  1. /*
  2. Support for VidaOne GPS for Pocket PC (.gpb) files
  3. Copyright (C) 2008 Olaf Klein, o.b.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. /*
  17. Simple layout:
  18. struct
  19. {
  20. double dLatitude
  21. double dLongitude
  22. float fReserved
  23. };
  24. */
  25. #include "defs.h"
  26. #include <stdlib.h>
  27. #include <math.h>
  28. #define MYNAME "vidaone"
  29. #define VIDAONE_VER "ver"
  30. static char* vidaone_opt_ver;
  31. static int vidaone_ver;
  32. static
  33. arglist_t vidaone_args[] = {
  34. {
  35. VIDAONE_VER, &vidaone_opt_ver,
  36. "Version of VidaOne file to read or write (1 or 2)",
  37. "1", ARGTYPE_INT, "1", "2"
  38. },
  39. ARG_TERMINATOR
  40. };
  41. static gbfile* fin, *fout;
  42. /*******************************************************************************
  43. * %%% global callbacks called by gpsbabel main process %%% *
  44. *******************************************************************************/
  45. static void
  46. vidaone_rd_init(const QString& fname)
  47. {
  48. vidaone_ver = atoi(vidaone_opt_ver);
  49. fin = gbfopen(fname, "rb", MYNAME);
  50. }
  51. static void
  52. vidaone_rd_deinit(void)
  53. {
  54. gbfclose(fin);
  55. }
  56. static void
  57. vidaone_read(void)
  58. {
  59. route_head* trk = NULL;
  60. while (! gbfeof(fin)) {
  61. Waypoint* wpt = new Waypoint;
  62. wpt->latitude = gbfgetdbl(fin);
  63. wpt->longitude = gbfgetdbl(fin);
  64. if (vidaone_ver >= 2) {
  65. wpt->altitude = gbfgetflt(fin);
  66. }
  67. (void) gbfgetflt(fin);
  68. /* Only one basic check of data integrity */
  69. if ((fabs(wpt->latitude) > 90) || (fabs(wpt->longitude) > 180)) {
  70. fatal(MYNAME ": Latitude and/or longitude out of range.\n");
  71. }
  72. if (!trk) {
  73. trk = route_head_alloc();
  74. track_add_head(trk);
  75. }
  76. track_add_wpt(trk, wpt);
  77. }
  78. }
  79. static void
  80. vidaone_wr_init(const QString& fname)
  81. {
  82. vidaone_ver = atoi(vidaone_opt_ver);
  83. fout = gbfopen(fname, "wb", MYNAME);
  84. }
  85. static void
  86. vidaone_wr_deinit(void)
  87. {
  88. gbfclose(fout);
  89. }
  90. static void
  91. vidaone_trkpt(const Waypoint* wpt)
  92. {
  93. gbfputdbl(wpt->latitude, fout);
  94. gbfputdbl(wpt->longitude, fout);
  95. if (vidaone_ver >= 2) {
  96. gbfputflt(wpt->altitude, fout);
  97. }
  98. gbfputflt(0, fout);
  99. }
  100. static void
  101. vidaone_write(void)
  102. {
  103. track_disp_all(NULL, NULL, vidaone_trkpt);
  104. }
  105. /**************************************************************************/
  106. ff_vecs_t vidaone_vecs = {
  107. ff_type_file,
  108. {
  109. ff_cap_none /* waypoints */,
  110. (ff_cap)(ff_cap_read | ff_cap_write) /* tracks */,
  111. ff_cap_none /* routes */
  112. },
  113. vidaone_rd_init,
  114. vidaone_wr_init,
  115. vidaone_rd_deinit,
  116. vidaone_wr_deinit,
  117. vidaone_read,
  118. vidaone_write,
  119. NULL,
  120. vidaone_args,
  121. CET_CHARSET_UTF8, 1
  122. };
  123. /**************************************************************************/