Class: Cosmos::LimitsItems
- Defined in:
- lib/cosmos/tools/limits_monitor/limits_monitor.rb
Constant Summary collapse
- UNKNOWN_ARRAY =
['UNKNOWN', 'UNKNOWN', nil]
Instance Attribute Summary collapse
-
#ignored ⇒ Array<String,String,String>
readonly
Target name, packet name, item name.
-
#initialized ⇒ Boolean
readonly
Whether the limits items have been fetched from the server.
Instance Method Summary collapse
-
#ignore(item) ⇒ Object
Ignore an item.
-
#ignored_items? ⇒ Boolean
Whether there are any items being ignored.
-
#initialize(new_item_callback, update_item_callback, clear_items_callback) ⇒ LimitsItems
constructor
A new instance of LimitsItems.
-
#open_config(filename) ⇒ String
Load a new configuration of ignored items and packets and reset.
-
#overall_state ⇒ Symbol
The overall limits state.
-
#process_events ⇒ Array<String,Symbol] String describing the event and a symbol indicating how the event string should be colored (:BLACK, :BLUE, :GREEN, :YELLOW, or :RED)
Calls get_limits_event to process all the server limits events that were subscribed to.
-
#remove_ignored(item) ⇒ Object
Remove an item from the ignored list to have it be displayed and count towards the overall limits state.
-
#request_reset ⇒ Object
Request that the limits items be refreshed from the server.
-
#save_config(filename) ⇒ String
Save the current configuration of ignored items and packets.
-
#update_values ⇒ Object
Update the values for all the out of limits items being tracked.
Constructor Details
#initialize(new_item_callback, update_item_callback, clear_items_callback) ⇒ LimitsItems
Returns a new instance of LimitsItems.
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/cosmos/tools/limits_monitor/limits_monitor.rb', line 67 def initialize(new_item_callback, update_item_callback, clear_items_callback) @new_item_callback = new_item_callback @update_item_callback = update_item_callback @clear_items_callback = clear_items_callback @ignored = [] @items = {} @out_of_limits = [] @queue_id = nil @limits_set = :DEFAULT request_reset() end |
Instance Attribute Details
#ignored ⇒ Array<String,String,String> (readonly)
Returns Target name, packet name, item name.
58 59 60 |
# File 'lib/cosmos/tools/limits_monitor/limits_monitor.rb', line 58 def ignored @ignored end |
#initialized ⇒ Boolean (readonly)
Returns Whether the limits items have been fetched from the server.
60 61 62 |
# File 'lib/cosmos/tools/limits_monitor/limits_monitor.rb', line 60 def initialized @initialized end |
Instance Method Details
#ignore(item) ⇒ Object
Ignore an item. Don’t display it in the GUI if it goes out of limits and don’t have it count towards the overall limit state. Still display its limits transitions in the log.
90 91 92 93 94 95 96 |
# File 'lib/cosmos/tools/limits_monitor/limits_monitor.rb', line 90 def ignore(item) index = @out_of_limits.delete_item(item) @items.delete("#{item[0]} #{item[1]} #{item[2]}") if index unless @ignored.includes_item?(item) @ignored << item end end |
#ignored_items? ⇒ Boolean
Returns Whether there are any items being ignored.
123 124 125 |
# File 'lib/cosmos/tools/limits_monitor/limits_monitor.rb', line 123 def ignored_items? !@ignored.empty? end |
#open_config(filename) ⇒ String
Load a new configuration of ignored items and packets and reset
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/cosmos/tools/limits_monitor/limits_monitor.rb', line 221 def open_config(filename) return "" unless filename unless Pathname.new(filename).absolute? filename = File.join(::Cosmos::USERPATH, 'config', 'tools', 'limits_monitor', filename) end return "Configuration file #{filename} not found!" unless File.exist?(filename) @ignored = [] begin parser = ConfigParser.new parser.parse_file(filename) do |keyword, params| case keyword # TODO: Eventually we can deprecate 'IGNORE' in favor # of 'IGNORE_ITEM' now that we also have 'IGNORE_PACKET' when 'IGNORE', 'IGNORE_ITEM' @ignored << ([params[0], params[1], params[2]]) when 'IGNORE_PACKET' @ignored << ([params[0], params[1], nil]) end end result = "#{filename} loaded. " result << "Warning: Some items ignored" if ignored_items? rescue => e result = "Error loading configuration : #{e.}" end # Since we may have loaded new ignored items we need to reset request_reset() result end |
#overall_state ⇒ Symbol
Returns The overall limits state. Returns :STALE if there is no connection to the server.
129 130 131 132 133 |
# File 'lib/cosmos/tools/limits_monitor/limits_monitor.rb', line 129 def overall_state get_overall_limits_state(@ignored) rescue DRb::DRbConnError :STALE end |
#process_events ⇒ Array<String,Symbol] String describing the event and a symbol indicating how the event string should be colored (:BLACK, :BLUE, :GREEN, :YELLOW, or :RED)
Calls get_limits_event to process all the server limits events that were subscribed to. This method should be called continuously until it returns nil which indicates no more events.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/cosmos/tools/limits_monitor/limits_monitor.rb', line 142 def process_events result = nil type = nil data = nil begin reset() unless @initialized # Get events non-blocking which is why we rescue ThreadError type, data = get_limits_event(@queue_id, true) rescue ThreadError # Do nothing (nominal exception if there are no events) rescue DRb::DRbConnError # The server is down so request a reset request_reset() end return result unless type case type when :LIMITS_CHANGE # The most common event: target, packet, item, state result = limits_change(data[0], data[1], data[2], data[4]) when :LIMITS_SET # Check if the overall limits set changed. If so we need to reset # to incorporate all the new limits. if @limits_set != data request_reset() result = ["INFO: Limits Set Changed to: #{data}\n", :BLACK] end when :LIMITS_SETTINGS # The limits settings for an individual item changed. Set our local tool # knowledge of the limits to match the server. begin System.limits.set(data[0], data[1], data[2], data[6], data[7], data[8], data[9], data[10], data[11], data[3], data[4], data[5]) result = ["INFO: Limits Settings Changed: #{data}\n", :BLACK] rescue # This can fail if we missed setting the DEFAULT limits set earlier end when :STALE_PACKET # A packet has gone stale: target, packet result = stale_packet(data[0], data[1]) end result end |
#remove_ignored(item) ⇒ Object
Remove an item from the ignored list to have it be displayed and count towards the overall limits state.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/cosmos/tools/limits_monitor/limits_monitor.rb', line 103 def remove_ignored(item) index = @ignored.delete_item(item) if index # If we deleted a packet we need to recalculate the stale packets if item[2].empty? get_stale(true).each do |target, packet| stale_packet(target, packet) end # We deleted an item so get all the current out of limit items else get_out_of_limits().each do |target, packet, item, state| limits_change(target, packet, item, state) end end end rescue DRb::DRbConnError # Do nothing end |
#request_reset ⇒ Object
Request that the limits items be refreshed from the server
80 81 82 |
# File 'lib/cosmos/tools/limits_monitor/limits_monitor.rb', line 80 def request_reset @initialized = false end |
#save_config(filename) ⇒ String
Save the current configuration of ignored items and packets.
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/cosmos/tools/limits_monitor/limits_monitor.rb', line 256 def save_config(filename) begin File.open(filename, "w") do |file| @ignored.each do |target, pkt_name, item_name| if item_name file.puts("IGNORE_ITEM #{target} #{pkt_name} #{item_name}") else file.puts("IGNORE_PACKET #{target} #{pkt_name}") end end end result = "#{filename} saved" rescue => e result = "Error saving configuration : #{e.}" end result end |
#update_values ⇒ Object
Update the values for all the out of limits items being tracked.
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/cosmos/tools/limits_monitor/limits_monitor.rb', line 189 def update_values # Reject any out of limits packets as they don't have values items = @out_of_limits.reject {|item| item[2].nil? } values, limits_states, limits_settings, limits_set = get_tlm_values(items, :WITH_UNITS) index = 0 items.each do |target_name, packet_name, item_name| begin # Update the limits settings each time we update values # to stay in sync with the Server. Responding to :LIMITS_SETTINGS # events isn't enough since we don't get those upon startup. System.limits.set(target_name, packet_name, item_name, limits_settings[index][0], limits_settings[index][1], limits_settings[index][2], limits_settings[index][3], limits_settings[index][4], limits_settings[index][5], limits_set) if limits_settings[index] rescue # This can fail if we missed setting the DEFAULT limits set earlier end name = "#{target_name} #{packet_name} #{item_name}" @update_item_callback.call(@items[name], values[index], limits_states[index], limits_set) index += 1 end rescue DRb::DRbConnError # Do nothing end |