forked from GPSBabel/gpsbabel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bushnell_trl.cc
151 lines (125 loc) · 3.12 KB
/
bushnell_trl.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
Read and write Bushnell trail *.trl files.
Copyright (C) 2009 Robert Lipe ([email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
*/
#include "defs.h"
#define MYNAME "Bushnell Trail"
static gbfile* file_in;
static gbfile* file_out;
static int trkpt_count;
static route_head* trk_head;
static
arglist_t bushnell_args[] = {
ARG_TERMINATOR
};
static void
rd_init(const QString& fname)
{
char h[0x14]; // Believed to be zero terminated.
file_in = gbfopen_le(fname, "rb", MYNAME);
gbfread(h, 1, sizeof(h), file_in);
trk_head = route_head_alloc();
track_add_head(trk_head);
trk_head->rte_name = lrtrim(h);
}
static void
rd_deinit(void)
{
gbfclose(file_in);
}
static void
wr_init(const QString& fname)
{
int i;
int l = fname.length();
char obuf[20] = { 0 } ;
char* p = obuf;
file_out = gbfopen_le(fname, "w", MYNAME);
trkpt_count = 0;
QString fnameu = fname.toUpper();
for (i = 0; (i < l) && (i < 20); i++) {
char c = fnameu[i].toLatin1();
if (isalnum(c)) {
*p++ = c;
}
if (c == '.') {
break;
}
}
gbfwrite(&obuf, 1, 20, file_out);
}
static void
wr_deinit(void)
{
int i = trkpt_count;
while (i < 4502) {
gbfputint32(0, file_out);
gbfputint32(0, file_out);
i++;
}
gbfputint32(0, file_out);
gbfputint16(trkpt_count, file_out);
gbfputc(1, file_out);
gbfclose(file_out);
}
/*
* Each file contains a single waypoint.
*/
static void
bushnell_read(void)
{
int lat_tmp,lon_tmp;
while (1) {
Waypoint* wpt_tmp;
lat_tmp = gbfgetint32(file_in);
lon_tmp = gbfgetint32(file_in);
if (!lat_tmp && !lon_tmp) {
break;
}
wpt_tmp = new Waypoint;
wpt_tmp->latitude = lat_tmp / 10000000.0;
wpt_tmp->longitude = lon_tmp / 10000000.0;
track_add_wpt(trk_head, wpt_tmp);
}
}
static void
bushnell_write_one(const Waypoint* wpt)
{
int32_t lat = wpt->latitude * 10000000.0;
int32_t lon = wpt->longitude * 10000000.0;
trkpt_count++;
if (trkpt_count > 4502) {
fatal(MYNAME " too many trackpoints. Max is 4502.");
}
gbfputint32(lat, file_out);
gbfputint32(lon, file_out);
}
static void
bushnell_write(void)
{
track_disp_all(NULL, NULL, bushnell_write_one);
}
ff_vecs_t bushnell_trl_vecs = {
ff_type_file,
{ ff_cap_none, (ff_cap)(ff_cap_read | ff_cap_write), ff_cap_none },
rd_init,
wr_init,
rd_deinit,
wr_deinit,
bushnell_read,
bushnell_write,
NULL,
bushnell_args,
CET_CHARSET_MS_ANSI, 0 /* Not really sure... */
};