Example #1
0
        /// <summary>
        /// Creates a new <see cref="ConfigurationFrame"/> from specified parameters.
        /// </summary>
        /// <param name="idCode">The ID code of this <see cref="ConfigurationFrame"/>.</param>
        /// <param name="timestamp">The exact timestamp, in <see cref="Ticks"/>, of the data represented by this <see cref="ConfigurationFrame"/>.</param>
        /// <param name="frameRate">The defined frame rate of this <see cref="ConfigurationFrame"/>.</param>
        /// <param name="nominalFrequency">The nominal <see cref="LineFrequency"/> of this <see cref="ConfigurationFrame"/>.</param>
        /// <param name="timeOffset">The time offset of F-NET device in <see cref="Ticks"/>.</param>
        /// <param name="stationName">The station name of the F-NET device.</param>
        /// <remarks>
        /// This constructor is used by a consumer to generate an F-NET configuration frame.
        /// </remarks>
        public ConfigurationFrame(ushort idCode, Ticks timestamp, ushort frameRate, LineFrequency nominalFrequency, Ticks timeOffset, string stationName)
            : base(idCode, new ConfigurationCellCollection(), timestamp, frameRate)
        {
            ConfigurationCell configCell = new ConfigurationCell(this, nominalFrequency, timeOffset);

            // FNet protocol sends data for one device
            Cells.Add(configCell);

            // Assign station name
            configCell.StationName = string.IsNullOrEmpty(stationName) ? $"F-NET Unit-{idCode}" : stationName;

            // Add a single frequency definition
            configCell.FrequencyDefinition = new FrequencyDefinition(configCell, "Line frequency");

            // Add a single phasor definition
            configCell.PhasorDefinitions.Add(new PhasorDefinition(configCell, "120V Phasor", PhasorType.Voltage, null));
        }
Example #2
0
        /// <summary>
        /// Creates a new <see cref="ConfigurationFrame"/> from specified parameters.
        /// </summary>
        /// <param name="idCode">The ID code of this <see cref="ConfigurationFrame"/>.</param>
        /// <param name="timestamp">The exact timestamp, in <see cref="Ticks"/>, of the data represented by this <see cref="ConfigurationFrame"/>.</param>
        /// <param name="frameRate">The defined frame rate of this <see cref="ConfigurationFrame"/>.</param>
        /// <param name="nominalFrequency">The nominal <see cref="LineFrequency"/> of this <see cref="ConfigurationFrame"/>.</param>
        /// <param name="timeOffset">The time offset of F-NET device in <see cref="Ticks"/>.</param>
        /// <param name="stationName">The station name of the F-NET device.</param>
        /// <remarks>
        /// This constructor is used by a consumer to generate an F-NET configuration frame.
        /// </remarks>
        public ConfigurationFrame(ushort idCode, Ticks timestamp, ushort frameRate, LineFrequency nominalFrequency, Ticks timeOffset, string stationName)
            : base(idCode, new ConfigurationCellCollection(), timestamp, frameRate)
        {
            ConfigurationCell configCell = new ConfigurationCell(this, nominalFrequency, timeOffset);

            // FNet protocol sends data for one device
            Cells.Add(configCell);

            // Assign station name
            if (string.IsNullOrEmpty(stationName))
                configCell.StationName = "F-NET Unit-" + idCode;
            else
                configCell.StationName = stationName;

            // Add a single frequency definition
            configCell.FrequencyDefinition = new FrequencyDefinition(configCell, "Line frequency");

            // Add a single phasor definition
            configCell.PhasorDefinitions.Add(new PhasorDefinition(configCell, "120V Phasor", PhasorType.Voltage, null));
        }
Example #3
0
 /// <summary>
 /// Creates a new <see cref="PhasorDefinition"/> from specified parameters.
 /// </summary>
 /// <param name="parent">The <see cref="ConfigurationCell"/> parent of this <see cref="PhasorDefinition"/>.</param>
 /// <param name="label">The label of this <see cref="PhasorDefinition"/>.</param>
 /// <param name="type">The <see cref="PhasorType"/> of this <see cref="PhasorDefinition"/>.</param>
 /// <param name="voltageReference">The associated <see cref="IPhasorDefinition"/> that represents the voltage reference (if any).</param>
 public PhasorDefinition(ConfigurationCell parent, string label, PhasorType type, PhasorDefinition voltageReference)
     : base(parent, label, 1, 0.0D, type, voltageReference)
 {
 }
