Class: OpenC3::StateParser

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parser) ⇒ StateParser

Returns a new instance of StateParser.

Parameters:



43
44
45
# File 'lib/openc3/packets/parsers/state_parser.rb', line 43

def initialize(parser)
  @parser = parser
end

Class Method Details

.parse(parser, packet, cmd_or_tlm, item, warnings) ⇒ Object

Parameters:

  • parser (ConfigParser)

    Configuration parser

  • packet (Packet)

    The current packet

  • cmd_or_tlm (String)

    Whether this is a command or telemetry packet

  • item (PacketItem)

    The packet item to create states on

  • warnings (Array<String>)

    Array of string warnings which will be appended with any warnings found when parsing the limits



33
34
35
36
37
38
39
40
# File 'lib/openc3/packets/parsers/state_parser.rb', line 33

def self.parse(parser, packet, cmd_or_tlm, item, warnings)
  raise parser.error("Items with LIMITS can't define STATE") if item.limits.values
  raise parser.error("Items with UNITS can't define STATE") if item.units

  parser = StateParser.new(parser)
  parser.verify_parameters(cmd_or_tlm)
  parser.create_state(packet, cmd_or_tlm, item, warnings)
end

Instance Method Details

#create_state(packet, cmd_or_tlm, item, warnings) ⇒ Object

Parameters:

  • packet (Packet)

    The current packet

  • cmd_or_tlm (String)

    Whether this is a command or telemetry packet

  • item (PacketItem)

    The packet item to create states on

  • warnings (Array<String>)

    Array of string warnings which will be appended with any warnings found when parsing the limits



64
65
66
67
68
69
70
71
# File 'lib/openc3/packets/parsers/state_parser.rb', line 64

def create_state(packet, cmd_or_tlm, item, warnings)
  item.states ||= {}

  state_name = get_state_name()
  check_for_duplicate_states(item, warnings)
  item.states[state_name] = get_state_value(item.data_type)
  parse_additional_parameters(packet, cmd_or_tlm, item)
end

#verify_parameters(cmd_or_tlm) ⇒ Object

Parameters:

  • cmd_or_tlm (String)

    Whether this is a command or telemetry packet



48
49
50
51
52
53
54
55
56
57
# File 'lib/openc3/packets/parsers/state_parser.rb', line 48

def verify_parameters(cmd_or_tlm)
  @usage = "STATE <STATE NAME> <STATE VALUE> "
  if cmd_or_tlm == PacketConfig::COMMAND
    @usage << "<HAZARDOUS / DISABLE_MESSAGES (Optional)> <Hazardous Description (Optional)>"
    @parser.verify_num_parameters(2, 4, @usage)
  else
    @usage << "<COLOR: GREEN/YELLOW/RED (Optional)>"
    @parser.verify_num_parameters(2, 3, @usage)
  end
end