Class: OpenC3::Limits

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

Overview

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.

Constant Summary collapse

LATEST_PACKET_NAME =
'LATEST'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Limits

Returns a new instance of Limits.

Parameters:

  • config (PacketConfig)

    Packet configuration to use to access the limits information



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

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject

Parameters:

  • config (PacketConfig)

    The packet configuration which controls all other outputs



33
34
35
# File 'lib/openc3/packets/limits.rb', line 33

def config
  @config
end

Instance Method Details

#disable(target_name, packet_name, item_name) ⇒ Object

Disables limit checking for the specified item

Parameters:

  • target_name (String)

    The target name

  • packet_name (String)

    The packet name. Must be a defined packet name and not 'LATEST'.

  • item_name (String)

    The item name



89
90
91
# File 'lib/openc3/packets/limits.rb', line 89

def disable(target_name, packet_name, item_name)
  _get_packet(target_name, packet_name).disable_limits(item_name)
end

#enable(target_name, packet_name, item_name) ⇒ Object

Enables limit checking for the specified item

Parameters:

  • target_name (String)

    The target name

  • packet_name (String)

    The packet name. Must be a defined packet name and not 'LATEST'.

  • item_name (String)

    The item name



82
83
84
# File 'lib/openc3/packets/limits.rb', line 82

def enable(target_name, packet_name, item_name)
  _get_packet(target_name, packet_name).enable_limits(item_name)
end

#enabled?(target_name, packet_name, item_name) ⇒ Boolean

Checks whether the limits are enabled for the specified item

Parameters:

  • target_name (String)

    The target name

  • packet_name (String)

    The packet name. Must be a defined packet name and not 'LATEST'.

  • item_name (String)

    The item name

Returns:

  • (Boolean)


75
76
77
# File 'lib/openc3/packets/limits.rb', line 75

def enabled?(target_name, packet_name, item_name)
  _get_packet(target_name, packet_name).get_item(item_name).limits.enabled
end

#get(target_name, packet_name, item_name, limits_set = nil) ⇒ Array<limits_set, persistence, enabled, red_low, yellow_low, red_high, yellow_high, green_low (optional), green_high (optional)] Limits information

Get the limits for a telemetry item

Parameters:

  • target_name (String)

    Target Name

  • packet_name (String)

    Packet Name

  • item_name (String)

    Item Name

  • limits_set (String or Symbol or nil) (defaults to: nil)

    Desired Limits set. nil = current limits set

Returns:

  • (Array<limits_set, persistence, enabled, red_low, yellow_low, red_high, yellow_high, green_low (optional), green_high (optional)] Limits information)

    Array<limits_set, persistence, enabled, red_low, yellow_low, red_high, yellow_high, green_low (optional), green_high (optional)] Limits information



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/openc3/packets/limits.rb', line 100

def get(target_name, packet_name, item_name, limits_set = nil)
  limits = _get_packet(target_name, packet_name).get_item(item_name).limits
  if limits.values
    if limits_set
      limits_set = limits_set.to_s.upcase.intern
    else
      limits_set = System.limits_set
    end
    limits_for_set = limits.values[limits_set]
    if limits_for_set
      return [limits_set, limits.persistence_setting, limits.enabled, limits_for_set[0], limits_for_set[1], limits_for_set[2], limits_for_set[3], limits_for_set[4], limits_for_set[5]]
    else
      return [nil, nil, nil, nil, nil, nil, nil, nil, nil]
    end
  else
    return [nil, nil, nil, nil, nil, nil, nil, nil, nil]
  end
end

#groupsHash(String, Array)

Returns The defined limits groups.

Returns:



66
67
68
# File 'lib/openc3/packets/limits.rb', line 66

def groups
  return @config.limits_groups
end

#out_of_limitsArray<Array<String, String, String, Symbol>>

Return an array of arrays indicating all items in the packet that are out of limits

[[target name, packet name, item name, item limits state], ...]

Returns:



54
55
56
57
58
59
60
61
62
63
# File 'lib/openc3/packets/limits.rb', line 54

