Class: OpenC3::ObjectReadConversion
- Inherits:
-
Conversion
- Object
- Conversion
- OpenC3::ObjectReadConversion
- Defined in:
- lib/openc3/conversions/object_read_conversion.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Conversion
#converted_array_size, #converted_bit_size, #converted_type
Instance Method Summary collapse
- #as_json(*a) ⇒ Object
-
#call(value, _packet, buffer) ⇒ Object
Perform the conversion on the value.
-
#initialize(cmd_or_tlm, target_name, packet_name) ⇒ ObjectReadConversion
constructor
A new instance of ObjectReadConversion.
- #lookup_packet ⇒ Object
-
#to_config(read_or_write) ⇒ String
Config fragment for this conversion.
-
#to_s ⇒ String
The conversion class.
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.
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_packet ⇒ Object
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.
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_s ⇒ String
Returns 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 |