Subversion Repositories public

Rev

Rev 248 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
88 andreas 1
/***************************************************************************
119 andreas 2
 *   Copyright (C) 2007, 2008 by Andreas Theofilu                          *
3
 *   andreas@theosys.at                                                    *
88 andreas 4
 *                                                                         *
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 version 3 of the License.                *
8
 *                                                                         *
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
 *                                                                         *
14
 *   You should have received a copy of the GNU General Public License     *
15
 *   along with this program; if not, write to the                         *
16
 *   Free Software Foundation, Inc.,                                       *
17
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18
 ***************************************************************************/
19
 
20
#ifndef _DISASSEMBLE_H
21
#define _DISASSEMBLE_H
22
 
104 andreas 23
#define DEG_2_RAD  0.0174532925199432957692369076848861271L
24
 
249 andreas 25
/**
26
 * \file disassemble.h
27
 */
28
 
88 andreas 29
typedef struct
30
{
31
  int		   type;
32
  char             ident[7];       /* identifier            */
33
  position_type    posn;           /* position              */
34
  char             cmnt[41];       /* comment               */
35
  float32          dst;            /* proximity distance (meters) */
36
  uint8            smbl;           /* symbol id                   */
37
  uint8            dspl;           /* display option                */
38
  char *           wpt_ident;      /* null-terminated string      */
39
  char *           lnk_ident;      /* null-terminated string  */
40
  uint8            wpt_class;      /* class                   */
41
  unsigned char    subclass[21];   /* subclass                */
42
  uint8            color;          /* waypoint color               */
43
  uint8            attr;           /* attributes (see below)          1      */
44
  float32          alt;            /* altitude in meters              4      */
45
  float32          dpth;           /* depth in meters                 4      */
46
  char             state[3];       /* state                           2      */
47
  char             cc[3];          /* country code                    2      */
48
  char *           identity;          /* variable length string          1-51   */
49
  char *           comment;        /* waypoint user comment           1-51   */
50
  char *           facility;       /* facility name                   1-31   */
51
  char *           city;           /* city name                       1-25   */
52
  char *           addr;           /* address number                  1-51   */
53
  char *           cross_road;     /* intersecting road label         1-51   */
54
  uint8            dtyp;           /* data packet type (0x01 for D109) 1    */
55
  uint8            dspl_color;     /* display & color (see below)      1    */
56
  uint32           ete;            /* outbound link ete in seconds     4    */
57
  float32          temp;           /* temperature                      4    */
58
  time_type        time;           /* timestamp                        4    */
59
  sint16           idx;            /* proximity index                   */
60
} WAYPOINT;
61
 
62
typedef struct
63
{
64
  char             name[18];        /* category name */
65
} WPCATEGORY;
66
 
67
typedef struct
68
{
69
  int		        type;
70
  uint8                 nmbr;       /* route number            */
71
  char                  cmnt[21];   /* comment                 */
72
  char *                rte_ident;  /* null-terminated string  */
73
} ROUTE;
74
 
75
typedef struct
76
{
77
  int			type;
78
  uint16                klasse;        /* link class; see below           */
79
  uint8                 subclass[20]; /* sublcass                        */
80
  char *                ident;        /* variable length string          */
81
} ROUTE_LINK;
82
 
83
typedef struct
84
{
85
  int		    type;
86
  position_type     posn;      /* position                        */
87
  uint32            time;      /* time                            */
88
  bool              new_trk;   /* new track segment?              */
89
  float32           alt;      /* altitude in meters        */
90
  float32           dpth;     /* depth in meters           */
91
  float32           temp;
92
  uint8             heart_rate;
93
  float32           distance;
94
  uint8             cadence;
95
  bool              sensor;
96
} POINT;
97
 
98
typedef struct POINT_NODE
99
{
100
	int number;
101
	POINT *point;
102
	POINT_NODE *next;
103
} POINT_NODE;
104
 
105
typedef struct
106
{
107
  int		type;
108
  bool          dspl;           /* display on the map?        */
109
  uint8         color;          /* color (same as D108)       */
110
  char *        trk_ident;      /* null-terminated string     */
111
  uint16        index;   /* unique among all tracks received from device */
112
} TRACK;
113
 
