using System; using System.Linq; using System.Text; using DTS.Common.Interface.Groups; namespace DTS.Common.ISO { /// /// /// this class represents a more simpilized version of the group/test object channel /// this is closer tied to what's in the database /// It extends a template channel adds more meta data /// public class TestObjectChannel : TestObjectTemplateChannel, IComparable, IGroupChannel { #region properties /// /// /// controls whether channel should be used when collecting data or not /// Disabled channels are not used in run test /// public bool Disabled { get; set; } public int ChannelIdx { get; set; } = CHANNEL_IDX_UNKNOWN; /// /// /// the serial number of the sensor associated with this channel (if any) /// public string SensorSerialNumber { get => GetProperty("SensorSerialNumber", "") as string; set => SetProperty("SensorSerialNumber", value); } /// /// /// the physical hardware channel associated with this channel (if any) /// public string HardwareId { get => GetProperty("HardwareId", "") as string; set { var tokens = value?.Split('_'); if (3 == tokens?.Length) { var sb = new StringBuilder(); sb.AppendFormat("{0}_{1}", tokens[0], tokens[1]); var index = tokens[2].IndexOf(CHANNEL_SEPARATOR); if (index >= 0) { sb.Append(tokens[2].Substring(index)); } value = sb.ToString(); } SetProperty("HardwareId", value); } } public SquibChannelTypes SquibChannelType { get; set; } /// /// the test object this channel belongs to /// public TestObject TestObject { get; } #endregion #region constants and enums private const char CHANNEL_SEPARATOR = 'x'; public const int CHANNEL_IDX_UNKNOWN = -1; public enum SquibChannelTypes { None, //Non-squib channels Voltage, Current } #endregion #region methods /// /// /// compares one channel to another, used for sorting /// order is determined by 1) display order, 2) name of the channels, 3) test object serial number (or original serial number) /// /// /// public int CompareTo(TestObjectChannel right) { if (null == right) { return 1; } if (this == right) { return 0; } var comp = DisplayOrder.CompareTo(right.DisplayOrder); if (0 != comp) { return comp; } comp = string.Compare(Name, right.Name, StringComparison.Ordinal); if (0 != comp) { return comp; } if (null == TestObject || null == right.TestObject) return 0; comp = string.Compare(TestObject.SerialNumberOrOriginalSerialNumber, right.TestObject.SerialNumberOrOriginalSerialNumber, StringComparison.Ordinal); return 0 != comp ? comp : 0; } public string GetGraphId() { return SquibChannelType == SquibChannelTypes.Current ? GetId() + Constants.CURRENT_SUFFIX : GetId(); } public string GetId() { return GetIdWithSpecificChannelId(Channel.Id); } public string GetIdWithSpecificChannelId(long id) { return $"{TestObject.SerialNumber}_{Channel.MMEChannelType}_{id}"; } public string GetDASId() { var result = string.Empty; if (HardwareId.Contains('_')) { result = HardwareId.Substring(0, HardwareId.IndexOf('_')); } return result; } #endregion #region constructors and initializers public TestObjectChannel(TestObjectTemplateChannel copy, TestObject testObject, TestObjectTemplate template) : base(copy, template) { TestObject = testObject; if (copy is TestObjectChannel channel) { Disabled = channel.Disabled; } } #endregion public int CompareTo(IGroupChannel other) { return CompareTo((TestObjectChannel)other); } } }