Subversion Repositories public

Rev

Rev 223 | Rev 248 | Go to most recent revision | 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
#include <time.h>
21
#include <string.h>
104 andreas 22
#include <math.h>
88 andreas 23
#include "garmin.h"
24
#include "disassemble.h"
25
 
104 andreas 26
#define Deg2Rad(n)	((n) * DEG_2_RAD)
27
 
88 andreas 28
disassemble::disassemble()
29
{
30
	lap_node = 0;
31
	run_node = 0;
32
	point_node = 0;
33
}
34
 
35
disassemble::~disassemble()
36
{
37
	destroy();
38
}
39
 
40
void disassemble::destroy()
41
{
42
LAP_NODE *lakt, *ln;
43
RUN_NODE *rakt, *rn;
44
POINT_NODE *pakt, *pn;
45
 
46
	if (lap_node != NULL)		// free allocated laps
47
	{
48
	   lakt = lap_node;
49
 
50
	   while (lakt)
51
	   {
52
	      ln = lakt;
53
	      delete ln->lap;
54
	      lakt = lakt->next;
55
	      delete ln;
56
	   }
57
	}
58
 
59
	lap_node = NULL;
60
 
61
	if (lap_node != NULL)		// free allocated runs
62
	{
63
	   rakt = run_node;
64
 
65
	   while (rakt)
66
	   {
67
	      rn = rakt;
68
	      delete rn->run;
69
	      rakt = rakt->next;
70
	      delete rn;
71
	   }
72
	}
73
 
74
	run_node = NULL;
75
 
76
	if (point_node != NULL)		// free allocated points
77
	{
78
	   pakt = point_node;
79
 
80
	   while (pakt)
81
	   {
82
	      pn = pakt;
83
	      delete pn->point;
84
	      pakt = pakt->next;
85
	      delete pn;
86
	   }
87
	}
88
 
89
	point_node = NULL;
90
}
91
 
92
LAP_NODE *disassemble::addLap ()
93
{
94
LAP_NODE *akt, *n;
95
 
96
	if (lap_node == 0)		// First lap to add
97
	{
98
	   lap_node = new LAP_NODE;
99
	   lap_node->lap = new LAP;
100
 
101
	   memmove (lap_node->lap, &lap, sizeof(LAP));
102
	   lap_node->next = 0;
103
	   akt = lap_node;
104
	}
105
	else				// additional lap to add
106
	{
107
	   n = lap_node;
108
 
109
	   while (n->next)
110
	      n = n->next;
111
 
112
	   akt = new LAP_NODE;
113
	   akt->lap = new LAP;
114
	   memmove (akt->lap, &lap, sizeof(LAP));
115
	   akt->next = 0;
116
	   n->next = akt;
117
	}
118
 
119
	return akt;
120
}
121
 
122
LAP *disassemble::getLap(int index)
123
{
124
LAP_NODE *akt = lap_node;
125
 
126
	while (akt)
127
	{
128
	   if (akt->lap->index == (uint32)index)
129
	      return akt->lap;
130
 
131
	   akt = akt->next;
132
	}
133
 
134
	return NULL;
135
}
136
 
223 andreas 137
LAP *disassemble::getLapT(uint32 time)
138
{
139
LAP_NODE *akt = lap_node;
140
 
141
	while (akt)
142
	{
143
	   if ((akt->lap->start_time + akt->lap->total_time / 100) >= time)
144
	      return akt->lap;
145
 
146
	   akt = akt->next;
147
	}
148
 
149
	return NULL;
150
}
151
 
88 andreas 152
RUN_NODE *disassemble::addRun ()
153
{
154
RUN_NODE *akt, *n;
155
 
156
	if (run_node == 0)		// First run to add
157
	{
158
	   run_node = new RUN_NODE;
159
	   run_node->run = new RUN;
160
 
161
	   memmove (run_node->run, &run, sizeof(RUN));
162
	   run_node->next = 0;
163
	   akt = run_node;
164
	}
165
	else				// additional run to add
166
	{
167
	   n = run_node;
168
 
169
	   while (n != NULL && n->next != NULL)
170
	      n = n->next;
171
 
172
	   akt = new RUN_NODE;
173
	   akt->run = new RUN;
174
	   memmove (akt->run, &run, sizeof(RUN));
175
	   akt->next = 0;
176
	   n->next = akt;
177
	}
178
 
179
	return akt;
180
}
181
 
182
POINT_NODE *disassemble::addPoint ()
183
{
184
POINT_NODE *akt, *n;
185
 
186
	if (point_node == 0)		// First point to add
187
	{
188
	   point_node = new POINT_NODE;
189
	   point_node->point = new POINT;
190
 
191
	   memmove (point_node->point, &point, sizeof(POINT));
192
	   point_node->number = 0;
193
	   point_node->next = 0;
194
	   akt = point_node;
195
	}
196
	else				// additional point to add
197
	{
198
	   n = point_node;
199
 
200
	   while (n != NULL && n->next != NULL)
201
	      n = n->next;
202
 
203
	   akt = new POINT_NODE;
204
	   akt->point = new POINT;
205
	   memmove (akt->point, &point, sizeof(point));
206
	   akt->number = n->number + 1;
207
	   akt->next = 0;
208
	   n->next = akt;
209
	}
210
 
211
	return akt;
212
}
213
 
214
POINT *disassemble::getPoint(int number)
215
{
216
POINT_NODE *akt;
217
 
218
	akt = point_node;
219
 
220
	while (akt)
221
	{
222
	   if (akt->number == number)
223
	      return akt->point;
224
 
225
	   akt = akt->next;
226
	}
227
 
228
	return 0;
229
}
230
 
231
POINT *disassemble::getPoint(uint32 time)
232
{
233
POINT_NODE *akt;
234
 
235
	akt = point_node;
236
 
237
	while (akt)
238
	{
239
	   if (akt->point->time >= time)
240
	      return akt->point;
241
 
242
	   akt = akt->next;
243
	}
244
 
245
	return 0;
246
}
247
 
248
/* 
249
   This file contains functions to get Garmin datatypes.
250
   The functions aim to reproduce the data losslessly, including
251
   floating point data, such that the data can be scanned back from the
252
   output and reconstructed exactly.
253
*/
254
 
255
void disassemble::garmin_print_dlist (garmin_list *l)
256
{
257
garmin_list_node *n;
258
 
259
	for (n = l->head; n != NULL; n = n->next)
260
	{
261
	   garmin_print_data(n->data);
262
	}
263
}
264
 
265
 
266
/* Support function to print a time value in ISO 8601 compliant format */
267
 
268
char *disassemble::garmin_print_dtime (uint32 t)
269
{
270
time_t     tval;
271
struct tm  tmval;
272
char       buf[128], hv0[128];
273
int        len;
274
 
275
	/* 
276
	                                012345678901234567890123
277
	   This will make, for example, 2007-04-20T23:55:01-0700, but that date
278
	   isn't quite ISO 8601 compliant.  We need to stick a ':' in the time
279
	   zone between the hours and the minutes.
280
	*/
281
 
282
	tval = t + TIME_OFFSET;
283
	localtime_r(&tval,&tmval);
284
	strftime(buf,sizeof(buf)-1,"%FT%T%z",&tmval);
285
 
286
	/* 
287
	   If the last character is a 'Z', don't do anything.  Otherwise, we 
288
	   need to move the last two characters out one and stick a colon in 
289
	   the vacated spot.  Let's not forget the trailing '\0' that needs to 
290
	   be moved as well.
291
	*/
292
 
293
	len = strlen(buf);
294
 
295
	if ( len > 0 && buf[len-1] != 'Z' )
296
	{
297
	   memmove(buf+len-1,buf+len-2,3);
298
	   buf[len-2] = ':';
299
	}
300
 
301
	/* OK.  Done. */
302
 
303
	sprintf(hv0,"%s", buf);
137 andreas 304
	return (char *)strdup(hv0);
88 andreas 305
}
306
 
307
 
308
/* Support function to print a position type */
309
 
