//******************************************************************************************************
// ConfigurationCell.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.Runtime.Serialization;
using GSF.Units.EE;
// ReSharper disable VirtualMemberCallInConstructor
namespace GSF.PhasorProtocols.FNET
{
///
/// Represents the F-NET implementation of a that can be sent or received.
///
[Serializable]
public class ConfigurationCell : ConfigurationCellBase
{
#region [ Members ]
// Fields
private Ticks m_timeOffset;
private double m_longitude;
private double m_latitude;
private int m_numberOfSatellites = 1; // We'll initially assume synchronization is good until told otherwise
#endregion
#region [ Constructors ]
///
/// Creates a new from specified parameters.
///
/// The reference to parent of this .
/// The nominal of the of this .
/// The time offset of F-NET device in .
internal ConfigurationCell(ConfigurationFrame parent, LineFrequency nominalFrequency, Ticks timeOffset)
: base(parent, parent.IDCode, Common.MaximumPhasorValues, Common.MaximumAnalogValues, Common.MaximumDigitalValues)
{
NominalFrequency = nominalFrequency;
m_timeOffset = timeOffset;
}
///
/// Creates a new from serialization parameters.
///
/// The with populated with data.
/// The source for this deserialization.
protected ConfigurationCell(SerializationInfo info, StreamingContext context)
: base(info, context)
{
// Deserialize configuration cell
m_timeOffset = info.GetInt64("timeOffset");
m_longitude = info.GetDouble("longitude");
m_latitude = info.GetDouble("latitude");
m_numberOfSatellites = info.GetInt32("numberOfSatellites");
}
#endregion
#region [ Properties ]
///
/// Gets a reference to the parent for this .
///
public new ConfigurationFrame Parent
{
get => base.Parent as ConfigurationFrame;
set => base.Parent = value;
}
///
/// Gets or sets the ID code of this .
///
public override ushort IDCode
{
// F-NET protocol only allows one device, so we share ID code with parent frame...
get => Parent.IDCode;
set
{
Parent.IDCode = value;
base.IDCode = value;
}
}
///
/// Gets or sets the for the objects in the of this .
///
///
/// This property only supports floating-point data; F-NET doesn't transport scaled values.
///
/// F-NET only supports floating-point data.
public override DataFormat PhasorDataFormat
{
get => DataFormat.FloatingPoint;
set
{
if (value != DataFormat.FloatingPoint)
throw new NotSupportedException("F-NET only supports floating-point data");
}
}
///
/// Gets or sets the for the objects in the of this .
///
///
/// This property only supports polar phasor data; F-NET doesn't transport rectangular phasor values.
///
/// F-NET only supports polar phasor data.
public override CoordinateFormat PhasorCoordinateFormat
{
get => CoordinateFormat.Polar;
set
{
if (value != CoordinateFormat.Polar)
throw new NotSupportedException("F-NET only supports polar phasor data");
}
}
///
/// Gets or sets the of the of this .
///
///
/// This property only supports floating-point data; F-NET doesn't transport scaled values.
///
/// F-NET only supports floating-point data.
public override DataFormat FrequencyDataFormat
{
get => DataFormat.FloatingPoint;
set
{
if (value != DataFormat.FloatingPoint)
throw new NotSupportedException("F-NET only supports floating-point data");
}
}
///
/// Gets or sets the for the objects in the of this .
///
///
/// This property only supports floating-point data; F-NET doesn't transport scaled values.
///
/// F-NET only supports floating-point data.
public override DataFormat AnalogDataFormat
{
get => DataFormat.FloatingPoint;
set
{
if (value != DataFormat.FloatingPoint)
throw new NotSupportedException("F-NET only supports floating-point data");
}
}
///
/// Gets or sets time offset of F-NET device in .
///
///
/// F-NET devices normally report time in 11 seconds past real-time, this property defines the offset for this artificial delay.
/// Note that the parameter value is in ticks to allow a very high-resolution offset; 1 second = 10,000,000 ticks.
///
public Ticks TimeOffset
{
get => m_timeOffset;
set => m_timeOffset = value;
}
///
/// Gets or sets the longitude (i.e., East/West geospatial position) of the device defined by this .
///
public double Longitude
{
get => m_longitude;
set => m_longitude = value;
}
///
/// Gets or sets the latitude (i.e., North/South geospatial position) of the device defined by this .
///
public double Latitude
{
get => m_latitude;
set => m_latitude = value;
}
///
/// Gets or sets the number of satellites visible to the GPS timing source of the device defined by this .
///
public int NumberOfSatellites
{
get => m_numberOfSatellites;
set => m_numberOfSatellites = value;
}
///
/// Gets the maximum length of the of this .
///
public override int MaximumStationNameLength => int.MaxValue; // The station name is defined external to the protocol, so there is no set limit
///
/// of string based property names and values for the object.
///
public override Dictionary Attributes
{
get
{
Dictionary baseAttributes = base.Attributes;
baseAttributes.Add("Time Offset (ticks)", ((long)TimeOffset).ToString());
baseAttributes.Add("Time Offset (seconds)", Ticks.ToSeconds(TimeOffset).ToString());
baseAttributes.Add("Longitude", Longitude.ToString());
baseAttributes.Add("Latitude", Latitude.ToString());
baseAttributes.Add("Number of Satellites", NumberOfSatellites.ToString());
return baseAttributes;
}
}
#endregion
#region [ Methods ]
///
/// 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 configuration cell
info.AddValue("timeOffset", (long)m_timeOffset);
info.AddValue("longitude", m_longitude);
info.AddValue("latitude", m_latitude);
info.AddValue("numberOfSatellites", m_numberOfSatellites);
}
#endregion
}
}