Subversion Repositories public

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
93 andreas 1
#include "config.h"
2
#include <time.h>
3
#include <string.h>
4
#include "garmin.h"
5
 
6
 
7
/* 
8
   This file contains functions to print Garmin datatypes in an XML-like
9
   form.  The functions aim to reproduce the data losslessly, including
10
   floating point data, such that the data can be scanned back from the
11
   printed output and reconstructed exactly.
12
*/
13
 
14
 
15
#define GARMIN_ENUM_NAME(x,y)                        \
16
  static char * garmin_d##x##_##y ( D##x##_##y z )   \
17
  {                                                  \
18
    char * name = "unknown";                         \
19
                                                     \
20
    switch ( z )
21
 
22
#define GARMIN_ENUM_CASE(x,y)                        \
23
    case D##x##_##y: name = #y; break
24
 
25
#define GARMIN_ENUM_DEFAULT                          \
26
    default: break;                                  \
27
    }                                                \
28
                                                     \
29
    return name
30
 
31
#define GARMIN_TAGFMT(w,x,y,z)                       \
32
  do {                                               \
33
    print_spaces(fp,spaces+x);                       \
34
    fprintf(fp,"<%s>" w "</%s>\n",y,z,y);            \
35
  } while ( 0 )
36
 
37
#define GARMIN_TAGFUN(w,x,y,z)                       \
38
  do {                                               \
39
    print_spaces(fp,spaces+x);                       \
40
    fprintf(fp,"<%s>",y);                            \
41
    w(z,fp);                                         \
42
    fprintf(fp,"</%s>\n",y);                         \
43
  } while ( 0 )
44
 
45
#define GARMIN_TAGPOS(x,y,z)                         \
46
  do {                                               \
47
    print_spaces(fp,spaces+x);                       \
48
    fprintf(fp,"<%s lat=\"%.8lf\" lon=\"%.8lf\"/>\n",\
49
            y,SEMI2DEG((z).lat),SEMI2DEG((z).lon));  \
50
  } while ( 0 )
51
 
52
#define GARMIN_TAGSYM(x,y,z)                         \
53
  do {                                               \
54
    print_spaces(fp,spaces+x);                       \
55
    fprintf(fp,"<%s value=\"0x%x\" name=\"%s\"/>\n", \
56
	    y,z,garmin_symbol_name(z));              \
57
  } while ( 0 )
58
 
59
#define GARMIN_TAGU8B(x,y,z,l)			     \
60
  do {                                               \
61
    int u8b;                                         \
62
                                                     \
63
    open_tag(y,fp,spaces+x);                         \
64
    print_spaces(fp,spaces+x);                       \
65
    for ( u8b = 0; u8b < l; u8b++ ) {                \
66
      fprintf(fp," 0x%02x",z[u8b]);                  \
67
    }                                                \
68
    fprintf(fp,"\n");                                \
69
    close_tag(y,fp,spaces+x);                        \
70
  } while ( 0 )
71
 
72
#define GARMIN_TAGSTR(x,y,z) GARMIN_TAGFMT("%s",x,y,z)
73
#define GARMIN_TAGINT(x,y,z) GARMIN_TAGFMT("%d",x,y,z)
74
#define GARMIN_TAGU32(x,y,z) GARMIN_TAGFMT("%u",x,y,z)
75
#define GARMIN_TAGF32(x,y,z) GARMIN_TAGFUN(garmin_print_float32,x,y,z)
76
#define GARMIN_TAGF64(x,y,z) GARMIN_TAGFUN(garmin_print_float64,x,y,z)
77
#define GARMIN_TAGHEX(x,y,z) GARMIN_TAGFMT("0x%x",x,y,z)
78
 
79
 
80
static void
81
print_spaces ( FILE * fp, int spaces )
82
{
83
  int i;
84
 
85
  for ( i = 0; i < spaces; i++ ) {
86
    fprintf(fp," ");
87
  }
88
}
89
 
90
 
91
static void
92
open_tag ( const char * tag, FILE * fp, int spaces ) 
93
{
94
  print_spaces(fp,spaces);
95
  fprintf(fp,"<%s>\n",tag);
96
}
97
 
98
 
99
static void
100
open_tag_with_type ( const char * tag, uint32 type, FILE * fp, int spaces ) 
101
{
102
  print_spaces(fp,spaces);
103
  fprintf(fp,"<%s type=\"%d\">\n",tag,type);
104
}
105
 
106
 
107
static void
108
close_tag ( const char * tag, FILE * fp, int spaces ) 
109
{
110
  print_spaces(fp,spaces);
111
  fprintf(fp,"</%s>\n",tag);
112
}
113
 
114
 
115
static void
116
garmin_print_dlist ( garmin_list * l, FILE * fp, int spaces )
117
{
118
  garmin_list_node * n;
119
 
120
  for ( n = l->head; n != NULL; n = n->next ) {
121
    garmin_print_data(n->data,fp,spaces);
122
  }
123
}
124
 
125
 
126
/* Support function to print a time value in ISO 8601 compliant format */
127
 
128
static void
129
garmin_print_dtime ( uint32 t, FILE * fp, const char * label )
130
{
131
  time_t     tval;
132
  struct tm  tmval;
133
  char       buf[128];
134
  int        len;
135
 
136
  /* 
137
                                  012345678901234567890123
138
     This will make, for example, 2007-04-20T23:55:01-0700, but that date
139
     isn't quite ISO 8601 compliant.  We need to stick a ':' in the time
140
     zone between the hours and the minutes.
141
  */
142
 
143
  tval = t + TIME_OFFSET;
144
  localtime_r(&tval,&tmval);
145
  strftime(buf,sizeof(buf)-1,"%FT%T%z",&tmval);
146
 
147
  /* 
148
     If the last character is a 'Z', don't do anything.  Otherwise, we 
149
     need to move the last two characters out one and stick a colon in 
150
     the vacated spot.  Let's not forget the trailing '\0' that needs to 
151
     be moved as well.
152
  */
153
 
154
  len = strlen(buf);
155
  if ( len > 0 && buf[len-1] != 'Z' ) {
156
    memmove(buf+len-1,buf+len-2,3);
157
    buf[len-2] = ':';
158
  }
159
 
160
  /* OK.  Done. */
161
 
162
  fprintf(fp," %s=\"%s\"",label,buf);
163
}
164
 
165
 
166
/* Support function to print a position type */
167
 
168
static void
169
garmin_print_dpos ( position_type * pos, FILE * fp )
170
{
171
  if ( pos->lat != 0x7fffffff ) {
172
    fprintf(fp," lat=\"%.8lf\"",SEMI2DEG(pos->lat));
173
  }
174
  if ( pos->lon != 0x7fffffff ) {
175
    fprintf(fp," lon=\"%.8lf\"",SEMI2DEG(pos->lon));
176
  }
177
}
178
 
179
 
180
/* 
181
   Print a float32 with enough precision such that it can be reconstructed
182
   exactly from its decimal representation.
183
*/
184
 
185
static void
186
garmin_print_float32 ( float32 f, FILE * fp )
187
{
188
  if ( f > 100000000.0 || f < -100000000.0 ) {
189
    fprintf(fp,"%.9e",f);
190
  } else if ( f > 10000000.0 || f < -10000000.0 ) {
191
    fprintf(fp,"%.1f",f);
192
  } else if ( f > 1000000.0 || f < -1000000.0 ) {
193
    fprintf(fp,"%.2f",f);
194
  } else if ( f > 100000.0 || f < -100000.0 ) {
195
    fprintf(fp,"%.3f",f);
196
  } else if ( f > 10000.0 || f < -10000.0 ) {
197
    fprintf(fp,"%.4f",f);
198
  } else if ( f > 1000.0 || f < -1000.0 ) {
199
    fprintf(fp,"%.5f",f);
200
  } else if ( f > 100.0 || f < -100.0 ) {
201
    fprintf(fp,"%.6f",f);
202
  } else if ( f > 10.0 || f < -10.0 ) {
203
    fprintf(fp,"%.7f",f);
204
  } else if ( f > 1.0 || f < -1.0 ) {
205
    fprintf(fp,"%.8f",f);
206
  } else if ( f > 0.1 || f < -0.1 ) {
207
    fprintf(fp,"%.9f",f);
208
  } else if ( f != 0 ) {
209
    fprintf(fp,"%.9e",f);
210
  } else {
211
    fprintf(fp,"%.8f",f);
212
  }
213
}
214
 
215
 
216
/* 
217
   Print a float64 with enough precision such that it can be reconstructed
218
   exactly from its decimal representation.
219
*/
220
 
221
static void
222
garmin_print_float64 ( float64 f, FILE * fp )
223
{
224
  if ( f > 10000000000000000.0 || f < -10000000000000000.0 ) {
225
    fprintf(fp,"%.17e",f);
226
  } else if ( f > 1000000000000000.0 || f < -1000000000000000.0 ) {
227
    fprintf(fp,"%.1f",f);
228
  } else if ( f > 100000000000000.0 || f < -100000000000000.0 ) {
229
    fprintf(fp,"%.2f",f);
230
  } else if ( f > 10000000000000.0 || f < -10000000000000.0 ) {
231
    fprintf(fp,"%.3f",f);
232
  } else if ( f > 1000000000000.0 || f < -1000000000000.0 ) {
233
    fprintf(fp,"%.4f",f);
234
  } else if ( f > 100000000000.0 || f < -100000000000.0 ) {
235
    fprintf(fp,"%.5f",f);
236
  } else if ( f > 10000000000.0 || f < -10000000000.0 ) {
237
    fprintf(fp,"%.6f",f);
238
  } else if ( f > 1000000000.0 || f < -1000000000.0 ) {
239
    fprintf(fp,"%.7f",f);
240
  } else if ( f > 100000000.0 || f < -100000000.0 ) {
241
    fprintf(fp,"%.8f",f);
242
  } else if ( f > 10000000.0 || f < -10000000.0 ) {
243
    fprintf(fp,"%.9f",f);
244
  } else if ( f > 1000000.0 || f < -1000000.0 ) {
245
    fprintf(fp,"%.10f",f);
246
  } else if ( f > 100000.0 || f < -100000.0 ) {
247
    fprintf(fp,"%.11f",f);
248
  } else if ( f > 10000.0 || f < -10000.0 ) {
249
    fprintf(fp,"%.12f",f);
250
  } else if ( f > 1000.0 || f < -1000.0 ) {
251
    fprintf(fp,"%.13f",f);
252
  } else if ( f > 100.0 || f < -100.0 ) {
253
    fprintf(fp,"%.14f",f);
254
  } else if ( f > 10.0 || f < -10.0 ) {
255
    fprintf(fp,"%.15f",f);
256
  } else if ( f > 1.0 || f < -1.0 ) {
257
    fprintf(fp,"%.16f",f);
258
  } else if ( f > 0.1 || f < -0.1 ) {
259
    fprintf(fp,"%.17f",f);
260
  } else if ( f != 0 ) {
261
    fprintf(fp,"%.17e",f);
262
  } else {
263
    fprintf(fp,"%.16f",f);
264
  }
265
}
266
 
267
 
268
/* 
269
   Print a float32 whose value is invalid (and should not be printed) if 
270
   greater than 1.0e24 
271
*/
272
 
273
static void
274
garmin_print_dfloat32 ( float32 f, FILE * fp, const char * label )
275
{
276
  if ( f < 1.0e24 ) {
277
    fprintf(fp," %s=\"",label);
278
    garmin_print_float32(f,fp);
279
    fprintf(fp,"\"");
280
  }
281
}
282
 
283
 
284
/* Print a duration and distance. */
285
 
286
static void
287
garmin_print_ddist ( uint32 dur, float32 dist, FILE * fp )
288
{
289
  int  hun;
290
  int  sec;
291
  int  min;
292
  int  hrs;
293
 
294
  hun  = dur % 100;
295
  dur -= hun;
296
  dur /= 100;
297
  sec  = dur % 60;
298
  dur -= sec;
299
  dur /= 60;
300
  min  = dur % 60;
301
  dur -= min;
302
  dur /= 60;
303
  hrs  = dur;
304
 
305
  fprintf(fp," duration=\"%d:%02d:%02d.%02d\" distance=\"",hrs,min,sec,hun);
306
  garmin_print_float32(dist,fp);
307
  fprintf(fp,"\"");
308
}
309
 
310
 
311
/* --------------------------------------------------------------------------*/
312
/* 7.4.1  D100                                                               */
313
/* --------------------------------------------------------------------------*/
314
 
315
static void
316
garmin_print_d100 ( D100 * x, FILE * fp, int spaces )
317
{
318
  open_tag_with_type("waypoint",100,fp,spaces);
319
  GARMIN_TAGSTR(1,"ident",x->ident);
320
  GARMIN_TAGPOS(1,"position",x->posn);
321
  GARMIN_TAGSTR(1,"comment",x->cmnt);
322
  close_tag("waypoint",fp,spaces);
323
}
324
 
325
 
326
/* --------------------------------------------------------------------------*/
327
/* 7.4.2  D101                                                               */
328
/* --------------------------------------------------------------------------*/
329
 