310
void disassemble::garmin_print_dpos (position_type *pos, double *lat, double *lon)
311
{
312
	if ( pos->lat != 0x7fffffff )
313
	   *lat = SEMI2DEG(pos->lat);
314
 
315
	if ( pos->lon != 0x7fffffff )
316
	   *lon = SEMI2DEG(pos->lon);
317
}
318
 
319
 
320
/* 
321
   Print a float32 with enough precision such that it can be reconstructed
322
   exactly from its decimal representation.
323
*/
324
 
325
char *disassemble::garmin_print_float32 (float32 f, char *ret)
326
{
327
	if (!ret)
328
	   return NULL;
329
 
330
	if ( f > 100000000.0 || f < -100000000.0 )
331
	    sprintf(ret, "%.9e",f);
332
	else if ( f > 10000000.0 || f < -10000000.0 )
333
	   sprintf(ret, "%.1f",f);
334
	else if ( f > 1000000.0 || f < -1000000.0 )
335
	   sprintf(ret, "%.2f",f);
336
	else if ( f > 100000.0 || f < -100000.0 )
337
	   sprintf(ret, "%.3f",f);
338
	else if ( f > 10000.0 || f < -10000.0 )
339
	   sprintf(ret, "%.4f",f);
340
	else if ( f > 1000.0 || f < -1000.0 )
341
	   sprintf(ret, "%.5f",f);
342
	else if ( f > 100.0 || f < -100.0 )
343
	   sprintf(ret, "%.6f",f);
344
	else if ( f > 10.0 || f < -10.0 )
345
	   sprintf(ret, "%.7f",f);
346
	else if ( f > 1.0 || f < -1.0 )
347
	   sprintf(ret, "%.8f",f);
348
	else if ( f > 0.1 || f < -0.1 )
349
	   sprintf(ret, "%.9f",f);
350
	else if ( f != 0 )
351
	   sprintf(ret, "%.9e",f);
352
	else
353
	   sprintf(ret, "%.8f",f);
354
 
355
	return ret;
356
}
357
 
358
 
359
/* 
360
   Print a float64 with enough precision such that it can be reconstructed
361
   exactly from its decimal representation.
362
*/
363
 
364
char *disassemble::garmin_print_float64 (float64 f, char *ret)
365
{
366
	if ( f > 10000000000000000.0 || f < -10000000000000000.0 )
367
	   sprintf(ret,"%.17e",f);
368
	else if ( f > 1000000000000000.0 || f < -1000000000000000.0 )
369
	   sprintf(ret,"%.1f",f);
370
	else if ( f > 100000000000000.0 || f < -100000000000000.0 )
371
	   sprintf(ret,"%.2f",f);
372
	else if ( f > 10000000000000.0 || f < -10000000000000.0 )
373
	   sprintf(ret,"%.3f",f);
374
	else if ( f > 1000000000000.0 || f < -1000000000000.0 )
375
	   sprintf(ret,"%.4f",f);
376
	else if ( f > 100000000000.0 || f < -100000000000.0 )
377
	   sprintf(ret,"%.5f",f);
378
	else if ( f > 10000000000.0 || f < -10000000000.0 )
379
	   sprintf(ret,"%.6f",f);
380
	else if ( f > 1000000000.0 || f < -1000000000.0 )
381
	   sprintf(ret,"%.7f",f);
382
	else if ( f > 100000000.0 || f < -100000000.0 )
383
	   sprintf(ret,"%.8f",f);
384
	else if ( f > 10000000.0 || f < -10000000.0 )
385
	   sprintf(ret,"%.9f",f);
386
	else if ( f > 1000000.0 || f < -1000000.0 )
387
	   sprintf(ret,"%.10f",f);
388
	else if ( f > 100000.0 || f < -100000.0 )
389
	   sprintf(ret,"%.11f",f);
390
	else if ( f > 10000.0 || f < -10000.0 )
391
	   sprintf(ret,"%.12f",f);
392
	else if ( f > 1000.0 || f < -1000.0 )
393
	   sprintf(ret,"%.13f",f);
394
	else if ( f > 100.0 || f < -100.0 )
395
	   sprintf(ret,"%.14f",f);
396
	else if ( f > 10.0 || f < -10.0 )
397
	   sprintf(ret,"%.15f",f);
398
	else if ( f > 1.0 || f < -1.0 )
399
	   sprintf(ret,"%.16f",f);
400
	else if ( f > 0.1 || f < -0.1 )
401
	   sprintf(ret,"%.17f",f);
402
	else if ( f != 0 )
403
	   sprintf(ret,"%.17e",f);
404
	else
405
	   sprintf(ret,"%.16f",f);
406
 
407
	return ret;
408
}
409
 
410
 
411
/* 
412
   Print a float32 whose value is invalid (and should not be printed) if 
413
   greater than 1.0e24 
414
*/
415
 
416
char *disassemble::garmin_print_dfloat32 (float32 f, char *ret)
417
{
418
	if (!ret)
419
	   return NULL;
420
 
421
	if ( f < 1.0e24 )
422
	   garmin_print_float32(f, ret);
423
 
424
	return ret;
425
}
426
 
427
 
428
/* Print a duration and distance. */
429
 
430
char *disassemble::garmin_print_ddist (uint32 dur, char *ret)
431
{
432
int  hun;
433
int  sec;
434
int  min;
435
int  hrs;
436
 
437
	if (!ret)
438
	   return NULL;
439
 
440
	hun  = dur % 100;
441
	dur -= hun;
442
	dur /= 100;
443
	sec  = dur % 60;
444
	dur -= sec;
445
	dur /= 60;
446
	min  = dur % 60;
447
	dur -= min;
448
	dur /= 60;
449
	hrs  = dur;
450
 
451
	sprintf(ret,"%d:%02d:%02d.%02d", hrs, min, sec, hun);
452
	return ret;
453
}
454
 
455
 
456
/* --------------------------------------------------------------------------*/
457
/* 7.4.1  D100                                                               */
458
/* --------------------------------------------------------------------------*/
459
 
460
void disassemble::garmin_print_d100 (D100 *x)
461
{
462
	memset (&waypoint, 0, sizeof(WAYPOINT));
463
	waypoint.type = 100;
464
	strncpy (waypoint.ident, x->ident, 5);
465
	waypoint.posn = x->posn;
466
	strncpy(waypoint.cmnt, x->cmnt, 40);
467
}
468
 
469
 
470
/* --------------------------------------------------------------------------*/
471
/* 7.4.2  D101                                                               */
472
/* --------------------------------------------------------------------------*/
473
 
474
void disassemble::garmin_print_d101 (D101 *x)
475
{
476
	memset (&waypoint, 0, sizeof(WAYPOINT));
477
	waypoint.type = 101;
478
	strncpy (waypoint.ident, x->ident, sizeof(waypoint.ident)-1);
479
	waypoint.posn = x->posn;
480
	strncpy (waypoint.cmnt, x->cmnt, sizeof(waypoint.cmnt)-1);
481
	waypoint.dst = x->dst;
482
	waypoint.smbl = x->smbl;
483
}
484
 
485
 
486
/* --------------------------------------------------------------------------*/
487
/* 7.4.3  D102                                                               */
488
/* --------------------------------------------------------------------------*/
489
 
490
void disassemble::garmin_print_d102 (D102 *x)
491
{
492
	garmin_print_d101 ((D101 *)x);
493
	waypoint.type = 102;
494
}
495
 
496
 
497
/* --------------------------------------------------------------------------*/
498
/* 7.4.4  D103                                                               */
499
/* --------------------------------------------------------------------------*/
500
 
501
 
502
void disassemble::garmin_print_d103 (D103 *x)
503
{
504
	garmin_print_d101((D101 *)x);
505
	waypoint.type = 103;
506
//	GARMIN_TAGSTR(1,"symbol",garmin_d103_smbl(x->smbl));
507
//	GARMIN_TAGSTR(1,"display",garmin_d103_dspl(x->dspl));
508
}
509
 
510
 
