Class: OpenC3::Conversion

Inherits:
Object show all
Defined in:
lib/openc3/conversions/conversion.rb

Overview

Performs a general conversion via the implementation of the call method

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConversion

Create a new conversion



35
36
37
38
39
# File 'lib/openc3/conversions/conversion.rb', line 35

def initialize
  @converted_type = nil
  @converted_bit_size = nil
  @converted_array_size = nil
end

Instance Attribute Details

#converted_array_sizeInteger (readonly)

Returns The size in bits of the converted array value.

Returns:

  • (Integer)

    The size in bits of the converted array value



32
33
34
# File 'lib/openc3/conversions/conversion.rb', line 32

def converted_array_size
  @converted_array_size
end

#converted_bit_sizeInteger (readonly)

Returns The size in bits of the converted value.

Returns:

  • (Integer)

    The size in bits of the converted value



30
31
32
# File 'lib/openc3/conversions/conversion.rb', line 30

def converted_bit_size
  @converted_bit_size
end

#converted_typeSymbol (readonly)

Returns The converted data type. Must be one of StructureItem#data_type.

Returns:



28
29
30
# File 'lib/openc3/conversions/conversion.rb', line 28

def converted_type
  @converted_type
end

Instance Method Details

#as_json(*_a) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/openc3/conversions/conversion.rb', line 64

def as_json(*_a)
  result = {}
  result['class'] = self.class.name.to_s
  result['converted_type'] = @converted_type if @converted_type
  result['converted_bit_size'] = @converted_bit_size if @converted_bit_size
  result['converted_array_size'] = @converted_array_size if @converted_array_size
  result
end

#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



49
50
51
# File 'lib/openc3/conversions/conversion.rb', line 49

def call(_value, _packet, _buffer)
  raise "call method must be defined by subclass"
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



60
61
62
# File 'lib/openc3/conversions/conversion.rb', line 60

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

#to_sString

Returns The conversion class.

Returns:

  • (String)

    The conversion class



54
55
56
# File 'lib/openc3/conversions/conversion.rb', line 54

def to_s
  self.class.to_s.split('::')[-1]
end