330
static void
331
garmin_print_d101 ( D101 * x, FILE * fp, int spaces )
332
{
333
  open_tag_with_type("waypoint",101,fp,spaces);
334
  GARMIN_TAGSTR(1,"ident",x->ident);
335
  GARMIN_TAGPOS(1,"position",x->posn);
336
  GARMIN_TAGSTR(1,"comment",x->cmnt);
337
  GARMIN_TAGF32(1,"proximity_distance",x->dst);
338
  GARMIN_TAGSYM(1,"symbol",x->smbl);
339
  close_tag("waypoint",fp,spaces);
340
}
341
 
342
 
343
/* --------------------------------------------------------------------------*/
344
/* 7.4.3  D102                                                               */
345
/* --------------------------------------------------------------------------*/
346
 
347
static void
348
garmin_print_d102 ( D102 * x, FILE * fp, int spaces )
349
{
350
  open_tag_with_type("waypoint",102,fp,spaces);
351
  GARMIN_TAGSTR(1,"ident",x->ident);
352
  GARMIN_TAGPOS(1,"position",x->posn);
353
  GARMIN_TAGSTR(1,"comment",x->cmnt);
354
  GARMIN_TAGF32(1,"proximity_distance",x->dst);
355
  GARMIN_TAGSYM(1,"symbol",x->smbl);
356
  close_tag("waypoint",fp,spaces);
357
}
358
 
359
 
360
/* --------------------------------------------------------------------------*/
361
/* 7.4.4  D103                                                               */
362
/* --------------------------------------------------------------------------*/
363
 
364
 
365
GARMIN_ENUM_NAME(103,smbl) {
366
  GARMIN_ENUM_CASE(103,smbl_dot);
367
  GARMIN_ENUM_CASE(103,smbl_house);
368
  GARMIN_ENUM_CASE(103,smbl_gas);
369
  GARMIN_ENUM_CASE(103,smbl_car);
370
  GARMIN_ENUM_CASE(103,smbl_fish);
371
  GARMIN_ENUM_CASE(103,smbl_boat);
372
  GARMIN_ENUM_CASE(103,smbl_anchor);
373
  GARMIN_ENUM_CASE(103,smbl_wreck);
374
  GARMIN_ENUM_CASE(103,smbl_exit);
375
  GARMIN_ENUM_CASE(103,smbl_skull);
376
  GARMIN_ENUM_CASE(103,smbl_flag);
377
  GARMIN_ENUM_CASE(103,smbl_camp);
378
  GARMIN_ENUM_CASE(103,smbl_circle_x);
379
  GARMIN_ENUM_CASE(103,smbl_deer);
380
  GARMIN_ENUM_CASE(103,smbl_1st_aid);
381
  GARMIN_ENUM_CASE(103,smbl_back_track);
382
  GARMIN_ENUM_DEFAULT;
383
}
384
 
385
 
386
GARMIN_ENUM_NAME(103,dspl) {
387
  GARMIN_ENUM_CASE(103,dspl_name);
388
  GARMIN_ENUM_CASE(103,dspl_none);
389
  GARMIN_ENUM_CASE(103,dspl_cmnt);
390
  GARMIN_ENUM_DEFAULT;
391
}
392
 
393
 
394
static void
395
garmin_print_d103 ( D103 * x, FILE * fp, int spaces )
396
{
397
  open_tag_with_type("waypoint",103,fp,spaces);
398
  GARMIN_TAGSTR(1,"ident",x->ident);
399
  GARMIN_TAGPOS(1,"position",x->posn);
400
  GARMIN_TAGSTR(1,"comment",x->cmnt);
401
  GARMIN_TAGSTR(1,"symbol",garmin_d103_smbl(x->smbl));
402
  GARMIN_TAGSTR(1,"display",garmin_d103_dspl(x->dspl));
403
  close_tag("waypoint",fp,spaces);
404
}
405
 
406
 
407
/* --------------------------------------------------------------------------*/
408
/* 7.4.5  D104                                                               */
409
/* --------------------------------------------------------------------------*/
410
 
411
 
412
GARMIN_ENUM_NAME(104,dspl) {
413
  GARMIN_ENUM_CASE(104,dspl_smbl_none);
414
  GARMIN_ENUM_CASE(104,dspl_smbl_only);
415
  GARMIN_ENUM_CASE(104,dspl_smbl_name);
416
  GARMIN_ENUM_CASE(104,dspl_smbl_cmnt);
417
  GARMIN_ENUM_DEFAULT;
418
}
419
 
420
 
421
static void
422
garmin_print_d104 ( D104 * x, FILE * fp, int spaces )
423
{
424
  open_tag_with_type("waypoint",104,fp,spaces);
425
  GARMIN_TAGSTR(1,"ident",x->ident);
426
  GARMIN_TAGPOS(1,"position",x->posn);
427
  GARMIN_TAGSTR(1,"comment",x->cmnt);
428
  GARMIN_TAGF32(1,"proximity_distance",x->dst);
429
  GARMIN_TAGSYM(1,"symbol",x->smbl);
430
  GARMIN_TAGSTR(1,"display",garmin_d104_dspl(x->dspl));
431
  close_tag("waypoint",fp,spaces);
432
}
433
 
434
 
435
/* --------------------------------------------------------------------------*/
436
/* 7.4.6  D105                                                               */
437
/* --------------------------------------------------------------------------*/
438
 
439
static void
440
garmin_print_d105 ( D105 * x, FILE * fp, int spaces )
441
{
442
  open_tag_with_type("waypoint",105,fp,spaces);
443
  GARMIN_TAGSTR(1,"ident",x->wpt_ident);
444
  GARMIN_TAGPOS(1,"position",x->posn);
445
  GARMIN_TAGSYM(1,"symbol",x->smbl);
446
  close_tag("waypoint",fp,spaces);
447
}
448
 
449
 
450
/* --------------------------------------------------------------------------*/
451
/* 7.4.7  D106                                                               */
452
/* --------------------------------------------------------------------------*/
453
 
454
static void
455
garmin_print_d106 ( D106 * x, FILE * fp, int spaces )
456
{
457
  open_tag_with_type("waypoint",106,fp,spaces);
458
  GARMIN_TAGSTR(1,"class",(x->wpt_class)?"non-user":"user");
459
  if ( x->wpt_class != 0 ) {
460
    GARMIN_TAGU8B(1,"subclass",x->subclass,13);
461
  }
462
  GARMIN_TAGSTR(1,"ident",x->wpt_ident);
463
  GARMIN_TAGPOS(1,"position",x->posn);
464
  GARMIN_TAGSYM(1,"symbol",x->smbl);
465
  GARMIN_TAGSTR(1,"link",x->lnk_ident);
466
  close_tag("waypoint",fp,spaces);
467
}
468
 
469
 
470
/* --------------------------------------------------------------------------*/
471
/* 7.4.8  D107                                                               */
472
/* --------------------------------------------------------------------------*/
473
 
474
 
475
GARMIN_ENUM_NAME(107,clr) {
476
  GARMIN_ENUM_CASE(107,clr_default);
477
  GARMIN_ENUM_CASE(107,clr_red);
478
  GARMIN_ENUM_CASE(107,clr_green);
479
  GARMIN_ENUM_CASE(107,clr_blue);
480
  GARMIN_ENUM_DEFAULT;
481
}
482
 
483
 
484
static void
485
garmin_print_d107 ( D107 * x, FILE * fp, int spaces )
486
{
487
  open_tag_with_type("waypoint",107,fp,spaces);
488
  GARMIN_TAGSTR(1,"ident",x->ident);
489
  GARMIN_TAGPOS(1,"position",x->posn);
490
  GARMIN_TAGSTR(1,"comment",x->cmnt);
491
  GARMIN_TAGF32(1,"proximity_distance",x->dst);
492
  GARMIN_TAGSTR(1,"symbol",garmin_d103_smbl(x->smbl));
493
  GARMIN_TAGSTR(1,"display",garmin_d103_dspl(x->dspl));
494
  GARMIN_TAGSTR(1,"color",garmin_d107_clr(x->color));
495
  close_tag("waypoint",fp,spaces);
496
}
497
 
498
 
499
/* --------------------------------------------------------------------------*/
500
/* 7.4.9  D108                                                               */
501
/* --------------------------------------------------------------------------*/
502
 
503
 
504
GARMIN_ENUM_NAME(108,wpt_class) {
505
  GARMIN_ENUM_CASE(108,user_wpt);
506
  GARMIN_ENUM_CASE(108,avtn_apt_wpt);
507
  GARMIN_ENUM_CASE(108,avtn_int_wpt);
508
  GARMIN_ENUM_CASE(108,avtn_ndb_wpt);
509
  GARMIN_ENUM_CASE(108,avtn_vor_wpt);
510
  GARMIN_ENUM_CASE(108,avtn_arwy_wpt);
511
  GARMIN_ENUM_CASE(108,avtn_aint_wpt);
512
  GARMIN_ENUM_CASE(108,avtn_andb_wpt);
513
  GARMIN_ENUM_CASE(108,map_pnt_wpt);
514
  GARMIN_ENUM_CASE(108,map_area_wpt);
515
  GARMIN_ENUM_CASE(108,map_int_wpt);
516
  GARMIN_ENUM_CASE(108,map_adrs_wpt);
517
  GARMIN_ENUM_CASE(108,map_line_wpt);
518
  GARMIN_ENUM_DEFAULT;
519
}
520
 
521
 
522
GARMIN_ENUM_NAME(108,color) {
523
  GARMIN_ENUM_CASE(108,black);
524
  GARMIN_ENUM_CASE(108,dark_red);
525
  GARMIN_ENUM_CASE(108,dark_green);
526
  GARMIN_ENUM_CASE(108,dark_yellow);
527
  GARMIN_ENUM_CASE(108,dark_blue);
528
  GARMIN_ENUM_CASE(108,dark_magenta);
529
  GARMIN_ENUM_CASE(108,dark_cyan);
530
  GARMIN_ENUM_CASE(108,light_gray);
531
  GARMIN_ENUM_CASE(108,dark_gray);
532
  GARMIN_ENUM_CASE(108,red);
533
  GARMIN_ENUM_CASE(108,green);
534
  GARMIN_ENUM_CASE(108,yellow);
535
  GARMIN_ENUM_CASE(108,blue);
536
  GARMIN_ENUM_CASE(108,magenta);
537
  GARMIN_ENUM_CASE(108,cyan);
538
  GARMIN_ENUM_CASE(108,white);
539
  GARMIN_ENUM_CASE(108,default_color);
540
  GARMIN_ENUM_DEFAULT;
541
}
542
 
543
 
544
static void
545
garmin_print_d108 ( D108 * x, FILE * fp, int spaces )
546
{
547
  open_tag_with_type("waypoint",108,fp,spaces);
548
  GARMIN_TAGSTR(1,"ident",x->ident);
549
  GARMIN_TAGPOS(1,"position",x->posn);
550
  GARMIN_TAGSTR(1,"comment",x->comment);
551
  GARMIN_TAGSYM(1,"symbol",x->smbl);
552
  GARMIN_TAGSTR(1,"display",garmin_d103_dspl(x->dspl));
553
  GARMIN_TAGSTR(1,"class",garmin_d108_wpt_class(x->wpt_class));
554
  GARMIN_TAGU8B(1,"subclass",x->subclass,18);
555
  GARMIN_TAGHEX(1,"attr",x->attr);
556
  GARMIN_TAGSTR(1,"color",garmin_d108_color(x->color));
557
  if ( x->alt  < 1.0e24 ) GARMIN_TAGF32(1,"altitude",x->alt);
558
  if ( x->dpth < 1.0e24 ) GARMIN_TAGF32(1,"depth",x->dpth);
559
  if ( x->dist < 1.0e24 ) GARMIN_TAGF32(1,"distance",x->dist);
560
  GARMIN_TAGSTR(1,"facility",x->facility);
561
  GARMIN_TAGSTR(1,"city",x->city);
562
  GARMIN_TAGSTR(1,"addr",x->addr);
563
  GARMIN_TAGSTR(1,"cross_road",x->cross_road);
564
  close_tag("waypoint",fp,spaces);
565
}
566
 
567
 
568
/* --------------------------------------------------------------------------*/
569
/* 7.4.10  D109                                                              */
570
/* --------------------------------------------------------------------------*/
571
 
