Class: Crubyflie::ParamTOCElement

Inherits:
TOCElement show all
Defined in:
lib/crubyflie/crazyflie/param.rb

Overview

An element in the Parameters Table of Contents

Constant Summary collapse

C_RUBY_TYPE_MAP =

A map between crazyflie C types and ruby directives to interpret them. This will help parsing the parameter data

{
    0 => {
        :ctype     => "int8_t",
        :directive => 'c',
        :size      => 1
    },
    1 => {
        :ctype     => "int16_t",
        :directive => 's<',
        :size      => 2
    },
    2 => {
        :ctype     => "int32_t",
        :directive => 'l<',
        :size      => 4
    },
    3 => {
        :ctype     => "int64_t",
        :directive => 'q<',
        :size      => 8
    },
    5 => {
        :ctype     => "FP16",
        :directive => 'e',
        :size      => 2
    },
    6 => {
        :ctype     => "float",
        :directive => 'e',
        :size      => 4
    },
    7 => {
        :ctype     => "double",
        :directive => 'E',
        :size      => 8
    },
    8 => {
        :ctype     => "uint8_t",
        :directive => 'C',
        :size      => 1
    },
    9 => {
        :ctype     => "uint16_t",
        :directive => 'S<',
        :size      => 2
    },
    10 => {
        :ctype     => "uint32_t",
        :directive => 'L<',
        :size      => 4
    },
    11 => {
        :ctype     => "int64_t",
        :directive => 'Q<',
        :size      => '8'
    }
}

Instance Attribute Summary

Attributes inherited from TOCElement

#access, #ctype, #directive, #group, #ident, #name, #type_id

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ParamTOCElement

TODO:

It turns out this is the same as Log. Only the type conversion

Initializes a Param TOC element, which means interpreting the data in the packet and calling the parent class changes

Parameters:

  • data (String)

    a binary payload



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/crubyflie/crazyflie/param.rb', line 89

def initialize(data)
    # The group and name are zero-terminated strings from the 3rd byte
    group, name = data[2..-1].unpack('Z*Z*')
    ident = data[0].ord()
    ctype_id = data[1].ord() & 0b1111  #from 0 to 15
    ctype = C_RUBY_TYPE_MAP[ctype_id][:ctype]
    directive = C_RUBY_TYPE_MAP[ctype_id][:directive]
    access = data[1].ord() & 0b00010000 # 5th bit

    super({
              :ident => ident,
              :group => group,
              :name  => name,
              :ctype => ctype,
              :type_id => ctype_id,
              :directive => directive,
              :access => access
          })
end