Class: OpenC3::LimitsParser

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parser) ⇒ LimitsParser

Returns a new instance of LimitsParser.



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

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 limits on

  • warnings (Array<String>)

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



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

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

  parser = LimitsParser.new(parser)
  parser.verify_parameters(cmd_or_tlm)
  parser.create_limits(packet, item, warnings)
end

Instance Method Details

#create_limits(packet, item, warnings) ⇒ Object

Parameters:

  • packet (Packet)

    The packet the item should be added to



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/openc3/packets/parsers/limits_parser.rb', line 54

def create_limits(packet, item, warnings)
  limits_set = get_limits_set()
  initialize_limits_values(packet, item)
  ensure_consistency_with_default(packet, item, warnings)

  item.limits.values[limits_set] = get_values()
  item.limits.enabled = get_enabled()
  item.limits.persistence_setting = get_persistence()
  item.limits.persistence_count = 0

  packet.update_limits_items_cache(item)
  limits_set
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/limits_parser.rb', line 44

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

  @usage = "LIMITS <LIMITS SET> <PERSISTENCE> <ENABLED/DISABLED> <RED LOW LIMIT> <YELLOW LOW LIMIT> <YELLOW HIGH LIMIT> <RED HIGH LIMIT> <GREEN LOW LIMIT (Optional)> <GREEN HIGH LIMIT (Optional)>"
  @parser.verify_num_parameters(7, 9, @usage)
end