px4_log_reader 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/lib/px4_log_reader/log_file.rb +13 -9
- data/lib/px4_log_reader/message_descriptor.rb +1 -1
- data/lib/px4_log_reader/version.rb +1 -1
- data/test/test_log_file.rb +94 -16
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0490cff29bd96afe03a73177375e181a7c5ee9f1
|
4
|
+
data.tar.gz: 98611a918006a2d12bbaedf6656db34b39f2ed9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf1783f773a16c17214a83167cf16ae520c6b3c59e2521068f54fd3620d6f3d244d1ca01b6546f3a85935a849279bd9cfc0b28c14004f247a5436f5102131ef4
|
7
|
+
data.tar.gz: 8f653267c2e89885394f3a2a990e28b9af69cda03eef319d65c90cc6b7431a8a75fe206d2e3d971c2024051b5324e5f01feade8ea784b447cb300d261fba4ba4
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -115,20 +115,24 @@ module Px4LogReader
|
|
115
115
|
|
116
116
|
begin
|
117
117
|
|
118
|
-
data = buffered_io.
|
118
|
+
data = buffered_io.read_nonblock( HEADER_MARKER.length )
|
119
119
|
|
120
|
-
if data && data.length ==
|
120
|
+
if data && ( data.length == HEADER_MARKER.length )
|
121
121
|
|
122
122
|
while !data.empty? && message_type.nil? do
|
123
123
|
|
124
|
-
if ( byte = buffered_io.
|
124
|
+
if ( byte = buffered_io.read_nonblock( 1 ) )
|
125
125
|
data << byte
|
126
126
|
end
|
127
127
|
|
128
|
-
if data.
|
129
|
-
|
128
|
+
if data.length >= ( HEADER_MARKER.length + 1 )
|
129
|
+
if data.unpack('CCC')[0,2] == HEADER_MARKER
|
130
|
+
message_type = data.unpack('CCC').last & 0xFF
|
131
|
+
else
|
132
|
+
data = data[1..-1]
|
133
|
+
end
|
130
134
|
else
|
131
|
-
data =
|
135
|
+
data = []
|
132
136
|
end
|
133
137
|
|
134
138
|
end
|
@@ -146,9 +150,9 @@ module Px4LogReader
|
|
146
150
|
|
147
151
|
|
148
152
|
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
|
153
|
+
io.write( HEADER_MARKER.pack('CC') )
|
154
|
+
io.write( [ message.descriptor.type ].pack('C') )
|
155
|
+
io.write( message.pack )
|
152
156
|
end
|
153
157
|
|
154
158
|
end
|
data/test/test_log_file.rb
CHANGED
@@ -41,33 +41,96 @@ class TestLogFile < MiniTest::Test
|
|
41
41
|
def teardown
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
class MockFileIO
|
45
45
|
|
46
|
-
|
47
|
-
# descriptors = Px4LogReader::LogFile.read_descriptors( log_file )
|
46
|
+
attr_reader :buffer
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
# end
|
48
|
+
def initialize
|
49
|
+
@buffer = ''
|
50
|
+
end
|
53
51
|
|
54
|
-
|
52
|
+
def reset
|
53
|
+
@buffer = ''
|
54
|
+
end
|
55
55
|
|
56
|
-
|
56
|
+
def read( byte_count = nil )
|
57
|
+
data = nil
|
58
|
+
|
59
|
+
if byte_count >= @buffer.size
|
60
|
+
data = @buffer.dup
|
61
|
+
@buffer = ''
|
62
|
+
else
|
63
|
+
data = @buffer[ 0, byte_count ].dup
|
64
|
+
@buffer = @buffer[ byte_count .. -1 ]
|
65
|
+
end
|
66
|
+
|
67
|
+
data
|
68
|
+
end
|
69
|
+
|
70
|
+
def read_nonblock( byte_count = nil )
|
71
|
+
return read( byte_count )
|
72
|
+
end
|
73
|
+
|
74
|
+
def write( data )
|
75
|
+
@buffer << data
|
76
|
+
end
|
57
77
|
|
58
78
|
end
|
59
79
|
|
60
|
-
def
|
80
|
+
def test_read_header
|
81
|
+
|
82
|
+
# First, test that read_message_header returns null if the file is exhausted
|
83
|
+
# without finding a message header.
|
84
|
+
mock_io = MockFileIO.new
|
85
|
+
mock_io.write( rand_data( 256 ).pack('C*') )
|
86
|
+
|
87
|
+
assert_nil Px4LogReader::LogFile.read_message_header( mock_io )
|
88
|
+
assert_equal true, mock_io.buffer.empty?
|
89
|
+
|
90
|
+
|
91
|
+
# Insert a message header with type = 0x80 into the middle of the data.
|
92
|
+
mock_io = MockFileIO.new
|
93
|
+
|
94
|
+
test_data = rand_data( 256 )
|
95
|
+
test_data.concat( Px4LogReader::LogFile::HEADER_MARKER )
|
96
|
+
test_data.concat( [ Px4LogReader::FORMAT_MESSAGE.type ] )
|
97
|
+
test_data.concat( rand_data( 256 ) )
|
98
|
+
mock_io.write( test_data.pack('C*') )
|
99
|
+
|
100
|
+
assert_equal Px4LogReader::FORMAT_MESSAGE.type, Px4LogReader::LogFile.read_message_header( mock_io )
|
101
|
+
assert_equal 256, mock_io.buffer.size
|
102
|
+
|
103
|
+
assert_nil Px4LogReader::LogFile.read_message_header( mock_io )
|
104
|
+
assert_equal true, mock_io.buffer.empty?
|
61
105
|
|
62
|
-
# log_file = open_log_file
|
63
|
-
# descriptors = Px4LogReader::LogFile.read_descriptors( log_file )
|
64
106
|
|
65
|
-
#
|
66
|
-
|
107
|
+
# Test with a buffer that ends in a message header sync pattern.
|
108
|
+
mock_io = MockFileIO.new
|
109
|
+
|
110
|
+
test_data = rand_data( 64 )
|
111
|
+
test_data.concat( Px4LogReader::LogFile::HEADER_MARKER )
|
112
|
+
mock_io.write( test_data.pack('C*') )
|
113
|
+
|
114
|
+
assert_nil Px4LogReader::LogFile.read_message_header( mock_io )
|
115
|
+
assert_equal true, mock_io.buffer.empty?
|
67
116
|
|
68
|
-
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_write_message
|
120
|
+
|
121
|
+
mock_io = MockFileIO.new
|
69
122
|
|
70
|
-
|
123
|
+
fields = [ 0x24, 32, 'test', 'IIbMh', 'id,counts,flag,length,ord' ]
|
124
|
+
|
125
|
+
message = Px4LogReader::LogMessage.new(
|
126
|
+
Px4LogReader::FORMAT_MESSAGE,
|
127
|
+
fields )
|
128
|
+
|
129
|
+
Px4LogReader::LogFile.write_message( mock_io, message )
|
130
|
+
|
131
|
+
expected_length = Px4LogReader::FORMAT_MESSAGE.length + Px4LogReader::LogFile::HEADER_MARKER.length + 1
|
132
|
+
assert_equal expected_length, mock_io.buffer.length
|
133
|
+
assert_equal [ 0xA3, 0x95, 0x80 ], mock_io.buffer[0,3].unpack('C*')
|
71
134
|
|
72
135
|
end
|
73
136
|
|
@@ -77,4 +140,19 @@ class TestLogFile < MiniTest::Test
|
|
77
140
|
log_file
|
78
141
|
end
|
79
142
|
|
143
|
+
# Generate array of random bytes (0-255) that does not contain any message
|
144
|
+
# header bytes.
|
145
|
+
def rand_data( byte_count )
|
146
|
+
test_data = []
|
147
|
+
byte_count.times do
|
148
|
+
byte = 0
|
149
|
+
loop do
|
150
|
+
byte = rand(256)
|
151
|
+
break unless Px4LogReader::LogFile::HEADER_MARKER.include?( byte )
|
152
|
+
end
|
153
|
+
test_data << byte
|
154
|
+
end
|
155
|
+
return test_data
|
156
|
+
end
|
157
|
+
|
80
158
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: px4_log_reader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Glissmann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -32,6 +32,8 @@ extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
34
|
- ".gitignore"
|
35
|
+
- ".travis.yml"
|
36
|
+
- Gemfile
|
35
37
|
- LICENSE.txt
|
36
38
|
- README.md
|
37
39
|
- Rakefile
|