//******************************************************************************************************
// IFrameParser.cs - Gbtc
//
// Copyright © 2012, 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://www.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:
// ----------------------------------------------------------------------------------------------------
// 01/14/2005 - J. Ritchie Carroll
// Generated original version of source code.
// 09/15/2009 - Stephen C. Wills
// Added new header and license agreement.
// 12/17/2012 - Starlynn Danyelle Gilliam
// Modified Header.
//
//******************************************************************************************************
using System;
using GSF.Parsing;
namespace GSF.PhasorProtocols
{
#region [ Enumerations ]
///
/// Source channel, e.g., data or command.
///
[Serializable]
public enum SourceChannel
{
///
/// Source channel is command (e.g., TCP).
///
Command,
///
/// Source channel is data (e.g., UDP).
///
Data,
///
/// Source channel is other.
///
Other
}
///
/// Check-sum validation frame-type flags.
///
[Serializable, Flags]
public enum CheckSumValidationFrameTypes : byte
{
///
/// Include no frame types for check-sum validation.
///
NoFrames = (byte)Bits.Nil,
///
/// Include configuration frame for check-sum validation.
///
ConfigurationFrame = (byte)Bits.Bit00,
///
/// Include data frame for check-sum validation.
///
DataFrame = (byte)Bits.Bit01,
///
/// Include header frame for check-sum validation.
///
HeaderFrame = (byte)Bits.Bit02,
///
/// Include command frame for check-sum validation.
///
CommandFrame = (byte)Bits.Bit03,
///
/// Include all frame types for check-sum validation.
///
AllFrames = 0xFF
}
#endregion
///
/// Represents a protocol independent representation of a frame parser.
///
///
/// This interface allows protocol specific frame parsers to be handled abstractly by the .
///
public interface IFrameParser : IProvideStatus, IDisposable
{
///
/// Occurs when any has been received.
///
///
/// is the that was received.
/// is the flag to determine if frame publication should continue.
///
event EventHandler> ReceivedChannelFrame;
///
/// Occurs when a has been received.
///
///
/// is the that was received.
///
event EventHandler> ReceivedCommandFrame;
///
/// Occurs when a has been received.
///
///
/// is the that was received.
///
event EventHandler> ReceivedConfigurationFrame;
///
/// Occurs when a has been received.
///
///
/// is the that was received.
///
event EventHandler> ReceivedDataFrame;
///
/// Occurs when a has been received.
///
///
/// is the that was received.
///
event EventHandler> ReceivedHeaderFrame;
///
/// Occurs when an undetermined has been received.
///
///
/// is the undetermined that was received.
///
event EventHandler> ReceivedUndeterminedFrame;
///
/// Occurs when a frame image has been received.
///
///
/// is the of the frame buffer image that was received.
/// is the length of the frame image that was received.
///
event EventHandler> ReceivedFrameImage;
///
/// Occurs when a frame buffer image has been received.
///
///
///
/// is the of the frame buffer image that was received.
/// is the buffer that contains the frame image that was received.
/// is the offset into the buffer that contains the frame image that was received.
/// is the length of data in the buffer that contains the frame image that was received.
///
///
/// Consumers should use the more efficient event if the buffer is not needed.
///
///
event EventHandler> ReceivedFrameBufferImage;
///
/// Occurs when a device sends a notification that its configuration has changed.
///
event EventHandler ConfigurationChanged;
///
/// Occurs when an is encountered while attempting to parse data.
///
///
/// is the encountered while parsing data.
///
event EventHandler> ParsingException;
///
/// Occurs when buffer parsing has completed.
///
event EventHandler BufferParsed;
///
/// Gets the total number of buffers that are currently queued for processing, if any.
///
int QueuedBuffers { get; }
///
/// Gets the total number of frames that are currently queued for publication, if any.
///
int QueuedOutputs { get; }
///
/// Gets the number of redundant frames in each packet.
///
///
/// This value is used when calculating statistics. It is assumed that for each
/// frame that is received, that frame will be included in the next n
/// packets, where n is the number of redundant frames per packet.
///
int RedundantFramesPerPacket { get; }
///
/// Gets or sets current used for parsing 's encountered in the data stream from a device.
///
///
/// If a has been parsed, this will return a reference to the parsed frame. Consumer can manually assign a
/// to start parsing data if one has not been encountered in the stream.
///
IConfigurationFrame ConfigurationFrame { get; set; }
///
/// Gets or sets any connection specific that may be needed for parsing.
///
IConnectionParameters ConnectionParameters { get; set; }
///
/// Gets or sets flags that determine if check-sums for specified frames should be validated.
///
///
/// It is expected that this will normally be set to .
///
CheckSumValidationFrameTypes CheckSumValidationFrameTypes { get; set; }
///
/// Gets or sets flag that determines if header lengths should be trusted over parsed byte count.
///
///
/// It is expected that this will normally be left as true.
///
bool TrustHeaderLength { get; set; }
///
/// Gets or sets a boolean value that indicates whether the data parser is currently enabled.
///
bool Enabled { get; set; }
///
/// Start the streaming data parser.
///
void Start();
///
/// Stops the streaming data parser.
///
void Stop();
///
/// Writes a sequence of bytes onto the stream for parsing.
///
/// Defines the source channel for the data.
/// An array of bytes. This method copies count bytes from buffer to the current stream.
/// The zero-based byte offset in buffer at which to begin copying bytes to the current stream.
/// The number of bytes to be written to the current stream.
void Parse(SourceChannel source, byte[] buffer, int offset, int count);
}
}