This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1,414 @@
using System;
using System.Collections.Generic;
using System.Linq;
using DTS.Common.Utilities;
namespace DTS.Slice.Control
{
// *** see DTS.Slice.Control.Event.cs ***
public partial class Event
{
// *** see DTS.Slice.Control.Event.Module.cs ***
public partial class Module
{
public partial class Channel
{
public abstract class CalculatedChannel : Channel, Common.DAS.Concepts.DAS.Channel.IEngineeringUnitAware
{
public enum Operation
{
Integral,
//DefiniteIntegral,
Derivative,
HeadInjuryCriteria,
FFT,
ImportedCSV,
Resultant,
TSR,
Scale,
Offset,
Sine,
Cosine,
}
private readonly Operation _operation;
public Operation CalculationType => _operation;
private readonly List<double> _x = new List<double>();
public double[] X => _x.ToArray();
private readonly List<double> _y = new List<double>();
public double[] Y => _y.ToArray();
private readonly XUnits _xAxis;
public XUnits XAxis => _xAxis;
public string XUnitsString
{
get
{
switch (_xAxis)
{
case XUnits.Hz: return "Hz";
case XUnits.msec: return "ms";
case XUnits.samples: return "samples";
case XUnits.sec: return "s";
default: return "N/A";
}
}
}
private string _yAxis;
public string EngineeringUnits { get => _yAxis;
set => _yAxis = value;
}
public override bool SupportsADC => false;
public override bool SupportsEU => true;
public override bool SupportsmV => false;
public override double ActualMaxRangeEu => _y.Max();
public override double ActualMaxRangeMv => throw new NotSupportedException();
public override double ActualMinRangeEu => _y.Min();
public override double ActualMinRangeMv => throw new NotImplementedException();
public override double DataHalfRangeValueEu => .5D * (_y.Min() + _y.Max());
public override double DataMaxEu => _y.Max();
public override double DataMinEu => _y.Min();
public override double DataRangeEu => (Math.Max(Math.Abs(_y.Min()), Math.Abs(_y.Max())));
public override short DataZeroLevelAdc => 0;
public override bool IsConfigured
{
get => true;
set => throw new NotSupportedException();
}
public override void FromDtsSerializationTestModuleChannel(Serialization.Test.Module.Channel that)
{
throw new NotSupportedException();
}
public override List<double> GetUnfilteredDataEu()
{
return new List<double>(_y);
}
/*
protected override void InitializeReviewableAttributes(List<ReviewableAttribute> reviewableAttributes)
{
switch (CalculationType)
{
case Operation.HeadInjuryCriteria:
break;
case Operation.ImportedCSV:
break;
case Operation.TSR:
break;
}
} */
public override void SetPropertyValuesFrom(DASLib.Service.DASChannel dasChannel)
{
throw new NotSupportedException();
}
public override void SetPropertyValuesFrom(DASLib.Service.DiagnosticsResult diagResults)
{
throw new NotSupportedException();
}
public override Serialization.Test.Module.Channel ToDtsSerializationTestModuleChannel(Serialization.Test.Module parentModule)
{
throw new NotSupportedException();
}
public override double SensorCapacityEU => throw new NotImplementedException();
public override List<double> GetUnfilteredDataMV()
{
throw new NotImplementedException();
}
public override double DesiredRangeEU => throw new NotImplementedException();
public enum XUnits
{
msec,
sec,
Hz,
samples
}
public CalculatedChannel(string name,
XUnits xAxis,
string yAxis,
double[] xValues,
double[] yValues,
Operation calcType,
int number,
Module parentModule
)
{
_x = new List<double>(xValues);
_y = new List<double>(yValues);
_xAxis = xAxis;
_yAxis = yAxis;
ChannelDescriptionString = name;
_operation = calcType;
Number = number;
CurrentFilter = new DefaultSaeJ211Filter(ChannelFilter.Unfiltered);
ParentModule = parentModule;
_UnfilteredDataEu = new List<double>(yValues);
DataCount = yValues.Length;
}
/// <summary>
/// Generate a <see cref="string"/> representation for this object.
/// </summary>
///
/// <returns>
/// The <see cref="string"/> representation of this object.
/// </returns>
///
public override string ToString()
{
try
{
return !string.IsNullOrEmpty(ChannelDescriptionString) ? ChannelDescriptionString : "N/A";
}
catch (System.Exception ex)
{
throw new Exception("encountered problem getting string representation", ex);
}
}
}
public class FFTCalculatedChannel : CalculatedChannel
{
private readonly double _peakFrequency;
public double PeakFrequency => _peakFrequency;
public FFTCalculatedChannel(string name,
XUnits xAxis,
string yAxis,
double[] xValues,
double[] yValues,
Operation calcType,
int number,
Module parentModule,
double peakFrequency)
: base(name, xAxis, yAxis, xValues, yValues, calcType, number, parentModule)
{
_peakFrequency = peakFrequency;
}
/*
protected override void InitializeReviewableAttributes(List<ReviewableAttribute> reviewableAttributes)
{
base.InitializeReviewableAttributes(reviewableAttributes);
//try { reviewableAttributes.Add(new ReviewablePeakFrequencyAttribute(this)); }
//catch { }
}
public class ReviewablePeakFrequencyAttribute : Slice.Control.Event.Module.Channel.ReviewableAttribute
{
public ReviewablePeakFrequencyAttribute(Event.Module.Channel channel)
: base("Peak (Hz)",
delegate { return (channel as FFTCalculatedChannel).PeakFrequency.ToString("N"); }) { }
}*/
}
public class IntegralCalculatedChannel : CalculatedChannel
{
public IntegralCalculatedChannel(string name,
XUnits xAxis,
string yAxis,
double[] xValues,
double[] yValues,
Operation calcType,
int number,
Module parentModule
)
: base(name, xAxis, yAxis, xValues, yValues, calcType, number, parentModule)
{ }
}
public class DerivativeCalculatedChannel : CalculatedChannel
{
public DerivativeCalculatedChannel(string name,
XUnits xAxis,
string yAxis,
double[] xValues,
double[] yValues,
Operation calcType,
int number,
Module parentModule
)
: base(name, xAxis, yAxis, xValues, yValues, calcType, number, parentModule)
{ }
}
public class ScaleCalculatedChannel : CalculatedChannel
{
public ScaleCalculatedChannel(string name,
XUnits xAxis,
string yAxis,
double[] xValues,
double[] yValues,
Operation calcType,
int number,
Module parentModule)
: base(name, xAxis, yAxis, xValues, yValues, calcType, number, parentModule)
{ }
}
public class OffsetCalculatedChannel : CalculatedChannel
{
public OffsetCalculatedChannel(string name,
XUnits xAxis,
string yAxis,
double[] xValues,
double[] yVAlues,
Operation calcType,
int number,
Module parentModule)
: base(name, xAxis, yAxis, xValues, yVAlues, calcType, number, parentModule)
{ }
}
public class ResultantCalculatedChannel : CalculatedChannel
{
public ResultantCalculatedChannel(string name,
XUnits xAxis,
string yAxis,
double[] xValues,
double[] yValues,
Operation calcType,
int number,
Module parentModule)
: base(name, xAxis, yAxis, xValues, yValues, calcType, number, parentModule)
{ }
}
public class AdditiveVectorCalculatedChannel : CalculatedChannel
{
public AdditiveVectorCalculatedChannel(string name,
XUnits xAxis,
string yAxis,
double[] xValues,
double[] yValues,
Operation calcType,
int number,
Module parentModule)
: base(name, xAxis, yAxis, xValues, yValues, calcType, number, parentModule)
{ }
}
public class SineCalculatedChannel : CalculatedChannel
{
public SineCalculatedChannel(string name,
XUnits xAxis,
string yAxis,
double[] xValues,
double[] yValues,
Operation calcType,
int number,
Module parentModule
)
: base(name, xAxis, yAxis, xValues, yValues, calcType, number, parentModule)
{ }
}
public class CosineCalculatedChannel : CalculatedChannel
{
public CosineCalculatedChannel(string name,
XUnits xAxis,
string yAxis,
double[] xValues,
double[] yValues,
Operation calcType,
int number,
Module parentModule
)
: base(name, xAxis, yAxis, xValues, yValues, calcType, number, parentModule)
{ }
}
/*
public class HICCalculatedChannel : CalculatedChannel
{
public double GetT1(bool ms)
{
double start = (double)HIC.StartSample - (double)ParentModule.TriggerSampleNumbers[0] +
(double)ParentModule.StartRecordSampleNumber;
start /= (double)ParentModule.SampleRateHz;
if (ms) { start *= 1000; }
return start;
}
public double GetT2(bool ms)
{
double end = (double)HIC.EndSample - (double)ParentModule.TriggerSampleNumbers[0]
+ (double)ParentModule.StartRecordSampleNumber;
end /= (double)ParentModule.SampleRateHz;
if (ms) { end *= 1000; }
return end;
}
public HICCalculatedChannel(string name,
XUnits xAxis,
string yAxis,
double[] xValues,
double[] yValues,
Operation calcType,
int number,
Module parentModule,
DTS.Calculations.HeadInjuryCriterion.HICResult hic
)
: base(name, xAxis, yAxis, xValues, yValues, calcType, number, parentModule)
{
_hic = hic;
}
private DTS.Calculations.HeadInjuryCriterion.HICResult _hic;
public DTS.Calculations.HeadInjuryCriterion.HICResult HIC { get { return _hic; } }
protected override void InitializeReviewableAttributes(List<ReviewableAttribute> reviewableAttributes)
{
base.InitializeReviewableAttributes(reviewableAttributes);
try { reviewableAttributes.Add(new ReviewableHICAttribute(this)); }
catch {}
try { reviewableAttributes.Add(new ReviewableHICLengthAttribute(this)); }
catch { }
try { reviewableAttributes.Add(new ReviewableHICT1T2Attribute(this)); }
catch { }
}
public class ReviewableHICLengthAttribute : Slice.Control.Event.Module.Channel.ReviewableAttribute
{
public ReviewableHICLengthAttribute(Event.Module.Channel channel)
: base("Clip Length",
delegate { return (channel as HICCalculatedChannel).HIC.HicLengthMS.ToString(); }) { }
}
public class ReviewableHICAttribute
: Slice.Control.Event.Module.Channel.ReviewableAttribute
{
/// <summary>
/// Initialize an instance of this class.
/// </summary>
///
/// <param name="channel">
/// The <see cref="Event.Module.Channel"/> to which this attribute is attached.
/// </param>
///
public ReviewableHICAttribute(Event.Module.Channel channel)
: base("HIC",
delegate { return (channel as HICCalculatedChannel).HIC.HIC.ToString("N1"); })
{
}
}
public class ReviewableHICT1T2Attribute
: Slice.Control.Event.Module.Channel.ReviewableAttribute
{
public ReviewableHICT1T2Attribute(Event.Module.Channel channel)
: base("T1/T2",
delegate
{
HICCalculatedChannel hic = channel as HICCalculatedChannel;
if (null == hic) { return ""; }
else { return string.Format("{0}s/{1}s", hic.GetT1(false), hic.GetT2(false)); }
})
{
}
}
}
* */
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,123 @@
/*
* DTS.Slice.Control.Event.Module.Channel.SaeJ211Filter.cs
*
* Copyright © 2009
* Diversified Technical Systems, Inc.
* All Rights Reserved
*/
using DTS.Common.Utilities;
namespace DTS.Slice.Control
{
public partial class Event
{ // *** see DTS.Slice.Control.Event.cs ***
public partial class Module
{ // *** see DTS.Slice.Control.Event.Module.cs ***
public partial class Channel
{ // *** see DTS.Slice.Control.Event.Module.Channel.cs ***
/// <summary>
/// Base class for all SaeJ211-based event module channel filters. It is intended
/// that fixed-filter-setting filters be derived from this class that will set their
/// filter setting using the protected constructor.
/// </summary>
public class DefaultSaeJ211Filter
: SaeJ211Filter
{
public DefaultSaeJ211Filter(SaeJ211Filter filter)
: base(filter)
{
}
/// <summary>
/// Initialize an instance of the DefaultSaeJ211Filter class.
/// </summary>
///
/// <param name="filter">
/// The <see cref="ChannelFilter"/> to be applied by this filter.
/// </param>
///
public DefaultSaeJ211Filter(ChannelFilter filterType)
: base(filterType)
{
}
/// <summary>
/// Initialize an instance of the DefaultSaeJ211Filter class.
/// </summary>
///
///<param name="adHocFrequency">
///The <see cref="double"/> ad hoc frequency of this filter.
/// </param>
///
public DefaultSaeJ211Filter(double adHocFrequency)
: base(adHocFrequency)
{
}
/// <summary>
/// The <see cref="string"/> name of this filter.
/// </summary>
public override string Name
{
get
{
try
{
return "Default (" + base.Name + ")";
}
catch (System.Exception ex)
{
throw new Exception("encountered problem generating name string for " + GetType().FullName, ex);
}
}
}
/// <summary>
/// Generate a string representation of this object.
/// </summary>
///
/// <returns>
/// A <see cref="string"/> representation of this object.
/// </returns>
///
public override string ToBaseString()
{
try
{
return base.Name;
}
catch (System.Exception ex)
{
throw new Exception("encountered problem generating the string value for " + GetType().FullName, ex);
}
}
/// <summary>
/// Generate a string representation of this object.
/// </summary>
///
/// <returns>
/// A <see cref="string"/> representation of this object.
/// </returns>
///
public override string ToString()
{
try
{
return Name;
}
catch (System.Exception ex)
{
throw new Exception("encountered problem generating the string value for " + GetType().FullName, ex);
}
}
}
}
}
}
}

View File

@@ -0,0 +1,81 @@
/*
* DTS.Slice.Control.Event.Module.Channel.DataValues.cs
*
* Copyright © 2009
* Diversified Technical Systems, Inc.
* All Rights Reserved
*/
using DTS.Common.Utilities;
using DTS.Common.Utilities.DotNetProgrammingConstructs;
namespace DTS.Slice.Control
{
// *** see DTS.Slice.Control.Event.cs ***
public partial class Event {
// *** see DTS.Slice.Control.Event.Module.cs ***
public partial class Module {
// *** see DTS.Slice.Control.Event.Module.Channel.cs ***
public partial class Channel {
/// <summary>
/// Representation of a channel's data.
/// </summary>
public class DataValues : Exceptional
{
/// <summary>
/// Initialize an instance of this class.
/// </summary>
public DataValues( )
: this( true )
{
}
/// <summary>
/// Initialize an instance of this class.
/// </summary>
///
/// <param name="useMemoryMappedFile">
/// A <see cref="bool"/> determining whether or not this data class will use memory mapped files
/// to store data (necessary for data sets that exceed internal process memory limitations).
/// </param>
///
public DataValues( bool useMemoryMappedFile )
{
try
{
UseMemoryMappedFile = useMemoryMappedFile;
if ( UseMemoryMappedFile )
{
}
}
catch ( System.Exception ex )
{
throw new Exception( "encountered problem constructing " + GetType( ).FullName, ex );
}
}
/// <summary>
/// Get/set the switch that will cause this class to use memory mapped files in lieu
/// of in-memory list.
/// </summary>
public bool UseMemoryMappedFile
{
get => _UseMemoryMappedFile.Value;
set => _UseMemoryMappedFile.Value = value;
}
private readonly Property<bool> _UseMemoryMappedFile =
new Property<bool>(
typeof( DataValues ).Namespace + ".UseMemoryMappedFile",
false,
false
);
}
} // *** End Event.Module.Channel ***
} // *** End Event.Module ***
} // *** End Event ***
}

View File

@@ -0,0 +1,99 @@
/*
* DTS.Slice.Control.Event.Module.Channel.cs
*
* Copyright © 2009
* Diversified Technical Systems, Inc.
* All Rights Reserved
*/
using System;
using DTS.Common.Utilities;
using DTS.Slice.Control.DAS.Channel;
namespace DTS.Slice.Control
{
public partial class Event
{ // *** see DTS.Slice.Control.Event.cs ***
public partial class Module
{ // *** see DTS.Slice.Control.Event.Module.cs ***
public partial class Channel
{ // *** see DTS.Slice.Control.Event.Module.Channel.cs ***
/// <summary>
/// A filter for DTS.Slice.Control.Event.Module.Channels.
/// </summary>
public abstract class Filter
: Exceptional,
IFilter
{
/// <summary>
/// A descriptive <see cref="string"/> designation for the filter.
/// </summary>
public abstract string Name
{
get;
}
/// <summary>
/// Get the <see cref="Boolean"/> value indicating whether or not this filter
/// corresponds to a CFC value.
/// </summary>
public abstract bool IsCfc
{
get;
}
/// <summary>
/// Get a <see cref="ChannelFilter"/> designation for this filter.
/// </summary>
public abstract ChannelFilter Type
{
get;
}
/// <summary>
/// Get the <see cref="double"/> cutoff frequency for this filter.
/// </summary>
public abstract double CutoffFrequencyHz
{
get;
}
/// <summary>
/// Apply the filter to the specified input.
/// </summary>
///
/// <param name="input">
/// The input to the filter.
/// </param>
///
/// <param name="displayUnits">
/// The <see cref="DTS.Slice.Control.Event.Module.Channel.DataDisplayUnits"/> to be
/// filtered from the channel.
/// </param>
/// <param name="bUseLegacyTDCSoftwareFilterAdjustment">
/// controls whether filtered data is adjusted by one sample to match TDC behavior
/// 8747
/// </param>
/// <returns>
/// The filtering of the input.
/// </returns>
///
public abstract double[] Apply(
Channel input,
DataDisplayUnits displayUnits,
bool bUseLegacyTDCSoftwareFilterAdjustment);
public abstract double[] Apply(
double[] data,
double sampleRate,
bool bUseLegacyTDCSoftwareFilterAdjustment);
/// <summary>
/// the ToString is already overloaded, but we sometimes need the base name, not the decorated name that
/// is returned in ToString.
/// </summary>
/// <returns></returns>
public abstract string ToBaseString();
}
}
}
}
}

View File

@@ -0,0 +1,81 @@
/*
* DTS.Slice.Control.Event.Module.Channel.ReviewableAttribute.NotApplicableException.cs
*
* Copyright © 2009
* Diversified Technical Systems, Inc.
* All Rights Reserved
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DTS.Slice.Control
{
// *** see DTS.Slice.Control.Event.cs ***
public partial class Event
{
// *** see DTS.Slice.Control.Event.Module.cs ***
public partial class Module
{
// *** see DTS.Slice.Control.Event.Module.Channel.cs ***
public partial class Channel
{
// *** see DTS.Slice.Control.Event.Module.Channel.ReviewableAttribute.cs ***
public partial class ReviewableAttribute
{
/// <summary>
/// Representation of an attempt to use a channel attribute that is not
/// applicable to the associated channel.
/// </summary>
public class NotApplicableException : ApplicationException
{ ///
/// <summary>
/// Initialize an instance of the NotApplicableException class.
/// </summary>
///
public NotApplicableException()
{
}
/// <summary>
/// Initialize an instance of the NotApplicableException class.
/// </summary>
///
/// <param name="msg">
/// The <see cref="string"/> message to be associated with this exception.
/// </param>
///
public NotApplicableException(string msg)
: base(msg)
{
}
/// <summary>
/// Initialize an instance of the NotApplicableException class.
/// </summary>
///
/// <param name="msg">
/// The <see cref="string"/> message to be associated with this exception.
/// </param>
///
/// <param name="innerEx">
/// The <see cref="System.Exception"/> responsible for this exception inception.
/// </param>
///
public NotApplicableException(string msg, System.Exception innerEx)
: base(msg, innerEx)
{
}
}
} // *** end ReviewableAttribute ***
} // *** end Channel ***
} // *** end Module ***
} // *** end Event ***
}

View File

@@ -0,0 +1,515 @@
/*
* DTS.Slice.Control.Event.Module.Channel.SaeJ211Filter.cs
*
* Copyright © 2009
* Diversified Technical Systems, Inc.
* All Rights Reserved
*/
using System;
using DTS.Common.DAS.Concepts.DAS.Channel;
using DTS.Common.Utilities;
using DTS.Common.Utilities.DotNetProgrammingConstructs;
using DTS.Common.Utilities.Logging;
using DTS.Common.Utilities.SaeJ211;
namespace DTS.Slice.Control
{
public partial class Event
{ // *** see DTS.Slice.Control.Event.cs ***
public partial class Module
{ // *** see DTS.Slice.Control.Event.Module.cs ***
public partial class Channel
{ // *** see DTS.Slice.Control.Event.Module.Channel.cs ***
/// <summary>
/// Base class for all SaeJ211-based event module channel filters. It is intended
/// that fixed-filter-setting filters be derived from this class that will set their
/// filter setting using the protected constructor.
/// </summary>
public class SaeJ211Filter
: Filter
{
public SaeJ211Filter(SaeJ211Filter originalFilter)
{
OriginalType = originalFilter.OriginalType;
_CutoffFrequencyHz.Value = originalFilter.CutoffFrequencyHz;
}
/// <summary>
/// Initialize an instance of the DTS.Utility.SaeJ211Filter class.
/// </summary>
///
/// <param name="originalType">
/// The <see cref="ChannelFilter"/> to be applied by this filter (ad hoc
/// filters that correspond to CFC values will be converted to the CFC, hence the
/// "original" qualification).
/// </param>
///
public SaeJ211Filter(ChannelFilter originalType)
{
try
{
switch (OriginalType = originalType)
{ //
// Try to set the frequency value according to type. Note that we can't set to
// "ad hoc" using this particular constructor as we don't know what frequency
// should be associated with it.
//
case ChannelFilter.AdHoc:
throw new Exception("cannot initialize SaeJ211 filter using only ChannelFilter of type " + OriginalType.ToString());
default:
_CutoffFrequencyHz.Value = (double)originalType;
break;
}
}
catch (System.Exception ex)
{
throw new Exception("encountered problem constructing " + GetType().FullName, ex);
}
}
/// <summary>
/// Initialize an instance of the DTS.Utility.SaeJ211Filter class.
/// </summary>
///
///<param name="adHocFrequency">
///The <see cref="double"/> ad hoc frequency of this filter.
/// </param>
///
public SaeJ211Filter(double cutoffFrequencyHz)
{
try
{
OriginalType = ChannelFilter.AdHoc;
_CutoffFrequencyHz.Value = cutoffFrequencyHz;
}
catch (System.Exception ex)
{
throw new Exception("encountered problem constructing " + GetType().FullName, ex);
}
}
/// <summary>
/// Get <see cref="Boolean"/> value indicating whether or not this filter matches one of the
/// specified CFC values.
/// </summary>
override public bool IsCfc
{
get
{
try
{ //
// If we're not unfiltered and we're not ad hoc, then we
// must be CFC-compliant.
//
return Type != ChannelFilter.Unfiltered
&& Type != ChannelFilter.AdHoc;
}
catch (System.Exception ex)
{
throw new Exception("encountered problem determining whether or not filter corresponds to a CFC value", ex);
}
}
}
/// <summary>
/// Convert the specified frequency into a ChannelFilter type.
/// </summary>
///
/// <param name="frequency">
/// The <see cref="double"/> frequency to be converted.
/// </param>
///
/// <returns>
/// The best matching <see cref="ChannelFilter"/> type. A CFC match is preferred;
/// if one does not exist, "ad hoc" will be selected (if frequency > 0).
/// </returns>
///
private ChannelFilter ConvertFrequencyToChannelFilter(double frequency)
{
try
{
var matchingFilterType = ChannelFilter.Unfiltered;
if (frequency > 0)
{
matchingFilterType = ChannelFilter.AdHoc;
var cfcCoder = new CfcValueAttributeCoder();
foreach (int filterValue in Enum.GetValues(typeof(ChannelFilter)))
if (frequency == filterValue)
matchingFilterType = (ChannelFilter)filterValue;
}
return matchingFilterType;
}
catch (System.Exception ex)
{
throw new Exception("encountered problem trying to match frequency to CRC value", ex);
}
}
/// <summary>
/// Get the "best fitting" <see cref="ChannelFilter"/> value for this filter.
/// </summary>
override public ChannelFilter Type
{
get
{
try
{
var actualType = OriginalType;
switch (OriginalType)
{
case ChannelFilter.AdHoc:
actualType = ConvertFrequencyToChannelFilter(CutoffFrequencyHz);
break;
default:
//
// Don't waste time on stuff we don't need to convert.
//
actualType = OriginalType;
break;
}
return actualType;
}
catch (System.Exception ex)
{
throw new Exception("encountered problem determining filter type", ex);
}
}
}
public char IsoDescription => new IsoDescriptionAttributeCoder().DecodeAttributeValue(OriginalType)[0];
/// <summary>
/// Get the <see cref="double"/> cutoff frequency value.
/// </summary>
override public double CutoffFrequencyHz => _CutoffFrequencyHz.Value;
private readonly Property<double> _CutoffFrequencyHz
= new Property<double>(
typeof(SaeJ211Filter).Namespace + ".SaeJ211Filter.CutoffFrequencyHz",
-1,
true
);
/// <summary>
/// The <see cref="ChannelFilter"/>ing done by this object.
/// </summary>
public ChannelFilter OriginalType
{
get => _OriginalType.Value;
private set => _OriginalType.Value = value;
}
private readonly Property<ChannelFilter> _OriginalType
= new Property<ChannelFilter>(
typeof(SaeJ211Filter).Namespace + ".SaeJ211Filter.OriginalType",
ChannelFilter.Unfiltered,
false
);
private const string CutoffFrequencyUnitString = "Hz";
/// <summary>
/// The <see cref="string"/> name of this filter.
/// </summary>
public override string Name
{
get
{
try
{
if (null == _Name)
{
var cult = new System.Globalization.CultureInfo("");
_Name = ChannelFilter.AdHoc == Type
? CutoffFrequencyHz.ToString(cult) + CutoffFrequencyUnitString
: new DescriptionAttributeCoder<ChannelFilter>().DecodeAttributeValue(Type);
}
return _Name;
}
catch (System.Exception ex)
{
throw new Exception("encountered problem generating name string for " + GetType().FullName, ex);
}
}
}
private string _Name = null;
/// <summary>
/// Apply this filter to the specified channel.
/// </summary>
///
/// <param name="channel">
/// The <see cref="DTS.Slice.Control.Event.Module.Channel"/> to be filtered.
/// </param>
///
/// <returns>
/// The array of filtered <see cref="double"/> EU data.
/// </returns>
///
public override double[] Apply
(
Channel channel,
DataDisplayUnits displayUnits,
bool bUseLegacyTDCSoftwareFilterAdjustment
)
{
try
{
var filterUtility = new FilterUtility();
filterUtility.Cfc = Type;
filterUtility.AdHocFrequency = CutoffFrequencyHz;
filterUtility.SampleRate = channel.ParentModule.SampleRateHz;
double[] data;
switch (displayUnits)
{
case DataDisplayUnits.Adc:
if (channel.UnfilteredData is Serialization.SliceRaw.File.PersistentChannel)
{
if (channel.UnfilteredData is ILargeDataAware)
if (!(channel.UnfilteredData as ILargeDataAware).IsDataArraySized)
throw new Serialization.SliceRaw.File.PersistentChannel.DataTooBigForArrayException("Data is too big to be viewed or filtered.");
using (var persistentUnfilteredData =
channel.UnfilteredData as Serialization.SliceRaw.File.PersistentChannel)// ;
{
var dataCount = persistentUnfilteredData.Count;
data = new double[dataCount];
for (var i = 0; i < dataCount; i++)
data[i] = persistentUnfilteredData[(ulong) i];
}
//persistentUnfilteredData.Dispose();
}
else if (channel.UnfilteredData is Serialization.TDAS.File.PersistentChannel)
{
if (channel.UnfilteredData is ILargeDataAware)
if (!(channel.UnfilteredData as ILargeDataAware).IsDataArraySized)
throw new Serialization.TDAS.File.PersistentChannel.DataTooBigForArrayException("Data is too big to be viewed or filtered.");
using (var persistentUnfilteredData =
channel.UnfilteredData as Serialization.TDAS.File.PersistentChannel)// ;
{
var dataCount = persistentUnfilteredData.Count;
data = new double[dataCount];
for (var i = 0; i < dataCount; i++)
data[i] = persistentUnfilteredData[(ulong)i];
}
//persistentUnfilteredData.Dispose();
}
else data = channel.UnfilteredData.ConvertAll<double>(delegate(short datum) { return (double)datum; }).ToArray();
break;
case DataDisplayUnits.Eu:
data = channel.UnfilteredDataEu.ToArray();
break;
case DataDisplayUnits.Mv:
data = channel.UnfilteredDataMv.ToArray();
break;
default:
throw new NotImplementedException("handling for display unit type \"" + displayUnits.ToString() + "\" has not been implemented");
}
return filterUtility.ApplyFilter(data, new FilterUtility.InvalidDataDelegate(delegate()
{
var msg = string.Format("Invalid data in channel: {0}.", channel.ChannelDescriptionString);
//var dr = System.Windows.Forms.MessageBox.Show(msg, "Warning", System.Windows.Forms.MessageBoxButtons.OK);
APILogger.Log(msg);
throw new Exception(msg);
}), bUseLegacyTDCSoftwareFilterAdjustment);
}
catch ( System.Exception ex )
{
throw new Exception( "encountered problem applying filter \"" + Name + "\" to channel", ex );
}
}
/// <summary>
/// Apply this filter to the specified channel.
/// </summary>
///
/// <param name="channel">
/// The <see cref="DTS.Slice.Control.Event.Module.Channel"/> to be filtered.
/// </param>
/// <param name="bUseLegacyTDCSoftwareFilterAdjustment">
/// controls whether filtered data is adjusted by one sample to match TDC behavior
/// 8747
/// </param>
/// <returns>
/// The array of filtered <see cref="double"/> EU data.
/// </returns>
public override double[] Apply
(
double [] data,
double sampleRate,
bool bUseLegacyTDCSoftwareFilterAdjustment
)
{
try
{
var filterUtility = new FilterUtility();
filterUtility.Cfc = Type;
filterUtility.AdHocFrequency = CutoffFrequencyHz;
filterUtility.SampleRate = sampleRate;
return filterUtility.ApplyFilter(data, new FilterUtility.InvalidDataDelegate(delegate()
{
var msg = string.Format("Invalid data in channel.");
//var dr = System.Windows.Forms.MessageBox.Show(msg, "Warning", System.Windows.Forms.MessageBoxButtons.OK);
APILogger.Log(msg);
throw new Exception(msg);
}), bUseLegacyTDCSoftwareFilterAdjustment);
}
catch (System.Exception ex)
{
throw new Exception("encountered problem applying filter \"" + Name + "\" to channel", ex);
}
}
/// <summary>
/// Generate a string representation of this object.
/// </summary>
///
/// <returns>
/// A <see cref="string"/> representation of this object.
/// </returns>
///
public override string ToString( )
{
try
{
return Name;
}
catch ( System.Exception ex )
{
throw new Exception( "encountered problem generating the string value for " + GetType( ).FullName, ex );
}
}
/// <summary>
/// Generate a string representation of this object.
/// </summary>
///
/// <returns>
/// A <see cref="string"/> representation of this object.
/// </returns>
///
public override string ToBaseString()
{
try
{
return Name;
}
catch (System.Exception ex)
{
throw new Exception("encountered problem generating the string value for " + GetType().FullName, ex);
}
}
/// <summary>
/// Determines whether this filter and the specified filter are the same.
/// </summary>
///
/// <param name="obj">
/// The filter <see cref="object"/> to be compared with this one.
/// </param>
///
/// <returns>
/// <see cref="bool"/> true if the filters are the same, false otherwise.
/// </returns>
///
public override bool Equals( object obj )
{
try
{
if (null == obj as SaeJ211Filter) { return false; }
return Name.Equals( ( obj as SaeJ211Filter ).Name, StringComparison.OrdinalIgnoreCase );
}
catch ( System.Exception ex )
{
throw new Exception(
"encountered problem equality checking filter \""
+ Name
+ "\" with filter "
+ ( null != obj && obj is SaeJ211Filter && null != ( obj as SaeJ211Filter ).Name ? "\"" + ( obj as SaeJ211Filter ).Name + "\"" : "<null>" ), ex );
}
}
/// <summary>
/// provides an index for a given <see cref="DTS.Slice.Control.Event.Module.Channel.SaeJ211Filter"/>
/// since we override Equals we should override get hashcode to ensure that any to objects considered
/// "Equal" are also hashed to the same location, however the result index does not need to be unique
/// between non equal objects.
/// 6/10/2010 - dtm
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
return Name.ToLower().GetHashCode();
}
/// <summary>
/// Create a filter from the specified string.
/// </summary>
///
/// <param name="serialization">
/// The <see cref="string"/> representation of the filter to be instantiated.
/// </param>
///
/// <returns>
/// A <see cref="DTS.Slice.Control.Event.Module.Channel.Filter"/> equivalent of the
/// specified string. Throws an exception if object could not be created.
/// </returns>
///
static public Filter Parse( string serialization )
{
try
{
Filter filter = null;
if ( !string.IsNullOrEmpty( serialization ) )
{
if ( serialization.Contains( CutoffFrequencyUnitString ) )
{
var cult = new System.Globalization.CultureInfo("");
filter = new DefaultSaeJ211Filter(double.Parse(serialization.Replace(CutoffFrequencyUnitString, ""), cult));
}
else
{
foreach ( ChannelFilter filterType in Enum.GetValues( typeof( ChannelFilter ) ) )
{
var coder = new DescriptionAttributeCoder<ChannelFilter>( );
if ( coder.DecodeAttributeValue( filterType ).Equals( serialization, StringComparison.OrdinalIgnoreCase ) )
filter = new DefaultSaeJ211Filter( filterType );
}
}
}
return ( null != filter ? filter : new SaeJ211Filter( ChannelFilter.Unfiltered ) );
}
catch ( System.Exception ex )
{
throw new Exception( "encountered problem parsing string " + ( null != serialization ? "\"" + serialization + "\"" : "<NULL>" ) + " into filter", ex );
}
}
}
}
}
}
}