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 +4 -4
- data/.gitignore +1 -1
- data/LICENSE.txt +23 -0
- data/README.md +2 -2
- data/Rakefile +34 -2
- data/lib/px4_log_reader/error.rb +43 -0
- data/lib/px4_log_reader/file_not_found_error.rb +41 -0
- data/lib/px4_log_reader/invalid_descriptor_error.rb +32 -14
- data/lib/px4_log_reader/log_buffer.rb +32 -0
- data/lib/px4_log_reader/log_file.rb +66 -35
- data/lib/px4_log_reader/log_message.rb +36 -5
- data/lib/px4_log_reader/message_descriptor.rb +46 -15
- data/lib/px4_log_reader/message_descriptor_cache.rb +53 -21
- data/lib/px4_log_reader/reader.rb +53 -21
- data/lib/px4_log_reader/version.rb +1 -1
- data/lib/px4_log_reader.rb +34 -0
- data/px4_log_reader.gemspec +44 -11
- data/test/test_files/pixhawk_descriptor_cache.px4mc +0 -0
- data/test/test_log_buffer.rb +32 -0
- data/test/test_log_file.rb +37 -1
- data/test/test_log_message.rb +74 -0
- data/test/test_message_descriptor.rb +32 -0
- data/test/test_message_descriptor_cache.rb +32 -0
- data/test/test_reader.rb +109 -1
- metadata +6 -4
- data/lib/px4log_parser.rb +0 -228
- data/test/test.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6071ae755e8bf6039fffcfddd4f08d38396509a
|
4
|
+
data.tar.gz: 1407b35a16ba00b5e2def9f4d2869269c7caaad4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1378a7bc49c3a8dc49acd0977712b8e696641b8d64f162a895097911c325b6648abc4f5c07e2be093c7b4708281d3493215d83a543091e12cb172a21e3633f50
|
7
|
+
data.tar.gz: 3818474002ba766ed277d0e98b39de6eef9d46211f4a2c921c30f02729e3068a50958e60008085e8c7c564497b619ab13b9b190ed0458a03b139de694a48694e
|
data/.gitignore
CHANGED
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('
|
28
|
+
att = [ messaged.get('Roll'), message.get('Pitch'), message.get('Yaw') ]
|
29
29
|
|
30
|
-
puts "ATT( @ #{context.find_by_name('GPS').get('
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
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
|
-
|
8
|
-
|
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
|
-
|
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
|
-
|
88
|
+
end
|
58
89
|
|
59
|
-
|
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
|
-
|
111
|
+
end
|
81
112
|
|
82
|
-
|
83
|
-
|
113
|
+
def self.read_message_header( buffered_io )
|
114
|
+
message_type = nil
|
84
115
|
|
85
|
-
|
116
|
+
begin
|
86
117
|
|
87
|
-
|
118
|
+
data = buffered_io.read(2)
|
88
119
|
|
89
|
-
|
120
|
+
if data && data.length == 2
|
90
121
|
|
91
|
-
|
122
|
+
while !data.empty? && message_type.nil? do
|
92
123
|
|
93
|
-
|
94
|
-
|
95
|
-
|
124
|
+
if ( byte = buffered_io.read(1) )
|
125
|
+
data << byte
|
126
|
+
end
|
96
127
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
-
|
104
|
-
|
134
|
+
end
|
135
|
+
end
|
105
136
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
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
|
-
|
114
|
-
|
144
|
+
return message_type
|
145
|
+
end
|
115
146
|
|
116
147
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
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
|
-
|
190
|
+
end
|
160
191
|
|
161
|
-
|
162
|
-
|
192
|
+
return corrected_fields.pack( @format_specifier )
|
193
|
+
end
|
163
194
|
|
164
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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 )
|