Example #4
0
 /// <summary>
 /// Creates a new <see cref="PhasorDefinition"/> from specified parameters.
 /// </summary>
 /// <param name="parent">The <see cref="ConfigurationCell"/> parent of this <see cref="PhasorDefinition"/>.</param>
 /// <param name="label">The label of this <see cref="PhasorDefinition"/>.</param>
 /// <param name="type">The <see cref="PhasorType"/> of this <see cref="PhasorDefinition"/>.</param>
 /// <param name="voltageReference">The associated <see cref="IPhasorDefinition"/> that represents the voltage reference (if any).</param>
 public PhasorDefinition(ConfigurationCell parent, string label, PhasorType type, PhasorDefinition voltageReference)
     : base(parent, label, 1, 0.0D, type, voltageReference)
 {
 }
Example #5
0
 /// <summary>
 /// Creates a new <see cref="FrequencyDefinition"/> from specified parameters.
 /// </summary>
 /// <param name="parent">The <see cref="ConfigurationCell"/> parent of this <see cref="FrequencyDefinition"/>.</param>
 /// <param name="label">The label of this <see cref="FrequencyDefinition"/>.</param>
 public FrequencyDefinition(ConfigurationCell parent, string label)
     : base(parent, label, 1, 1, 0.0D)
 {
 }
 /// <summary>
 /// Creates a new <see cref="FrequencyDefinition"/> from specified parameters.
 /// </summary>
 /// <param name="parent">The <see cref="ConfigurationCell"/> parent of this <see cref="FrequencyDefinition"/>.</param>
 /// <param name="label">The label of this <see cref="FrequencyDefinition"/>.</param>
 public FrequencyDefinition(ConfigurationCell parent, string label)
     : base(parent, label, 1, 1, 0.0D)
 {
 }
Example #7
0
        /// <summary>
        /// Parses the binary body image.
        /// </summary>
        /// <param name="buffer">Binary image to parse.</param>
        /// <param name="startIndex">Start index into <paramref name="buffer"/> to begin parsing.</param>
        /// <param name="length">Length of valid data within <paramref name="buffer"/>.</param>
        /// <returns>The length of the data that was parsed.</returns>
        /// <remarks>
        /// The longitude, latitude and number of satellites arrive at the top of minute in F-NET data as the analog
        /// data in a single row, each on their own row, as sample 1, 2, and 3 respectively.
        /// </remarks>
        protected override int ParseBodyImage(byte[] buffer, int startIndex, int length)
        {
            DataFrame         parent       = Parent;
            CommonFrameHeader commonHeader = parent.CommonHeader;

            string[]          data = commonHeader.DataElements;
            ConfigurationCell configurationCell = ConfigurationCell;
            uint sampleIndex;

            // Attempt to parse sample index
            if (uint.TryParse(data[Element.SampleIndex], out sampleIndex))
            {
                parent.SampleIndex = sampleIndex;

                // Get timestamp of data record
                parent.Timestamp = configurationCell.TimeOffset + ParseTimestamp(data[Element.Date], data[Element.Time], parent.SampleIndex, configurationCell.FrameRate);

                // Parse out first analog value (can be long/lat at top of minute)
                m_analogValue = double.Parse(data[Element.Analog]);

                if (data[Element.Time].Length >= 7 && int.Parse(data[Element.Time].Substring(4, 2)) == 0)
                {
                    switch (parent.SampleIndex)
                    {
                    case 1:
                        configurationCell.Latitude = m_analogValue;
                        break;

                    case 2:
                        configurationCell.Longitude = m_analogValue;
                        break;

                    case 3:
                        configurationCell.NumberOfSatellites = (int)m_analogValue;
                        break;
                    }
                }

                // Update (or create) frequency value
                double frequency = double.Parse(data[Element.Frequency]);

                if (FrequencyValue != null)
                {
                    FrequencyValue.Frequency = frequency;
                }
                else
                {
                    FrequencyValue = new FrequencyValue(this, configurationCell.FrequencyDefinition as FrequencyDefinition, frequency, 0.0D);
                }

                // Update (or create) phasor value
                Angle       angle     = double.Parse(data[Element.Angle]);
                double      magnitude = double.Parse(data[Element.Voltage]);
                PhasorValue phasor    = null;

                if (PhasorValues.Count > 0)
                {
                    phasor = PhasorValues[0] as PhasorValue;
                }

                if (phasor != null)
                {
                    phasor.Angle     = angle;
                    phasor.Magnitude = magnitude;
                }
                else
                {
                    phasor = new PhasorValue(this, configurationCell.PhasorDefinitions[0] as PhasorDefinition, angle, magnitude);
                    PhasorValues.Add(phasor);
                }
            }

            return(commonHeader.ParsedLength);
        }