Class: Cosmos::LimitsParser

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parser) ⇒ LimitsParser

Returns a new instance of LimitsParser.



36
37
38
# File 'lib/cosmos/packets/parsers/limits_parser.rb', line 36

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



28
29
30
31
32
33
34
# File 'lib/cosmos/packets/parsers/limits_parser.rb', line 28

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



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cosmos/packets/parsers/limits_parser.rb', line 51

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



41
42
43
44
45
46
47
48
# File 'lib/cosmos/packets/parsers/limits_parser.rb', line 41

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