px4_log_reader 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4866bef24e75e23430bf53f0d79860ce51179031
4
- data.tar.gz: 99c4506ee9f1324a75be0967a1e4d0e16b92410b
3
+ metadata.gz: b6071ae755e8bf6039fffcfddd4f08d38396509a
4
+ data.tar.gz: 1407b35a16ba00b5e2def9f4d2869269c7caaad4
5
5
  SHA512:
6
- metadata.gz: 4fbfd8dfa77d550d8bc7139fdae14600d50d5450d017b881b2a45c478f35fff60fa835b77cbd3697dcf5b2d6d19ce66182e0ee2204e6eb4ce21c77752aa35487
7
- data.tar.gz: e5d5c1eb3fa33137568d1908c40cd68249066809c61ca0a1b360f59fe69f9ec7f1b49dadf08f802084d8ceacb6f34b83ff4eed44e188ba01aae096777df7fd8e
6
+ metadata.gz: 1378a7bc49c3a8dc49acd0977712b8e696641b8d64f162a895097911c325b6648abc4f5c07e2be093c7b4708281d3493215d83a543091e12cb172a21e3633f50
7
+ data.tar.gz: 3818474002ba766ed277d0e98b39de6eef9d46211f4a2c921c30f02729e3068a50958e60008085e8c7c564497b619ab13b9b190ed0458a03b139de694a48694e
data/.gitignore CHANGED
@@ -1,4 +1,4 @@
1
1
  *.sublime-*
2
2
  .DS_Store
3
3
  *.gem