114
typedef struct
115
{
116
  int		type;
117
  sint16        wn;    /* week number                          (weeks)    */
118
  float32       toa;   /* almanac data reference time              (s)    */
119
  float32       af0;   /* clock correction coefficient             (s)    */
120
  float32       af1;   /* clock correction coefficient           (s/s)    */
121
  float32       e;     /* eccentricity                             (-)    */
122
  float32       sqrta; /* square root of semi-major axis (a)  (m**1/2)    */
123
  float32       m0;    /* mean anomaly at reference time           (r)    */
124
  float32       w;     /* argument of perigee                      (r)    */
125
  float32       omg0;  /* right ascension                          (r)    */
126
  float32       odot;  /* rate of right ascension                (r/s)    */
127
  float32       i;     /* inclination angle                        (r)    */
128
  uint8         hlth;  /* almanac health                                 */
129
  char          svid;  /* satellite id                                   */
130
} ALMANAC;
131
 
132
typedef struct
133
{
134
  uint8     month;            /* month  (1-12)                  */
135
  uint8     day;              /* day    (1-31)                  */
136
  uint16    year;             /* year   (1990 means 1990)       */
137
  sint16    hour;             /* hour   (0-23)                  */
138
  uint8     minute;           /* minute (0-59)                  */
139
  uint8     second;           /* second (0-59)                  */
140
} DATETIME;
141
 
142
typedef struct
143
{
144
  int		    type;
145
  time_type         takeoff_time;
146
  time_type         landing_time;
147
  position_type     takeoff_posn;
148
  position_type     landing_posn;
149
  uint32            night_time;
150
  uint32            num_landings;
151
  float32           max_speed;
152
  float32           max_alt;
153
  float32           distance;
154
  bool              cross_country_flag;
155
  char *            departure_name;
156
  char *            departure_ident;
157
  char *            arrival_name;
158
  char *            arrival_ident;
159
  char *            ac_id;
160
} FLIGHTBOOK;
161
 
162
typedef struct
163
{
164
  float32               alt;        /* alt above WGS 84 ellipsoid (m)        */
165
  float32               epe;        /* est. position error, 2 sigma (m)      */
166
  float32               eph;        /* epe, but horizontal only (meters)     */
167
  float32               epv;        /* epe, but vertical only (meters)       */
168
  sint16                fix;        /* type of position fix                  */
169
  float64               tow;        /* time of week (seconds)                */
170
  radian_position_type  posn;       /* latitude and longitude (radians)      */
171
  float32               east;       /* velocity east  (meters/second)        */
172
  float32               north;      /* velocity north (meters/second)        */
173
  float32               up;         /* velocity up    (meters/second)        */
174
  float32               msl_hght;   /* ht. of WGS 84 ellipsoid above MSL (m) */
175
  sint16                leap_scnds; /* diff between GPS and UTC (seconds)    */
176
  sint32                wn_days;    /* week number days                      */
177
} PVT;
178
 
179
typedef struct
180
{
181
  int		   type;
182
  uint32           start_time;
183
  uint32           total_time;      /* In hundredths of a second */
184
  float32          total_distance;  /* In meters */
185
  position_type    begin;           /* Invalid if lat and lon are 0x7fffffff */
186
  position_type    end;             /* Invalid if lat and lon are 0x7fffffff */
187
  uint16           calories;
188
  uint8            track_index;     /* See below */
189
  uint32           index;
190
  float32          max_speed;
191
  uint8            avg_heart_rate;
192
  uint8            max_heart_rate;
193
  uint8            intensity;
194
  uint8            avg_cadence;
195
  uint8            trigger_method;
196
} LAP;
197
 
198
typedef struct LAP_NODE
199
{
200
	LAP *lap;
201
	LAP_NODE *next;
202
} LAP_NODE;
203
 
204
typedef struct
205
{
206
  int			       type;
207
  uint32                       num_valid_steps;
208
  struct {
209
    char                       custom_name[17];
210
    float32                    target_custom_zone_low;
211
    float32                    target_custom_zone_high;
212
    uint16                     duration_value;
213
    uint8                      intensity;
214
    uint8                      duration_type;
215
    uint8                      target_type;
216
    uint8                      target_value;
217
  }                            steps[20];
218
  char                         name[17];
219
  uint8                        sport_type;
220
  char                         workout_name[17];
221
  time_type                    day;
222
  uint32                       max_workouts;
223
  uint32                       max_unscheduled_workouts;
224
  uint32                       max_occurrences;
225
} WORKOUT;
226
 
227
typedef struct
228
{
229
  int				type;
230
  uint32                       track_index;
231
  uint32                       first_lap_index;
232
  uint32                       last_lap_index;
233
  uint8                        sport_type;
234
  uint8                        program_type;
235
  uint8                        multisport;
236
  struct {
237
    uint32                     time;
238
    float32                    distance;
239
  }                            virtual_partner;
240
  WORKOUT                      workout;
241
} RUN;
242
 
243
typedef struct RUN_NODE
244
{
245
	RUN *run;
246
	RUN_NODE *next;
247
} RUN_NODE;
248
 