511
/* --------------------------------------------------------------------------*/
512
/* 7.4.5  D104                                                               */
513
/* --------------------------------------------------------------------------*/
514
 
515
void disassemble::garmin_print_d104 (D104 *x)
516
{
517
	garmin_print_d101((D101 *)x);
518
	waypoint.dspl = x->dspl;
519
	waypoint.type = 104;
520
//	GARMIN_TAGF32(1,"proximity_distance",x->dst);
521
//	GARMIN_TAGSTR(1,"display",garmin_d104_dspl(x->dspl));
522
}
523
 
524
 
525
/* --------------------------------------------------------------------------*/
526
/* 7.4.6  D105                                                               */
527
/* --------------------------------------------------------------------------*/
528
 
529
void disassemble::garmin_print_d105 (D105 *x)
530
{
531
	memset (&waypoint, 0, sizeof(WAYPOINT));
532
	waypoint.type = 105;
533
	waypoint.wpt_ident = x->wpt_ident;
534
	waypoint.posn = x->posn;
535
	waypoint.smbl = x->smbl;
536
}
537
 
538
 
539
/* --------------------------------------------------------------------------*/
540
/* 7.4.7  D106                                                               */
541
/* --------------------------------------------------------------------------*/
542
 
543
void disassemble::garmin_print_d106 (D106 *x)
544
{
545
	memset (&waypoint, 0, sizeof(WAYPOINT));
546
	waypoint.type = 106;
547
	waypoint.wpt_class = x->wpt_class;
548
	waypoint.subclass[0] = 0;
549
 
550
	if ( x->wpt_class != 0 )
551
	{
552
	   strncpy ((char *)waypoint.subclass, (char *)x->subclass, 13);
553
	   waypoint.subclass[13] = 0;
554
	}
555
 
556
	waypoint.wpt_ident = x->wpt_ident;
557
	waypoint.posn = x->posn;
558
	waypoint.smbl = x->smbl;
559
	waypoint.lnk_ident = x->lnk_ident;
560
}
561
 
562
 
563
/* --------------------------------------------------------------------------*/
564
/* 7.4.8  D107                                                               */
565
/* --------------------------------------------------------------------------*/
566
 
567
void disassemble::garmin_print_d107 (D107 *x)
568
{
569
	memset (&waypoint, 0, sizeof(WAYPOINT));
570
	waypoint.type = 107;
571
	strncpy(waypoint.ident, x->ident, sizeof(waypoint.ident)-1);
572
	waypoint.posn = x->posn;
573
	strncpy(waypoint.cmnt, x->cmnt, sizeof(waypoint.cmnt)-1);
574
	waypoint.dst = x->dst;
575
	waypoint.smbl = x->smbl;
576
	waypoint.dspl = x->dspl;
577
	waypoint.color = x->color;
578
}
579
 
580
 
581
/* --------------------------------------------------------------------------*/
582
/* 7.4.9  D108                                                               */
583
/* --------------------------------------------------------------------------*/
584
 
585
void disassemble::garmin_print_d108 (D108 *x)
586
{
587
	memset(&waypoint, 0, sizeof(WAYPOINT));
588
	waypoint.type = 108;
589
	waypoint.identity = x->ident;
590
	waypoint.posn = x->posn;
591
	waypoint.comment = x->comment;
592
	waypoint.smbl = x->smbl;
593
	waypoint.dspl = x->dspl;
594
	waypoint.wpt_class = x->wpt_class;
595
	strncpy((char *)waypoint.subclass, (char *)x->subclass, 18);
596
	waypoint.attr = x->attr;
597
	waypoint.color = x->color;
598
	waypoint.alt = x->alt;
599
	waypoint.dpth = x->dpth;
600
	waypoint.dst = x->dist;
601
	waypoint.facility = x->facility;
602
	waypoint.city = x->city;
603
	waypoint.addr = x->addr;
604
	waypoint.cross_road = x->cross_road;
605
}
606
 
607
 
608
/* --------------------------------------------------------------------------*/
609
/* 7.4.10  D109                                                              */
610
/* --------------------------------------------------------------------------*/
611
 
612
void disassemble::garmin_print_d109 (D109 *x)
613
{
614
uint8 color = x->dspl_color & 0x1f;
615
 
616
	if (color == 0x1f)
617
	   color = D108_default_color;
618
 
619
	memset(&waypoint, 0, sizeof(WAYPOINT));
620
	waypoint.type = 109;
621
	waypoint.identity = x->ident;
622
	waypoint.posn = x->posn;
623
	waypoint.comment = x->comment;
624
	waypoint.smbl = x->smbl;
625
	waypoint.wpt_class = x->wpt_class;
626
	strncpy((char *)waypoint.subclass, (char *)x->subclass, 18);
627
	waypoint.attr = x->attr;
628
	waypoint.color = color;
629
	waypoint.alt = x->alt;
630
	waypoint.dtyp = x->dtyp;
631
	waypoint.ete = x->ete;
632
	waypoint.dpth = x->dpth;
633
	waypoint.dst = x->dist;
634
	waypoint.facility = x->facility;
635
	waypoint.city = x->city;
636
	waypoint.addr = x->addr;
637
	waypoint.cross_road = x->cross_road;
638
}
639
 
640
 
641
/* --------------------------------------------------------------------------*/
642
/* 7.4.11  D110                                                              */
643
/* --------------------------------------------------------------------------*/
644
 
645
void disassemble::garmin_print_d110 (D110 *x)
646
{
647
	memset(&waypoint, 0, sizeof(WAYPOINT));
648
	waypoint.type = 110;
649
	waypoint.identity = x->ident;
650
	waypoint.posn = x->posn;
651
	waypoint.comment = x->comment;
652
	waypoint.smbl = x->smbl;
653
	waypoint.wpt_class = x->wpt_class;
654
	strncpy((char *)waypoint.subclass, (char *)x->subclass, 18);
655
	waypoint.attr = x->attr;
656
	waypoint.alt = x->alt;
657
	waypoint.dtyp = x->dtyp;
658
	waypoint.ete = x->ete;
659
	waypoint.dpth = x->dpth;
660
	waypoint.dst = x->dist;
661
	waypoint.facility = x->facility;
662
	waypoint.city = x->city;
663
	waypoint.addr = x->addr;
664
	waypoint.cross_road = x->cross_road;
665
 
666
/*  GARMIN_TAGSTR(1,"wpt_class",garmin_d110_wpt_class(x->wpt_class));
667
  GARMIN_TAGSTR(1,"color",garmin_d110_color((x->dspl_color) & 0x1f));
668
  GARMIN_TAGSTR(1,"display",garmin_d110_dspl((x->dspl_color >> 5) & 0x03));
669
  GARMIN_TAGSYM(1,"symbol",x->smbl);
670
  if ( x->temp < 1.0e24 ) GARMIN_TAGF32(1,"temperature",x->temp);
671
  GARMIN_TAGSTR(1,"state",x->state);
672
  GARMIN_TAGSTR(1,"country_code",x->cc);
673
  if ( x->time != 0xffffffff ) GARMIN_TAGU32(1,"time",x->time);
674
  GARMIN_TAGHEX(1,"category",x->wpt_cat); */
675
}
676
 
677
 
678
/* --------------------------------------------------------------------------*/
679
/* 7.4.12  D120                                                              */
680
/* --------------------------------------------------------------------------*/
681
 
682
void disassemble::garmin_print_d120 (D120 *x)
683
{
684
	memset(&wpcategory, 0, sizeof(WPCATEGORY));
685
	strncpy(wpcategory.name, x->name, 17);
686
}
687
 
688
 
689
/* --------------------------------------------------------------------------*/
690
/* 7.4.13  D150                                                              */
691
/* --------------------------------------------------------------------------*/
692
 
