/* * 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 { /// /// /// Representation of the information found in a binary channel header. /// /// public class TDASBinaryChannelHeader : Exceptional, IChannelHeader { /// /// /// Get/set acquisition rate value. /// public Double AcquisitionRate { get; set; } /// /// Get/set number of pre-T0 data points. /// public int NumberOfPreT0DataPoints { get; set; } /// /// Get/set number of post-T0 data points. /// public int NumberOfPostT0DataPoints { get; set; } /// /// Get/set z. /// public int PreZeroLevelInCnts { get; set; } /// /// Get/set z. /// public int PreCalLevelInCnts { get; set; } /// /// Get/set z. /// public Double SignalToNoiseRatioInDb { get; set; } /// /// Get/set z. /// public int PostZeroLevelInCnts { get; set; } /// /// Get/set z. /// public int PostCalLevelInCnts { get; set; } /// /// Get/set z. /// public int DataZeroLevelInCnts { get; set; } /// /// Get/set scale factor MV. /// public Double ScaleFactorMVPerCnt { get; set; } /// /// Get/set z. /// public Double ScaleFactorEUPerCnt { get; set; } /// /// Calculate the CRC32 for this binary channe header. /// /// /// /// option enables/disables automatic stripping of EU padding. /// /// /// /// The CRC32 of the binary channel header. /// /// private UInt32 CalculateCrc32(bool stripEuPadding, bool bKeepEuLength) { try { var data = new List(); 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); } } } /// /// Get The CRC for the current state of the header (autostrip padding from EU first). /// 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); } } } /// /// Get the CRC for the current state of the header. /// 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); } } } } } }