Example #1
0
        /// <summary>
        /// Get signal reference for specified <see cref="SignalKind"/>.
        /// </summary>
        /// <param name="type"><see cref="SignalKind"/> to request signal reference for.</param>
        /// <returns>Signal reference of given <see cref="SignalKind"/>.</returns>
        public string GetSignalReference(SignalKind type)
        {
            // We cache non-indexed signal reference strings so they don't need to be generated at each mapping call.
            // This helps with performance since the mappings for each signal occur 30 times per second.
            string[] references;
            int      typeIndex = (int)type;

            // Look up synonym in dictionary based on signal type, if found return single element
            references = m_generatedSignalReferenceCache[typeIndex];

            if ((object)references != null)
            {
                return(references[0]);
            }

            // Create a new signal reference array (for single element)
            references = new string[1];

            // Create and cache new non-indexed signal reference
            references[0] = SignalReference.ToString(IDLabel, type);

            // Cache generated signal synonym
            m_generatedSignalReferenceCache[typeIndex] = references;

            return(references[0]);
        }
Example #2
0
 public Signal(string id, SymbolInfo symbol, SignalKind kind, DateTime creationTime)
 {
     Id           = id;
     Symbol       = symbol;
     Kind         = kind;
     CreationTime = creationTime;
 }
Example #3
0
        /// <summary>
        /// Returns a <see cref="string"/> that represents the specified <paramref name="acronym"/>, <see cref="SignalKind"/> and <paramref name="index"/>.
        /// </summary>
        /// <param name="acronym">Acronym portion of the desired <see cref="string"/> representation.</param>
        /// <param name="type"><see cref="SignalKind"/> portion of the desired <see cref="string"/> representation.</param>
        /// <param name="index">Index of <see cref="SignalKind"/> portion of the desired <see cref="string"/> representation.</param>
        /// <returns>A <see cref="string"/> that represents the specified <paramref name="acronym"/>, <see cref="SignalKind"/> and <paramref name="index"/>.</returns>
        public static string ToString(string acronym, SignalKind type, int index)
        {
            if (index > 0)
            {
                return(string.Format("{0}-{1}{2}", acronym, type.GetAcronym(), index));
            }

            return(string.Format("{0}-{1}", acronym, type.GetAcronym()));
        }
Example #4
0
 /// <summary>
 /// Creates a new instance of the <see cref="AnalogChannel"/>.
 /// </summary>
 public AnalogChannel()
 {
     m_phaseDesignation  = char.MinValue;
     m_signalKind        = SignalKind.Analog;
     m_coordinateFormat  = CoordinateFormat.Polar;
     m_multipler         = 0.04;
     m_adder             = 0.0;
     m_nominalFrequency  = 60.0D;
     m_minValue          = -99999;
     m_maxValue          = 99998;
     m_primaryRatio      = 1.0;
     m_secondaryRatio    = 1.0;
     m_scalingIdentifier = 'P';
 }
 /// <summary>
 /// Creates a new instance of the <see cref="AnalogChannel"/>.
 /// </summary>
 public AnalogChannel()
 {
     m_phaseDesignation = char.MinValue;
     m_signalKind = SignalKind.Analog;
     m_coordinateFormat = CoordinateFormat.Polar;
     m_multipler = 0.04;
     m_adder = 0.0;
     m_nominalFrequency = 60.0D;
     m_minValue = -99999;
     m_maxValue = 99998;
     m_primaryRatio = 1.0;
     m_secondaryRatio = 1.0;
     m_scalingIdentifier = 'P';
 }
Example #6
0
 /// <summary>
 /// Creates a new instance of the <see cref="AnalogChannel"/>.
 /// </summary>
 /// <param name="version">Target schema version.</param>
 /// <param name="targetFloatingPoint">Determines if file type is targeting floating point.</param>
 public AnalogChannel(int version = 1999, bool targetFloatingPoint = false)
 {
     m_version             = version;
     m_targetFloatingPoint = targetFloatingPoint;
     m_phaseDesignation    = char.MinValue;
     m_signalKind          = SignalKind.Analog;
     CoordinateFormat      = CoordinateFormat.Polar;
     Multiplier            = targetFloatingPoint ? 1.0D : DefaultAnalogMultipler;
     Adder = 0.0D;
     m_nominalFrequency  = 60.0D;
     MinValue            = targetFloatingPoint ? float.MinValue : -99999;
     MaxValue            = targetFloatingPoint ? float.MaxValue : 99998;
     PrimaryRatio        = 1.0D;
     SecondaryRatio      = 1.0D;
     m_scalingIdentifier = 'P';
 }