693
void disassemble::garmin_print_d150 (D150 *x)
694
{
695
	memset(&waypoint, 0, sizeof(WAYPOINT));
696
	waypoint.type = 150;
697
	strncpy(waypoint.ident, x->ident, sizeof(waypoint.ident)-1);
698
	waypoint.wpt_class = x->wpt_class;
699
	waypoint.posn = x->posn;
700
	strncpy(waypoint.cmnt, x->cmnt, sizeof(waypoint.cmnt)-1);
701
 
702
	if (x->wpt_class != D150_usr_wpt_class)
703
	{
704
	   waypoint.city = x->city;
705
	   strncpy(waypoint.state, x->state, 2);
706
	   waypoint.facility = x->name;
707
	   strncpy(waypoint.cc, x->cc, 2);
708
	}
709
 
710
	if (x->wpt_class == D150_apt_wpt_class)
711
	   waypoint.alt = x->alt;
712
}
713
 
714
 
715
/* --------------------------------------------------------------------------*/
716
/* 7.4.14  D151                                                              */
717
/* --------------------------------------------------------------------------*/
718
 
719
void disassemble::garmin_print_d151 (D151 *x)
720
{
721
	memset(&waypoint, 0, sizeof(WAYPOINT));
722
	waypoint.type = 151;
723
	strncpy(waypoint.ident, x->ident, sizeof(waypoint.ident)-1);
724
	waypoint.wpt_class = x->wpt_class;
725
	waypoint.posn = x->posn;
726
	strncpy(waypoint.cmnt, x->cmnt, sizeof(waypoint.cmnt)-1);
727
	waypoint.dst = x->dst;
728
 
729
	if (x->wpt_class != D150_usr_wpt_class)
730
	{
731
	   waypoint.city = x->city;
732
	   strncpy(waypoint.state, x->state, 2);
733
	   waypoint.facility = x->name;
734
	   strncpy(waypoint.cc, x->cc, 2);
735
	}
736
 
737
	if (x->wpt_class == D150_apt_wpt_class)
738
	   waypoint.alt = x->alt;
739
}
740
 
741
 
742
/* --------------------------------------------------------------------------*/
743
/* 7.4.15  D152                                                              */
744
/* --------------------------------------------------------------------------*/
745
 
746
void disassemble::garmin_print_d152 (D152 *x)
747
{
748
	memset(&waypoint, 0, sizeof(WAYPOINT));
749
	waypoint.type = 152;
750
	strncpy(waypoint.ident, x->ident, sizeof(waypoint.ident)-1);
751
	waypoint.wpt_class = x->wpt_class;
752
	waypoint.posn = x->posn;
753
	strncpy(waypoint.cmnt, x->cmnt, sizeof(waypoint.cmnt)-1);
754
	waypoint.dst = x->dst;
755
 
756
	if (x->wpt_class != D152_usr_wpt_class)
757
	{
758
	   waypoint.city = x->city;
759
	   strncpy(waypoint.state, x->state, 2);
760
	   waypoint.facility = x->name;
761
	   strncpy(waypoint.cc, x->cc, 2);
762
	}
763
 
764
	if (x->wpt_class == D152_apt_wpt_class)
765
	   waypoint.alt = x->alt;
766
}
767
 
768
 
769
/* --------------------------------------------------------------------------*/
770
/* 7.4.16  D154                                                              */
771
/* --------------------------------------------------------------------------*/
772
 
773
void disassemble::garmin_print_d154 (D154 *x)
774
{
775
	memset(&waypoint, 0, sizeof(WAYPOINT));
776
	waypoint.type = 154;
777
	strncpy(waypoint.ident, x->ident, sizeof(waypoint.ident)-1);
778
	waypoint.wpt_class = x->wpt_class;
779
	waypoint.posn = x->posn;
780
	strncpy(waypoint.cmnt, x->cmnt, sizeof(waypoint.cmnt)-1);
781
	waypoint.dst = x->dst;
782
 
783
	if (x->wpt_class != D154_usr_wpt_class)
784
	{
785
	   waypoint.city = x->city;
786
	   strncpy(waypoint.state, x->state, 2);
787
	   waypoint.facility = x->name;
788
	   strncpy(waypoint.cc, x->cc, 2);
789
	}
790
 
791
	if (x->wpt_class == D154_apt_wpt_class)
792
	   waypoint.alt = x->alt;
793
 
794
	waypoint.smbl = x->smbl;
795
}
796
 
797
 
798
/* --------------------------------------------------------------------------*/
799
/* 7.4.17  D155                                                              */
800
/* --------------------------------------------------------------------------*/
801
 
802
void disassemble::garmin_print_d155 (D155 *x)
803
{
804
	memset(&waypoint, 0, sizeof(WAYPOINT));
805
	waypoint.type = 155;
806
	strncpy(waypoint.ident, x->ident, sizeof(waypoint.ident)-1);
807
	waypoint.wpt_class = x->wpt_class;
808
	waypoint.posn = x->posn;
809
	strncpy(waypoint.cmnt, x->cmnt, sizeof(waypoint.cmnt)-1);
810
	waypoint.dst = x->dst;
811
 
812
	if (x->wpt_class != D155_usr_wpt_class)
813
	{
814
	   waypoint.city = x->city;
815
	   strncpy(waypoint.state, x->state, 2);
816
	   waypoint.facility = x->name;
817
	   strncpy(waypoint.cc, x->cc, 2);
818
	}
819
 
820
	if (x->wpt_class == D155_apt_wpt_class)
821
	   waypoint.alt = x->alt;
822
 
823
	waypoint.smbl = x->smbl;
824
	waypoint.dspl = x->dspl;
825
}
826
 
827
 
828
/* --------------------------------------------------------------------------*/
829
/* 7.4.18  D200                                                              */
830
/* --------------------------------------------------------------------------*/
831
 
832
void disassemble::garmin_print_d200 (D200 *x)
833
{
834
	route_header = *x;
835
}
836
 
837
 
838
/* --------------------------------------------------------------------------*/
839
/* 7.4.19  D201                                                              */
840
/* --------------------------------------------------------------------------*/
841
 
842
void disassemble::garmin_print_d201 (D201 *x)
843
{
844
	memset(&route, 0, sizeof(ROUTE));
845
	route.type = 201;
846
	route.nmbr = x->nmbr;
847
	strncpy(route.cmnt, x->cmnt, 20);
848
}
849
 
850
 
851
/* --------------------------------------------------------------------------*/
852
/* 7.4.20  D202                                                              */
853
/* --------------------------------------------------------------------------*/
854
 
855
void disassemble::garmin_print_d202 (D202 *x)
856
{
857
	memset(&route, 0, sizeof(ROUTE));
858
	route.type = 202;
859
	route.rte_ident = x->rte_ident;
860
}
861
 
862
 
863
/* --------------------------------------------------------------------------*/
864
/* 7.4.21  D210                                                              */
865
/* --------------------------------------------------------------------------*/
866
 
867
void disassemble::garmin_print_d210 (D210 *x)
868
{
869
	memset(&route_link, 0, sizeof(ROUTE_LINK));
870
	route_link.type = 210;
871
	route_link.klasse = x->klasse;
872
	route_link.ident = x->ident;
873
	strncpy((char *)route_link.subclass, (char *)x->subclass, 18);
874
}
875
 
876
 
877
/* --------------------------------------------------------------------------*/
878
/* 7.4.22  D300                                                              */
879
/* --------------------------------------------------------------------------*/
880
 
881
void disassemble::garmin_print_d300 (D300 *p)
882
{
883
	memset(&point, 0, sizeof(POINT));
884
	point.type = 300;
885
	point.time = p->time;
886
	point.posn = p->posn;
887
	point.new_trk = p->new_trk;
888
	addPoint();
889
}
890
 
891
 
892
/* --------------------------------------------------------------------------*/
893
/* 7.4.23  D301                                                              */
894
/* --------------------------------------------------------------------------*/
895
 
896
void disassemble::garmin_print_d301 (D301 *p)
897
{
898
	memset(&point, 0, sizeof(POINT));
899
	point.type = 301;
900
	point.time = p->time;
901
	point.posn = p->posn;
902
	point.new_trk = p->new_trk;
903
	point.alt = p->alt;
904
	point.dpth = p->dpth;
905
	addPoint();
906
}
907
 