572
static void
573
garmin_print_d109 ( D109 * x, FILE * fp, int spaces )
574
{
575
  uint8 color = x->dspl_color & 0x1f;
576
 
577
  if ( color == 0x1f ) color = D108_default_color;
578
 
579
  open_tag_with_type("waypoint",109,fp,spaces);
580
  GARMIN_TAGSTR(1,"ident",x->ident);
581
  GARMIN_TAGPOS(1,"position",x->posn);
582
  GARMIN_TAGSTR(1,"comment",x->comment);
583
  GARMIN_TAGSYM(1,"symbol",x->smbl);
584
  GARMIN_TAGSTR(1,"color",garmin_d108_color(color));
585
  GARMIN_TAGSTR(1,"display",garmin_d103_dspl((x->dspl_color >> 5) & 0x03));
586
  GARMIN_TAGSTR(1,"class",garmin_d108_wpt_class(x->wpt_class));
587
  GARMIN_TAGU8B(1,"subclass",x->subclass,18);
588
  GARMIN_TAGHEX(1,"attr",x->attr);
589
  GARMIN_TAGHEX(1,"dtyp",x->dtyp);
590
  GARMIN_TAGU32(1,"ete",x->ete);
591
  if ( x->alt  < 1.0e24 ) GARMIN_TAGF32(1,"altitude",x->alt);
592
  if ( x->dpth < 1.0e24 ) GARMIN_TAGF32(1,"depth",x->dpth);
593
  if ( x->dist < 1.0e24 ) GARMIN_TAGF32(1,"distance",x->dist);
594
  GARMIN_TAGSTR(1,"facility",x->facility);
595
  GARMIN_TAGSTR(1,"city",x->city);
596
  GARMIN_TAGSTR(1,"addr",x->addr);
597
  GARMIN_TAGSTR(1,"cross_road",x->cross_road);
598
  close_tag("waypoint",fp,spaces);
599
}
600
 
601
 
602
/* --------------------------------------------------------------------------*/
603
/* 7.4.11  D110                                                              */
604
/* --------------------------------------------------------------------------*/
605
 
606
 
607
GARMIN_ENUM_NAME(110,wpt_class) {
608
  GARMIN_ENUM_CASE(110,user_wpt);
609
  GARMIN_ENUM_CASE(110,avtn_apt_wpt);
610
  GARMIN_ENUM_CASE(110,avtn_int_wpt);
611
  GARMIN_ENUM_CASE(110,avtn_ndb_wpt);
612
  GARMIN_ENUM_CASE(110,avtn_vor_wpt);
613
  GARMIN_ENUM_CASE(110,avtn_arwy_wpt);
614
  GARMIN_ENUM_CASE(110,avtn_aint_wpt);
615
  GARMIN_ENUM_CASE(110,avtn_andb_wpt);
616
  GARMIN_ENUM_CASE(110,map_pnt_wpt);
617
  GARMIN_ENUM_CASE(110,map_area_wpt);
618
  GARMIN_ENUM_CASE(110,map_int_wpt);
619
  GARMIN_ENUM_CASE(110,map_adrs_wpt);
620
  GARMIN_ENUM_CASE(110,map_line_wpt);
621
  GARMIN_ENUM_DEFAULT;
622
}
623
 
624
 
625
GARMIN_ENUM_NAME(110,color) {
626
  GARMIN_ENUM_CASE(110,black);
627
  GARMIN_ENUM_CASE(110,dark_red);
628
  GARMIN_ENUM_CASE(110,dark_green);
629
  GARMIN_ENUM_CASE(110,dark_yellow);
630
  GARMIN_ENUM_CASE(110,dark_blue);
631
  GARMIN_ENUM_CASE(110,dark_magenta);
632
  GARMIN_ENUM_CASE(110,dark_cyan);
633
  GARMIN_ENUM_CASE(110,light_gray);
634
  GARMIN_ENUM_CASE(110,dark_gray);
635
  GARMIN_ENUM_CASE(110,red);
636
  GARMIN_ENUM_CASE(110,green);
637
  GARMIN_ENUM_CASE(110,yellow);
638
  GARMIN_ENUM_CASE(110,blue);
639
  GARMIN_ENUM_CASE(110,magenta);
640
  GARMIN_ENUM_CASE(110,cyan);
641
  GARMIN_ENUM_CASE(110,white);
642
  GARMIN_ENUM_CASE(110,transparent);
643
  GARMIN_ENUM_DEFAULT;
644
}
645
 
646
 
647
GARMIN_ENUM_NAME(110,dspl) {
648
  GARMIN_ENUM_CASE(110,symbol_name);
649
  GARMIN_ENUM_CASE(110,symbol_only);
650
  GARMIN_ENUM_CASE(110,symbol_comment);
651
  GARMIN_ENUM_DEFAULT;
652
}
653
 
654
 
655
static void
656
garmin_print_d110 ( D110 * x, FILE * fp, int spaces )
657
{
658
  open_tag_with_type("waypoint",110,fp,spaces);
659
  GARMIN_TAGHEX(1,"dtyp",x->dtyp);
660
  GARMIN_TAGSTR(1,"wpt_class",garmin_d110_wpt_class(x->wpt_class));
661
  GARMIN_TAGSTR(1,"color",garmin_d110_color((x->dspl_color) & 0x1f));
662
  GARMIN_TAGSTR(1,"display",garmin_d110_dspl((x->dspl_color >> 5) & 0x03));
663
  GARMIN_TAGHEX(1,"attr",x->attr);
664
  GARMIN_TAGSYM(1,"symbol",x->smbl);
665
  GARMIN_TAGPOS(1,"position",x->posn);
666
  if ( x->alt  < 1.0e24 ) GARMIN_TAGF32(1,"altitude",x->alt);
667
  if ( x->dpth < 1.0e24 ) GARMIN_TAGF32(1,"depth",x->dpth);
668
  if ( x->dist < 1.0e24 ) GARMIN_TAGF32(1,"distance",x->dist);
669
  if ( x->temp < 1.0e24 ) GARMIN_TAGF32(1,"temperature",x->temp);
670
  GARMIN_TAGSTR(1,"state",x->state);
671
  GARMIN_TAGSTR(1,"country_code",x->cc);
672
  GARMIN_TAGU32(1,"ete",x->ete);
673
  if ( x->time != 0xffffffff ) GARMIN_TAGU32(1,"time",x->time);
674
  GARMIN_TAGHEX(1,"category",x->wpt_cat);
675
  GARMIN_TAGSTR(1,"ident",x->ident);
676
  GARMIN_TAGSTR(1,"comment",x->comment);
677
  GARMIN_TAGSTR(1,"facility",x->facility);
678
  GARMIN_TAGSTR(1,"city",x->city);
679
  GARMIN_TAGSTR(1,"address_number",x->addr);
680
  GARMIN_TAGSTR(1,"cross_road",x->cross_road);
681
  close_tag("waypoint",fp,spaces);
682
}
683
 
684
 
685
/* --------------------------------------------------------------------------*/
686
/* 7.4.12  D120                                                              */
687
/* --------------------------------------------------------------------------*/
688
 
689
static void
690
garmin_print_d120 ( D120 * x, FILE * fp, int spaces )
691
{
692
  GARMIN_TAGSTR(0,"waypoint_category",x->name);
693
}
694
 
695
 
696
/* --------------------------------------------------------------------------*/
697
/* 7.4.13  D150                                                              */
698
/* --------------------------------------------------------------------------*/
699
 
700
 
701
GARMIN_ENUM_NAME(150,wpt_class) {
702
  GARMIN_ENUM_CASE(150,apt_wpt_class);
703
  GARMIN_ENUM_CASE(150,int_wpt_class);
704
  GARMIN_ENUM_CASE(150,ndb_wpt_class);
705
  GARMIN_ENUM_CASE(150,vor_wpt_class);
706
  GARMIN_ENUM_CASE(150,usr_wpt_class);
707
  GARMIN_ENUM_CASE(150,rwy_wpt_class);
708
  GARMIN_ENUM_CASE(150,aint_wpt_class);
709
  GARMIN_ENUM_CASE(150,locked_wpt_class);
710
  GARMIN_ENUM_DEFAULT;
711
}
712
 
713
 
714
static void
715
garmin_print_d150 ( D150 * x, FILE * fp, int spaces )
716
{
717
  open_tag_with_type("waypoint",150,fp,spaces);
718
  GARMIN_TAGSTR(1,"ident",x->ident);
719
  GARMIN_TAGSTR(1,"class",garmin_d150_wpt_class(x->wpt_class));
720
  GARMIN_TAGPOS(1,"position",x->posn);
721
  GARMIN_TAGSTR(1,"comment",x->cmnt);
722
  if ( x->wpt_class != D150_usr_wpt_class ) {
723
    GARMIN_TAGSTR(1,"city",x->city);
724
    GARMIN_TAGSTR(1,"state",x->state);
725
    GARMIN_TAGSTR(1,"facility_name",x->name);
726
    GARMIN_TAGSTR(1,"country_code",x->cc);
727
  }
728
  if ( x->wpt_class == D150_apt_wpt_class ) {
729
    GARMIN_TAGINT(1,"altitude",x->alt);
730
  }
731
  close_tag("waypoint",fp,spaces);
732
}
733
 
734
 
735
/* --------------------------------------------------------------------------*/
736
/* 7.4.14  D151                                                              */
737
/* --------------------------------------------------------------------------*/
738
 
739
 
740
GARMIN_ENUM_NAME(151,wpt_class) {
741
  GARMIN_ENUM_CASE(151,apt_wpt_class);
742
  GARMIN_ENUM_CASE(151,vor_wpt_class);
743
  GARMIN_ENUM_CASE(151,usr_wpt_class);
744
  GARMIN_ENUM_CASE(151,locked_wpt_class);
745
  GARMIN_ENUM_DEFAULT;
746
}
747
 
748
 
749
static void
750
garmin_print_d151 ( D151 * x, FILE * fp, int spaces )
751
{
752
  open_tag_with_type("waypoint",151,fp,spaces);
753
  GARMIN_TAGSTR(1,"ident",x->ident);
754
  GARMIN_TAGSTR(1,"class",garmin_d151_wpt_class(x->wpt_class));
755
  GARMIN_TAGPOS(1,"position",x->posn);
756
  GARMIN_TAGSTR(1,"comment",x->cmnt);
757
  GARMIN_TAGF32(1,"proximity_distance",x->dst);
758
  if ( x->wpt_class != D151_usr_wpt_class ) {
759
    GARMIN_TAGSTR(1,"city",x->city);
760
    GARMIN_TAGSTR(1,"state",x->state);
761
    GARMIN_TAGSTR(1,"facility_name",x->name);
762
    GARMIN_TAGSTR(1,"country_code",x->cc);
763
  }
764
  if ( x->wpt_class == D151_apt_wpt_class ) {
765
    GARMIN_TAGINT(1,"altitude",x->alt);
766
  }
767
  close_tag("waypoint",fp,spaces);
768
}
769
 
770
 
771
/* --------------------------------------------------------------------------*/
772
/* 7.4.15  D152                                                              */
773
/* --------------------------------------------------------------------------*/
774
 
775
 
776
GARMIN_ENUM_NAME(152,wpt_class) {
777
  GARMIN_ENUM_CASE(152,apt_wpt_class);
778
  GARMIN_ENUM_CASE(152,int_wpt_class);
779
  GARMIN_ENUM_CASE(152,ndb_wpt_class);
780
  GARMIN_ENUM_CASE(152,vor_wpt_class);
781
  GARMIN_ENUM_CASE(152,usr_wpt_class);
782
  GARMIN_ENUM_CASE(152,locked_wpt_class);
783
  GARMIN_ENUM_DEFAULT;
784
}
785
 
786
 
787
static void
788
garmin_print_d152 ( D152 * x, FILE * fp, int spaces )
789
{
790
  open_tag_with_type("waypoint",152,fp,spaces);
791
  GARMIN_TAGSTR(1,"ident",x->ident);
792
  GARMIN_TAGSTR(1,"class",garmin_d152_wpt_class(x->wpt_class));
793
  GARMIN_TAGPOS(1,"position",x->posn);
794
  GARMIN_TAGSTR(1,"comment",x->cmnt);
795
  GARMIN_TAGF32(1,"proximity_distance",x->dst);
796
  if ( x->wpt_class != D152_usr_wpt_class ) {
797
    GARMIN_TAGSTR(1,"city",x->city);
798
    GARMIN_TAGSTR(1,"state",x->state);
799
    GARMIN_TAGSTR(1,"facility_name",x->name);
800
    GARMIN_TAGSTR(1,"country_code",x->cc);
801
  }
802
  if ( x->wpt_class == D152_apt_wpt_class ) {
803
    GARMIN_TAGINT(1,"altitude",x->alt);
804
  }
805
  close_tag("waypoint",fp,spaces);
806
}
807
 
808
 
809
/* --------------------------------------------------------------------------*/
810
/* 7.4.16  D154                                                              */
811
/* --------------------------------------------------------------------------*/
812
 
813
 
814
GARMIN_ENUM_NAME(154,wpt_class) {
815
  GARMIN_ENUM_CASE(154,apt_wpt_class);
816
  GARMIN_ENUM_CASE(154,int_wpt_class);
817
  GARMIN_ENUM_CASE(154,ndb_wpt_class);
818
  GARMIN_ENUM_CASE(154,vor_wpt_class);
819
  GARMIN_ENUM_CASE(154,usr_wpt_class);
820
  GARMIN_ENUM_CASE(154,rwy_wpt_class);
821
  GARMIN_ENUM_CASE(154,aint_wpt_class);
822
  GARMIN_ENUM_CASE(154,andb_wpt_class);
823
  GARMIN_ENUM_CASE(154,sym_wpt_class);
824
  GARMIN_ENUM_CASE(154,locked_wpt_class);
825
  GARMIN_ENUM_DEFAULT;
826
}
827
 
