-
Notifications
You must be signed in to change notification settings - Fork 127
/
dg-100.h
220 lines (178 loc) · 5.69 KB
/
dg-100.h
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*
GlobalSat DG-100/DG-200 GPS data logger download.
Copyright (C) 2007 Mirko Parthey, mirko.parthey@informatik.tu-chemnitz.de
Copyright (C) 2005-2008 Robert Lipe, robertlipe+source@gpsbabel.org
Copyright (C) 2012 Nicolas Boullis, nboullis@debian.org
Copyright (C) 2014 Jean-Claude Repetto, gpsbabel@repetto.org
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*
DG-100 / DG-200 communication protocol specification:
http://www.usglobalsat.com/s-176-developer-information.aspx
*/
#ifndef DG100_H_INCLUDED_
#define DG100_H_INCLUDED_
#include <cstdint> // for uint8_t, int16_t, uint16_t
#include <cstdio> // for size_t
#include <QDateTime> // for QDateTime
#include <QList> // for QList
#include <QString> // for QString
#include <QVector> // for QVector
#include "defs.h"
#include "format.h" // for Format
#include "gbfile.h" // for gbfile
#include "option.h" // for OptionBool
class Dg100Format : public Format
{
public:
/* Member Functions */
QVector<arglist_t>* get_args() override
{
return &dg100_args;
}
QVector<ff_cap> get_cap() const override
{
return {
ff_cap_read /* waypoints */,
ff_cap_read /* tracks */,
ff_cap_none /* routes */
};
}
void read() override;
void rd_deinit() override;
protected:
/* Types */
enum dg100_command_id {
dg100cmd_getconfig = 0xB7,
dg100cmd_setconfig = 0xB8,
dg100cmd_getfileheader = 0xBB,
dg100cmd_getfile = 0xB5,
dg100cmd_erase = 0xBA,
dg100cmd_getid = 0xBF,
dg100cmd_setid = 0xC0,
dg100cmd_gpsmouse = 0xBC,
dg200cmd_reset = 0x80
};
struct dg100_command {
int id;
int sendsize;
int recvsize;
int trailing_bytes;
const char* text; /* Textual description for debugging */
};
struct model_t {
const char* name;
unsigned speed;
bool has_trailing_bytes;
bool has_payload_end_seq;
const dg100_command* commands;
unsigned int numcommands;
};
/* Constants */
/* maximum frame size observed so far: 1817 bytes
* (dg100cmd_getfileheader returning 150 entries)
* dg100cmd_getfileheader is the only answer type of variable length,
* answers of other types are always shorter than 1817 bytes */
static constexpr int FRAME_MAXLEN = 4096;
/* Member Functions */
const dg100_command* dg100_findcmd(int id) const;
static QDateTime bintime2utc(int date, int time);
static void dg100_debug(const char* hdr, int include_nl, size_t sz, unsigned char* buf);
[[gnu::format(printf, 1, 2)]] static void dg100_log(const char* fmt, ...);
static float bin2deg(int val);
void process_gpsfile(uint8_t* data, route_head** track) const;
static uint16_t dg100_checksum(const uint8_t* buf, int count);
size_t dg100_send(uint8_t cmd, const void* payload, size_t param_len) const;
int dg100_recv_byte() const;
int dg100_read_wait(void* handle, void* buf, unsigned int len, unsigned int ms) const;
int dg100_recv_frame(const dg100_command** cmdinfo_result, uint8_t** payload) const;
int dg100_recv(uint8_t expected_id, void* buf, unsigned int len) const;
int dg100_request(uint8_t cmd, const void* sendbuf, void* recvbuf, size_t count) const;
QList<int> dg100_getfileheaders() const;
void dg100_getconfig() const;
void dg100_getfile(int16_t num, route_head** track) const;
void dg100_getfiles() const;
int dg100_erase() const;
void common_rd_init(const QString& fname);
void dg100_rd_init(const QString& fname, bool is_file);
void dg200_rd_init(const QString& fname, bool is_file);
/* Data Members */
const model_t* model{nullptr};
void* serial_handle{nullptr};
gbfile* fin{nullptr};
bool isfile{false};
static const dg100_command dg100_commands[];
static const dg100_command dg200_commands[];
/* GPSBabel integration */
OptionBool erase;
OptionBool erase_only;
QVector<arglist_t> dg100_args = {
{
"erase", &erase, "Erase device data after download",
"0", ARGTYPE_BOOL, ARG_NOMINMAX, nullptr
},
{
"erase_only", &erase_only, "Only erase device data, do not download anything",
"0", ARGTYPE_BOOL, ARG_NOMINMAX, nullptr
},
};
};
class Dg100SerialFormat : public Dg100Format
{
public:
ff_type get_type() const override
{
return ff_type_serial;
}
void rd_init(const QString& fname) override
{
dg100_rd_init(fname, false);
}
};
class Dg100FileFormat : public Dg100Format
{
public:
ff_type get_type() const override
{
return ff_type_internal;
}
void rd_init(const QString& fname) override
{
dg100_rd_init(fname, true);
}
};
class Dg200SerialFormat : public Dg100Format
{
public:
ff_type get_type() const override
{
return ff_type_serial;
}
void rd_init(const QString& fname) override
{
dg200_rd_init(fname, false);
}
};
class Dg200FileFormat : public Dg100Format
{
public:
ff_type get_type() const override
{
return ff_type_internal;
}
void rd_init(const QString& fname) override
{
dg200_rd_init(fname, true);
}
};
#endif // DG100_H_INCLUDED_