Method: OpenC3::DecomMicroservice#limits_change_callback

Defined in:
lib/openc3/microservices/decom_microservice.rb

#limits_change_callback(packet, item, old_limits_state, value, log_change) ⇒ Object

Called when an item in any packet changes limits states.

Parameters:

  • packet (Packet)

    Packet which has had an item change limits state

  • item (PacketItem)

    The item which has changed limits state

  • old_limits_state (Symbol)

    The previous state of the item. See PacketItemLimits#state

  • value (Object)

    The current value of the item

  • log_change (Boolean)

    Whether to log this limits change event



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/openc3/microservices/decom_microservice.rb', line 119

def limits_change_callback(packet, item, old_limits_state, value, log_change)
  return if @cancel_thread
  packet_time = packet.packet_time
  if value
    message = "#{packet.target_name} #{packet.packet_name} #{item.name} = #{value} is #{item.limits.state}"
  else
    message = "#{packet.target_name} #{packet.packet_name} #{item.name} is disabled"
  end
  message << " (#{packet.packet_time.sys.formatted})" if packet_time

  time_nsec = packet_time ? packet_time.to_nsec_from_epoch : Time.now.to_nsec_from_epoch
  if log_change
    case item.limits.state
    when :BLUE, :GREEN, :GREEN_LOW, :GREEN_HIGH
      @logger.info message
    when :YELLOW, :YELLOW_LOW, :YELLOW_HIGH
      @logger.warn(message, type: Logger::NOTIFICATION)
    when :RED, :RED_LOW, :RED_HIGH
      @logger.error(message, type: Logger::ALERT)
    end
  end

  # The openc3_limits_events topic can be listened to for all limits events, it is a continuous stream
  event = { type: :LIMITS_CHANGE, target_name: packet.target_name, packet_name: packet.packet_name,
            item_name: item.name, old_limits_state: old_limits_state.to_s, new_limits_state: item.limits.state.to_s,
            time_nsec: time_nsec, message: message.to_s }
  LimitsEventTopic.write(event, scope: @scope)

  if item.limits.response
    begin
      item.limits.response.call(packet, item, old_limits_state)
    rescue Exception => e
      @error = e
      @logger.error "#{packet.target_name} #{packet.packet_name} #{item.name} Limits Response Exception!"
      @logger.error "Called with old_state = #{old_limits_state}, new_state = #{item.limits.state}"
      @logger.error e.formatted
    end
  end
end