908
 
909
/* --------------------------------------------------------------------------*/
910
/* 7.4.24  D302                                                              */
911
/* --------------------------------------------------------------------------*/
912
 
913
void disassemble::garmin_print_d302 (D302 *p)
914
{
915
	memset(&point, 0, sizeof(POINT));
916
	point.type = 302;
917
	point.time = p->time;
918
	point.posn = p->posn;
919
	point.new_trk = p->new_trk;
920
	point.alt = p->alt;
921
	point.dpth = p->dpth;
922
	point.temp = p->temp;
923
	addPoint();
924
}
925
 
926
 
927
/* --------------------------------------------------------------------------*/
928
/* 7.4.25  D303                                                              */
929
/* --------------------------------------------------------------------------*/
930
 
931
void disassemble::garmin_print_d303 (D303 *p)
932
{
933
	memset(&point, 0, sizeof(POINT));
934
	point.type = 303;
935
	point.time = p->time;
936
	point.posn = p->posn;
937
	point.alt = p->alt;
938
	point.heart_rate = p->heart_rate;
939
	addPoint();
940
}
941
 
942
 
943
/* --------------------------------------------------------------------------*/
944
/* 7.4.26  D304                                                              */
945
/* --------------------------------------------------------------------------*/
946
 
947
void disassemble::garmin_print_d304 (D304 *p)
948
{
949
	memset(&point, 0, sizeof(POINT));
950
	point.type = 304;
951
	point.time = p->time;
952
	point.posn = p->posn;
953
	point.alt = p->alt;
954
	point.heart_rate = p->heart_rate;
955
	point.distance = p->distance;
956
	point.cadence = p->cadence;
957
	point.sensor = p->sensor;
958
	addPoint();
959
}
960
 
961
 
962
/* --------------------------------------------------------------------------*/
963
/* 7.4.27  D310                                                              */
964
/* --------------------------------------------------------------------------*/
965
 
966
void disassemble::garmin_print_d310 (D310 *x)
967
{
968
	memset(&track, 0, sizeof(TRACK));
969
	track.type = 310;
970
	track.trk_ident = x->trk_ident;
971
	track.color = x->color;
972
	track.dspl = x->dspl;
973
}
974
 
975
 
976
/* --------------------------------------------------------------------------*/
977
/* 7.4.28  D311                                                              */
978
/* --------------------------------------------------------------------------*/
979
 
980
void disassemble::garmin_print_d311 (D311 *h)
981
{
982
	memset(&track, 0, sizeof(TRACK));
983
	track.type = 311;
984
	track.index = h->index;
985
}
986
 
987
 
988
/* --------------------------------------------------------------------------*/
989
/* 7.4.29  D312                                                              */
990
/* --------------------------------------------------------------------------*/
991
 
992
void disassemble::garmin_print_d312 (D312 *h)
993
{
994
	memset(&track, 0, sizeof(TRACK));
995
	track.type = 312;
996
	track.trk_ident = h->trk_ident;
997
	track.color = h->color;
998
	track.dspl = h->dspl;
999
}
1000
 
1001
 
1002
/* --------------------------------------------------------------------------*/
1003
/* 7.4.30  D400                                                              */
1004
/* --------------------------------------------------------------------------*/
1005
 
1006
void disassemble::garmin_print_d400 (D400 *x)
1007
{
1008
	garmin_print_d400((D400 *)&x->wpt);
1009
	waypoint.type = 400;
1010
	waypoint.dst = x->dst;
1011
}
1012
 
1013
 
1014
/* --------------------------------------------------------------------------*/
1015
/* 7.4.31  D403                                                              */
1016
/* --------------------------------------------------------------------------*/
1017
 
1018
void disassemble::garmin_print_d403 (D403 *x)
1019
{
1020
	garmin_print_d103(&x->wpt);
1021
	waypoint.type = 403;
1022
	waypoint.dst = x->dst;
1023
}
1024
 
1025
 
1026
/* --------------------------------------------------------------------------*/
1027
/* 7.4.32  D450                                                              */
1028
/* --------------------------------------------------------------------------*/
1029
 
1030
void disassemble::garmin_print_d450 (D450 *x)
1031
{
1032
	garmin_print_d150(&x->wpt);
1033
	waypoint.type = 450;
1034
	waypoint.dst = x->dst;
1035
	waypoint.idx = x->idx;
1036
}
1037
 
1038
 
1039
/* --------------------------------------------------------------------------*/
1040
/* 7.4.33  D500                                                              */
1041
/* --------------------------------------------------------------------------*/
1042
 
1043
void disassemble::garmin_print_d500 (D500 *x)
1044
{
1045
	memset(&almanac, 0, sizeof(ALMANAC));
1046
	almanac.type = 500;
1047
	almanac.wn = x->wn;
1048
	almanac.toa = x->toa;
1049
	almanac.af0 = x->af0;
1050
	almanac.af1 = x->af1;
1051
	almanac.e = x->e;
1052
	almanac.sqrta = x->sqrta;
1053
	almanac.m0 = x->m0;
1054
	almanac.w = x->w;
1055
	almanac.omg0 = x->omg0;
1056
	almanac.odot = x->odot;
1057
	almanac.i = x->i;
1058
}
1059
 
1060
 
1061
/* --------------------------------------------------------------------------*/
1062
/* 7.4.34  D501                                                              */
1063
/* --------------------------------------------------------------------------*/
1064
 
1065
void disassemble::garmin_print_d501 (D501 *x)
1066
{
1067
	memset(&almanac, 0, sizeof(ALMANAC));
1068
	almanac.type = 501;
1069
	almanac.wn = x->wn;
1070
	almanac.toa = x->toa;
1071
	almanac.af0 = x->af0;
1072
	almanac.af1 = x->af1;
1073
	almanac.e = x->e;
1074
	almanac.sqrta = x->sqrta;
1075
	almanac.m0 = x->m0;
1076
	almanac.w = x->w;
1077
	almanac.omg0 = x->omg0;
1078
	almanac.odot = x->odot;
1079
	almanac.i = x->i;
1080
	almanac.hlth = x->hlth;
1081
}
1082
 
1083
 
1084
/* --------------------------------------------------------------------------*/
1085
/* 7.4.35  D550                                                              */
1086
/* --------------------------------------------------------------------------*/
1087
 
1088
void disassemble::garmin_print_d550 (D550 *x)
1089
{
1090
	memset(&almanac, 0, sizeof(ALMANAC));
1091
	almanac.type = 550;
1092
	almanac.wn = x->wn;
1093
	almanac.toa = x->toa;
1094
	almanac.af0 = x->af0;
1095
	almanac.af1 = x->af1;
1096
	almanac.e = x->e;
1097
	almanac.sqrta = x->sqrta;
1098
	almanac.m0 = x->m0;
1099
	almanac.w = x->w;
1100
	almanac.omg0 = x->omg0;
1101
	almanac.odot = x->odot;
1102
	almanac.i = x->i;
1103
	almanac.svid = x->svid;
1104
}
1105
 
1106
 
1107
/* --------------------------------------------------------------------------*/
1108
/* 7.4.36  D551                                                              */
1109
/* --------------------------------------------------------------------------*/
1110
 
1111
void disassemble::garmin_print_d551 (D551 *x)
1112
{
1113
	memset(&almanac, 0, sizeof(ALMANAC));
1114
	almanac.type = 551;
1115
	almanac.wn = x->wn;
1116
	almanac.toa = x->toa;
1117
	almanac.af0 = x->af0;
1118
	almanac.af1 = x->af1;
1119
	almanac.e = x->e;
1120
	almanac.sqrta = x->sqrta;
1121
	almanac.m0 = x->m0;
1122
	almanac.w = x->w;
1123
	almanac.omg0 = x->omg0;
1124
	almanac.odot = x->odot;
1125
	almanac.i = x->i;
1126
	almanac.svid = x->svid;
1127
	almanac.hlth = x->hlth;
1128
}
1129
 