Example #7
0
        /// <summary>
        ///     Create a new signal
        /// </summary>
        /// <param name="signalName">Must be unique in the application</param>
        /// <param name="kind">Indicates if this signal represents that something is working or failing.</param>
        /// <returns>Created signal</returns>
        /// <remarks>
        /// </remarks>
        /// <exception cref="InvalidOperationException">A signal with that name have already been added.</exception>
        public static Signal Create(string signalName, SignalKind kind)
        {
            if (signalName == null)
            {
                throw new ArgumentNullException("signalName");
            }

            var signal = new Signal(signalName);

            if (!_signalManager.TryAdd(signalName, signal))
            {
                throw new InvalidOperationException("A signal with name '" + signalName + "' have already been added.");
            }

            signal.Kind        = kind;
            signal.Raised     += OnTriggerGlobalRaise;
            signal.Suppressed += OnTriggerGlobalSuppress;
            return(signal);
        }
Example #8
0
        /// <summary>
        /// Gets the acronym for the specified <see cref="SignalKind"/>.
        /// </summary>
        /// <param name="signal"><see cref="SignalKind"/> to convert to an acronym.</param>
        /// <returns>The acronym for the specified <see cref="SignalKind"/>.</returns>
        public static string GetAcronym(this SignalKind signal)
        {
            switch (signal)
            {
            case SignalKind.Angle:
                return("PA");    // Phase Angle

            case SignalKind.Magnitude:
                return("PM");    // Phase Magnitude

            case SignalKind.Frequency:
                return("FQ");    // Frequency

            case SignalKind.DfDt:
                return("DF");    // dF/dt

            case SignalKind.Status:
                return("SF");    // Status Flags

            case SignalKind.Digital:
                return("DV");    // Digital Value

            case SignalKind.Analog:
                return("AV");    // Analog Value

            case SignalKind.Calculation:
                return("CV");    // Calculated Value

            case SignalKind.Statistic:
                return("ST");    // Statistical Value

            case SignalKind.Alarm:
                return("AL");    // Alarm Value

            case SignalKind.Quality:
                return("QF");    // Quality Flags

            default:
                return("??");
            }
        }
Example #9
0
        /// <summary>
        /// Get signal reference for specified <see cref="SignalKind"/> and <paramref name="index"/>.
        /// </summary>
        /// <param name="type"><see cref="SignalKind"/> to request signal reference for.</param>
        /// <param name="index">Index <see cref="SignalKind"/> to request signal reference for.</param>
        /// <param name="count">Number of signals defined for this <see cref="SignalKind"/>.</param>
        /// <returns>Signal reference of given <see cref="SignalKind"/> and <paramref name="index"/>.</returns>
        public string GetSignalReference(SignalKind type, int index, int count)
        {
            // We cache indexed signal reference strings so they don't need to be generated at each mapping call.
            // This helps with performance since the mappings for each signal occur 30 times per second.
            // For speed purposes we intentionally do not validate that signalIndex falls within signalCount, be
            // sure calling procedures are very careful with parameters...
            string[] references;
            int      typeIndex = (int)type;

            // Look up synonym in dictionary based on signal type
            references = m_generatedSignalReferenceCache[typeIndex];

            if ((object)references != null)
            {
                // Verify signal count has not changed (we may have received new configuration from device)
                if (count == references.Length)
                {
                    // Create and cache new signal reference if it doesn't exist
                    if ((object)references[index] == null)
                    {
                        references[index] = SignalReference.ToString(IDLabel, type, index + 1);
                    }

                    return(references[index]);
                }
            }

            // Create a new indexed signal reference array
            references = new string[count];

            // Create and cache new signal reference
            references[index] = SignalReference.ToString(IDLabel, type, index + 1);

            // Cache generated signal synonym array
            m_generatedSignalReferenceCache[typeIndex] = references;

            return(references[index]);
        }
