fit_parser 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +105 -0
- data/LICENSE.txt +20 -0
- data/README.md +27 -0
- data/Rakefile +38 -0
- data/lib/fit_parser/file/data.rb +99 -0
- data/lib/fit_parser/file/definition.rb +120 -0
- data/lib/fit_parser/file/definitions.rb +705 -0
- data/lib/fit_parser/file/header.rb +18 -0
- data/lib/fit_parser/file/record.rb +37 -0
- data/lib/fit_parser/file/record_header.rb +27 -0
- data/lib/fit_parser/file/type.rb +41 -0
- data/lib/fit_parser/file/types.rb +954 -0
- data/lib/fit_parser/file.rb +29 -0
- data/lib/fit_parser/version.rb +3 -0
- data/lib/fit_parser.rb +19 -0
- data/spec/file/data_spec.rb +111 -0
- data/spec/file/definition_spec.rb +26 -0
- data/spec/file/definitions_spec.rb +81 -0
- data/spec/file/header_spec.rb +28 -0
- data/spec/file/record_header_spec.rb +20 -0
- data/spec/file/record_spec.rb +56 -0
- data/spec/file/type_spec.rb +99 -0
- data/spec/file/types_spec.rb +100 -0
- data/spec/file_spec.rb +21 -0
- data/spec/fit_spec.rb +10 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/support/examples/file/full_file_with_wrong_crc.fit +0 -0
- data/spec/support/examples/file/header +0 -0
- data/spec/support/examples/file/header_14b.fit +0 -0
- data/spec/support/examples/record/data_record_2.fit +0 -0
- data/spec/support/examples/record/data_record_2bis.fit +0 -0
- data/spec/support/examples/record/definition_record +0 -0
- data/spec/support/examples/record/definition_record_2.fit +0 -0
- data/spec/support/examples/record/message/data_dynamic_fields.fit +0 -0
- data/spec/support/examples/record/message/data_field_array.fit +0 -0
- data/spec/support/examples/record/message/data_file_capabilities_activities.fit +0 -0
- data/spec/support/examples/record/message/data_file_capabilities_settings.fit +0 -0
- data/spec/support/examples/record/message/definition +0 -0
- data/spec/support/examples/record/message/definition_dynamic_fields.fit +0 -0
- data/spec/support/examples/record/message/definition_field_array.fit +0 -0
- data/spec/support/examples/record/message/definition_file_capabilities.fit +0 -0
- data/spec/support/examples/record/normal_header +1 -0
- metadata +230 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
module FitParser
|
2
|
+
class File
|
3
|
+
class Header < BinData::Record
|
4
|
+
endian :little
|
5
|
+
|
6
|
+
uint8 :header_size, :check_value => lambda { value >= 12 }
|
7
|
+
uint8 :protocol_version
|
8
|
+
uint16 :profile_version
|
9
|
+
uint32 :data_size
|
10
|
+
string :data_type, :read_length => 4
|
11
|
+
uint16 :crc, :onlyif => lambda { header_size == 14 }
|
12
|
+
|
13
|
+
def end_pos
|
14
|
+
header_size + data_size - 2
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module FitParser
|
2
|
+
class File
|
3
|
+
class Record
|
4
|
+
|
5
|
+
@@definitions = {}
|
6
|
+
mattr_reader :definitions, instance_reader: false
|
7
|
+
|
8
|
+
def self.read(io)
|
9
|
+
new.read(io)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.clear_definitions!
|
13
|
+
@@definitions.clear
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_reader :header, :content
|
17
|
+
|
18
|
+
def read(io)
|
19
|
+
@header = RecordHeader.read(io)
|
20
|
+
|
21
|
+
@content = case @header.message_type.snapshot
|
22
|
+
when 1
|
23
|
+
Definition.read(io).tap do |definition|
|
24
|
+
@@definitions[@header.local_message_type.snapshot] = Data.generate(definition)
|
25
|
+
end
|
26
|
+
when 0
|
27
|
+
definition = @@definitions[@header.local_message_type.snapshot]
|
28
|
+
raise "No definition for local message type: #{@header.local_message_type}" if definition.nil?
|
29
|
+
definition.read(io)
|
30
|
+
end
|
31
|
+
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module FitParser
|
2
|
+
class File
|
3
|
+
class RecordHeader < BinData::Record
|
4
|
+
hide :reserved_bits
|
5
|
+
|
6
|
+
bit1 :header_type
|
7
|
+
|
8
|
+
bit1 :message_type, :onlyif => :normal?
|
9
|
+
bit2 :reserved_bits, :onlyif => :normal?
|
10
|
+
|
11
|
+
choice :local_message_type, :selection => :header_type do
|
12
|
+
bit4 0
|
13
|
+
bit2 1
|
14
|
+
end
|
15
|
+
|
16
|
+
bit5 :time_offset, :onlyif => :compressed_timestamp?
|
17
|
+
|
18
|
+
def normal?
|
19
|
+
header_type == 0
|
20
|
+
end
|
21
|
+
|
22
|
+
def compressed_timestamp?
|
23
|
+
header_type == 1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module FitParser
|
2
|
+
class File
|
3
|
+
class Type
|
4
|
+
|
5
|
+
@@types = {}
|
6
|
+
|
7
|
+
def self.get_type(name)
|
8
|
+
return @@types[name] if @@types.has_key? name
|
9
|
+
type = Types.get_type_definition name
|
10
|
+
@@types[name] = type ? new(type) : nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(type)
|
14
|
+
@type = type
|
15
|
+
end
|
16
|
+
|
17
|
+
def value(val)
|
18
|
+
return nil unless is_valid(val)
|
19
|
+
if @type.has_key? :method
|
20
|
+
Types.send(@type[:method], val, @type[:values], @type[:parameters])
|
21
|
+
else
|
22
|
+
values = @type[:values]
|
23
|
+
value = values[val] if values
|
24
|
+
return value unless value.nil?
|
25
|
+
val
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def is_valid(val)
|
31
|
+
if @type.has_key? :invalid
|
32
|
+
invalid_value = @type[:invalid]
|
33
|
+
else
|
34
|
+
invalid_value = Types.get_type_definition(@type[:basic_type])[:invalid]
|
35
|
+
end
|
36
|
+
return false if val == invalid_value
|
37
|
+
true
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|