px4_log_reader 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,44 @@
1
+ require 'minitest/autorun'
2
+ require 'px4_log_reader'
3
+
4
+ class TestLogFile < MiniTest::Test
5
+
6
+ def setup
7
+ end
8
+
9
+ def teardown
10
+ end
11
+
12
+ def test_read_descriptors
13
+
14
+ # log_file = open_log_file
15
+ # descriptors = Px4LogReader::LogFile.read_descriptors( log_file )
16
+
17
+ # puts "Found #{descriptors.count} descriptors"
18
+ # descriptors.each do |type,descriptor|
19
+ # puts " #{descriptor.name}"
20
+ # end
21
+
22
+ # log_file.close
23
+
24
+ end
25
+
26
+ def test_read_message
27
+
28
+ # log_file = open_log_file
29
+ # descriptors = Px4LogReader::LogFile.read_descriptors( log_file )
30
+
31
+ # log_file.rewind
32
+ # message = Px4LogReader::LogFile.read_message( log_file, descriptors )
33
+
34
+ # puts message.descriptor
35
+
36
+ end
37
+
38
+
39
+ def open_log_file
40
+ log_file = File.open( File.join( '/Volumes/rvaughan_share/Development/px4_log_reader_test_data', '2016-07-24', '17_18_36.px4log' ), 'r' )
41
+ log_file
42
+ end
43
+
44
+ end
@@ -0,0 +1,56 @@
1
+ require 'minitest/autorun'
2
+ require 'px4_log_reader'
3
+
4
+ class TestMessageDescriptor < MiniTest::Test
5
+
6
+ def setup
7
+ end
8
+
9
+ def teardown
10
+ end
11
+
12
+ def test_build_format_specifier
13
+
14
+ px4_format_specifier = 'BBnNZ'
15
+ ruby_format_specifier =
16
+ Px4LogReader::MessageDescriptor.build_format_specifier( px4_format_specifier )
17
+
18
+ assert_equal 'CCA4A16A64', ruby_format_specifier
19
+ end
20
+
21
+ def test_unpack_message
22
+
23
+ end
24
+
25
+ def test_descriptor_from_message
26
+
27
+ fields = [ 0x24, 32, 'test', 'IIbMh', 'id,counts,flag,length,ord' ]
28
+
29
+ message = Px4LogReader::LogMessage.new(
30
+ Px4LogReader::FORMAT_MESSAGE,
31
+ fields )
32
+
33
+ descriptor = Px4LogReader::MessageDescriptor.new
34
+ assert_equal nil, descriptor.type
35
+ assert_equal nil, descriptor.name
36
+ assert_equal nil, descriptor.length
37
+ assert_equal nil, descriptor.format
38
+ assert_equal nil, descriptor.format_specifier
39
+ assert_equal true, descriptor.field_list.empty?
40
+
41
+ descriptor.from_message( message )
42
+ assert_equal 0x24, descriptor.type
43
+ assert_equal 'test', descriptor.name
44
+ assert_equal 32, descriptor.length
45
+ assert_equal 'IIbMh', descriptor.format
46
+ assert_equal 'LLcCs', descriptor.format_specifier
47
+ assert_equal false, descriptor.field_list.empty?
48
+ assert_equal 0, descriptor.field_list['id']
49
+ assert_equal 1, descriptor.field_list['counts']
50
+ assert_equal 2, descriptor.field_list['flag']
51
+ assert_equal 3, descriptor.field_list['length']
52
+ assert_equal 4, descriptor.field_list['ord']
53
+
54
+ end
55
+
56
+ end
@@ -0,0 +1,70 @@
1
+ require 'minitest/autorun'
2
+ require 'px4_log_reader'
3
+
4
+ class TestMessageDescriptorCache < MiniTest::Test
5
+
6
+ def setup
7
+ end
8
+
9
+ def teardown
10
+ end
11
+
12
+ def test_write_read_descriptors
13
+
14
+ cache_filename = File.join( 'test', 'test_files', 'test_cache.px4mc' )
15
+
16
+ FileUtils.rm( cache_filename ) if File.exist? cache_filename
17
+
18
+ # Create a couple of descriptors
19
+ w_descriptors = {}
20
+ descriptor = Px4LogReader::MessageDescriptor.new({
21
+ name: 'FMT',
22
+ type: 0x80,
23
+ length: 89,
24
+ format: 'BBnNZ',
25
+ fields: [ "Type", "Length", "Name", "Format", "Labels" ] })
26
+ w_descriptors[ descriptor.type ] = descriptor.dup
27
+
28
+ descriptor = Px4LogReader::MessageDescriptor.new({
29
+ name: 'ATT',
30
+ type: 0x23,
31
+ length: 18,
32
+ format: 'LLBbff',
33
+ fields: [ "sec", "usec", "valid", "offset", "latitude", "longitude" ] })
34
+ w_descriptors[ descriptor.type ] = descriptor.dup
35
+
36
+
37
+ cache = Px4LogReader::MessageDescriptorCache.new( cache_filename )
38
+ assert_equal false, cache.exist?
39
+
40
+ cache.write_descriptors( w_descriptors )
41
+ assert_equal true, cache.exist?
42
+
43
+ r_descriptors = cache.read_descriptors
44
+
45
+ # assert_equal 2, r_descriptors.size
46
+ # assert_equal [ 0x23, 0x80 ], r_descriptors.keys.sort
47
+
48
+ w_descriptors.each do |type,w_descriptor|
49
+
50
+ assert_equal true, r_descriptors.keys.include?( type )
51
+
52
+ if r_descriptors.keys.include? type
53
+
54
+ r_descriptor = r_descriptors[ type ]
55
+
56
+ assert_equal w_descriptor.name, r_descriptor.name
57
+ assert_equal w_descriptor.type, r_descriptor.type
58
+ assert_equal w_descriptor.length, r_descriptor.length
59
+ assert_equal w_descriptor.format, r_descriptor.format
60
+ assert_equal w_descriptor.field_list.keys, r_descriptor.field_list.keys
61
+
62
+ end
63
+
64
+ end
65
+
66
+ FileUtils.rm( cache_filename )
67
+
68
+ end
69
+
70
+ end
@@ -0,0 +1,127 @@
1
+ require 'minitest/autorun'
2
+ require 'px4_log_reader'
3
+
4
+ class TestReader < MiniTest::Test
5
+
6
+ def setup
7
+ end
8
+
9
+ def test_non_existent_log_file
10
+
11
+ nonexistent_filename = 'nonexistent_logfile.px4log'
12
+
13
+ exception = assert_raises Px4LogReader::FileNotFoundError do
14
+ reader = Px4LogReader.open!( nonexistent_filename )
15
+ end
16
+
17
+ exception = assert_raises Px4LogReader::FileNotFoundError do
18
+ Px4LogReader.open!( nonexistent_filename ) do |reader|
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ def test_non_existent_log_file_no_except
25
+
26
+ nonexistent_filename = 'nonexistent_logfile.px4log'
27
+
28
+ assert_nil Px4LogReader.open( nonexistent_filename )
29
+
30
+ Px4LogReader.open( nonexistent_filename ) do |reader|
31
+ assert_nil reader
32
+ end
33
+ end
34
+
35
+ def test_reader
36
+
37
+ log_file_opened = false
38
+ log_filename = File.join( 'test', 'test_files', 'test_log.px4log' )
39
+
40
+ Px4LogReader.open( log_filename ) do |reader|
41
+
42
+ log_file_opened = true
43
+
44
+ # Verify that all expected descriptors are read.
45
+ descriptors = reader.descriptors
46
+ assert_equal Hash, descriptors.class
47
+ assert_equal false, descriptors.empty?
48
+
49
+ assert_equal true, all_descriptors_found( descriptors )
50
+
51
+
52
+ # The log file associated with this test case contains the following
53
+ # messages in the specified order. Validate the order and context.
54
+ #
55
+ # 1) TIME
56
+ # 2) STAT
57
+ # 3) IMU
58
+ # 4) SENS
59
+ # 5) IMU1
60
+ # 6) VTOL
61
+ # 7) GPS
62
+ #
63
+ index = 0
64
+ expected_message_names = ['TIME','STAT','IMU','SENS','IMU1','VTOL','GPS']
65
+ expected_message_types = [0x81,0x0A,0x04,0x05,0x16,0x2B,0x08]
66
+
67
+ reader.each_message do |message,context|
68
+
69
+ expected_name = expected_message_names[ index ]
70
+ expected_type = expected_message_types[ index ]
71
+
72
+ assert_equal expected_name, message.descriptor.name
73
+ assert_equal expected_type, message.descriptor.type
74
+
75
+ context_message = context.find_by_name( expected_name )
76
+ refute_nil context_message
77
+ assert_equal expected_name, context_message.descriptor.name
78
+
79
+ context_message = context.find_by_type( expected_type )
80
+ refute_nil context_message
81
+ assert_equal expected_type, context_message.descriptor.type
82
+
83
+ index += 1
84
+ assert_equal index, context.messages.size
85
+
86
+ end
87
+
88
+
89
+ index = 0
90
+ expected_message_names = ['TIME','IMU','SENS','VTOL','GPS']
91
+ expected_message_types = [0x81,0x04,0x05,0x2B,0x08]
92
+
93
+ reader.each_message( { without: ['STAT','IMU1'] } ) do |message,context|
94
+
95
+ expected_name = expected_message_names[ index ]
96
+ expected_type = expected_message_types[ index ]
97
+
98
+ assert_equal expected_name, message.descriptor.name
99
+ assert_equal expected_type, message.descriptor.type
100
+
101
+ context_message = context.find_by_name( expected_name )
102
+ refute_nil context_message
103
+ assert_equal expected_name, context_message.descriptor.name
104
+
105
+ context_message = context.find_by_type( expected_type )
106
+ refute_nil context_message
107
+ assert_equal expected_type, context_message.descriptor.type
108
+
109
+ index += 1
110
+ assert_equal index, context.messages.size
111
+
112
+ end
113
+
114
+ end
115
+
116
+ assert_equal true, log_file_opened
117
+
118
+ end
119
+
120
+
121
+
122
+ def all_descriptors_found( descriptors )
123
+ # TODO: Validate all descriptors?
124
+ return true
125
+ end
126
+
127
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: px4_log_reader
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Robert Glissmann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ description: Px4LogReader is a gem for parsing PX4-format flight logs generated by
28
+ the Pixhawk.
29
+ email: Robert.Glissmann@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - README.md
36
+ - Rakefile
37
+ - lib/px4_log_reader.rb
38
+ - lib/px4_log_reader/invalid_descriptor_error.rb
39
+ - lib/px4_log_reader/log_buffer.rb
40
+ - lib/px4_log_reader/log_file.rb
41
+ - lib/px4_log_reader/log_message.rb
42
+ - lib/px4_log_reader/message_descriptor.rb
43
+ - lib/px4_log_reader/message_descriptor_cache.rb
44
+ - lib/px4_log_reader/reader.rb
45
+ - lib/px4_log_reader/version.rb
46
+ - lib/px4log_parser.rb
47
+ - px4_log_reader.gemspec
48
+ - test/test.rb
49
+ - test/test_files/pixhawk_descriptor_cache.px4mc
50
+ - test/test_files/test_log.px4log
51
+ - test/test_log_buffer.rb
52
+ - test/test_log_file.rb
53
+ - test/test_message_descriptor.rb
54
+ - test/test_message_descriptor_cache.rb
55
+ - test/test_reader.rb
56
+ homepage: https://github.com/rgmann/px4_log_reader
57
+ licenses:
58
+ - BSD
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.4.5.1
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: PX4 flight log reader
80
+ test_files: []
81
+ has_rdoc: