Subversion Repositories public

Rev

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