828
 
829
static void
830
garmin_print_d154 ( D154 * x, FILE * fp, int spaces )
831
{
832
  open_tag_with_type("waypoint",154,fp,spaces);
833
  GARMIN_TAGSTR(1,"ident",x->ident);
834
  GARMIN_TAGSTR(1,"class",garmin_d154_wpt_class(x->wpt_class));
835
  GARMIN_TAGPOS(1,"position",x->posn);
836
  GARMIN_TAGSTR(1,"comment",x->cmnt);
837
  GARMIN_TAGF32(1,"proximity_distance",x->dst);
838
  if ( x->wpt_class != D154_usr_wpt_class ) {
839
    GARMIN_TAGSTR(1,"city",x->city);
840
    GARMIN_TAGSTR(1,"state",x->state);
841
    GARMIN_TAGSTR(1,"facility_name",x->name);
842
    GARMIN_TAGSTR(1,"country_code",x->cc);
843
  }
844
  if ( x->wpt_class == D154_apt_wpt_class ) {
845
    GARMIN_TAGINT(1,"altitude",x->alt);
846
  }
847
  GARMIN_TAGSYM(1,"symbol",x->smbl);
848
  close_tag("waypoint",fp,spaces);
849
}
850
 
851
 
852
/* --------------------------------------------------------------------------*/
853
/* 7.4.17  D155                                                              */
854
/* --------------------------------------------------------------------------*/
855
 
856
 
857
GARMIN_ENUM_NAME(155,wpt_class) {
858
  GARMIN_ENUM_CASE(155,apt_wpt_class);
859
  GARMIN_ENUM_CASE(155,int_wpt_class);
860
  GARMIN_ENUM_CASE(155,ndb_wpt_class);
861
  GARMIN_ENUM_CASE(155,vor_wpt_class);
862
  GARMIN_ENUM_CASE(155,usr_wpt_class);
863
  GARMIN_ENUM_CASE(155,locked_wpt_class);
864
  GARMIN_ENUM_DEFAULT;
865
}
866
 
867
 
868
GARMIN_ENUM_NAME(155,dspl) {
869
  GARMIN_ENUM_CASE(155,dspl_smbl_only);
870
  GARMIN_ENUM_CASE(155,dspl_smbl_name);
871
  GARMIN_ENUM_CASE(155,dspl_smbl_cmnt);
872
  GARMIN_ENUM_DEFAULT;
873
}
874
 
875
 
876
static void
877
garmin_print_d155 ( D155 * x, FILE * fp, int spaces )
878
{
879
  open_tag_with_type("waypoint",155,fp,spaces);
880
  GARMIN_TAGSTR(1,"ident",x->ident);
881
  GARMIN_TAGSTR(1,"class",garmin_d155_wpt_class(x->wpt_class));
882
  GARMIN_TAGPOS(1,"position",x->posn);
883
  GARMIN_TAGSTR(1,"comment",x->cmnt);
884
  GARMIN_TAGF32(1,"proximity_distance",x->dst);
885
  if ( x->wpt_class != D155_usr_wpt_class ) {
886
    GARMIN_TAGSTR(1,"city",x->city);
887
    GARMIN_TAGSTR(1,"state",x->state);
888
    GARMIN_TAGSTR(1,"facility_name",x->name);
889
    GARMIN_TAGSTR(1,"country_code",x->cc);
890
  }
891
  if ( x->wpt_class == D155_apt_wpt_class ) {
892
    GARMIN_TAGINT(1,"altitude",x->alt);
893
  }
894
  GARMIN_TAGSYM(1,"symbol",x->smbl);
895
  GARMIN_TAGSTR(1,"display",garmin_d155_dspl(x->dspl));
896
  close_tag("waypoint",fp,spaces);
897
}
898
 
899
 
900
/* --------------------------------------------------------------------------*/
901
/* 7.4.18  D200                                                              */
902
/* --------------------------------------------------------------------------*/
903
 
904
static void
905
garmin_print_d200 ( D200 * x, FILE * fp, int spaces )
906
{
907
  print_spaces(fp,spaces);
908
  fprintf(fp,"<route_header type=\"200\" number=\"%d\"/>\n", *x);
909
}
910
 
911
 
912
/* --------------------------------------------------------------------------*/
913
/* 7.4.19  D201                                                              */
914
/* --------------------------------------------------------------------------*/
915
 
916
static void
917
garmin_print_d201 ( D201 * x, FILE * fp, int spaces )
918
{
919
  print_spaces(fp,spaces);
920
  fprintf(fp,"<route_header type=\"201\" number=\"%d\">%s</route_header>\n",
921
	  x->nmbr,x->cmnt);
922
}
923
 
924
 
925
/* --------------------------------------------------------------------------*/
926
/* 7.4.20  D202                                                              */
927
/* --------------------------------------------------------------------------*/
928
 
929
static void
930
garmin_print_d202 ( D202 * x, FILE * fp, int spaces )
931
{
932
  print_spaces(fp,spaces);
933
  fprintf(fp,"<route_header type=\"202\" ident=\"%s\"/>\n",
934
	  x->rte_ident);
935
}
936
 
937
 
938
/* --------------------------------------------------------------------------*/
939
/* 7.4.21  D210                                                              */
940
/* --------------------------------------------------------------------------*/
941
 
942
 
943
GARMIN_ENUM_NAME(210,class) {
944
  GARMIN_ENUM_CASE(210,line);
945
  GARMIN_ENUM_CASE(210,link);
946
  GARMIN_ENUM_CASE(210,net);
947
  GARMIN_ENUM_CASE(210,direct);
948
  GARMIN_ENUM_CASE(210,snap);
949
  GARMIN_ENUM_DEFAULT;
950
}
951
 
952
 
953
static void
954
garmin_print_d210 ( D210 * x, FILE * fp, int spaces )
955
{
956
  print_spaces(fp,spaces);
957
  fprintf(fp,"<route_link type=\"210\" class=\"%s\" ident=\"%s\">\n",
958
	  garmin_d210_class(x->class),x->ident);
959
  GARMIN_TAGU8B(1,"route_link_subclass",x->subclass,18);
960
  close_tag("route_link",fp,spaces);
961
}
962
 
963
 
964
/* --------------------------------------------------------------------------*/
965
/* 7.4.22  D300                                                              */
966
/* --------------------------------------------------------------------------*/
967
 
968
static void
969
garmin_print_d300 ( D300 * p, FILE * fp, int spaces )
970
{
971
  print_spaces(fp,spaces);
972
  fprintf(fp,"<point type=\"300\"");
973
  garmin_print_dtime(p->time,fp,"time");
974
  garmin_print_dpos(&p->posn,fp);
975
  if ( p->new_trk != 0 ) {
976
    fprintf(fp," new=\"true\"");
977
  }
978
  fprintf(fp,"/>\n");
979
}
980
 
981
 
982
/* --------------------------------------------------------------------------*/
983
/* 7.4.23  D301                                                              */
984
/* --------------------------------------------------------------------------*/
985
 
986
static void
987
garmin_print_d301 ( D301 * p, FILE * fp, int spaces )
988
{
989
  print_spaces(fp,spaces);
990
  fprintf(fp,"<point type=\"301\"");
991
  garmin_print_dtime(p->time,fp,"time");
992
  garmin_print_dpos(&p->posn,fp);
993
  garmin_print_dfloat32(p->alt,fp,"alt");
994
  garmin_print_dfloat32(p->dpth,fp,"depth");
995
  if ( p->new_trk != 0 ) {
996
    fprintf(fp," new=\"true\"");
997
  }
998
  fprintf(fp,"/>\n");
999
}
1000
 
1001
 
1002
/* --------------------------------------------------------------------------*/
1003
/* 7.4.24  D302                                                              */
1004
/* --------------------------------------------------------------------------*/
1005
 
1006
static void
1007
garmin_print_d302 ( D302 * p, FILE * fp, int spaces )
1008
{
1009
  print_spaces(fp,spaces);
1010
  fprintf(fp,"<point type=\"302\"");
1011
  garmin_print_dtime(p->time,fp,"time");
1012
  garmin_print_dpos(&p->posn,fp);
1013
  garmin_print_dfloat32(p->alt,fp,"alt");
1014
  garmin_print_dfloat32(p->dpth,fp,"depth");
1015
  garmin_print_dfloat32(p->temp,fp,"temperature");
1016
  if ( p->new_trk != 0 ) {
1017
    fprintf(fp," new=\"true\"");
1018
  }
1019
  fprintf(fp,"/>\n");
1020
 
1021
}
1022
 
1023
 
1024
/* --------------------------------------------------------------------------*/
1025
/* 7.4.25  D303                                                              */
1026
/* --------------------------------------------------------------------------*/
1027
 
1028
static void
1029
garmin_print_d303 ( D303 * p, FILE * fp, int spaces )
1030
{
1031
  print_spaces(fp,spaces);
1032
  fprintf(fp,"<point type=\"303\"");
1033
  garmin_print_dtime(p->time,fp,"time");
1034
  garmin_print_dpos(&p->posn,fp);
1035
  garmin_print_dfloat32(p->alt,fp,"alt");
1036
  if ( p->heart_rate != 0 ) {
1037
    fprintf(fp," hr=\"%d\"",p->heart_rate);
1038
  }
1039
  fprintf(fp,"/>\n");
1040
}
1041
 
1042
 
1043
/* --------------------------------------------------------------------------*/
1044
/* 7.4.26  D304                                                              */
1045
/* --------------------------------------------------------------------------*/
1046
 
1047
static void
1048
garmin_print_d304 ( D304 * p, FILE * fp, int spaces )
1049
{
1050
  print_spaces(fp,spaces);
1051
  fprintf(fp,"<point type=\"304\"");
1052
  garmin_print_dtime(p->time,fp,"time");
1053
  garmin_print_dpos(&p->posn,fp);
1054
  garmin_print_dfloat32(p->alt,fp,"alt");
1055
  garmin_print_dfloat32(p->distance,fp,"distance");
1056
  if ( p->heart_rate != 0 ) {
1057
    fprintf(fp," hr=\"%d\"", p->heart_rate);
1058
  }
1059
  if ( p->cadence != 0xff ) {
1060
    fprintf(fp, " cadence=\"%d\"", p->cadence);
1061
  }
1062
  if ( p->sensor != 0 ) {
1063
    fprintf(fp, " sensor=\"true\"");
1064
  }
1065
  fprintf(fp,"/>\n");
1066
}
1067
 
1068
 
1069
/* --------------------------------------------------------------------------*/
1070
/* 7.4.27  D310                                                              */
1071
/* --------------------------------------------------------------------------*/
1072
 
1073
static void
1074
garmin_print_d310 ( D310 * x, FILE * fp, int spaces )
1075
{
1076
  print_spaces(fp,spaces);
1077
  fprintf(fp,"<track type=\"310\" ident=\"%s\" color=\"%s\" "
1078
	  "display=\"%s\"/>\n",
1079
	  x->trk_ident,garmin_d108_color(x->color),
1080
	  (x->dspl) ? "true" : "false");
1081
}
1082
 
1083
 
1084
/* --------------------------------------------------------------------------*/
1085
/* 7.4.28  D311                                                              */
1086
/* --------------------------------------------------------------------------*/
1087
 
1088
static void
1089
garmin_print_d311 ( D311 * h, FILE * fp, int spaces )
1090
{
1091
  print_spaces(fp,spaces);
1092
  fprintf(fp,"<track type=\"311\" index=\"%d\"/>\n",h->index);
1093
}
1094
 
1095
 
1096
/* --------------------------------------------------------------------------*/
1097
/* 7.4.29  D312                                                              */
1098
/* --------------------------------------------------------------------------*/
1099
 
1100
GARMIN_ENUM_NAME(312,color) {
1101
  GARMIN_ENUM_CASE(312,black);
1102
  GARMIN_ENUM_CASE(312,dark_red);
1103
  GARMIN_ENUM_CASE(312,dark_green);
1104
  GARMIN_ENUM_CASE(312,dark_yellow);
1105
  GARMIN_ENUM_CASE(312,dark_blue);
1106
  GARMIN_ENUM_CASE(312,dark_magenta);
1107
  GARMIN_ENUM_CASE(312,dark_cyan);
1108
  GARMIN_ENUM_CASE(312,light_gray);
1109
  GARMIN_ENUM_CASE(312,dark_gray);
1110
  GARMIN_ENUM_CASE(312,red);
1111
  GARMIN_ENUM_CASE(312,green);
1112
  GARMIN_ENUM_CASE(312,yellow);
1113
  GARMIN_ENUM_CASE(312,blue);
1114
  GARMIN_ENUM_CASE(312,magenta);
1115
  GARMIN_ENUM_CASE(312,cyan);
1116
  GARMIN_ENUM_CASE(312,white);
1117
  GARMIN_ENUM_CASE(312,transparent);
1118
  GARMIN_ENUM_CASE(312,default_color);
1119
  GARMIN_ENUM_DEFAULT;
1120
}
1121
 
