Class: OpenC3::ProcessorParser

Inherits:
Object
  • Object
show all
Defined in:
lib/openc3/packets/parsers/processor_parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parser, language = 'ruby') ⇒ ProcessorParser

Returns a new instance of ProcessorParser.

Parameters:



38
39
40
41
# File 'lib/openc3/packets/parsers/processor_parser.rb', line 38

def initialize(parser, language = 'ruby')
  @parser = parser
  @language = language
end

Class Method Details

.parse(parser, packet, cmd_or_tlm, language = 'ruby') ⇒ Object

Parameters:

  • parser (ConfigParser)

    Configuration parser

  • packet (Packet)

    The current packet

  • cmd_or_tlm (String)

    Whether this is a command or telemetry packet



31
32
33
34
35
# File 'lib/openc3/packets/parsers/processor_parser.rb', line 31

def self.parse(parser, packet, cmd_or_tlm, language = 'ruby')
  parser = ProcessorParser.new(parser, language)
  parser.verify_parameters(cmd_or_tlm)
  parser.create_processor(packet)
end

Instance Method Details

#create_processor(packet) ⇒ Object

Parameters:

  • packet (Packet)

    The packet the processor should be added to



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/openc3/packets/parsers/processor_parser.rb', line 54

def create_processor(packet)
  if @language == 'ruby'
    # require should be performed in target.txt
    klass = OpenC3.require_class(@parser.parameters[1])

    if @parser.parameters[2]
      processor = klass.new(*@parser.parameters[2..(@parser.parameters.length - 1)])
    else
      processor = klass.new
    end
    raise ArgumentError, "processor must be a OpenC3::Processor but is a #{processor.class}" unless OpenC3::Processor === processor
  else
    if @parser.parameters[2]
      processor = PythonProxy.new('Processor', @parser.parameters[1], *@parser.parameters[2..(@parser.parameters.length - 1)])
    else
      processor = PythonProxy.new('Processor', @parser.parameters[1], [])
    end
  end
  processor.name = get_processor_name()
  packet.processors[processor.name] = processor
end

#verify_parameters(cmd_or_tlm) ⇒ Object

Parameters:

  • cmd_or_tlm (String)

    Whether this is a command or telemetry packet



44
45
46
47
48
49
50
51
# File 'lib/openc3/packets/parsers/processor_parser.rb', line 44

def verify_parameters(cmd_or_tlm)
  if cmd_or_tlm == PacketConfig::COMMAND
    raise @parser.error("PROCESSOR only applies to telemetry packets")
  end

  @usage = "PROCESSOR <PROCESSOR NAME> <PROCESSOR CLASS FILENAME> <PROCESSOR SPECIFIC OPTIONS>"
  @parser.verify_num_parameters(2, nil, @usage)
end