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.
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/openc3/microservices/decom_microservice.rb', line 202 def limits_change_callback(packet, item, old_limits_state, value, log_change) return if @cancel_thread # Make a copy because packet_time is frozen packet_time = packet.packet_time.dup if value = "#{packet.target_name} #{packet.packet_name} #{item.name} = #{value} is #{item.limits.state}" if item.limits.values values = item.limits.values[System.limits_set] # Check if the state is RED_LOW, YELLOW_LOW, YELLOW_HIGH, RED_HIGH, GREEN_LOW, GREEN_HIGH if LIMITS_STATE_INDEX[item.limits.state] # Directly index into the values and return the value += " (#{values[LIMITS_STATE_INDEX[item.limits.state]]})" elsif item.limits.state == :GREEN # If we're green we display the green range (YELLOW_LOW - YELLOW_HIGH) += " (#{values[1]} to #{values[2]})" elsif item.limits.state == :BLUE # If we're blue we display the blue range (GREEN_LOW - GREEN_HIGH) += " (#{values[4]} to #{values[5]})" end end else = "#{packet.target_name} #{packet.packet_name} #{item.name} is disabled" end # Include the packet_time in the log json but not the log message time = { packet_time: packet_time.utc.iso8601(6) } if log_change case item.limits.state when :BLUE, :GREEN, :GREEN_LOW, :GREEN_HIGH # Only print INFO messages if we're changing ... not on initialization @logger.info(, other: time) if old_limits_state when :YELLOW, :YELLOW_LOW, :YELLOW_HIGH @logger.warn(, other: time, type: Logger::NOTIFICATION) when :RED, :RED_LOW, :RED_HIGH @logger.error(, other: time, 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: packet_time.to_nsec_from_epoch, message: .to_s } LimitsEventTopic.write(event, scope: @scope) if item.limits.response copied_packet = packet.deep_copy copied_item = packet.items[item.name] @limits_response_queue << [copied_packet, copied_item, old_limits_state] end end |