1122
 
1123
static void
1124
garmin_print_d312 ( D312 * h,
1125
		    FILE *              fp,
1126
		    int                 spaces )
1127
{
1128
  print_spaces(fp,spaces);
1129
  fprintf(fp,"<track type=\"312\" ident=\"%s\" color=\"%s\" "
1130
	  "display=\"%s\"/>\n",
1131
	  h->trk_ident,
1132
	  garmin_d312_color(h->color),
1133
	  (h->dspl) ? "true" : "false");
1134
}
1135
 
1136
 
1137
/* --------------------------------------------------------------------------*/
1138
/* 7.4.30  D400                                                              */
1139
/* --------------------------------------------------------------------------*/
1140
 
1141
static void
1142
garmin_print_d400 ( D400 * x, FILE * fp, int spaces )
1143
{
1144
  open_tag_with_type("proximity_waypoint",400,fp,spaces);
1145
  garmin_print_d100(&x->wpt,fp,spaces+1);
1146
  GARMIN_TAGF32(1,"distance",x->dst);
1147
  close_tag("proximity_waypoint",fp,spaces);
1148
}
1149
 
1150
 
1151
/* --------------------------------------------------------------------------*/
1152
/* 7.4.31  D403                                                              */
1153
/* --------------------------------------------------------------------------*/
1154
 
1155
static void
1156
garmin_print_d403 ( D403 * x, FILE * fp, int spaces )
1157
{
1158
  open_tag_with_type("proximity_waypoint",403,fp,spaces);
1159
  garmin_print_d103(&x->wpt,fp,spaces+1);
1160
  GARMIN_TAGF32(1,"distance",x->dst);
1161
  close_tag("proximity_waypoint",fp,spaces);
1162
}
1163
 
1164
 
1165
/* --------------------------------------------------------------------------*/
1166
/* 7.4.32  D450                                                              */
1167
/* --------------------------------------------------------------------------*/
1168
 
1169
static void
1170
garmin_print_d450 ( D450 * x, FILE * fp, int spaces )
1171
{
1172
  open_tag_with_type("proximity_waypoint",450,fp,spaces);
1173
  GARMIN_TAGINT(1,"index",x->idx);
1174
  garmin_print_d150(&x->wpt,fp,spaces+1);
1175
  GARMIN_TAGF32(1,"distance",x->dst);
1176
  close_tag("proximity_waypoint",fp,spaces);
1177
 
1178
}
1179
 
1180
 
1181
/* --------------------------------------------------------------------------*/
1182
/* 7.4.33  D500                                                              */
1183
/* --------------------------------------------------------------------------*/
1184
 
1185
static void
1186
garmin_print_d500 ( D500 * x, FILE * fp, int spaces )
1187
{
1188
  open_tag_with_type("almanac",500,fp,spaces);
1189
  GARMIN_TAGINT(1,"wn",x->wn);
1190
  GARMIN_TAGF32(1,"toa",x->toa);
1191
  GARMIN_TAGF32(1,"afo",x->af0);
1192
  GARMIN_TAGF32(1,"af1",x->af1);
1193
  GARMIN_TAGF32(1,"e",x->e);
1194
  GARMIN_TAGF32(1,"sqrta",x->sqrta);
1195
  GARMIN_TAGF32(1,"m0",x->m0);
1196
  GARMIN_TAGF32(1,"w",x->w);
1197
  GARMIN_TAGF32(1,"omg0",x->omg0);
1198
  GARMIN_TAGF32(1,"odot",x->odot);
1199
  GARMIN_TAGF32(1,"i",x->i);
1200
  close_tag("almanac",fp,spaces);
1201
}
1202
 
1203
 
1204
/* --------------------------------------------------------------------------*/
1205
/* 7.4.34  D501                                                              */
1206
/* --------------------------------------------------------------------------*/
1207
 
1208
static void
1209
garmin_print_d501 ( D501 * x, FILE * fp, int spaces )
1210
{
1211
  open_tag_with_type("almanac",501,fp,spaces);
1212
  GARMIN_TAGINT(1,"wn",x->wn);
1213
  GARMIN_TAGF32(1,"toa",x->toa);
1214
  GARMIN_TAGF32(1,"afo",x->af0);
1215
  GARMIN_TAGF32(1,"af1",x->af1);
1216
  GARMIN_TAGF32(1,"e",x->e);
1217
  GARMIN_TAGF32(1,"sqrta",x->sqrta);
1218
  GARMIN_TAGF32(1,"m0",x->m0);
1219
  GARMIN_TAGF32(1,"w",x->w);
1220
  GARMIN_TAGF32(1,"omg0",x->omg0);
1221
  GARMIN_TAGF32(1,"odot",x->odot);
1222
  GARMIN_TAGF32(1,"i",x->i);
1223
  GARMIN_TAGINT(1,"hlth",x->hlth);
1224
  close_tag("almanac",fp,spaces);
1225
}
1226
 
1227
 
1228
/* --------------------------------------------------------------------------*/
1229
/* 7.4.35  D550                                                              */
1230
/* --------------------------------------------------------------------------*/
1231
 
1232
static void
1233
garmin_print_d550 ( D550 * x, FILE * fp, int spaces )
1234
{
1235
  open_tag_with_type("almanac",550,fp,spaces);
1236
  GARMIN_TAGINT(1,"svid",x->svid);
1237
  GARMIN_TAGINT(1,"wn",x->wn);
1238
  GARMIN_TAGF32(1,"toa",x->toa);
1239
  GARMIN_TAGF32(1,"afo",x->af0);
1240
  GARMIN_TAGF32(1,"af1",x->af1);
1241
  GARMIN_TAGF32(1,"e",x->e);
1242
  GARMIN_TAGF32(1,"sqrta",x->sqrta);
1243
  GARMIN_TAGF32(1,"m0",x->m0);
1244
  GARMIN_TAGF32(1,"w",x->w);
1245
  GARMIN_TAGF32(1,"omg0",x->omg0);
1246
  GARMIN_TAGF32(1,"odot",x->odot);
1247
  GARMIN_TAGF32(1,"i",x->i);
1248
  close_tag("almanac",fp,spaces);
1249
}
1250
 
1251
 
1252
/* --------------------------------------------------------------------------*/
1253
/* 7.4.36  D551                                                              */
1254
/* --------------------------------------------------------------------------*/
1255
 
1256
static void
1257
garmin_print_d551 ( D551 * x, FILE * fp, int spaces )
1258
{
1259
  open_tag_with_type("almanac",551,fp,spaces);
1260
  GARMIN_TAGINT(1,"svid",x->svid);
1261
  GARMIN_TAGINT(1,"wn",x->wn);
1262
  GARMIN_TAGF32(1,"toa",x->toa);
1263
  GARMIN_TAGF32(1,"afo",x->af0);
1264
  GARMIN_TAGF32(1,"af1",x->af1);
1265
  GARMIN_TAGF32(1,"e",x->e);
1266
  GARMIN_TAGF32(1,"sqrta",x->sqrta);
1267
  GARMIN_TAGF32(1,"m0",x->m0);
1268
  GARMIN_TAGF32(1,"w",x->w);
1269
  GARMIN_TAGF32(1,"omg0",x->omg0);
1270
  GARMIN_TAGF32(1,"odot",x->odot);
1271
  GARMIN_TAGF32(1,"i",x->i);
1272
  GARMIN_TAGINT(1,"hlth",x->hlth);
1273
  close_tag("almanac",fp,spaces);
1274
}
1275
 
1276
 
1277
/* --------------------------------------------------------------------------*/
1278
/* 7.4.37  D600                                                              */
1279
/* --------------------------------------------------------------------------*/
1280
 
1281
static void
1282
garmin_print_d600 ( D600 * x, FILE * fp, int spaces )
1283
{
1284
  print_spaces(fp,spaces);
1285
  fprintf(fp,"<date_time type=\"600\">"
1286
	  "%04d-%02d-%02d %02d:%02d:%02d</date_time>\n",
1287
	  x->year,x->month,x->day,x->hour,x->minute,x->second);
1288
}
1289
 
1290
 
1291
/* --------------------------------------------------------------------------*/
1292
/* 7.4.38  D650                                                              */
1293
/* --------------------------------------------------------------------------*/
1294
 
1295
static void
1296
garmin_print_d650 ( D650 * x, FILE * fp, int spaces )
1297
{
1298
  open_tag("flightbook type=\"650\"",fp,spaces);
1299
  GARMIN_TAGU32(1,"takeoff_time",x->takeoff_time + TIME_OFFSET);
1300
  GARMIN_TAGU32(1,"landing_time",x->takeoff_time + TIME_OFFSET);
1301
  GARMIN_TAGPOS(1,"takeoff_position",x->takeoff_posn);
1302
  GARMIN_TAGPOS(1,"landing_position",x->takeoff_posn);
1303
  GARMIN_TAGU32(1,"night_time",x->night_time);
1304
  GARMIN_TAGU32(1,"num_landings",x->num_landings);
1305
  GARMIN_TAGF32(1,"max_speed",x->max_speed);
1306
  GARMIN_TAGF32(1,"max_alt",x->max_alt);
1307
  GARMIN_TAGF32(1,"distance",x->distance);
1308
  GARMIN_TAGSTR(1,"cross_country_flag",
1309
		(x->cross_country_flag != 0) ? "true" : "false");
1310
  GARMIN_TAGSTR(1,"departure_name",x->departure_name);
1311
  GARMIN_TAGSTR(1,"departure_ident",x->departure_ident);
1312
  GARMIN_TAGSTR(1,"arrival_name",x->arrival_name);
1313
  GARMIN_TAGSTR(1,"arrival_ident",x->arrival_ident);
1314
  GARMIN_TAGSTR(1,"ac_id",x->ac_id);
1315
  close_tag("flightbook",fp,spaces);
1316
}
1317
 
1318
 
1319
/* ------------------------------------------------------------------------- */
1320
/* 7.4.39  D700                                                              */
1321
/* ------------------------------------------------------------------------- */
1322
 
1323
static void
1324
garmin_print_d700 ( D700 * x, FILE * fp, int spaces )
1325
{
1326
  print_spaces(fp,spaces);
1327
  fprintf(fp,"<position type=\"700\" lat=\"%f\" lon=\"%f\"/>\n",
1328
	  RAD2DEG(x->lat),RAD2DEG(x->lon));
1329
}
1330
 
1331
 
1332
/* --------------------------------------------------------------------------*/
1333
/* 7.4.40  D800                                                              */
1334
/* --------------------------------------------------------------------------*/
1335
 
1336
 
1337
GARMIN_ENUM_NAME(800,fix) {
1338
  GARMIN_ENUM_CASE(800,unusable);
1339
  GARMIN_ENUM_CASE(800,invalid);
1340
  GARMIN_ENUM_CASE(800,2D);
1341
  GARMIN_ENUM_CASE(800,3D);
1342
  GARMIN_ENUM_CASE(800,2D_diff);
1343
  GARMIN_ENUM_CASE(800,3D_diff);
1344
  GARMIN_ENUM_DEFAULT;
1345
}
1346
 
1347
 
1348
static void
1349
garmin_print_d800 ( D800 * x, FILE * fp, int spaces )
1350
{
1351
  open_tag("pvt type=\"800\"",fp,spaces);
1352
  GARMIN_TAGF32(1,"alt",x->alt);
1353
  GARMIN_TAGF32(1,"epe",x->epe);
1354
  GARMIN_TAGF32(1,"eph",x->eph);
1355
  GARMIN_TAGF32(1,"epv",x->epv);
1356
  GARMIN_TAGSTR(1,"position_fix",garmin_d800_fix(x->fix));
1357
  garmin_print_d700(&x->posn,fp,spaces+1);
1358
  print_spaces(fp,spaces+1);
1359
  fprintf(fp,"<velocity east=\"");
1360
  garmin_print_float32(x->east,fp);
1361
  fprintf(fp,"\" north=\"");
1362
  garmin_print_float32(x->north,fp);
1363
  fprintf(fp,"\" up=\"");
1364
  garmin_print_float32(x->up,fp);
1365
  fprintf(fp,"\"/>\n");
1366
  GARMIN_TAGF32(1,"msl_height",x->msl_hght);
1367
  GARMIN_TAGINT(1,"leap_seconds",x->leap_scnds);
1368
  GARMIN_TAGU32(1,"week_number_days",x->wn_days);
1369
  GARMIN_TAGF64(1,"time_of_week",x->tow);
1370
  close_tag("pvt",fp,spaces);
1371
}
1372
 
1373
 
1374
/* --------------------------------------------------------------------------*/
1375
/* 7.4.41  D906                                                              */
1376
/* --------------------------------------------------------------------------*/
1377
 
