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.

mynav.cc 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. Handle MyNav TRC format .trc and .ftn files
  3. Copyright (c) 2014 Ralf Horstmann <ralf@ackstorm.de>
  4. Copyright (C) 2014 Robert Lipe, robertlipe+source@gpsbabel.org
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
  16. */
  17. #include "defs.h"
  18. #include <QtCore/QDebug>
  19. #include <QtCore/QStringList>
  20. #define MYNAME "mynav"
  21. typedef enum {
  22. fld_type = 0,
  23. fld_lon,
  24. fld_lat,
  25. fld_direction,
  26. fld_speed,
  27. fld_altitude,
  28. fld_timestamp,
  29. fld_duration,
  30. fld_gps_valid,
  31. fld_distance,
  32. fld_ascent,
  33. fld_cadence,
  34. fld_heart_rate,
  35. fld_id,
  36. fld_total_duration,
  37. fld_terminator
  38. } field_e;
  39. static route_head* mynav_track;
  40. static gbfile* fin;
  41. //***************************************************************************
  42. // local helper functions
  43. //***************************************************************************
  44. static void
  45. mynav_rd_line(QString line)
  46. {
  47. QStringList fields = line.split("|");
  48. if (global_opts.debug_level > 1) {
  49. qDebug() << "line: " << line;
  50. for (int i = 0; i < fields.size(); i++) {
  51. qDebug() << "field" << i << fields.at(i);
  52. }
  53. }
  54. // don't consider lines without latitude/longitude
  55. if (fields.size() <= fld_lat) {
  56. return;
  57. }
  58. // only type 1 and type 5 lines contain coordinates
  59. bool ok = false;
  60. int val_type = fields.at(fld_type).trimmed().toInt(&ok);
  61. if (!ok) {
  62. return;
  63. }
  64. if (val_type != 1 && val_type != 5) {
  65. return;
  66. }
  67. // This field is not present in .trc files, only in .ftn, so
  68. // ignore line if present and != 1
  69. if (fields.size() > fld_gps_valid) {
  70. int val_gps_valid = fields.at(fld_gps_valid).trimmed().toInt(&ok);
  71. if (!ok || val_gps_valid != 1) {
  72. return;
  73. }
  74. }
  75. double val_lon = fields.at(fld_lon).trimmed().toDouble(&ok) / 3600000.0;
  76. if (!ok) {
  77. return;
  78. }
  79. double val_lat = fields.at(fld_lat).trimmed().toDouble(&ok) / 3600000.0;
  80. if (!ok) {
  81. return;
  82. }
  83. Waypoint* wpt = new Waypoint;
  84. wpt->latitude = val_lat;
  85. wpt->longitude = val_lon;
  86. if (fields.size() > fld_altitude) {
  87. double val_alt = fields.at(fld_altitude).trimmed().toDouble(&ok);
  88. if (ok) {
  89. wpt->altitude = val_alt;
  90. }
  91. }
  92. if (fields.size() > fld_timestamp) {
  93. int val_time = fields.at(fld_timestamp).trimmed().toInt(&ok);
  94. if (ok) {
  95. wpt->SetCreationTime(val_time);
  96. }
  97. }
  98. track_add_wpt(mynav_track, wpt);
  99. }
  100. //***************************************************************************
  101. // global callbacks called by gpsbabel main process
  102. //***************************************************************************
  103. static void
  104. mynav_rd_init(const QString& fname)
  105. {
  106. fin = gbfopen(fname, "rb", MYNAME);
  107. mynav_track = route_head_alloc();
  108. track_add_head(mynav_track);
  109. }
  110. static void
  111. mynav_rd_deinit(void)
  112. {
  113. gbfclose(fin);
  114. }
  115. static void
  116. mynav_rd(void)
  117. {
  118. QString buff;
  119. while ((buff = gbfgetstr(fin)), !buff.isNull()) {
  120. buff = buff.trimmed();
  121. if ((buff.isEmpty()) || (buff[0] == '#')) {
  122. continue;
  123. }
  124. mynav_rd_line(buff);
  125. }
  126. }
  127. ff_vecs_t mynav_vecs = {
  128. ff_type_file,
  129. {
  130. ff_cap_none, // waypoints
  131. ff_cap_read, // tracks
  132. ff_cap_none // routes
  133. },
  134. mynav_rd_init, // rd_init
  135. NULL, // wr_init
  136. mynav_rd_deinit, // rd_deinit
  137. NULL, // wr_deinit
  138. mynav_rd, // read
  139. NULL, // write
  140. NULL, // exit
  141. NULL, //args
  142. CET_CHARSET_ASCII, 0 //encode,fixed_encode
  143. //NULL //name dynamic/internal?
  144. };