Class: OpenC3::ObjectReadConversion

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

Direct Known Subclasses

ObjectWriteConversion

Instance Attribute Summary

Attributes inherited from Conversion

#converted_array_size, #converted_bit_size, #converted_type

Instance Method Summary collapse

Constructor Details

#initialize(cmd_or_tlm, target_name, packet_name) ⇒ ObjectReadConversion

Returns a new instance of ObjectReadConversion.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/openc3/conversions/object_read_conversion.rb', line 24

def initialize(cmd_or_tlm, target_name, packet_name)
  super()
  cmd_or_tlm = ConfigParser.handle_nil(cmd_or_tlm)
  if cmd_or_tlm
    @cmd_or_tlm = cmd_or_tlm.to_s.upcase.intern
    raise ArgumentError, "Unknown type: #{cmd_or_tlm}" unless %i(CMD TLM COMMAND TELEMETRY).include?(@cmd_or_tlm)
  else
    # Unknown - Will need to search
    @cmd_or_tlm = nil
  end
  @target_name = target_name.to_s.upcase
  @packet_name = packet_name.to_s.upcase
  @converted_type = :OBJECT
  @converted_bit_size = 0
end

Instance Method Details

#as_json(*a) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/openc3/conversions/object_read_conversion.rb', line 80

def as_json(*a)
  result = super(*a)
  result['cmd_or_tlm'] = @cmd_or_tlm
  result['target_name'] = @target_name
  result['packet_name'] = @packet_name
  return result
end

#call(value, _packet, buffer) ⇒ Object

Perform the conversion on the value.

Parameters:

  • value (String)

    The BLOCK data to make into a packet

  • packet (Packet)

    Unused

  • buffer (String)

    The packet buffer

Returns:

  • The converted value



63
64
65
66
67
# File 'lib/openc3/conversions/object_read_conversion.rb', line 63

def call(value, _packet, buffer)
  fill_packet = lookup_packet()
  fill_packet.buffer = value
  return fill_packet.read_all(:CONVERTED, buffer, true).to_h
end

#lookup_packetObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/openc3/conversions/object_read_conversion.rb', line 40

def lookup_packet
  if @cmd_or_tlm
    if @cmd_or_tlm == :CMD or @cmd_or_tlm == :COMMAND
      return System.commands.packet(@target_name, @packet_name)
    else
      return System.telemetry.packet(@target_name, @packet_name)
    end
  else
    # Always searches commands first
    begin
      return System.commands.packet(@target_name, @packet_name)
    rescue
      return System.telemetry.packet(@target_name, @packet_name)
    end
  end
end

#to_config(read_or_write) ⇒ String

Returns Config fragment for this conversion.

Parameters:

  • read_or_write (String)

    Not used

Returns:

  • (String)

    Config fragment for this conversion



76
77
78
# File 'lib/openc3/conversions/object_read_conversion.rb', line 76

def to_config(read_or_write)
  "    #{read_or_write}_CONVERSION #{self.class.name.class_name_to_filename} #{@cmd_or_tlm ? @cmd_or_tlm : "nil"} #{@target_name} #{@packet_name}\n"
end

#to_sString

Returns The conversion class.

Returns:

  • (String)

    The conversion class



70
71
72
# File 'lib/openc3/conversions/object_read_conversion.rb', line 70

def to_s
  "#{self.class.to_s.split('::')[-1]} #{@cmd_or_tlm ? @cmd_or_tlm : "nil"} #{@target_name} #{@packet_name}"
end