Files
DP44/Common/DTS.Common.DataModel/.svn/pristine/fc/fc67d91bda87e9e96f631b44a4bc6f06611aa6ba.svn-base
2026-04-17 14:55:32 -04:00

3830 lines
181 KiB
Plaintext

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Xml;
using DataPROWin7.Common;
using DataPROWin7.DataModel.Classes.Hardware;
using DTS.Common;
using DTS.Common.Classes.Hardware;
using DTS.Common.Enums;
using DTS.Common.Enums.DASFactory;
using DTS.Common.Enums.Hardware;
using DTS.Common.Enums.Sensors;
using DTS.Common.Interface.DASFactory;
using DTS.Common.Interface.DataRecorders;
using DTS.Common.ISO;
using DTS.Common.Storage;
using DTS.Common.Utilities.Logging;
using DTS.Common.Utils;
using DTS.DASLib.Service;
using DTS.Common.DataModel;
using DTS.Common.SharedResource.Strings;
using System.Threading;
using DTS.Common.SerializationPlus;
using DTS.Common.Interface.Sensors.AnalogDiagnostics;
using DTS.Common.Interface.DASFactory.Config;
using DTS.Common.DataModel.Common;
namespace DataPROWin7.DataModel
{
public class DASHardware : DTS.Common.Base.BasePropertyChanged, IComparable<DASHardware>, IDASHardware
{
public bool IsAlignUDPToPPSSupported()
{
var hwType = GetHardwareTypeEnum();
if (!_dasThatMightSupportAlignUDP.Contains(hwType)) { return false; }
switch(hwType)
{
case HardwareTypes.SLICE6_AIR: return IsAlignUDPToPPSSupportedS6A();
case HardwareTypes.SLICE6_AIR_BR: return IsAlignUDPToPPSSupportedS6ABR();
}
return false;
}
private bool IsAlignUDPToPPSSupportedS6ABR()
{
return ProtocolVersion >= DTS.Common.Constant.DASSpecific.SLICE6AIRBR.UDPALIGNONPPS_PROTOCOL;
}
private bool IsAlignUDPToPPSSupportedS6A()
{
return ProtocolVersion >= DTS.Common.Constant.DASSpecific.SLICE6AIR.UDPALIGNONPPS_PROTOCOL;
}
private static readonly HashSet<HardwareTypes> _dasThatMightSupportAlignUDP = new HashSet<HardwareTypes>
{
HardwareTypes.SLICE6_AIR
};
private static readonly HashSet<HardwareTypes> _dasWithT0Recovery = new HashSet<HardwareTypes>
{
HardwareTypes.SLICE_Base,
HardwareTypes.SLICE2_Base,
HardwareTypes.SLICE1_5_Nano_Base,
HardwareTypes.SLICE_Micro_Base,
HardwareTypes.SLICE_NANO_Base,
HardwareTypes.SLICE2_SIM,
HardwareTypes.SLICE2_DIM,
HardwareTypes.SLICE2_TOM,
HardwareTypes.SLICE1_5_Micro_Base,
HardwareTypes.SLICE2_SLS,
HardwareTypes.SLICE1_G5Stack,
HardwareTypes.SLICE2_SLT,
HardwareTypes.SLICE2_SLD,
HardwareTypes.SLICE6_Base,
HardwareTypes.SLICE6_AIR,
HardwareTypes.SLICE6_AIR_BR
};
public static bool SupportsT0Recovery(HardwareTypes hType)
{
return _dasWithT0Recovery.Contains(hType);
}
public static bool SupportsT0Recovery(IDASCommunication idas)
{
return SupportsT0Recovery(idas.GetHardwareType());
}
public static List<EventInfoAggregate> GetAllEvents(List<IDASCommunication> dasList)
{
var madeUpEventInfo = new List<DownloadReport.EventInfo>();
var eventIds = new List<string>();
var events = new Dictionary<string, EventInfoAggregate>();
foreach (var dasEvents in dasList.Where(x => null != x.EventInfo).Select(y => y.EventInfo.Events).Where(z => z.Any()))
{
foreach (var ei in dasEvents)
{
var eventInfo = (DownloadReport.EventInfo)ei;
if (ei.TestID.Equals(DFConstantsAndEnums.MADEUPEVENT_TESTID))
{
madeUpEventInfo.Add(eventInfo);
}
else
{
var key = GetHash(eventInfo);
if (!eventIds.Contains(key))
{
eventIds.Add(key);
events.Add(key, new EventInfoAggregate(eventInfo));
}
else
{
events[key].Add(eventInfo);
}
}
}
}
if (madeUpEventInfo.Any())
{
foreach (var madeUpEvent in madeUpEventInfo)
{
foreach (var eventInfo in events)
{
var copy = new DownloadReport.EventInfo(madeUpEvent);
copy.TestID = eventInfo.Value.EventId;
eventInfo.Value.Add(madeUpEvent);
}
}
}
var eventInfosAggregate = new List<EventInfoAggregate>();
if (events.Count > 0)
{
foreach (var ei in events.Values)
{
eventInfosAggregate.Add(ei);
}
}
return eventInfosAggregate;
}
public static IEnumerable<DASHardware> GetChildrenDAS(string dasSerial, IDictionary<string, DASHardware> hardwareLookup = null)
{
var hardware = new List<DASHardware>();
using (var sql = DbOperations.GetSQLCommand(true))
{
try
{
var hResult = DbOperations.DASChildrenGet(dasSerial, out var serials);
if (0 != hResult) { return hardware.ToArray(); }
foreach (var serial in serials)
{
DASHardware thisDas = null;
if (null != hardwareLookup && hardwareLookup.ContainsKey(serial))
{
thisDas = hardwareLookup[serial];
}
if (null == thisDas)
{
thisDas = DASHardwareList.GetList().GetHardware(serial);
}
if (null == thisDas) continue;
if (!hardware.Contains(thisDas))
{
hardware.Add(thisDas);
}
}
}
finally
{
sql.Connection.Dispose();
}
}
return hardware.ToArray();
}
/// <summary>
/// returns true if the das should have channels that can be assigned to or not
/// </summary>
public bool ShouldHaveChannels()
{
if (IsSLICEEthernetController) { return false; }
//if (DASTypeEnum == HardwareTypes.S6A_EthernetRecorder) { return false; }
return true;
}
public bool IsNonDistributorHardware
{
get
{
switch (DASTypeEnum)
{
case HardwareTypes.SLICE_Distributor:
case HardwareTypes.SLICE_EthernetController:
case HardwareTypes.SLICE_LabEthernet:
case HardwareTypes.SLICE6DB:
case HardwareTypes.SLICE6DB3:
case HardwareTypes.SLICE_Pro_Distributor:
case HardwareTypes.SLICE6DB_InDummy:
case HardwareTypes.SLICE_Mini_Distributor:
return false;
}
return true;
}
}
public const string SLICE6DB3ImagePath = "Assets/Hardware/SLICE6Db3.png";
/// <summary>
/// reconfigures das using the source as a guide
/// </summary>
public void ReconfigureAsNeeded(DASHardware source)
{
//only SLICE2 sim and TDAS racks need reconfiguring
switch (DASTypeEnum)
{
case HardwareTypes.SLICE2_SIM:
case HardwareTypes.SLICE2_SLS:
ReconfigureSLICEAsNeeded(source);
break;
case HardwareTypes.TDAS_LabRack:
case HardwareTypes.TDAS_Pro_Rack:
ReconfigureTDASAsNeeded(source);
break;
}
}
/// <summary>
/// reconfigure the das using the source
/// we could use one function for both slice and tdas, but I think this
/// allows easier changes in the future
/// </summary>
private void ReconfigureSLICEAsNeeded(DASHardware source)
{
//remove any unnecessary channels
var channelsDest = _hardware.ISOChannels.ToList();
var channelsSource = source._hardware.ISOChannels.ToList();
channelsDest.Clear();
for (var i = 0; i < channelsSource.Count; i++)
{
var ch = channelsSource[i];
channelsDest.Add(new DTS.Common.ISO.HardwareChannel(ch, _hardware));
}
_hardware.ISOChannels = channelsDest.ToArray();
_hardware.MaxSampleRate = source._hardware.MaxSampleRate;
Channels = _hardware.ISOChannels.Select(channel => new HardwareChannel(channel, this)).ToArray();
}
/// <summary>
/// reconfigure the das using the source
/// </summary>
private void ReconfigureTDASAsNeeded(DASHardware source)
{
var channelsDest = _hardware.ISOChannels.ToList();
var channelsSource = source._hardware.ISOChannels.ToList();
channelsDest.Clear();
for (var i = 0; i < channelsSource.Count; i++)
{
var ch = channelsSource[i];
//sanity check, this should have been already prevented at a higher level, but panic if it wasn't
Trace.Assert(ch.ModuleArrayIndex < MaxModules,
$"We are copying a larger rack to a smaller one, should have been prevented before this ... channel array index: {ch.ModuleArrayIndex} >= array length: {MaxModules}");
channelsDest.Add(new DTS.Common.ISO.HardwareChannel(ch, _hardware));
}
_hardware.ISOChannels = channelsDest.ToArray();
_hardware.MaxSampleRate = source._hardware.MaxSampleRate;
_hardware.MaxMemory = source._hardware.MaxMemory;
Channels = _hardware.ISOChannels.Select(channel => new HardwareChannel(channel, this)).ToArray();
}
/// <summary>
/// sets the first use date of the hardware in the db to today
/// [sets in db only ...]
/// 15524 DAS "First Use Date"
/// </summary>
/// <param name="hardware"></param>
public static void SetFirstUseDate(IDASHardware hardware)
{
using (var sql = DbOperations.GetSQLCommand(true))
{
try
{
sql.CommandType = CommandType.StoredProcedure;
sql.CommandText = "sp_DASFirstUseSet";
sql.Parameters.Add(new SqlParameter("@DASId", SqlDbType.Int) { Value = hardware.DASId });
sql.Parameters.Add(new SqlParameter("@FirstUseDate", SqlDbType.DateTime) { Value = DateTime.Today });
var errorNumber = new SqlParameter("@errorNumber", SqlDbType.Int)
{ Direction = ParameterDirection.Output };
sql.Parameters.Add(errorNumber);
var errorMessage = new SqlParameter("@errorMessage", SqlDbType.NVarChar, 255)
{ Direction = ParameterDirection.Output };
sql.Parameters.Add(errorMessage);
sql.ExecuteNonQuery();
if (!DBNull.Value.Equals(errorNumber.Value))
{
if (0 != Convert.ToInt32(errorNumber.Value))
{
throw new Exception(
$"Failed to set first use date for hardware in db, {hardware.SerialNumber}, {Convert.ToString(errorMessage.Value)}");
}
}
}
finally
{
sql.Connection.Dispose();
}
}
}
public int DASId => _hardware.DASId;
public int GetDatabaseID()
{
var dbId = 0;
var hResult = DbOperations.DASGet(SerialNumber, null, out var dbDAS);
if (0 == hResult && null != dbDAS && dbDAS.Any())
{
return dbDAS[0].DASId;
}
return dbId;
}
public void SetDASId(int id)
{
_hardware.DASId = id;
}
/// <summary>
/// returns whether this device has configurable external clock syncing options
/// </summary>
/// <returns></returns>
public bool IsConfigurableClockSync
{
get
{
switch (GetHardwareTypeEnum())
{
case HardwareTypes.SLICE6DB:
case HardwareTypes.SLICE6DB_InDummy:
case HardwareTypes.SLICE6_Base:
case HardwareTypes.SLICE6_AIR:
case HardwareTypes.SLICE6_AIR_BR:
case HardwareTypes.TSR_AIR:
case HardwareTypes.TSR_AIR_RevB:
return true;
case HardwareTypes.SLICE_Pro_Distributor:
case HardwareTypes.SLICE6DB3:
case HardwareTypes.DKR:
case HardwareTypes.DIR:
default:
return false;
}
}
}
public string ClockSyncStatus
{
get
{
var status = string.Empty;
var device = ApplicationProperties.DASFactory.GetActiveDevices().Find(idas => idas.SerialNumber == SerialNumber);
if (null == device) return status;
status = DTS.Common.Strings.Strings.ResourceManager.GetString(device.DASClockSyncProfile.GetEnumDescription()) + Environment.NewLine;
var synced = Utils.IsClockSynced(device.DASClockSyncStatus, device.DASClockSyncProfile, device.GetHardwareType());
status += null != synced && device.DiagnosticsHasBeenRun ? ((bool)synced ? StringResources.Diagnostics_Synced : StringResources.Diagnostics_NotSynced) : StringResources.ArmChecklist_NA;
return status;
}
}
public bool IsTOM()
{
switch (GetHardwareTypeEnum())
{
case HardwareTypes.SLICE_Base:
case HardwareTypes.SLICE_Bridge:
case HardwareTypes.SLICE_Distributor:
case HardwareTypes.SLICE2_IEPE_Hi:
case HardwareTypes.SLICE2_IEPE_Lo:
case HardwareTypes.SLICE2_Bridge_Hi:
case HardwareTypes.SLICE2_Bridge_Lo:
case HardwareTypes.SLICE2_Base:
case HardwareTypes.SIM:
case HardwareTypes.DIM:
case HardwareTypes.G5VDS:
case HardwareTypes.Ribeye:
case HardwareTypes.RibeyeLED:
case HardwareTypes.SLICE_IEPE:
case HardwareTypes.SLICE1_5_Nano_Base:
case HardwareTypes.SLICE_Micro_Base:
case HardwareTypes.SLICE_NANO_Base:
case HardwareTypes.SLICE2_SIM:
case HardwareTypes.SLICE2_DIM:
case HardwareTypes.G5INDUMMY:
case HardwareTypes.SLICE_EthernetController:
case HardwareTypes.SLICE_Mini_Distributor:
case HardwareTypes.SLICE1_5_Micro_Base:
case HardwareTypes.SLICE_LabEthernet:
case HardwareTypes.SLICE2_SLS:
case HardwareTypes.SLICE1_G5Stack:
case HardwareTypes.SLICE2_SLD:
case HardwareTypes.SLICE6_Base:
case HardwareTypes.SLICE6_AIR:
case HardwareTypes.SLICE6_AIR_BR:
case HardwareTypes.SLICE6DB:
case HardwareTypes.SLICE_Pro_Distributor:
case HardwareTypes.SLICE6DB_InDummy:
case HardwareTypes.SLICE6DB3:
case HardwareTypes.TSR_AIR:
case HardwareTypes.TSR_AIR_RevB:
case HardwareTypes.DKR:
case HardwareTypes.DIR:
return false;
case HardwareTypes.TDAS_Pro_Rack:
case HardwareTypes.TDAS_LabRack:
return Array.Exists(Channels, ch => ch.IsSupportedBridgeType(SensorConstants.BridgeType.SQUIB));
case HardwareTypes.TOM:
case HardwareTypes.SLICE2_TOM:
case HardwareTypes.SLICE2_SLT:
return true;
}
return false;
}
public bool IsBattery()
{
return GetHardwareTypeEnum() == HardwareTypes.PowerPro;
}
public bool IsTSRAIR()
{
return GetHardwareTypeEnum() == HardwareTypes.TSR_AIR ||
GetHardwareTypeEnum() == HardwareTypes.TSR_AIR_RevB ||
GetHardwareTypeEnum() == HardwareTypes.DKR ||
GetHardwareTypeEnum() == HardwareTypes.DIR;
}
public bool IsTSRAIRModule()
{
return GetHardwareTypeEnum() == HardwareTypes.EMB_ANG_ACC ||
GetHardwareTypeEnum() == HardwareTypes.EMB_ANG_ARS ||
GetHardwareTypeEnum() == HardwareTypes.EMB_ATM ||
GetHardwareTypeEnum() == HardwareTypes.EMB_LIN_ACC_HI ||
GetHardwareTypeEnum() == HardwareTypes.EMB_LIN_ACC_LO ||
GetHardwareTypeEnum() == HardwareTypes.EMB_MAG ||
GetHardwareTypeEnum() == HardwareTypes.EMB_MAG_SWITCH ||
GetHardwareTypeEnum() == HardwareTypes.EMB_MIC ||
GetHardwareTypeEnum() == HardwareTypes.EMB_OPT ||
GetHardwareTypeEnum() == HardwareTypes.EMB_RTC_S_MARK ||
GetHardwareTypeEnum() == HardwareTypes.EMB_RTC_NS_PAD;
}
public bool IsSLICETC()
{
return GetHardwareTypeEnum() == HardwareTypes.SLICE6_AIR_TC;
}
public bool CareAboutSampleRate
{
get
{
switch (DASTypeEnum)
{
case HardwareTypes.SLICE6DB:
case HardwareTypes.SLICE6DB3:
case HardwareTypes.SLICE_Pro_Distributor:
case HardwareTypes.SLICE6DB_InDummy:
case HardwareTypes.PowerPro:
case HardwareTypes.SLICE_EthernetController:
case HardwareTypes.SLICE_Mini_Distributor:
case HardwareTypes.SLICE_LabEthernet:
return false;
}
return true;
}
}
/// <summary>
/// returns whether in the UI this device should be represented as a rack even though it isn't (SLICE6Db, ECM, SLE)
/// </summary>
/// <returns></returns>
public bool IsPseudoRack()
{
switch (GetHardwareTypeEnum())
{
case HardwareTypes.SLICE_LabEthernet:
//FB 16148 is SLICE_Mini_Distributor Pseudo rack ?
case HardwareTypes.SLICE_Mini_Distributor:
case HardwareTypes.SLICE_EthernetController:
case HardwareTypes.SLICE_Pro_Distributor:
case HardwareTypes.SLICE6DB:
case HardwareTypes.SLICE6DB3:
case HardwareTypes.SLICE6DB_InDummy:
case HardwareTypes.TSR_AIR:
case HardwareTypes.TSR_AIR_RevB:
case HardwareTypes.DKR:
case HardwareTypes.DIR:
return true;
default: return false;
}
}
/// <summary>
/// returns true if the device in question could be connected to a PseudoRack
/// (SLICE6/SLICE2 family)
/// </summary>
/// <returns></returns>
public bool IsPseudoRackModule()
{
switch (GetHardwareTypeEnum())
{
case HardwareTypes.SLICE6_Base:
case HardwareTypes.SLICE6_AIR:
case HardwareTypes.SLICE6_AIR_BR:
case HardwareTypes.SLICE2_TOM:
case HardwareTypes.SLICE2_SLT:
case HardwareTypes.SLICE2_SLS:
case HardwareTypes.SLICE2_SLD:
case HardwareTypes.SLICE2_SIM:
case HardwareTypes.SLICE2_DIM:
case HardwareTypes.SLICE2_Base:
return true;
default: return false;
}
}
/// <inheritdoc />
/// <summary>
/// returns true if the hardware represents a rack of TDAS modules
/// </summary>
/// <returns></returns>
public bool IsTDASRack()
{
switch (GetHardwareTypeEnum())
{
case HardwareTypes.TDAS_LabRack:
case HardwareTypes.TDAS_Pro_Rack:
return true;
default:
return false;
}
}
public string ParentDAS
{
get => _hardware.ParentDAS;
set => _hardware.ParentDAS = value;
}
public int PortOnDistributor
{
get => _hardware.Port;
set => _hardware.Port = value;
}
public int PositionOnChain
{
get => _hardware.PositionOnChain;
set => _hardware.PositionOnChain = value;
}
public int PositionOnDistributor
{
get => _hardware.PositionOnDistributor;
set => _hardware.PositionOnDistributor = value;
}
public DateTime LastModified
{
get => _hardware.LastModified;
set => _hardware.LastModified = value;
}
public string LastModifiedBy
{
get => _hardware.LastModifiedBy;
set => _hardware.LastModifiedBy = value;
}
public string DASSerialNumber
{
get
{
if (!IsModule()) return SerialNumber;
if (!string.IsNullOrWhiteSpace(ParentDAS))
{
return $"{ParentDAS}-{PortOnDistributor}.{PositionOnChain}[{PositionOnDistributor}]";
}
return Connection.IndexOf("x", StringComparison.Ordinal) > 0
? Connection.Substring(0, Connection.IndexOf("x", StringComparison.Ordinal))
: StringResources.Table_NA;
}
}
/// <summary>
/// returns the id in the database for a hardware with the given serial number
/// returns 0 otherwise
/// </summary>
/// <param name="serialNumber"></param>
/// <returns></returns>
public static int GetDataBaseID(string serialNumber)
{
var dbId = 0;
var hResult = DbOperations.DASGet(serialNumber, null, out var dbDAS);
if (0 == hResult && null != dbDAS && dbDAS.Any())
{
return dbDAS[0].DASId;
}
return dbId;
}
public static double GetMaxAAFRateFromPrototype(string serialNumber)
{
var hResult = DbOperations.DASGet(serialNumber, DbOperations.DAS.PROTOTYPE_POSITION, out var dbDAS);
if (0 == hResult && null != dbDAS && dbDAS.Any())
{
return dbDAS[0].MaxAAFRate;
}
return 0;
}
/// <summary>
/// Gets the Maximum sample rate for a particular recording mode, first implemented because the maximum sample rate
/// can vary depending on the baud rate set for UART recording (39151)
/// </summary>
/// <param name="mode"></param>
/// <param name="baudRate"></param>
/// <returns></returns>
public double MaxSampleRateForRecordingMode(RecordingModes mode, uint baudRate = 0)
{
return HardwareConstants.MaxSampleRateForRecordingMode(this, mode, ProtocolVersion, baudRate);
}
public bool SupportsRecordingMode(RecordingModes mode, bool includeNativeSupportOnly = false)
{
return HardwareConstants.IsRecordingModeSupported(mode, DASTypeEnum, ProtocolVersion, includeNativeSupportOnly);
}
public bool SupportsStreamingProfile(UDPStreamProfile profile)
{
return HardwareConstants.IsStreamingProfileSupported(profile, DASTypeEnum, ProtocolVersion);
}
public bool SupportsClockSyncProfile(ClockSyncProfile profile, bool master)
{
return HardwareConstants.IsClockSyncProfileSupported(profile, DASTypeEnum, ProtocolVersion, false, master);
}
public bool SupportsDbVersion()
{
switch (DASTypeEnum)
{
case HardwareTypes.SLICE6_AIR_BR:
return DbOperations.GetConnectionDbVersion() >= Constants.SLICE6AIR_BR_DB_VERSION;
default:
return true;
}
}
public void UnassociateDAS()
{
if (!IsModule()) return;
Connection = "";
OnPropertyChanged("Connection");
OnPropertyChanged("DASSerialNumber");
}
public bool IsModule()
{
return GetHardware().IsModule;
}
public void SetIsModule(bool bModule)
{
GetHardware().IsModule = bModule;
}
public enum Tags
{
MeasuredBatteryVoltage,
MeasuredInputVoltage,
Channels,
ChannelCount,
Selected,
BackgroundColor,
SerialNumber,
DASTypeEnum,
Connection,
FirmwareVersion,
MaxModules,
ChannelTypes,
Reprogramable,
Reconfigurable,
LocalOnly,
CurrentClockSync,
CurrenClockProfile
}
public bool Equals(DASHardware other)
{
return 0 == CompareTo(other);
}
public int CompareTo(DASHardware right)
{
if (null == right) { return 1; }
if (this == right) { return 0; }
if (SerialNumber == right.SerialNumber)
{
return 0;
}
//ensure that children of a das are sorted behind their parents
if (!string.IsNullOrWhiteSpace(ParentDAS) && right.SerialNumber == ParentDAS)
{
return 1;
}
if (!string.IsNullOrWhiteSpace(right.ParentDAS) && right.ParentDAS == SerialNumber)
{
return -1;
}
if (!string.IsNullOrWhiteSpace(right.ParentDAS) && right.ParentDAS == ParentDAS)
{
if (PositionOnDistributor != right.PositionOnDistributor)
{
return PositionOnDistributor.CompareTo(right.PositionOnDistributor);
}
}
return string.Compare(SerialNumber, right.SerialNumber, StringComparison.Ordinal);
}
public bool IsEthernetDevice
{
get
{
switch (DASTypeEnum)
{
case HardwareTypes.G5VDS:
//case ISODll.Hardware.HardwareTypes.G5IPORT:
case HardwareTypes.G5INDUMMY:
case HardwareTypes.PowerPro:
case HardwareTypes.SLICE_Distributor:
case HardwareTypes.SLICE_Pro_Distributor:
case HardwareTypes.SLICE_EthernetController:
case HardwareTypes.SLICE_Mini_Distributor:
case HardwareTypes.SLICE6DB:
case HardwareTypes.SLICE6DB3:
case HardwareTypes.SLICE6DB_InDummy:
case HardwareTypes.SLICE_LabEthernet:
case HardwareTypes.TDAS_Pro_Rack:
case HardwareTypes.TDAS_LabRack:
case HardwareTypes.SLICE6_Base:
case HardwareTypes.SLICE6_AIR:
case HardwareTypes.SLICE6_AIR_BR:
case HardwareTypes.TSR_AIR:
case HardwareTypes.TSR_AIR_RevB:
return true;
default: return false;
}
}
}
private double _batteryVoltage = double.NaN;
public double MeasuredBatteryVoltage
{
get => _batteryVoltage;
set => SetProperty(ref _batteryVoltage, value, Tags.MeasuredBatteryVoltage.ToString());
}
private double _inputVoltage = double.NaN;
public double MeasuredInputVoltage
{
get => _inputVoltage;
set => SetProperty(ref _inputVoltage, value, Tags.MeasuredInputVoltage.ToString());
}
private List<HardwareChannel> _channels = new List<HardwareChannel>();
public HardwareChannel[] Channels
{
get => _channels.ToArray();
set
{
var channels = new List<HardwareChannel>(value);
channels.Sort();
SetProperty(ref _channels, channels, Tags.Channels.ToString());
OnPropertyChanged(Tags.ChannelCount.ToString());
}
}
public string Margin => "0,0,0,0";
private bool _bSelected = true;
public bool Selected
{
get => _bSelected;
set
{
SetProperty(ref _bSelected, value, Tags.Selected.ToString());
OnPropertyChanged(Tags.BackgroundColor.ToString());
}
}
public Color BackgroundColor => Selected ? Colors.Yellow : Colors.AliceBlue;
public bool IsG5()
{
return SerialNumber.StartsWith("5M");
}
public static bool IsG5(IDASCommunication idas)
{
return idas.SerialNumber.StartsWith("5M");
}
public static bool IsG5WithLostDock(IDASCommunication idas)
{
if (IsG5(idas))
{
try
{
var modelHardware = DASHardwareList.GetList().GetHardware(idas.SerialNumber);
return (modelHardware?.DASTypeEnum == HardwareTypes.G5VDS) &&
(new DASHardware(idas).DASTypeEnum == HardwareTypes.G5INDUMMY);
}
catch (Exception e)
{
APILogger.LogException(e);
}
}
return false;
}
public string SerialNumber
{
get => _hardware.SerialNumber;
set
{
_hardware.SerialNumber = value;
OnPropertyChanged(Tags.SerialNumber.ToString());
}
}
public HardwareTypes DASTypeEnum
{
get => _hardware.DASTypeEnum;
set
{
bool bReconfigure = _hardware.DASTypeEnum != value;
_hardware.DASTypeEnum = value;
if (bReconfigure) { Reconfigure(); }
OnPropertyChanged(Tags.DASTypeEnum.ToString());
}
}
public string HardwareType
{
get
{
var hardwareType = (HardwareTypes)_hardware.DASType;
return DASHardware.GetStringForType(hardwareType);
}
}
public int GetHardwareTypeInt() { return _hardware.DASType; }
public HardwareTypes GetHardwareTypeEnum() { return (HardwareTypes)GetHardwareTypeInt(); }
/// <summary>
/// returns an image given a type of hardware
/// </summary>
/// <param name="hw"></param>
/// <returns></returns>
public static string GetImage(HardwareTypes hw)
{
var image = "";
switch (hw)
{
case HardwareTypes.TOM: image = "Assets/Hardware/TDAS_TOM_Front.jpg"; break;
case HardwareTypes.SIM: image = "Assets/Hardware/TDAS_SIM_Front.jpg"; break;
case HardwareTypes.SLICE1_G5Stack: image = "Assets/Hardware/SLICE_G5_Angle.jpg"; break;
case HardwareTypes.G5INDUMMY: image = "Assets/Hardware/TDAS_G5_Angle.jpg"; break;
case HardwareTypes.G5VDS: image = "Assets/Hardware/G5 Docking Station - retouched.jpg"; break;
case HardwareTypes.DIM: image = "Assets/Hardware/TDAS_DIM_Front.jpg"; break;
case HardwareTypes.TDAS_Pro_Rack: image = "Assets/Hardware/TDAS_Rack_4M8M_Angle.jpg"; break;
case HardwareTypes.RibeyeLED: image = "Assets/LightGray.png"; break;
case HardwareTypes.Ribeye: image = "Assets/LightGray.png"; break;
case HardwareTypes.SLICE2_IEPE_Lo: image = "Assets/Hardware/SLICE_PRO_Angle.jpg"; break;
case HardwareTypes.SLICE2_IEPE_Hi: image = "Assets/Hardware/SLICE_PRO_Angle.jpg"; break;
case HardwareTypes.SLICE2_Bridge_Lo: image = "Assets/Hardware/SLICE_PRO_Angle.jpg"; break;
case HardwareTypes.SLICE2_Bridge_Hi: image = "Assets/Hardware/SLICE_PRO_Angle.jpg"; break;
case HardwareTypes.TDAS_LabRack:
image = "Assets/Hardware/LAB Rack - retouched.jpg";
break;
case HardwareTypes.SLICE2_DIM:
image = "Assets/Hardware/SLICE PRO DIM_removed.png";
break;
case HardwareTypes.SLICE2_SLD:
image = "Assets/Hardware/SLICE_LAB_DIM.jpg";
break;
case HardwareTypes.SLICE2_SLS:
image = "Assets/Hardware/SLICE_PRO_SLS_Angle.jpg";
break;
case HardwareTypes.SLICE2_SIM:
case HardwareTypes.SLICE2_Base:
image = "Assets/Hardware/SLICE_PRO_Angle.jpg";
break;
case HardwareTypes.SLICE2_TOM:
image = "Assets/Hardware/SLICE PRO TOM_removed.png";
break;
case HardwareTypes.SLICE2_SLT:
image = "Assets/Hardware/SLICE_LAB_TOM.jpg";
break;
case HardwareTypes.SLICE1_5_Nano_Base:
image = "Assets/Hardware/SLICE_1_5_NANO_Angle.jpg";
break;
case HardwareTypes.SLICE1_5_Micro_Base:
image = "Assets/Hardware/SLICE_1_5_MICRO_Angle.jpg";
break;
case HardwareTypes.SLICE_IEPE: image = "Assets/Hardware/SLICE_1_NANO_BRIDGE_Connctor_Angle.jpg"; break;
case HardwareTypes.SLICE_Distributor: image = "Assets/Hardware/SLICE_1_DB_Angle.jpg"; break;
case HardwareTypes.SLICE_Bridge: image = "Assets/Hardware/SLICE_1_NANO_BRIDGE_Connctor_Angle.jpg"; break;
case HardwareTypes.SLICE_Base:
case HardwareTypes.SLICE_NANO_Base:
image = "Assets/Hardware/SLICE_Base_NANO_Angle.jpg";
break;
case HardwareTypes.SLICE_LabEthernet:
image = "Assets/Hardware/SLICE PRO Lab ECM.png";
break;
case HardwareTypes.SLICE_Micro_Base: image = "Assets/Hardware/SLICE_Base_MICRO_Angle.jpg"; break;
case HardwareTypes.SLICE_EthernetController:
image = "Assets/Hardware/SLICE PRO ECM_removed.png";
break;
case HardwareTypes.SLICE_Pro_Distributor:
image = "Assets/Hardware/SLICEPRODb.png";
break;
case HardwareTypes.SLICE_Mini_Distributor:
image = "Assets/Hardware/SLICE_Mini_DB_Angle.jpg";
break;
case HardwareTypes.SLICE6DB:
image = "Assets/Hardware/SLICE6Db.png";
break;
case HardwareTypes.SLICE6DB3:
image = SLICE6DB3ImagePath;
break;
case HardwareTypes.SLICE6DB_InDummy:
image = "Assets/Hardware/SLICE6Db.png";
break;
case HardwareTypes.SLICE6_Base:
image = "Assets/Hardware/SLICE6 Base.png";
break;
case HardwareTypes.SLICE6_AIR:
case HardwareTypes.S6A_EthernetRecorder:
image = "Assets/Hardware/SLICE6 AIR.png";
break;
case HardwareTypes.SLICE6_AIR_BR:
image = "Assets/Hardware/SLICE6_AIR_BR.png";
break;
case HardwareTypes.PowerPro:
image = "Assets/Hardware/PowerPro.jpg";
break;
case HardwareTypes.TSR_AIR:
case HardwareTypes.TSR_AIR_RevB:
image = "Assets/Hardware/TSRAIR.png";
break;
case HardwareTypes.DKR:
image = "Assets/Hardware/DKR-ISO.jpg";
break;
case HardwareTypes.DIR:
image = "Assets/Hardware/DIR-ISO.jpg";
break;
default: break;
}
return image;
}
public static string GetStringForType(HardwareTypes type)
{
switch (type)
{
case HardwareTypes.SLICE1_G5Stack:
return StringResources.AutoDetectDas_SliceG5;
case HardwareTypes.G5VDS: return StringResources.AutoDetectDas_G5VDS;
case HardwareTypes.G5INDUMMY: return StringResources.AutoDetectDas_G5INDUMMY;
case HardwareTypes.TDAS_Pro_Rack: return StringResources.AutoDetectDas_TDAS_Pro_Rack;
case HardwareTypes.SLICE2_Base: return StringResources.AutoDetectDas_SLICE2_Base;
case HardwareTypes.SLICE2_SLD: return StringResources.SLICEPRO_SLD;
case HardwareTypes.SLICE2_SIM: return StringResources.SLICEPRO_SIM;
case HardwareTypes.SLICE2_SLS: return StringResources.SLICEPRO_SLS;
case HardwareTypes.SLICE2_SLT: return StringResources.SLICELAB_TOM;
case HardwareTypes.SLICE2_DIM: return StringResources.SLICEPRO_DIM;
case HardwareTypes.SLICE_Pro_Distributor: return StringResources.SLICEPRODB;
case HardwareTypes.SLICE6DB: return StringResources.SLICE6DB;
case HardwareTypes.SLICE6DB3: return StringResources.SLICE6DB3;
case HardwareTypes.SLICE6DB_InDummy: return StringResources.SLICE6DB_InDummy;
case HardwareTypes.SLICE2_TOM: return StringResources.SLICEPRO_TOM;
case HardwareTypes.SLICE1_5_Nano_Base: return StringResources.AutoDetectDas_SLICE1_5_NANO_Base;
case HardwareTypes.SLICE1_5_Micro_Base: return StringResources.AutoDetectDas_SLICE1_5_MICRO_Base;
case HardwareTypes.SLICE_Distributor: return StringResources.AutoDetectDas_SliceDB;
case HardwareTypes.SLICE_Mini_Distributor: return StringResources.AutoDetectDas_SliceMiniDB;
case HardwareTypes.SLICE_EthernetController: return StringResources.AutoDetectDAS_SLICE_EthernetController;
case HardwareTypes.SLICE_LabEthernet: return StringResources.SLICEPROLAB_Ethernet;
case HardwareTypes.SLICE_Base: return StringResources.AutoDetectDas_SLICE_Base;
case HardwareTypes.SLICE_Micro_Base: return StringResources.AutoDetectDas_SLICE_Micro_Base;
case HardwareTypes.SLICE_NANO_Base: return StringResources.AutoDetectDas_SLICE_NANO_Base;
case HardwareTypes.SLICE_Bridge: return StringResources.AutoDetectDASControl_SLICEBridge;
case HardwareTypes.SLICE_IEPE: return StringResources.AutoDetectDASControl_SLICEIEPE;
case HardwareTypes.SLICE2_Bridge_Hi: return StringResources.AutoDetectDASControl_SLICEBridge;
case HardwareTypes.SLICE2_Bridge_Lo: return StringResources.AutoDetectDASControl_SLICEBridge;
case HardwareTypes.SLICE2_IEPE_Hi: return StringResources.AutoDetectDASControl_SLICEBridge;
case HardwareTypes.SLICE2_IEPE_Lo: return StringResources.AutoDetectDASControl_SLICEBridge;
case HardwareTypes.TOM: return StringResources.AutoDetectDASControl_TDASPRO_TOM;
case HardwareTypes.SIM: return StringResources.AutoDetectDASControl_TDASPRO_SIM;
case HardwareTypes.DIM: return StringResources.AutoDetectDASControl_TDASPRO_DIM;
case HardwareTypes.TDAS_LabRack: return StringResources.TDAS_Pro_LabRack;
case HardwareTypes.SLICE6_Base: return StringResources.SLICE6_Base;
case HardwareTypes.SLICE6_AIR: return StringResources.SLICE6_AIR;
case HardwareTypes.SLICE6_AIR_BR: return StringResources.SLICE6_AIR_BR;
case HardwareTypes.PowerPro: return StringResources.PowerPRO;
case HardwareTypes.TSR_AIR:
case HardwareTypes.TSR_AIR_RevB: return StringResources.TSR_AIR;
case HardwareTypes.DKR: return StringResources.DKR;
case HardwareTypes.DIR: return StringResources.DIR;
case HardwareTypes.S6A_EthernetRecorder: return StringResources.Slice6EthernetRecorder;
default: return StringResources.UnknownModule;
}
}
public bool IsSLICEEthernetController
{
get
{
switch (GetHardwareTypeEnum())
{
case HardwareTypes.SLICE_EthernetController:
case HardwareTypes.SLICE_Mini_Distributor:
case HardwareTypes.SLICE_Distributor:
case HardwareTypes.SLICE_LabEthernet:
case HardwareTypes.SLICE_Pro_Distributor:
case HardwareTypes.SLICE6DB:
case HardwareTypes.SLICE6DB3:
case HardwareTypes.SLICE6DB_InDummy:
case HardwareTypes.PowerPro:
return true;
default:
return false;
}
}
}
public bool IsS6AEthernetRecorder
{
get
{
return GetHardwareTypeEnum() == HardwareTypes.S6A_EthernetRecorder;
}
}
/// <summary>
/// returns true if the unit should warn when it's missing during hardware check
/// some units we may not care about (ECM?) and it's okay to continue without them
/// even ECM can be a bad assumption as sometimes they need to be armed in systems
/// so we may come back and have all units warn when missing, but for now I'm just fixing
/// 17799 No missing DAS error for offline POWER PRO
/// </summary>
/// <returns></returns>
public bool ShouldWarnWhenMissing()
{
switch (GetHardwareTypeEnum())
{
case HardwareTypes.SLICE_EthernetController:
case HardwareTypes.SLICE_Distributor:
case HardwareTypes.SLICE_LabEthernet:
case HardwareTypes.SLICE6DB:
case HardwareTypes.SLICE_Pro_Distributor:
case HardwareTypes.SLICE6DB_InDummy:
case HardwareTypes.SLICE6DB3:
return false;
default: return true;
}
}
public bool IsSLICEEthernetDAS
{
get
{
if (Connection.ToUpper().Contains("USB")) return false;
switch (GetHardwareTypeEnum())
{
case HardwareTypes.SLICE1_5_Micro_Base:
case HardwareTypes.SLICE_NANO_Base:
case HardwareTypes.SLICE1_5_Nano_Base:
case HardwareTypes.SLICE1_G5Stack:
case HardwareTypes.SLICE2_Base:
case HardwareTypes.SLICE2_DIM:
case HardwareTypes.SLICE2_SLD:
case HardwareTypes.SLICE2_SIM:
case HardwareTypes.SLICE2_SLS:
case HardwareTypes.SLICE2_SLT:
case HardwareTypes.SLICE2_TOM:
case HardwareTypes.SLICE_Base:
case HardwareTypes.SLICE_Micro_Base:
case HardwareTypes.SLICE6_Base:
case HardwareTypes.SLICE6_AIR:
case HardwareTypes.S6A_EthernetRecorder:
case HardwareTypes.SLICE6_AIR_BR:
case HardwareTypes.TSR_AIR:
case HardwareTypes.TSR_AIR_RevB:
case HardwareTypes.DKR:
case HardwareTypes.DIR:
return true;
default:
return false;
}
}
}
//FB 26817
public bool IsSLICEE1
{
get
{
if (Connection.ToUpper().Contains("USB")) return false;
switch (GetHardwareTypeEnum())
{
case HardwareTypes.SLICE_Base:
case HardwareTypes.SLICE_Micro_Base:
case HardwareTypes.SLICE_NANO_Base:
return true;
default:
return false;
}
}
}
public bool IsSLICE6Distributor
{
get
{
if (Connection.ToUpper().Contains("USB")) return false;
switch (GetHardwareTypeEnum())
{
case HardwareTypes.SLICE6DB:
case HardwareTypes.SLICE6DB3:
case HardwareTypes.SLICE6DB_InDummy:
return true;
default:
return false;
}
}
}
public bool IsSLICE6OrSLICE6A
{
get
{
if (Connection.ToUpper().Contains("USB")) return false;
switch (GetHardwareTypeEnum())
{
case HardwareTypes.SLICE6_Base:
case HardwareTypes.SLICE6_AIR:
case HardwareTypes.SLICE6_AIR_BR:
return true;
default:
return false;
}
}
}
public bool IsEmbeddedSensorIC
{
get
{
switch (GetHardwareTypeEnum())
{
case HardwareTypes.EMB_LIN_ACC_LO:
case HardwareTypes.EMB_LIN_ACC_HI:
case HardwareTypes.EMB_ANG_ACC:
case HardwareTypes.EMB_ANG_ARS:
case HardwareTypes.EMB_ATM:
case HardwareTypes.EMB_MAG:
case HardwareTypes.EMB_MAG_SWITCH:
case HardwareTypes.EMB_MIC:
case HardwareTypes.EMB_OPT:
case HardwareTypes.EMB_RTC_S_MARK:
case HardwareTypes.EMB_RTC_NS_PAD:
return true;
default:
return false;
}
}
}
public string Connection
{
get => _hardware.IPAddress;
set
{
_hardware.IPAddress = value;
OnPropertyChanged(Tags.Connection.ToString());
}
}
/// <summary>
/// returns a cleaned up string ...
/// for ethernet slice this will be the ip address,
/// for modules this will be the base serial
/// </summary>
public string ConnectionUSBAware2
{
get
{
if (IsModule())
{
return Connection.IndexOf("x", StringComparison.Ordinal) > 0 ? StringResources.Table_NA : Connection;
}
return Connection;
}
}
/// <summary>
/// returns the true connection for devices, for ethernet slice this will contain USB
/// </summary>
public string ConnectionUSBAware
{
get
{
switch (GetHardwareTypeEnum())
{
case HardwareTypes.Ribeye:
case HardwareTypes.RibeyeLED:
case HardwareTypes.SLICE_Base:
case HardwareTypes.SLICE_Bridge:
case HardwareTypes.SLICE_IEPE:
case HardwareTypes.SLICE_Micro_Base:
case HardwareTypes.SLICE_NANO_Base:
case HardwareTypes.SLICE1_5_Micro_Base:
case HardwareTypes.SLICE1_5_Nano_Base:
case HardwareTypes.SLICE2_Base:
case HardwareTypes.SLICE2_Bridge_Hi:
case HardwareTypes.SLICE2_Bridge_Lo:
case HardwareTypes.SLICE2_DIM:
case HardwareTypes.SLICE2_SLD:
case HardwareTypes.SLICE2_IEPE_Hi:
case HardwareTypes.SLICE2_IEPE_Lo:
case HardwareTypes.SLICE2_SIM:
case HardwareTypes.SLICE2_SLS:
case HardwareTypes.SLICE2_TOM:
case HardwareTypes.SLICE2_SLT:
case HardwareTypes.DKR:
case HardwareTypes.DIR:
case HardwareTypes.EMB_ANG_ACC:
case HardwareTypes.EMB_ANG_ARS:
case HardwareTypes.EMB_ATM:
case HardwareTypes.EMB_LIN_ACC_LO:
case HardwareTypes.EMB_LIN_ACC_HI:
case HardwareTypes.EMB_MAG:
case HardwareTypes.EMB_MAG_SWITCH:
case HardwareTypes.EMB_MIC:
case HardwareTypes.EMB_OPT:
case HardwareTypes.EMB_RTC_S_MARK:
case HardwareTypes.EMB_RTC_NS_PAD:
return "USB";
}
return Connection;
}
}
public string Firmware
{
get => _hardware.FirmwareVersion;
set
{
_hardware.FirmwareVersion = value;
OnPropertyChanged(Tags.FirmwareVersion.ToString());
}
}
public DateTime CalDate => _hardware.CalDate;
/// <summary>
/// whether hardware supports and is using first use date
/// 15524 DAS "First Use Date"
/// </summary>
public bool IsFirstUseValid => _hardware.IsFirstUseValid;
/// <summary>
/// first date of use after calibration
/// only valid if IsFirstUseValid is true
/// null value indicates hardware has not been used since calibration
/// (once again, only if IsFirstUseValid is true)
/// 15524 DAS "First Use Date"
/// </summary>
public DateTime? FirstUseDate => _hardware.FirstUseDate;
public bool CalDateFailed
{
get
{
if (CalDate.Year <= 1970) { return false; }
var dueDate = CalDueDate;
return dueDate <= DateTime.Now.Date;
}
}
public bool CalDateWarning
{
get
{
if (CalDate.Year <= 1970) { return false; }
var dueDate = CalWarningDate;
return dueDate <= DateTime.Now.Date;
}
}
public DateTime CalDueDate
{
get
{
//15524 DAS "First Use Date
var firstUseDate = CalDate;
if (IsFirstUseValid)
{
if (null == FirstUseDate)
{
firstUseDate = DateTime.Today;
}
else
{
firstUseDate = (DateTime)FirstUseDate;
}
}
GetDueDatePeriod(out var days, out var years);
try
{
return firstUseDate.AddDays(days).AddYears(years);
}
catch (ArgumentOutOfRangeException ex)
{
APILogger.Log("CalDueDate is not a valid date", ex);
return DateTime.MaxValue;
}
catch (Exception ex)
{
APILogger.Log("Failed to get calduedate", ex);
return DateTime.Today;
}
}
}
private void GetDueDatePeriod(out int days, out int years)
{
days = 0;
years = 0;
switch (GetHardwareTypeEnum())
{
case HardwareTypes.G5INDUMMY:
case HardwareTypes.G5VDS:
days = SerializedSettings.G5CalPeriod;
break;
case HardwareTypes.Ribeye:
case HardwareTypes.RibeyeLED:
case HardwareTypes.SLICE_Base:
case HardwareTypes.SLICE_Bridge:
case HardwareTypes.SLICE_IEPE:
case HardwareTypes.SLICE_Micro_Base:
case HardwareTypes.SLICE_NANO_Base:
case HardwareTypes.SLICE1_G5Stack:
days = SerializedSettings.SLICE1CalPeriod;
break;
case HardwareTypes.SLICE_Distributor:
case HardwareTypes.SLICE_EthernetController:
case HardwareTypes.SLICE_Mini_Distributor:
case HardwareTypes.SLICE_LabEthernet:
years = 25;
break;
case HardwareTypes.SLICE1_5_Micro_Base:
case HardwareTypes.SLICE1_5_Nano_Base:
days = SerializedSettings.SLICE1_5CalPeriod;
break;
case HardwareTypes.SLICE6DB:
case HardwareTypes.SLICE6DB3:
case HardwareTypes.SLICE6DB_InDummy:
case HardwareTypes.SLICE_Pro_Distributor:
days = SerializedSettings.SLICE6DB_CalPeriod;
break;
case HardwareTypes.SLICE6_Base:
days = SerializedSettings.SLICE6_CalPeriod;
break;
case HardwareTypes.SLICE6_AIR:
days = SerializedSettings.SLICE6Air_CalPeriod;
break;
case HardwareTypes.SLICE6_AIR_BR:
days = SerializedSettings.SLICE6_CalPeriod;
break;
case HardwareTypes.SLICE2_Base:
case HardwareTypes.SLICE2_Bridge_Hi:
case HardwareTypes.SLICE2_Bridge_Lo:
case HardwareTypes.SLICE2_DIM:
case HardwareTypes.SLICE2_SLD:
case HardwareTypes.SLICE2_IEPE_Hi:
case HardwareTypes.SLICE2_IEPE_Lo:
case HardwareTypes.SLICE2_SIM:
case HardwareTypes.SLICE2_SLS:
case HardwareTypes.SLICE2_TOM:
case HardwareTypes.SLICE2_SLT:
days = SerializedSettings.SLICE2_CalPeriod;
break;
case HardwareTypes.TSR_AIR:
case HardwareTypes.TSR_AIR_RevB:
case HardwareTypes.DKR:
case HardwareTypes.DIR:
case HardwareTypes.EMB_ANG_ACC:
case HardwareTypes.EMB_ANG_ARS:
case HardwareTypes.EMB_ATM:
case HardwareTypes.EMB_LIN_ACC_LO:
case HardwareTypes.EMB_LIN_ACC_HI:
case HardwareTypes.EMB_MAG:
case HardwareTypes.EMB_MAG_SWITCH:
case HardwareTypes.EMB_MIC:
case HardwareTypes.EMB_OPT:
case HardwareTypes.EMB_RTC_S_MARK:
case HardwareTypes.EMB_RTC_NS_PAD:
days = SerializedSettings.TSRAir_CalPeriod;
break;
case HardwareTypes.TDAS_Pro_Rack:
case HardwareTypes.TDAS_LabRack:
case HardwareTypes.TOM:
case HardwareTypes.DIM:
case HardwareTypes.SIM:
days = SerializedSettings.TDASCalPeriod;
break;
case HardwareTypes.PowerPro:
days = SerializedSettings.POWERPRO_CalPeriod;
break;
default:
days = SerializedSettings.SLICE1CalPeriod;
break;
}
}
public DateTime CalWarningDate
{
get
{
try
{
return CalDueDate.AddDays(-1 * SerializedSettings.CalWarningPeriod);
}
catch (ArgumentOutOfRangeException ex)
{
APILogger.Log($"CalWarning period is invalid", ex);
return DateTime.MaxValue;
}
catch (Exception ex)
{
APILogger.Log("Failed to get calwarning date", ex);
return DateTime.Today;
}
}
}
public int MaxModules
{
get => _hardware.MaxModules;
set
{
_hardware.MaxModules = value;
OnPropertyChanged(Tags.MaxModules.ToString());
}
}
public int[] ChannelTypes
{
get => _hardware.ChannelTypes;
set
{
_hardware.ChannelTypes = value;
OnPropertyChanged(Tags.ChannelTypes.ToString());
}
}
public bool Reprogrammable
{
get => _hardware.IsProgrammable;
set
{
_hardware.IsProgrammable = value;
OnPropertyChanged(Tags.Reprogramable.ToString());
}
}
public bool Reconfigurable
{
get => _hardware.IsReconfigurable;
set
{
_hardware.IsReconfigurable = value;
OnPropertyChanged(Tags.Reconfigurable.ToString());
}
}
public string MaxMemory => long.MinValue == _hardware.MaxMemory ? "" : ReadableSize(_hardware.MaxMemory);
public long GetMaxMemoryLong() { return _hardware.MaxMemory; }
public string MaxSampleRate => double.IsNaN(_hardware.MaxSampleRate) ? "" : _hardware.MaxSampleRate.ToString("N");
public double GetMaxSampleRateDouble() { return _hardware.MaxSampleRate; }
public string MinSampleRate => double.IsNaN(_hardware.MinSampleRate) ? "" : _hardware.MinSampleRate.ToString("N");
public double GetMinSampleRateDouble() { return _hardware.MinSampleRate; }
public string MaxAAFRate => double.IsNaN(_hardware.MaxAAFRate) ? "" : _hardware.MaxAAFRate.ToString("N");
public double GetMaxAAFRateDouble() { return _hardware.MaxAAFRate; }
public bool LocalOnly
{
get => _hardware.LocalOnly;
set
{
_hardware.LocalOnly = value;
OnPropertyChanged(Tags.LocalOnly.ToString());
}
}
public int ProtocolVersion => _hardware.ProtocolVersion;
public static string ReadableSize(long size, int unit = 0)
{
string[] units = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
while (size >= 1024)
{
size /= 1024;
++unit;
}
var unitstring = "N/A";
if (unit < units.Length) { unitstring = units[unit]; }
return $"{size:G4} {unitstring}";
}
public static string GetConnectionString(IDASCommunication das)
{
var s = ((ICommunication)das).Transport.ConnectString;
s = s.IndexOf(':') > 0 ? s.Split(new[] { ':' }, 2)[0] : "USB";
return s;
}
public string GetConnectionStringNonStatic(IDASCommunication das)
{
return GetConnectionString(das);
}
/// <summary>
/// returns the connect string of the das (IP:Port, or USB connect string)
/// </summary>
/// <param name="das"></param>
/// <returns></returns>
public static string GetTransportConnectString(IDASCommunication das)
{
return ((ICommunication)das).Transport.ConnectString;
}
public static string GetConnectionStringDiscoverHardware(IDASCommunication das)
{
var s = ((ICommunication)das).Transport.ConnectString;
s = s.IndexOf(':') > 0 ? s.Split(new[] { ':' }, 2)[0] : "USB";
switch (das.GetHardwareType())
{
case HardwareTypes.SLICE2_TOM:
case HardwareTypes.SLICE2_SLT:
case HardwareTypes.SLICE2_SIM:
case HardwareTypes.SLICE2_SLS:
case HardwareTypes.SLICE2_SLD:
case HardwareTypes.SLICE2_IEPE_Lo:
case HardwareTypes.SLICE2_IEPE_Hi:
case HardwareTypes.SLICE2_DIM:
case HardwareTypes.SLICE2_Bridge_Lo:
case HardwareTypes.SLICE2_Bridge_Hi:
case HardwareTypes.SLICE2_Base:
case HardwareTypes.SLICE1_G5Stack:
case HardwareTypes.SLICE1_5_Nano_Base:
case HardwareTypes.SLICE1_5_Micro_Base:
case HardwareTypes.SLICE_NANO_Base:
case HardwareTypes.SLICE_Micro_Base:
case HardwareTypes.SLICE_IEPE:
case HardwareTypes.SLICE_Bridge:
case HardwareTypes.SLICE_Base:
case HardwareTypes.Ribeye:
case HardwareTypes.RibeyeLED:
case HardwareTypes.DIR:
case HardwareTypes.DKR:
if (s != "USB") { s += "xUSB"; }
break;
case HardwareTypes.EMB_ANG_ACC:
case HardwareTypes.EMB_ANG_ARS:
case HardwareTypes.EMB_ATM:
case HardwareTypes.EMB_LIN_ACC_HI:
case HardwareTypes.EMB_LIN_ACC_LO:
case HardwareTypes.EMB_MAG:
case HardwareTypes.EMB_MAG_SWITCH:
case HardwareTypes.EMB_MIC:
case HardwareTypes.EMB_OPT:
case HardwareTypes.EMB_RTC_S_MARK:
case HardwareTypes.EMB_RTC_NS_PAD:
if (s != "EMB") { s += "xEMB"; }
break;
}
return s;
}
public DASHardware()
{
}
private static double GetMaxAAFRateFromDASType(HardwareTypes dasTypeEnum)
{
var maxAAFRate = 0D;
var serialNumber = string.Empty;
if ((dasTypeEnum == HardwareTypes.G5INDUMMY) ||
(dasTypeEnum == HardwareTypes.G5VDS) ||
(dasTypeEnum == HardwareTypes.SLICE1_G5Stack))
{
maxAAFRate = Common.SerializedSettings.MaxAAFRate_G5;
}
else if ((dasTypeEnum == HardwareTypes.TDAS_LabRack) ||
(dasTypeEnum == HardwareTypes.TDAS_Pro_Rack) ||
(dasTypeEnum == HardwareTypes.TOM) ||
(dasTypeEnum == HardwareTypes.SIM) ||
(dasTypeEnum == HardwareTypes.DIM))
{
maxAAFRate = Common.SerializedSettings.MaxAAFRate_TDAS;
}
else
{
switch (dasTypeEnum)
{
case HardwareTypes.DIR:
serialNumber = DbOperations.DAS.DIR_PROTOTYPE;
break;
case HardwareTypes.DKR:
serialNumber = DbOperations.DAS.DKR_PROTOTYPE;
break;
case HardwareTypes.PowerPro:
serialNumber = DbOperations.DAS.POWERPRO_PROTOTYPE;
break;
case HardwareTypes.S6A_EthernetRecorder:
serialNumber = DbOperations.DAS.SLICE6_AIR_ER_PROTOTYPE;
break;
case HardwareTypes.SLICE1_5_Micro_Base:
serialNumber = DbOperations.DAS.SLICE1_5_MicroPROTOTYPE;
break;
case HardwareTypes.SLICE1_5_Nano_Base:
serialNumber = DbOperations.DAS.SLICE1_5PROTOTYPE;
break;
case HardwareTypes.SLICE2_Base:
serialNumber = DbOperations.DAS.SLICEPRO_PROTOTYPE;
break;
case HardwareTypes.SLICE2_DIM:
serialNumber = DbOperations.DAS.SLICEPRODIM_PROTOTYPE;
break;
case HardwareTypes.SLICE2_SIM:
serialNumber = DbOperations.DAS.SLICEPROSIM_PROTOTYPE;
break;
case HardwareTypes.SLICE2_SLD:
serialNumber = DbOperations.DAS.SLICEPROSLD_PROTOTYPE;
break;
case HardwareTypes.SLICE2_SLS:
serialNumber = DbOperations.DAS.SLICEPROSLS_PROTOTYPE;
break;
case HardwareTypes.SLICE_Pro_Distributor:
serialNumber = DbOperations.DAS.SLICEPRO_DB_PROTOTYPE;
break;
case HardwareTypes.SLICE2_SLT:
serialNumber = DbOperations.DAS.SLICEPROSLT_PROTOTYPE;
break;
case HardwareTypes.SLICE2_TOM:
serialNumber = DbOperations.DAS.SLICEPROTOM_PROTOTYPE;
break;
case HardwareTypes.SLICE6DB:
serialNumber = DbOperations.DAS.SLICE6DB_PROTOTYPE;
break;
case HardwareTypes.SLICE6DB3:
serialNumber = DbOperations.DAS.SLICE6DB3_PROTOTYPE;
break;
case HardwareTypes.SLICE6DB_InDummy:
serialNumber = DbOperations.DAS.SLICE6DB_INDUMMY_PROTOTYPE;
break;
case HardwareTypes.SLICE6_AIR_BR:
serialNumber = DbOperations.DAS.SLICE6_AIR_BR_PROTOTYPE;
break;
case HardwareTypes.SLICE6_AIR:
serialNumber = DbOperations.DAS.SLICE6_AIR_PROTOTYPE;
break;
case HardwareTypes.SLICE6_Base:
serialNumber = DbOperations.DAS.SLICE6_PROTOTYPE;
break;
case HardwareTypes.SLICE_Base:
serialNumber = DbOperations.DAS.SLICE1_PROTOTYPE;
break;
case HardwareTypes.SLICE_Distributor:
serialNumber = DbOperations.DAS.SDB_PROTOTYPE;
break;
case HardwareTypes.SLICE_EthernetController:
serialNumber = DbOperations.DAS.ECM_PROTOTYPE;
break;
case HardwareTypes.SLICE_LabEthernet:
serialNumber = DbOperations.DAS.SLE_PROTOTYPE;
break;
case HardwareTypes.SLICE_Micro_Base:
serialNumber = DbOperations.DAS.Slice_MicroPROTOTYPE;
break;
case HardwareTypes.SLICE_Mini_Distributor:
serialNumber = DbOperations.DAS.SPM_PROTOTYPE;
break;
case HardwareTypes.SLICE_NANO_Base:
serialNumber = DbOperations.DAS.Slice_NanoPROTOTYPE;
break;
case HardwareTypes.TSR_AIR:
serialNumber = DbOperations.DAS.TSR_AIR_PROTOTYPE;
break;
case HardwareTypes.TSR_AIR_RevB:
serialNumber = DbOperations.DAS.TSR_AIR_REVB_PROTOTYPE;
break;
}
maxAAFRate = GetMaxAAFRateFromPrototype(serialNumber);
}
return maxAAFRate;
}
public static Hardware ReadXML(XmlElement root)
{
var hardware = new Hardware() { IsFirstUseValid = false, FirstUseDate = null };
foreach (var node in root.ChildNodes)
{
if (node is XmlElement) { ProcessFirstLevelElement(node as XmlElement, ref hardware); }
}
//18860 MaxAAFRate validation after import of old Test Setup export fails
if (hardware.MaxAAFRate == 0)
{
hardware.MaxAAFRate = GetMaxAAFRateFromDASType(hardware.DASTypeEnum);
}
if (hardware.DASTypeEnum != HardwareTypes.G5VDS) return hardware;
//correct any G5 VDS that may have been written into xml without support for Half Bridge plus sig
//12431 Cannot run test after 1.4 to 1.10 migration with TDAS G5 VDS.
foreach (var ch in hardware.ISOChannels)
{
if (ch.SupportedBridges == ((int)SensorConstants.BridgeType.FullBridge | (int)SensorConstants.BridgeType.HalfBridge))
{
ch.SupportedBridges = (int)SensorConstants.BridgeType.FullBridge |
(int)SensorConstants.BridgeType.HalfBridge |
(int)SensorConstants.BridgeType.HalfBridge_SigPlus;
}
}
return hardware;
}
private static void ProcessFirstLevelElement(XmlElement node, ref Hardware hardware)
{
if (Enum.TryParse(node.Name, out DbOperations.DAS.Fields field))
{
switch (field)
{
case DbOperations.DAS.Fields.CalDate: hardware.CalDate = DateTime.Parse(node.InnerText, CultureInfo.InvariantCulture); break;
case DbOperations.DAS.Fields.Channels: hardware.Channels = int.Parse(node.InnerText, CultureInfo.InvariantCulture); break;
case DbOperations.DAS.Fields.ChannelTypes:
{
var channels = new List<int>();
var tokens = node.InnerText.Split(new[] { CultureInfo.InvariantCulture.TextInfo.ListSeparator }, StringSplitOptions.None);
foreach (var tok in tokens)
{
if (string.IsNullOrEmpty(tok)) { break; }
channels.Add(int.Parse(tok, CultureInfo.InvariantCulture));
}
hardware.ChannelTypes = channels.ToArray();
}
break;
case DbOperations.DAS.Fields.Connection: hardware.IPAddress = node.InnerText; break;
case DbOperations.DAS.Fields.FirmwareVersion: hardware.FirmwareVersion = node.InnerText; break;
case DbOperations.DAS.Fields.LastModified: hardware.LastModified = DateTime.Parse(node.InnerText, CultureInfo.InvariantCulture); break;
case DbOperations.DAS.Fields.LastModifiedBy: hardware.LastModifiedBy = node.InnerText; break;
case DbOperations.DAS.Fields.LastUsed: hardware.LastUsed = DateTime.Parse(node.InnerText, CultureInfo.InvariantCulture); break;
case DbOperations.DAS.Fields.LastUsedBy: hardware.LastUsedBy = node.InnerText; break;
case DbOperations.DAS.Fields.LocalOnly: hardware.LocalOnly = Convert.ToBoolean(node.InnerText); break;
case DbOperations.DAS.Fields.MaxMemory: hardware.MaxMemory = Convert.ToInt64(node.InnerText, CultureInfo.InvariantCulture); break;
case DbOperations.DAS.Fields.MaxModules: hardware.MaxModules = Convert.ToInt32(node.InnerText, CultureInfo.InvariantCulture); break;
case DbOperations.DAS.Fields.MaxSampleRate: hardware.MaxSampleRate = Convert.ToDouble(node.InnerText, CultureInfo.InvariantCulture); break;
case DbOperations.DAS.Fields.MinSampleRate: hardware.MinSampleRate = Convert.ToDouble(node.InnerText, CultureInfo.InvariantCulture); break;
case DbOperations.DAS.Fields.Position: hardware.Position = node.InnerText; break;
case DbOperations.DAS.Fields.ProtocolVersion: hardware.ProtocolVersion = Convert.ToInt32(node.InnerText, CultureInfo.InvariantCulture); break;
case DbOperations.DAS.Fields.Reconfigurable: hardware.IsReconfigurable = Convert.ToBoolean(node.InnerText); break;
case DbOperations.DAS.Fields.IsModule: hardware.IsModule = Convert.ToBoolean(node.InnerText); break;
case DbOperations.DAS.Fields.Reprogramable: hardware.IsProgrammable = Convert.ToBoolean(node.InnerText); break;
case DbOperations.DAS.Fields.SerialNumber: hardware.SerialNumber = node.InnerText; break;
case DbOperations.DAS.Fields.Type: hardware.DASType = Convert.ToInt32(node.InnerText, CultureInfo.InvariantCulture); break;
case DbOperations.DAS.Fields.Version: hardware.Version = Convert.ToInt32(node.InnerText, CultureInfo.InvariantCulture); break;
case DbOperations.DAS.Fields.ParentDAS: hardware.ParentDAS = node.InnerText; break;
case DbOperations.DAS.Fields.DASId: hardware.DASId = Convert.ToInt32(node.InnerText); break;
case DbOperations.DAS.Fields.Port:
hardware.Port = Convert.ToInt32(node.InnerText,
CultureInfo.InvariantCulture); break;
case DbOperations.DAS.Fields.PositionOnChain:
hardware.PositionOnChain =
Convert.ToInt32(node.InnerText, CultureInfo.InvariantCulture); break;
case DbOperations.DAS.Fields.PositionOnDistributor:
hardware.PositionOnDistributor =
Convert.ToInt32(node.InnerText, CultureInfo.InvariantCulture);
break;
case DbOperations.DAS.Fields.FirstUseDate:
if (DateTime.TryParse(node.InnerText, CultureInfo.InvariantCulture,
DateTimeStyles.None, out var dt))
{
if (dt.Equals(DFConstantsAndEnums.FIRST_USE_DATE_NOT_SET))
{
hardware.FirstUseDate = null;
}
else
{
hardware.FirstUseDate = dt;
}
hardware.IsFirstUseValid = true;
}
else
{
APILogger.Log($"Possible in valid first use date: '{node.InnerText}' on {hardware.SerialNumber}");
hardware.IsFirstUseValid = false;
hardware.FirstUseDate = null;
}
break;
case DbOperations.DAS.Fields.StandIn:
hardware.StandIn = Convert.ToBoolean(node.InnerText);
break;
case DbOperations.DAS.Fields.TestId:
{
if (int.TryParse(node.InnerText, NumberStyles.Any, CultureInfo.InvariantCulture, out var iTemp))
{
hardware.TestId = iTemp;
}
else
{
hardware.TestId = null;
}
}
break;
case DbOperations.DAS.Fields.GroupId:
{
if (int.TryParse(node.InnerText, NumberStyles.Any, CultureInfo.InvariantCulture, out var iTemp))
{
hardware.GroupId = iTemp;
}
else
{
hardware.GroupId = null;
}
}
break;
case DbOperations.DAS.Fields.MaxAAFRate:
{
if (double.TryParse(node.InnerText, NumberStyles.Any, CultureInfo.InvariantCulture, out var iTemp))
{
hardware.MaxAAFRate = iTemp;
}
else
{
hardware.MaxAAFRate = hardware.MaxSampleRate / 5; //check this
}
}
break;
default: throw new NotSupportedException("DASHardware::ProcessFirstLevelElement unknown field: " + field);
}
}
else if (node.Name == "DASChannel")
{
var channel = new DTS.Common.ISO.HardwareChannel();
channel.ParentDAS = hardware;
var existingChannels = new List<DTS.Common.ISO.HardwareChannel>(hardware.ISOChannels);
foreach (var child in node.ChildNodes)
{
if (child is XmlElement)
{
ProcessSecondLevelElement(child as XmlElement, ref channel);
}
}
existingChannels.Add(channel);
hardware.ISOChannels = existingChannels.ToArray();
}
}
private static void ProcessSecondLevelElement(XmlElement node, ref DTS.Common.ISO.HardwareChannel channel)
{
if (!Enum.TryParse(node.Name, out DbOperations.DAS.DASChannelFields field)) return;
switch (field)
{
case DbOperations.DAS.DASChannelFields.ChannelIdx: channel.ChannelIdx = Convert.ToInt32(node.InnerText, CultureInfo.InvariantCulture); break;
case DbOperations.DAS.DASChannelFields.DASDisplayOrder: channel.DASDisplayOrder = Convert.ToInt32(node.InnerText, CultureInfo.InvariantCulture); break;
case DbOperations.DAS.DASChannelFields.HardwareId: break;
case DbOperations.DAS.DASChannelFields.LocalOnly: channel.LocalOnly = Convert.ToBoolean(node.InnerText); break;
case DbOperations.DAS.DASChannelFields.ModuleArrayIndex: channel.ModuleArrayIndex = Convert.ToInt32(node.InnerText); break;
case DbOperations.DAS.DASChannelFields.SupportedBridges: channel.SupportedBridges = Convert.ToInt32(node.InnerText, CultureInfo.InvariantCulture); break;
case DbOperations.DAS.DASChannelFields.SupportedExcitations: channel.SupportedExcitations = Convert.ToInt32(node.InnerText, CultureInfo.InvariantCulture); break;
case DbOperations.DAS.DASChannelFields.SupportedDigitalInputModes: channel.SupportedDigitalInputModes = Convert.ToInt32(node.InnerText, CultureInfo.InvariantCulture); break;
case DbOperations.DAS.DASChannelFields.SupportedDigitalOutputModes: channel.SupportedDigitalOutputModes = Convert.ToInt32(node.InnerText, CultureInfo.InvariantCulture); break;
case DbOperations.DAS.DASChannelFields.SupportedSquibFireModes: channel.SupportedSquibFireModes = Convert.ToInt32(node.InnerText, CultureInfo.InvariantCulture); break;
case DbOperations.DAS.DASChannelFields.ModuleSerialNumber: channel.ModuleSerialNumber = node.InnerText; break;
default: throw new NotSupportedException("DASHardware::ProcessSecondLevelElement unsupported field: " + field);
}
}
public void WriteXML(ref XmlWriter writer)
{
writer.WriteStartElement("DASHardware");
var fields = Enum.GetValues(typeof(DbOperations.DAS.Fields))
.Cast<DbOperations.DAS.Fields>().ToArray();
var isoH = GetHardware();
foreach (var f in fields)
{
if (f == DbOperations.DAS.Fields.FirstUseDate && !IsFirstUseValid)
{
continue;
}
if (f == DbOperations.DAS.Fields.GroupId && null == isoH.GroupId) { continue; }
if (f == DbOperations.DAS.Fields.TestId && null == isoH.TestId) { continue; }
writer.WriteStartElement(f.ToString());
switch (f)
{
case DbOperations.DAS.Fields.CalDate: writer.WriteString(CalDate.ToString(CultureInfo.InvariantCulture)); break;
case DbOperations.DAS.Fields.Channels: writer.WriteString(isoH.Channels.ToString(CultureInfo.InvariantCulture)); break;
case DbOperations.DAS.Fields.ChannelTypes:
{
var channeltypes = new List<string>();
foreach (var ct in isoH.ChannelTypes) { channeltypes.Add(ct.ToString(CultureInfo.InvariantCulture)); }
writer.WriteString(string.Join(CultureInfo.InvariantCulture.TextInfo.ListSeparator, channeltypes.ToArray()));
}
break;
case DbOperations.DAS.Fields.Connection: writer.WriteString(isoH.IPAddress); break;
case DbOperations.DAS.Fields.FirmwareVersion: writer.WriteString(isoH.FirmwareVersion); break;
case DbOperations.DAS.Fields.LastModified: writer.WriteString(isoH.LastModified.ToString(CultureInfo.InvariantCulture)); break;
case DbOperations.DAS.Fields.LastModifiedBy: writer.WriteString(isoH.LastModifiedBy); break;
case DbOperations.DAS.Fields.LastUsed: writer.WriteString(isoH.LastUsed.ToString(CultureInfo.InvariantCulture)); break;
case DbOperations.DAS.Fields.LastUsedBy: writer.WriteString(isoH.LastUsedBy); break;
case DbOperations.DAS.Fields.LocalOnly: writer.WriteString(isoH.LocalOnly.ToString()); break;
case DbOperations.DAS.Fields.MaxMemory: writer.WriteString(isoH.MaxMemory.ToString(CultureInfo.InvariantCulture)); break;
case DbOperations.DAS.Fields.MaxModules: writer.WriteString(isoH.MaxModules.ToString(CultureInfo.InvariantCulture)); break;
case DbOperations.DAS.Fields.MaxSampleRate: writer.WriteString(isoH.MaxSampleRate.ToString(CultureInfo.InvariantCulture)); break;
case DbOperations.DAS.Fields.MinSampleRate: writer.WriteString(isoH.MinSampleRate.ToString(CultureInfo.InvariantCulture)); break;
case DbOperations.DAS.Fields.Position: writer.WriteString(isoH.Position); break;
case DbOperations.DAS.Fields.ProtocolVersion: writer.WriteString(isoH.ProtocolVersion.ToString(CultureInfo.InvariantCulture)); break;
case DbOperations.DAS.Fields.Reconfigurable: writer.WriteString(isoH.IsReconfigurable.ToString()); break;
case DbOperations.DAS.Fields.IsModule: writer.WriteString(isoH.IsModule.ToString()); break;
case DbOperations.DAS.Fields.Reprogramable: writer.WriteString(isoH.IsProgrammable.ToString()); break;
case DbOperations.DAS.Fields.SerialNumber: writer.WriteString(isoH.SerialNumber); break;
case DbOperations.DAS.Fields.Type: writer.WriteString(isoH.DASType.ToString(CultureInfo.InvariantCulture)); break;
case DbOperations.DAS.Fields.Version: writer.WriteString(isoH.Version.ToString(CultureInfo.InvariantCulture)); break;
case DbOperations.DAS.Fields.DASId:
writer.WriteString(isoH.DASId.ToString(CultureInfo.InvariantCulture));
break;
case DbOperations.DAS.Fields.ParentDAS: writer.WriteString(isoH.ParentDAS); break;
case DbOperations.DAS.Fields.Port:
writer.WriteString(isoH.Port.ToString(CultureInfo.InvariantCulture)); break;
case DbOperations.DAS.Fields.PositionOnChain:
writer.WriteString(
isoH.PositionOnChain.ToString(CultureInfo.InvariantCulture));
break;
case DbOperations.DAS.Fields.PositionOnDistributor:
writer.WriteString(
isoH.PositionOnDistributor.ToString(CultureInfo.InvariantCulture));
break;
case DbOperations.DAS.Fields.FirstUseDate:
{
var dt = DFConstantsAndEnums.FIRST_USE_DATE_NOT_SET;
if (null != FirstUseDate)
{
dt = (DateTime)FirstUseDate;
}
writer.WriteString(dt.ToString("d", CultureInfo.InvariantCulture));
}
break;
case DbOperations.DAS.Fields.StandIn:
writer.WriteString(isoH.StandIn.ToString(CultureInfo.InvariantCulture));
break;
case DbOperations.DAS.Fields.TestId:
writer.WriteString(((int)isoH.TestId).ToString(CultureInfo.InvariantCulture));
break;
case DbOperations.DAS.Fields.GroupId:
writer.WriteString(((int)isoH.GroupId).ToString(CultureInfo.InvariantCulture));
break;
case DbOperations.DAS.Fields.MaxAAFRate:
writer.WriteString(isoH.MaxAAFRate.ToString(CultureInfo.InvariantCulture));
break;
default: throw new NotSupportedException("DASHardware::WriteXML unsupported field: " + f);
}
writer.WriteEndElement();//f.ToString()
}
var cFields = Enum.GetValues(typeof(DbOperations.DAS.DASChannelFields))
.Cast<DbOperations.DAS.DASChannelFields>().ToArray();
foreach (var channel in Channels)
{
var isoChannel = channel.GetISOChannel();
writer.WriteStartElement("DASChannel");
foreach (var cf in cFields)
{
writer.WriteStartElement(cf.ToString());
switch (cf)
{
case DbOperations.DAS.DASChannelFields.ChannelIdx: writer.WriteString(isoChannel.ChannelIdx.ToString(CultureInfo.InvariantCulture)); break;
case DbOperations.DAS.DASChannelFields.DASDisplayOrder: writer.WriteString(isoChannel.DASDisplayOrder.ToString(CultureInfo.InvariantCulture)); break;
case DbOperations.DAS.DASChannelFields.ModuleSerialNumber: writer.WriteString(isoChannel.ModuleSerialNumber); break;
case DbOperations.DAS.DASChannelFields.HardwareId: writer.WriteString(isoH.GetId()); break;
case DbOperations.DAS.DASChannelFields.ModuleArrayIndex: writer.WriteString(isoChannel.ModuleArrayIndex.ToString(CultureInfo.InvariantCulture)); break;
case DbOperations.DAS.DASChannelFields.LocalOnly: writer.WriteString(isoChannel.LocalOnly.ToString()); break;
case DbOperations.DAS.DASChannelFields.SupportedBridges: writer.WriteString(isoChannel.SupportedBridges.ToString(CultureInfo.InvariantCulture)); break;
case DbOperations.DAS.DASChannelFields.SupportedDigitalOutputModes: writer.WriteString(isoChannel.SupportedDigitalOutputModes.ToString(CultureInfo.InvariantCulture)); break;
case DbOperations.DAS.DASChannelFields.SupportedDigitalInputModes: writer.WriteString(isoChannel.SupportedDigitalInputModes.ToString(CultureInfo.InvariantCulture)); break;
case DbOperations.DAS.DASChannelFields.SupportedExcitations: writer.WriteString(isoChannel.SupportedExcitations.ToString(CultureInfo.InvariantCulture)); break;
case DbOperations.DAS.DASChannelFields.SupportedSquibFireModes: writer.WriteString(isoChannel.SupportedSquibFireModes.ToString(CultureInfo.InvariantCulture)); break;
default: throw new NotSupportedException("DASHardware::WriteXML unsupported field: " + cf);
}
writer.WriteEndElement();//cf.toString()
}
writer.WriteEndElement();//dasChannel
}
writer.WriteEndElement();
}
public int ChannelCount => _channels.Count;
/// <summary>
/// when switching DAS Type, a bunch of properties can be set automatically.
/// this function is designed to set those properties as a result of a das type change
/// it does it's work using prototyped versions of the das in question.
/// </summary>
public void Reconfigure()
{
var hardwareToCopy = new DASHardware();
switch (DASTypeEnum)
{
case HardwareTypes.SLICE_Mini_Distributor:
hardwareToCopy = DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.SPM_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.SLICE_EthernetController:
hardwareToCopy = DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.ECM_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.SLICE_Distributor:
hardwareToCopy = DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.SDB_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.SLICE_LabEthernet:
hardwareToCopy = DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.SLE_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.SLICE1_G5Stack:
hardwareToCopy =
DASHardwareList.GetList()
.GetPrototypeHardware(DbOperations.DAS.SG5_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.G5VDS:
hardwareToCopy = DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.G5_VDSPROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.G5INDUMMY:
hardwareToCopy = DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.G5_INDUMMYPROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.SLICE_NANO_Base:
hardwareToCopy = DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.Slice_NanoPROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.SLICE_Micro_Base:
hardwareToCopy = DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.Slice_MicroPROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.SLICE_Base:
hardwareToCopy = DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.SLICE1_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.SLICE1_5_Nano_Base:
hardwareToCopy = DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.SLICE1_5PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.SLICE1_5_Micro_Base:
hardwareToCopy = DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.SLICE1_5_MicroPROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.SLICE2_SLD:
hardwareToCopy =
DASHardwareList.GetList()
.GetPrototypeHardware(DbOperations.DAS.SLICEPROSLD_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.SLICE2_DIM:
hardwareToCopy = DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.SLICEPRODIM_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.SLICE2_TOM:
hardwareToCopy = DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.SLICEPROTOM_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.SLICE2_SLT:
hardwareToCopy =
DASHardwareList.GetList()
.GetPrototypeHardware(DbOperations.DAS.SLICEPROSLT_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.SLICE2_SIM:
hardwareToCopy = DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.SLICEPROSIM_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.SLICE2_SLS:
hardwareToCopy = DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.SLICEPROSLS_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.SLICE2_Base:
hardwareToCopy = DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.SLICEPRO_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.TDAS_Pro_Rack:
hardwareToCopy = DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.TDASPRO_4MRack, (int)DASTypeEnum);
break;
case HardwareTypes.SLICE6_Base:
hardwareToCopy =
DASHardwareList.GetList()
.GetPrototypeHardware(DbOperations.DAS.SLICE6_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.SLICE6_AIR:
hardwareToCopy =
DASHardwareList.GetList()
.GetPrototypeHardware(DbOperations.DAS.SLICE6_AIR_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.SLICE6_AIR_BR:
hardwareToCopy =
DASHardwareList.GetList()
.GetPrototypeHardware(DbOperations.DAS.SLICE6_AIR_BR_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.SLICE_Pro_Distributor:
hardwareToCopy = DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.SLICEPRO_DB_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.S6A_EthernetRecorder:
hardwareToCopy =
DASHardwareList.GetList()
.GetPrototypeHardware(DbOperations.DAS.SLICE6_AIR_ER_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.SLICE6DB:
hardwareToCopy =
DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.SLICE6DB_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.SLICE6DB3:
hardwareToCopy =
DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.SLICE6DB3_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.SLICE6DB_InDummy:
hardwareToCopy =
DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.SLICE6DB_INDUMMY_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.TDAS_LabRack:
hardwareToCopy =
DASHardwareList.GetList()
.GetPrototypeHardware(DbOperations.DAS.TDASPRO_LabRack, (int)DASTypeEnum);
break;
case HardwareTypes.PowerPro:
hardwareToCopy =
DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.POWERPRO_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.TSR_AIR:
hardwareToCopy =
DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.TSR_AIR_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.TSR_AIR_RevB:
hardwareToCopy =
DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.TSR_AIR_REVB_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.DKR:
hardwareToCopy =
DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.DKR_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.DIR:
hardwareToCopy =
DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.DIR_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.EMB_LIN_ACC_LO:
hardwareToCopy =
DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.EMB_LIN_ACC_LO_MODULE_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.EMB_LIN_ACC_HI:
hardwareToCopy =
DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.EMB_LIN_ACC_HI_MODULE_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.EMB_ANG_ARS:
hardwareToCopy =
DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.EMB_ARS_MODULE_PROTOTYPE, (int)DASTypeEnum);
break;
case HardwareTypes.EMB_ATM:
hardwareToCopy =
DASHardwareList.GetList().GetPrototypeHardware(DbOperations.DAS.EMB_ATM_MODULE_PROTOTYPE, (int)DASTypeEnum);
break;
}
var dasId = DASId;
var h = new Hardware(hardwareToCopy.GetHardware());
h.SerialNumber = SerialNumber;
h.Position = "";
//14035 Unhandled exception saving test setup
//the das ID was being assigned the prototype hardware's das id, above, but we don't want that, so we reset to what it
//originally was ...
h.DASId = dasId;
SetHardware(h);
}
private static readonly Dictionary<DFConstantsAndEnums.ModuleType, HardwareTypes> _moduleTypeToHWType = new Dictionary<DFConstantsAndEnums.ModuleType, HardwareTypes>
{
{ DFConstantsAndEnums.ModuleType.SliceBridge, HardwareTypes.SLICE_Bridge },
{DFConstantsAndEnums.ModuleType.SliceBridge2High, HardwareTypes.SLICE2_Bridge_Hi },
{DFConstantsAndEnums.ModuleType.SliceBridge2Low, HardwareTypes.SLICE2_Bridge_Lo },
{DFConstantsAndEnums.ModuleType.SLICEIEPE, HardwareTypes.SLICE_IEPE },
{DFConstantsAndEnums.ModuleType.SliceIEPE2High, HardwareTypes.SLICE2_IEPE_Hi },
{DFConstantsAndEnums.ModuleType.SliceIEPE2Low, HardwareTypes.SLICE2_IEPE_Lo },
{DFConstantsAndEnums.ModuleType.SliceARS, HardwareTypes.SLICE_Bridge },
{DFConstantsAndEnums.ModuleType.RibeyeLED, HardwareTypes.RibeyeLED },
{DFConstantsAndEnums.ModuleType.ProDIM, HardwareTypes.DIM },
{DFConstantsAndEnums.ModuleType.ProSIM, HardwareTypes.SIM },
{DFConstantsAndEnums.ModuleType.ProTOM, HardwareTypes.TOM },
{DFConstantsAndEnums.ModuleType.EmbeddedLinearAccelLowG, HardwareTypes.EMB_LIN_ACC_LO },
{DFConstantsAndEnums.ModuleType.EmbeddedLinearAccelHighG, HardwareTypes.EMB_LIN_ACC_HI },
{DFConstantsAndEnums.ModuleType.EmbeddedAngularAccel, HardwareTypes.EMB_ANG_ACC },
{DFConstantsAndEnums.ModuleType.EmbeddedAngularRate, HardwareTypes.EMB_ANG_ARS },
{DFConstantsAndEnums.ModuleType.EmbeddedAtmospheric, HardwareTypes.EMB_ATM },
{DFConstantsAndEnums.ModuleType.EmbeddedOptical, HardwareTypes.EMB_OPT },
{DFConstantsAndEnums.ModuleType.EmbeddedMagnetometer, HardwareTypes.EMB_MAG },
{DFConstantsAndEnums.ModuleType.EmbeddedMagnetInput, HardwareTypes.EMB_MAG_SWITCH },
{DFConstantsAndEnums.ModuleType.EmbeddedMicrophone, HardwareTypes.EMB_MIC },
{DFConstantsAndEnums.ModuleType.EmbeddedClockSecondsAndMarker, HardwareTypes.EMB_RTC_S_MARK },
{DFConstantsAndEnums.ModuleType.EmbeddedClockNanosAndPad, HardwareTypes.EMB_RTC_NS_PAD }
};
public DASHardware(InfoResult.Module module, IDASCommunication das)
{
_bSelected = true;
_hardware.CalDate = module.CalibrationDate ?? DASDBRecord.INVALID_DATE;
_hardware.IPAddress = $"{das.SerialNumber}xUSB";
_hardware.IsModule = true;
_hardware.FirmwareVersion = module.FirmwareVersion;
_hardware.SerialNumber = module.SerialNumber;
if (_moduleTypeToHWType.ContainsKey(module.TypeOfModule))
{
_hardware.DASTypeEnum = _moduleTypeToHWType[module.TypeOfModule];
}
else
{
_hardware.DASTypeEnum = HardwareTypes.SLICE_Bridge;
}
_hardware.Channels = 0;
_hardware.ChannelTypes = new int[0];
_hardware.ISOChannels = new DTS.Common.ISO.HardwareChannel[0];
_hardware.IsProgrammable = false;
_hardware.IsReconfigurable = false;
_hardware.LastModified = DateTime.Now;
_hardware.LastModifiedBy = ApplicationProperties.CurrentUser.UserName;
_hardware.LastUsed = DateTime.Now;
_hardware.LastUsedBy = ApplicationProperties.CurrentUser.UserName;
_hardware.LocalOnly = false;
_hardware.MaxMemory = 0;
_hardware.MaxModules = 0;
_hardware.MaxSampleRate = 0;
_hardware.MinSampleRate = 0;
_hardware.MaxAAFRate = 0;
_hardware.Position = $"{das.SerialNumber}_{module.ModuleArrayIndex}";
_hardware.ProtocolVersion = 0;
_hardware.Version = 1;
}
private static readonly HashSet<HardwareTypes> _dontCareAboutModules = new HashSet<HardwareTypes>
{
HardwareTypes.G5INDUMMY,
HardwareTypes.G5VDS,
HardwareTypes.SLICE1_G5Stack,
HardwareTypes.SLICE2_SIM,
HardwareTypes.SLICE2_SLS,
HardwareTypes.SLICE2_DIM,
HardwareTypes.SLICE2_SLD,
HardwareTypes.SLICE2_TOM,
HardwareTypes.SLICE2_SLT,
HardwareTypes.SLICE_Distributor,
HardwareTypes.SLICE_EthernetController,
HardwareTypes.SLICE_Mini_Distributor,
HardwareTypes.SLICE_Pro_Distributor,
HardwareTypes.SLICE6DB,
HardwareTypes.SLICE6DB3,
HardwareTypes.SLICE6DB_InDummy,
HardwareTypes.SLICE_LabEthernet,
HardwareTypes.SLICE6_Base,
HardwareTypes.SLICE6_AIR,
HardwareTypes.SLICE6_AIR_BR,
HardwareTypes.S6A_EthernetRecorder,
HardwareTypes.PowerPro
};
public bool CareAboutModules
{
get
{
if (_hardware.StandIn) { return false; }
if (_dontCareAboutModules.Contains(GetHardwareTypeEnum()))
{
return false;
}
return true;
}
}
/// <summary>
/// returns a software frequency which is probably appropriate for a given sample rate using
/// 10000/1065 as the ratio and then truncated down to nearest 10hz
/// </summary>
/// <param name="dasRate"></param>
/// <returns></returns>
public static double GetSuitableSWFrequencyForSampleRate(double dasRate)
{
if (double.IsNaN(dasRate)) { return 0; }
//http://manuscript.dts.local/f/cases/43027/Incorrect-Y-Axis-Scale-in-View-Data-for-Low-Sampling-Rate
//per 43027 use 6.06 (10k/1065) as the default software filter rate rounded down to nearest 10hz
var rate = 10 * Math.Truncate(dasRate / (6.06 * 10));
return rate;
}
public DASHardware(IDASCommunication das)
{
if (das?.DASInfo == null) { return; }
_bSelected = true;
_hardware.CalDate = das.DASInfo.CalibrationDate ?? DASDBRecord.INVALID_DATE;
_hardware.IsFirstUseValid = das.IsFirstUseDateSupported;
_hardware.FirstUseDate = das.FirstUseDate;
_hardware.IPAddress = GetConnectionString(das);
_hardware.FirmwareVersion = das.FirmwareVersion;
SerialNumber = das.SerialNumber;
var hardwareType = das.GetHardwareType();
_hardware.DASType = (int)hardwareType;
if (null == das.ConfigData) { return; }
switch (hardwareType)
{
case HardwareTypes.SLICE2_TOM:
case HardwareTypes.SLICE2_SLT:
case HardwareTypes.SLICE2_Base:
case HardwareTypes.SLICE2_DIM:
case HardwareTypes.SLICE2_SLD:
case HardwareTypes.SLICE2_SIM:
case HardwareTypes.SLICE2_SLS:
{
_channels = new List<HardwareChannel>();
var i = 0;
if (null != das.ConfigData.Modules)
{
foreach (var iDASModule in das.ConfigData.Modules)
{
var module = (DASModule)iDASModule;
foreach (var channel in module.Channels)
{
var supportedExcitation = new List<ExcitationVoltageOptions.ExcitationVoltageOption>();
var supportedBridges = new List<SensorConstants.BridgeType>();
var supportedInputModes = new List<DigitalInputModes>();
var supportedSquibFireModes = new List<SquibFireMode>();
var supportedDigitalOutputModes = new List<DigitalOutputModes>();
if (channel is AnalogInputDASChannel)
{
var alog = channel as AnalogInputDASChannel;
supportedBridges.AddRange(alog.SupportedBridges);
supportedExcitation.AddRange(alog.SupportedExcitation);
supportedInputModes.AddRange(alog.SupportedDigitalInputModes);
supportedSquibFireModes.Add(SquibFireMode.NONE);
supportedDigitalOutputModes.AddRange(new[] {
DigitalOutputModes.NONE,
DigitalOutputModes.CCNC,
DigitalOutputModes.CCNO,
DigitalOutputModes.FVHL,
DigitalOutputModes.FVLH
});
}
else if (channel is OutputSquibChannel)
{
supportedBridges.Add(SensorConstants.BridgeType.SQUIB);
supportedExcitation.Add(ExcitationVoltageOptions.ExcitationVoltageOption.Volt5);
supportedInputModes.Add(DigitalInputModes.CCNC);
supportedSquibFireModes.Add(SquibFireMode.NONE);
supportedSquibFireModes.Add(SquibFireMode.CONSTANT);
supportedSquibFireModes.Add(SquibFireMode.CAP);
supportedDigitalOutputModes.Add(DigitalOutputModes.NONE);
}
else if (channel is OutputTOMDigitalChannel)
{
supportedBridges.Add(SensorConstants.BridgeType.TOMDigital);
supportedExcitation.Add(ExcitationVoltageOptions.ExcitationVoltageOption.Volt5);
supportedInputModes.Add(DigitalInputModes.CCNC);
supportedSquibFireModes.Add(SquibFireMode.NONE);
supportedDigitalOutputModes.AddRange(new[]{
DigitalOutputModes.NONE,
DigitalOutputModes.FVLH,
DigitalOutputModes.FVHL,
DigitalOutputModes.CCNO,
DigitalOutputModes.CCNC
});
}
var displayOrder = das.ConfigData.GetDisplayOrder(Convert.ToUInt32(i));
if (null == module.OwningDAS) { module.OwningDAS = das; }
_channels.Add(
new HardwareChannel(
i,
this,
supportedBridges,
supportedExcitation,
displayOrder,
supportedInputModes,
supportedSquibFireModes,
supportedDigitalOutputModes,
module.SerialNumber(),
module.ModuleArrayIndex));
i++;
}
}
}
Channels = _channels.ToArray();
}
break;
case HardwareTypes.G5VDS:
case HardwareTypes.G5INDUMMY:
{
_channels = new List<HardwareChannel>();
var i = 0;
if (null != das.ConfigData.Modules)
{
foreach (var module in das.ConfigData.Modules)
{
foreach (var channel in module.Channels)
{
var supportedExcitation = new List<ExcitationVoltageOptions.ExcitationVoltageOption>();
var supportedBridges = new List<SensorConstants.BridgeType>();
var supportedInputModes = new List<DigitalInputModes>();
var supportedSquibFireModes = new List<SquibFireMode>();
var supportedDigitalOutputModes = new List<DigitalOutputModes>();
if (channel is AnalogInputDASChannel)
{
var alog = channel as AnalogInputDASChannel;
supportedBridges.AddRange(alog.SupportedBridges);
supportedExcitation.AddRange(alog.SupportedExcitation);
supportedInputModes.AddRange(alog.SupportedDigitalInputModes);
supportedSquibFireModes.Add(SquibFireMode.NONE);
supportedDigitalOutputModes.AddRange(new[] {
DigitalOutputModes.NONE,
DigitalOutputModes.CCNC,
DigitalOutputModes.CCNO,
DigitalOutputModes.FVHL,
DigitalOutputModes.FVLH
});
}
var displayOrder = das.ConfigData.GetDisplayOrder(Convert.ToUInt32(i));
_channels.Add(new HardwareChannel
(i,
this,
supportedBridges,
supportedExcitation,
displayOrder,
supportedInputModes,
supportedSquibFireModes,
supportedDigitalOutputModes,
module.SerialNumber(),
module.ModuleArrayIndex));
i++;
}
}
}
Channels = _channels.ToArray();
}
break;
case HardwareTypes.SLICE1_5_Nano_Base:
{
_channels = new List<HardwareChannel>();
var i = 0;
if (null != das.ConfigData.Modules)
{
foreach (var module in das.ConfigData.Modules)
{
foreach (var channel in module.Channels)
{
var supportedExcitation = new List<ExcitationVoltageOptions.ExcitationVoltageOption>();
var supportedBridges = new List<SensorConstants.BridgeType>();
var supportedInputModes = new List<DigitalInputModes>();
var supportedSquibFireModes = new List<SquibFireMode>();
var supportedDigitalOutputModes = new List<DigitalOutputModes>();
if (channel is AnalogInputDASChannel)
{
var alog = channel as AnalogInputDASChannel;
supportedBridges.AddRange(alog.SupportedBridges);
supportedExcitation.AddRange(alog.SupportedExcitation);
supportedSquibFireModes.Add(SquibFireMode.NONE);
supportedDigitalOutputModes.AddRange(new[] {
DigitalOutputModes.NONE,
DigitalOutputModes.CCNC,
DigitalOutputModes.CCNO,
DigitalOutputModes.FVHL,
DigitalOutputModes.FVLH
});
}
var displayOrder = das.ConfigData.GetDisplayOrder(Convert.ToUInt32(i));
_channels.Add(new HardwareChannel(
i,
this,
supportedBridges,
supportedExcitation,
displayOrder,
supportedInputModes,
supportedSquibFireModes,
supportedDigitalOutputModes,
module.SerialNumber(),
module.ModuleArrayIndex));
i++;
}
}
}
Channels = _channels.ToArray();
}
break;
default:
{
_channels = new List<HardwareChannel>();
var i = 0;
if (das.ConfigData?.Modules != null)
{
foreach (var module in das.ConfigData.Modules)
{
if (null == module) { continue; }
foreach (var channel in module.Channels)
{
var supportedExcitation = new List<ExcitationVoltageOptions.ExcitationVoltageOption>();
var supportedBridges = new List<SensorConstants.BridgeType>();
var supportedInputModes = new List<DigitalInputModes>();
var supportedSquibFireModes = new List<SquibFireMode>();
var supportedDigitalOutputModes = new List<DigitalOutputModes>();
if (channel is OutputSquibChannel)
{
var squib = channel as OutputSquibChannel;
supportedBridges.AddRange(new[] { SensorConstants.BridgeType.SQUIB });
supportedExcitation.AddRange(new[] { ExcitationVoltageOptions.ExcitationVoltageOption.Volt5 });
supportedSquibFireModes.AddRange(squib.SupportedSquibFireModes);
}
else if (channel is OutputTOMDigitalChannel)
{
supportedExcitation.Add(ExcitationVoltageOptions.ExcitationVoltageOption.Volt5);
supportedBridges.Add(SensorConstants.BridgeType.TOMDigital);
supportedDigitalOutputModes.AddRange(new[] {
DigitalOutputModes.NONE,
DigitalOutputModes.CCNC,
DigitalOutputModes.CCNO,
DigitalOutputModes.FVHL,
DigitalOutputModes.FVLH
});
}
else if (channel is UARTInputDASChannel)
{
supportedBridges.Add(SensorConstants.BridgeType.UART);
supportedExcitation.Add(ExcitationVoltageOptions.ExcitationVoltageOption.Undefined);
supportedSquibFireModes.Add(SquibFireMode.NONE);
supportedDigitalOutputModes.Add(DigitalOutputModes.NONE);
}
else if (channel is StreamOutputDASChannel)
{
//30429 Invalidate/fail sooner than Arm step if DAS doesn't have streaming capability/channel (TSR AIR may or may not)
if (das.IsStreamingSupported)
{
supportedBridges.Add(SensorConstants.BridgeType.StreamOut);
supportedExcitation.Add(ExcitationVoltageOptions.ExcitationVoltageOption.Undefined);
supportedSquibFireModes.Add(SquibFireMode.NONE);
supportedDigitalOutputModes.Add(DigitalOutputModes.NONE);
}
else
{
continue;
}
}
else if (channel is StreamInputDASChannel)
{
supportedBridges.Add(SensorConstants.BridgeType.StreamIn);
supportedExcitation.Add(ExcitationVoltageOptions.ExcitationVoltageOption.Undefined);
supportedSquibFireModes.Add(SquibFireMode.NONE);
supportedDigitalOutputModes.Add(DigitalOutputModes.NONE);
}
else if (channel is TimestampDASChannel)
{
supportedBridges.Add(SensorConstants.BridgeType.RTC);
supportedExcitation.Add(ExcitationVoltageOptions.ExcitationVoltageOption.Undefined);
supportedSquibFireModes.Add(SquibFireMode.NONE);
supportedDigitalOutputModes.Add(DigitalOutputModes.NONE);
}
else if (channel is AnalogInputDASChannel)
{
var alog = channel as AnalogInputDASChannel;
supportedBridges.AddRange(alog.SupportedBridges);
supportedExcitation.AddRange(alog.SupportedExcitation);
supportedInputModes.AddRange(alog.SupportedDigitalInputModes);
}
var displayOrder = das.ConfigData.GetDisplayOrder(Convert.ToUInt32(i));
_channels.Add(new HardwareChannel(
i,
this,
supportedBridges,
supportedExcitation,
displayOrder,
supportedInputModes,
supportedSquibFireModes,
supportedDigitalOutputModes,
module.SerialNumber(),
module.ModuleArrayIndex));
i++;
}
}
}
Channels = _channels.ToArray();
}
break;
}
_hardware.Channels = Channels.Length;
var channelTypes = new List<int>();
if (das.ConfigData?.Modules != null)
{
foreach (var m in das.ConfigData.Modules)
{
if (null == m) { continue; }
foreach (var c in m.Channels)
{
switch (c)
{
case OutputSquibChannel _:
channelTypes.Add((int)Hardware.ChannelType.Squib);
break;
case OutputTOMDigitalChannel _:
channelTypes.Add((int)Hardware.ChannelType.DigitalOutput);
break;
case TimestampDASChannel _:
channelTypes.Add((int)Hardware.ChannelType.RTC);
break;
case UARTInputDASChannel _:
channelTypes.Add((int)Hardware.ChannelType.UART);
break;
case StreamOutputDASChannel _:
//30429 Invalidate/fail sooner than Arm step if DAS doesn't have streaming capability/channel (TSR AIR may or may not)
if (das.IsStreamingSupported)
{
channelTypes.Add((int)Hardware.ChannelType.StreamOutput);
}
break;
case StreamInputDASChannel _:
channelTypes.Add((int)Hardware.ChannelType.StreamInput);
break;
case AnalogInputDASChannel _:
if (((AnalogInputDASChannel)c).IEPEChannel)
{
channelTypes.Add((int)Hardware.ChannelType.IEPE);
}
else
{
channelTypes.Add((int)Hardware.ChannelType.Analog);
}
break;
}
}
}
}
_hardware.ChannelTypes = channelTypes.ToArray();
if (das is IDASReconfigure) { Reconfigurable = true; }
else { Reconfigurable = false; }
if (das.DASInfo.Modules.Length > 0 && das.DASInfo.Modules[0].IsProgrammable) { Reprogrammable = true; }
else { Reprogrammable = false; }
_hardware.MaxMemory = das.MaxMemory();
_hardware.MaxModules = GetMaxModules(GetHardwareTypeInt(), das);
_hardware.MaxSampleRate = Convert.ToDouble(das.MaxSampleRate(0));
_hardware.MinSampleRate = Convert.ToDouble(das.MinSampleRate());
_hardware.MaxAAFRate = Convert.ToDouble(das.MaxAAFilterRate());
try
{
_hardware.ProtocolVersion = ((ICommunication)das).ProtocolVersion;
}
catch (Exception ex) { APILogger.Log(ex); }
}
public DASHardware(DASHardware copy, DASHardware parentDAS)
{
if (null != copy.Channels)
{
Channels = copy.Channels.Select(ch => new HardwareChannel(ch)).ToArray();
}
_hardware = new Hardware(copy.GetHardware());
}
private static readonly HashSet<HardwareTypes> _dasWithNoBattery = new HashSet<HardwareTypes>
{
HardwareTypes.DIM,
HardwareTypes.G5INDUMMY,
HardwareTypes.G5VDS,
HardwareTypes.Ribeye,
HardwareTypes.RibeyeLED,
HardwareTypes.SLICE_Distributor,
HardwareTypes.SLICE_Mini_Distributor,
HardwareTypes.SLICE2_SLT,
HardwareTypes.SLICE2_SLD,
//apparently the rack also doesn't return battery?
HardwareTypes.TDAS_Pro_Rack,
HardwareTypes.TDAS_LabRack,
HardwareTypes.SLICE2_SLS,
HardwareTypes.SLICE_LabEthernet,
HardwareTypes.SLICE1_G5Stack,
HardwareTypes.SLICE6_Base,
HardwareTypes.SLICE6_AIR,
HardwareTypes.SLICE6_AIR_BR
};
public bool CanHaveBattery()
{
return !_dasWithNoBattery.Contains(GetHardwareTypeEnum());
}
private static readonly Dictionary<HardwareTypes, int> _maxModulesPerType = new Dictionary<HardwareTypes, int>
{
{ HardwareTypes.DIM,8 },
{ HardwareTypes.SLICE1_G5Stack,6 },
{ HardwareTypes.G5VDS, 4 },
{ HardwareTypes.G5INDUMMY,4 },
{ HardwareTypes.Ribeye,8 },
{ HardwareTypes.RibeyeLED,3 },
{ HardwareTypes.SIM,8 },
{ HardwareTypes.SLICE_Base, 8 },
{ HardwareTypes.SLICE_Micro_Base, 8 },
{ HardwareTypes.SLICE_NANO_Base, 8 },
{ HardwareTypes.SLICE_Bridge, 3 },
{ HardwareTypes.SLICE_Distributor, 0 },
{ HardwareTypes.SLICE6DB, 0 },
{ HardwareTypes.SLICE6DB3, 0 },
{ HardwareTypes.SLICE_Pro_Distributor, 0 },
{ HardwareTypes.SLICE6DB_InDummy, 0 },
{ HardwareTypes.SLICE_EthernetController, 0 },
{ HardwareTypes.SLICE_Mini_Distributor, 0 },
{ HardwareTypes.SLICE_LabEthernet, 0 },
{ HardwareTypes.SLICE2_Base, 8 },
{ HardwareTypes.SLICE2_SIM, 8 },
{ HardwareTypes.SLICE2_SLS, 8 },
{ HardwareTypes.SLICE2_DIM, 8 },
{ HardwareTypes.SLICE2_SLD, 8 },
{ HardwareTypes.SLICE2_TOM, 8 },
{ HardwareTypes.SLICE2_SLT, 8 },
{ HardwareTypes.TDAS_LabRack, 6 },
{ HardwareTypes.TOM, 4 },
{ HardwareTypes.SLICE1_5_Nano_Base, 8 },
{ HardwareTypes.SLICE1_5_Micro_Base, 8 },
{ HardwareTypes.S6A_EthernetRecorder, 1 },
{ HardwareTypes.TSR_AIR, 5 },
{ HardwareTypes.TSR_AIR_RevB, 12 },
{ HardwareTypes.DKR, 2 },
{ HardwareTypes.DIR, 4 }
};
private static int GetMaxModules(int type, IDASCommunication das)
{
var hwType = (HardwareTypes)type;
if (_maxModulesPerType.ContainsKey(hwType)) { return _maxModulesPerType[hwType]; }
if (hwType == HardwareTypes.TDAS_Pro_Rack) { return das.MaxModules; }
return 0;
}
public static string GenerateChannelsString(int analogChannels, int digitalInputChannels, int squibChannels, int digitalOutputChannels, int uartChannels, int streamOutputChannels)
{
var sb = new StringBuilder();
if (analogChannels > 0)
{
sb.AppendFormat("{0}{1}", analogChannels, StringResources.AutoDetectDas_Analog);
}
if (digitalInputChannels > 0)
{
if (sb.Length > 0) { sb.Append(CultureInfo.CurrentCulture.TextInfo.ListSeparator + " "); }
sb.AppendFormat("{0}{1}", digitalInputChannels, StringResources.AutodetectDas_DigitalInput);
}
if (squibChannels > 0)
{
if (sb.Length > 0) { sb.Append(CultureInfo.CurrentCulture.TextInfo.ListSeparator + " "); }
sb.AppendFormat("{0}{1}", squibChannels, StringResources.AutoDetectDas_Squib);
}
if (digitalOutputChannels > 0)
{
if (sb.Length > 0) { sb.Append(CultureInfo.CurrentCulture.TextInfo.ListSeparator + " "); }
sb.AppendFormat("{0}{1}", digitalOutputChannels, StringResources.AutoDetectDas_DigitalOut);
}
if (uartChannels > 0)
{
if (sb.Length > 0) { sb.Append(CultureInfo.CurrentCulture.TextInfo.ListSeparator + " "); }
sb.AppendFormat("{0}{1}", uartChannels, StringResources.AutoDetectDas_UART);
}
if (streamOutputChannels > 0)
{
if (sb.Length > 0) { sb.Append(CultureInfo.CurrentCulture.TextInfo.ListSeparator + " "); }
sb.AppendFormat("{0}{1}", streamOutputChannels, StringResources.AutoDetectDas_StreamOut);
}
if (sb.Length > 0)
{
sb.AppendFormat(" {0}", StringResources.AutoDetectDAS_Channels);
}
else
{
sb.Append(StringResources.AutoDetectDAS_NoChannelsFound); // http://fogbugz/fogbugz/default.asp?6999
}
return sb.ToString();
}
public static string GetChannelsString(DASHardware das)
{
if (das.IsModule() && !das.IsPseudoRackModule())
{
return StringResources.Table_NA;
}
var analogChannels = 0;
var digitalInputChannels = 0;
var squibChannels = 0;
var digitalOutputChannels = 0;
var uartChannels = 0;
var streamOutputChannels = 0;
switch (das.GetHardwareTypeEnum())
{
case HardwareTypes.S6A_EthernetRecorder:
return StringResources.Slice6EthernetRecorder;
case HardwareTypes.SLICE6_AIR:
analogChannels += 6;
uartChannels = 1;
streamOutputChannels = 1;
break;
case HardwareTypes.SLICE6_AIR_BR:
case HardwareTypes.SLICE6_Base:
analogChannels += 6;
streamOutputChannels = 1;
break;
case HardwareTypes.SLICE1_G5Stack:
analogChannels += 18;
break;
case HardwareTypes.G5INDUMMY:
analogChannels += 32;
break;
case HardwareTypes.G5VDS:
analogChannels += 32;
digitalInputChannels += 16;
break;
case HardwareTypes.SIM:
case HardwareTypes.SLICE2_Base:
case HardwareTypes.SLICE2_SIM:
case HardwareTypes.SLICE2_SLS:
analogChannels += das.ChannelCount;
break;
case HardwareTypes.SLICE2_TOM:
case HardwareTypes.SLICE2_SLT:
digitalOutputChannels += 8;
squibChannels += 4;
break;
case HardwareTypes.SLICE2_DIM:
case HardwareTypes.SLICE2_SLD:
digitalInputChannels += das.ChannelCount;
break;
case HardwareTypes.SLICE1_5_Micro_Base:
case HardwareTypes.SLICE1_5_Nano_Base:
case HardwareTypes.SLICE_NANO_Base:
case HardwareTypes.SLICE_Micro_Base:
case HardwareTypes.SLICE_Base:
analogChannels += das.ChannelCount;
break;
case HardwareTypes.TDAS_Pro_Rack:
case HardwareTypes.TDAS_LabRack:
for (var i = 0; i < das.Channels.Length; i++)
{
if (das.Channels[i].IsSupportedBridgeType(SensorConstants.BridgeType.SQUIB))
{
//TOM
squibChannels += 4;
digitalOutputChannels += 8;
i += 15; //the ++ will advance it past the 16th channel
}
else if (
das.Channels[i].IsSupportedBridgeType(SensorConstants.BridgeType.DigitalInput))
{
digitalInputChannels += 16;
i += 15;
}
else
{
analogChannels += 8;
i += 7; //the ++ will advance it past the 8th channel
//for now it better be a SIM as we don't support DIM
}
}
break;
case HardwareTypes.SLICE_Distributor:
{
return StringResources.AutoDetectDas_SliceDB;
}
case HardwareTypes.SLICE_Mini_Distributor:
{
return StringResources.AutoDetectDas_SliceMiniDB;
}
case HardwareTypes.SLICE_Pro_Distributor:
{
if (null == das.LinkedDASSerials || 0 == das.LinkedDASSerials.Length)
{
return StringResources.SLICEPRODB;
}
foreach (var serial in das.LinkedDASSerials)
{
if (serial.StartsWith("SLS") || serial.StartsWith("SPS"))
{
analogChannels += 18;
}
else if (serial.StartsWith("SLD") || serial.StartsWith("SPD"))
{
digitalInputChannels += 18;
}
else if (serial.StartsWith("SLT") || serial.StartsWith("SPT"))
{
squibChannels += 4;
digitalOutputChannels += 8;
}
}
}
break;
case HardwareTypes.SLICE_LabEthernet:
case HardwareTypes.SLICE_EthernetController:
{
if (null == das.LinkedDASSerials || 0 == das.LinkedDASSerials.Length)
{
return StringResources.AutoDetectDAS_SLICE_EthernetController;
}
foreach (var serial in das.LinkedDASSerials)
{
if (serial.StartsWith("SLS") || serial.StartsWith("SPS"))
{
analogChannels += 18;
}
else if (serial.StartsWith("SLD") || serial.StartsWith("SPD"))
{
digitalInputChannels += 18;
}
else if (serial.StartsWith("SLT") || serial.StartsWith("SPT"))
{
squibChannels += 4;
digitalOutputChannels += 8;
}
}
}
break;
case HardwareTypes.SLICE6DB:
case HardwareTypes.SLICE6DB3:
case HardwareTypes.SLICE6DB_InDummy:
{
//find all DAS connected to this SLICE6DB and add their channels
if (null != das.LinkedDASSerials)
{
analogChannels = das.LinkedDASSerials.Length * 6;
}
}
break;
case HardwareTypes.PowerPro:
{
return StringResources.AutoDetectDas_PowerPro;
}
case HardwareTypes.TSR_AIR:
case HardwareTypes.TSR_AIR_RevB:
uartChannels = 1;
var outputString = $"{StringResources.AutoDetectDas_EmbeddedSensors}, {uartChannels}{StringResources.AutoDetectDas_UART}";
for (var i = 0; i < das.Channels.Length; i++)
{
if (das.Channels[i].IsSupportedBridgeType(SensorConstants.BridgeType.StreamOut))
{
streamOutputChannels = 1;
outputString += $", {streamOutputChannels}{StringResources.AutoDetectDas_StreamOut}";
}
}
return outputString + $" {StringResources.AutoDetectDAS_Channels}";
case HardwareTypes.DKR:
case HardwareTypes.DIR:
{
return StringResources.AutoDetectDas_EmbeddedSensors;
}
case HardwareTypes.SLICE6_AIR_TC:
analogChannels = das.Channels.Length - 1; //Subtract the Stream Out channel
streamOutputChannels = 1;
break;
}
return GenerateChannelsString(analogChannels, digitalInputChannels, squibChannels, digitalOutputChannels, uartChannels, streamOutputChannels);
}
public string[] LinkedDASSerials { get; set; }
public static string GetChannelsString(IDASCommunication idas)
{
switch (idas.GetHardwareType())
{
case HardwareTypes.SLICE2_Base:
case HardwareTypes.SLICE2_SIM:
case HardwareTypes.SLICE2_SLD:
case HardwareTypes.SLICE2_SLS:
case HardwareTypes.SLICE2_DIM:
case HardwareTypes.SLICE2_TOM:
case HardwareTypes.SLICE2_SLT:
case HardwareTypes.SLICE1_G5Stack:
case HardwareTypes.SLICE_Base:
case HardwareTypes.SLICE_Micro_Base:
case HardwareTypes.SLICE_NANO_Base:
case HardwareTypes.SLICE1_5_Nano_Base:
case HardwareTypes.SLICE1_5_Micro_Base:
case HardwareTypes.G5VDS:
case HardwareTypes.G5INDUMMY:
case HardwareTypes.TDAS_Pro_Rack:
case HardwareTypes.TDAS_LabRack:
{
var analog = 0;
var squib = 0;
var digitalout = 0;
var iepe = 0;
var dim = 0;
var programable = 0;
if ((null != idas.ConfigData) &&
(null != idas.ConfigData.Modules) &&
(0 < idas.DASInfo.Modules.Length))
{
foreach (var m in idas.ConfigData.Modules)
{
foreach (var c in m.Channels)
{
if (c is OutputSquibChannel)
{
squib++;
}
else if (c is OutputTOMDigitalChannel)
{
digitalout++;
}
else if (c is AnalogInputDASChannel)
{
if (idas.DASInfo.Modules[m.ModuleArrayIndex].IsProgrammable)
{
programable++;
}
else
{
if ((c as AnalogInputDASChannel).IEPEChannel)
{
iepe++;
}
else if ((c as AnalogInputDASChannel).DigitalInputChannel)
{
dim++;
}
else
{
analog++;
}
}
}
}
}
var sb = new StringBuilder();
if (null == idas.DASInfo && (0 < idas.DASInfo.Modules.Length)
&& idas.DASInfo.Modules[0].IsProgrammable)
{
sb.Append(StringResources.AutoDetectDAS_Programable);
}
var bNeedComma = false;
if (analog > 0)
{
bNeedComma = true;
sb.Append(analog.ToString());
sb.Append(StringResources.AutoDetectDas_Analog);
}
if (iepe > 0)
{
if (bNeedComma) { sb.Append(", "); } else { bNeedComma = true; }
sb.Append(iepe.ToString());
sb.Append(StringResources.AutoDetectDas_IEPE);
}
if (dim > 0)
{
if (bNeedComma) { sb.Append(", "); } else { bNeedComma = true; }
sb.Append(dim.ToString());
sb.Append(StringResources.AutoDetectDas_DIM);
}
if (squib > 0)
{
if (bNeedComma) { sb.Append(", "); } else { bNeedComma = true; }
sb.Append((squib / 2).ToString());
sb.Append(StringResources.AutoDetectDas_Squib);
}
if (digitalout > 0)
{
if (bNeedComma) { sb.Append(", "); } else { bNeedComma = true; }
sb.Append(digitalout.ToString());
sb.Append(StringResources.AutoDetectDas_DigitalOut);
}
if (programable > 0)
{
if (bNeedComma) { sb.Append(", "); }
sb.Append(programable.ToString());
sb.Append(StringResources.AutoDetectDas_IEPEAndAnalogProgrammable);
}
sb.Append(" ");
sb.Append(StringResources.AutoDetectDAS_Channels);
return sb.ToString();
}
if (null == idas.ConfigData) { APILogger.Log("null ConfigData :" + idas.SerialNumber); }
else if (null == idas.ConfigData.Modules || idas.ConfigData.Modules.Length == 0)
{
APILogger.Log("empty modules! " + idas.SerialNumber);
}
return $"0 {StringResources.AutoDetectDAS_Channels}";
}
case HardwareTypes.SLICE_Distributor: return StringResources.AutoDetectDas_SliceDB;
case HardwareTypes.SLICE_Mini_Distributor: return StringResources.AutoDetectDas_SliceMiniDB;
case HardwareTypes.SLICE_EthernetController: return StringResources.AutoDetectDAS_SLICE_EthernetController;
case HardwareTypes.SLICE_LabEthernet: return StringResources.SLICEPROLAB_Ethernet;
case HardwareTypes.SLICE6DB: return StringResources.SLICE6DB;
case HardwareTypes.SLICE6DB_InDummy: return StringResources.SLICE6DB_InDummy;
case HardwareTypes.SLICE6DB3: return StringResources.SLICE6DB3;
case HardwareTypes.SLICE_Pro_Distributor: return StringResources.SLICEPRODB;
case HardwareTypes.TSR_AIR:
case HardwareTypes.TSR_AIR_RevB: return StringResources.TSR_AIR;
case HardwareTypes.DKR: return StringResources.AutoDetectDas_DKR;
case HardwareTypes.DIR: return StringResources.AutoDetectDas_DIR;
default: throw new NotSupportedException("unsupported das type: " + idas.GetHardwareType());
}
}
private static readonly string[] AVAILABLE_SLICE2_CONFIGURATIONS = {
StringResources.HardwareDiscoveryControl_MegaSampleConfig,
StringResources.HardwareDiscoveryControl_800kSampleConfig,
StringResources.HardwareDiscoveryControl_700kSampleConfig,
StringResources.HardwareDiscoveryControl_600kSampleConfig
};
/// <summary>
/// all available configurations for TSR AIR
/// http://manuscript.dts.local/f/cases/37929/Implement-TSRAIR-module-on-off-selection-via-Max-Slice-Enable-system-attribute
/// </summary>
private static readonly string[] AVAILABLE_TSRAIR_CONFIGURATIONS =
{
StringResources.HardwareDiscoveryControl_TSRAIRConfigLowG,
StringResources.HardwareDiscoveryControl_TSRAIRConfigLowGHighG,
StringResources.HardwareDiscoveryControl_TSRAIRConfigLowGHighGARS,
StringResources.HardwareDiscoveryControl_TSRAIRConfigAll
};
/// <summary>
/// All available configurations for SLICE6AIRTC
/// </summary>
private static readonly string[] AVAILABLE_SLICE6AIRTC_CONFIGURATIONS = {
StringResources.HardwareDiscoveryControl_SLICE6AIRTC_EightChannel_Config,
StringResources.HardwareDiscoveryControl_SLICE6AIRTC_SixteenChannel_Config,
StringResources.HardwareDiscoveryControl_SLICE6AIRTC_TwentyFourChannel_Config
};
public static string GetSelectedConfiguration(HardwareTypes hardwareType, int moduleLength)
{
switch (hardwareType)
{
case HardwareTypes.SLICE2_SIM:
case HardwareTypes.SLICE2_SLS:
{
switch (moduleLength)
{
case 3:
return AVAILABLE_SLICE2_CONFIGURATIONS[0];
case 4:
return AVAILABLE_SLICE2_CONFIGURATIONS[1];
case 5:
return AVAILABLE_SLICE2_CONFIGURATIONS[2];
default:
return AVAILABLE_SLICE2_CONFIGURATIONS[3];
}
}
case HardwareTypes.TSR_AIR:
case HardwareTypes.TSR_AIR_RevB:
return GetSelectedConfigurationTSRAIR(moduleLength);
case HardwareTypes.SLICE6_AIR_TC:
{
switch (moduleLength)
{
case 1:
return AVAILABLE_SLICE6AIRTC_CONFIGURATIONS[0];
case 2:
return AVAILABLE_SLICE6AIRTC_CONFIGURATIONS[1];
default:
return AVAILABLE_SLICE6AIRTC_CONFIGURATIONS[2];
}
}
default: return "MAX";
}
}
public static string GetSelectedConfiguration(IDASCommunication das)
{
if (null == das.DASInfo)
{
return "MAX";
}
return GetSelectedConfiguration(das.GetHardwareType(), das.DASInfo.Modules.Length);
}
/// <summary>
/// returns a string for the selected configuration for a TSR AIR based on the module length
/// module length here considers UART and STREAM modules
/// number is a count, not an index
/// </summary>
private static string GetSelectedConfigurationTSRAIR(int moduleLength)
{
//assume we ALWAYS have Steamout and UART moduels?
switch(moduleLength)
{
case 3: return AVAILABLE_TSRAIR_CONFIGURATIONS[0];
case 4: return AVAILABLE_TSRAIR_CONFIGURATIONS[1];
case 5: return AVAILABLE_TSRAIR_CONFIGURATIONS[2];
default: return AVAILABLE_TSRAIR_CONFIGURATIONS[3];
}
}
private static string [] GetAvailableConfigurations(HardwareTypes hardwareType)
{
switch (hardwareType)
{
case HardwareTypes.SLICE2_SIM:
case HardwareTypes.SLICE2_SLS:
return AVAILABLE_SLICE2_CONFIGURATIONS;
case HardwareTypes.TSR_AIR:
case HardwareTypes.TSR_AIR_RevB:
return AVAILABLE_TSRAIR_CONFIGURATIONS;
case HardwareTypes.SLICE6_AIR_TC:
return AVAILABLE_SLICE6AIRTC_CONFIGURATIONS;
default: return new[] { "MAX" };
}
}
public static string [] GetAvailableConfigurations(DASHardware h)
{
return GetAvailableConfigurations(h.GetHardwareTypeEnum());
}
public static string[] GetAvailableConfigurations(IDASCommunication das)
{
return GetAvailableConfigurations(das.GetHardwareType());
}
private Hardware _hardware = new Hardware();
public Hardware GetHardware() { return _hardware; }
public void SetHardware(Hardware h)
{
_hardware = h;
var channels = new List<HardwareChannel>();
foreach (var channel in h.ISOChannels)
{
channels.Add(new HardwareChannel(channel, this));
}
Channels = channels.ToArray();
}
/// <summary>
/// note that if you use this constructor, you should set
/// TimeStampDb explicitly
/// </summary>
/// <param name="hardware"></param>
public DASHardware(Hardware hardware)
{
_hardware = new Hardware(hardware);
Channels = hardware.ISOChannels.Select(channel => new HardwareChannel(channel, this)).ToArray();
}
/// <summary>
/// returns a channel using Module Number, ChannelNumber, like how TDC TSF handles
/// counting channels
/// note TDC starts with 1, not 0, so the numbers are not indices
/// </summary>
/// <param name="moduleNumber"></param>
/// <param name="channelNumber"></param>
/// <returns></returns>
public HardwareChannel GetChannel(int moduleNumber, int channelNumber)
{
var moduleChannelNumber = 0;
var moduleIndex = moduleNumber - 1;
//14291 Unable to read EIDs in quick checkout using TDAS G5
//this function appears to have multiple entry points, primarily
//import (TTS) and quick checkout
//however while presumably it's working in the other entry points, it's not working in
//14291 (quick checkout)
//this is because the channels all have the modulearray index properly set
//while atleast one of the other entry points appear to be expecting a flat 1-32 channel with modulearray index=0
//so I'm preserving the existing logic but adding additional logic to handle the expectations of quick sensor check ...
var dasChannelIndex = 0;
var isG5 = IsG5(); //this is a function, so lets just cache the value and not make multiple calls
if (isG5)
{
channelNumber = moduleIndex * 8 + channelNumber;
moduleIndex = 0;
}
foreach (var ch in Channels)
{
dasChannelIndex++;
if (isG5 && channelNumber == dasChannelIndex) { return ch; } //see note on 14291 above
if (ch.ModuleArrayIndex == moduleIndex)
{
moduleChannelNumber++;
if (moduleChannelNumber == channelNumber) { return ch; }
}
else if (ch.ModuleArrayIndex > moduleIndex &&
(!isG5 || (isG5 && dasChannelIndex > channelNumber))) //if we are a g5 we have to go further because of issue 14291
{ break; }
}
return null;
}
public bool IsDummy()
{
return SerialNumber.Contains("Dummy");
}
/// <summary>
/// returns true if DAS is a stand-in DAS
/// </summary>
public bool IsStandIn()
{
return GetHardware().StandIn;
}
private static string GetEnumDescription(Enum value)
{
var fi = value.GetType().GetField(value.ToString());
DescriptionAttribute[] attributes =
(DescriptionAttribute[])fi.GetCustomAttributes
(typeof(DescriptionAttribute), false);
if (attributes.Length > 0)
{
var s = DTS.Common.Strings.Strings.ResourceManager.GetString(attributes[0].Description);
if (!string.IsNullOrWhiteSpace(s)) { return s; }
return attributes[0].Description;
}
return value.ToString();
}
public override string ToString()
{
if (_hardware.StandIn)
{
return GetEnumDescription(_hardware.DASTypeEnum);
}
return IsModule() && IsPseudoRackModule() ? $"{ParentDAS}:{SerialNumber}" : SerialNumber;
}
public Visibility ExpandedVisibility => Visibility.Visible;
public void ClearDiagnostics()
{
foreach (var c in Channels)
{
c.DiagnosticStatus = DiagnosticStatus.Untested;
c._diagnostics = null;
}
}
public IHardwareChannel[] GetIHardwareChannels()
{
var channels = Channels;
var list = new List<IHardwareChannel>(channels.Length);
list.AddRange(channels);
return list.ToArray();
}
public string SerialNumberFamily { get; set; }
public string EIDFound { get; set; }
public string BatteryVoltageStatus { get; set; }
public SolidColorBrush BatteryVoltageColor { get; set; }
public string InputVoltageStatus { get; set; }
public SolidColorBrush InputVoltageColor { get; set; }
/// <summary>
/// marks all das as unconfigured and no diagnostics run
/// </summary>
/// <param name="ldas"></param>
public static void MarkAllDASUnclean(List<IDASCommunication> ldas)
{
foreach (var das in ldas)
{
das.DiagnosticsHasBeenRun = false;
das.ConfigureHasBeenRun = false;
}
}
public static HardwareStatus CheckDASStates(List<IDASCommunication> dasList, int checkForDataTimeout,
StatusHelpers.SetProgressValueDelegate setProgressFunction)
{
lock (GetArmStatusLock)
{
try
{
if (dasList.Count > 0)
{
if (AnyArmed(dasList))
{
foreach (var das in dasList)
{
//18019 it's armed, so we can infer it went through diagnostics already
//mark as such before sending along to Arm step
das.DiagnosticsHasBeenRun = true;
}
return HardwareStatus.Armed;
}
else if (AnyInFlashWrite(dasList))
{
return HardwareStatus.ClearingFlash;
}
else if (!DataAvailableForDownload(dasList, checkForDataTimeout, setProgressFunction))
{
return HardwareStatus.NoDataToDownload;
}
else if (DataNeverDownloaded(dasList))
{
return HardwareStatus.DataNeverDownloaded;
}
else
{
return HardwareStatus.ReadyForDownload;
}
}
else
{
return HardwareStatus.NoDASConnected;
}
}
catch (Exception ex)
{
APILogger.Log(ex);
return HardwareStatus.NotOK;
}
}
}
public enum HardwareStatus
{
Armed, //OG from CheckHardware
CheckingForData,
ClearingFlash,
DataNeverDownloaded,
Detached,
Error,
Faulted,
GettingEventInfo,
NoDataCollected,
NoDataCollectedNoneTriggered,
NoDataCollectedSomeTriggered,
NoDataToDownload,
NoDASConnected,
NotOK, //OG from CheckHardware
OK, //OG from CheckHardware
PostTestProcessing,
ReadyForDownload,
ReadyForDownloadFaulted,
ReadyForDownloadSomeTriggered,
Rearming,
Recording,
WaitingForInterval,
WaitingForSchedule, //Scheduled but not yet recording
WaitingForTrigger,
Streaming, //Can't arm for Streaming in TSR AIR Go, but maybe it was armed in DataPRO
}
public static readonly object GetArmStatusLock = new object();
public static readonly object GetEventInfoLock = new object();
public static DateTime GetScheduledStartDateTime(List<IDASCommunication> dasList)
{
var scheduledStartDateTime = DateTime.MinValue;
if ((dasList != null) && (dasList.Count > 0))
{
if (dasList[0].ConfigData == null)
{
using (var cs = new ConfigurationService())
{
var mre = new ManualResetEvent(false);
cs.GetConfiguration(dasList, false, delegate (ServiceBase.CallbackData data)
{
switch (data.Status)
{
case ServiceBase.CallbackData.CallbackStatus.AllFinished: mre.Set(); break;
}
}, dasList);
mre.WaitOne();
Thread.Sleep(10);
}
}
var tsrAirDas = dasList.Find(d => d.ConfigData.Modules[0].RecordingMode == DFConstantsAndEnums.RecordingMode.Scheduled ||
d.ConfigData.Modules[0].RecordingMode == DFConstantsAndEnums.RecordingMode.Interval);
if (tsrAirDas != null)
{
scheduledStartDateTime = tsrAirDas.ConfigData.Modules[0].ScheduledStartTime;
scheduledStartDateTime = scheduledStartDateTime.Subtract(new TimeSpan(0, 0, scheduledStartDateTime.Second));
}
}
return scheduledStartDateTime;
}
public static bool AnyArmed(List<IDASCommunication> activeDASList)
{
if (activeDASList.Count < 1) { return false; }
var bNeedToRequeryStatus = false;
foreach (var das in activeDASList)
{
if (null == das.DASArmStatus || das.DASArmStatus.IsArmed) //We may have come from Check trigger, so re-query
{
bNeedToRequeryStatus = true;
}
}
if (activeDASList.Exists(x => null == x.DASArmStatus)) { bNeedToRequeryStatus = true; }
if (bNeedToRequeryStatus)
{
lock (GetArmStatusLock)
{
var mre = new ManualResetEvent(false);
using (var armingService = new ArmingService())
{
try
{
armingService.GetArmStatus(activeDASList, delegate (ServiceBase.CallbackData cbdata)
{
switch (cbdata.Status)
{
case ServiceBase.CallbackData.CallbackStatus.Success:
break;
case ServiceBase.CallbackData.CallbackStatus.AllFinished:
mre.Set();
break;
}
}, activeDASList, 11000, MAX_ARM_STATUS_TIME);
mre.WaitOne();
}
catch
{
return false;
}
}
}
}
return activeDASList.Exists(unit => unit.DASArmStatus != null && unit.DASArmStatus.IsArmed);
}
public const int MAX_ARM_STATUS_TIME = 4000;
public static bool AnyInFlashWrite(IEnumerable<IDASCommunication> das)
{
return das.Where(idas => idas?.DASArmStatus != null).Any(idas => idas.DASArmStatus.IsInFlashWrite);
}
/// <summary>
/// returns true if any DAS in the test has a streaming mode set and is in realtime mode according
/// to QATS
/// http://manuscript.dts.local/f/cases/40534/DataPro-fail-to-disarm-device-armed-in-Stream-only-if-current-test-is-other-than-streaming-only-mode
/// </summary>
public static bool AnyDASStreaming(List<IDASCommunication> dasList)
{
try
{
foreach (var armStatus in dasList.Select(x => x.DASArmStatus).Where(y => null != y))
{
if (!armStatus.IsInRealtime) { continue; }
if (armStatus.IsArmed) { continue; }
if (RecordingModeExtensions.IsAStreamMode((DFConstantsAndEnums.RecordingMode)armStatus.RecordingMode))
{
return true;
}
}
}
catch (Exception ex)
{
APILogger.Log(ex);
}
return false;
}
public static bool AnyNotArmed(IEnumerable<IDASCommunication> dasList)
{
foreach (var armStatus in dasList.Where(x => !x.IsEthernetDistributor()).
Select(y => y.DASArmStatus).Where(z => null != z))
{
if (!armStatus.IsArmed)
{
return true;
}
}
return false;
}
public static bool AllNotArmed(IEnumerable<IDASCommunication> dasList)
{
foreach (var das in dasList)
{
if (!das.IsEthernetDistributor() && das.DASArmStatus.IsArmed && !das.DASArmStatus.IsInPostTestDiagnostics)
{
return false;
}
}
return true;
}
public static bool AllNotRecording(IEnumerable<IDASCommunication> dasList)
{
foreach (var armStatus in dasList.Select(x => x.DASArmStatus).Where(y => null != y))
{
if (armStatus.TimeRemainingSeconds > 0 && armStatus.IsRecording && !armStatus.IsInPostTestDiagnostics)
{
return false;
}
}
return true;
}
public static bool AnyNotYetRecording(List<IDASCommunication> dasList, IReadOnlyDictionary<string, bool> dasHasBeenRecording, IReadOnlyDictionary<string, bool> dasHasTriggered)
{
foreach (var das in dasList)
{
if (!das.IsEthernetDistributor()
&& das.DASArmStatus.TimeRemainingSeconds > 0
&& !das.DASArmStatus.IsRecording
&& (!dasHasTriggered.ContainsKey(das.SerialNumber) || !dasHasTriggered[das.SerialNumber])
&& !das.DASArmStatus.IsUndefined
&& !das.DASArmStatus.IsInPostTestDiagnostics
&& !das.DASArmStatus.IsInFlashWrite
&& (!dasHasBeenRecording.ContainsKey(das.SerialNumber) || !dasHasBeenRecording[das.SerialNumber])
)
{
return true;
}
}
return false;
}
/// <summary>
/// returns true if any units are done recording, false otherwise
/// </summary>
public static bool AnyDoneRecording(IEnumerable<IDASCommunication> dasList, IReadOnlyDictionary<string, bool> dasHasBeenRecording,
ApplicationStatusTypes? overallStatus = null)
{
foreach (var das in dasList)
{
//if we are "Waiting for Start With Event" done return AnyDone = true, as we aren't done yet ...
//assuming we are also armed of course, if it's not armed, then do whatever the reset of the logic says to do
//http://manuscript.dts.local/f/cases/26960/Arm-display-w-TSR-AIR-in-Start-recording-with-trigger-mode-shows-0-seconds
if (null != overallStatus && ((ApplicationStatusTypes)overallStatus == ApplicationStatusTypes.WaitingForStartWithEvent || (ApplicationStatusTypes)overallStatus == ApplicationStatusTypes.IdleWaitingForStartWithEvent) && das.DASArmStatus.IsArmed)
{
return false;
}
if (!das.IsEthernetDistributor() && dasHasBeenRecording.ContainsKey(das.SerialNumber) && dasHasBeenRecording[das.SerialNumber] && !das.DASArmStatus.IsRecording)
{
return true;
}
}
return false;
}
public static bool AnyTriggered(List<IDASCommunication> dasList, IReadOnlyDictionary<string, bool> dasHasTriggered)
{
foreach (var dasSerialNumber in dasList.Select(x => x.SerialNumber))
{
if (dasHasTriggered.ContainsKey(dasSerialNumber) && dasHasTriggered[dasSerialNumber])
{
return true;
}
}
return false;
}
public static bool AnyNotTriggered(List<IDASCommunication> dasList, IReadOnlyDictionary<string, bool> dasHasTriggered)
{
foreach (var das in dasList)
{
if (das.DASArmStatus.TimeRemainingSeconds > 0 &&
(!dasHasTriggered.ContainsKey(das.SerialNumber) || !dasHasTriggered[das.SerialNumber]))
{
return true;
}
}
return false;
}
public static bool AnyNotTriggeredAndNotRecording(List<IDASCommunication> dasList, IReadOnlyDictionary<string, bool> dasHasTriggered)
{
foreach (var das in dasList)
{
if (!das.IsEthernetDistributor() && das.DASArmStatus.TimeRemainingSeconds > 0 &&
(!dasHasTriggered.ContainsKey(das.SerialNumber) || !dasHasTriggered[das.SerialNumber]) && !das.DASArmStatus.IsRecording)
{
return true;
}
}
return false;
}
public static bool AnyRecording(IEnumerable<IDASCommunication> das)
{
return das.Where(idas => idas?.DASArmStatus != null).Any(idas => idas.DASArmStatus.IsRecording);
}
public static bool AnyEvents(List<IDASCommunication> dasList)
{
foreach (var das in dasList)
{
if ((das.DASArmStatus != null) && (das.DASArmStatus.EventNumber > 0))
{
return true;
}
}
return false;
}
private static bool DataAvailableForDownload(List<IDASCommunication> dasList, int checkForDataTimeout,
StatusHelpers.SetProgressValueDelegate setProgressFunction)
{
try
{
GetEventInfo(dasList, false, checkForDataTimeout, setProgressFunction);
}
catch (Exception ex)
{
APILogger.Log("Error getting event info", ex);
}
return GetAllEvents(dasList).Count > 0;
}
private static void GetEventInfo(List<IDASCommunication> dasList, bool bForce, int checkForDataTimeout, StatusHelpers.SetProgressValueDelegate setProgressFunction )
{
lock (GetEventInfoLock)
{
var qdList = new List<IDASCommunication>();
var queryList = new List<IDASCommunication>();
foreach (var das in dasList)
{
if (das.ConfigData == null)
{
queryList.Add(das);
setProgressFunction?.Invoke(das, 0D, DTS.Common.DataModel.Classes.TSRAIRGo.TSRAIRGoStatus.StatusTypes.QUERYING);
}
if (das.EventInfo == null || bForce)
{
qdList.Add(das);
setProgressFunction?.Invoke(das, 0D, DTS.Common.DataModel.Classes.TSRAIRGo.TSRAIRGoStatus.StatusTypes.QUERYING);
}
}
if (queryList.Count > 0)
{
var mre = new ManualResetEvent(false);
lock (GetArmStatusLock)
{
using (var cs = new ConfigurationService())
{
cs.GetConfiguration(queryList, false, delegate (ServiceBase.CallbackData data)
{
switch (data.Status)
{
case ServiceBase.CallbackData.CallbackStatus.AllFinished: mre.Set(); break;
}
}, queryList);
mre.WaitOne();
Thread.Sleep(10);
}
}
}
if (qdList.Count == 0)
{
// everyone has it
return;
}
using (var dlService = new DownloadService())
{
try
{
foreach( var das in qdList)
{
setProgressFunction?.Invoke(das, 0D, DTS.Common.DataModel.Classes.TSRAIRGo.TSRAIRGoStatus.StatusTypes.GETTINGEVENTDATA);
}
var finishedEvent = new ManualResetEvent(false);
dlService.ServiceAvailable += dlService_ServiceAvailable;
var errStr = string.Empty;
Exception excep = null;
TDASServiceSetupInfoLookup setupInfo = null;
dlService.QueryDownload(qdList, delegate (ServiceBase.CallbackData data)
{
switch(data.Status)
{
case ServiceBase.CallbackData.CallbackStatus.Progress:
setProgressFunction?.Invoke(data.Target, (double)data.ProgressValue, DTS.Common.DataModel.Classes.TSRAIRGo.TSRAIRGoStatus.StatusTypes.GETTINGEVENTDATA);
break;
case ServiceBase.CallbackData.CallbackStatus.Failure:
break;
default:
return;
}
if (!string.IsNullOrWhiteSpace(data.ErrorMessage))
{
errStr = data.ErrorMessage;
}
if (null != data.ErrorException)
{
excep = data.ErrorException;
}
},
finishedEvent, -1, setupInfo);
if (!finishedEvent.WaitOne(checkForDataTimeout, false))
{
// timeout
dlService.Cancel();
throw new TimeoutException();
}
if (excep != null)
{
throw excep;
}
if (errStr != string.Empty)
{
throw new InvalidOperationException(errStr);
}
}
catch (Exception ex)
{
APILogger.Log(ex);
throw;
}
}
}
}
private static void dlService_ServiceAvailable(object sender, ServiceBase.CallbackData data)
{
(data.UserData as ManualResetEvent)?.Set();
}
private static string GetHash(DownloadReport.EventInfo myEvent)
{
return string.Format("{0}_{1:00}", myEvent.TestID, myEvent.EventNumber).ToUpper();
}
private static bool DataNeverDownloaded(List<IDASCommunication> dasList)
{
var bHaveUnDownloadedData = false;
foreach (var dasEventDownloadStatus in dasList.Select(x => x.EventDownloadedStatus))
{
if (bHaveUnDownloadedData)
{
break;
}
if (null != dasEventDownloadStatus &&
Array.Exists(dasEventDownloadStatus, b => !b))
{
bHaveUnDownloadedData = true;
}
}
return bHaveUnDownloadedData;
}
}
}