Class: OpenC3::PacketItemLimits

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePacketItemLimits

Create a PacketItemLimits



71
72
73
74
75
76
77
78
# File 'lib/openc3/packets/packet_item_limits.rb', line 71

def initialize
  @values = nil
  @enabled = false
  @state = nil
  @response = nil
  @persistence_setting = 1
  @persistence_count = 0
end

Instance Attribute Details

#enabledBoolean

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.

Returns:

  • (Boolean)

    Whether limits are enabled on this item



48
49
50
# File 'lib/openc3/packets/packet_item_limits.rb', line 48

def enabled
  @enabled
end

#persistence_countInteger

Current persistent count. The count will be reset to zero if the limits state hasn’t changed (i.e. remained :GREEN).

Returns:

  • (Integer)

    Current running persistence count



68
69
70
# File 'lib/openc3/packets/packet_item_limits.rb', line 68

def persistence_count
  @persistence_count
end

#persistence_settingInteger

Returns Number of out of limits samples at which the limits state will change.

Returns:

  • (Integer)

    Number of out of limits samples at which the limits state will change



63
64
65
# File 'lib/openc3/packets/packet_item_limits.rb', line 63

def persistence_setting
  @persistence_setting
end

#responseLimitsResponse

Returns Response method to be called on limits changes.

Returns:



59
60
61
# File 'lib/openc3/packets/packet_item_limits.rb', line 59

def response
  @response
end

#stateSymbol?

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.

Returns:

  • (Symbol, nil)

    Current limits state of the item



56
57
58
# File 'lib/openc3/packets/packet_item_limits.rb', line 56

def state
  @state
end

#valuesHash{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)].

Returns:

  • (Hash{Symbol=>Array})

    Hash of all the limits defined for this item. Must include a hash key of :DEFAULT which returns the default limits.



41
42
43
# File 'lib/openc3/packets/packet_item_limits.rb', line 41

def values
  @values
end

Class Method Details

.from_json(hash) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
# File 'lib/openc3/packets/packet_item_limits.rb', line 153

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



138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/openc3/packets/packet_item_limits.rb', line 138

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

#cloneObject Also known as: dup

Make a light weight clone of this limits



130
131
132
133
134
135
# File 'lib/openc3/packets/packet_item_limits.rb', line 130

def clone
  limits = super()
  limits.values = self.values.clone if self.values
  limits.response = self.response.clone if self.response
  limits
end