lib/cosmos/packets/limits.rb in cosmos-4.5.2-java vs lib/cosmos/packets/limits.rb in cosmos-5.0.2.pre.beta2

- old
+ new

@@ -1,26 +1,35 @@ # encoding: ascii-8bit -# Copyright 2014 Ball Aerospace & Technologies Corp. +# Copyright 2022 Ball Aerospace & Technologies Corp. # All Rights Reserved. # # This program is free software; you can modify and/or redistribute it -# under the terms of the GNU General Public License +# under the terms of the GNU Affero General Public License # as published by the Free Software Foundation; version 3 with # attribution addendums as found in the LICENSE.txt +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# This program may also be used under the terms of a commercial or +# enterprise edition license of COSMOS if purchased from the +# copyright holder require 'cosmos/packets/packet_config' module Cosmos - # Limits uses PacketConfig to parse the command and telemetry # configuration files. It provides the API layer which other classes use to # access information about and manipulate limits. This includes getting, # setting and checking individual limit items as well as manipulating limits # groups. class Limits - attr_reader :config + # @param config [PacketConfig] The packet configuration which controls all other outputs + attr_accessor :config LATEST_PACKET_NAME = 'LATEST'.freeze # @param config [PacketConfig] Packet configuration to use to access the # limits information @@ -36,16 +45,10 @@ # (see PacketConfig#limits_sets) def sets return @config.limits_sets end - # @param config [PacketConfig] Set the packet configuration to a new - # configuration. This will change everything this class returns! - def config=(config) - @config = config - end - # (see Cosmos::Packet#out_of_limits) def out_of_limits items = [] @config.telemetry.each do |target_name, target_packets| target_packets.each do |packet_name, packet| @@ -79,10 +82,11 @@ items_out_of_limits.concat(packet.out_of_limits) end end items_out_of_limits.each do |target_name, packet_name, item_name, limits_state| next if ignored_items && includes_item?(ignored_items, target_name, packet_name, item_name) + case overall # If our overall state is currently blue or green we can go to any state when :BLUE, :GREEN, :GREEN_HIGH, :GREEN_LOW overall = limits_state # If our overal state is yellow we can only go higher to red @@ -208,11 +212,11 @@ else limits_set = System.limits_set end if !limits.values if limits_set == :DEFAULT - limits.values = {:DEFAULT => []} + limits.values = { :DEFAULT => [] } else raise "DEFAULT limits must be defined for #{target_name} #{packet_name} #{item_name} before setting limits set #{limits_set}" end end limits_for_set = limits.values[limits_set] @@ -240,22 +244,25 @@ protected def get_packet(target_name, packet_name) raise "LATEST packet not valid" if packet_name.upcase == LATEST_PACKET_NAME + packets = @config.telemetry[target_name.to_s.upcase] raise "Telemetry target '#{target_name.to_s.upcase}' does not exist" unless packets + packet = packets[packet_name.to_s.upcase] raise "Telemetry packet '#{target_name.to_s.upcase} #{packet_name.to_s.upcase}' does not exist" unless packet + return packet end def includes_item?(ignored_items, target_name, packet_name, item_name) ignored_items.each do |array_target_name, array_packet_name, array_item_name| - if ((array_target_name == target_name) && - (array_packet_name == packet_name) && - # If the item name is nil we're ignoring an entire packet - (array_item_name == item_name || array_item_name.nil?)) + if (array_target_name == target_name) && + (array_packet_name == packet_name) && + # If the item name is nil we're ignoring an entire packet + (array_item_name == item_name || array_item_name.nil?) return true end end return false end