init
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,140 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using DTS.Common.Interface.Groups;
|
||||
|
||||
namespace DTS.Common.ISO
|
||||
{
|
||||
/// <inheritdoc cref="TestObjectTemplateChannel" />
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
public class TestObjectChannel : TestObjectTemplateChannel, IComparable<TestObjectChannel>, IGroupChannel
|
||||
{
|
||||
#region properties
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// controls whether channel should be used when collecting data or not
|
||||
/// Disabled channels are not used in run test
|
||||
/// </summary>
|
||||
public bool Disabled { get; set; }
|
||||
public int ChannelIdx { get; set; } = CHANNEL_IDX_UNKNOWN;
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// the serial number of the sensor associated with this channel (if any)
|
||||
/// </summary>
|
||||
public string SensorSerialNumber
|
||||
{
|
||||
get => GetProperty("SensorSerialNumber", "") as string;
|
||||
set => SetProperty("SensorSerialNumber", value);
|
||||
}
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// the physical hardware channel associated with this channel (if any)
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
/// <summary>
|
||||
/// the test object this channel belongs to
|
||||
/// </summary>
|
||||
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
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// 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)
|
||||
/// </summary>
|
||||
/// <param name="right"></param>
|
||||
/// <returns></returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user