Class: Crubyflie::LogTOCElement

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

Overview

An element in the Logging Table of Contents A LogTOCElement knows what the type of data that comes in a #LogBlock and is able to initialize the #TOCElement from a TOC Logging packet

Constant Summary collapse

C_RUBY_TYPE_MAP =

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

{
    1 => {
        :ctype     => "uint8_t",
        :directive => 'C',
        :size      => 1
    },
    2 => {
        :ctype     => "uint16_t",
        :directive => 'S<',
        :size      => 2
    },
    3 => {
        :ctype     => "uint32_t",
        :directive => 'L<',
        :size      => 4
    },
    4 => {
        :ctype     => "int8_t",
        :directive => 'c',
        :size      => '1'
    },
    5 => {
        :ctype     => "int16_t",
        :directive => 's<',
        :size      => 2
    },
    6 => {
        :ctype     => "int32_t",
        :directive => 'l<',
        :size      => 4
    },
    7 => {
        :ctype     => "float",
        :directive => 'e',
        :size      => 4
    },
    # Unsupported
    # 8 => {
    #     :ctype     => "FP16",
    #     :directive => '',
    #     :size      => 2
    # }
}

Instance Attribute Summary

Attributes inherited from TOCElement

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

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ LogTOCElement

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

Parameters:

  • data (String)

    a binary payload


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/crubyflie/crazyflie/log.rb', line 78

def initialize(data)
    # unpack two null padded strings
    group, name = data[2..-1].unpack('Z*Z*')
    ident = data[0].ord()
    ctype_id = data[1].ord() & 0b1111 # go 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 # 0x10, the 5th bit

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