Class: Crubyflie::RadioAck

Inherits:
Object
  • Object
show all
Defined in:
lib/crubyflie/crazyradio/radio_ack.rb

Overview

An acknowlegdement packet from the Crazyflie

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ack = nil, powerDet = nil, retry_count = 0, data = []) ⇒ RadioAck

Initialize a Radio Ack

Parameters:

  • ack (TrueClass, FalseClass) (defaults to: nil)

    indicates if it is an ack

  • powerDet (TrueClass, FalseClass) (defaults to: nil)

    powerDet

  • retry_count (Integer) (defaults to: 0)

    the times we retried to send the packet

  • data (Array) (defaults to: [])

    the payload of the ack packet



29
30
31
32
33
34
# File 'lib/crubyflie/crazyradio/radio_ack.rb', line 29

def initialize(ack=nil, powerDet=nil, retry_count=0, data=[])
    @ack = ack
    @powerDet = powerDet
    @retry_count = retry_count
    @data = data
end

Instance Attribute Details

#ackObject

Returns the value of attribute ack.



22
23
24
# File 'lib/crubyflie/crazyradio/radio_ack.rb', line 22

def ack
  @ack
end

#dataObject

Returns the value of attribute data.



22
23
24
# File 'lib/crubyflie/crazyradio/radio_ack.rb', line 22

def data
  @data
end

#powerDetObject

Returns the value of attribute powerDet.



22
23
24
# File 'lib/crubyflie/crazyradio/radio_ack.rb', line 22

def powerDet
  @powerDet
end

#retry_countObject

Returns the value of attribute retry_count.



22
23
24
# File 'lib/crubyflie/crazyradio/radio_ack.rb', line 22

def retry_count
  @retry_count
end

Class Method Details

.from_raw(data, arc = 0) ⇒ RadioAck

Create from raw usb response

Parameters:

  • data (String)

    binary data

Returns:

  • (RadioAck)

    a properly initialized RadioAck



39
40
41
42
43
44
45
46
# File 'lib/crubyflie/crazyradio/radio_ack.rb', line 39

def self.from_raw(data, arc=0)
    response = data.unpack('C*')
    header = response.shift()
    ack = (header & 0x01) != 0
    powerDet = (header & 0x02) != 0
    retry_count = header != 0 ? header >> 4 : arc
    return RadioAck.new(ack, powerDet, retry_count, response)
end