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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26a162b17897f536d316acc8e36dad49d36a3a72
|
4
|
+
data.tar.gz: 597240fbd8ee2fef1a95e1165e9a1fcb95f1948d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67a8ee06d504f0a96a7a3a3b1619692b287192830fdeb252c701dad9f7eb7dfb8dc1084ab36d7ef640ce2955110c099a6f29e16699c9734f9b8a77d2b729f829
|
7
|
+
data.tar.gz: 7c4795cb5492141343f2f6c50dc3b866b6a3101bfc6b05a56ec5cc6403adaf5befaf0bb14644c2d0df4ca52172094893f7f2ba3f963b0bb9bde68073a39d61de
|
data/lib/fit_parser/file/data.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
module FitParser
|
2
2
|
class File
|
3
3
|
class Data < BinData::Record
|
4
|
-
|
5
|
-
class_attribute :global_message_number, :instance_writer => false
|
4
|
+
class_attribute :global_message_number, instance_writer: false
|
6
5
|
|
7
6
|
def self.generate(definition)
|
8
7
|
msg_num = definition.global_message_number.snapshot
|
@@ -20,15 +19,15 @@ module FitParser
|
|
20
19
|
RUBY
|
21
20
|
|
22
21
|
definition.fields.each do |field|
|
23
|
-
code =
|
22
|
+
code = ''
|
24
23
|
|
25
24
|
# in case the field size is a multiple of the field length, we must build an array
|
26
|
-
if
|
25
|
+
if field.type != 'string' && field.size > field.length
|
27
26
|
code << "array :#{field.raw_name}, :type => :#{field.type}, :initial_length => #{field.size/field.length}\n"
|
28
27
|
else
|
29
28
|
# string are not null terminated when they have exactly the lenght of the field
|
30
29
|
code << "#{field.type} :#{field.raw_name}"
|
31
|
-
if field.type ==
|
30
|
+
if field.type == 'string'
|
32
31
|
code << ", :read_length => #{field.size}, :trim_padding => true"
|
33
32
|
end
|
34
33
|
code << "\n"
|
@@ -52,48 +51,46 @@ module FitParser
|
|
52
51
|
end
|
53
52
|
RUBY
|
54
53
|
|
55
|
-
class_eval code
|
54
|
+
class_eval code, __FILE__, __LINE__ + 1
|
56
55
|
end
|
57
|
-
|
56
|
+
|
58
57
|
private
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
raw_value / raw_scale
|
69
|
-
end
|
58
|
+
|
59
|
+
# return the dynamic value if relevant
|
60
|
+
# otherwise, it returns value (scaled if necessary)
|
61
|
+
def get_value(raw_value, raw_type, raw_scale, dyn_data)
|
62
|
+
val = get_dyn_value(dyn_data, raw_value)
|
63
|
+
return val unless val.nil?
|
64
|
+
if raw_scale
|
65
|
+
if raw_value.is_a? Enumerable
|
66
|
+
raw_value.map { |elt| elt / raw_scale }
|
70
67
|
else
|
71
|
-
|
68
|
+
raw_value / raw_scale
|
72
69
|
end
|
70
|
+
else
|
71
|
+
get_real_value raw_type, raw_value
|
73
72
|
end
|
73
|
+
end
|
74
74
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
75
|
+
# return the value based on real type
|
76
|
+
def get_real_value(real_type, raw_value)
|
77
|
+
type = Type.get_type(real_type.to_sym)
|
78
|
+
# TODO: manage case where an array is returned
|
79
|
+
type ? type.value(raw_value) : raw_value
|
80
|
+
end
|
81
81
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
return get_real_value(dyn[:type], raw_value)
|
89
|
-
end
|
82
|
+
def get_dyn_value(dyn_data, raw_value)
|
83
|
+
return nil if dyn_data.nil?
|
84
|
+
dyn_data.each do |key, dyn|
|
85
|
+
# make sure method exist before calling send (all fields are not always defined)
|
86
|
+
if respond_to?("raw_#{dyn[:ref_field_name]}") && dyn[:ref_field_values].include?(send("raw_#{dyn[:ref_field_name]}"))
|
87
|
+
return get_real_value(dyn[:type], raw_value)
|
90
88
|
end
|
91
|
-
nil
|
92
89
|
end
|
93
|
-
|
90
|
+
nil
|
91
|
+
end
|
94
92
|
end
|
95
93
|
end
|
96
|
-
|
97
94
|
end
|
98
95
|
end
|
99
96
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module FitParser
|
2
2
|
class File
|
3
3
|
class Definition < BinData::Record
|
4
|
-
|
5
4
|
class Field < BinData::Record
|
6
5
|
hide :reserved_bits
|
7
6
|
|
@@ -14,7 +13,7 @@ module FitParser
|
|
14
13
|
def data
|
15
14
|
@data ||= Definitions.get_field(parent.parent.global_message_number.snapshot,
|
16
15
|
field_definition_number.snapshot) ||
|
17
|
-
{ :
|
16
|
+
{ name: "field_#{field_definition_number.snapshot}", scale: nil }
|
18
17
|
end
|
19
18
|
|
20
19
|
def dyn_data
|
@@ -58,13 +57,13 @@ module FitParser
|
|
58
57
|
# some cases found where string has the max field length
|
59
58
|
# and is therefore not null terminated
|
60
59
|
@length = 1
|
61
|
-
|
60
|
+
'string'
|
62
61
|
when 8
|
63
62
|
@length = 4
|
64
|
-
|
63
|
+
'float'
|
65
64
|
when 9
|
66
65
|
@length = 8
|
67
|
-
|
66
|
+
'double'
|
68
67
|
when 10 # uint8z
|
69
68
|
build_int_type 8, false
|
70
69
|
when 11 # uint16z
|
@@ -74,7 +73,7 @@ module FitParser
|
|
74
73
|
when 13 # array of bytes
|
75
74
|
build_int_type 8, false
|
76
75
|
else
|
77
|
-
|
76
|
+
fail "Can't map base_type_number #{base_type_number} to a data type"
|
78
77
|
end
|
79
78
|
end
|
80
79
|
|
@@ -82,7 +81,7 @@ module FitParser
|
|
82
81
|
def size
|
83
82
|
field_size
|
84
83
|
end
|
85
|
-
|
84
|
+
|
86
85
|
# return the length in byte of the given type
|
87
86
|
def length
|
88
87
|
@length
|
@@ -92,19 +91,19 @@ module FitParser
|
|
92
91
|
|
93
92
|
def build_int_type(length, signed)
|
94
93
|
# @length is in byte not in bits, so divide by 8
|
95
|
-
@length = length/8
|
94
|
+
@length = length / 8
|
96
95
|
(signed ? '' : 'u') << 'int' << length.to_s
|
97
96
|
end
|
98
97
|
end
|
99
98
|
|
100
|
-
skip :
|
99
|
+
skip length: 1
|
101
100
|
bit8 :architecture
|
102
|
-
choice :global_message_number, :
|
101
|
+
choice :global_message_number, selection: :architecture do
|
103
102
|
uint16le 0
|
104
103
|
uint16be 1
|
105
104
|
end
|
106
105
|
bit8 :field_count
|
107
|
-
array :fields, :
|
106
|
+
array :fields, type: Field, initial_length: :field_count
|
108
107
|
|
109
108
|
def endianness
|
110
109
|
architecture.snapshot == 0 ? :little : :big
|
@@ -113,8 +112,6 @@ module FitParser
|
|
113
112
|
def record_type
|
114
113
|
:definition
|
115
114
|
end
|
116
|
-
|
117
115
|
end
|
118
116
|
end
|
119
117
|
end
|
120
|
-
|