Class: OpenC3::IpWriteConversion

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

Instance Attribute Summary

Attributes inherited from Conversion

#converted_array_size, #converted_bit_size, #converted_type, #params

Instance Method Summary collapse

Methods inherited from Conversion

#as_json

Constructor Details

#initializeIpWriteConversion

Returns a new instance of IpWriteConversion.



18
19
20
21
22
# File 'lib/openc3/conversions/ip_write_conversion.rb', line 18

def initialize
  @converted_type = :UINT
  @converted_bit_size = 32
  @converted_array_size = nil
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



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/openc3/conversions/ip_write_conversion.rb', line 32

def call(value, _packet, _buffer)
  bytes = value.split('.')
  result = 0
  result += Integer(bytes[0])
  result = result << 8
  result += Integer(bytes[1])
  result = result << 8
  result += Integer(bytes[2])
  result = result << 8
  result += Integer(bytes[3])
  return result
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



52
53
54
# File 'lib/openc3/conversions/ip_write_conversion.rb', line 52

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



46
47
48
# File 'lib/openc3/conversions/ip_write_conversion.rb', line 46

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