//******************************************************************************************************
// DataFrame.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:
// ----------------------------------------------------------------------------------------------------
// 02/08/2007 - J. Ritchie Carroll & Jian Ryan Zuo
// 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 System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;
using GSF.Parsing;
namespace GSF.PhasorProtocols.FNET
{
///
/// Represents the F-NET implementation of a that can be sent or received.
///
[Serializable]
public class DataFrame : DataFrameBase, ISupportSourceIdentifiableFrameImage
{
#region [ Members ]
// Fields
private CommonFrameHeader m_frameHeader;
private uint m_sampleIndex;
#endregion
#region [ Constructors ]
///
/// Creates a new .
///
///
/// This constructor is used by to parse an F-NET data frame.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public DataFrame()
: base(new DataCellCollection(), 0, null)
{
}
///
/// Creates a new from specified parameters.
///
/// The exact timestamp, in , of the data represented by this .
/// The associated with this .
/// The sample index of this .
///
/// This constructor is used by a consumer to generate a F-NET data frame.
///
public DataFrame(Ticks timestamp, ConfigurationFrame configurationFrame, uint sampleIndex)
: base(new DataCellCollection(), timestamp, configurationFrame)
{
m_sampleIndex = sampleIndex;
}
///
/// Creates a new from serialization parameters.
///
/// The with populated with data.
/// The source for this deserialization.
protected DataFrame(SerializationInfo info, StreamingContext context)
: base(info, context)
{
// Deserialize data frame
m_sampleIndex = info.GetUInt32("sampleIndex");
}
#endregion
#region [ Properties ]
///
/// Gets reference to the for this .
///
public new DataCellCollection Cells => base.Cells as DataCellCollection;
///
/// Gets or sets associated with this .
///
public new ConfigurationFrame ConfigurationFrame
{
get => base.ConfigurationFrame as ConfigurationFrame;
set => base.ConfigurationFrame = value;
}
///
/// Gets the identifier that is used to identify the F-NET frame.
///
public int TypeID => 0; // F-NET only defines a single frame type...
///
/// Gets or sets the sample index of this .
///
public uint SampleIndex
{
get => m_sampleIndex;
set => m_sampleIndex = value;
}
///
/// Gets or sets current .
///
public CommonFrameHeader CommonHeader
{
get => m_frameHeader;
set
{
m_frameHeader = value;
if (m_frameHeader is not null)
State = m_frameHeader.State as IDataFrameParsingState;
}
}
// This interface implementation satisfies ISupportFrameImage.CommonHeader
ICommonHeader ISupportFrameImage.CommonHeader
{
get => CommonHeader;
set => CommonHeader = value as CommonFrameHeader;
}
///
/// of string based property names and values for the object.
///
public override Dictionary Attributes
{
get
{
Dictionary baseAttributes = base.Attributes;
baseAttributes.Add("Sample Index", SampleIndex.ToString());
return baseAttributes;
}
}
#endregion
#region [ Methods ]
///
/// Determines if checksum in the is valid.
///
/// Buffer image to validate.
/// Start index into to perform checksum.
/// Flag that determines if checksum over is valid.
///
/// F-NET doesn't use checksums - this always returns true.
///
protected override bool ChecksumIsValid(byte[] buffer, int startIndex)
{
return true;
}
///
/// Method is not implemented.
///
/// F-NET doesn't use checksums.
/// Array of s.
/// An value for the bytes to read.
/// An value for offset to read from.
/// An as the checksum.
protected override ushort CalculateChecksum(byte[] buffer, int offset, int length)
{
throw new NotImplementedException();
}
///
/// Populates a with the data needed to serialize the target object.
///
/// The to populate with data.
/// The destination for this serialization.
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
// Serialize data frame
info.AddValue("sampleIndex", m_sampleIndex);
}
#endregion
}
}