1378
static void
1379
garmin_print_d906 ( D906 * x, FILE * fp, int spaces )
1380
{
1381
  print_spaces(fp,spaces);
1382
  fprintf(fp,"<lap type=\"906\"");
1383
  garmin_print_dtime(x->start_time,fp,"start");
1384
  garmin_print_ddist(x->total_time,x->total_distance,fp);
1385
  fprintf(fp,">\n");
1386
 
1387
  if ( x->begin.lat != 0x7fffffff && x->begin.lon != 0x7fffffff ) {
1388
    GARMIN_TAGPOS(1,"begin_pos",x->begin);
1389
  }
1390
  if ( x->end.lat != 0x7fffffff && x->end.lon != 0x7fffffff ) {
1391
    GARMIN_TAGPOS(1,"end_pos",x->end);
1392
  }
1393
 
1394
  GARMIN_TAGINT(1,"calories",x->calories);
1395
 
1396
  switch ( x->track_index ) {
1397
  case 0xff:
1398
    GARMIN_TAGSTR(1,"track_index","default");
1399
    break;
1400
  case 0xfe:
1401
  case 0xfd:
1402
    GARMIN_TAGSTR(1,"track_index","none");
1403
    break;
1404
  default:
1405
    GARMIN_TAGINT(1,"track_index",x->track_index);
1406
    break;
1407
  }
1408
 
1409
  close_tag("lap",fp,spaces);
1410
}
1411
 
1412
 
1413
/* --------------------------------------------------------------------------*/
1414
/* 7.4.42  D1000                                                             */
1415
/* --------------------------------------------------------------------------*/
1416
 
1417
 
1418
static void garmin_print_d1002 ( D1002 * x, FILE * fp, int spaces );
1419
 
1420
 
1421
GARMIN_ENUM_NAME(1000,sport_type) {
1422
  GARMIN_ENUM_CASE(1000,running);
1423
  GARMIN_ENUM_CASE(1000,biking);
1424
  GARMIN_ENUM_CASE(1000,other);
1425
  GARMIN_ENUM_DEFAULT;
1426
}
1427
 
1428
 
1429
GARMIN_ENUM_NAME(1000,program_type) {
1430
  GARMIN_ENUM_CASE(1000,none);
1431
  GARMIN_ENUM_CASE(1000,virtual_partner);
1432
  GARMIN_ENUM_CASE(1000,workout);
1433
  GARMIN_ENUM_DEFAULT;
1434
}
1435
 
1436
 
1437
static void
1438
garmin_print_d1000 ( D1000 * x, FILE * fp, int spaces )
1439
{
1440
  print_spaces(fp,spaces);
1441
  fprintf(fp,"<run type=\"1000\" track=\"%d\" sport=\"%s\">\n",
1442
	  x->track_index,garmin_d1000_sport_type(x->sport_type));
1443
  print_spaces(fp,spaces+1);
1444
  fprintf(fp,"<laps first=\"%u\" last=\"%u\"/>\n",
1445
	  x->first_lap_index, x->last_lap_index);
1446
  GARMIN_TAGSTR(1,"program_type",
1447
		garmin_d1000_program_type(x->program_type));
1448
  if ( x->program_type == D1000_virtual_partner ) {
1449
    print_spaces(fp,spaces+1);
1450
    fprintf(fp,"<virtual_partner time=\"%u\" distance=\"%f\"/>\n",
1451
	    x->virtual_partner.time, x->virtual_partner.distance);
1452
  }
1453
  if ( x->program_type == D1000_workout ) {
1454
    garmin_print_d1002(&x->workout,fp,spaces+1);
1455
  }
1456
  close_tag("run",fp,spaces);
1457
 
1458
  garmin_print_d1002(&x->workout,fp,spaces+1);
1459
}
1460
 
1461
 
1462
/* --------------------------------------------------------------------------*/
1463
/* 7.4.43  D1001                                                             */
1464
/* --------------------------------------------------------------------------*/
1465
 
1466
 
1467
GARMIN_ENUM_NAME(1001,intensity) {
1468
  GARMIN_ENUM_CASE(1001,active);
1469
  GARMIN_ENUM_CASE(1001,rest);
1470
  GARMIN_ENUM_DEFAULT;
1471
}
1472
 
1473
 
1474
static void
1475
garmin_print_d1001 ( D1001 * x, FILE * fp, int spaces )
1476
{
1477
  print_spaces(fp,spaces);
1478
  fprintf(fp,"<lap type=\"1001\" index=\"%d\"",x->index);
1479
  garmin_print_dtime(x->start_time,fp,"start");
1480
  garmin_print_ddist(x->total_time,x->total_dist,fp);
1481
  fprintf(fp,">\n");
1482
  if ( x->begin.lat != 0x7fffffff && x->begin.lon != 0x7fffffff ) {
1483
    GARMIN_TAGPOS(1,"begin_pos",x->begin);
1484
  }
1485
  if ( x->end.lat != 0x7fffffff && x->end.lon != 0x7fffffff ) {
1486
    GARMIN_TAGPOS(1,"end_pos",x->end);
1487
  }
1488
  GARMIN_TAGF32(1,"max_speed",x->max_speed);
1489
  GARMIN_TAGINT(1,"calories",x->calories);
1490
  if ( x->avg_heart_rate != 0 ) {
1491
    GARMIN_TAGINT(1,"avg_hr",x->avg_heart_rate);
1492
  }
1493
  if ( x->max_heart_rate != 0 ) {
1494
    GARMIN_TAGINT(1,"max_hr",x->max_heart_rate);
1495
  }
1496
  GARMIN_TAGSTR(1,"intensity",garmin_d1001_intensity(x->intensity));
1497
  close_tag("lap",fp,spaces);  
1498
}
1499
 
1500
 
1501
/* --------------------------------------------------------------------------*/
1502
/* 7.4.44  D1002                                                             */
1503
/* --------------------------------------------------------------------------*/
1504
 
1505
 
1506
GARMIN_ENUM_NAME(1002,duration_type) {
1507
  GARMIN_ENUM_CASE(1002,time);
1508
  GARMIN_ENUM_CASE(1002,distance);
1509
  GARMIN_ENUM_CASE(1002,heart_rate_less_than);
1510
  GARMIN_ENUM_CASE(1002,heart_rate_greater_than);
1511
  GARMIN_ENUM_CASE(1002,calories_burned);
1512
  GARMIN_ENUM_CASE(1002,open);
1513
  GARMIN_ENUM_CASE(1002,repeat);
1514
  GARMIN_ENUM_DEFAULT;
1515
}
1516
 
1517
 
1518
static void
1519
garmin_print_d1002 ( D1002 * x, FILE * fp, int spaces )
1520
{
1521
  int i;
1522
 
1523
  print_spaces(fp,spaces);
1524
  fprintf(fp,"<workout type=\"1002\" name=\"%s\" steps=\"%d\" "
1525
	  "sport_type=\"%s\"",
1526
	  x->name,x->num_valid_steps,garmin_d1000_sport_type(x->sport_type));
1527
  if ( x->num_valid_steps > 0 ) {
1528
    fprintf(fp,">\n");
1529
    for ( i = 0; i < x->num_valid_steps; i++ ) {
1530
      print_spaces(fp,spaces+1);
1531
      fprintf(fp,"<step name=\"%s\">\n",x->steps[i].custom_name);
1532
      GARMIN_TAGSTR(1,"intensity",
1533
		    garmin_d1001_intensity(x->steps[i].intensity));
1534
      print_spaces(fp,spaces+1);
1535
      fprintf(fp,"<duration type=\"%s\">%d</duration>\n",
1536
	      garmin_d1002_duration_type(x->steps[i].duration_type),
1537
	      x->steps[i].duration_value);
1538
      print_spaces(fp,spaces+1);
1539
      if ( x->steps[i].duration_type == D1002_repeat ) {
1540
	switch ( x->steps[i].target_type ) {
1541
	case 0:
1542
	  fprintf(fp,"<target type=\"speed_zone\" "
1543
		  "value=\"%d\" low=\"%f m/s\" high=\"%f m/s\"/>\n",
1544
		  x->steps[i].target_value,
1545
		  x->steps[i].target_custom_zone_low,
1546
		  x->steps[i].target_custom_zone_high);
1547
	  break;
1548
	case 1:
1549
	  fprintf(fp,"<target type=\"heart_rate_zone\" "
1550
		  "value=\"%d\" low=\"%f%s\" high=\"%f%s\"/>\n",
1551
		  x->steps[i].target_value,
1552
		  x->steps[i].target_custom_zone_low,
1553
		  (x->steps[i].target_custom_zone_low <= 100) ? "%" : " bpm",
1554
		  x->steps[i].target_custom_zone_high,
1555
		  (x->steps[i].target_custom_zone_high <= 100) ? "%" : " bpm");
1556
	  break;
1557
	case 2:
1558
	  fprintf(fp,"<target type=\"open\"/>\n");
1559
	  break;
1560
	default:
1561
	  break;
1562
	}
1563
      } else {
1564
	fprintf(fp,"<target type=\"repetitions\" value=\"%d\"/>\n",
1565
		x->steps[i].target_value);
1566
      }
1567
      close_tag("step",fp,spaces+1);
1568
    }
1569
    close_tag("workout",fp,spaces);
1570
  } else {
1571
    fprintf(fp,"/>\n");
1572
  }
1573
}
1574
 
1575
 
1576
/* --------------------------------------------------------------------------*/
1577
/* 7.4.45  D1003                                                             */
1578
/* --------------------------------------------------------------------------*/
1579
 
1580
static void
1581
garmin_print_d1003 ( D1003 * x, FILE * fp, int spaces )
1582
{
1583
  print_spaces(fp,spaces);
1584
  fprintf(fp,"<workout_occurrence type=\"1003\" name=\"%s\" day=\"%u\"/>\n",
1585
	  x->workout_name,x->day);
1586
}
1587
 
1588
 
1589
/* --------------------------------------------------------------------------*/
1590
/* 7.4.46  D1004                                                             */
1591
/* --------------------------------------------------------------------------*/
1592
 
1593
static void
1594
garmin_print_d1004 ( D1004 *  d, FILE * fp, int spaces )
1595
{
1596
  int i;
1597
  int j;
1598
 
1599
  print_spaces(fp,spaces);
1600
  fprintf(fp,
1601
	  "<fitness_user_profile type=\"1004\" weight=\"%f\" "
1602
	  "birth_date=\"%04d-%02d-%02d\" gender=\"%s\">\n",
1603
	  d->weight,
1604
	  d->birth_year,
1605
	  d->birth_month,
1606
	  d->birth_day,
1607
	  (d->gender == D1004_male) ? "male" : "female");
1608
  open_tag("activities",fp,spaces+1);
1609
  for ( i = 0; i < 3; i++ ) {
1610
    print_spaces(fp,spaces+2);
1611
    fprintf(fp,"<activity gear_weight=\"%f\" max_hr=\"%d\">\n",
1612
	    d->activities[i].gear_weight,
1613
	    d->activities[i].max_heart_rate);
1614
    open_tag("hr_zones",fp,spaces+3);
1615
    for ( j = 0; j < 5; j++ ) {
1616
      print_spaces(fp,spaces+4);
1617
      fprintf(fp,"<hr_zone low=\"%d\" high=\"%d\"/>\n",
1618
	      d->activities[i].heart_rate_zones[j].low_heart_rate,
1619
	      d->activities[i].heart_rate_zones[j].high_heart_rate);
1620
    }
1621
    close_tag("hr_zones",fp,spaces+3);
1622
    open_tag("speed_zones",fp,spaces+3);
1623
    for ( j = 0; j < 10; j++ ) {
1624
      print_spaces(fp,spaces+4);
1625
      fprintf(fp,"<speed_zone low=\"%f\" high=\"%f\" name=\"%s\"/>\n",
1626
	      d->activities[i].speed_zones[j].low_speed,
1627
	      d->activities[i].speed_zones[j].high_speed,
1628
	      d->activities[i].speed_zones[j].name);
1629
    }
1630
    close_tag("speed_zones",fp,spaces+3);
1631
    close_tag("activity",fp,spaces+2);
1632
  }
1633
  close_tag("activities",fp,spaces+1);
1634
  close_tag("fitness_user_profile",fp,spaces);
1635
}
1636
 
1637
 
1638
/* --------------------------------------------------------------------------*/
1639
/* 7.4.47  D1005                                                             */
1640
/* --------------------------------------------------------------------------*/
1641
 
1642
static void
1643
garmin_print_d1005 ( D1005 * limits, FILE * fp, int spaces )
1644
{
1645
  print_spaces(fp,spaces);
1646
  fprintf(fp,
1647
	  "<workout_limits type=\"1005\" workouts=\"%d\" unscheduled=\"%d\" "
1648
	  "occurrences=\"%d\"/>\n",
1649
	  limits->max_workouts,
1650
	  limits->max_unscheduled_workouts,
1651
	  limits->max_occurrences);
1652
}
1653
 
1654
 
1655
/* --------------------------------------------------------------------------*/
1656
/* 7.4.48  D1006                                                             */
1657
/* --------------------------------------------------------------------------*/
1658
 
1659
static void
1660
garmin_print_d1006 ( D1006 * x, FILE * fp, int spaces )
1661
{
1662
  print_spaces(fp,spaces);
1663
  fprintf(fp,"<course type=\"1006\" index=\"%d\" name=\"%s\" "
1664
	  "track_index=\"%d\"/>\n",
1665
	  x->index,
1666
	  x->course_name,
1667
	  x->track_index);
1668
}
1669
 