Example #10
0
        /// <summary>
        /// Creates a new <see cref="SignalReference"/>.
        /// </summary>
        /// <param name="signal"><see cref="string"/> representation of this <see cref="SignalReference"/>.</param>
        public SignalReference(string signal)
        {
            // Signal reference may contain multiple dashes, we're interested in the last one
            int splitIndex = signal.LastIndexOf('-');

            // Assign default values to fields
            Index     = 0;
            CellIndex = 0;

            if (splitIndex > -1)
            {
                string signalType = signal.Substring(splitIndex + 1).Trim().ToUpper();
                Acronym = signal.Substring(0, splitIndex).Trim().ToUpper();

                // If the length of the signal type acronym is greater than 2, then this
                // is an indexed signal type (e.g., CORDOVA-PA2)
                if (signalType.Length > 2)
                {
                    Kind = signalType.Substring(0, 2).ParseSignalKind();

                    if (Kind != SignalKind.Unknown)
                    {
                        Index = int.Parse(signalType.Substring(2));
                    }
                }
                else
                {
                    Kind = signalType.ParseSignalKind();
                }
            }
            else
            {
                // This represents an error - best we can do is assume entire string is the acronym
                Acronym = signal.Trim().ToUpper();
                Kind    = SignalKind.Unknown;
            }
        }
Example #11
0
        // Static Methods

        /// <summary>
        /// Returns a <see cref="string"/> that represents the specified <paramref name="acronym"/> and <see cref="SignalKind"/>.
        /// </summary>
        /// <param name="acronym">Acronym portion of the desired <see cref="string"/> representation.</param>
        /// <param name="type"><see cref="SignalKind"/> portion of the desired <see cref="string"/> representation.</param>
        /// <returns>A <see cref="string"/> that represents the specified <paramref name="acronym"/> and <see cref="SignalKind"/>.</returns>
        public static string ToString(string acronym, SignalKind type)
        {
            return(ToString(acronym, type, 0));
        }
Example #12
0
        // Static Methods

        /// <summary>
        /// Returns a <see cref="string"/> that represents the specified <paramref name="acronym"/> and <see cref="SignalKind"/>.
        /// </summary>
        /// <param name="acronym">Acronym portion of the desired <see cref="string"/> representation.</param>
        /// <param name="type"><see cref="SignalKind"/> portion of the desired <see cref="string"/> representation.</param>
        /// <returns>A <see cref="string"/> that represents the specified <paramref name="acronym"/> and <see cref="SignalKind"/>.</returns>
        public static string ToString(string acronym, SignalKind type) =>
        ToString(acronym, type, 0);
