Class: Px4LogReader::Reader
- Inherits:
-
Object
- Object
- Px4LogReader::Reader
- Defined in:
- lib/px4_log_reader/reader.rb
Instance Method Summary collapse
- #descriptors ⇒ Object
- #each_message(options = {}, &block) ⇒ Object
-
#initialize(file, options) ⇒ Reader
constructor
A new instance of Reader.
Constructor Details
#initialize(file, options) ⇒ Reader
Returns a new instance of Reader.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/px4_log_reader/reader.rb', line 60 def initialize( file, ) opts = { cache_filename: '', buffer_size_kb: 10 * 1024 }.merge( ) = {} @buffers = LogBufferArray.new @descriptor_cache = nil @context = Context.new @log_file = file # @buffers.set_file( @log_file, load_buffers: true ) @descriptor_cache = MessageDescriptorCache.new( opts[:cache_filename] ) end |
Instance Method Details
#descriptors ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/px4_log_reader/reader.rb', line 78 def descriptors if @log_file && .empty? if @descriptor_cache && @descriptor_cache.exist? = @descriptor_cache.read_descriptors else = LogFile::read_descriptors( @log_file, @descriptor_cache ) end [ FORMAT_MESSAGE.type ] = FORMAT_MESSAGE end return end |
#each_message(options = {}, &block) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/px4_log_reader/reader.rb', line 92 def ( = {}, &block ) opts ={ with: [], # white list - empty means all minus those in without list without: ['FMT'] # black list - includes types or names }.merge( || {} ) opts[:with].map! do |val| if val.class == String descriptor = descriptors.values.find { |desc| desc.name == val } val = descriptor.type end end opts[:without].map! do |val| if val.class == String descriptor = descriptors.values.find { |desc| desc.name == val } if descriptor val = descriptor.type else raise "Failed to find descriptor with name '#{val}'" end end end if block_given? loop do = LogFile::( @log_file, ) break if .nil? # Added message to the set of latest messages. @context.set( ) if opts[:with].empty? if !opts[:without].include?( .descriptor.name ) yield , @context end else if opts[:with].include?( .descriptor.type ) yield , @context end end end else raise BlockRequiredError.new end end |