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:



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

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



26
27
28
29
30
# File 'lib/openc3/packets/parsers/processor_parser.rb', line 26

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



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/openc3/packets/parsers/processor_parser.rb', line 49

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



39
40
41
42
43
44
45
46
# File 'lib/openc3/packets/parsers/processor_parser.rb', line 39

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