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



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

#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



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

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



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

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



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

def persistence_setting
  @persistence_setting
end

#responseLimitsResponse

Returns Response method to be called on limits changes.

Returns:



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

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



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

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.



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

#cloneObject 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