Exemplo n.º 1
0
        /// <summary>
        /// Creates a new <see cref="CommandFrame"/> from the given <paramref name="buffer"/>.
        /// </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>
        /// <remarks>
        /// This constructor is used by a consumer to parse a received IEC 61850-90-5 command frame. Typically
        /// command frames are sent to a device. This constructor would used if this code was being used
        /// inside of a phasor measurement device.
        /// </remarks>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="length"/> is not large enough to parse frame.</exception>
        public CommandFrame(byte[] buffer, int startIndex, int length)
            : base(new CommandCellCollection(Common.MaximumExtendedDataLength), DeviceCommand.ReservedBits)
        {
            if (length < CommonFrameHeader.FixedLength)
                throw new ArgumentOutOfRangeException(nameof(length));

            m_frameHeader = new CommonFrameHeader(null, false, false, false, true, true, AngleFormat.Degrees, buffer, startIndex, 0);

            if (m_frameHeader.TypeID != IEC61850_90_5.FrameType.CommandFrame)
                throw new InvalidOperationException("Binary image does not represent an IEC 61850-90-5 command frame");

            if (length < m_frameHeader.FrameLength)
                throw new ArgumentOutOfRangeException(nameof(length), string.Format("Buffer size, {0}, is not large enough to parse IEC 61850-90-5 command frame with a length of {1}", length, m_frameHeader.FrameLength));

            // Validate check-sum
            int sumLength = m_frameHeader.FrameLength - 2;

            if (BigEndian.ToUInt16(buffer, startIndex + sumLength) != CalculateChecksum(buffer, startIndex, sumLength))
                throw new InvalidOperationException("Invalid binary image detected - check sum of " + this.GetType().Name + " did not match");

            m_frameHeader.State = new CommandFrameParsingState(m_frameHeader.FrameLength, m_frameHeader.DataLength, true, true);
            CommonHeader = m_frameHeader;
            ParseBinaryImage(buffer, startIndex, length);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new <see cref="CommandFrame"/> from the given <paramref name="binaryImage"/>.
        /// </summary>
        /// <param name="binaryImage">Binary image to parse.</param>
        /// <param name="startIndex">Start index into <paramref name="binaryImage"/> to begin parsing.</param>
        /// <param name="length">Length of valid data within <paramref name="binaryImage"/>.</param>
        /// <remarks>
        /// This constructor is used by a consumer to parse a received IEEE C37.118 command frame. Typically
        /// command frames are sent to a device. This constructor would used if this code was being used
        /// inside of a phasor measurement device.
        /// </remarks>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="length"/> is not large enough to parse frame.</exception>
        public CommandFrame(byte[] binaryImage, int startIndex, int length)
            : base(new CommandCellCollection(Common.MaximumExtendedDataLength), DeviceCommand.ReservedBits)
        {
            if (length < CommonFrameHeader.FixedLength)
                throw new ArgumentOutOfRangeException("length");

            m_frameHeader = new CommonFrameHeader(null, binaryImage, startIndex);

            if (m_frameHeader.TypeID != IeeeC37_118.FrameType.CommandFrame)
                throw new InvalidOperationException("Binary image does not represent an IEEE C37.118 command frame");

            if (length < m_frameHeader.FrameLength)
                throw new ArgumentOutOfRangeException("length", string.Format("Buffer size, {0}, is not large enough to parse IEEE C37.118 command frame with a length of {1}", length, m_frameHeader.FrameLength));

            // Validate check-sum
            int sumLength = m_frameHeader.FrameLength - 2;

            if (EndianOrder.BigEndian.ToUInt16(binaryImage, startIndex + sumLength) != CalculateChecksum(binaryImage, startIndex, sumLength))
                throw new InvalidOperationException("Invalid binary image detected - check sum of " + this.GetType().Name + " did not match");

            m_frameHeader.State = new CommandFrameParsingState(m_frameHeader.FrameLength, m_frameHeader.DataLength);
            CommonHeader = m_frameHeader;
            Initialize(binaryImage, startIndex, length);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Creates a new <see cref="CommandFrame"/> from serialization parameters.
 /// </summary>
 /// <param name="info">The <see cref="SerializationInfo"/> with populated with data.</param>
 /// <param name="context">The source <see cref="StreamingContext"/> for this deserialization.</param>
 protected CommandFrame(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     // Deserialize command frame
     m_frameHeader = (CommonFrameHeader)info.GetValue("frameHeader", typeof(CommonFrameHeader));
 }