Example #13
0
 /// <summary>
 /// Returns a <see cref="string"/> that represents the specified <paramref name="acronym"/>, <see cref="SignalKind"/> and <paramref name="index"/>.
 /// </summary>
 /// <param name="acronym">Acronym portion of the desired <see cref="string"/> representation.</param>
 /// <param name="type"><see cref="SignalKind"/> portion of the desired <see cref="string"/> representation.</param>
 /// <param name="index">Index of <see cref="SignalKind"/> portion of the desired <see cref="string"/> representation.</param>
 /// <returns>A <see cref="string"/> that represents the specified <paramref name="acronym"/>, <see cref="SignalKind"/> and <paramref name="index"/>.</returns>
 public static string ToString(string acronym, SignalKind type, int index) =>
 $"{acronym}-{type.GetAcronym()}{(index > 0 ? $"{index}" : "")}";
        /// <summary>
        /// Get signal reference for specified <see cref="SignalKind"/> and <paramref name="index"/>.
        /// </summary>
        /// <param name="type"><see cref="SignalKind"/> to request signal reference for.</param>
        /// <param name="index">Index <see cref="SignalKind"/> to request signal reference for.</param>
        /// <param name="count">Number of signals defined for this <see cref="SignalKind"/>.</param>
        /// <returns>Signal reference of given <see cref="SignalKind"/> and <paramref name="index"/>.</returns>
        public string GetSignalReference(SignalKind type, int index, int count)
        {
            // We cache indexed signal reference strings so they don't need to be generated at each mapping call.
            // For speed purposes we intentionally do not validate that signalIndex falls within signalCount, be
            // sure calling procedures are very careful with parameters...
            string[] references;

            // Look up synonym in dictionary based on signal type
            if (m_generatedSignalReferenceCache.TryGetValue(type, out references))
            {
                // Verify signal count has not changed (we may have received new configuration from device)
                if (count == references.Length)
                {
                    // Create and cache new signal reference if it doesn't exist
                    if ((object)references[index] == null)
                        references[index] = SignalReference.ToString(Name + "!IS", type, index + 1);

                    return references[index];
                }
            }

            // Create a new indexed signal reference array
            references = new string[count];

            // Create and cache new signal reference
            references[index] = SignalReference.ToString(Name + "!IS", type, index + 1);

            // Cache generated signal synonym array
            m_generatedSignalReferenceCache.TryAdd(type, references);

            return references[index];
        }
        /// <summary>
        /// Get signal reference for specified <see cref="SignalKind"/>.
        /// </summary>
        /// <param name="type"><see cref="SignalKind"/> to request signal reference for.</param>
        /// <returns>Signal reference of given <see cref="SignalKind"/>.</returns>
        public string GetSignalReference(SignalKind type)
        {
            // We cache non-indexed signal reference strings so they don't need to be generated at each mapping call.
            string[] references;

            // Look up synonym in dictionary based on signal type, if found return single element
            if (m_generatedSignalReferenceCache.TryGetValue(type, out references))
                return references[0];

            // Create a new signal reference array (for single element)
            references = new string[1];

            // Create and cache new non-indexed signal reference
            references[0] = SignalReference.ToString(Name + "!IS", type);

            // Cache generated signal synonym
            m_generatedSignalReferenceCache.TryAdd(type, references);

            return references[0];
        }
Example #16
0
 public static Signal <TDetails> MakeSignal <TDetails>(SignalKind kind, TDetails details) => new Signal <TDetails>
 {
     Kind    = kind,
     Details = details
 };
Example #17
0
        /// <summary>
        /// Get <see cref="MeasurementMetadata"/> for specified <see cref="SignalKind"/>.
        /// </summary>
        /// <param name="lookup">A lookup table by signal reference.</param>
        /// <param name="type"><see cref="SignalKind"/> to request signal reference for.</param>
        /// <param name="index">Index <see cref="SignalKind"/> to request signal reference for.</param>
        /// <param name="count">Number of signals defined for this <see cref="SignalKind"/>.</param>
        /// <returns>The MeasurementMetadata for a given <see cref="SignalKind"/>. Null if it does not exist.</returns>
        public MeasurementMetadata GetMetadata(Dictionary <string, MeasurementMetadata> lookup, SignalKind type, int index, int count)
        {
            // Clear the cache if the lookup dictionary has changed.
            // Since the instance of Lookup is effectively readonly as implemented in PhasorMeasurementMapper
            // a simple reference check is all that is needed. If it could be modified, this would likely be a
            // concurrent dictionary instead.
            if (m_metadataLookupObject != lookup)
            {
                Array.Clear(m_generatedMeasurementMetadataCache, 0, m_generatedMeasurementMetadataCache.Length);
                m_metadataLookupObject = lookup;
            }

            // Gets the cache for the supplied SignalKind
            int typeIndex = (int)type;

            MeasurementMetadata[] metadataArray = m_generatedMeasurementMetadataCache[typeIndex];

            // If this SignalKind is null, create the sub array and generate all item lookups, also, rebuild
            // if the count is not the same. This could be because a new config frame was received.
            if ((object)metadataArray == null || metadataArray.Length != count)
            {
                metadataArray = new MeasurementMetadata[count];
                m_generatedMeasurementMetadataCache[typeIndex] = metadataArray;

                for (int x = 0; x < count; x++)
                {
                    string signalReference = GetSignalReference(type, x, count);
                    MeasurementMetadata metadata;

                    if (lookup.TryGetValue(signalReference, out metadata))
                    {
                        metadataArray[x] = metadata;
                    }
                }
            }

            return(metadataArray[index]);
        }
