forked from GPSBabel/gpsbabel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
garmin_fit.cc
750 lines (682 loc) · 23.2 KB
/
garmin_fit.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
/*
Support for FIT track files.
Copyright (C) 2011 Paul Brook, [email protected]
Copyright (C) 2003-2011 Robert Lipe, [email protected]
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
*/
#include "defs.h"
#include <cstdio>
#define MYNAME "fit"
// constants for global IDs
const int kIdDeviceSettings = 0;
const int kIdLap = 19;
const int kIdRecord = 20;
// constants for message fields
// for all global IDs
const int kFieldTimestamp = 253;
// for global ID: device settings
const int kFieldGlobalUtcOffset = 4;
// for global ID: lap
const int kFieldStartTime = 2;
const int kFieldStartLatitude = 3;
const int kFieldStartLongitude = 4;
const int kFieldEndLatitude = 5;
const int kFieldEndLongitude = 6;
const int kFieldElapsedTime = 7;
const int kFieldTotalDistance = 9;
// for global ID: record
const int kFieldLatitude = 0;
const int kFieldLongitude = 1;
const int kFieldAltitude = 2;
const int kFieldHeartRate = 3;
const int kFieldCadence = 4;
const int kFieldDistance = 5;
const int kFieldSpeed = 6;
const int kFieldPower = 7;
const int kFieldTemperature = 13;
const int kFieldEnhancedSpeed = 73;
const int kFieldEnhancedAltitude = 78;
// For developer fields as a non conflicting id
const int kFieldInvalid = 255;
static char* opt_allpoints = nullptr;
static int lap_ct = 0;
static
arglist_t fit_args[] = {
{
"allpoints", &opt_allpoints,
"Read all points even if latitude or longitude is missing",
nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr
},
ARG_TERMINATOR
};
typedef struct {
int id;
int size;
int type;
} fit_field_t;
typedef struct {
int endian;
int global_id;
int num_fields;
fit_field_t* fields;
} fit_message_def;
static struct {
int len;
int endian;
route_head* track;
uint32_t last_timestamp;
uint32_t global_utc_offset;
fit_message_def message_def[16];
} fit_data;
static gbfile* fin;
/*******************************************************************************
* %%% global callbacks called by gpsbabel main process %%% *
*******************************************************************************/
static void
fit_rd_init(const QString& fname)
{
fin = gbfopen_le(fname, "rb", MYNAME);
}
static void
fit_rd_deinit()
{
for (int local_id = 0; local_id<16; local_id++) {
fit_message_def* def = &fit_data.message_def[local_id];
if (def->fields) {
xfree(def->fields);
def->fields = nullptr;
}
}
gbfclose(fin);
}
/*******************************************************************************
* fit_parse_header- parse the global FIT header
*******************************************************************************/
static void
fit_parse_header()
{
char sig[4];
int len = gbfgetc(fin);
if (len == EOF || len < 12) {
fatal(MYNAME ": Bad header\n");
}
if (global_opts.debug_level >= 1) {
debug_print(1,"%s: header len=%d\n", MYNAME, len);
}
int ver = gbfgetc(fin);
if (ver == EOF || (ver >> 4) > 2)
fatal(MYNAME ": Unsupported protocol version %d.%d\n",
ver >> 4, ver & 0xf);
if (global_opts.debug_level >= 1) {
debug_print(1,"%s: protocol version=%d\n", MYNAME, ver);
}
// profile version
ver = gbfgetuint16(fin);
// data length
fit_data.len = gbfgetuint32(fin);
// File signature
is_fatal(gbfread(sig, 4, 1, fin) != 1,
MYNAME ": Unexpected end of file\n");
if (sig[0] != '.' || sig[1] != 'F' || sig[2] != 'I' || sig[3] != 'T') {
fatal(MYNAME ": .FIT signature missing\n");
}
if (global_opts.debug_level >= 1) {
debug_print(1,"%s: profile version=%d\n", MYNAME, ver);
debug_print(1,"%s: fit_data.len=%d\n", MYNAME, fit_data.len);
}
if (len > 12) {
// Unused according to Ingo Arndt
gbfgetuint16(fin);
}
fit_data.global_utc_offset = 0;
}
static uint8_t
fit_getuint8()
{
if (fit_data.len == 0) {
// fail gracefully for GARMIN Edge 800 with newest firmware, seems to write a wrong record length
// for the last record.
//fatal(MYNAME ": record truncated: fit_data.len=0\n");
if (global_opts.debug_level >= 1) {
warning("%s: record truncated: fit_data.len=0\n", MYNAME);
}
return 0;
}
int val = gbfgetc(fin);
if (val == EOF) {
fatal(MYNAME ": unexpected end of file with fit_data.len=%d\n",fit_data.len);
}
fit_data.len--;
return (uint8_t)val;
}
static uint16_t
fit_getuint16()
{
char buf[2];
if (fit_data.len < 2) {
fatal(MYNAME ": record truncated: expecting char[2], but only got %d\n",fit_data.len);
}
is_fatal(gbfread(buf, 2, 1, fin) != 1,
MYNAME ": unexpected end of file with fit_data.len=%d\n",fit_data.len);
fit_data.len -= 2;
if (fit_data.endian) {
return be_read16(buf);
} else {
return le_read16(buf);
}
}
static uint32_t
fit_getuint32()
{
char buf[4];
if (fit_data.len < 4) {
fatal(MYNAME ": record truncated: expecting char[4], but only got %d\n",fit_data.len);
}
is_fatal(gbfread(buf, 4, 1, fin) != 1,
MYNAME ": unexpected end of file with fit_data.len=%d\n",fit_data.len);
fit_data.len -= 4;
if (fit_data.endian) {
return be_read32(buf);
} else {
return le_read32(buf);
}
}
static void
fit_parse_definition_message(uint8_t header)
{
int local_id = header & 0x0f;
fit_message_def* def = &fit_data.message_def[local_id];
if (def->fields) {
xfree(def->fields);
}
// first byte is reserved. It's usually 0 and we don't know what it is,
// but we've seen some files that are 0x40. So we just read it and toss it.
int i = fit_getuint8();
// second byte is endianness
def->endian = fit_getuint8();
if (def->endian > 1) {
fatal(MYNAME ": Bad endian field\n");
}
fit_data.endian = def->endian;
// next two bytes are the global message number
def->global_id = fit_getuint16();
// byte 5 has the number of records in the remainder of the definition message
def->num_fields = fit_getuint8();
if (global_opts.debug_level >= 8) {
debug_print(8,"%s: definition message contains %d records\n",MYNAME, def->num_fields);
}
if (def->num_fields == 0) {
def->fields = (fit_field_t*) xmalloc(sizeof(fit_field_t));
}
// remainder of the definition message is data at one byte per field * 3 fields
if (def->num_fields > 0) {
def->fields = (fit_field_t*) xmalloc(def->num_fields * sizeof(fit_field_t));
for (i = 0; i < def->num_fields; i++) {
def->fields[i].id = fit_getuint8();
def->fields[i].size = fit_getuint8();
def->fields[i].type = fit_getuint8();
if (global_opts.debug_level >= 8) {
debug_print(8,"%s: record %d ID: %d SIZE: %d TYPE: %d fit_data.len=%d\n",
MYNAME, i, def->fields[i].id, def->fields[i].size, def->fields[i].type,fit_data.len);
}
}
}
// If we have developer fields (since version 2.0) they must be read too
// These is one byte containing the number of fields and 3 bytes for every field.
// So this is identical to the normal fields but the meaning of the content is different.
//
// Currently we just want to ignore the developer fields because they are not meant
// to hold relevant data we need (currently handle) for the conversion.
// For simplicity using the existing infrastructure we do it in the following way:
// * We read it in as normal fields
// * We set the field id to kFieldInvalid so that it do not interfere with valid id's from
// the normal fields.
// -In our opinion in practice this will not happen, because we do not expect
// developer fields e.g. inside lap or record records. But we want to be safe here.
// * We do not have to change the type as we did for the id above, because fit_read_field()
// already uses the size information to read the data, if the type does not match the size.
//
// If we want to change this or if we want to avoid the xrealloc call, we can change
// it in the future by e.g. extending the fit_message_def struct.
// Bit 5 of the header specify if we have developer fields in the data message
bool hasDevFields = static_cast<bool>(header & 0x20);
if (hasDevFields) {
int numOfDevFields = fit_getuint8();
if (global_opts.debug_level >= 8) {
debug_print(8,"%s: definition message contains %d developer records\n",MYNAME, numOfDevFields);
}
if (numOfDevFields == 0) {
return;
}
int numOfFields = def->num_fields+numOfDevFields;
def->fields = (fit_field_t*) xrealloc(def->fields, numOfFields * sizeof(fit_field_t));
for (i = def->num_fields; i < numOfFields; i++) {
def->fields[i].id = fit_getuint8();
def->fields[i].size = fit_getuint8();
def->fields[i].type = fit_getuint8();
if (global_opts.debug_level >= 8) {
debug_print(8,"%s: developer record %d ID: %d SIZE: %d TYPE: %d fit_data.len=%d\n",
MYNAME, i-def->num_fields, def->fields[i].id, def->fields[i].size, def->fields[i].type,fit_data.len);
}
// Because we parse developer fields like normal fields and we do not want
// that the field id interfere which valid id's from the normal fields
def->fields[i].id = kFieldInvalid;
}
def->num_fields = numOfFields;
}
return;
}
static uint32_t
fit_read_field(fit_field_t* f)
{
/* https://forums.garmin.com/showthread.php?223645-Vivoactive-problems-plus-suggestions-for-future-firmwares&p=610929#post610929
* Per section 4.2.1.4.2 of the FIT Protocol the size of a field may be a
* multiple of the size of the underlying type, indicating the field
* contains multiple elements represented as an array.
*
* Garmin Product Support
*/
// In the case that the field contains one value of the indicated type we return that value,
// otherwise we just skip over the data.
int i;
if (global_opts.debug_level >= 8) {
debug_print(8,"%s: fit_read_field: read data field with f->type=0x%X and f->size=%d fit_data.len=%d\n",
MYNAME, f->type, f->size, fit_data.len);
}
switch (f->type) {
case 1: // sint8
case 2: // uint8
if (f->size == 1) {
return fit_getuint8();
} else { // ignore array data
for (i = 0; i < f->size; i++) {
fit_getuint8();
}
if (global_opts.debug_level >= 8) {
debug_print(8, "%s: fit_read_field: skipping 1-byte array data\n", MYNAME);
}
return -1;
}
case 0x83: // sint16
case 0x84: // uint16
if (f->size == 2) {
return fit_getuint16();
} else { // ignore array data
for (i = 0; i < f->size; i++) {
fit_getuint8();
}
if (global_opts.debug_level >= 8) {
debug_print(8, "%s: fit_read_field: skipping 2-byte array data\n", MYNAME);
}
return -1;
}
case 0x85: // sint32
case 0x86: // uint32
if (f->size == 4) {
return fit_getuint32();
} else { // ignore array data
for (i = 0; i < f->size; i++) {
fit_getuint8();
}
if (global_opts.debug_level >= 8) {
debug_print(8, "%s: fit_read_field: skipping 4-byte array data\n", MYNAME);
}
return -1;
}
default: // Ignore everything else for now.
for (i = 0; i < f->size; i++) {
fit_getuint8();
}
if (global_opts.debug_level >= 8) {
debug_print(8, "%s: fit_read_field: skipping unrecognized data type\n", MYNAME);
}
return -1;
}
}
static void
fit_parse_data(fit_message_def* def, int time_offset)
{
uint32_t timestamp = fit_data.last_timestamp + time_offset;
int32_t lat = 0x7fffffff;
int32_t lon = 0x7fffffff;
uint16_t alt = 0xffff;
uint16_t speed = 0xffff;
uint8_t heartrate = 0xff;
uint8_t cadence = 0xff;
uint16_t power = 0xffff;
int8_t temperature = 0x7f;
Waypoint* waypt;
int32_t startlat = 0x7fffffff;
int32_t startlon = 0x7fffffff;
int32_t endlat = 0x7fffffff;
int32_t endlon = 0x7fffffff;
uint32_t starttime = 0; // ??? default ?
char cbuf[10];
Waypoint* lappt; // WptPt in gpx
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: parsing fit data ID %d with num_fields=%d\n", MYNAME, def->global_id, def->num_fields);
}
for (int i = 0; i < def->num_fields; i++) {
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: parsing field %d\n", MYNAME, i);
}
fit_field_t* f = &def->fields[i];
uint32_t val = fit_read_field(f);
if (f->id == kFieldTimestamp) {
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: parsing fit data: timestamp=%d\n", MYNAME, val);
}
timestamp = val;
// if the timestamp is < 0x10000000, this value represents
// system time; to convert it to UTC, add the global utc offset to it
if (timestamp < 0x10000000)
timestamp += fit_data.global_utc_offset;
fit_data.last_timestamp = timestamp;
} else {
switch (def->global_id) {
case kIdDeviceSettings: // device settings message
switch (f->id) {
case kFieldGlobalUtcOffset:
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: parsing fit data: global utc_offset=%d\n", MYNAME, val);
}
fit_data.global_utc_offset = val;
break;
default:
if (global_opts.debug_level >= 1) {
debug_print(1, "%s: unrecognized data type in GARMIN FIT device settings: f->id=%d\n", MYNAME, f->id);
}
break;
} // switch (f->id)
// end of case def->global_id = kIdDeviceSettings
break;
case kIdRecord: // record message - trkType is a track
switch (f->id) {
case kFieldLatitude:
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: parsing fit data: lat=%d\n", MYNAME, val);
}
lat = val;
break;
case kFieldLongitude:
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: parsing fit data: lon=%d\n", MYNAME, val);
}
lon = val;
break;
case kFieldAltitude:
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: parsing fit data: alt=%d\n", MYNAME, val);
}
alt = val;
break;
case kFieldHeartRate:
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: parsing fit data: heartrate=%d\n", MYNAME, val);
}
heartrate = val;
break;
case kFieldCadence:
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: parsing fit data: cadence=%d\n", MYNAME, val);
}
cadence = val;
break;
case kFieldDistance:
// NOTE: 5 is DISTANCE in cm ... unused.
if (global_opts.debug_level >= 7) {
debug_print(7, "%s: unrecognized data type in GARMIN FIT record: f->id=%d\n", MYNAME, f->id);
}
break;
case kFieldSpeed:
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: parsing fit data: speed=%d\n", MYNAME, val);
}
speed = val;
break;
case kFieldPower:
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: parsing fit data: power=%d\n", MYNAME, val);
}
power = val;
break;
case kFieldTemperature:
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: parsing fit data: temperature=%d\n", MYNAME, val);
}
temperature = val;
break;
case kFieldEnhancedSpeed:
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: parsing fit data: enhanced_speed=%d\n", MYNAME, val);
}
speed = val;
break;
case kFieldEnhancedAltitude:
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: parsing fit data: enhanced_altitude=%d\n", MYNAME, val);
}
alt = val;
break;
default:
if (global_opts.debug_level >= 1) {
debug_print(1, "%s: unrecognized data type in GARMIN FIT record: f->id=%d\n", MYNAME, f->id);
}
break;
} // switch (f->id)
// end of case def->global_id = kIdRecord
break;
case kIdLap: // lap wptType , endlat+lon is wpt
switch (f->id) {
case kFieldStartTime:
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: parsing fit data: starttime=%d\n", MYNAME, val);
}
starttime = val;
break;
case kFieldStartLatitude:
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: parsing fit data: startlat=%d\n", MYNAME, val);
}
startlat = val;
break;
case kFieldStartLongitude:
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: parsing fit data: startlon=%d\n", MYNAME, val);
}
startlon = val;
break;
case kFieldEndLatitude:
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: parsing fit data: endlat=%d\n", MYNAME, val);
}
endlat = val;
break;
case kFieldEndLongitude:
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: parsing fit data: endlon=%d\n", MYNAME, val);
}
endlon = val;
break;
case kFieldElapsedTime:
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: parsing fit data: elapsedtime=%d\n", MYNAME, val);
}
//elapsedtime = val;
break;
case kFieldTotalDistance:
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: parsing fit data: totaldistance=%d\n", MYNAME, val);
}
//totaldistance = val;
break;
default:
if (global_opts.debug_level >= 1) {
debug_print(1, "%s: unrecognized data type in GARMIN FIT lap: f->id=%d\n", MYNAME, f->id);
}
break;
} // switch (f->id)
// end of case def->global_id = kIdLap
break;
default:
if (global_opts.debug_level >= 1) {
debug_print(1, "%s: unrecognized/unhandled global ID for GARMIN FIT: %d\n", MYNAME, def->global_id);
}
break;
} // switch (def->global_id)
}
}
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: storing fit data with num_fields=%d\n", MYNAME, def->num_fields);
}
switch (def->global_id) {
case kIdLap: // lap message
if (endlat == 0x7fffffff || endlon == 0x7fffffff) {
break;
}
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: storing fit data LAP %d\n", MYNAME, def->global_id);
}
lappt = new Waypoint;
lappt->latitude = (endlat / (double)0x7fffffff) * 180;
lappt->longitude = (endlon / (double)0x7fffffff) * 180;
lap_ct++;
snprintf(cbuf, sizeof(cbuf), "LAP%03d", lap_ct);
lappt->shortname = cbuf;
waypt_add(lappt);
break;
case kIdRecord: // record message
if ((lat == 0x7fffffff || lon == 0x7fffffff) && !opt_allpoints) {
break;
}
waypt = new Waypoint;
if (lat != 0x7fffffff) {
waypt->latitude = (lat / (double)0x7fffffff) * 180;
}
if (lon != 0x7fffffff) {
waypt->longitude = (lon / (double)0x7fffffff) * 180;
}
if (alt != 0xffff) {
waypt->altitude = (alt / 5.0) - 500;
}
waypt->SetCreationTime(QDateTime::fromTime_t(timestamp + 631065600));
if (speed != 0xffff) {
WAYPT_SET(waypt, speed, speed / 1000.0f);
}
if (heartrate != 0xff) {
waypt->heartrate = heartrate;
}
if (cadence != 0xff) {
waypt->cadence = cadence;
}
if (power != 0xffff) {
waypt->power = power;
}
if (temperature != 0x7f) {
WAYPT_SET(waypt, temperature, temperature);
}
track_add_wpt(fit_data.track, waypt);
break;
}
}
static void
fit_parse_data_message(uint8_t header)
{
int local_id = header & 0x1f;
fit_message_def* def = &fit_data.message_def[local_id];
fit_parse_data(def, 0);
}
static void
fit_parse_compressed_message(uint8_t header)
{
int local_id = (header >> 5) & 3;
fit_message_def* def = &fit_data.message_def[local_id];
fit_parse_data(def, header & 0x1f);
}
/*******************************************************************************
* fit_parse_record- parse each record in the file
*******************************************************************************/
static void
fit_parse_record()
{
uint8_t header = fit_getuint8();
// high bit 7 set -> compressed message (0 for normal)
// second bit 6 set -> 0 for data message, 1 for definition message
// bit 5 -> message type specific
// definition message: Bit set means that we have additional Developer Field definitions
// behind the field definitions inside the record content
// data message: currently not used
// bit 4 -> reserved
// bits 3..0 -> local message type
if (header & 0x80) {
if (global_opts.debug_level >= 6) {
debug_print(6,"%s: got compressed message at fit_data.len=%d", MYNAME, fit_data.len);
debug_print(0," ...local message type 0x%X\n", header&0x0f);
}
fit_parse_compressed_message(header);
} else if (header & 0x40) {
if (global_opts.debug_level >= 6) {
debug_print(6,"%s: got definition message at fit_data.len=%d", MYNAME, fit_data.len);
debug_print(0," ...local message type 0x%X\n", header&0x0f);
}
fit_parse_definition_message(header);
} else {
if (global_opts.debug_level >= 6) {
debug_print(6,"%s: got data message at fit_data.len=%d", MYNAME, fit_data.len);
debug_print(0," ...local message type 0x%X\n", header&0x0f);
}
fit_parse_data_message(header);
}
}
/*******************************************************************************
* fit_read- global entry point
* - parse the header
* - parse all the records in the file
*******************************************************************************/
static void
fit_read()
{
fit_parse_header();
fit_data.track = route_head_alloc();
track_add_head(fit_data.track);
if (global_opts.debug_level >= 1) {
debug_print(1,"%s: starting to read data with fit_data.len=%d\n", MYNAME, fit_data.len);
}
while (fit_data.len) {
fit_parse_record();
}
}
/**************************************************************************/
// capabilities below means: we can only read and write waypoints
// please change this depending on your new module
ff_vecs_t format_fit_vecs = {
ff_type_file,
{
ff_cap_none /* waypoints */,
ff_cap_read /* tracks */,
ff_cap_none /* routes */
},
fit_rd_init,
nullptr,
fit_rd_deinit,
nullptr,
fit_read,
nullptr,
nullptr,
fit_args,
CET_CHARSET_ASCII, 0 /* ascii is the expected character set */
/* not fixed, can be changed through command line parameter */
, NULL_POS_OPS,
nullptr
};
/**************************************************************************/