class Px4LogReader::LogBuffer
Attributes
data[R]
read_position[R]
write_position[R]
Public Class Methods
new( size )
click to toggle source
# File lib/px4_log_reader/log_buffer.rb, line 41 def initialize( size ) @data = Array.new( size, 0x00 ) @read_position = 0 @write_position = 0 end
Public Instance Methods
empty?()
click to toggle source
# File lib/px4_log_reader/log_buffer.rb, line 85 def empty? return ( @read_position == @write_position ) end
read( num_bytes )
click to toggle source
# File lib/px4_log_reader/log_buffer.rb, line 70 def read( num_bytes ) data = '' if !empty? last_index = @read_position + num_bytes last_index = @data.size if last_index > @data.size read_count = last_index - @read_position data = @data[ @read_position, read_count ].pack('C*') @read_position += read_count end return data end
reset()
click to toggle source
# File lib/px4_log_reader/log_buffer.rb, line 47 def reset @read_position = 0 @write_position = 0 end
write( file )
click to toggle source
# File lib/px4_log_reader/log_buffer.rb, line 52 def write( file ) while ( @write_position < @data.size ) do begin bytes = file.read( @data.size - @write_position ) if bytes write_bytes( bytes.unpack('C*') ) else break end rescue EOFError => error break end end end
Protected Instance Methods
write_bytes( bytes )
click to toggle source
# File lib/px4_log_reader/log_buffer.rb, line 91 def write_bytes( bytes ) bytes.each do |byte| if @write_position < @data.size @data[ @write_position ] = byte @write_position += 1 end end end