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.

sbp.cc 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. Locosys NaviGPS GT-31/BGT-31 binary datalog format (SBP)
  3. Copyright (C) 2008 Rodney Lorrimar <rodney@rodney.id.au>
  4. Copyright (C) 2005 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 "navilink.h"
  19. #define MYNAME "sbp"
  20. static gbfile* file_handle = NULL;
  21. static
  22. arglist_t sbp_args[] = {
  23. ARG_TERMINATOR
  24. };
  25. /*******************************************************************************
  26. * %%% global callbacks called by gpsbabel main process %%% *
  27. *******************************************************************************/
  28. static void
  29. sbp_rd_init(const QString& fname)
  30. {
  31. file_handle = gbfopen(fname, "r", MYNAME);
  32. }
  33. static void
  34. sbp_rd_deinit(void)
  35. {
  36. gbfclose(file_handle);
  37. }
  38. static void
  39. read_sbp_header(route_head* track)
  40. {
  41. /*
  42. * A complete SBP file contains 64 bytes header,
  43. *
  44. * Here is the definition of the SBP header
  45. * BYTE 0 ~1 : true SBP header length
  46. * BYTE 2~63: MID_FILE_ID(0xfd)
  47. * will stuff 0xff for remaining bytes
  48. */
  49. #define HEADER_SKIP 7
  50. int success;
  51. char header[64];
  52. if (gbfread(header, sizeof(header), 1, file_handle) == 1) {
  53. size_t len = le_read16(header) - HEADER_SKIP;
  54. if (len > sizeof(header)) {
  55. len = sizeof(header);
  56. }
  57. success = locosys_decode_file_id(header + HEADER_SKIP, len);
  58. } else {
  59. success = FALSE;
  60. }
  61. if (!success) {
  62. fatal(MYNAME ": Format error: Couldn't read SBP header."
  63. "This probably isn't a SBP file.\n");
  64. }
  65. }
  66. static Waypoint*
  67. read_logpoint(void)
  68. {
  69. unsigned char buffer[SBP_RECORD_LEN];
  70. if (gbfread(buffer, sizeof(buffer), 1, file_handle) == 1) {
  71. return navilink_decode_logpoint(buffer);
  72. }
  73. return NULL;
  74. }
  75. static void
  76. sbp_read(void)
  77. {
  78. Waypoint* logpoint;
  79. route_head* track;
  80. track = route_head_alloc();
  81. track_add_head(track);
  82. read_sbp_header(track);
  83. while ((logpoint = read_logpoint())) {
  84. track_add_wpt(track, logpoint);
  85. }
  86. }
  87. static void
  88. sbp_exit(void)
  89. {
  90. }
  91. /**************************************************************************/
  92. ff_vecs_t sbp_vecs = {
  93. ff_type_file,
  94. {
  95. ff_cap_none /* waypoints */,
  96. ff_cap_read /* tracks */,
  97. ff_cap_none /* routes */
  98. },
  99. sbp_rd_init,
  100. NULL,
  101. sbp_rd_deinit,
  102. NULL,
  103. sbp_read,
  104. NULL,
  105. sbp_exit,
  106. sbp_args,
  107. CET_CHARSET_ASCII, 0 /* ascii is the expected character set */
  108. /* not fixed, can be changed through command line parameter */
  109. };
  110. /**************************************************************************/