/// <summary> /// Sets the limit state of the condition. /// </summary> /// <param name="context">The system context.</param> /// <param name="limit">The bit masks specifying the current state.</param> public virtual void SetLimitState( ISystemContext context, LimitAlarmStates limit) { switch (limit) { case LimitAlarmStates.HighHigh: { this.LimitState.SetState(context, Objects.ExclusiveLimitStateMachineType_HighHigh); break; } case LimitAlarmStates.High: { this.LimitState.SetState(context, Objects.ExclusiveLimitStateMachineType_High); break; } case LimitAlarmStates.Low: { this.LimitState.SetState(context, Objects.ExclusiveLimitStateMachineType_Low); break; } case LimitAlarmStates.LowLow: { this.LimitState.SetState(context, Objects.ExclusiveLimitStateMachineType_LowLow); break; } default: { this.LimitState.SetState(context, 0); break; } } SetActiveEffectiveSubState(context, this.LimitState.CurrentState.Value, DateTime.UtcNow); base.SetActiveState(context, limit != LimitAlarmStates.Inactive); }
/// <summary> /// Sets the limit state of the condition. /// </summary> /// <param name="context">The system context.</param> /// <param name="limit">The bit masks specifying the current state.</param> public virtual void SetLimitState( ISystemContext context, LimitAlarmStates limit) { if (this.HighState != null) { UpdateState(this.HighState, ((limit & LimitAlarmStates.High) != 0 || (limit & LimitAlarmStates.HighHigh) != 0)); } if (this.HighHighState != null) { UpdateState(this.HighHighState, (limit & LimitAlarmStates.HighHigh) != 0); } if (this.LowState != null) { UpdateState(this.LowState, ((limit & LimitAlarmStates.Low) != 0 || (limit & LimitAlarmStates.LowLow) != 0)); } if (this.LowLowState != null) { UpdateState(this.LowLowState, (limit & LimitAlarmStates.LowLow) != 0); } // select an appropriate effective display name for the active state. TranslationInfo displayName = null; if ((limit & LimitAlarmStates.HighHigh) != 0) { displayName = new TranslationInfo( "ConditionStateHighHighActive", "en-US", ConditionStateNames.HighHighActive); } else if ((limit & LimitAlarmStates.LowLow) != 0) { displayName = new TranslationInfo( "ConditionStateLowLowActive", "en-US", ConditionStateNames.LowLowActive); } else if ((limit & LimitAlarmStates.High) != 0) { displayName = new TranslationInfo( "ConditionStateHighActive", "en-US", ConditionStateNames.HighActive); } else if ((limit & LimitAlarmStates.Low) != 0) { displayName = new TranslationInfo( "ConditionStateLowActive", "en-US", ConditionStateNames.LowActive); } else { displayName = new TranslationInfo( "ConditionStateInactive", "en-US", ConditionStateNames.Inactive); } // update the active superstae. SetActiveEffectiveSubState(context, new LocalizedText(displayName), DateTime.UtcNow); UpdateEffectiveState(context); }
/// <summary> /// Updates the alarm with a new state. /// </summary> /// <param name="node">The node.</param> /// <param name="alarm">The alarm.</param> private void UpdateAlarm(AlarmConditionState node, UnderlyingSystemAlarm alarm) { ISystemContext context = m_nodeManager.SystemContext; // remove old event. if (node.EventId.Value != null) { m_events.Remove(Utils.ToHexString(node.EventId.Value)); } // update the basic event information (include generating a unique id for the event). node.EventId.Value = Guid.NewGuid().ToByteArray(); node.Time.Value = DateTime.UtcNow; node.ReceiveTime.Value = node.Time.Value; // save the event for later lookup. m_events[Utils.ToHexString(node.EventId.Value)] = node; // determine the retain state. node.Retain.Value = true; if (alarm != null) { node.Time.Value = alarm.Time; node.Message.Value = new LocalizedText(alarm.Reason); // update the states. node.SetEnableState(context, (alarm.State & UnderlyingSystemAlarmStates.Enabled) != 0); node.SetAcknowledgedState(context, (alarm.State & UnderlyingSystemAlarmStates.Acknowledged) != 0); node.SetConfirmedState(context, (alarm.State & UnderlyingSystemAlarmStates.Confirmed) != 0); node.SetActiveState(context, (alarm.State & UnderlyingSystemAlarmStates.Active) != 0); node.SetSuppressedState(context, (alarm.State & UnderlyingSystemAlarmStates.Suppressed) != 0); // update other information. node.SetComment(context, alarm.Comment, alarm.UserName); node.SetSeverity(context, alarm.Severity); node.EnabledState.TransitionTime.Value = alarm.EnableTime; node.ActiveState.TransitionTime.Value = alarm.ActiveTime; // check for deleted items. if ((alarm.State & UnderlyingSystemAlarmStates.Deleted) != 0) { node.Retain.Value = false; } // handle high alarms. ExclusiveLimitAlarmState highAlarm = node as ExclusiveLimitAlarmState; if (highAlarm != null) { highAlarm.HighLimit.Value = alarm.Limits[0]; if ((alarm.State & UnderlyingSystemAlarmStates.High) != 0) { highAlarm.SetLimitState(context, LimitAlarmStates.High); } } // handle high-low alarms. NonExclusiveLimitAlarmState highLowAlarm = node as NonExclusiveLimitAlarmState; if (highLowAlarm != null) { highLowAlarm.HighHighLimit.Value = alarm.Limits[0]; highLowAlarm.HighLimit.Value = alarm.Limits[1]; highLowAlarm.LowLimit.Value = alarm.Limits[2]; highLowAlarm.LowLowLimit.Value = alarm.Limits[3]; LimitAlarmStates limit = LimitAlarmStates.Inactive; if ((alarm.State & UnderlyingSystemAlarmStates.HighHigh) != 0) { limit |= LimitAlarmStates.HighHigh; } if ((alarm.State & UnderlyingSystemAlarmStates.High) != 0) { limit |= LimitAlarmStates.High; } if ((alarm.State & UnderlyingSystemAlarmStates.Low) != 0) { limit |= LimitAlarmStates.Low; } if ((alarm.State & UnderlyingSystemAlarmStates.LowLow) != 0) { limit |= LimitAlarmStates.LowLow; } highLowAlarm.SetLimitState(context, limit); } } // not interested in disabled or inactive alarms. if (!node.EnabledState.Id.Value || !node.ActiveState.Id.Value) { node.Retain.Value = false; } }