1670
 
1671
/* --------------------------------------------------------------------------*/
1672
/* 7.4.49  D1007                                                             */
1673
/* --------------------------------------------------------------------------*/
1674
 
1675
static void
1676
garmin_print_d1007 ( D1007 * x, FILE * fp, int spaces )
1677
{
1678
  print_spaces(fp,spaces);
1679
  fprintf(fp,"<course_lap type=\"1007\" course_index=\"%d\" lap_index=\"%d\"",
1680
	  x->course_index,
1681
	  x->lap_index);
1682
  garmin_print_ddist(x->total_time,x->total_dist,fp);
1683
  fprintf(fp,">\n");
1684
  if ( x->begin.lat != 0x7fffffff && x->begin.lon != 0x7fffffff ) {
1685
    GARMIN_TAGPOS(1,"begin_pos",x->begin);
1686
  }
1687
  if ( x->end.lat != 0x7fffffff && x->end.lon != 0x7fffffff ) {
1688
    GARMIN_TAGPOS(1,"end_pos",x->end);
1689
  }
1690
  if ( x->avg_heart_rate != 0 ) GARMIN_TAGINT(1,"avg_hr",x->avg_heart_rate);
1691
  if ( x->max_heart_rate != 0 ) GARMIN_TAGINT(1,"max_hr",x->max_heart_rate);
1692
  if ( x->avg_cadence != 0xff ) GARMIN_TAGINT(1,"avg_cadence",x->avg_cadence);
1693
  GARMIN_TAGSTR(1,"intensity",garmin_d1001_intensity(x->intensity));
1694
 
1695
  close_tag("course_lap",fp,spaces);
1696
}
1697
 
1698
 
1699
/* --------------------------------------------------------------------------*/
1700
/* 7.4.50  D1008                                                             */
1701
/* --------------------------------------------------------------------------*/
1702
 
1703
 
1704
static void
1705
garmin_print_d1008 ( D1008 * w, FILE * fp, int spaces )
1706
{
1707
  /* For some reason, D1008 is identical to D1002. */
1708
 
1709
  garmin_print_d1002((D1002 *)w,fp,spaces);
1710
}
1711
 
1712
 
1713
/* --------------------------------------------------------------------------*/
1714
/* 7.4.51  D1009                                                             */
1715
/* --------------------------------------------------------------------------*/
1716
 
1717
 
1718
GARMIN_ENUM_NAME(1009,multisport) {
1719
  GARMIN_ENUM_CASE(1009,no);
1720
  GARMIN_ENUM_CASE(1009,yes);
1721
  GARMIN_ENUM_CASE(1009,yesAndLastInGroup);
1722
  GARMIN_ENUM_DEFAULT;
1723
}
1724
 
1725
 
1726
static void
1727
garmin_print_d1009 ( D1009 * run, FILE * fp, int spaces )
1728
{
1729
  int npt = 0;
1730
 
1731
  print_spaces(fp,spaces);
1732
  fprintf(fp,"<run type=\"1009\" track=\"%d\" sport=\"%s\" "
1733
	  "multisport=\"%s\">\n",
1734
	  run->track_index,garmin_d1000_sport_type(run->sport_type),
1735
	  garmin_d1009_multisport(run->multisport));
1736
  print_spaces(fp,spaces+1);
1737
  fprintf(fp,"<laps first=\"%u\" last=\"%u\"/>\n",
1738
	  run->first_lap_index, run->last_lap_index);
1739
 
1740
  if ( run->program_type != 0 ) {
1741
    print_spaces(fp,spaces+1);
1742
    fprintf(fp,"<program_type>");
1743
    if ( run->program_type & 0x01 ) {
1744
      fprintf(fp,"%s%s",(npt++) ? ", " : "", "virtual_partner");
1745
    }
1746
    if ( run->program_type & 0x02 ) {
1747
      fprintf(fp,"%s%s",(npt++) ? ", " : "", "workout");
1748
    }
1749
    if ( run->program_type & 0x04 ) {
1750
      fprintf(fp,"%s%s",(npt++) ? ", " : "", "quick_workout");
1751
    } 
1752
    if ( run->program_type & 0x08 ) {
1753
      fprintf(fp,"%s%s",(npt++) ? ", " : "", "course");
1754
    }
1755
    if ( run->program_type & 0x10 ) {
1756
      fprintf(fp,"%s%s",(npt++) ? ", " : "", "interval_workout");
1757
    }
1758
    if ( run->program_type & 0x20 ) {
1759
      fprintf(fp,"%s%s",(npt++) ? ", " : "", "auto_multisport");
1760
    }
1761
    fprintf(fp,"</program_type>\n");
1762
  }  
1763
 
1764
  if ( run->program_type & 0x02 ) {
1765
    print_spaces(fp,spaces+1);
1766
    fprintf(fp,"<quick_workout time=\"%u\" distance=\"%f\"/>\n",
1767
	    run->quick_workout.time, run->quick_workout.distance);
1768
  }
1769
 
1770
  if ( run->program_type & 0x01 ) {
1771
    garmin_print_d1008(&run->workout,fp,spaces+1);
1772
  }
1773
 
1774
  close_tag("run",fp,spaces);
1775
}
1776
 
1777
 
1778
/* --------------------------------------------------------------------------*/
1779
/* 7.4.52  D1010                                                             */
1780
/* --------------------------------------------------------------------------*/
1781
 
1782
 
1783
GARMIN_ENUM_NAME(1010,program_type) {
1784
  GARMIN_ENUM_CASE(1010,none);
1785
  GARMIN_ENUM_CASE(1010,virtual_partner);
1786
  GARMIN_ENUM_CASE(1010,workout);
1787
  GARMIN_ENUM_CASE(1010,auto_multisport);
1788
  GARMIN_ENUM_DEFAULT;
1789
}
1790
 
1791
 
1792
static void
1793
garmin_print_d1010 ( D1010 * x, FILE * fp, int spaces )
1794
{
1795
  print_spaces(fp,spaces);
1796
  fprintf(fp,"<run type=\"1010\" track=\"%d\" sport=\"%s\" "
1797
	  "multisport=\"%s\">\n",
1798
	  x->track_index,garmin_d1000_sport_type(x->sport_type),
1799
	  garmin_d1009_multisport(x->multisport));
1800
  print_spaces(fp,spaces+1);
1801
  fprintf(fp,"<laps first=\"%u\" last=\"%u\"/>\n",
1802
	  x->first_lap_index, x->last_lap_index);
1803
  GARMIN_TAGSTR(1,"program_type",
1804
		garmin_d1010_program_type(x->program_type));
1805
  if ( x->program_type == D1010_virtual_partner ) {
1806
    print_spaces(fp,spaces+1);
1807
    fprintf(fp,"<virtual_partner time=\"%u\" distance=\"%f\"/>\n",
1808
	    x->virtual_partner.time, x->virtual_partner.distance);
1809
  }
1810
  garmin_print_d1002(&x->workout,fp,spaces+1);
1811
  close_tag("run",fp,spaces);
1812
}
1813
 
1814
 
1815
/* --------------------------------------------------------------------------*/
1816
/* 7.4.53  D1011                                                             */
1817
/* --------------------------------------------------------------------------*/
1818
 
1819
 
1820
GARMIN_ENUM_NAME(1011,trigger_method) {
1821
  GARMIN_ENUM_CASE(1011,manual);
1822
  GARMIN_ENUM_CASE(1011,distance);
1823
  GARMIN_ENUM_CASE(1011,location);
1824
  GARMIN_ENUM_CASE(1011,time);
1825
  GARMIN_ENUM_CASE(1011,heart_rate);
1826
  GARMIN_ENUM_DEFAULT;
1827
}
1828
 
1829
 
1830
static void
1831
garmin_print_d1011 ( D1011 * lap, FILE * fp, int spaces )
1832
{
1833
  print_spaces(fp,spaces);
1834
  fprintf(fp,"<lap type=\"1011\" index=\"%d\"",lap->index);
1835
  garmin_print_dtime(lap->start_time,fp,"start");
1836
  garmin_print_ddist(lap->total_time,lap->total_dist,fp);
1837
  fprintf(fp," trigger=\"%s\">\n",
1838
	  garmin_d1011_trigger_method(lap->trigger_method));
1839
  if ( lap->begin.lat != 0x7fffffff && lap->begin.lon != 0x7fffffff ) {
1840
    GARMIN_TAGPOS(1,"begin_pos",lap->begin);
1841
  }
1842
  if ( lap->end.lat != 0x7fffffff && lap->end.lon != 0x7fffffff ) {
1843
    GARMIN_TAGPOS(1,"end_pos",lap->end);
1844
  }
1845
  GARMIN_TAGF32(1,"max_speed",lap->max_speed);
1846
  GARMIN_TAGINT(1,"calories",lap->calories);
1847
  if ( lap->avg_heart_rate != 0 ) {
1848
    GARMIN_TAGINT(1,"avg_hr",lap->avg_heart_rate);
1849
  }
1850
  if ( lap->max_heart_rate != 0 ) {
1851
    GARMIN_TAGINT(1,"max_hr",lap->max_heart_rate);
1852
  }
1853
  if ( lap->avg_cadence != 0xff ) {
1854
    GARMIN_TAGINT(1,"avg_cadence",lap->avg_cadence);
1855
  }
1856
  GARMIN_TAGSTR(1,"intensity",garmin_d1001_intensity(lap->intensity));
1857
  close_tag("lap",fp,spaces);
1858
}
1859
 
1860
 
1861
/* --------------------------------------------------------------------------*/
1862
/* 7.4.54  D1012                                                             */
1863
/* --------------------------------------------------------------------------*/
1864
 
1865
 
1866
GARMIN_ENUM_NAME(1012,point_type) {
1867
  GARMIN_ENUM_CASE(1012,generic);
1868
  GARMIN_ENUM_CASE(1012,summit);
1869
  GARMIN_ENUM_CASE(1012,valley);
1870
  GARMIN_ENUM_CASE(1012,water);
1871
  GARMIN_ENUM_CASE(1012,food);
1872
  GARMIN_ENUM_CASE(1012,danger);
1873
  GARMIN_ENUM_CASE(1012,left);
1874
  GARMIN_ENUM_CASE(1012,right);
1875
  GARMIN_ENUM_CASE(1012,straight);
1876
  GARMIN_ENUM_CASE(1012,first_aid);
1877
  GARMIN_ENUM_CASE(1012,fourth_category);
1878
  GARMIN_ENUM_CASE(1012,third_category);
1879
  GARMIN_ENUM_CASE(1012,second_category);
1880
  GARMIN_ENUM_CASE(1012,first_category);
1881
  GARMIN_ENUM_CASE(1012,hors_category);
1882
  GARMIN_ENUM_CASE(1012,sprint);
1883
  GARMIN_ENUM_DEFAULT;
1884
}
1885
 
1886
 
1887
static void
1888
garmin_print_d1012 ( D1012 * x, FILE * fp, int spaces )
1889
{
1890
  print_spaces(fp,spaces);
1891
  fprintf(fp,"<course_point type=\"1012\" course_index=\"%d\" "
1892
	  "name=\"%s\" type=\"%s\">\n",
1893
	  x->course_index,x->name,
1894
	  garmin_d1012_point_type(x->point_type));
1895
  GARMIN_TAGU32(1,"track_point_time",x->track_point_time);
1896
  close_tag("course_point",fp,spaces);
1897
}
1898
 
1899
 
1900
/* --------------------------------------------------------------------------*/
1901
/* 7.4.55  D1013                                                             */
1902
/* --------------------------------------------------------------------------*/
1903
 
1904
static void
1905
garmin_print_d1013 ( D1013 * x, FILE * fp, int spaces )
1906
{
1907
  print_spaces(fp,spaces);
1908
  fprintf(fp,"<course_limits type=\"1013\" courses=\"%d\" laps=\"%d\" "
1909
	  "points=\"%d\" track_points=\"%d\"/>\n",
1910
	  x->max_courses,
1911
	  x->max_course_laps,
1912
	  x->max_course_pnt,
1913
	  x->max_course_trk_pnt);
1914
}
1915
 
1916
 
1917
/* --------------------------------------------------------------------------*/
1918
/* 7.4.XX  D1015 (Undocumented)                                              */
1919
/* --------------------------------------------------------------------------*/
1920
 
