Subversion Repositories public

Rev

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