1130
 
1131
/* --------------------------------------------------------------------------*/
1132
/* 7.4.37  D600                                                              */
1133
/* --------------------------------------------------------------------------*/
1134
 
1135
void disassemble::garmin_print_d600 (D600 *x)
1136
{
1137
	datetime.year = x->year;
1138
	datetime.month = x->month;
1139
	datetime.day = x->day;
1140
	datetime.hour = x->hour;
1141
	datetime.minute = x->minute;
1142
	datetime.second = x->second;
1143
}
1144
 
1145
 
1146
/* --------------------------------------------------------------------------*/
1147
/* 7.4.38  D650                                                              */
1148
/* --------------------------------------------------------------------------*/
1149
 
1150
void disassemble::garmin_print_d650 (D650 *x)
1151
{
1152
	memset(&flightbook, 0, sizeof(FLIGHTBOOK));
1153
	flightbook.type = 650;
1154
	flightbook.takeoff_time = x->takeoff_time;
1155
	flightbook.landing_time = x->landing_time;
1156
	flightbook.takeoff_posn = x->takeoff_posn;
1157
	flightbook.landing_posn = x->landing_posn;
1158
	flightbook.night_time = x->night_time;
1159
	flightbook.num_landings = x->num_landings;
1160
	flightbook.max_speed = x->max_speed;
1161
	flightbook.max_alt = x->max_alt;
1162
	flightbook.distance = x->distance;
1163
	flightbook.cross_country_flag = x->cross_country_flag;
1164
	flightbook.departure_name = x->departure_name;
1165
	flightbook.departure_ident = x->departure_ident;
1166
	flightbook.arrival_name = x->arrival_name;
1167
	flightbook.arrival_ident = x->arrival_ident;
1168
	flightbook.ac_id = x->ac_id;
1169
}
1170
 
1171
 
1172
/* ------------------------------------------------------------------------- */
1173
/* 7.4.39  D700                                                              */
1174
/* ------------------------------------------------------------------------- */
1175
 
1176
void disassemble::garmin_print_d700 (D700 *x)
1177
{
1178
	rpt.lat = x->lat;
1179
	rpt.lon = x->lon;
1180
}
1181
 
1182
 
1183
/* --------------------------------------------------------------------------*/
1184
/* 7.4.40  D800                                                              */
1185
/* --------------------------------------------------------------------------*/
1186
 
1187
void disassemble::garmin_print_d800 (D800 *x)
1188
{
1189
	memset(&pvt, 0, sizeof(PVT));
1190
	pvt.alt = x->alt;
1191
	pvt.epe = x->epe;
1192
	pvt.eph = x->eph;
1193
	pvt.epv = x->epv;
1194
	pvt.fix = x->fix;
1195
	pvt.posn.lat = x->posn.lat;
1196
	pvt.posn.lon = x->posn.lon;
1197
	pvt.east = x->east;
1198
	pvt.north = x->north;
1199
	pvt.up = x->up;
1200
	pvt.msl_hght = x->msl_hght;
1201
	pvt.leap_scnds = x->leap_scnds;
1202
	pvt.wn_days = x->wn_days;
1203
	pvt.tow = x->tow;
1204
}
1205
 
1206
 
1207
/* --------------------------------------------------------------------------*/
1208
/* 7.4.41  D906                                                              */
1209
/* --------------------------------------------------------------------------*/
1210
 
1211
void disassemble::garmin_print_d906 (D906 *x)
1212
{
1213
	memset (&lap, 0, sizeof(LAP));
1214
	lap.type = 906;
1215
	lap.start_time = x->start_time;
1216
	lap.total_time = x->total_time;
1217
	lap.total_distance = x->total_distance;
1218
	lap.begin.lat = x->begin.lat;
1219
	lap.begin.lon = x->begin.lon;
1220
	lap.end.lat = x->end.lat;
1221
	lap.end.lon = x->end.lon;
1222
	lap.calories = x->calories;
1223
	lap.track_index = x->track_index;
1224
	addLap();
1225
}
1226
 
1227
 
1228
/* --------------------------------------------------------------------------*/
1229
/* 7.4.42  D1000                                                             */
1230
/* --------------------------------------------------------------------------*/
1231
 
1232
 
1233
void disassemble::garmin_print_d1000 (D1000 *x)
1234
{
1235
	memset(&run, 0, sizeof(RUN));
1236
	garmin_print_d1002((D1002 *)&x->workout);
1237
	run.type = 1000;
1238
	run.track_index = x->track_index;
1239
	run.sport_type = x->sport_type;
1240
	run.first_lap_index = x->first_lap_index;
1241
	run.last_lap_index = x->last_lap_index;
1242
	run.program_type = x->program_type;
1243
	run.virtual_partner.time = x->virtual_partner.time;
1244
	run.virtual_partner.distance = x->virtual_partner.distance;
1245
	addRun();
1246
}
1247
 
1248
 
1249
/* --------------------------------------------------------------------------*/
1250
/* 7.4.43  D1001                                                             */
1251
/* --------------------------------------------------------------------------*/
1252
 
1253
 
1254
void disassemble::garmin_print_d1001 (D1001 *x)
1255
{
1256
	memset(&lap, 0, sizeof(LAP));
1257
	lap.type = 1001;
1258
	lap.start_time = x->start_time;
1259
	lap.total_time = x->total_time;
1260
	lap.total_distance = x->total_dist;
1261
	lap.begin.lat = x->begin.lat;
1262
	lap.begin.lon = x->begin.lon;
1263
	lap.end.lat = x->end.lat;
1264
	lap.end.lon = x->end.lon;
1265
	lap.calories = x->calories;
1266
	lap.index = x->index;
1267
	lap.max_speed = x->max_speed;
1268
	lap.avg_heart_rate = x->avg_heart_rate;
1269
	lap.max_heart_rate = x->max_heart_rate;
1270
	lap.intensity = x->intensity;
1271
	addLap();
1272
}
1273
 
1274
 
1275
/* --------------------------------------------------------------------------*/
1276
/* 7.4.44  D1002                                                             */
1277
/* --------------------------------------------------------------------------*/
1278
 
1279
 
1280
void disassemble::garmin_print_d1002 (D1002 *x)
1281
{
213 andreas 1282
unsigned int i;
88 andreas 1283
 
1284
	memset (&workout, 0, sizeof(WORKOUT));
1285
	workout.type = 1002;
1286
	strncpy (workout.name, x->name, 16);
1287
	workout.num_valid_steps = x->num_valid_steps;
1288
 
1289
	if (x->num_valid_steps > 0)
1290
	{
1291
	   for (i = 0; i < x->num_valid_steps; i++)
1292
	   {
1293
	      if (i >= 20)
1294
		 break;
1295
 
1296
	      strncpy (workout.steps[i].custom_name, x->steps[i].custom_name, 16);
1297
	      workout.steps[i].intensity = x->steps[i].intensity;
1298
	      workout.steps[i].duration_type = x->steps[i].duration_type;
1299
	      workout.steps[i].duration_value = x->steps[i].duration_value;
1300
	      workout.steps[i].target_type = x->steps[i].target_type;
1301
	      workout.steps[i].target_value = x->steps[i].target_value;
1302
	      workout.steps[i].target_custom_zone_low = x->steps[i].target_custom_zone_low;
1303
	      workout.steps[i].target_custom_zone_high = x->steps[i].target_custom_zone_high;
1304
	   }
1305
	}
1306
}
1307
 
1308
 
1309
/* --------------------------------------------------------------------------*/
1310
/* 7.4.45  D1003                                                             */
1311
/* --------------------------------------------------------------------------*/
1312
 
1313
void disassemble::garmin_print_d1003 (D1003 *x)
1314
{
1315
	memset (&workout, 0, sizeof(WORKOUT));
1316
	workout.type = 1003;
1317
	strncpy (workout.workout_name, x->workout_name, 16);
1318
	workout.day = x->day;
1319
}
1320
 
1321
 
