px4_log_reader 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/.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
data/lib/px4log_parser.rb
DELETED
@@ -1,228 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
# class Px4LogReader
|
6
|
-
|
7
|
-
# include PX4
|
8
|
-
|
9
|
-
# HEADER_MARKER = [0xA3,0x95]#.pack('CC').freeze
|
10
|
-
# HEADER_LENGTH = 3
|
11
|
-
|
12
|
-
# FORMAT_MESSAGE = Px4LogMessageDescription.new({
|
13
|
-
# name: 'FMT',
|
14
|
-
# type: 0x80,
|
15
|
-
# length: 89,
|
16
|
-
# format: 'BBnZ',
|
17
|
-
# fields: ["Type", "Length", "Name", "Format", "Labels"] }).freeze
|
18
|
-
|
19
|
-
# attr_reader :message_descriptions
|
20
|
-
# attr_reader :messages
|
21
|
-
# attr_reader :px4_log_format
|
22
|
-
|
23
|
-
# def initialize
|
24
|
-
# @message_descriptions = {}
|
25
|
-
# @messages = []
|
26
|
-
# @px4_log_format = false
|
27
|
-
# end
|
28
|
-
|
29
|
-
# def parse_log( filename, cache_filename=nil )
|
30
|
-
# @message_descriptions = {}
|
31
|
-
# @messages = []
|
32
|
-
|
33
|
-
# @file_size = File.size?(filename)
|
34
|
-
|
35
|
-
# if cache_filename && File.exist?( cache_filename )
|
36
|
-
# if File.exist?( cache_filename )
|
37
|
-
# File.open( cache_filename, 'r' ) do |io|
|
38
|
-
# begin
|
39
|
-
# loop do
|
40
|
-
# description_size = io.read_nonblock(4).unpack('L').first
|
41
|
-
# description = Marshal.load( io.read(description_size) )
|
42
|
-
|
43
|
-
# @message_descriptions[ description.type ] = description
|
44
|
-
# end
|
45
|
-
# rescue EOFError => error
|
46
|
-
# puts "Parsed #{@message_descriptions.size} cached message descriptions"
|
47
|
-
# # @message_descriptions.each do |message_type,description|
|
48
|
-
# # puts description
|
49
|
-
# # end
|
50
|
-
# rescue StandardError => error
|
51
|
-
# puts "#{error.class}: #{error.message}"
|
52
|
-
# puts error.backtrace.join("\n")
|
53
|
-
# end
|
54
|
-
# end
|
55
|
-
# else
|
56
|
-
# puts "Cache file '#{cache_filename}' not found"
|
57
|
-
# end
|
58
|
-
# else
|
59
|
-
# File.open( filename, 'r' ) do |io|
|
60
|
-
# read_formats( io, cache_filename )
|
61
|
-
# end
|
62
|
-
# end
|
63
|
-
|
64
|
-
# if @message_descriptions.size > 0
|
65
|
-
# File.open( filename, 'r' ) do |io|
|
66
|
-
# begin
|
67
|
-
# loop do
|
68
|
-
# message = read_message( io )
|
69
|
-
|
70
|
-
# if message.nil?
|
71
|
-
# puts "Failed to read message"
|
72
|
-
# break
|
73
|
-
# elsif message.description.name != "FMT"
|
74
|
-
# @messages << message
|
75
|
-
# end
|
76
|
-
|
77
|
-
# $stdout.printf "\rReading messages %d/%d", io.pos, @file_size
|
78
|
-
# end
|
79
|
-
# rescue StandardError => error
|
80
|
-
# puts "#{error.class}: #{error.message}"
|
81
|
-
# puts error.backtrace.join("\n")
|
82
|
-
# end
|
83
|
-
# end
|
84
|
-
# else
|
85
|
-
# raise "No message descriptions found"
|
86
|
-
# end
|
87
|
-
# puts
|
88
|
-
# end
|
89
|
-
|
90
|
-
# def read_message_header( io )
|
91
|
-
# byte = nil
|
92
|
-
|
93
|
-
# begin
|
94
|
-
|
95
|
-
# data = io.read(2)
|
96
|
-
|
97
|
-
# if data && data.length == 2
|
98
|
-
# loop do
|
99
|
-
|
100
|
-
# data << io.read_nonblock(1)
|
101
|
-
|
102
|
-
# # puts "#{data.unpack('CCC')[0,2]} == #{HEADER_MARKER}"
|
103
|
-
# if data.unpack('CCC')[0,2] == HEADER_MARKER
|
104
|
-
# byte = data.unpack('CCC').last & 0xFF
|
105
|
-
# # puts "Found message header #{data.unpack('CCC')}"
|
106
|
-
# # puts "message_type = #{'%02X'%byte}"
|
107
|
-
# break
|
108
|
-
# else
|
109
|
-
# data = data[1..-1]
|
110
|
-
# end
|
111
|
-
|
112
|
-
# end
|
113
|
-
# end
|
114
|
-
|
115
|
-
# rescue EOFError => error
|
116
|
-
# # Nothing to do.
|
117
|
-
# rescue StandardError => error
|
118
|
-
# puts error.message
|
119
|
-
# puts error.backtrace.join("\n")
|
120
|
-
# end
|
121
|
-
|
122
|
-
# return byte
|
123
|
-
# end
|
124
|
-
|
125
|
-
# def read_message( io )
|
126
|
-
|
127
|
-
# message = nil
|
128
|
-
# while message.nil? do
|
129
|
-
# message_type = read_message_header( io )
|
130
|
-
|
131
|
-
# if message_type && (message_type != FORMAT_MESSAGE.type)
|
132
|
-
# message_description = @message_descriptions[ message_type ]
|
133
|
-
|
134
|
-
# if message_description
|
135
|
-
# message_data = io.read( message_description.length - HEADER_LENGTH )
|
136
|
-
# message = message_description.parse_message( message_data )
|
137
|
-
# else
|
138
|
-
# puts "ERROR: Failed to get description for message of type '#{'0x%02X' % message_type}'"
|
139
|
-
# end
|
140
|
-
# elsif message_type.nil?
|
141
|
-
# break
|
142
|
-
# end
|
143
|
-
|
144
|
-
# # $stdout.printf "\rReading formats %d/%d", io.pos, @file_size
|
145
|
-
# end
|
146
|
-
|
147
|
-
# return message
|
148
|
-
# end
|
149
|
-
|
150
|
-
# def read_formats( io, cache_filename )
|
151
|
-
# loop do
|
152
|
-
# begin
|
153
|
-
# message_type = read_message_header( io )
|
154
|
-
|
155
|
-
# if message_type.nil?
|
156
|
-
# break
|
157
|
-
# elsif message_type == FORMAT_MESSAGE.type
|
158
|
-
# # puts "Found format message"
|
159
|
-
# message_description = Px4LogMessageDescription.new
|
160
|
-
# message_description.parse_from_io( io )
|
161
|
-
|
162
|
-
# unless @message_descriptions.keys.include? message_description.type
|
163
|
-
# @message_descriptions[message_description.type] = message_description
|
164
|
-
# end
|
165
|
-
|
166
|
-
# if message_description.name == "TIME"
|
167
|
-
# @px4_log_format = true
|
168
|
-
# end
|
169
|
-
# end
|
170
|
-
|
171
|
-
# $stdout.printf "\rReading formats %d/%d", io.pos, @file_size
|
172
|
-
|
173
|
-
# rescue StandardError => e
|
174
|
-
# puts "#{e.class}: #{e.message}"
|
175
|
-
# puts e.backtrace.join("\n")
|
176
|
-
# break
|
177
|
-
# end
|
178
|
-
# end
|
179
|
-
# $stdout.puts
|
180
|
-
|
181
|
-
# if cache_filename
|
182
|
-
# File.open( cache_filename, 'w+' ) do |io|
|
183
|
-
# @message_descriptions.each do |message_type,description|
|
184
|
-
# description_data = Marshal.dump( description )
|
185
|
-
# io.write( [ description_data.size ].pack('L') )
|
186
|
-
# io.write( description_data )
|
187
|
-
# end
|
188
|
-
# end
|
189
|
-
# end
|
190
|
-
# end
|
191
|
-
|
192
|
-
# end
|
193
|
-
|
194
|
-
|
195
|
-
# if ARGV.size == 2
|
196
|
-
# filename = ARGV[0]
|
197
|
-
# output_dir = ARGV[1]
|
198
|
-
# puts "Attempting to parse #{filename}"
|
199
|
-
|
200
|
-
# cache_filename = File.join( 'px4_csvs', "#{File.basename( filename, '.px4log' )}.px4log_description_cache" )
|
201
|
-
|
202
|
-
# log = Px4LogReader.new
|
203
|
-
# log.parse_log( filename, cache_filename )
|
204
|
-
|
205
|
-
# log.message_descriptions.each do |type,description|
|
206
|
-
# # puts description
|
207
|
-
# File.open(File.join(output_dir,"#{description.name.downcase}_log.csv"),"w+") do |io|
|
208
|
-
# io.puts description.to_csv_line
|
209
|
-
# end
|
210
|
-
# end
|
211
|
-
|
212
|
-
# last_timestamp = 0
|
213
|
-
# log.messages.each do |message|
|
214
|
-
# if message.description.name == "TIME"
|
215
|
-
# last_timestamp = message.get(0)
|
216
|
-
# end
|
217
|
-
|
218
|
-
# File.open(File.join(output_dir,"#{message.description.name.downcase}_log.csv"),"a+") do |io|
|
219
|
-
# io.puts message.to_csv_line(last_timestamp)
|
220
|
-
# end
|
221
|
-
# end
|
222
|
-
|
223
|
-
# else
|
224
|
-
|
225
|
-
# puts "Specify source and destination"
|
226
|
-
|
227
|
-
# end
|
228
|
-
|
data/test/test.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
if ARGV.size == 2
|
2
|
-
filename = ARGV[0]
|
3
|
-
output_dir = ARGV[1]
|
4
|
-
puts "Attempting to parse #{filename}"
|
5
|
-
|
6
|
-
cache_filename = File.join( 'px4_csvs', "#{File.basename( filename, '.px4log' )}.px4log_description_cache" )
|
7
|
-
|
8
|
-
log = Px4LogReader.new
|
9
|
-
log.parse_log( filename, cache_filename )
|
10
|
-
|
11
|
-
log.message_descriptions.each do |type,description|
|
12
|
-
# puts description
|
13
|
-
File.open(File.join(output_dir,"#{description.name.downcase}_log.csv"),"w+") do |io|
|
14
|
-
io.puts description.to_csv_line
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
last_timestamp = 0
|
19
|
-
log.messages.each do |message|
|
20
|
-
if message.description.name == "TIME"
|
21
|
-
last_timestamp = message.get(0)
|
22
|
-
end
|
23
|
-
|
24
|
-
File.open(File.join(output_dir,"#{message.description.name.downcase}_log.csv"),"a+") do |io|
|
25
|
-
io.puts message.to_csv_line(last_timestamp)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
else
|
30
|
-
|
31
|
-
puts "Specify source and destination"
|
32
|
-
|
33
|
-
end
|