Class: OpenC3::PacketItemLimits
- Defined in:
- lib/openc3/packets/packet_item_limits.rb
Overview
Maintains knowledge of limits for a PacketItem
Constant Summary collapse
- LIMITS_STATES =
Array of all limit states
[:RED, :RED_HIGH, :RED_LOW, :YELLOW, :YELLOW_HIGH, :YELLOW_LOW, :GREEN, :GREEN_HIGH, :GREEN_LOW, :BLUE, :STALE, nil]
- OUT_OF_LIMITS_STATES =
Array of all limit states which should be considered in error
[:RED, :RED_HIGH, :RED_LOW, :YELLOW, :YELLOW_HIGH, :YELLOW_LOW]
Instance Attribute Summary collapse
-
#enabled ⇒ Boolean
Every item effectively always has “limits” enabled because it can go from :STALE to nil as needed.
-
#persistence_count ⇒ Integer
Current persistent count.
-
#persistence_setting ⇒ Integer
Number of out of limits samples at which the limits state will change.
-
#response ⇒ LimitsResponse
Response method to be called on limits changes.
-
#state ⇒ Symbol?
Current limits state of the item.
-
#values ⇒ Hash{Symbol=>Array}
Hash of arrays - Hash key is uppercase symbol designating limits set.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(*a) ⇒ Object
-
#clone ⇒ Object
(also: #dup)
Make a light weight clone of this limits.
-
#initialize ⇒ PacketItemLimits
constructor
Create a PacketItemLimits.
Constructor Details
#initialize ⇒ PacketItemLimits
Create a PacketItemLimits
72 73 74 75 76 77 78 79 |
# File 'lib/openc3/packets/packet_item_limits.rb', line 72 def initialize @values = nil @enabled = false @state = nil @response = nil @persistence_setting = 1 @persistence_count = 0 end |
Instance Attribute Details
#enabled ⇒ Boolean
Every item effectively always has “limits” enabled because it can go from :STALE to nil as needed. This flag indicates whether an item with defined limit values can transition from nil to the various other states.
49 50 51 |
# File 'lib/openc3/packets/packet_item_limits.rb', line 49 def enabled @enabled end |
#persistence_count ⇒ Integer
Current persistent count. The count will be reset to zero if the limits state hasn’t changed (i.e. remained :GREEN).
69 70 71 |
# File 'lib/openc3/packets/packet_item_limits.rb', line 69 def persistence_count @persistence_count end |
#persistence_setting ⇒ Integer
Returns Number of out of limits samples at which the limits state will change.
64 65 66 |
# File 'lib/openc3/packets/packet_item_limits.rb', line 64 def persistence_setting @persistence_setting end |
#response ⇒ LimitsResponse
Returns Response method to be called on limits changes.
60 61 62 |
# File 'lib/openc3/packets/packet_item_limits.rb', line 60 def response @response end |
#state ⇒ Symbol?
Current limits state of the item. One of nil, :STALE, :BLUE, :GREEN, :GREEN_HIGH, :GREEN_LOW, :YELLOW, :YELLOW_HIGH, :YELLOW_LOW, :RED, :RED_HIGH, :RED_LOW. Items initialize to :STALE and change states as the item value changes. If the limits are disabled the state changes to nil. If a packet becomes stale the items state changes to :STALE.
57 58 59 |
# File 'lib/openc3/packets/packet_item_limits.rb', line 57 def state @state end |
#values ⇒ Hash{Symbol=>Array}
Hash of arrays - Hash key is uppercase symbol designating limits set. :DEFAULT limits set is required if item has limits. nil indicates the item does not have limits. For defined limits, each array in the hash contains [:RED_LOW, :YELLOW_LOW, :YELLOW_HIGH, :RED_HIGH, :GREEN_LOW (optional), GREEN_HIGH (optional)].
42 43 44 |
# File 'lib/openc3/packets/packet_item_limits.rb', line 42 def values @values end |
Class Method Details
.from_json(hash) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/openc3/packets/packet_item_limits.rb', line 154 def self.from_json(hash) limits = PacketItemLimits.new limits.values = hash['values'].transform_keys(&:to_sym) if hash['values'] limits.enabled = hash['enabled'] limits.state = hash['state'] ? hash['state'].to_sym : nil # Can't recreate a LimitsResponse class # limits.response = hash['response'] limits.persistence_setting = hash['persistence_setting'] if hash['persistence_setting'] limits.persistence_count = hash['persistence_count'] if hash['persistence_count'] limits end |
Instance Method Details
#as_json(*a) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/openc3/packets/packet_item_limits.rb', line 139 def as_json(*a) hash = {} hash['values'] = self.values hash['enabled'] = self.enabled hash['state'] = self.state if self.response hash['response'] = self.response.to_s else hash['response'] = nil end hash['persistence_setting'] = self.persistence_setting hash['persistence_count'] = self.persistence_count hash end |
#clone ⇒ Object Also known as: dup
Make a light weight clone of this limits
131 132 133 134 135 136 |
# File 'lib/openc3/packets/packet_item_limits.rb', line 131 def clone limits = super() limits.values = self.values.clone if self.values limits.response = self.response.clone if self.response limits end |