Class: OpenC3::IpReadConversion

Inherits:
Conversion show all
Defined in:
lib/openc3/conversions/ip_read_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

#initializeIpReadConversion

Returns a new instance of IpReadConversion.



23
24
25
26
27
# File 'lib/openc3/conversions/ip_read_conversion.rb', line 23

def initialize
  @converted_type = :STRING
  @converted_bit_size = 120
  @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



37
38
39
40
41
42
43
44
45
46
# File 'lib/openc3/conversions/ip_read_conversion.rb', line 37

def call(value, _packet, _buffer)
  byte4 = (value & 0xFF)
  value = value >> 8
  byte3 = (value & 0xFF)
  value = value >> 8
  byte2 = (value & 0xFF)
  value = value >> 8
  byte1 = (value & 0xFF)
  return "#{byte1}.#{byte2}.#{byte3}.#{byte4}"
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



55
56
57
# File 'lib/openc3/conversions/ip_read_conversion.rb', line 55

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



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

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