//******************************************************************************************************
// StatusFlags.cs - Gbtc
//
// Copyright © 2017, Grid Protection Alliance. All Rights Reserved.
//
// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
// the NOTICE file distributed with this work for additional information regarding copyright ownership.
// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
// file except in compliance with the License. You may obtain a copy of the License at:
//
// http://opensource.org/licenses/MIT
//
// Unless agreed to in writing, the subject software distributed under the License is distributed on an
// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
// License for the specific language governing permissions and limitations.
//
// Code Modification History:
// ----------------------------------------------------------------------------------------------------
// 03/14/2017 - J. Ritchie Carroll
// Generated original version of source code.
//
//******************************************************************************************************
using System;
using GSF.TimeSeries;
namespace eDNAAdapters
{
#region [ Enumerations ]
///
/// Defines eDNA data types.
///
public enum DataType
{
///
/// Analog data type.
///
Analog,
///
/// Digital data type.
///
Digital
}
///
/// eDNA point status flags.
///
[Flags]
public enum StatusFlags : short
{
///
/// Evaluate status.
///
EVAL = -1,
///
/// Not yet initialized.
///
RTSTAT_UNUSED = 0,
///
/// Has been initialized.
///
RTSTAT_INITED = 1,
///
/// Has been updated.
///
RTSTAT_UPDATED = 2,
///
/// Data is bad.
///
RTSTAT_UNRELIABLE = 4,
///
/// Sensor bad.
///
RTSTAT_OOR = 8,
///
/// Low-low alarm.
///
RTSTAT_LL_ALARM = 16,
///
/// Low alarm.
///
RTSTAT_L_ALARM = 32,
///
/// High alarm.
///
RTSTAT_H_ALARM = 64,
///
/// High-high alarm.
///
RTSTAT_HH_ALARM = 128,
///
/// Manual input.
///
RTSTAT_MANUAL = 256,
///
/// Reset not acknowledged.
///
RTSTAT_UNACKRST = 512,
///
/// Alarm not acknowledged.
///
RTSTAT_UNACKAL = 1024,
///
/// Tickle flags for history repeat.
///
RTSTAT_REPEAT = 2048,
///
/// Digital point type.
///
RTSTAT_DIGITAL_IN = 4096,
///
/// Analog point type.
///
RTSTAT_ANALOG_OUT = 8192,
///
/// Digital point type.
///
RTSTAT_DIGITAL_OUT = 12288,
///
/// Analog Point Initialized, Received Value, Reliable Quality.
///
ANALOG_OK = 3,
///
/// Analog Point Initialized, Received Value, Unreliable Quality,
///
ANALOG_UNRELIABLE = 7,
///
/// Analog Point Initialized, Received Value, Reliable Quality, Value goes below Low Warning Threshold.
///
ANALOG_LOW_WARNING = 35,
///
/// Analog Point Initialized, Received Value, Reliable Quality, Value goes below Low Alarm Threshold.
///
ANALOG_LOW_ALARM = 51,
///
/// Analog Point Initialized, Received Value, Reliable Quality, Value goes below Low Out of Range Threshold.
///
ANALOG_LOW_OUT_OF_RANGE = 59,
///
/// Analog Point Initialized, Received Value, Reliable Quality, Value goes above High Warning Threshold.
///
ANALOG_HIGH_WARNING = 67,
///
/// Analog Point Initialized, Received Value, Reliable Quality, Value goes above High Alarm Threshold.
///
ANALOG_HIGH_ALARM = 195,
///
/// Analog Point Initialized, Received Value, Reliable Quality, Value goes above High Out of Range Threshold.
///
ANALOG_HIGH_OUT_OF_RANGE = 203,
///
/// Analog Point Initialized, Received Value, Manually Input into eDNA, Reliable Quality.
///
ANALOG_OK_MANUAL = 259,
///
/// Analog Point Initialized, Received Value, Manually Input into eDNA, Unreliable Quality.
///
ANALOG_UNRELIABLE_MANUAL = 263,
///
/// Analog Point Initialized, Received Value, Reliable Quality, Reset Unacknowledged Alarm.
///
ANALOG_OK_UNACK_ALARM = 515,
///
/// Analog Point Initialized, Received Value, Reliable Quality, Value goes below Low Warning Threshold, Unacknowledged Alarm.
///
ANALOG_LOW_WARNING_UNACK_ALARM = 1059,
///
/// Analog Point Initialized, Received Value, Reliable Quality, Value goes below Low Alarm Threshold, Unacknowledged Alarm.
///
ANALOG_LOW_ALARM_UNACK_ALARM = 1075,
///
/// Analog Point Initialized, Received Value, Reliable Quality, Value goes below Low Out of Range Threshold, Unacknowledged Alarm.
///
ANALOG_LOW_OUT_OF_RANGE_UNACK_ALARM = 1083,
///
/// Analog Point Initialized, Received Value, Reliable Quality, Value goes above High Warning Threshold, Unacknowledged Alarm.
///
ANALOG_HIGH_WARNING_UNACK_ALARM = 1091,
///
/// Analog Point Initialized, Received Value, Reliable Quality, Value goes above High Alarm Threshold, Unacknowledged Alarm.
///
ANALOG_HIGH_ALARM_UNACK_ALARM = 1219,
///
/// Analog Point Initialized, Received Value, Reliable Quality, Value goes above High Out of Range Threshold, Unacknowledged Alarm.
///
ANALOG_HIGH_OUT_OF_RANGE_UNACK_ALARM = 1227,
///
/// Analog Point Initialized, Received Value, Reliable Quality, Repeat History Value (Forced).
///
ANALOG_OK_FORCED = 2051,
///
/// Digital Point Initialized, not received a value.
///
DIGITAL_NOT_UPDATED = 4097,
///
/// Digital Point Initialized, Received Value, Reliable Quality, Value = 0.
///
DIGITAL_OK_NOT_SET = 4099,
///
/// Digital Point Initialized, Received Value, Reliable Quality, Value = 1.
///
DIGITAL_OK_SET = 4163,
///
/// Digital Point Initialized, Received Value, Unreliable Quality, Value = 0.
///
DIGITAL_UNRELIABLE_NOT_SET = 4103,
///
/// Digital Point Initialized, Received Value, Unreliable Quality, Value = 1.
///
DIGITAL_UNRELIABLE_SET = 4167,
///
/// Digital Point Initialized, Received Value, Reliable Quality, Value = 0, Repeat History Value (Forced).
///
DIGITAL_OK_NOT_SET_FORCED = 6147,
///
/// Digital Point Initialized, Received Value, Reliable Quality, Value = 1, Repeat History Value (Forced).
///
DIGITAL_OK_SET_FORCED = 6211,
///
/// Digital Point Initialized, Received Value, Reliable Quality, Value = 0, Warning Flag Set.
///
DIGITAL_WARNING_NOT_SET = 4227,
///
/// Digital Point Initialized, Received Value, Reliable Quality, Value = 1, Warning Flag Set.
///
DIGITAL_WARNING_SET = 4291,
///
/// Digital Point Initialized, Received Value, Reliable Quality, Value = 0, Chattering Flag Set.
///
DIGITAL_CHATTERING_NOT_SET = 4115,
///
/// Digital Point Initialized, Received Value, Reliable Quality, Value = 1, Chattering Flag Set.
///
DIGITAL_CHATTERING_SET = 4179
}
#endregion
///
/// Defines static methods for mapping between eDNA status flags and full measurement states.
///
public static class MeasurementStateMappingExtensions
{
///
/// Maps to eDNA status (short value).
///
/// Flags to map.
/// Data type of measurement.
/// Flag that determines if digital value is set.
/// eDNA status mapped from .
public static short MapToStatus(this MeasurementStateFlags stateFlags, DataType type = DataType.Analog, bool digitalSet = false)
{
return (short)stateFlags.MapToStatusFlags(type, digitalSet);
}
///
/// Maps to .
///
/// Flags to map.
/// Data type of measurement.
/// Flag that determines if digital value is set.
/// mapped from .
public static StatusFlags MapToStatusFlags(this MeasurementStateFlags stateFlags, DataType type = DataType.Analog, bool digitalSet = false)
{
StatusFlags status = StatusFlags.RTSTAT_UNUSED;
if ((stateFlags & MeasurementStateFlags.ReceivedAsBad) > 0)
status |= StatusFlags.RTSTAT_UNRELIABLE;
if ((stateFlags & MeasurementStateFlags.BadTime) > 0 ||
(stateFlags & MeasurementStateFlags.SuspectTime) > 0 ||
(stateFlags & MeasurementStateFlags.LateTimeAlarm) > 0 ||
(stateFlags & MeasurementStateFlags.FutureTimeAlarm) > 0 ||
(stateFlags & MeasurementStateFlags.SystemError) > 0 ||
(stateFlags & MeasurementStateFlags.SystemWarning) > 0)
status |= StatusFlags.RTSTAT_OOR;
if (type == DataType.Analog)
{
// Point is analog
if (stateFlags == MeasurementStateFlags.Normal)
{
status = StatusFlags.ANALOG_OK;
}
else
{
if ((stateFlags & MeasurementStateFlags.BadData) > 0 ||
(stateFlags & MeasurementStateFlags.SuspectData) > 0 ||
(stateFlags & MeasurementStateFlags.FlatlineAlarm) > 0 ||
(stateFlags & MeasurementStateFlags.ComparisonAlarm) > 0 ||
(stateFlags & MeasurementStateFlags.ROCAlarm) > 0 ||
(stateFlags & MeasurementStateFlags.CalculationError) > 0 ||
(stateFlags & MeasurementStateFlags.CalculationWarning) > 0 ||
(stateFlags & MeasurementStateFlags.MeasurementError) > 0)
status |= StatusFlags.ANALOG_UNRELIABLE;
if ((stateFlags & MeasurementStateFlags.OverRangeError) > 0)
status |= StatusFlags.ANALOG_HIGH_OUT_OF_RANGE;
if ((stateFlags & MeasurementStateFlags.UnderRangeError) > 0)
status |= StatusFlags.ANALOG_LOW_OUT_OF_RANGE;
if ((stateFlags & MeasurementStateFlags.AlarmHigh) > 0)
status |= StatusFlags.ANALOG_HIGH_ALARM;
if ((stateFlags & MeasurementStateFlags.AlarmLow) > 0)
status |= StatusFlags.ANALOG_LOW_ALARM;
if ((stateFlags & MeasurementStateFlags.WarningHigh) > 0)
status |= StatusFlags.ANALOG_HIGH_WARNING;
if ((stateFlags & MeasurementStateFlags.WarningLow) > 0)
status |= StatusFlags.ANALOG_LOW_WARNING;
}
}
else if (type == DataType.Digital)
{
// Point is digital
if (digitalSet)
{
if (stateFlags == MeasurementStateFlags.Normal)
{
status = StatusFlags.DIGITAL_OK_SET;
}
else
{
if ((stateFlags & MeasurementStateFlags.BadData) > 0 ||
(stateFlags & MeasurementStateFlags.SuspectData) > 0 ||
(stateFlags & MeasurementStateFlags.FlatlineAlarm) > 0 ||
(stateFlags & MeasurementStateFlags.ComparisonAlarm) > 0 ||
(stateFlags & MeasurementStateFlags.ROCAlarm) > 0 ||
(stateFlags & MeasurementStateFlags.CalculationError) > 0 ||
(stateFlags & MeasurementStateFlags.CalculationWarning) > 0 ||
(stateFlags & MeasurementStateFlags.MeasurementError) > 0)
status |= StatusFlags.DIGITAL_UNRELIABLE_SET;
if ((stateFlags & MeasurementStateFlags.OverRangeError) > 0 ||
(stateFlags & MeasurementStateFlags.UnderRangeError) > 0 ||
(stateFlags & MeasurementStateFlags.AlarmHigh) > 0 ||
(stateFlags & MeasurementStateFlags.AlarmLow) > 0 ||
(stateFlags & MeasurementStateFlags.WarningHigh) > 0 ||
(stateFlags & MeasurementStateFlags.WarningLow) > 0)
status |= StatusFlags.DIGITAL_WARNING_SET;
}
}
else
{
if (stateFlags == MeasurementStateFlags.Normal)
{
status = StatusFlags.DIGITAL_OK_NOT_SET;
}
else
{
if ((stateFlags & MeasurementStateFlags.BadData) > 0 ||
(stateFlags & MeasurementStateFlags.SuspectData) > 0 ||
(stateFlags & MeasurementStateFlags.FlatlineAlarm) > 0 ||
(stateFlags & MeasurementStateFlags.ComparisonAlarm) > 0 ||
(stateFlags & MeasurementStateFlags.ROCAlarm) > 0 ||
(stateFlags & MeasurementStateFlags.CalculationError) > 0 ||
(stateFlags & MeasurementStateFlags.CalculationWarning) > 0 ||
(stateFlags & MeasurementStateFlags.MeasurementError) > 0)
status |= StatusFlags.DIGITAL_UNRELIABLE_NOT_SET;
if ((stateFlags & MeasurementStateFlags.OverRangeError) > 0 ||
(stateFlags & MeasurementStateFlags.UnderRangeError) > 0 ||
(stateFlags & MeasurementStateFlags.AlarmHigh) > 0 ||
(stateFlags & MeasurementStateFlags.AlarmLow) > 0 ||
(stateFlags & MeasurementStateFlags.WarningHigh) > 0 ||
(stateFlags & MeasurementStateFlags.WarningLow) > 0)
status |= StatusFlags.DIGITAL_WARNING_NOT_SET;
}
}
}
return status;
}
}
}