1322
/* --------------------------------------------------------------------------*/
1323
/* 7.4.46  D1004                                                             */
1324
/* --------------------------------------------------------------------------*/
1325
 
1326
void disassemble::garmin_print_d1004 (D1004 *d)
1327
{
1328
int i;
1329
int j;
1330
 
1331
	memset (&fitness, 0, sizeof(FITNESS));
1332
	fitness.type = 1004;
1333
	fitness.weight = d->weight;
1334
	fitness.birth_year = d->birth_year;
1335
	fitness.birth_month = d->birth_month;
1336
	fitness.birth_day = d->birth_day;
1337
	fitness.gender = d->gender;
1338
 
1339
	for (i = 0; i < 3; i++)
1340
	{
1341
	   fitness.activities[i].gear_weight = d->activities[i].gear_weight;
1342
	   fitness.activities[i].max_heart_rate = d->activities[i].max_heart_rate;
1343
 
1344
	   for (j = 0; j < 5; j++)
1345
	   {
1346
	      fitness.activities[i].heart_rate_zones[j].low_heart_rate = d->activities[i].heart_rate_zones[j].low_heart_rate;
1347
	      fitness.activities[i].heart_rate_zones[j].high_heart_rate = d->activities[i].heart_rate_zones[j].high_heart_rate;
1348
	   }
1349
 
1350
	   for (j = 0; j < 10; j++)
1351
	   {
1352
	      fitness.activities[i].speed_zones[j].low_speed = d->activities[i].speed_zones[j].low_speed;
1353
	      fitness.activities[i].speed_zones[j].high_speed = d->activities[i].speed_zones[j].high_speed;
1354
	      strncpy (fitness.activities[i].speed_zones[j].name, d->activities[i].speed_zones[j].name, 16);
1355
	   }
1356
	}
1357
}
1358
 
1359
 
1360
/* --------------------------------------------------------------------------*/
1361
/* 7.4.47  D1005                                                             */
1362
/* --------------------------------------------------------------------------*/
1363
 
1364
void disassemble::garmin_print_d1005 (D1005 *limits)
1365
{
1366
	memset (&workout, 0, sizeof(WORKOUT));
1367
	workout.type = 1005;
1368
	workout.max_workouts = limits->max_workouts;
1369
	workout.max_unscheduled_workouts = limits->max_unscheduled_workouts;
1370
	workout.max_occurrences = limits->max_occurrences;
1371
}
1372
 
1373
 
1374
/* --------------------------------------------------------------------------*/
1375
/* 7.4.48  D1006                                                             */
1376
/* --------------------------------------------------------------------------*/
1377
 
1378
void disassemble::garmin_print_d1006 (D1006 *x)
1379
{
1380
	memset (&course, 0, sizeof(COURSE));
1381
	course.type = 1006;
1382
	course.index = x->index;
1383
	strncpy(course.course_name, x->course_name, 16);
1384
	course.track_index = x->track_index;
1385
}
1386
 
1387
 
1388
/* --------------------------------------------------------------------------*/
1389
/* 7.4.49  D1007                                                             */
1390
/* --------------------------------------------------------------------------*/
1391
 
1392
void disassemble::garmin_print_d1007 (D1007 *x)
1393
{
1394
	memset (&course, 0, sizeof(COURSE));
1395
	course.type = 1007;
1396
	course.course_index = x->course_index;
1397
	course.lap_index = x->lap_index;
1398
	course.total_time = x->total_time;
1399
	course.total_dist = x->total_dist;
1400
	course.begin.lat = x->begin.lat;
1401
	course.begin.lon = x->begin.lon;
1402
	course.end.lat = x->end.lat;
1403
	course.end.lon = x->end.lon;
1404
	course.avg_heart_rate = x->avg_heart_rate;
1405
	course.max_heart_rate = x->max_heart_rate;
1406
	course.avg_cadence = x->avg_cadence;
1407
	course.intensity = x->intensity;
1408
}
1409
 
1410
 
1411
/* --------------------------------------------------------------------------*/
1412
/* 7.4.50  D1008                                                             */
1413
/* --------------------------------------------------------------------------*/
1414
 
1415
 
1416
void disassemble::garmin_print_d1008 (D1008 *w)
1417
{
1418
	/* For some reason, D1008 is identical to D1002. */
1419
	garmin_print_d1002((D1002 *)w);
1420
	workout.type = 1008;
1421
}
1422
 
1423
 
1424
/* --------------------------------------------------------------------------*/
1425
/* 7.4.51  D1009                                                             */
1426
/* --------------------------------------------------------------------------*/
1427
 
1428
 
1429
void disassemble::garmin_print_d1009 (D1009 *x)
1430
{
1431
	memset(&run, 0, sizeof(RUN));
1432
	garmin_print_d1002((D1002 *)&x->workout);
217 andreas 1433
	memmove (&run.workout, &workout, sizeof (WORKOUT));
88 andreas 1434
	run.type = 1009;
1435
	run.track_index = x->track_index;
1436
	run.sport_type = x->sport_type;
1437
	run.first_lap_index = x->first_lap_index;
1438
	run.last_lap_index = x->last_lap_index;
1439
	run.program_type = x->program_type;
1440
	run.virtual_partner.time = x->quick_workout.time;
1441
	run.virtual_partner.distance = x->quick_workout.distance;
1442
	run.multisport = x->multisport;
1443
	addRun();
1444
}
1445
 
1446
 
1447
/* --------------------------------------------------------------------------*/
1448
/* 7.4.52  D1010                                                             */
1449
/* --------------------------------------------------------------------------*/
1450
 
1451
 
1452
void disassemble::garmin_print_d1010 (D1010 *x)
1453
{
1454
	memset(&run, 0, sizeof(RUN));
1455
	garmin_print_d1002((D1002 *)&x->workout);
1456
	run.type = 1010;
1457
	run.track_index = x->track_index;
1458
	run.sport_type = x->sport_type;
1459
	run.first_lap_index = x->first_lap_index;
1460
	run.last_lap_index = x->last_lap_index;
1461
	run.program_type = x->program_type;
1462
	run.virtual_partner.time = x->virtual_partner.time;
1463
	run.virtual_partner.distance = x->virtual_partner.distance;
1464
	run.multisport = x->multisport;
1465
	addRun();
1466
}
1467
 
1468
 
1469
/* --------------------------------------------------------------------------*/
1470
/* 7.4.53  D1011                                                             */
1471
/* --------------------------------------------------------------------------*/
1472
 
1473
 
1474
void disassemble::garmin_print_d1011 (D1011 *x)
1475
{
1476
	memset(&lap, 0, sizeof(LAP));
1477
	lap.type = 1011;
1478
	lap.start_time = x->start_time;
1479
	lap.total_time = x->total_time;
1480
	lap.total_distance = x->total_dist;
1481
	lap.begin.lat = x->begin.lat;
1482
	lap.begin.lon = x->begin.lon;
1483
	lap.end.lat = x->end.lat;
1484
	lap.end.lon = x->end.lon;
1485
	lap.calories = x->calories;
1486
	lap.index = x->index;
1487
	lap.max_speed = x->max_speed;
1488
	lap.avg_heart_rate = x->avg_heart_rate;
1489
	lap.max_heart_rate = x->max_heart_rate;
1490
	lap.intensity = x->intensity;
1491
	lap.avg_cadence = x->avg_cadence;
1492
	lap.trigger_method = x->trigger_method;
1493
	addLap();
1494
}
1495
 
1496
 
1497
/* --------------------------------------------------------------------------*/
1498
/* 7.4.54  D1012                                                             */
1499
/* --------------------------------------------------------------------------*/
1500
 
1501
void disassemble::garmin_print_d1012 (D1012 *x)
1502
{
1503
	memset (&course, 0, sizeof(COURSE));
1504
	course.type = 1012;
1505
	course.course_index = x->course_index;
1506
	strncpy (course.course_name, x->name, 11);
1507
	course.track_point_time = x->track_point_time;
1508
	course.point_type = x->point_type;
1509
}
1510
 
1511
 
