Class: Crubyflie::LogBlock
- Inherits:
-
Object
- Object
- Crubyflie::LogBlock
- Defined in:
- lib/crubyflie/crazyflie/log.rb
Overview
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
Constant Summary collapse
- @@block_id_counter =
0
Instance Attribute Summary collapse
-
#data_callback ⇒ Object
writeonly
Sets the attribute data_callback.
-
#ident ⇒ Object
readonly
Returns the value of attribute ident.
-
#period ⇒ Object
readonly
Returns the value of attribute period.
Instance Method Summary collapse
-
#initialize(variables, opts = {}) ⇒ LogBlock
constructor
Initialize a LogBlock.
-
#unpack_log_data(data) ⇒ Object
Finds out the binary data by unpacking each of the variables depending on the number of bites for the declared size.
Constructor Details
#initialize(variables, opts = {}) ⇒ LogBlock
Initialize a LogBlock
118 119 120 121 122 123 124 125 126 |
# File 'lib/crubyflie/crazyflie/log.rb', line 118 def initialize(variables, opts={}) @variables = variables || [] @ident = @@block_id_counter @@block_id_counter += 1 @period = opts.delete(:period) || 10 @data_callback = nil end |
Instance Attribute Details
#data_callback=(value) ⇒ Object (writeonly)
Sets the attribute data_callback
112 113 114 |
# File 'lib/crubyflie/crazyflie/log.rb', line 112 def data_callback=(value) @data_callback = value end |
#ident ⇒ Object (readonly)
Returns the value of attribute ident.
111 112 113 |
# File 'lib/crubyflie/crazyflie/log.rb', line 111 def ident @ident end |
#period ⇒ Object (readonly)
Returns the value of attribute period.
111 112 113 |
# File 'lib/crubyflie/crazyflie/log.rb', line 111 def period @period end |
Instance Method Details
#unpack_log_data(data) ⇒ Object
Finds out the binary data by unpacking each of the variables depending on the number of bites for the declared size
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/crubyflie/crazyflie/log.rb', line 131 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 |