Class: OpenC3::BitReverseConversion

Inherits:
Conversion show all
Defined in:
lib/openc3/conversions/bit_reverse_conversion.rb

Instance Attribute Summary

Attributes inherited from Conversion

#converted_array_size, #converted_bit_size, #converted_type

Instance Method Summary collapse

Methods inherited from Conversion

#as_json

Constructor Details

#initialize(converted_type, converted_bit_size) ⇒ BitReverseConversion

Returns a new instance of BitReverseConversion.



23
24
25
26
27
28
29
30
# File 'lib/openc3/conversions/bit_reverse_conversion.rb', line 23

def initialize(converted_type, converted_bit_size)
  super()
  @converted_type = converted_type.to_s.upcase.intern
  @converted_bit_size = converted_bit_size.to_i
  if @converted_type == :FLOAT
    raise "Float Bit Reverse Not Yet Supported"
  end
end

Instance Method Details

#call(value, _packet, _buffer) ⇒ Object

Perform the conversion on the value.

Parameters:

  • value (Object)

    The value to convert

  • packet (Packet)

    The packet which contains the value. This can be useful to reach into the packet and use other values in the conversion.

  • buffer (String)

    The packet buffer

Returns:

  • The converted value



40
41
42
43
44
45
46
47
# File 'lib/openc3/conversions/bit_reverse_conversion.rb', line 40

def call(value, _packet, _buffer)
  reversed = 0
  @converted_bit_size.times do
    reversed = (reversed << 1) | (value & 1)
    value >>= 1
  end
  return reversed & ((2 ** @converted_bit_size) - 1)
end

#to_config(read_or_write) ⇒ String

Returns Config fragment for this conversion.

Parameters:

  • read_or_write (String)

    Either 'READ' or 'WRITE'

Returns:

  • (String)

    Config fragment for this conversion



56
57
58
# File 'lib/openc3/conversions/bit_reverse_conversion.rb', line 56

def to_config(read_or_write)
  "    #{read_or_write}_CONVERSION #{self.class.name.class_name_to_filename} #{@converted_type} #{@converted_bit_size}\n"
end

#to_sString

Returns The conversion class.

Returns:

  • (String)

    The conversion class



50
51
52
# File 'lib/openc3/conversions/bit_reverse_conversion.rb', line 50

def to_s
  "#{self.class.to_s.split('::')[-1]}.new(:#{@converted_type}, #{@converted_bit_size})"
end