init
This commit is contained in:
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
* TDAS.File.BinaryChannelHeader.cs
|
||||
*
|
||||
* Copyright © 2009
|
||||
* Diversified Technical Systems, Inc.
|
||||
* All Rights Reserved
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DTS.Common.Utilities;
|
||||
using DTS.Common.Utils;
|
||||
|
||||
namespace DTS.Serialization.TDAS
|
||||
{
|
||||
// *** see TDAS.File.cs ***
|
||||
public partial class File
|
||||
{ ///
|
||||
/// <summary>
|
||||
/// Representation of the information found in a binary channel header.
|
||||
/// </summary>
|
||||
///
|
||||
public class TDASBinaryChannelHeader
|
||||
: Exceptional,
|
||||
IChannelHeader
|
||||
{ ///
|
||||
/// <summary>
|
||||
/// Get/set acquisition rate value.
|
||||
/// </summary>
|
||||
public Double AcquisitionRate
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set number of pre-T0 data points.
|
||||
/// </summary>
|
||||
public int NumberOfPreT0DataPoints
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set number of post-T0 data points.
|
||||
/// </summary>
|
||||
public int NumberOfPostT0DataPoints
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set z.
|
||||
/// </summary>
|
||||
public int PreZeroLevelInCnts
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set z.
|
||||
/// </summary>
|
||||
public int PreCalLevelInCnts
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set z.
|
||||
/// </summary>
|
||||
public Double SignalToNoiseRatioInDb
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set z.
|
||||
/// </summary>
|
||||
public int PostZeroLevelInCnts
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set z.
|
||||
/// </summary>
|
||||
public int PostCalLevelInCnts
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set z.
|
||||
/// </summary>
|
||||
public int DataZeroLevelInCnts
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set scale factor MV.
|
||||
/// </summary>
|
||||
public Double ScaleFactorMVPerCnt
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get/set z.
|
||||
/// </summary>
|
||||
public Double ScaleFactorEUPerCnt
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the CRC32 for this binary channe header.
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="stripEuPadding">
|
||||
/// <see cref="bool"/> option enables/disables automatic stripping of EU padding.
|
||||
/// </param>
|
||||
///
|
||||
/// <returns>
|
||||
/// The CRC32 of the binary channel header.
|
||||
/// </returns>
|
||||
///
|
||||
private UInt32 CalculateCrc32(bool stripEuPadding, bool bKeepEuLength)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = new List<byte>();
|
||||
|
||||
data.AddRange(BitConverter.GetBytes(AcquisitionRate));
|
||||
data.AddRange(BitConverter.GetBytes(NumberOfPreT0DataPoints));
|
||||
data.AddRange(BitConverter.GetBytes(NumberOfPostT0DataPoints));
|
||||
data.AddRange(BitConverter.GetBytes(PreZeroLevelInCnts));
|
||||
data.AddRange(BitConverter.GetBytes(PreCalLevelInCnts));
|
||||
data.AddRange(BitConverter.GetBytes(SignalToNoiseRatioInDb));
|
||||
data.AddRange(BitConverter.GetBytes(PostZeroLevelInCnts));
|
||||
data.AddRange(BitConverter.GetBytes(PostCalLevelInCnts));
|
||||
data.AddRange(BitConverter.GetBytes(DataZeroLevelInCnts));
|
||||
data.AddRange(BitConverter.GetBytes(ScaleFactorMVPerCnt));
|
||||
data.AddRange(BitConverter.GetBytes(ScaleFactorEUPerCnt));
|
||||
if (data.Count % 2 > 0) data.Add(0x0);
|
||||
var byteDataArray = data.ToArray();
|
||||
ushort crc = 0xFFFF;
|
||||
for (var i = 0; i < data.Count; i += 2)
|
||||
crc = Utils.Math_DoCRC16Step(BitConverter.ToUInt16(byteDataArray, i), crc);
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
throw new Exception("encountered problem calculating CRC 32", ex);
|
||||
}
|
||||
}
|
||||
public UInt32 UnpaddedEuStringPaddedEuLengthCrc32
|
||||
{
|
||||
get
|
||||
{
|
||||
try { return CalculateCrc32(true, true); }
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
throw new Exception("encountered problem getting CRC32 for binary header channel with unpadded EU string and padded EU Length", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Get The CRC for the current state of the header (autostrip padding from EU first).
|
||||
/// </summary>
|
||||
public UInt32 UnpaddedEuCrc32
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return CalculateCrc32(true, false);
|
||||
}
|
||||
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
throw new Exception("encountered problem getting CRC32 for binary header channel with unpadded EU string", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the CRC for the current state of the header.
|
||||
/// </summary>
|
||||
public UInt32 Crc32
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return CalculateCrc32(false, false);
|
||||
}
|
||||
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
throw new Exception("encountered problem generating CRC for binary channel header information", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user