class Crubyflie::LogBlock
A LogBlock
represents a piece of logging information that is received periodically from the Crazyflie
after having set the START_LOGGING command. Each LogBlock
will trigger a callback when a piece of data is received for it.
Note log blocks are added/removed by the Logging
class through the interface provided. So you should not need to use them directly
Attributes
data_callback[W]
ident[R]
period[R]
Public Class Methods
new(variables, opts={})
click to toggle source
Initialize a LogBlock
@param variables [Array] a set of LogConfVariables @param opts [Hash] current options:
:period, in centiseconds (100 = 1s)
# File lib/crubyflie/crazyflie/log.rb, line 117 def initialize(variables, opts={}) @variables = variables || [] @ident = @@block_id_counter @@block_id_counter += 1 @period = opts.delete(:period) || 10 @data_callback = nil end
Public Instance Methods
unpack_log_data(data)
click to toggle source
Finds out the binary data by unpacking each of the variables depending on the number of bites for the declared size @param data [String] Binary data string
# File lib/crubyflie/crazyflie/log.rb, line 130 def unpack_log_data(data) unpacked_data = {} position = 0 @variables.each do |var| fetch_as = var.fetch_as map = LogTOCElement::C_RUBY_TYPE_MAP size = map[fetch_as][:size] directive = map[fetch_as][:directive] name = var.name data_to_unpack = data[position..position + size - 1] value = data_to_unpack.unpack(directive).first unpacked_data[name] = value position += size end @data_callback.call(unpacked_data) if @data_callback end