using DTS.Common.Classes.DSP; using DTS.Common.Enums; using DTS.Common.Interface.Channels; using DTS.Common.Interface.DASFactory; using DTS.Common.Interface.Sensors; using DTS.Common.Interface.StatusAndProgressBar; using DTS.Common.Interface.TestSetups.TestSetupsList; using System.Collections.Generic; using System.Text; namespace DTS.DASLib.Service.StateMachine { public class ConfigureStatusParameters : IStatusParameters { #region ResolveChannels public bool RequireIdFoundForSensorsWithIds { get; set; } = true; public bool AllowMissingSensors { get; set; } = false; public bool AllowSensorsOutOfPosition { get; set; } = true; public ITestSetup TestSetupConfiguration { get; set; } public delegate ISensorData GetSensorDelegate(IGroupChannel groupChannel); public delegate ISensorCalibration GetSensorCalibrationDelegate(ISensorData sensor, ExcitationVoltageOptions.ExcitationVoltageOption excitation); /// /// delegate allowing us to retrieve the latest sensor calibration given a sensor and an excitation /// public GetSensorCalibrationDelegate GetCalibrationAction { get; set; } /// /// retrieves a sensor given a group channel /// this is handled in DataPRO by DataModel.TestTemplate /// but since that exists in UI land, we'll just define a delegate /// and allow it to be provided by the consumer by whatever mechanism it chooses /// for run test this should be testtemplate, but for testing it could equally /// just come from the db or directly provided /// public GetSensorDelegate GetSensorAction { get; set; } public bool AllowSensorIdToBlankChannel { get; set; } public delegate int GetDatabaseIdDelegate(IDASCommunication das); public GetDatabaseIdDelegate GetDatabaseIdAction { get; set; } public delegate void SetSensorCalibrationDelegate(ISensorData sd, ISensorCalibration sc); public SetSensorCalibrationDelegate SetSensorCalibrationAction { get; set; } #endregion #region Configure /// /// Excitation should be turned off, this flag is reverted as soon as the process to turn off excitation starts /// public bool TurnOffExcitation { get; set; } = false; /// /// defines an array of units which configuration should be applied to /// public IDASCommunication[] UnitsToConfigure { get; set; } = new IDASCommunication[0]; /// /// whether strict check should be used when applying configuration /// public bool DoStrictCheck { get; set; } = true; /// /// whether configuration should be written to even or diagnostic file stores /// (this is a legacy feature of sliceware, not all units support it, but SLICE units have multiple file stores /// so configuration could be written to different ones (diagnostic/event) /// public bool EventConfig { get; set; } = true; /// /// whether we are configuring units for data collection or just dummy collection (not collecting data) /// public bool DummyConfig { get; set; } = false; /// /// the MAX AAF for SLICE and TDAS /// public double[] MaxAAF { get; set; } = new double[0]; /// /// whether digital outputs should be applied or not when applying configuration /// this allows digital outputs to not be configured for say trigger check /// public bool ConfigureDigitalOutputs { get; set; } = true; /// /// the current configure process can occasionally require user input /// [probably to acknowledge AAF errors?] this allows a method of interacting /// during this process /// public ErrorCallback ErrorRequiringActionAction { get; set; } /// /// whether AAF should be turned off for realtime or not /// AAF takes up a lot of time for slice realtime, so it's usually desirable to turn off /// public bool TurnOffAAFRealtime { get; set; } = true; /// /// whether to reset the hardware event lines before setting the config /// public bool ResetHardwareEventLines { get; set; } = false; /// /// whether to prepare for diagnostics (turn on excitation, switches) /// public bool PrepareForDiagnostics { get; set; } = false; /// /// lookup serial number to data collection rate /// public IReadOnlyDictionary SampleRateLookup { get; set; } = new Dictionary(); /// /// lookup serial number to Anti Alias Filter rate /// public IReadOnlyDictionary AAFRateLookup { get; set; } = new Dictionary(); /// /// whether turning on power should be skipped or not /// this can allow excitation to remain off which is sometimes used to keep the units in low power state /// until the user explicitly turns on power /// public bool SkipTurnOnPower { get; set; } = false; /// /// whether to apply configuration or not /// public bool SetConfiguration { get; set; } = true; public DSPFilterType DSPFilterType { get; set; } /// /// whether to discard diagnostics when setting configuration /// public bool DiscardDiagnostics { get; set; } = true; #endregion public ConfigureStatusParameters() { ResetDSPFilterType(); } private void ResetDSPFilterType() { var dsp = DSPFilterCollection.GetDSPFilterCollection(); DSPFilterType = dsp.GetFilter(string.Empty); } /// /// resets all parameters back to defaults /// public void Reset() { RequireIdFoundForSensorsWithIds = true; AllowMissingSensors = false; AllowSensorsOutOfPosition = true; DoStrictCheck = true; EventConfig = true; DummyConfig = false; MaxAAF = new double[0]; ConfigureDigitalOutputs = true; ErrorRequiringActionAction = null; TestSetupConfiguration = null; GetSensorAction = null; AllowSensorIdToBlankChannel = false; ResetHardwareEventLines = false; PrepareForDiagnostics = false; UnitsToConfigure = new IDASCommunication[0]; SampleRateLookup = new Dictionary(); AAFRateLookup = new Dictionary(); SkipTurnOnPower = false; SetConfiguration = true; TurnOffExcitation = false; DiscardDiagnostics = true; ResetDSPFilterType(); } public override string ToString() { var sb = new StringBuilder(); sb.AppendLine($"RequireIdFoundForSensorsWithIds={RequireIdFoundForSensorsWithIds.ToString()}"); sb.AppendLine($"AllowMissingSensors={AllowMissingSensors.ToString()}"); sb.AppendLine($"AllowSensorsOutOfPosition={AllowSensorsOutOfPosition.ToString()}"); sb.AppendLine($"DoStrictCheck={DoStrictCheck.ToString()}"); sb.AppendLine($"EventConfig={EventConfig.ToString()}"); sb.AppendLine($"DummyConfig={DummyConfig.ToString()}"); sb.Append("MaxAAF="); for (int i = 0; i < MaxAAF.Length; i++) { if (i > 0) { sb.Append(", "); } sb.Append(MaxAAF[i].ToString()); } sb.AppendLine(); sb.AppendLine($"ConfigureDigitalOutputs={ConfigureDigitalOutputs.ToString()}"); sb.AppendLine($"AllowSensorIdToBlankChannel={AllowSensorIdToBlankChannel.ToString()}"); sb.AppendLine($"ResetHardwareEventLines={ResetHardwareEventLines.ToString()}"); sb.AppendLine($"PrepareForDiagnostics={PrepareForDiagnostics.ToString()}"); sb.Append("UnitsToConfigure="); for (var i = 0; i < UnitsToConfigure.Length; i++) { if (i > 0) { sb.Append(", "); } sb.Append(UnitsToConfigure[i].SerialNumber); } sb.AppendLine(); sb.Append("SampleRateLookup="); var first = true; using (var enumSampleRate = SampleRateLookup.GetEnumerator()) { while (enumSampleRate.MoveNext()) { if (!first) { sb.Append(", "); } sb.Append($"{enumSampleRate.Current.Key}={enumSampleRate.Current.Value.ToString()}"); first = false; } } sb.AppendLine(); sb.Append("AAFLookup="); first = true; using (var enumAAF = AAFRateLookup.GetEnumerator()) { while (enumAAF.MoveNext()) { if (!first) { sb.Append(", "); } sb.Append($"{enumAAF.Current.Key}={enumAAF.Current.Value.ToString()}"); first = false; } } sb.AppendLine(); sb.AppendLine($"SkipTurnOnPower={SkipTurnOnPower.ToString()}"); sb.Append("ErrorRequiringActionAction="); sb.AppendLine(null == ErrorRequiringActionAction ? "[null]" : "[defined]"); sb.AppendLine($"SetConfiguration={SetConfiguration.ToString()}"); sb.AppendLine($"TurnOffExcitation={TurnOffExcitation.ToString()}"); sb.AppendLine($"DiscardDiagnostics={DiscardDiagnostics.ToString()}"); return sb.ToString(); } } }