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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b6071ae755e8bf6039fffcfddd4f08d38396509a
4
- data.tar.gz: 1407b35a16ba00b5e2def9f4d2869269c7caaad4
3
+ metadata.gz: 0490cff29bd96afe03a73177375e181a7c5ee9f1
4
+ data.tar.gz: 98611a918006a2d12bbaedf6656db34b39f2ed9f
5
5
  SHA512:
6
- metadata.gz: 1378a7bc49c3a8dc49acd0977712b8e696641b8d64f162a895097911c325b6648abc4f5c07e2be093c7b4708281d3493215d83a543091e12cb172a21e3633f50
7
- data.tar.gz: 3818474002ba766ed277d0e98b39de6eef9d46211f4a2c921c30f02729e3068a50958e60008085e8c7c564497b619ab13b9b190ed0458a03b139de694a48694e
6
+ metadata.gz: cf1783f773a16c17214a83167cf16ae520c6b3c59e2521068f54fd3620d6f3d244d1ca01b6546f3a85935a849279bd9cfc0b28c14004f247a5436f5102131ef4
7
+ data.tar.gz: 8f653267c2e89885394f3a2a990e28b9af69cda03eef319d65c90cc6b7431a8a75fe206d2e3d971c2024051b5324e5f01feade8ea784b447cb300d261fba4ba4
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ sudo: false
3
+ cache: bundler
4
+ rvm:
5
+ - 2.0.0
6
+ - 2.1.6
7
+ - 2.2.2
8
+ script: bundle exec rake test
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gem 'rake', '10.4.2'
3
+ gem 'minitest', '>= 5.4.0'
4
+
@@ -115,20 +115,24 @@ module Px4LogReader
115
115
 
116
116
  begin
117
117
 
118
- data = buffered_io.read(2)
118
+ data = buffered_io.read_nonblock( HEADER_MARKER.length )
119
119
 
120
- if data && data.length == 2
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.read(1) )
124
+ if ( byte = buffered_io.read_nonblock( 1 ) )
125
125
  data << byte
126
126
  end
127
127
 
128
- if data.unpack('CCC')[0,2] == HEADER_MARKER
129
- message_type = data.unpack('CCC').last & 0xFF
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 = data[1..-1]
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
@@ -209,7 +209,7 @@ module Px4LogReader
209
209
  FORMAT_MESSAGE = Px4LogReader::MessageDescriptor.new({
210
210
  name: 'FMT',
211
211
  type: 0x80,
212
- length: 89,
212
+ length: 86,
213
213
  format: 'BBnNZ',
214
214
  fields: [ "Type", "Length", "Name", "Format", "Labels" ] }).freeze
215
215
 
@@ -1,3 +1,3 @@
1
1
  module Px4LogReader
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
@@ -41,33 +41,96 @@ class TestLogFile < MiniTest::Test
41
41
  def teardown
42
42
  end
43
43
 
44
- def test_read_descriptors
44
+ class MockFileIO
45
45
 
46
- # log_file = open_log_file
47
- # descriptors = Px4LogReader::LogFile.read_descriptors( log_file )
46
+ attr_reader :buffer
48
47
 
49
- # puts "Found #{descriptors.count} descriptors"
50
- # descriptors.each do |type,descriptor|
51
- # puts " #{descriptor.name}"
52
- # end
48
+ def initialize
49
+ @buffer = ''
50
+ end
53
51
 
54
- # log_file.close
52
+ def reset
53
+ @buffer = ''
54
+ end
55
55
 
56
- # TODO
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 test_read_message
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
- # log_file.rewind
66
- # message = Px4LogReader::LogFile.read_message( log_file, descriptors )
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
- # puts message.descriptor
117
+ end
118
+
119
+ def test_write_message
120
+
121
+ mock_io = MockFileIO.new
69
122
 
70
- # TODO
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.6
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-08 00:00:00.000000000 Z
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