Debian Codegraph @

globalsat_sport.h

raw symbols SCIP
1 /*
2 Global data for GPSBabel.
3
4 Copyright (C) 2012-2016, Zingo Andersen [email protected]
5 Copyright (C) 2016 Robert Lipe, [email protected]
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
21 */
22 /*
23 * This is the bridge between the GPSBabel and globalsat sport devices
24 * gh625XT. Globalsat has a few devices under the sport brand and they
25 * are using a similar USB serial protocol.
26 * Currently only gh625XT is supported by this driver but the code could
27 * extended (maybe autodetect) support more devices in the future.
28 *
29 * The code is based on GH625XT-COMMUNICATION_SPECS_20111205-1.pdf from Globasat
30 * that they nicely supplied on request.
31 *
32 * Usage examples:
33 * gpsbabel -i globalsat -f /dev/ttyUSB0 -o gpx,garminextensions -F xxx.gpx
34 * gpsbabel -i globalsat -f /dev/ttyUSB0 -o gtrnctr,course=0,sport=Running -F xxx.fit
35 *
36 */
37 #ifndef GLOBALSATSPORT_H_INCLUDED_
38 #define GLOBALSATSPORT_H_INCLUDED_
39
40 #include <cstdint> // for uint32_t, uint8_t, uint16_t, int16_t
41
42 #include <QList> // for QList
43 #include <QString> // for QString
44 #include <QTimeZone> // for QTimeZone
45 #include <QVector> // for QVector
46
47 #include "defs.h"
48 #include "format.h" // for Format
49 #include "gbfile.h" // for gbfclose, gbfopen, gbfread, gbfwrite, gbfile
50 #include "option.h" // for OptionString, OptionBool
51
52
53 class GlobalsatSportFormat : public Format
54 {
55 public:
56 QVector<arglist_t>* get_args() override
57 {
58 return &globalsat_args;
59 }
60
61 ff_type get_type() const override
62 {
63 return ff_type_serial;
64 }
65
66 QVector<ff_cap> get_cap() const override
67 {
68 return {
69 ff_cap_none, // waypoints
70 ff_cap_read, // tracks
71 ff_cap_none, // routes
72 };
73 }
74
75 void rd_init(const QString& fname) override;
76 void read() override;
77 void rd_deinit() override;
78
79 private:
80 /* Types */
81 enum globalsat_commands_e {
82 CommandWhoAmI = 0xBF,
83 CommandGetSystemInformation = 0x85,
84 CommandGetSystemConfiguration = 0x86,
85
86 CommandSetSystemConfiguration = 0x96,
87 CommandSetSystemInformation = 0x98,
88 CommandGetScreenshot = 0x83,
89
90 CommandGetWaypoints = 0x77,
91 CommandSendWaypoint = 0x76,
92 CommandDeleteWaypoints = 0x75,
93
94 CommandSendRoute = 0x93,
95 CommandDeleteAllRoutes = 0x97,
96
97 CommandGetTrackFileHeaders = 0x78,
98 CommandGetTrackFileSections = 0x80,
99 CommandGetNextTrackSection = 0x81,
100 //CommandReGetLastSection = 0x82,
101 CommandId_FINISH = 0x8A,
102 CommandSendTrackStart = 0x90,
103 CommandSendTrackSection = 0x91,
104
105 HeaderTypeLaps = 0xAA,
106 HeaderTypeTrackPoints = 0x55,
107
108 ResponseInsufficientMemory = 0x95,
109 ResponseResendTrackSection = 0x92,
110 ResponseSendTrackFinish = 0x9A
111 };
112
113 struct gh_date {
114 uint8_t Year;
115 uint8_t Month;
116 uint8_t Day;
117 };
118
119 struct gh_time {
120 uint8_t Hour;
121 uint8_t Minute;
122 uint8_t Second;
123 };
124
125 struct gh_trainheader {
126 gh_date dateStart;
127 gh_time timeStart;
128 uint32_t TotalPoint; //6-9
129 uint32_t TotalTime; //10-13
130 uint32_t TotalDistance; //14-17
131 uint16_t LapCnts; //18-19
132 union {
133 uint32_t Index;
134 uint32_t StartPt;
135 } gh_ptrec; //20-23
136 union {
137 uint32_t LapIndex;
138 uint32_t EndPt;
139 } gh_laprec; //24-27
140 uint8_t DataType; //28
141 };
142
143 struct gh_db_train {
144 gh_date dateStart;
145 gh_time timeStart;
146 uint32_t TotalPoint; //6-9
147 uint32_t TotalTime; //10-13
148 uint32_t TotalDistance; //14-17
149 uint16_t LapCnts; //18-19
150 union {
151 uint32_t Index;
152 uint32_t StartPt;
153 } gh_ptrec; //20-23
154 union {
155 uint32_t LapIndex;
156 uint32_t EndPt;
157 } gh_laprec; //24-27
158 uint8_t MultiSport; //28 on/off
159 uint16_t Calory; //29-30
160 uint32_t MaxSpeed;
161 uint8_t MaxHeart;
162 uint8_t AvgHeart;
163
164 uint16_t Ascent;
165 uint16_t Descent;
166
167 int16_t MinAlti;
168 int16_t MaxAlti;
169 uint16_t AvgCadns;
170 uint16_t BestCadns;
171 uint16_t AvgPower;
172 uint16_t MaxPower;
173 uint8_t Sport1;
174 uint8_t Sport2;
175 uint8_t Sport3;
176 uint8_t Sport4;
177 uint8_t Sport5;
178 };
179
180 struct gh_db_lap {
181 uint32_t AccruedTime;
182 uint32_t TotalTime;
183 uint32_t TotalDistance;
184 uint16_t Calory;
185 uint32_t MaxSpeed;
186 uint8_t MaxHeart;
187 uint8_t AvgHeart;
188 int16_t MinAlti;
189 int16_t MaxAlti;
190 uint16_t AvgCadns;
191 uint16_t BestCadns;
192 uint16_t AvgPower;
193 uint16_t MaxPower;
194 uint8_t MultiSportIndex;
195 uint32_t StartPt;
196 uint32_t EndPt;
197 };
198
199 struct gh_recpoint {
200 uint32_t Latitude;
201 uint32_t Longitude;
202 int16_t Altitude;
203 uint32_t Speed;
204 uint8_t HeartRate;
205 uint32_t IntervalTime;
206 uint16_t Cadence;
207 uint16_t PwrCadence;
208 uint16_t Power;
209 };
210
211 /* Member Functions */
212
213 void serial_init(const char* fname);
214 void serial_deinit();
215 int serial_recv_byte() const;
216 void serial_write_byte(uint8_t byte);
217 int recv_byte();
218 void write_byte(uint8_t byte);
219 void globalsat_write_package(uint8_t* payload, uint32_t size);
220 uint8_t* globalsat_read_package(int* out_length, uint8_t* out_DeviceCommand);
221 void globalsat_send_simple(uint8_t command);
222 void globalsat_probe_device();
223 void waypoint_read();
224 void track_read();
225 static void route_read();
226
227 /* Data Members */
228
229 void* serial_handle{nullptr};
230 bool isSizeSwapped{false};
231
232 OptionBool showlist; // if true show a list instead of download tracks
233
234 OptionString opt_dump_file; // dump raw data to this file (optional)
235 OptionBool opt_input_dump_file; // if true input is from a dump-file instead of serial console
236 OptionString opt_timezone;
237 gbfile* dumpfile{nullptr}; // used for creating bin/RAW datadump files, useful for testing
238 gbfile* in_file{nullptr}; // used for reading from bin/RAW datadump files, useful for testing
239 QTimeZone* timezn{nullptr};
240
241 QVector<arglist_t> globalsat_args = {
242 {"showlist", &showlist, "list tracks", nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr},
243 {"dump-file", &opt_dump_file, "Dump raw data to this file", nullptr, ARGTYPE_OUTFILE, ARG_NOMINMAX, nullptr},
244 {"input-is-dump-file", &opt_input_dump_file, "Dump raw data to this file", nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr},
245 {"timezone", &opt_timezone, "Time zone ID", nullptr, ARGTYPE_STRING, ARG_NOMINMAX, nullptr},
246 };
247 };
248 #endif // GLOBALSATSPORT_H_INCLUDED_