fit_parser 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fit_parser/file/data.rb +33 -36
- data/lib/fit_parser/file/definition.rb +10 -13
- data/lib/fit_parser/file/definitions.rb +588 -588
- data/lib/fit_parser/file/record.rb +6 -19
- data/lib/fit_parser/file/type.rb +12 -11
- data/lib/fit_parser/file/types.rb +84 -84
- data/lib/fit_parser/file.rb +4 -8
- data/lib/fit_parser/version.rb +1 -1
- data/lib/fit_parser.rb +1 -1
- data/spec/file/data_spec.rb +43 -25
- data/spec/file/definition_spec.rb +2 -2
- data/spec/file/definitions_spec.rb +21 -21
- data/spec/file/header_spec.rb +6 -6
- data/spec/file/record_header_spec.rb +2 -2
- data/spec/file/record_spec.rb +33 -44
- data/spec/file/type_spec.rb +15 -11
- data/spec/file/types_spec.rb +21 -17
- data/spec/fit_parser_spec.rb +14 -1
- data/spec/support/examples/file/3110334490 +0 -0
- data/spec/support/examples/file/3863374146 +0 -0
- metadata +26 -43
- data/.document +0 -5
- data/.rspec +0 -2
- data/Gemfile +0 -15
- data/Gemfile.lock +0 -105
- data/README.md +0 -11
- data/Rakefile +0 -38
@@ -1,41 +1,28 @@
|
|
1
1
|
module FitParser
|
2
2
|
class File
|
3
3
|
class Record
|
4
|
-
|
5
|
-
new.read(io)
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.clear_definitions!
|
9
|
-
@definitions = {}
|
10
|
-
end
|
4
|
+
attr_reader :header, :content, :definitions
|
11
5
|
|
12
|
-
def
|
13
|
-
@definitions =
|
6
|
+
def initialize(definitions)
|
7
|
+
@definitions = definitions
|
14
8
|
end
|
15
9
|
|
16
|
-
def self.definitions
|
17
|
-
@definitions
|
18
|
-
end
|
19
|
-
|
20
|
-
attr_reader :header, :content
|
21
|
-
|
22
10
|
def read(io)
|
23
11
|
@header = RecordHeader.read(io)
|
24
12
|
|
25
13
|
@content = case @header.message_type.snapshot
|
26
14
|
when 1
|
27
15
|
Definition.read(io).tap do |definition|
|
28
|
-
|
16
|
+
@definitions[@header.local_message_type.snapshot] = Data.generate(definition)
|
29
17
|
end
|
30
18
|
when 0
|
31
|
-
definition =
|
32
|
-
|
19
|
+
definition = @definitions[@header.local_message_type.snapshot]
|
20
|
+
fail "No definition for local message type: #{@header.local_message_type}" if definition.nil?
|
33
21
|
definition.read(io)
|
34
22
|
end
|
35
23
|
|
36
24
|
self
|
37
25
|
end
|
38
|
-
|
39
26
|
end
|
40
27
|
end
|
41
28
|
end
|
data/lib/fit_parser/file/type.rb
CHANGED
@@ -10,7 +10,7 @@ module FitParser
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.get_type(name)
|
13
|
-
return Type.types[name] if Type.types.
|
13
|
+
return Type.types[name] if Type.types.key?(name)
|
14
14
|
type = Types.get_type_definition name
|
15
15
|
Type.types[name] = type ? new(type) : nil
|
16
16
|
end
|
@@ -20,8 +20,8 @@ module FitParser
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def value(val)
|
23
|
-
return nil unless
|
24
|
-
if @type.
|
23
|
+
return nil unless valid?(val)
|
24
|
+
if @type.key?(:method)
|
25
25
|
Types.send(@type[:method], val, @type[:values], @type[:parameters])
|
26
26
|
else
|
27
27
|
values = @type[:values]
|
@@ -32,15 +32,16 @@ module FitParser
|
|
32
32
|
end
|
33
33
|
|
34
34
|
private
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
return false if val == invalid_value
|
42
|
-
true
|
35
|
+
|
36
|
+
def valid?(val)
|
37
|
+
if @type.key?(:invalid)
|
38
|
+
invalid_value = @type[:invalid]
|
39
|
+
else
|
40
|
+
invalid_value = Types.get_type_definition(@type[:basic_type])[:invalid]
|
43
41
|
end
|
42
|
+
return false if val == invalid_value
|
43
|
+
true
|
44
|
+
end
|
44
45
|
end
|
45
46
|
end
|
46
47
|
end
|
@@ -48,23 +48,23 @@ module FitParser
|
|
48
48
|
end
|
49
49
|
|
50
50
|
# basic types
|
51
|
-
FitParser::File::Types.add_type :enum, nil, :
|
52
|
-
FitParser::File::Types.add_type :sint8, nil, :
|
53
|
-
FitParser::File::Types.add_type :uint8, nil, :
|
54
|
-
FitParser::File::Types.add_type :sint16, nil, :
|
55
|
-
FitParser::File::Types.add_type :uint16, nil, :
|
56
|
-
FitParser::File::Types.add_type :sint32, nil, :
|
57
|
-
FitParser::File::Types.add_type :uint32, nil, :
|
58
|
-
FitParser::File::Types.add_type :string, nil, :
|
59
|
-
FitParser::File::Types.add_type :float32, nil, :
|
60
|
-
FitParser::File::Types.add_type :float64, nil, :
|
61
|
-
FitParser::File::Types.add_type :uint8z, nil, :
|
62
|
-
FitParser::File::Types.add_type :uint16z, nil, :
|
63
|
-
FitParser::File::Types.add_type :uint32z, nil, :
|
64
|
-
FitParser::File::Types.add_type :byte, nil, :
|
51
|
+
FitParser::File::Types.add_type :enum, nil, invalid: 0xFF
|
52
|
+
FitParser::File::Types.add_type :sint8, nil, invalid: 0x7F
|
53
|
+
FitParser::File::Types.add_type :uint8, nil, invalid: 0xFF
|
54
|
+
FitParser::File::Types.add_type :sint16, nil, invalid: 0x7FFF
|
55
|
+
FitParser::File::Types.add_type :uint16, nil, invalid: 0xFFFF
|
56
|
+
FitParser::File::Types.add_type :sint32, nil, invalid: 0x7FFFFFFF
|
57
|
+
FitParser::File::Types.add_type :uint32, nil, invalid: 0xFFFFFFFF
|
58
|
+
FitParser::File::Types.add_type :string, nil, invalid: 0x00
|
59
|
+
FitParser::File::Types.add_type :float32, nil, invalid: 0xFFFFFFFF
|
60
|
+
FitParser::File::Types.add_type :float64, nil, invalid: 0xFFFFFFFFFFFFFFFF
|
61
|
+
FitParser::File::Types.add_type :uint8z, nil, invalid: 0x00
|
62
|
+
FitParser::File::Types.add_type :uint16z, nil, invalid: 0x0000
|
63
|
+
FitParser::File::Types.add_type :uint32z, nil, invalid: 0x00000000
|
64
|
+
FitParser::File::Types.add_type :byte, nil, invalid: 0xFF
|
65
65
|
|
66
66
|
# derived types
|
67
|
-
FitParser::File::Types.add_type :file, :enum, :
|
67
|
+
FitParser::File::Types.add_type :file, :enum, values: {
|
68
68
|
1 => 'device',
|
69
69
|
2 => 'settings',
|
70
70
|
3 => 'sport',
|
@@ -80,7 +80,7 @@ FitParser::File::Types.add_type :file, :enum, :values => {
|
|
80
80
|
20 => 'activity_summary',
|
81
81
|
28 => 'monitoring_daily',
|
82
82
|
32 => 'monitoring_b' }
|
83
|
-
FitParser::File::Types.add_type :mesg_num, :uint16, :
|
83
|
+
FitParser::File::Types.add_type :mesg_num, :uint16, values: {
|
84
84
|
0 => 'file_id',
|
85
85
|
1 => 'capabilities',
|
86
86
|
2 => 'device_settings',
|
@@ -125,31 +125,31 @@ FitParser::File::Types.add_type :mesg_num, :uint16, :values => {
|
|
125
125
|
145 => 'memo_glob',
|
126
126
|
65280 => 'mfg_range_min',
|
127
127
|
65534 => 'mfg_range_max' }
|
128
|
-
FitParser::File::Types.add_type :checksum, :uint8, :
|
128
|
+
FitParser::File::Types.add_type :checksum, :uint8, values: {
|
129
129
|
0 => 'clear',
|
130
130
|
1 => 'ok' }
|
131
|
-
FitParser::File::Types.add_type :file_flags, :uint8z, :
|
131
|
+
FitParser::File::Types.add_type :file_flags, :uint8z, values: {
|
132
132
|
0x02 => 'read',
|
133
133
|
0x04 => 'write',
|
134
|
-
0x08 => 'erase' }, :
|
135
|
-
FitParser::File::Types.add_type :mesg_count, :enum, :
|
134
|
+
0x08 => 'erase' }, method: :bitfield_value
|
135
|
+
FitParser::File::Types.add_type :mesg_count, :enum, values: {
|
136
136
|
0 => 'num_per_file',
|
137
137
|
1 => 'max_per_file',
|
138
138
|
2 => 'max_per_file_type' }
|
139
|
-
FitParser::File::Types.add_type :date_time, :uint32, :
|
140
|
-
268435456 => 'min' }, :
|
141
|
-
FitParser::File::Types.add_type :local_date_time, :uint32, :
|
142
|
-
268435456 => 'min' }, :
|
143
|
-
FitParser::File::Types.add_type :message_index, :uint16, :
|
139
|
+
FitParser::File::Types.add_type :date_time, :uint32, values: {
|
140
|
+
268435456 => 'min' }, method: :date_time_value, parameters: {utc: true}
|
141
|
+
FitParser::File::Types.add_type :local_date_time, :uint32, values: {
|
142
|
+
268435456 => 'min' }, method: :date_time_value, parameters: {utc: false}
|
143
|
+
FitParser::File::Types.add_type :message_index, :uint16, values: {
|
144
144
|
32768 => 'selected',
|
145
145
|
26872 => 'reserved',
|
146
|
-
4095 => 'mask' }, :
|
147
|
-
FitParser::File::Types.add_type :device_index, :uint8, :
|
146
|
+
4095 => 'mask' }, method: :message_index_value
|
147
|
+
FitParser::File::Types.add_type :device_index, :uint8, values: {
|
148
148
|
0 => 'creator' }
|
149
|
-
FitParser::File::Types.add_type :gender, :enum, :
|
149
|
+
FitParser::File::Types.add_type :gender, :enum, values: {
|
150
150
|
0 => 'female',
|
151
151
|
1 => 'male' }
|
152
|
-
FitParser::File::Types.add_type :language, :enum, :
|
152
|
+
FitParser::File::Types.add_type :language, :enum, values: {
|
153
153
|
0 => 'english',
|
154
154
|
1 => 'french',
|
155
155
|
2 => 'italian',
|
@@ -177,7 +177,7 @@ FitParser::File::Types.add_type :language, :enum, :values => {
|
|
177
177
|
24 => 'bulgarian',
|
178
178
|
25 => 'romanian',
|
179
179
|
254 => 'custom' }
|
180
|
-
FitParser::File::Types.add_type :time_zone, :enum, :
|
180
|
+
FitParser::File::Types.add_type :time_zone, :enum, values: {
|
181
181
|
0 => 'almaty',
|
182
182
|
1 => 'bangkok',
|
183
183
|
2 => 'bombay',
|
@@ -284,17 +284,17 @@ FitParser::File::Types.add_type :time_zone, :enum, :values => {
|
|
284
284
|
103 => 'santiago',
|
285
285
|
253 => 'manual',
|
286
286
|
254 => 'automatic' }
|
287
|
-
FitParser::File::Types.add_type :display_measure, :enum, :
|
287
|
+
FitParser::File::Types.add_type :display_measure, :enum, values: {
|
288
288
|
0 => 'metric',
|
289
289
|
1 => 'statute' }
|
290
|
-
FitParser::File::Types.add_type :display_heart, :enum, :
|
290
|
+
FitParser::File::Types.add_type :display_heart, :enum, values: {
|
291
291
|
0 => 'bpm',
|
292
292
|
1 => 'max',
|
293
293
|
2 => 'reserve' }
|
294
|
-
FitParser::File::Types.add_type :display_power, :enum, :
|
294
|
+
FitParser::File::Types.add_type :display_power, :enum, values: {
|
295
295
|
0 => 'watts',
|
296
296
|
1 => 'percent_ftp' }
|
297
|
-
FitParser::File::Types.add_type :display_position, :enum, :
|
297
|
+
FitParser::File::Types.add_type :display_position, :enum, values: {
|
298
298
|
0 => 'degree',
|
299
299
|
1 => 'degree_minute',
|
300
300
|
2 => 'degree_minute_second',
|
@@ -337,7 +337,7 @@ FitParser::File::Types.add_type :display_position, :enum, :values => {
|
|
337
337
|
39 => 'estonian_grid',
|
338
338
|
40 => 'latvian_grid',
|
339
339
|
41 => 'swedish_ref_99_grid' }
|
340
|
-
FitParser::File::Types.add_type :sport, :enum, :
|
340
|
+
FitParser::File::Types.add_type :sport, :enum, values: {
|
341
341
|
0 => 'generic',
|
342
342
|
1 => 'running',
|
343
343
|
2 => 'cycling',
|
@@ -359,7 +359,7 @@ FitParser::File::Types.add_type :sport, :enum, :values => {
|
|
359
359
|
18 => 'multisport',
|
360
360
|
19 => 'paddling',
|
361
361
|
254 => 'all' }
|
362
|
-
FitParser::File::Types.add_type :sport_bits_0, :uint8z, :
|
362
|
+
FitParser::File::Types.add_type :sport_bits_0, :uint8z, values: {
|
363
363
|
1 => 'generic',
|
364
364
|
2 => 'running',
|
365
365
|
4 => 'cycling',
|
@@ -368,7 +368,7 @@ FitParser::File::Types.add_type :sport_bits_0, :uint8z, :values => {
|
|
368
368
|
32 => 'swimming',
|
369
369
|
64 => 'basketball',
|
370
370
|
128 => 'soccer' }
|
371
|
-
FitParser::File::Types.add_type :sport_bits_1, :uint8z, :
|
371
|
+
FitParser::File::Types.add_type :sport_bits_1, :uint8z, values: {
|
372
372
|
1 => 'tennis',
|
373
373
|
2 => 'american_football',
|
374
374
|
4 => 'training',
|
@@ -377,12 +377,12 @@ FitParser::File::Types.add_type :sport_bits_1, :uint8z, :values => {
|
|
377
377
|
32 => 'alpine_skiing',
|
378
378
|
64 => 'snowboarding',
|
379
379
|
128 => 'rowing' }
|
380
|
-
FitParser::File::Types.add_type :sport_bits_2, :uint8z, :
|
380
|
+
FitParser::File::Types.add_type :sport_bits_2, :uint8z, values: {
|
381
381
|
1 => 'mountaineering',
|
382
382
|
2 => 'hiking',
|
383
383
|
4 => 'multisport',
|
384
384
|
8 => 'paddling' }
|
385
|
-
FitParser::File::Types.add_type :sub_sport, :enum, :
|
385
|
+
FitParser::File::Types.add_type :sub_sport, :enum, values: {
|
386
386
|
0 => 'generic',
|
387
387
|
1 => 'treadmill',
|
388
388
|
2 => 'street',
|
@@ -411,20 +411,20 @@ FitParser::File::Types.add_type :sub_sport, :enum, :values => {
|
|
411
411
|
25 => 'indoor_skiing',
|
412
412
|
26 => 'cardio_training',
|
413
413
|
254 => 'all' }
|
414
|
-
FitParser::File::Types.add_type :activity, :enum, :
|
414
|
+
FitParser::File::Types.add_type :activity, :enum, values: {
|
415
415
|
0 => 'manual',
|
416
416
|
1 => 'auto_multi_sport' }
|
417
|
-
FitParser::File::Types.add_type :intensity, :enum, :
|
417
|
+
FitParser::File::Types.add_type :intensity, :enum, values: {
|
418
418
|
0 => 'active',
|
419
419
|
1 => 'rest',
|
420
420
|
2 => 'warmup',
|
421
421
|
3 => 'cooldown' }
|
422
|
-
FitParser::File::Types.add_type :session_trigger, :enum, :
|
422
|
+
FitParser::File::Types.add_type :session_trigger, :enum, values: {
|
423
423
|
0 => 'activity_end',
|
424
424
|
1 => 'manual',
|
425
425
|
2 => 'auto_multi_sport',
|
426
426
|
3 => 'fitness_equipment' }
|
427
|
-
FitParser::File::Types.add_type :autolap_trigger, :enum, :
|
427
|
+
FitParser::File::Types.add_type :autolap_trigger, :enum, values: {
|
428
428
|
0 => 'time',
|
429
429
|
1 => 'distance',
|
430
430
|
2 => 'position_start',
|
@@ -432,7 +432,7 @@ FitParser::File::Types.add_type :autolap_trigger, :enum, :values => {
|
|
432
432
|
4 => 'position_waypoint',
|
433
433
|
5 => 'position_marked',
|
434
434
|
6 => 'off' }
|
435
|
-
FitParser::File::Types.add_type :lap_trigger, :enum, :
|
435
|
+
FitParser::File::Types.add_type :lap_trigger, :enum, values: {
|
436
436
|
0 => 'manual',
|
437
437
|
1 => 'time',
|
438
438
|
2 => 'distance',
|
@@ -442,7 +442,7 @@ FitParser::File::Types.add_type :lap_trigger, :enum, :values => {
|
|
442
442
|
6 => 'position_marked',
|
443
443
|
7 => 'session_end',
|
444
444
|
8 => 'fitness_equipment' }
|
445
|
-
FitParser::File::Types.add_type :event, :enum, :
|
445
|
+
FitParser::File::Types.add_type :event, :enum, values: {
|
446
446
|
0 => 'timer',
|
447
447
|
3 => 'workout',
|
448
448
|
4 => 'workout_step',
|
@@ -477,7 +477,7 @@ FitParser::File::Types.add_type :event, :enum, :values => {
|
|
477
477
|
43 => 'rear_gear_change',
|
478
478
|
45 => 'elev_high_alert',
|
479
479
|
46 => 'elev_low_alert' }
|
480
|
-
FitParser::File::Types.add_type :event_type, :enum, :
|
480
|
+
FitParser::File::Types.add_type :event_type, :enum, values: {
|
481
481
|
0 => 'start',
|
482
482
|
1 => 'stop',
|
483
483
|
2 => 'consecutive_depreciated',
|
@@ -488,27 +488,27 @@ FitParser::File::Types.add_type :event_type, :enum, :values => {
|
|
488
488
|
7 => 'end_all_depreciated',
|
489
489
|
8 => 'stop_disable',
|
490
490
|
9 => 'stop_disable_all' }
|
491
|
-
FitParser::File::Types.add_type :timer_trigger, :enum, :
|
491
|
+
FitParser::File::Types.add_type :timer_trigger, :enum, values: {
|
492
492
|
0 => 'manual',
|
493
493
|
1 => 'auto',
|
494
494
|
2 => 'fitness_equipment' }
|
495
|
-
FitParser::File::Types.add_type :fitness_equipment_state, :enum, :
|
495
|
+
FitParser::File::Types.add_type :fitness_equipment_state, :enum, values: {
|
496
496
|
0 => 'ready',
|
497
497
|
1 => 'in_use',
|
498
498
|
2 => 'paused',
|
499
499
|
3 => 'unknown' }
|
500
|
-
FitParser::File::Types.add_type :activity_class, :enum, :
|
500
|
+
FitParser::File::Types.add_type :activity_class, :enum, values: {
|
501
501
|
127 => 'level',
|
502
502
|
100 => 'level_max',
|
503
503
|
128 => 'athlete' }
|
504
|
-
FitParser::File::Types.add_type :hr_zone_calc, :enum, :
|
504
|
+
FitParser::File::Types.add_type :hr_zone_calc, :enum, values: {
|
505
505
|
0 => 'custom',
|
506
506
|
1 => 'percent_max_hr',
|
507
507
|
2 => 'percent_hrr' }
|
508
|
-
FitParser::File::Types.add_type :pwr_zone_calc, :enum, :
|
508
|
+
FitParser::File::Types.add_type :pwr_zone_calc, :enum, values: {
|
509
509
|
0 => 'custom',
|
510
510
|
1 => 'percent_ftp' }
|
511
|
-
FitParser::File::Types.add_type :wkt_step_duration, :enum, :
|
511
|
+
FitParser::File::Types.add_type :wkt_step_duration, :enum, values: {
|
512
512
|
0 => 'time',
|
513
513
|
1 => 'distance',
|
514
514
|
2 => 'hr_less_than',
|
@@ -526,7 +526,7 @@ FitParser::File::Types.add_type :wkt_step_duration, :enum, :values => {
|
|
526
526
|
14 => 'power_less_than',
|
527
527
|
15 => 'power_greater_than',
|
528
528
|
28 => 'repetition_time' }
|
529
|
-
FitParser::File::Types.add_type :wkt_step_target, :enum, :
|
529
|
+
FitParser::File::Types.add_type :wkt_step_target, :enum, values: {
|
530
530
|
0 => 'speed',
|
531
531
|
1 => 'heart_rate',
|
532
532
|
2 => 'open',
|
@@ -534,23 +534,23 @@ FitParser::File::Types.add_type :wkt_step_target, :enum, :values => {
|
|
534
534
|
4 => 'power',
|
535
535
|
5 => 'grade',
|
536
536
|
6 => 'resistance' }
|
537
|
-
FitParser::File::Types.add_type :goal, :enum, :
|
537
|
+
FitParser::File::Types.add_type :goal, :enum, values: {
|
538
538
|
0 => 'time',
|
539
539
|
1 => 'distance',
|
540
540
|
2 => 'calories',
|
541
541
|
3 => 'frequency',
|
542
542
|
4 => 'steps' }
|
543
|
-
FitParser::File::Types.add_type :goal_recurrence, :enum, :
|
543
|
+
FitParser::File::Types.add_type :goal_recurrence, :enum, values: {
|
544
544
|
0 => 'off',
|
545
545
|
1 => 'daily',
|
546
546
|
2 => 'weekly',
|
547
547
|
3 => 'monthly',
|
548
548
|
4 => 'yearly',
|
549
549
|
5 => 'custom' }
|
550
|
-
FitParser::File::Types.add_type :schedule, :enum, :
|
550
|
+
FitParser::File::Types.add_type :schedule, :enum, values: {
|
551
551
|
0 => 'workout',
|
552
552
|
1 => 'course' }
|
553
|
-
FitParser::File::Types.add_type :course_point, :enum, :
|
553
|
+
FitParser::File::Types.add_type :course_point, :enum, values: {
|
554
554
|
0 => 'generic',
|
555
555
|
1 => 'summit',
|
556
556
|
2 => 'valley',
|
@@ -575,7 +575,7 @@ FitParser::File::Types.add_type :course_point, :enum, :values => {
|
|
575
575
|
21 => 'slight_right',
|
576
576
|
22 => 'sharp_right',
|
577
577
|
23 => 'u_turn' }
|
578
|
-
FitParser::File::Types.add_type :manufacturer, :uint16, :
|
578
|
+
FitParser::File::Types.add_type :manufacturer, :uint16, values: {
|
579
579
|
1 => 'garmin',
|
580
580
|
2 => 'garmin_fr405_antfs',
|
581
581
|
3 => 'zephyr',
|
@@ -671,7 +671,7 @@ FitParser::File::Types.add_type :manufacturer, :uint16, :values => {
|
|
671
671
|
258 => 'lezyne',
|
672
672
|
259 => 'scribe_labs',
|
673
673
|
5759 => 'actigraphcorp' }
|
674
|
-
FitParser::File::Types.add_type :garmin_product, :uint16, :
|
674
|
+
FitParser::File::Types.add_type :garmin_product, :uint16, values: {
|
675
675
|
1 => 'hrm1',
|
676
676
|
2 => 'axh01',
|
677
677
|
3 => 'axb01',
|
@@ -753,7 +753,7 @@ FitParser::File::Types.add_type :garmin_product, :uint16, :values => {
|
|
753
753
|
20119 => 'training_center',
|
754
754
|
65532 => 'android_antplus_plugin',
|
755
755
|
65534 => 'connect' }
|
756
|
-
FitParser::File::Types.add_type :antplus_device_type, :uint8, :
|
756
|
+
FitParser::File::Types.add_type :antplus_device_type, :uint8, values: {
|
757
757
|
1 => 'antfs',
|
758
758
|
11 => 'bike_power',
|
759
759
|
12 => 'environment_sensor_legacy',
|
@@ -771,12 +771,12 @@ FitParser::File::Types.add_type :antplus_device_type, :uint8, :values => {
|
|
771
771
|
122 => 'bike_cadence',
|
772
772
|
123 => 'bike_speed',
|
773
773
|
124 => 'stride_speed_distance' }
|
774
|
-
FitParser::File::Types.add_type :ant_network, :enum, :
|
774
|
+
FitParser::File::Types.add_type :ant_network, :enum, values: {
|
775
775
|
0 => 'public',
|
776
776
|
1 => 'antplus',
|
777
777
|
2 => 'antfs',
|
778
778
|
3 => 'private' }
|
779
|
-
FitParser::File::Types.add_type :workout_capabilities, :uint32z, :
|
779
|
+
FitParser::File::Types.add_type :workout_capabilities, :uint32z, values: {
|
780
780
|
0x00000001 => 'interval',
|
781
781
|
0x00000002 => 'custom',
|
782
782
|
0x00000004 => 'fitness_equipment',
|
@@ -790,17 +790,17 @@ FitParser::File::Types.add_type :workout_capabilities, :uint32z, :values => {
|
|
790
790
|
0x00000800 => 'power',
|
791
791
|
0x00001000 => 'grade',
|
792
792
|
0x00002000 => 'resistance',
|
793
|
-
0x00004000 => 'protected' }, :
|
794
|
-
FitParser::File::Types.add_type :battery_status, :uint8, :
|
793
|
+
0x00004000 => 'protected' }, method: :bitfield_value
|
794
|
+
FitParser::File::Types.add_type :battery_status, :uint8, values: {
|
795
795
|
1 => 'new',
|
796
796
|
2 => 'good',
|
797
797
|
3 => 'ok',
|
798
798
|
4 => 'low',
|
799
799
|
5 => 'critical' }
|
800
|
-
FitParser::File::Types.add_type :hr_type, :enum, :
|
800
|
+
FitParser::File::Types.add_type :hr_type, :enum, values: {
|
801
801
|
0 => 'normal',
|
802
802
|
1 => 'irregular' }
|
803
|
-
FitParser::File::Types.add_type :course_capabilities, :uint32z, :
|
803
|
+
FitParser::File::Types.add_type :course_capabilities, :uint32z, values: {
|
804
804
|
0x00000001 => 'processed',
|
805
805
|
0x00000002 => 'valid',
|
806
806
|
0x00000004 => 'time',
|
@@ -810,27 +810,27 @@ FitParser::File::Types.add_type :course_capabilities, :uint32z, :values => {
|
|
810
810
|
0x00000040 => 'power',
|
811
811
|
0x00000080 => 'cadence',
|
812
812
|
0x00000100 => 'training',
|
813
|
-
0x00000200 => 'navigation' }, :
|
814
|
-
FitParser::File::Types.add_type :weight, :uint16, :
|
813
|
+
0x00000200 => 'navigation' }, method: :bitfield_value
|
814
|
+
FitParser::File::Types.add_type :weight, :uint16, values: {
|
815
815
|
65534 => 'calculating' }
|
816
|
-
FitParser::File::Types.add_type :workout_hr, :uint32, :
|
816
|
+
FitParser::File::Types.add_type :workout_hr, :uint32, values: {
|
817
817
|
100 => 'bpm_offset' }
|
818
|
-
FitParser::File::Types.add_type :workout_power, :uint32, :
|
818
|
+
FitParser::File::Types.add_type :workout_power, :uint32, values: {
|
819
819
|
1000 => 'watts_offset' }
|
820
|
-
FitParser::File::Types.add_type :bp_status, :enum, :
|
820
|
+
FitParser::File::Types.add_type :bp_status, :enum, values: {
|
821
821
|
0 => 'no_error',
|
822
822
|
1 => 'error_incomplete_data',
|
823
823
|
2 => 'error_no_measurement',
|
824
824
|
3 => 'error_data_out_of_range',
|
825
825
|
4 => 'error_irregular_heart_rate' }
|
826
|
-
FitParser::File::Types.add_type :user_local_id, :uint16, :
|
826
|
+
FitParser::File::Types.add_type :user_local_id, :uint16, values: {
|
827
827
|
0 => 'local_min',
|
828
828
|
15 => 'local_max',
|
829
829
|
16 => 'stationary_min',
|
830
830
|
255 => 'stationary_max',
|
831
831
|
256 => 'portable_min',
|
832
832
|
65534 => 'portable_max' }
|
833
|
-
FitParser::File::Types.add_type :swim_stroke, :enum, :
|
833
|
+
FitParser::File::Types.add_type :swim_stroke, :enum, values: {
|
834
834
|
0 => 'freestyle',
|
835
835
|
1 => 'backstroke',
|
836
836
|
2 => 'breaststroke',
|
@@ -838,7 +838,7 @@ FitParser::File::Types.add_type :swim_stroke, :enum, :values => {
|
|
838
838
|
4 => 'drill',
|
839
839
|
5 => 'mixed',
|
840
840
|
6 => 'im' }
|
841
|
-
FitParser::File::Types.add_type :activity_type, :enum, :
|
841
|
+
FitParser::File::Types.add_type :activity_type, :enum, values: {
|
842
842
|
0 => 'generic',
|
843
843
|
1 => 'running',
|
844
844
|
2 => 'cycling',
|
@@ -847,7 +847,7 @@ FitParser::File::Types.add_type :activity_type, :enum, :values => {
|
|
847
847
|
5 => 'swimming',
|
848
848
|
6 => 'walking',
|
849
849
|
254 => 'all' }
|
850
|
-
FitParser::File::Types.add_type :activity_subtype, :enum, :
|
850
|
+
FitParser::File::Types.add_type :activity_subtype, :enum, values: {
|
851
851
|
0 => 'generic',
|
852
852
|
1 => 'treadmill',
|
853
853
|
2 => 'street',
|
@@ -868,20 +868,20 @@ FitParser::File::Types.add_type :activity_subtype, :enum, :values => {
|
|
868
868
|
17 => 'lap_swimming',
|
869
869
|
18 => 'open_water',
|
870
870
|
254 => 'all' }
|
871
|
-
FitParser::File::Types.add_type :activity_level, :enum, :
|
871
|
+
FitParser::File::Types.add_type :activity_level, :enum, values: {
|
872
872
|
0 => 'low',
|
873
873
|
1 => 'medium',
|
874
874
|
2 => 'high' }
|
875
|
-
FitParser::File::Types.add_type :left_right_balance, :uint8, :
|
875
|
+
FitParser::File::Types.add_type :left_right_balance, :uint8, values: {
|
876
876
|
127 => 'mask',
|
877
877
|
128 => 'right' }
|
878
|
-
FitParser::File::Types.add_type :left_right_balance_100, :uint16, :
|
878
|
+
FitParser::File::Types.add_type :left_right_balance_100, :uint16, values: {
|
879
879
|
16383 => 'mask',
|
880
880
|
32768 => 'right' }
|
881
|
-
FitParser::File::Types.add_type :length_type, :enum, :
|
881
|
+
FitParser::File::Types.add_type :length_type, :enum, values: {
|
882
882
|
0 => 'idle',
|
883
883
|
1 => 'active' }
|
884
|
-
FitParser::File::Types.add_type :connectivity_capabilities, :uint32z, :
|
884
|
+
FitParser::File::Types.add_type :connectivity_capabilities, :uint32z, values: {
|
885
885
|
1 => 'bluetooth',
|
886
886
|
2 => 'bluetooth_le',
|
887
887
|
4 => 'ant',
|
@@ -896,14 +896,14 @@ FitParser::File::Types.add_type :connectivity_capabilities, :uint32z, :values =>
|
|
896
896
|
2048 => 'setup_incomplete',
|
897
897
|
4096 => 'continue_sync_after_software_update',
|
898
898
|
8192 => 'connect_iq_app_download' }
|
899
|
-
FitParser::File::Types.add_type :stroke_type, :enum, :
|
899
|
+
FitParser::File::Types.add_type :stroke_type, :enum, values: {
|
900
900
|
0 => 'no_event',
|
901
901
|
1 => 'other',
|
902
902
|
2 => 'serve',
|
903
903
|
3 => 'forehand',
|
904
904
|
4 => 'backhand',
|
905
905
|
5 => 'smash' }
|
906
|
-
FitParser::File::Types.add_type :body_location, :enum, :
|
906
|
+
FitParser::File::Types.add_type :body_location, :enum, values: {
|
907
907
|
0 => 'left_leg',
|
908
908
|
1 => 'left_calf',
|
909
909
|
2 => 'left_shin',
|
@@ -940,7 +940,7 @@ FitParser::File::Types.add_type :body_location, :enum, :values => {
|
|
940
940
|
33 => 'right_forearm_extensors',
|
941
941
|
34 => 'neck',
|
942
942
|
35 => 'throat' }
|
943
|
-
FitParser::File::Types.add_type :source_type, :enum, :
|
943
|
+
FitParser::File::Types.add_type :source_type, :enum, values: {
|
944
944
|
0 => 'ant',
|
945
945
|
1 => 'antplus',
|
946
946
|
2 => 'bluetooth',
|
@@ -951,6 +951,6 @@ FitParser::File::Types.add_type :source_type, :enum, :values => {
|
|
951
951
|
# the type below is assigned to some fileds, but
|
952
952
|
# it is not defined in terms of values and basic type in FIT SDK as
|
953
953
|
# of 2015-01-29
|
954
|
-
FitParser::File::Types.add_type :bool, :uint8, :
|
954
|
+
FitParser::File::Types.add_type :bool, :uint8, values: {
|
955
955
|
0 => false,
|
956
956
|
1 => true }
|
data/lib/fit_parser/file.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module FitParser
|
2
2
|
class File
|
3
|
-
|
4
3
|
def self.read(io)
|
5
4
|
new.read(io)
|
6
5
|
end
|
@@ -13,17 +12,14 @@ module FitParser
|
|
13
12
|
|
14
13
|
def read(io)
|
15
14
|
@header = Header.read(io)
|
16
|
-
|
17
|
-
Record.clear_definitions!
|
18
|
-
|
15
|
+
definitions = {}
|
19
16
|
while io.pos < @header.end_pos
|
20
|
-
|
17
|
+
record = Record.new(definitions)
|
18
|
+
@records << record.read(io)
|
19
|
+
definitions = record.definitions
|
21
20
|
end
|
22
|
-
|
23
21
|
@crc = io.read(2)
|
24
|
-
|
25
22
|
self
|
26
23
|
end
|
27
|
-
|
28
24
|
end
|
29
25
|
end
|
data/lib/fit_parser/version.rb
CHANGED