Example #18
0
        /// <summary>
        /// Get <see cref="MeasurementMetadata"/> for specified <see cref="SignalKind"/>.
        /// </summary>
        /// <param name="lookup">A lookup table by signal reference.</param>
        /// <param name="type"><see cref="SignalKind"/> to request signal reference for.</param>
        /// <returns>The <see cref="MeasurementMetadata"/> for a given <see cref="SignalKind"/>; otherwise <c>null</c> if value does not exist.</returns>
        public MeasurementMetadata GetMetadata(Dictionary <string, MeasurementMetadata> lookup, SignalKind type)
        {
            // Clear the cache if the lookup dictionary has changed.
            // Since the instance of Lookup is effectively readonly as implemented in PhasorMeasurementMapper
            // a simple reference check is all that is needed. If it could be modified, this would likely be a
            // concurrent dictionary instead.
            if (m_metadataLookupObject != lookup)
            {
                Array.Clear(m_generatedMeasurementMetadataCache, 0, m_generatedMeasurementMetadataCache.Length);
                m_metadataLookupObject = lookup;
            }

            // Gets the cache for the supplied SignalKind
            int typeIndex = (int)type;

            MeasurementMetadata[] metadataArray = m_generatedMeasurementMetadataCache[typeIndex];

            // If this SignalKind is null, create the sub array and generate all item lookups
            if ((object)metadataArray == null)
            {
                metadataArray = new MeasurementMetadata[1];
                m_generatedMeasurementMetadataCache[typeIndex] = metadataArray;

                string signalReference = GetSignalReference(type);
                MeasurementMetadata metadata;

                if (lookup.TryGetValue(signalReference, out metadata))
                {
                    metadataArray[0] = metadata;
                }
            }

            return(metadataArray[0]);
        }
        /// <summary>
        /// Get signal reference for specified <see cref="SignalKind"/>.
        /// </summary>
        /// <param name="type"><see cref="SignalKind"/> to request signal reference for.</param>
        /// <returns>Signal reference of given <see cref="SignalKind"/>.</returns>
        public string GetSignalReference(SignalKind type)
        {
            // We cache non-indexed signal reference strings so they don't need to be generated at each mapping call.
            // This helps with performance since the mappings for each signal occur 30 times per second.
            string[] references;
            int typeIndex = (int)type;

            // Look up synonym in dictionary based on signal type, if found return single element
            references = m_generatedSignalReferenceCache[typeIndex];

            if ((object)references != null)
                return references[0];

            // Create a new signal reference array (for single element)
            references = new string[1];

            // Create and cache new non-indexed signal reference
            references[0] = SignalReference.ToString(IDLabel, type);

            // Cache generated signal synonym
            m_generatedSignalReferenceCache[typeIndex] = references;

            return references[0];
        }
        /// <summary>
        /// Get signal reference for specified <see cref="SignalKind"/> and <paramref name="index"/>.
        /// </summary>
        /// <param name="type"><see cref="SignalKind"/> to request signal reference for.</param>
        /// <param name="index">Index <see cref="SignalKind"/> to request signal reference for.</param>
        /// <param name="count">Number of signals defined for this <see cref="SignalKind"/>.</param>
        /// <returns>Signal reference of given <see cref="SignalKind"/> and <paramref name="index"/>.</returns>
        public string GetSignalReference(SignalKind type, int index, int count)
        {
            // We cache indexed signal reference strings so they don't need to be generated at each mapping call.
            // This helps with performance since the mappings for each signal occur 30 times per second.
            // For speed purposes we intentionally do not validate that signalIndex falls within signalCount, be
            // sure calling procedures are very careful with parameters...
            string[] references;
            int typeIndex = (int)type;

            // Look up synonym in dictionary based on signal type
            references = m_generatedSignalReferenceCache[typeIndex];

            if ((object)references != null)
            {
                // Verify signal count has not changed (we may have received new configuration from device)
                if (count == references.Length)
                {
                    // Create and cache new signal reference if it doesn't exist
                    if ((object)references[index] == null)
                        references[index] = SignalReference.ToString(IDLabel, type, index + 1);

                    return references[index];
                }
            }

            // Create a new indexed signal reference array
            references = new string[count];

            // Create and cache new signal reference
            references[index] = SignalReference.ToString(IDLabel, type, index + 1);

            // Cache generated signal synonym array
            m_generatedSignalReferenceCache[typeIndex] = references;

            return references[index];
        }
        /// <summary>
        /// Get <see cref="MeasurementMetadata"/> for specified <see cref="SignalKind"/>.
        /// </summary>
        /// <param name="lookup">A lookup table by signal reference.</param>
        /// <param name="type"><see cref="SignalKind"/> to request signal reference for.</param>
        /// <param name="index">Index <see cref="SignalKind"/> to request signal reference for.</param>
        /// <param name="count">Number of signals defined for this <see cref="SignalKind"/>.</param>
        /// <returns>The MeasurementMetadata for a given <see cref="SignalKind"/>. Null if it does not exist.</returns>
        public MeasurementMetadata GetMetadata(Dictionary<string, MeasurementMetadata> lookup, SignalKind type, int index, int count)
        {
            // Clear the cache if the lookup dictionary has changed.
            // Since the instance of Lookup is effectively readonly as implemented in PhasorMeasurementMapper
            // a simple reference check is all that is needed. If it could be modified, this would likely be a
            // concurrent dictionary instead.
            if (m_metadataLookupObject != lookup)
            {
                Array.Clear(m_generatedMeasurementMetadataCache, 0, m_generatedMeasurementMetadataCache.Length);
                m_metadataLookupObject = lookup;
            }

            // Gets the cache for the supplied SignalKind
            int typeIndex = (int)type;
            MeasurementMetadata[] metadataArray = m_generatedMeasurementMetadataCache[typeIndex];

            // If this SignalKind is null, create the sub array and generate all item lookups, also, rebuild
            // if the count is not the same. This could be because a new config frame was received.
            if ((object)metadataArray == null || metadataArray.Length != count)
            {
                metadataArray = new MeasurementMetadata[count];
                m_generatedMeasurementMetadataCache[typeIndex] = metadataArray;

                for (int x = 0; x < count; x++)
                {
                    string signalReference = GetSignalReference(type, x, count);
                    MeasurementMetadata metadata;

                    if (lookup.TryGetValue(signalReference, out metadata))
                        metadataArray[x] = metadata;
                }
            }

            return metadataArray[index];
        }
        /// <summary>
        /// Get <see cref="MeasurementMetadata"/> for specified <see cref="SignalKind"/>.
        /// </summary>
        /// <param name="lookup">A lookup table by signal reference.</param>
        /// <param name="type"><see cref="SignalKind"/> to request signal reference for.</param>
        /// <returns>The <see cref="MeasurementMetadata"/> for a given <see cref="SignalKind"/>; otherwise <c>null</c> if value does not exist.</returns>
        public MeasurementMetadata GetMetadata(Dictionary<string, MeasurementMetadata> lookup, SignalKind type)
        {
            // Clear the cache if the lookup dictionary has changed.
            // Since the instance of Lookup is effectively readonly as implemented in PhasorMeasurementMapper
            // a simple reference check is all that is needed. If it could be modified, this would likely be a
            // concurrent dictionary instead.
            if (m_metadataLookupObject != lookup)
            {
                Array.Clear(m_generatedMeasurementMetadataCache, 0, m_generatedMeasurementMetadataCache.Length);
                m_metadataLookupObject = lookup;
            }

            // Gets the cache for the supplied SignalKind
            int typeIndex = (int)type;
            MeasurementMetadata[] metadataArray = m_generatedMeasurementMetadataCache[typeIndex];

            // If this SignalKind is null, create the sub array and generate all item lookups
            if ((object)metadataArray == null)
            {
                metadataArray = new MeasurementMetadata[1];
                m_generatedMeasurementMetadataCache[typeIndex] = metadataArray;

                string signalReference = GetSignalReference(type);
                MeasurementMetadata metadata;

                if (lookup.TryGetValue(signalReference, out metadata))
                    metadataArray[0] = metadata;
            }

            return metadataArray[0];
        }