1512
/* --------------------------------------------------------------------------*/
1513
/* 7.4.55  D1013                                                             */
1514
/* --------------------------------------------------------------------------*/
1515
 
1516
void disassemble::garmin_print_d1013 (D1013 *x)
1517
{
1518
	memset (&course, 0, sizeof(COURSE));
1519
	course.type = 1012;
1520
	course.max_courses = x->max_courses;
1521
	course.max_course_laps = x->max_course_laps;
1522
	course.max_course_pnt = x->max_course_pnt;
1523
	course.max_course_trk_pnt = x->max_course_trk_pnt;
1524
}
1525
 
1526
 
1527
/* --------------------------------------------------------------------------*/
1528
/* 7.4.XX  D1015 (Undocumented)                                              */
1529
/* --------------------------------------------------------------------------*/
1530
 
1531
void disassemble::garmin_print_d1015 (D1015 *x)
1532
{
1533
	memset(&lap, 0, sizeof(LAP));
1534
	lap.type = 1011;
1535
	lap.start_time = x->start_time;
1536
	lap.total_time = x->total_time;
1537
	lap.total_distance = x->total_dist;
1538
	lap.begin.lat = x->begin.lat;
1539
	lap.begin.lon = x->begin.lon;
1540
	lap.end.lat = x->end.lat;
1541
	lap.end.lon = x->end.lon;
1542
	lap.calories = x->calories;
1543
	lap.index = x->index;
1544
	lap.max_speed = x->max_speed;
1545
	lap.avg_heart_rate = x->avg_heart_rate;
1546
	lap.max_heart_rate = x->max_heart_rate;
1547
	lap.intensity = x->intensity;
1548
	lap.avg_cadence = x->avg_cadence;
1549
	lap.trigger_method = x->trigger_method;
1550
	addLap();
1551
}
1552
 
1553
 
1554
/* ========================================================================= */
1555
/* garmin_print_data                                                         */
1556
/* ========================================================================= */
1557
 
1558
void disassemble::garmin_print_data (garmin_data *d)
1559
{
245 andreas 1560
	if (!d)
1561
	   return;
1562
 
88 andreas 1563
#define CASE_PRINT(x) \
1564
  case data_D##x: garmin_print_d##x((D##x *)d->data); break
1565
 
1566
	switch (d->type)
1567
	{
1568
	   case data_Dlist:
1569
	      garmin_print_dlist ((garmin_list *)d->data);
1570
	   break;
1571
 
1572
	   CASE_PRINT(100);
1573
	   CASE_PRINT(101);
1574
	   CASE_PRINT(102);
1575
	   CASE_PRINT(103);
1576
	   CASE_PRINT(104);
1577
	   CASE_PRINT(105);
1578
	   CASE_PRINT(106);
1579
	   CASE_PRINT(107);
1580
	   CASE_PRINT(108);
1581
	   CASE_PRINT(109);
1582
	   CASE_PRINT(110);
1583
	   CASE_PRINT(120);
1584
	   CASE_PRINT(150);
1585
	   CASE_PRINT(151);
1586
	   CASE_PRINT(152);
1587
	   CASE_PRINT(154);
1588
	   CASE_PRINT(155);
1589
	   CASE_PRINT(200);
1590
	   CASE_PRINT(201);
1591
	   CASE_PRINT(202);
1592
	   CASE_PRINT(210);
1593
	   CASE_PRINT(300);
1594
	   CASE_PRINT(301);
1595
	   CASE_PRINT(302);
1596
	   CASE_PRINT(303);
1597
	   CASE_PRINT(304);
1598
	   CASE_PRINT(310);
1599
	   CASE_PRINT(311);
1600
	   CASE_PRINT(312);
1601
	   CASE_PRINT(400);
1602
	   CASE_PRINT(403);
1603
	   CASE_PRINT(450);
1604
	   CASE_PRINT(500);
1605
	   CASE_PRINT(501);
1606
	   CASE_PRINT(550);
1607
	   CASE_PRINT(551);
1608
	   CASE_PRINT(600);
1609
	   CASE_PRINT(650);
1610
	   CASE_PRINT(700);
1611
	   CASE_PRINT(800);
1612
	   CASE_PRINT(906);
1613
	   CASE_PRINT(1000);
1614
	   CASE_PRINT(1001);
1615
	   CASE_PRINT(1002);
1616
	   CASE_PRINT(1003);
1617
	   CASE_PRINT(1004);
1618
	   CASE_PRINT(1005);
1619
	   CASE_PRINT(1006);
1620
	   CASE_PRINT(1007);
1621
	   CASE_PRINT(1008);
1622
	   CASE_PRINT(1009);
1623
	   CASE_PRINT(1010);
1624
	   CASE_PRINT(1011);
1625
	   CASE_PRINT(1012);
1626
	   CASE_PRINT(1013);
1627
	   CASE_PRINT(1015);
137 andreas 1628
	   default: break;
88 andreas 1629
	}
1630
 
1631
#undef CASE_PRINT
1632
}
1633
 
104 andreas 1634
/*
1635
 * The following functions are to calculate some GPS related parameters.
1636
 * Base is the WGS84 date.
1637
 *
1638
 * This functions are not needed tho handle the files and data out of
1639
 * the GPS-device!
1640
 */
1641
double disassemble::CalcRad(double lat)
1642
/* earth's radius of curvature in meters at specified latitude.*/
1643
{
1644
const double a = 6378.137;
1645
const double e2 = 0.081082 * 0.081082;
1646
 
1647
	/*
1648
	 * the radius of curvature of an ellipsoidal Earth in the plane of a
1649
	 * meridian of latitude is given by
1650
	 *
1651
	 * R' = a * (1 - e^2) / (1 - e^2 * (sin(lat))^2)^(3/2)
1652
	 *
1653
	 * where a is the equatorial radius,
1654
	 * b is the polar radius, and
1655
	 * e is the eccentricity of the ellipsoid = sqrt(1 - b^2/a^2)
1656
	 *
1657
	 * a = 6378 km (3963 mi) Equatorial radius (surface to center distance)
1658
	 * b = 6356.752 km (3950 mi) Polar radius (surface to center distance)
1659
	 * e = 0.081082 Eccentricity
1660
	 */
1661
	double sc = sin(Deg2Rad(lat));
1662
	double x = a * (1.0 - e2);
1663
	double z = 1.0 - e2 * sc * sc;
1664
	double y = pow(z, 1.5);
1665
	double r = x / y;
1666
 
1667
	return r * 1000.0; // Convert to meters
1668
}
1669
 
1670
double disassemble::earth_distance(double lat1, double lon1, double lat2, double lon2)
1671
/* distance in meters between two points specified in degrees. */
1672
{
1673
double x1 = CalcRad(lat1) * cos(Deg2Rad(lon1)) * sin(Deg2Rad(90-lat1));
1674
double x2 = CalcRad(lat2) * cos(Deg2Rad(lon2)) * sin(Deg2Rad(90-lat2));
1675
double y1 = CalcRad(lat1) * sin(Deg2Rad(lon1)) * sin(Deg2Rad(90-lat1));
1676
double y2 = CalcRad(lat2) * sin(Deg2Rad(lon2)) * sin(Deg2Rad(90-lat2));
1677
double z1 = CalcRad(lat1) * cos(Deg2Rad(90-lat1));
1678
double z2 = CalcRad(lat2) * cos(Deg2Rad(90-lat2));
1679
double a = (x1*x2 + y1*y2 + z1*z2)/pow(CalcRad((lat1+lat2)/2),2);
1680
 
1681
	// a should be in [1, -1] but can sometimes fall outside it by
1682
	// a very small amount due to rounding errors in the preceding
1683
	// calculations (this is prone to happen when the argument points
1684
	// are very close together). Thus we constrain it here.
1685
	if (abs(a) > 1)
1686
	   a = 1;
1687
	else if (a < -1)
1688
	   a = -1;
1689
 
1690
	return CalcRad((lat1+lat2) / 2) * acos(a);
1691
}