1921
static void
1922
garmin_print_d1015 ( D1015 * lap, FILE * fp, int spaces )
1923
{
1924
  print_spaces(fp,spaces);
1925
  fprintf(fp,"<lap type=\"1011\" index=\"%d\"",lap->index);
1926
  garmin_print_dtime(lap->start_time,fp,"start");
1927
  garmin_print_ddist(lap->total_time,lap->total_dist,fp);
1928
  fprintf(fp," trigger=\"%s\">\n",
1929
	  garmin_d1011_trigger_method(lap->trigger_method));
1930
  if ( lap->begin.lat != 0x7fffffff && lap->begin.lon != 0x7fffffff ) {
1931
    GARMIN_TAGPOS(1,"begin_pos",lap->begin);
1932
  }
1933
  if ( lap->end.lat != 0x7fffffff && lap->end.lon != 0x7fffffff ) {
1934
    GARMIN_TAGPOS(1,"end_pos",lap->end);
1935
  }
1936
  GARMIN_TAGF32(1,"max_speed",lap->max_speed);
1937
  GARMIN_TAGINT(1,"calories",lap->calories);
1938
  if ( lap->avg_heart_rate != 0 ) {
1939
    GARMIN_TAGINT(1,"avg_hr",lap->avg_heart_rate);
1940
  }
1941
  if ( lap->max_heart_rate != 0 ) {
1942
    GARMIN_TAGINT(1,"max_hr",lap->max_heart_rate);
1943
  }
1944
  if ( lap->avg_cadence != 0xff ) {
1945
    GARMIN_TAGINT(1,"avg_cadence",lap->avg_cadence);
1946
  }
1947
  GARMIN_TAGSTR(1,"intensity",garmin_d1001_intensity(lap->intensity));
1948
  GARMIN_TAGU8B(1,"unknown",lap->unknown,5);  
1949
  close_tag("lap",fp,spaces);
1950
}
1951
 
1952
 
1953
/* ========================================================================= */
1954
/* garmin_print_data                                                         */
1955
/* ========================================================================= */
1956
 
1957
void
1958
garmin_print_data ( garmin_data * d, FILE * fp, int spaces )
1959
{
1960
#define CASE_PRINT(x) \
1961
  case data_D##x: garmin_print_d##x(d->data,fp,spaces); break
1962
 
1963
  switch ( d->type ) {
1964
  CASE_PRINT(list);
1965
  CASE_PRINT(100);
1966
  CASE_PRINT(101);
1967
  CASE_PRINT(102);
1968
  CASE_PRINT(103);
1969
  CASE_PRINT(104);
1970
  CASE_PRINT(105);
1971
  CASE_PRINT(106);
1972
  CASE_PRINT(107);
1973
  CASE_PRINT(108);
1974
  CASE_PRINT(109);
1975
  CASE_PRINT(110);
1976
  CASE_PRINT(120);
1977
  CASE_PRINT(150);
1978
  CASE_PRINT(151);
1979
  CASE_PRINT(152);
1980
  CASE_PRINT(154);
1981
  CASE_PRINT(155);
1982
  CASE_PRINT(200);
1983
  CASE_PRINT(201);
1984
  CASE_PRINT(202);
1985
  CASE_PRINT(210);
1986
  CASE_PRINT(300);
1987
  CASE_PRINT(301);
1988
  CASE_PRINT(302);
1989
  CASE_PRINT(303);
1990
  CASE_PRINT(304);
1991
  CASE_PRINT(310);
1992
  CASE_PRINT(311);
1993
  CASE_PRINT(312);
1994
  CASE_PRINT(400);
1995
  CASE_PRINT(403);
1996
  CASE_PRINT(450);
1997
  CASE_PRINT(500);
1998
  CASE_PRINT(501);
1999
  CASE_PRINT(550);
2000
  CASE_PRINT(551);
2001
  CASE_PRINT(600);
2002
  CASE_PRINT(650);
2003
  CASE_PRINT(700);
2004
  CASE_PRINT(800);
2005
  CASE_PRINT(906);
2006
  CASE_PRINT(1000);
2007
  CASE_PRINT(1001);
2008
  CASE_PRINT(1002);
2009
  CASE_PRINT(1003);
2010
  CASE_PRINT(1004);
2011
  CASE_PRINT(1005);
2012
  CASE_PRINT(1006);
2013
  CASE_PRINT(1007);
2014
  CASE_PRINT(1008);
2015
  CASE_PRINT(1009);
2016
  CASE_PRINT(1010);
2017
  CASE_PRINT(1011);
2018
  CASE_PRINT(1012);
2019
  CASE_PRINT(1013);
2020
  CASE_PRINT(1015);
2021
  default:
2022
    print_spaces(fp,spaces);
2023
    fprintf(fp,"<data type=\"%d\"/>\n",d->type);
2024
    break;
2025
  }
2026
 
2027
#undef CASE_PRINT
2028
}
2029
 
2030
 
2031
/* ========================================================================= */
2032
/* garmin_print_protocols                                                    */
2033
/* ========================================================================= */
2034
 
2035
void
2036
garmin_print_protocols ( garmin_unit * garmin, FILE * fp, int spaces )
2037
{
2038
#define PROTO1_AND_DATA(x)                                                \
2039
  do {                                                                    \
2040
    if ( garmin->protocol.x != appl_Anil ) {                              \
2041
      print_spaces(fp,spaces+1);                                          \
2042
      fprintf(fp,"<garmin_" #x                                            \
2043
	      " protocol=\"A%03d\" " #x "=\"D%03d\"/>\n",                 \
2044
	      garmin->protocol.x, garmin->datatype.x);                    \
2045
    }                                                                     \
2046
  } while ( 0 )
2047
 
2048
#define PROTO2_AND_DATA(x,y)                                              \
2049
  do {                                                                    \
2050
    if ( garmin->protocol.x.y != appl_Anil ) {                            \
2051
      print_spaces(fp,spaces+2);                                          \
2052
      fprintf(fp,"<garmin_" #x "_" #y                                     \
2053
	      " protocol=\"A%03d\" " #y "=\"D%03d\"/>\n",                 \
2054
	      garmin->protocol.x.y, garmin->datatype.x.y);                \
2055
    }                                                                     \
2056
  } while ( 0 )
2057
 
2058
  open_tag("garmin_protocols",fp,spaces);
2059
 
2060
  /* Physical */
2061
 
2062
  print_spaces(fp,spaces+1);
2063
  fprintf(fp,"<garmin_physical protocol=\"P%03d\"/>\n",
2064
	  garmin->protocol.physical);
2065
 
2066
  /* Link */
2067
 
2068
  print_spaces(fp,spaces+1);
2069
  fprintf(fp,"<garmin_link protocol=\"L%03d\"/>\n",
2070
	  garmin->protocol.link);
2071
 
2072
  /* Command */
2073
 
2074
  print_spaces(fp,spaces+1);
2075
  fprintf(fp,"<garmin_command protocol=\"A%03d\"/>\n",
2076
	  garmin->protocol.command);
2077
 
2078
  /* Waypoint */
2079
 
2080
  if ( garmin->protocol.waypoint.waypoint  != appl_Anil ||
2081
       garmin->protocol.waypoint.category  != appl_Anil ||
2082
       garmin->protocol.waypoint.proximity != appl_Anil ) {
2083
    open_tag("garmin_waypoint",fp,spaces+1);
2084
    PROTO2_AND_DATA(waypoint,waypoint);
2085
    PROTO2_AND_DATA(waypoint,category);
2086
    PROTO2_AND_DATA(waypoint,proximity);
2087
    close_tag("garmin_waypoint",fp,spaces+1);
2088
  }
2089
 
2090
  /* Route */
2091
 
2092
  if ( garmin->protocol.route != appl_Anil ) {
2093
    print_spaces(fp,spaces+1);
2094
    fprintf(fp,"<garmin_route protocol=\"A%03d\"",
2095
	    garmin->protocol.route);
2096
    if ( garmin->datatype.route.header != data_Dnil ) {
2097
      fprintf(fp," header=\"D%03d\"",
2098
	      garmin->datatype.route.header);
2099
    }
2100
    if ( garmin->datatype.route.waypoint != data_Dnil ) {
2101
      fprintf(fp," waypoint=\"D%03d\"",
2102
	      garmin->datatype.route.waypoint);
2103
    }
2104
    if ( garmin->datatype.route.link != data_Dnil ) {
2105
      fprintf(fp," link=\"D%03d\"",
2106
	      garmin->datatype.route.link);
2107
    }
2108
    fprintf(fp,"/>\n");
2109
  }
2110
 
2111
  /* Track */
2112
 
2113
  if ( garmin->protocol.track != appl_Anil ) {
2114
    print_spaces(fp,spaces+1);
2115
    fprintf(fp,"<garmin_track protocol=\"A%03d\"",
2116
	    garmin->protocol.track);
2117
    if ( garmin->datatype.track.header != data_Dnil ) {
2118
      fprintf(fp," header=\"D%03d\"",
2119
	      garmin->datatype.track.header);
2120
    }
2121
    if ( garmin->datatype.track.data != data_Dnil ) {
2122
      fprintf(fp," data=\"D%03d\"",
2123
	      garmin->datatype.track.data);
2124
    }
2125
    fprintf(fp,"/>\n");
2126
  }
2127
 
2128
  /* Almanac, Date/Time, FlightBook, Position, PVT, Lap, Run */
2129
 
2130
  PROTO1_AND_DATA(almanac);
2131
  PROTO1_AND_DATA(date_time);
2132
  PROTO1_AND_DATA(flightbook);
2133
  PROTO1_AND_DATA(position);
2134
  PROTO1_AND_DATA(pvt);
2135
  PROTO1_AND_DATA(lap);
2136
  PROTO1_AND_DATA(run);
2137
 
2138
  /* Workout */
2139
 
2140
  if ( garmin->protocol.workout.workout     != appl_Anil ||
2141
       garmin->protocol.workout.occurrence  != appl_Anil ||
2142
       garmin->protocol.workout.limits      != appl_Anil ) {
2143
    open_tag("garmin_workout",fp,spaces+1);
2144
    PROTO2_AND_DATA(workout,workout);
2145
    PROTO2_AND_DATA(workout,occurrence);
2146
    PROTO2_AND_DATA(workout,limits);
2147
    close_tag("garmin_workout",fp,spaces+1);
2148
  }
2149
 
2150
  /* Fitness user profile */
2151
 
2152
  PROTO1_AND_DATA(fitness);
2153
 
2154
  /* Course */
2155
 
2156
  if ( garmin->protocol.course.course != appl_Anil ||
2157
       garmin->protocol.course.lap    != appl_Anil ||
2158
       garmin->protocol.course.track  != appl_Anil ||
2159
       garmin->protocol.course.point  != appl_Anil ||
2160
       garmin->protocol.course.limits != appl_Anil ) {
2161
    open_tag("garmin_course",fp,spaces+1);
2162
    PROTO2_AND_DATA(course,course);
2163
    PROTO2_AND_DATA(course,lap);
2164
 
2165
    if ( garmin->protocol.course.track != appl_Anil ) {
2166
      print_spaces(fp,spaces+2);
2167
      fprintf(fp,"<garmin_course_track protocol=\"A%03d\"",
2168
	      garmin->protocol.course.track);
2169
      if ( garmin->datatype.course.track.header != data_Dnil ) {
2170
	fprintf(fp," header=\"D%03d\"",
2171
		garmin->datatype.course.track.header);
2172
      }
2173
      if ( garmin->datatype.course.track.data != data_Dnil ) {
2174
	fprintf(fp," data=\"D%03d\"",
2175
		garmin->datatype.course.track.data);
2176
      }
2177
      close_tag("garmin_course_track",fp,spaces+1);      
2178
    }
2179
 
2180
    PROTO2_AND_DATA(course,point);
2181
    PROTO2_AND_DATA(course,limits);
2182
    close_tag("garmin_course",fp,spaces+1);
2183
  }
2184
 
2185
  /* All done. */
2186
 
2187
  close_tag("garmin_protocols",fp,spaces);
2188
 
2189
#undef PROTO1_AND_DATA
2190
#undef PROTO2_AND_DATA
2191
}
2192
 
2193
 
2194
void
2195
garmin_print_info ( garmin_unit * unit, FILE * fp, int spaces )
2196
{
2197
  char ** s;
2198
 
2199
  print_spaces(fp,spaces);
2200
  fprintf(fp,"<garmin_unit id=\"%x\">\n",unit->id);
2201
  print_spaces(fp,spaces+1);
2202
  fprintf(fp,"<garmin_product id=\"%d\" software_version=\"%.2f\">\n",
2203
	  unit->product.product_id,unit->product.software_version/100.0);
2204
  GARMIN_TAGSTR(2,"product_description",unit->product.product_description);
2205
  if ( unit->product.additional_data != NULL ) {
2206
    open_tag("additional_data_list",fp,spaces+2);
2207
    for ( s = unit->product.additional_data; s != NULL && *s != NULL; s++ ) {
2208
      GARMIN_TAGSTR(3,"additional_data",*s);
2209
    }
2210
    close_tag("additional_data_list",fp,spaces+2);
2211
  }
2212
  close_tag("garmin_product",fp,spaces+1);
2213
  if ( unit->extended.ext_data != NULL ) {
2214
    open_tag("extended_data_list",fp,spaces+1);
2215
    for ( s = unit->extended.ext_data; s != NULL && *s != NULL; s++ ) {
2216
      GARMIN_TAGSTR(2,"extended_data",*s);
2217
    }
2218
    close_tag("extended_data_list",fp,spaces+1);
2219
  }  
2220
  garmin_print_protocols(unit,fp,spaces+1);
2221
  close_tag("garmin_unit",fp,spaces);
2222
}
2223