4
- *.txt
4
+ default_log_path.txt
data/LICENSE.txt ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2016, Robert Glissmann
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md CHANGED
@@ -25,9 +25,9 @@ or add this to your Gemfile if you use [Bundler](http://gembundler.com/):
25
25
  Px4LogReader.open( 'a_test_log.px4log' ) do |reader|
26
26
  reader.each_message( { with: [ 'ATT' ] } ) do |message,context|
27
27
 
28
- att = [ messaged.get('roll'), message.get('pitch'), message.get('yaw') ]
28
+ att = [ messaged.get('Roll'), message.get('Pitch'), message.get('Yaw') ]
29
29
 
30
- puts "ATT( @ #{context.find_by_name('GPS').get('time')} ): roll=#{att[0]}, pitch=#{att[1]}, yaw=#{att[2]}"
30
+ puts "ATT( @ #{context.find_by_name('GPS').get('GPSTime')} ): roll=#{att[0]}, pitch=#{att[1]}, yaw=#{att[2]}"
31
31
 
32
32
  end
33
33
  end
data/Rakefile CHANGED
@@ -1,3 +1,35 @@
1
+ #
2
+ # Copyright (c) 2016, Robert Glissmann
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ #
26
+
27
+ # %% license-end-token %%
28
+ #
29
+ # Author: Robert.Glissmann@gmail.com (Robert Glissmann)
30
+ #
31
+ #
32
+
1
33
  require 'rake/testtask'
2
34
 
3
35
  Rake::TestTask.new do |t|
@@ -10,10 +42,10 @@ task :default => :test
10
42
  def read_default_log_filename
11
43
  log_filename = ''
12
44
  File.open( 'default_log_path.txt', 'r' ) do |input|
13
- log_filename = input.readline
45
+ log_filename = input.readline.strip
14
46
  end
15
47
 
16
- unless File.exist? log_filename
48
+ unless File.exist?( log_filename )
17
49
  raise "Failed to find '#{log_filename}'"
18
50
  end
19
51
 
@@ -0,0 +1,43 @@
1
+ #
2
+ # Copyright (c) 2016, Robert Glissmann
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ #
26
+
27
+ # %% license-end-token %%
28
+ #
29
+ # Author: Robert.Glissmann@gmail.com (Robert Glissmann)
30
+ #
31
+ #
32
+
33
+ module Px4LogReader
34
+
35
+ class Error < StandardError
36
+
37
+ def initialize( message='' )
38
+ super( message )
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,41 @@
1
+ #
2
+ # Copyright (c) 2016, Robert Glissmann
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ #
26
+
27
+ # %% license-end-token %%
28
+ #
29
+ # Author: Robert.Glissmann@gmail.com (Robert Glissmann)
30
+ #
31
+ #
32
+
33
+ module Px4LogReader
34
+
35
+ class FileNotFoundError < Error
36
+ def initialize( filename )
37
+ super( "Failed to find '#{filename}'" )
38
+ end
39
+ end
40
+
41
+ end
@@ -1,12 +1,36 @@
1
- module Px4LogReader
2
-
3
- class Error < StandardError
4
-
5
- def initialize( message='' )
6
- super( message )
7
- end
1
+ #
2
+ # Copyright (c) 2016, Robert Glissmann
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ #
26
+
27
+ # %% license-end-token %%
28
+ #
29
+ # Author: Robert.Glissmann@gmail.com (Robert Glissmann)
30
+ #
31
+ #
8
32
 
9
- end
33
+ module Px4LogReader
10
34
 
11
35
  class InvalidDescriptorError < Error
12
36
 
@@ -16,10 +40,4 @@ module Px4LogReader
16
40
 
17
41
  end
18
42
 
19
- class FileNotFoundError < Error
20
- def initialize( filename )
21
- super( "Failed to find '#{filename}'" )
22
- end
23
- end
24
-
25
43
  end
@@ -1,3 +1,35 @@
1
+ #
2
+ # Copyright (c) 2016, Robert Glissmann
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ #
26
+
27
+ # %% license-end-token %%
28
+ #
29
+ # Author: Robert.Glissmann@gmail.com (Robert Glissmann)
30
+ #
31
+ #
32
+
1
33
  module Px4LogReader
2
34
 
3
35
  class LogBuffer
@@ -1,11 +1,42 @@
1
+ #
2
+ # Copyright (c) 2016, Robert Glissmann
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ #
26
+
27
+ # %% license-end-token %%
28
+ #
29
+ # Author: Robert.Glissmann@gmail.com (Robert Glissmann)
30
+ #
31
+ #
1
32
 
2
33
  module Px4LogReader
3
34
 
4
35
  module LogFile
5
36
 
6
37
  HEADER_MARKER = [0xA3,0x95]
7
- HEADER_LENGTH = 3
8
- FORMAT_DESCRIPTOR_TABLE = { FORMAT_MESSAGE.type => FORMAT_MESSAGE }.freeze
38
+ HEADER_LENGTH = 3
39
+ FORMAT_DESCRIPTOR_TABLE = { FORMAT_MESSAGE.type => FORMAT_MESSAGE }.freeze
9
40
 
10
41
  def self.read_descriptors( buffered_io, descriptor_cache=nil )
11
42
 
@@ -29,7 +60,7 @@ module Px4LogReader
29
60
 
30
61
  message_descriptor = nil
31
62
 
32
- begin
63
+ begin
33
64
 
34
65
  descriptor_message = read_message( buffered_io, FORMAT_DESCRIPTOR_TABLE )
35
66
 
@@ -54,9 +85,9 @@ module Px4LogReader
54
85
  end
55
86
 
56
87
  return message_descriptor
57
- end
88
+ end
58
89
 
59
- def self.read_message( buffered_io, message_descriptors )
90
+ def self.read_message( buffered_io, message_descriptors )
60
91
 
61
92
  message = nil
62
93
  while message.nil? do
@@ -77,48 +108,48 @@ module Px4LogReader
77
108
  end
78
109
 
79
110
  return message
80
- end
111
+ end
81
112
 
82
- def self.read_message_header( buffered_io )
83
- message_type = nil
113
+ def self.read_message_header( buffered_io )
114
+ message_type = nil
84
115
 
85
- begin
116
+ begin
86
117
 
87
- data = buffered_io.read(2)
118
+ data = buffered_io.read(2)
88
119
 
89
- if data && data.length == 2
120
+ if data && data.length == 2
90
121
 
91
- while !data.empty? && message_type.nil? do
122
+ while !data.empty? && message_type.nil? do
92
123
 
93
- if ( byte = buffered_io.read(1) )
94
- data << byte
95
- end
124
+ if ( byte = buffered_io.read(1) )
125
+ data << byte
126
+ end
96
127
 
97
- if data.unpack('CCC')[0,2] == HEADER_MARKER
98
- message_type = data.unpack('CCC').last & 0xFF
99
- else
100
- data = data[1..-1]
101
- end
128
+ if data.unpack('CCC')[0,2] == HEADER_MARKER
129
+ message_type = data.unpack('CCC').last & 0xFF
130
+ else
131
+ data = data[1..-1]
132
+ end
102
133
 
103
- end
104
- end
134
+ end
135
+ end
105
136
 
106
- rescue EOFError => error
107
- # Nothing to do.
108
- rescue StandardError => error
109
- puts error.message
110
- puts error.backtrace.join("\n")
111
- end
137
+ rescue EOFError => error
138
+ # Nothing to do.
139
+ rescue StandardError => error
140
+ puts error.message
141
+ puts error.backtrace.join("\n")
142
+ end
112
143
 
113
- return message_type
114
- end
144
+ return message_type
145
+ end
115
146
 
116
147
 
117
- def self.write_message( io, message )
118
- io.write HEADER_MARKER.pack('CC')
119
- io.write [ message.descriptor.type ].pack('C')
120
- io.write message.pack
121
- end
148
+ def self.write_message( io, message )
149
+ io.write HEADER_MARKER.pack('CC')
150
+ io.write [ message.descriptor.type ].pack('C')
151
+ io.write message.pack
152
+ end
122
153
 
123
154
  end
124
155
 
@@ -1,8 +1,42 @@
1
+ #
2
+ # Copyright (c) 2016, Robert Glissmann
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ #
26
+
27
+ # %% license-end-token %%
28
+ #
29
+ # Author: Robert.Glissmann@gmail.com (Robert Glissmann)
30
+ #
31
+ #
32
+
1
33
  module Px4LogReader
2
34
 
3
35
  class LogMessage
36
+
4
37
  attr_reader :descriptor
5
38
  attr_reader :fields
39
+
6
40
  def initialize( descriptor, fields )
7
41
  @descriptor = descriptor
8
42
  @fields = fields
@@ -10,21 +44,18 @@ module Px4LogReader
10
44
 
11
45
  def get( index )
12
46
 
13
- index = index
14
47
  if index.class == String
15
48
  index = descriptor.field_list[ index ]
16
49
  end
17
50
 
18
- return @fields[ index ]
51
+ return @fields[ index ] if index
52
+ return nil
19
53
  end
20
54
 
21
55
  def pack
22
56
  return @descriptor.pack_message( @fields )
23
57
  end
24
58
 
25
- def to_s
26
- return to_csv_line( Time.now )
27
- end
28
59
  end
29
60
 
30
61
  end
@@ -1,16 +1,47 @@
1
+ #
2
+ # Copyright (c) 2016, Robert Glissmann
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ #
26
+
27
+ # %% license-end-token %%
28
+ #
29
+ # Author: Robert.Glissmann@gmail.com (Robert Glissmann)
30
+ #
31
+ #
1
32
 
2
33
  module Px4LogReader
3
34
 
4
35
  class MessageDescriptor
5
36
 
6
- attr_reader :name
7
- attr_reader :type
8
- attr_reader :length
9
- attr_reader :format
10
- attr_reader :field_list
11
- attr_reader :format_specifier
37
+ attr_reader :name
38
+ attr_reader :type
39
+ attr_reader :length
40
+ attr_reader :format
41
+ attr_reader :field_list
42
+ attr_reader :format_specifier
12
43
 
13
- def initialize(attrs={})
44
+ def initialize(attrs={})
14
45
  if attrs.keys.uniq.sort == [:name,:type,:length,:format,:fields].uniq.sort
15
46
  @name = attrs[:name]
16
47
  @type = attrs[:type]
@@ -30,7 +61,7 @@ module Px4LogReader
30
61
 
31
62
  @field_list = {}
32
63
  end
33
- end
64
+ end
34
65
 
35
66
  def from_message( message )
36
67
 
@@ -65,9 +96,9 @@ module Px4LogReader
65
96
 
66
97
  end
67
98
 
68
- def to_message
69
- return LogMessage.new( FORMAT_MESSAGE, [ @type, @length, @name, @format, @fields_string ] )
70
- end
99
+ def to_message
100
+ return LogMessage.new( FORMAT_MESSAGE, [ @type, @length, @name, @format, @fields_string ] )
101
+ end
71
102
 
72
103
  class << self
73
104
 
@@ -156,12 +187,12 @@ module Px4LogReader
156
187
  corrected_fields[index] /= 1.0E-2
157
188
  else
158
189
  end
159
- end
190
+ end
160
191
 
161
- return corrected_fields.pack( @format_specifier )
162
- end
192
+ return corrected_fields.pack( @format_specifier )
193
+ end
163
194
 
164
- def to_s
195
+ def to_s
165
196
  puts "#{@name}( #{@type} ):"
166
197
  puts " length = #{@length}"
167
198
  puts " format = #{@format}"
@@ -1,3 +1,35 @@
1
+ #
2
+ # Copyright (c) 2016, Robert Glissmann
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ #
26
+
27
+ # %% license-end-token %%
28
+ #
29
+ # Author: Robert.Glissmann@gmail.com (Robert Glissmann)
30
+ #
31
+ #
32
+
1
33
  module Px4LogReader
2
34
 
3
35
  class MessageDescriptorCache
@@ -16,27 +48,27 @@ module Px4LogReader
16
48
 
17
49
  message_descriptors = {}
18
50
 
19
- if File.exist?( cache_filename )
20
- File.open( cache_filename, 'r' ) do |input|
21
- begin
22
- while ( ( data = input.read(4) ) && ( data.length == 4 ) ) do
23
- descriptor_size = data.unpack('L').first
24
- descriptor = Marshal.load( input.read( descriptor_size ) )
25
-
26
- message_descriptors[ descriptor.type ] = descriptor
27
- end
28
- rescue EOFError => error
29
- puts "Parsed #{@message_descriptions.size} cached message descriptions"
30
- rescue StandardError => error
31
- puts "#{error.class}: #{error.message}"
32
- puts error.backtrace.join("\n")
33
- end
34
- end
35
- else
36
- puts "Cache file '#{cache_filename}' not found"
37
- end
38
-
39
- return message_descriptors
51
+ if File.exist?( cache_filename )
52
+ File.open( cache_filename, 'r' ) do |input|
53
+ begin
54
+ while ( ( data = input.read(4) ) && ( data.length == 4 ) ) do
55
+ descriptor_size = data.unpack('L').first
56
+ descriptor = Marshal.load( input.read( descriptor_size ) )
57
+
58
+ message_descriptors[ descriptor.type ] = descriptor
59
+ end
60
+ rescue EOFError => error
61
+ puts "Parsed #{@message_descriptions.size} cached message descriptions"
62
+ rescue StandardError => error
63
+ puts "#{error.class}: #{error.message}"
64
+ puts error.backtrace.join("\n")
65
+ end
66
+ end
67
+ else
68
+ puts "Cache file '#{cache_filename}' not found"
69
+ end
70
+
71
+ return message_descriptors
40
72
  end
41
73
 
42
74
  def write_descriptors( message_descriptors )