249
typedef struct
250
{
251
  int			       type;
252
  struct {
253
    struct {
254
      uint8                    low_heart_rate;
255
      uint8                    high_heart_rate;
256
    }                          heart_rate_zones[5];
257
    struct {
258
      float32                  low_speed;
259
      float32                  high_speed;
260
      char                     name[17];
261
    }                          speed_zones[10];
262
    float32                    gear_weight;
263
    uint8                      max_heart_rate;
264
  }                            activities[3];
265
  float32                      weight;
266
  uint16                       birth_year;
267
  uint8                        birth_month;
268
  uint8                        birth_day;
269
  uint8                        gender;
270
} FITNESS;
271
 
272
typedef struct
273
{
274
  int				type;
275
  uint16                       index;
276
  char                         course_name[17];
277
  uint16                       track_index;
278
  uint16                       course_index;
279
  uint16                       lap_index;
280
  uint32                       total_time;
281
  float32                      total_dist;
282
  position_type                begin;
283
  position_type                end;
284
  uint8                        avg_heart_rate;
285
  uint8                        max_heart_rate;
286
  uint8                        intensity;
287
  uint8                        avg_cadence;
288
  time_type                    track_point_time;
289
  uint8                        point_type;
290
  uint32                       max_courses;
291
  uint32                       max_course_laps;
292
  uint32                       max_course_pnt;
293
  uint32                       max_course_trk_pnt;
294
} COURSE;
295
 
249 andreas 296
/**
297
  * disassemble provides support for some Garmin Forerunner devices
298
  * connected over the USB port.
299
  *
300
  * It has routines to get out the data structure and stores everything
301
  * into an own structure. Beside this, it finds out some statistic
302
  * values.
303
  *
304
  * @author Andreas Theofilu <andreas@theosys.at>
305
  * @short class for deviding Garmin binary data into a structure
306
  */
88 andreas 307
class disassemble
308
{
309
	public:
249 andreas 310
	/**
311
	  * Constructs a disassemble class.
312
	  */
88 andreas 313
	   disassemble();
249 andreas 314
	/**
315
	  * Destructor
316
	  */
88 andreas 317
	   ~disassemble();
249 andreas 318
	/**
319
	  * Destroys all stored information about the currently loaded
320
	  * activity and cleans everything.
321
	  *
322
	  * This must be called before a new activity is loaded. It is also
323
	  * called, when the class is deleted from the destructor.
324
	  */
88 andreas 325
	   void destroy();
249 andreas 326
	/**
327
	  * This function needs a garmin_data structure. It devides the
328
	  * raw data in it to a node chain, a chain containing the laps and
329
	  * a chain containing all points.
330
	  *
331
	  * @param d    A pointer to a garmin_data structure.
332
	  */
88 andreas 333
	   void garmin_print_data (garmin_data *d);
334
 
335
	   LAP_NODE *addLap ();
336
	   LAP_NODE *getLapNode () { return lap_node; }
337
	   LAP *getLap(int index);
223 andreas 338
	   LAP *getLapT(uint32 time);
88 andreas 339
 
340
	   RUN_NODE *addRun ();
341
	   RUN_NODE *getRunNode () { return run_node; }
342
 
343
	   POINT_NODE *addPoint();
344
	   POINT_NODE *getPointNode() { return point_node; }
345
	   POINT *getPoint(int number);
346
	   POINT *getPoint(uint32 time);
249 andreas 347
	   POINT *getLastPoint();
88 andreas 348
 
248 andreas 349
	   double getTotalDistance() { return totalDistance; }
350
	   long   getTotalTime() { return totalTime; }
249 andreas 351
	   long   getPauseTime() { return pauseTime; }
248 andreas 352
	   double getAvgHR() { return avgHR; }
353
	   double getAvgSpeed() { return avgSpeed; }
354
	   double getMaxSpeed() { return maxSpeed; }
249 andreas 355
	   int    getAvgCadence() { return avgCadence; }
248 andreas 356
	   double getAscend() { return ascend; }
357
	   double getDescend() { return descend; }
358
 
104 andreas 359
	   double CalcRad(double lat);
360
	   double earth_distance(double lat1, double lon1, double lat2, double lon2);
361
 
88 andreas 362
	protected:
363
	   void garmin_print_dlist (garmin_list *l);
364
	   char *garmin_print_dtime (uint32 t);
365
	   void garmin_print_dpos (position_type *pos, double *lat, double *lon);
366
	   char *garmin_print_float32 (float32 f, char *ret);
367
	   char *garmin_print_float64 (float64 f, char *ret);
368
	   char *garmin_print_dfloat32 (float32 f, char *ret);
369
	   char *garmin_print_ddist (uint32 dur, char *ret);
370
 
371
	private:
372
	   void garmin_print_d100 (D100 *x);
373
	   void garmin_print_d101 (D101 *x);
374
	   void garmin_print_d102 (D102 *x);
375
	   void garmin_print_d103 (D103 *x);
376
	   void garmin_print_d104 (D104 *x);
377
	   void garmin_print_d105 (D105 *x);
378
	   void garmin_print_d106 (D106 *x);
379
	   void garmin_print_d107 (D107 *x);
380
	   void garmin_print_d108 (D108 *x);
381
	   void garmin_print_d109 (D109 *x);
382
	   void garmin_print_d110 (D110 *x);
383
	   void garmin_print_d120 (D120 *x);
384
	   void garmin_print_d150 (D150 *x);
385
	   void garmin_print_d151 (D151 *x);
386
	   void garmin_print_d152 (D152 *x);
387
	   void garmin_print_d154 (D154 *x);
388
	   void garmin_print_d155 (D155 *x);
389
	   void garmin_print_d200 (D200 *x);
390
	   void garmin_print_d201 (D201 *x);
391
	   void garmin_print_d202 (D202 *x);
392
	   void garmin_print_d210 (D210 *x);
393
	   void garmin_print_d300 (D300 *p);
394
	   void garmin_print_d301 (D301 *p);
395
	   void garmin_print_d302 (D302 *p);
396
	   void garmin_print_d303 (D303 *p);
397
	   void garmin_print_d304 (D304 *p);
398
	   void garmin_print_d310 (D310 *x);
399
	   void garmin_print_d311 (D311 *h);
400
	   void garmin_print_d312 (D312 *h);
401
	   void garmin_print_d400 (D400 *x);
402
	   void garmin_print_d403 (D403 *x);
403
	   void garmin_print_d450 (D450 *x);
404
	   void garmin_print_d500 (D500 *x);
405
	   void garmin_print_d501 (D501 *x);
406
	   void garmin_print_d550 (D550 *x);
407
	   void garmin_print_d551 (D551 *x);
408
	   void garmin_print_d600 (D600 *x);
409
	   void garmin_print_d650 (D650 *x);
410
	   void garmin_print_d700 (D700 *x);
411
	   void garmin_print_d800 (D800 *x);
412
	   void garmin_print_d906 (D906 *x);
413
	   void garmin_print_d1000 (D1000 *x);
414
	   void garmin_print_d1001 (D1001 *x);
415
	   void garmin_print_d1002 (D1002 *x);
416
	   void garmin_print_d1003 (D1003 *x);
417
	   void garmin_print_d1004 (D1004 *d);
418
	   void garmin_print_d1005 (D1005 *limits);
419
	   void garmin_print_d1006 (D1006 *x);
420
	   void garmin_print_d1007 (D1007 *x);
421
	   void garmin_print_d1008 (D1008 *w);
422
	   void garmin_print_d1009 (D1009 *x);
423
	   void garmin_print_d1010 (D1010 *x);
424
	   void garmin_print_d1011 (D1011 *x);
425
	   void garmin_print_d1012 (D1012 *x);
426
	   void garmin_print_d1013 (D1013 *x);
427
	   void garmin_print_d1015 (D1015 *x);
428
 
429
	private:
430
	   WAYPOINT waypoint;
431
	   WPCATEGORY wpcategory;
432
	   int route_header;
433
	   ROUTE route;
434
	   ROUTE_LINK route_link;
435
	   POINT point;
436
	   POINT_NODE *point_node;
437
	   TRACK track;
438
	   ALMANAC almanac;
439
	   DATETIME datetime;
440
	   FLIGHTBOOK flightbook;
441
	   radian_position_type rpt;
442
	   PVT pvt;
443
	   LAP lap;
444
	   LAP_NODE *lap_node;
445
	   RUN run;
446
	   RUN_NODE *run_node;
447
	   WORKOUT workout;
448
	   FITNESS fitness;
449
	   COURSE course;
248 andreas 450
 
451
	   double totalDistance;	// Distance in meters
452
	   long totalTime;		// Time in seconds
249 andreas 453
	   long pauseTime;		// Pause in seconds
248 andreas 454
	   double avgHR;		// Heart rate in beats per minute
455
	   double avgSpeed;		// Speed in km per hour
456
	   double maxSpeed;		// Speed in km per hour
457
	   int avgCadence;		// Cadence
458
	   double ascend;		// Height in meters
459
	   double descend;		// Height (downhill) in meters
88 andreas 460
};
461
 
462
#endif