ChecksumExtensions
Namespace:
GSF.Core
We found 10 examples in language CSharp for this search.
You will see 16 fragments of code.
Other methods
Other methods
Project:io
File:ChecksumExtensions.cs
Examples:6
/// <summary>Calculates the Adler-32 checksum on specified portion of a buffer.</summary>
/// <param name="data">Data buffer to perform checksum on.</param>
/// <param name="startIndex">Starts index in data buffer to begin checksum.</param>
/// <param name="length">Total number of bytes from <paramref name="startIndex">startIndex</paramref> to
/// perform checksum over.</param>
/// <returns>Computed Adler-32 checksum over the specified portion of the buffer.</returns>
public static uint Adler32Checksum(this byte[] data, int startIndex, int length)
{
Adler32 checksum = new Adler32();
checksum.Update(data, startIndex, length);
return checksum.Value;
}
/// <summary>Calculates the CRC16 check-sum on specified portion of a buffer.</summary>
/// <param name="data">Data buffer to perform check-sum on.</param>
/// <param name="startIndex">Starts index in data buffer to begin check-sum.</param>
/// <param name="length">Total number of bytes from <paramref name="startIndex">startIndex</paramref> to
/// perform check-sum over.</param>
/// <returns>Computed CRC16 checksum over the specified portion of the buffer.</returns>
public static ushort Crc16Checksum(this byte[] data, int startIndex, int length)
{
Crc16 checksum = new Crc16();
checksum.Update(data, startIndex, length);
return checksum.Value;
}
/// <summary>Calculates the CRC-CCITT check-sum on specified portion of a buffer.</summary>
/// <param name="data">Data buffer to perform check-sum on.</param>
/// <param name="startIndex">Starts index in data buffer to begin check-sum.</param>
/// <param name="length">Total number of bytes from <paramref name="startIndex">startIndex</paramref> to
/// perform check-sum over.</param>
/// <returns>Computed CRC-CCITT checksum over the specified portion of the buffer.</returns>
/// <remarks>
/// The CRC-CCITT is a table based 16-bit CRC popular for modem protocols defined for use by the
/// Consultative Committee on International Telegraphy and Telephony (CCITT)
/// </remarks>
public static ushort CrcCCITTChecksum(this byte[] data, int startIndex, int length)
{
CrcCCITT checksum = new CrcCCITT();
checksum.Update(data, startIndex, length);
return checksum.Value;
}
/// <summary>Calculates the CRC-ModBus check-sum on specified portion of a buffer.</summary>
/// <param name="data">Data buffer to perform check-sum on.</param>
/// <param name="startIndex">Starts index in data buffer to begin check-sum.</param>
/// <param name="length">Total number of bytes from <paramref name="startIndex">startIndex</paramref> to
/// perform check-sum over.</param>
/// <returns>Computed CRC-ModBus checksum over the specified portion of the buffer.</returns>
public static ushort ModBusCrcChecksum(this byte[] data, int startIndex, int length)
{
Crc16 checksum = new Crc16(ChecksumType.ModBus);
checksum.Update(data, startIndex, length);
return checksum.Value;
}
/// <summary>Calculates the CRC32 check-sum on specified portion of a buffer.</summary>
/// <param name="data">Data buffer to perform check-sum on.</param>
/// <param name="startIndex">Starts index in data buffer to begin check-sum.</param>
/// <param name="length">Total number of bytes from <paramref name="startIndex">startIndex</paramref> to
/// perform check-sum over.</param>
/// <returns>Computed CRC32 checksum over the specified portion of the buffer.</returns>
public static uint Crc32Checksum(this byte[] data, int startIndex, int length)
{
Crc32 checksum = new Crc32();
checksum.Update(data, startIndex, length);
return checksum.Value;
}
/// <summary>Calculates byte length (8-bit) XOR-based check-sum on specified portion of a buffer.</summary>
/// <param name="data">Data buffer to perform XOR check-sum on.</param>
/// <param name="startIndex">Starts index in data buffer to begin XOR check-sum.</param>
/// <param name="length">Total number of bytes from <paramref name="startIndex">startIndex</paramref> to
/// perform XOR check-sum over.</param>
/// <returns>Byte length XOR check-sum.</returns>
public static byte Xor8Checksum(this byte[] data, int startIndex, int length)
{
Xor8 checksum = new Xor8();
checksum.Update(data, startIndex, length);
return checksum.Value;
}
Project:Adapt
File:ChannelParsingStateBase.cs
Examples:1
//******************************************************************************************************
// ChannelParsingStateBase.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:
// ----------------------------------------------------------------------------------------------------
// 3/7/2005 - J. Ritchie Carroll
// Generated original version of source code.
// 09/15/2009 - Stephen C. Wills
// Added new header and license agreement.
// 10/5/2012 - Gavin E. Holden
// Added new header and license agreement.
// 12/17/2012 - Starlynn Danyelle Gilliam
// Modified Header.
// 04/27/2021 - C. Lackner
// moved to .net core for ADAPT.
//
//******************************************************************************************************
using Gemstone;
using Gemstone.IO.Checksums.ChecksumExtensions;
using Gemstone.IO.Parsing;
using Gemstone.Numeric;
using GemstoneCommon;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
namespace GemstonePhasorProtocolls
{
/// <summary>
/// Represents the common implementation of the protocol independent parsing state class used by any kind of data.<br/>
/// This is the base class of all parsing state classes in the phasor protocols library;
/// it is the root of the parsing state class hierarchy.
/// </summary>
/// <remarks>
/// This class is inherited by subsequent classes to provide parsing state information particular to data type needs.
/// </remarks>
public abstract class ChannelParsingStateBase : IChannelParsingState
{
#region [ Members ]
// Fields
#endregion
#region [ Properties ]
/// <summary>
/// Gets or sets the length of the associated <see cref="IChannel"/> object being parsed from the binary image.
/// </summary>
public virtual int ParsedBinaryLength { get; set; }
#endregion
}
}
Project:Adapt
File:DataCellCollection.cs
Examples:1
//******************************************************************************************************
// DataCellCollection.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:
// ----------------------------------------------------------------------------------------------------
// 11/12/2004 - 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.
// 04/27/2021 - C. Lackner
// moved to .net core for ADAPT.
//
//******************************************************************************************************
using Gemstone;
using Gemstone.ArrayExtensions;
using Gemstone.IO.Checksums.ChecksumExtensions;
using Gemstone.IO.Parsing;
using Gemstone.Numeric;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;
using System.Text;
namespace GemstonePhasorProtocolls.IEEEC37_118
{
/// <summary>
/// Represents a IEEE C37.118 implementation of a collection of <see cref="IDataCell"/> objects.
/// </summary>
[Serializable]
public class DataCellCollection : GemstonePhasorProtocolls.DataCellCollection
{
#region [ Constructors ]
/// <summary>
/// Creates a new <see cref="DataCellCollection"/>.
/// </summary>
public DataCellCollection()
: base(ushort.MaxValue, false)
{
}
/// <summary>
/// Creates a new <see cref="DataCellCollection"/> 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 DataCellCollection(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
#endregion
#region [ Properties ]
/// <summary>
/// Gets or sets <see cref="DataCell"/> at specified <paramref name="index"/>.
/// </summary>
/// <param name="index">Index of value to get or set.</param>
public new DataCell this[int index]
{
get => base[index] as DataCell;
set => base[index] = value;
}
#endregion
}
}
Project:Adapt
File:ConfigurationFrame1Draft6.cs
Examples:1
//******************************************************************************************************
// ConfigurationFrame1Draft6.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:
// ----------------------------------------------------------------------------------------------------
// 11/12/2004 - 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.
// 04/23/2021 - C. Lackner
// moved to .net core for ADAPT.
//
//******************************************************************************************************
using Gemstone;
using Gemstone.IO.Checksums.ChecksumExtensions;
using Gemstone.IO.Parsing;
using Gemstone.Numeric;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;
using System.Text;
namespace GemstonePhasorProtocolls.IEEEC37_118
{
/// <summary>
/// Represents the IEEE C37.118 draft 6 implementation of a <see cref="IConfigurationFrame"/>, type 1, that can be sent or received.
/// </summary>
[Serializable]
public class ConfigurationFrame1Draft6 : ConfigurationFrame1
{
#region [ Constructors ]
/// <summary>
/// Creates a new <see cref="ConfigurationFrame1Draft6"/>.
/// </summary>
/// <remarks>
/// This constructor is used by <see cref="FrameImageParserBase{TTypeIdentifier,TOutputType}"/> to parse an IEEE C37.118 draft 6 configuration frame.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public ConfigurationFrame1Draft6()
{
}
/// <summary>
/// Creates a new <see cref="ConfigurationFrame1Draft6"/> from specified parameters.
/// </summary>
/// <param name="timebase">Timebase to use for fraction second resolution.</param>
/// <param name="idCode">The ID code of this <see cref="ConfigurationFrame1Draft6"/>.</param>
/// <param name="timestamp">The exact timestamp, in <see cref="Ticks"/>, of the data represented by this <see cref="ConfigurationFrame1Draft6"/>.</param>
/// <param name="frameRate">The defined frame rate of this <see cref="ConfigurationFrame1Draft6"/>.</param>
/// <remarks>
/// This constructor is used by a consumer to generate an IEEE C37.118 draft 6 configuration frame.
/// </remarks>
public ConfigurationFrame1Draft6(uint timebase, ushort idCode, Ticks timestamp, ushort frameRate)
: base(timebase, idCode, timestamp, frameRate)
{
}
/// <summary>
/// Creates a new <see cref="ConfigurationFrame1Draft6"/> 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 ConfigurationFrame1Draft6(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
#endregion
#region [ Properties ]
/// <summary>
/// Gets the <see cref="IEEEC37_118.DraftRevision"/> of this <see cref="ConfigurationFrame1Draft6"/>.
/// </summary>
public override DraftRevision DraftRevision => DraftRevision.Draft6;
#endregion
}
}
Project:Adapt
File:ConfigurationFrame2.cs
Examples:1
//******************************************************************************************************
// ConfigurationFrame2.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:
// ----------------------------------------------------------------------------------------------------
// 11/12/2004 - 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.
// 04/27/2021 - C. Lackner
// moved to .net core for ADAPT.
//
//******************************************************************************************************
using Gemstone;
using Gemstone.IO.Checksums.ChecksumExtensions;
using Gemstone.IO.Parsing;
using Gemstone.Numeric;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;
using System.Text;
namespace GemstonePhasorProtocolls.IEEEC37_118
{
/// <summary>
/// Represents the IEEE C37.118 implementation of a <see cref="IConfigurationFrame"/>, type 2, that can be sent or received.
/// </summary>
[Serializable]
public class ConfigurationFrame2 : ConfigurationFrame1
{
#region [ Constructors ]
/// <summary>
/// Creates a new <see cref="ConfigurationFrame2"/>.
/// </summary>
/// <remarks>
/// This constructor is used by <see cref="FrameImageParserBase{TTypeIdentifier,TOutputType}"/> to parse an IEEE C37.118 configuration frame, type 2.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public ConfigurationFrame2()
{
}
/// <summary>
/// Creates a new <see cref="ConfigurationFrame2"/> from specified parameters.
/// </summary>
/// <param name="timebase">Timebase to use for fraction second resolution.</param>
/// <param name="idCode">The ID code of this <see cref="ConfigurationFrame2"/>.</param>
/// <param name="timestamp">The exact timestamp, in <see cref="Ticks"/>, of the data represented by this <see cref="ConfigurationFrame2"/>.</param>
/// <param name="frameRate">The defined frame rate of this <see cref="ConfigurationFrame2"/>.</param>
/// <remarks>
/// This constructor is used by a consumer to generate an IEEE C37.118 configuration frame, type 2.
/// </remarks>
public ConfigurationFrame2(uint timebase, ushort idCode, Ticks timestamp, ushort frameRate)
: base(timebase, idCode, timestamp, frameRate)
{
}
/// <summary>
/// Creates a new <see cref="ConfigurationFrame2"/> 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 ConfigurationFrame2(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
#endregion
#region [ Properties ]
/// <summary>
/// Gets the <see cref="FrameType"/> of this <see cref="ConfigurationFrame2"/>.
/// </summary>
public override FrameType TypeID => IEEEC37_118.FrameType.ConfigurationFrame2;
#endregion
}
}
Project:Adapt
File:DataFrameParsingState.cs
Examples:1
//******************************************************************************************************
// DataFrameParsingState.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.
// 10/5/2012 - Gavin E. Holden
// Added new header and license agreement.
// 12/17/2012 - Starlynn Danyelle Gilliam
// Modified Header.
// 04/26/2021 - C. Lackner
// moved to .net core for ADAPT.
//
//******************************************************************************************************
using Gemstone;
using Gemstone.IO.Checksums.ChecksumExtensions;
using Gemstone.IO.Parsing;
using Gemstone.Numeric;
using GemstoneCommon;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
namespace GemstonePhasorProtocolls.IEEEC37_118
{
/// <summary>
/// Represents the protocol independent common implementation of the parsing state used by any <see cref="IDataFrame"/>.
/// </summary>
public class DataFrameParsingState : ChannelFrameParsingStateBase<IDataCell>, IDataFrameParsingState
{
#region [ Members ]
// Fields
#endregion
#region [ Constructors ]
/// <summary>
/// Creates a new <see cref="DataFrameParsingState"/> from specified parameters.
/// </summary>
/// <param name="parsedBinaryLength">Binary length of the <see cref="IDataFrame"/> being parsed.</param>
/// <param name="configurationFrame">Reference to the <see cref="IConfigurationFrame"/> associated with the <see cref="IDataFrame"/> being parsed.</param>
/// <param name="createNewCellFunction">Reference to delegate to create new <see cref="IDataCell"/> instances.</param>
/// <param name="trustHeaderLength">Determines if header lengths should be trusted over parsed byte count.</param>
/// <param name="validateCheckSum">Determines if frame's check-sum should be validated.</param>
public DataFrameParsingState(int parsedBinaryLength, IConfigurationFrame configurationFrame, CreateNewCellFunction<IDataCell> createNewCellFunction, bool trustHeaderLength, bool validateCheckSum)
: base(parsedBinaryLength, createNewCellFunction, trustHeaderLength, validateCheckSum)
{
if (configurationFrame is null)
return;
CellCount = configurationFrame.Cells.Count;
ConfigurationFrame = configurationFrame;
}
#endregion
#region [ Properties ]
/// <summary>
/// Gets reference to the <see cref="IConfigurationFrame"/> associated with the <see cref="IDataFrame"/> being parsed.
/// </summary>
public virtual IConfigurationFrame ConfigurationFrame { get; }
#endregion
}
}
Project:Adapt
File:ConfigurationFrame2Draft6.cs
Examples:1
//******************************************************************************************************
// ConfigurationFrame2Draft6.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:
// ----------------------------------------------------------------------------------------------------
// 11/12/2004 - 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.
// 04/27/2021 - C. Lackner
// moved to .net core for ADAPT.
//
//******************************************************************************************************
using Gemstone;
using Gemstone.IO.Checksums.ChecksumExtensions;
using Gemstone.IO.Parsing;
using Gemstone.Numeric;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;
using System.Text;
namespace GemstonePhasorProtocolls.IEEEC37_118
{
/// <summary>
/// Represents the IEEE C37.118 draft 6 implementation of a <see cref="IConfigurationFrame"/>, type 2, that can be sent or received.
/// </summary>
[Serializable]
public class ConfigurationFrame2Draft6 : ConfigurationFrame2
{
#region [ Constructors ]
/// <summary>
/// Creates a new <see cref="ConfigurationFrame2Draft6"/>.
/// </summary>
/// <remarks>
/// This constructor is used by <see cref="FrameImageParserBase{TTypeIdentifier,TOutputType}"/> to parse an IEEE C37.118 draft 6 configuration frame, type 2.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public ConfigurationFrame2Draft6()
{
}
/// <summary>
/// Creates a new <see cref="ConfigurationFrame2Draft6"/> from specified parameters.
/// </summary>
/// <param name="timebase">Timebase to use for fraction second resolution.</param>
/// <param name="idCode">The ID code of this <see cref="ConfigurationFrame2Draft6"/>.</param>
/// <param name="timestamp">The exact timestamp, in <see cref="Ticks"/>, of the data represented by this <see cref="ConfigurationFrame2Draft6"/>.</param>
/// <param name="frameRate">The defined frame rate of this <see cref="ConfigurationFrame2Draft6"/>.</param>
/// <remarks>
/// This constructor is used by a consumer to generate an IEEE C37.118 draft 6 configuration frame, type 2.
/// </remarks>
public ConfigurationFrame2Draft6(uint timebase, ushort idCode, Ticks timestamp, ushort frameRate)
: base(timebase, idCode, timestamp, frameRate)
{
}
/// <summary>
/// Creates a new <see cref="ConfigurationFrame2Draft6"/> 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 ConfigurationFrame2Draft6(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
#endregion
#region [ Properties ]
/// <summary>
/// Gets the <see cref="IEEEC37_118.DraftRevision"/> of this <see cref="ConfigurationFrame2Draft6"/>.
/// </summary>
public override DraftRevision DraftRevision => DraftRevision.Draft6;
#endregion
}
}
Project:Adapt
File:ConfigurationFrameParsingState.cs
Examples:1
//******************************************************************************************************
// ConfigurationFrameParsingState.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.
// 10/5/2012 - Gavin E. Holden
// Added new header and license agreement.
// 12/17/2012 - Starlynn Danyelle Gilliam
// Modified Header.
// 04/27/2021 - C. Lackner
// moved to .net core for ADAPT.
//
//******************************************************************************************************
using Gemstone;
using Gemstone.IO.Checksums.ChecksumExtensions;
using Gemstone.IO.Parsing;
using Gemstone.Numeric;
using GemstoneCommon;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
namespace GemstonePhasorProtocolls
{
/// <summary>
/// Represents the protocol independent common implementation of the parsing state used by any <see cref="IConfigurationFrame"/>.
/// </summary>
public class ConfigurationFrameParsingState : ChannelFrameParsingStateBase<IConfigurationCell>, IConfigurationFrameParsingState
{
#region [ Constructors ]
/// <summary>
/// Creates a new <see cref="ConfigurationFrameParsingState"/> from specified parameters.
/// </summary>
/// <param name="parsedBinaryLength">Binary length of the <see cref="IConfigurationFrame"/> being parsed.</param>
/// <param name="createNewCellFunction">Reference to delegate to create new <see cref="IConfigurationCell"/> instances.</param>
/// <param name="trustHeaderLength">Determines if header lengths should be trusted over parsed byte count.</param>
/// <param name="validateCheckSum">Determines if frame's check-sum should be validated.</param>
public ConfigurationFrameParsingState(int parsedBinaryLength, CreateNewCellFunction<IConfigurationCell> createNewCellFunction, bool trustHeaderLength, bool validateCheckSum)
: base(parsedBinaryLength, createNewCellFunction, trustHeaderLength, validateCheckSum)
{
}
/// <summary>
/// Creates a new <see cref="ConfigurationFrameParsingState"/> from specified parameters.
/// </summary>
/// <param name="parsedBinaryLength">Binary length of the <see cref="IConfigurationFrame"/> being parsed.</param>
/// <param name="createNewCellFunction">Reference to delegate to create new <see cref="IConfigurationCell"/> instances.</param>
/// <param name="trustHeaderLength">Determines if header lengths should be trusted over parsed byte count.</param>
/// <param name="validateCheckSum">Determines if frame's check-sum should be validated.</param>
/// <param name="cellCount">Number of cells that exist in the frame to be parsed.</param>
public ConfigurationFrameParsingState(int parsedBinaryLength, CreateNewCellFunction<IConfigurationCell> createNewCellFunction, bool trustHeaderLength, bool validateCheckSum, int cellCount)
: base(parsedBinaryLength, createNewCellFunction, trustHeaderLength, validateCheckSum)
{
CellCount = cellCount;
}
#endregion
}
}
Project:Adapt
File:FrameImageCollector.cs
Examples:2
#endregion
#region [ Methods ]
/// <summary>
/// Releases all the resources used by the <see cref="FrameImageCollector"/> object.
/// </summary>
public void Dispose()
{
if (m_disposed)
return;
try
{
m_frameQueue?.Dispose();
}
finally
{
m_disposed = true; // Prevent duplicate dispose.
}
}
/// <summary>
/// Appends the current frame image to the frame image collection.
/// </summary>
/// <param name="buffer">A <see cref="byte"/> array to append to the collection.</param>
/// <param name="length">An <see cref="int"/> value indicating the number of bytes to read from the <paramref name="buffer"/>.</param>
/// <param name="offset">An <see cref="int"/> value indicating the offset to read from.</param>
public void AppendFrameImage(byte[] buffer, int offset, int length)
{
// Include initial header in new stream
if (m_frameQueue.Length == 0)
m_frameQueue.Write(buffer, offset, ConfigurationFrame3.FrameHeaderLength);
// Skip past header, including CONT_IDX
offset += ConfigurationFrame3.FrameHeaderLength;
// Include frame image
m_frameQueue.Write(buffer, offset, length - ConfigurationFrame3.FrameHeaderLength);
// Track total frame images
Count++;
}
Project:Adapt
File:ChannelFrameParsingStateBase.cs
Examples:1
//******************************************************************************************************
// ChannelFrameParsingStateBase.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.
// 10/5/2012 - Gavin E. Holden
// Added new header and license agreement.
// 12/17/2012 - Starlynn Danyelle Gilliam
// Modified Header.
// 04/27/2021 - C. Lackner
// moved to .net core for ADAPT.
//
//******************************************************************************************************
using Gemstone;
using Gemstone.IO.Checksums.ChecksumExtensions;
using Gemstone.IO.Parsing;
using Gemstone.Numeric;
using GemstoneCommon;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
namespace GemstonePhasorProtocolls
{
/// <summary>
/// Represents the protocol independent common implementation of the parsing state used by any <see cref="IChannelFrame"/>.
/// </summary>
/// <typeparam name="T"><see cref="Type"/> of <see cref="IChannelCell"/> referenced by <see cref="IChannelFrame"/> being parsed.</typeparam>
public abstract class ChannelFrameParsingStateBase<T> : ChannelParsingStateBase, IChannelFrameParsingState<T> where T : IChannelCell
{
#region [ Members ]
// Fields
private bool m_trustHeaderLength;
private bool m_validateCheckSum;
#endregion
#region [ Constructors ]
/// <summary>
/// Creates a new <see cref="ChannelFrameParsingStateBase{T}"/> from specified parameters.
/// </summary>
/// <param name="parsedBinaryLength">Binary length of the <see cref="IChannelFrame"/> being parsed.</param>
/// <param name="createNewCellFunction">Reference to delegate to create new <see cref="IChannelCell"/> instances.</param>
/// <param name="trustHeaderLength">Determines if header lengths should be trusted over parsed byte count.</param>
/// <param name="validateCheckSum">Determines if frame's check-sum should be validated.</param>
protected ChannelFrameParsingStateBase(int parsedBinaryLength, CreateNewCellFunction<T> createNewCellFunction, bool trustHeaderLength, bool validateCheckSum)
{
base.ParsedBinaryLength = parsedBinaryLength;
CreateNewCell = createNewCellFunction;
m_trustHeaderLength = trustHeaderLength;
m_validateCheckSum = validateCheckSum;
}
#endregion
#region [ Properties ]
/// <summary>
/// Gets reference to delegate used to create a new <see cref="IChannelCell"/> object.
/// </summary>
public virtual CreateNewCellFunction<T> CreateNewCell { get; }
/// <summary>
/// Gets or sets number of cells that are expected in associated <see cref="IChannelFrame"/> being parsed.
/// </summary>
public virtual int CellCount { get; set; }
/// <summary>
/// Gets or sets flag that determines if header lengths should be trusted over parsed byte count.
/// </summary>
/// <remarks>
/// It is expected that this will normally be left as <c>true</c>.
/// </remarks>
public virtual bool TrustHeaderLength
{
get => m_trustHeaderLength;
set => m_trustHeaderLength = value;
}
/// <summary>
/// Gets or sets flag that determines if frame's check-sum should be validated.
/// </summary>
/// <remarks>
/// It is expected that this will normally be left as <c>true</c>.
/// </remarks>
public virtual bool ValidateCheckSum
{
get => m_validateCheckSum;
set => m_validateCheckSum = value;
}
#endregion
}
}
GSF.IO.Checksums.ChecksumExtensions : Object
Methods :
public static UInt32 Adler32Checksum(Byte[] data = , Int32 startIndex = , Int32 length = )public static UInt16 Crc16Checksum(Byte[] data = , Int32 startIndex = , Int32 length = )
public static UInt16 CrcCCITTChecksum(Byte[] data = , Int32 startIndex = , Int32 length = )
public static UInt16 ModBusCrcChecksum(Byte[] data = , Int32 startIndex = , Int32 length = )
public static UInt32 Crc32Checksum(Byte[] data = , Int32 startIndex = , Int32 length = )
public static Byte Xor8Checksum(Byte[] data = , Int32 startIndex = , Int32 length = )
public static UInt16 Xor16Checksum(Byte[] data = , Int32 startIndex = , Int32 length = )
public static UInt32 Xor32Checksum(Byte[] data = , Int32 startIndex = , Int32 length = )
public static UInt64 Xor64Checksum(Byte[] data = , Int32 startIndex = , Int32 length = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()