def out_of_limits
  items = []
  @config.telemetry.each do |target_name, target_packets|
    target_packets.each do |packet_name, packet|
      new_items = packet.out_of_limits
      items.concat(new_items)
    end
  end
  return items
end

#set(target_name, packet_name, item_name, red_low, yellow_low, yellow_high, red_high, green_low = nil, green_high = nil, limits_set = :CUSTOM, persistence = nil, enabled = true) ⇒ Array<limits_set, persistence, enabled, red_low, yellow_low, red_high, yellow_high, green_low (optional), green_high (optional)] Limits information

Set the limits for a telemetry item

Parameters:

  • target_name (String)

    Target Name

  • packet_name (String)

    Packet Name

  • item_name (String)

    Item Name

  • red_low (Float)

    Red Low Limit

  • yellow_low (Float)

    Yellow Low Limit

  • yellow_high (Float)

    Yellow High Limit

  • red_high (Float)

    Red High Limit

  • green_low (Float) (defaults to: nil)

    Green Low Limit

  • green_high (Float) (defaults to: nil)

    Green High Limit

  • limits_set (String or Symbol or nil) (defaults to: :CUSTOM)

    Desired Limits set. nil = current limits set, recommend using :CUSTOM

  • persistence (Integer) (defaults to: nil)

    The number of samples the value must be out of limits before detecting a limits change. nil = Leave unchanged

  • enabled (Boolean) (defaults to: true)

    If limits monitoring is enabled for this item

Returns:

  • (Array<limits_set, persistence, enabled, red_low, yellow_low, red_high, yellow_high, green_low (optional), green_high (optional)] Limits information)

    Array<limits_set, persistence, enabled, red_low, yellow_low, red_high, yellow_high, green_low (optional), green_high (optional)] Limits information



134
135
136
137
138
139
140
141
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
# File 'lib/openc3/packets/limits.rb', line 134

def set(target_name, packet_name, item_name, red_low, yellow_low, yellow_high, red_high, green_low = nil, green_high = nil, limits_set = :CUSTOM, persistence = nil, enabled = true)
  packet = _get_packet(target_name, packet_name)
  item = packet.get_item(item_name)
  limits = item.limits
  if limits_set
    limits_set = limits_set.to_s.upcase.intern
  else
    limits_set = System.limits_set
  end
  if !limits.values
    if limits_set == :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]
  unless limits_for_set
    limits.values[limits_set] = []
    limits_for_set = limits.values[limits_set]
  end
  limits_for_set[0] = red_low.to_f
  limits_for_set[1] = yellow_low.to_f
  limits_for_set[2] = yellow_high.to_f
  limits_for_set[3] = red_high.to_f
  limits_for_set.delete_at(5) if limits_for_set[5]
  limits_for_set.delete_at(4) if limits_for_set[4]
  if green_low && green_high
    limits_for_set[4] = green_low.to_f
    limits_for_set[5] = green_high.to_f
  end
  limits.enabled = enabled if not enabled.nil?
  limits.persistence_setting = Integer(persistence) if persistence
  packet.update_limits_items_cache(item)
  @config.limits_sets << limits_set
  @config.limits_sets.uniq!
  return [limits_set, limits.persistence_setting, limits.enabled, limits_for_set[0], limits_for_set[1], limits_for_set[2], limits_for_set[3], limits_for_set[4], limits_for_set[5]]
end

#setsArray<Symbol>

Returns The defined limits sets for all items in the packet. This will always include :DEFAULT.

Returns:

  • (Array<Symbol>)

    The defined limits sets for all items in the packet. This will always include :DEFAULT.



49
50
51
# File 'lib/openc3/packets/limits.rb', line 49

def sets
  return @config.limits_sets
end

#warningsArray<String>

Returns Array of strings listing all the warnings that were created while parsing the configuration file.

Returns:

  • (Array<String>)

    Array of strings listing all the warnings that were created while parsing the configuration file.



44
45
46
# File 'lib/openc3/packets/limits.rb', line 44

def warnings
  return @config.warnings
end