init
This commit is contained in:
@@ -0,0 +1,461 @@
|
||||
using DTS.Common.Enums;
|
||||
using DTS.Common.Enums.Hardware;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
|
||||
namespace DataPROWin7.DataModel.BatteryAndInputVoltageDefaults
|
||||
{
|
||||
public class DasBatteryInputSettings
|
||||
{
|
||||
/// <summary>
|
||||
/// all possible battery settings
|
||||
/// note that the order is important since serialization assumes this order,
|
||||
/// so don't change order without addressing that.
|
||||
/// </summary>
|
||||
public enum Settings
|
||||
{
|
||||
BatteryLowDiagnosticsThreshold,
|
||||
BatteryHighDiagnosticsThreshold,
|
||||
BatteryLowArmedThreshold,
|
||||
BatteryHighArmedThreshold,
|
||||
InputLowDiagnosticsThreshold,
|
||||
InputHighDiagnosticsThreshold,
|
||||
InputLowArmedThreshold,
|
||||
InputHighArmedThreshold,
|
||||
MinimumValidBatteryThreshold,
|
||||
MinimumValidInputThreshold,
|
||||
MaximumValidBatteryThreshold,
|
||||
MaximumValidInputThreshold,
|
||||
BatteryMediumDiagnosticsThreshold,
|
||||
BatteryMediumArmedThreshold,
|
||||
InputMediumDiagnosticsThreshold,
|
||||
InputMediumArmedThreshold,
|
||||
}
|
||||
|
||||
public double BatteryLowDiagnosticsThreshold
|
||||
{
|
||||
get => GetValue(Settings.BatteryLowDiagnosticsThreshold);
|
||||
set => SetValue(Settings.BatteryLowDiagnosticsThreshold, value);
|
||||
}
|
||||
|
||||
public double BatteryHighDiagnosticsThreshold
|
||||
{
|
||||
get => GetValue(Settings.BatteryHighDiagnosticsThreshold);
|
||||
set => SetValue(Settings.BatteryHighDiagnosticsThreshold, value);
|
||||
}
|
||||
|
||||
public double BatteryLowArmedThreshold
|
||||
{
|
||||
get => GetValue(Settings.BatteryLowArmedThreshold);
|
||||
set => SetValue(Settings.BatteryLowArmedThreshold, value);
|
||||
}
|
||||
|
||||
public double BatteryHighArmedThreshold
|
||||
{
|
||||
get => GetValue(Settings.BatteryHighArmedThreshold);
|
||||
set => SetValue(Settings.BatteryHighArmedThreshold, value);
|
||||
}
|
||||
|
||||
public double InputLowDiagnosticsThreshold
|
||||
{
|
||||
get => GetValue(Settings.InputLowDiagnosticsThreshold);
|
||||
set => SetValue(Settings.InputLowDiagnosticsThreshold, value);
|
||||
}
|
||||
|
||||
public double InputHighDiagnosticsThreshold
|
||||
{
|
||||
get => GetValue(Settings.InputHighDiagnosticsThreshold);
|
||||
set => SetValue(Settings.InputHighDiagnosticsThreshold, value);
|
||||
}
|
||||
|
||||
public double InputLowArmedThreshold
|
||||
{
|
||||
get => GetValue(Settings.InputLowArmedThreshold);
|
||||
set => SetValue(Settings.InputLowArmedThreshold, value);
|
||||
}
|
||||
|
||||
public double InputHighArmedThreshold
|
||||
{
|
||||
get => GetValue(Settings.InputHighArmedThreshold);
|
||||
set => SetValue(Settings.InputHighArmedThreshold, value);
|
||||
}
|
||||
|
||||
public double MinimumValidBatteryThreshold
|
||||
{
|
||||
get => GetValue(Settings.MinimumValidBatteryThreshold);
|
||||
set => SetValue(Settings.MinimumValidBatteryThreshold, value);
|
||||
}
|
||||
|
||||
public double MinimumValidInputThreshold
|
||||
{
|
||||
get => GetValue(Settings.MinimumValidInputThreshold);
|
||||
set => SetValue(Settings.MinimumValidInputThreshold, value);
|
||||
}
|
||||
|
||||
public double MaximumValidBatteryThreshold
|
||||
{
|
||||
get => GetValue(Settings.MaximumValidBatteryThreshold);
|
||||
set => SetValue(Settings.MaximumValidBatteryThreshold, value);
|
||||
}
|
||||
|
||||
public double MaximumValidInputThreshold
|
||||
{
|
||||
get => GetValue(Settings.MaximumValidInputThreshold);
|
||||
set => SetValue(Settings.MaximumValidInputThreshold, value);
|
||||
}
|
||||
|
||||
public double BatteryMediumDiagnosticsThreshold
|
||||
{
|
||||
get => GetValue(Settings.BatteryMediumDiagnosticsThreshold);
|
||||
set => SetValue(Settings.BatteryMediumDiagnosticsThreshold, value);
|
||||
}
|
||||
|
||||
public double BatteryMediumArmedThreshold
|
||||
{
|
||||
get => GetValue(Settings.BatteryMediumArmedThreshold);
|
||||
set => SetValue(Settings.BatteryMediumArmedThreshold, value);
|
||||
}
|
||||
|
||||
public double InputMediumDiagnosticsThreshold
|
||||
{
|
||||
get => GetValue(Settings.InputMediumDiagnosticsThreshold);
|
||||
set => SetValue(Settings.InputMediumDiagnosticsThreshold, value);
|
||||
}
|
||||
|
||||
public double InputMediumArmedThreshold
|
||||
{
|
||||
get => GetValue(Settings.InputMediumArmedThreshold);
|
||||
set => SetValue(Settings.InputMediumArmedThreshold, value);
|
||||
}
|
||||
public Dictionary<Settings, double> SettingsProperty { get; } = new Dictionary<Settings, double>();
|
||||
|
||||
public DasBatteryInputSettings(string s)
|
||||
{
|
||||
var tokens = s.Split(new char[] { ',' });
|
||||
for (int i = 0; i < tokens.Length; i++)
|
||||
{
|
||||
var setting = (Settings)i;
|
||||
if (double.TryParse(tokens[i], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out double d))
|
||||
{
|
||||
SettingsProperty[setting] = d;
|
||||
}
|
||||
}
|
||||
}
|
||||
public DasBatteryInputSettings(DasBatteryInputSettings copy)
|
||||
{
|
||||
using (var e = copy.SettingsProperty.GetEnumerator())
|
||||
{
|
||||
while (e.MoveNext())
|
||||
{
|
||||
SettingsProperty[e.Current.Key] = e.Current.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
public DasBatteryInputSettings()
|
||||
{
|
||||
var settings = Enum.GetValues(typeof(Settings)).Cast<Settings>().ToArray();
|
||||
foreach (var s in settings)
|
||||
{
|
||||
double d = double.NaN;
|
||||
switch (s)
|
||||
{
|
||||
case Settings.BatteryHighArmedThreshold: d = 9D; break;
|
||||
case Settings.BatteryHighDiagnosticsThreshold: d = 9D; break;
|
||||
case Settings.BatteryLowArmedThreshold: d = 6.8D; break;
|
||||
case Settings.BatteryLowDiagnosticsThreshold: d = 7.8D; break;
|
||||
case Settings.InputHighArmedThreshold: d = 15.3; break;
|
||||
case Settings.InputHighDiagnosticsThreshold: d = 15.3; break;
|
||||
case Settings.InputLowArmedThreshold: d = 6.5D; break;
|
||||
case Settings.InputLowDiagnosticsThreshold: d = 10D; break;
|
||||
case Settings.MinimumValidBatteryThreshold: d = 4D; break;
|
||||
case Settings.MinimumValidInputThreshold: d = 4D; break;
|
||||
case Settings.MaximumValidBatteryThreshold: d = 9D; break;
|
||||
case Settings.MaximumValidInputThreshold: d = 19D; break;
|
||||
|
||||
case Settings.BatteryMediumArmedThreshold: d = 7.9D; break; //7.9 is halfway between low and high
|
||||
case Settings.BatteryMediumDiagnosticsThreshold: d = 8.4D; break; //8.4 is halfway between low and high
|
||||
case Settings.InputMediumArmedThreshold: d = 10.9D; break; //10.9 is halfway between low and high
|
||||
case Settings.InputMediumDiagnosticsThreshold: d = 12.7D; break; //12.7 is halfway between low and high
|
||||
|
||||
default: throw new NotSupportedException("Unknown Battery setting: " + s.ToString());
|
||||
}
|
||||
SettingsProperty[s] = d;
|
||||
}
|
||||
}
|
||||
public string ToSerializedString()
|
||||
{
|
||||
var settings = Enum.GetValues(typeof(Settings)).Cast<Settings>().ToArray();
|
||||
var sb = new string[settings.Length];
|
||||
|
||||
foreach (var setting in settings)
|
||||
{
|
||||
sb[(int)setting] = GetValue(setting).ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
return string.Join(",", sb);
|
||||
}
|
||||
public double GetValue(Settings setting)
|
||||
{
|
||||
if (SettingsProperty.ContainsKey(setting)) { return SettingsProperty[setting]; }
|
||||
else { throw new NotSupportedException("unknown setting: " + setting.ToString()); }
|
||||
}
|
||||
|
||||
public void SetValue(Settings setting, double d)
|
||||
{
|
||||
SettingsProperty[setting] = d;
|
||||
}
|
||||
}
|
||||
public static class InputAndBatterySettings
|
||||
{
|
||||
/// <summary>
|
||||
/// holds the battery/input settings in a cache so they don't have to be requeried from db
|
||||
/// 17615 BatteryAndInputVoltageDefaults improvements 3.2
|
||||
/// </summary>
|
||||
public static Dictionary<HardwareTypes, DasBatteryInputSettings> _cache =
|
||||
new Dictionary<HardwareTypes, DasBatteryInputSettings>();
|
||||
|
||||
/// <summary>
|
||||
/// clears the cache. This serves the purpose of ensuring
|
||||
/// that the values will be re-queried between runs, so if the settings are changed
|
||||
/// between runs the new values will be used
|
||||
/// </summary>
|
||||
public static void ClearCache()
|
||||
{
|
||||
_cache.Clear();
|
||||
}
|
||||
public static double GetValue(string DasType, DasBatteryInputSettings.Settings setting)
|
||||
{
|
||||
if (Enum.TryParse(DasType, out HardwareTypes type))
|
||||
{
|
||||
return GetValue(type, setting);
|
||||
}
|
||||
else { return double.NaN; }
|
||||
}
|
||||
|
||||
public static DasBatteryInputSettings GetDefaultSettingForHWType(HardwareTypes type)
|
||||
{
|
||||
if (RunTestVariables.InRunTest && RunTestVariables.CacheVoltageSettingsInRunTest)
|
||||
{
|
||||
if (_cache.ContainsKey(type))
|
||||
{
|
||||
return _cache[type];
|
||||
}
|
||||
}
|
||||
DasBatteryInputSettings setting = null;
|
||||
switch (type)
|
||||
{
|
||||
case HardwareTypes.G5INDUMMY: setting = Common.SerializedSettings.G5INDUMMY_PowerSetting_Default; break;
|
||||
case HardwareTypes.G5VDS: setting = Common.SerializedSettings.G5VDS_PowerSetting_Default; break;
|
||||
|
||||
case HardwareTypes.SLICE_Distributor: setting = Common.SerializedSettings.SLICE_Distributor_PowerSetting_Default; break;
|
||||
case HardwareTypes.SLICE_Mini_Distributor: setting = Common.SerializedSettings.SLICE_Mini_Distributor_PowerSetting_Default; break;
|
||||
case HardwareTypes.SLICE_EthernetController: setting = Common.SerializedSettings.SLICE_EthernetController_PowerSetting_Default; break;
|
||||
case HardwareTypes.SLICE_LabEthernet: setting = Common.SerializedSettings.SLICE_LabEthernet_PowerSetting_Default; break;
|
||||
|
||||
case HardwareTypes.SLICE_Micro_Base: setting = Common.SerializedSettings.SLICE_Micro_Base_PowerSetting_Default; break;
|
||||
case HardwareTypes.SLICE_NANO_Base: setting = Common.SerializedSettings.SLICE_NANO_Base_PowerSetting_Default; break;
|
||||
|
||||
case HardwareTypes.SLICE1_5_Micro_Base: setting = Common.SerializedSettings.SLICE1_5_Micro_Base_PowerSetting_Default; break;
|
||||
case HardwareTypes.SLICE1_5_Nano_Base: setting = Common.SerializedSettings.SLICE1_5_Nano_Base_PowerSetting_Default; break;
|
||||
case HardwareTypes.SLICE1_G5Stack: setting = Common.SerializedSettings.SLICE1_G5Stack_PowerSetting_Default; break;
|
||||
|
||||
case HardwareTypes.SLICE2_DIM: setting = Common.SerializedSettings.SLICE2_DIM_PowerSetting_Default; break;
|
||||
case HardwareTypes.SLICE2_SIM:
|
||||
case HardwareTypes.SLICE2_Base:
|
||||
setting = Common.SerializedSettings.SLICE2_SIM_PowerSetting_Default; break;
|
||||
case HardwareTypes.SLICE2_TOM: setting = Common.SerializedSettings.SLICE2_TOM_PowerSetting_Default; break;
|
||||
|
||||
case HardwareTypes.SLICE2_SLD: setting = Common.SerializedSettings.SLICE2_SLD_PowerSetting_Default; break;
|
||||
case HardwareTypes.SLICE2_SLS: setting = Common.SerializedSettings.SLICE2_SLS_PowerSetting_Default; break;
|
||||
case HardwareTypes.SLICE2_SLT: setting = Common.SerializedSettings.SLICE2_SLT_PowerSetting_Default; break;
|
||||
|
||||
|
||||
case HardwareTypes.TDAS_Pro_Rack:
|
||||
case HardwareTypes.TDAS_LabRack:
|
||||
setting = Common.SerializedSettings.TDAS_Pro_Rack_PowerSetting_Default; break;
|
||||
case HardwareTypes.SLICE6_Base:
|
||||
setting = Common.SerializedSettings.SLICE6_PowerSetting_Default; break;
|
||||
case HardwareTypes.SLICE6_AIR:
|
||||
setting = Common.SerializedSettings.SLICE6_AIR_PowerSetting_Default; break;
|
||||
case HardwareTypes.SLICE6_AIR_BR:
|
||||
setting = Common.SerializedSettings.SLICE6_AIR_BR_PowerSetting_Default; break;
|
||||
case HardwareTypes.SLICE6DB: setting = Common.SerializedSettings.SLICE6Db_PowerSetting_Default; break;
|
||||
case HardwareTypes.SLICE_Pro_Distributor: setting = Common.SerializedSettings.SLICEPRODistributor_PowerSetting_Default; break;
|
||||
case HardwareTypes.SLICE6DB3: setting = Common.SerializedSettings.SLICE6Db3_PowerSetting_Default; break;
|
||||
case HardwareTypes.SLICE6DB_InDummy: setting = Common.SerializedSettings.SLICE6Db_InDummy_PowerSetting_Default; break;
|
||||
case HardwareTypes.PowerPro: setting = Common.SerializedSettings.PowerPRO_PowerSetting_Default; break;
|
||||
case HardwareTypes.TSR_AIR:
|
||||
case HardwareTypes.TSR_AIR_RevB:
|
||||
setting = Common.SerializedSettings.TSRAIR_PowerSetting_Default; break;
|
||||
//case HardwareTypes.SLICE_Pro_Distributor: setting = Common.SerializedSettings.SLICEPRODistributor_PowerSetting_Default; break;
|
||||
//case HardwareTypes.Falcon: setting = Common.SerializedSettings.Falcon_PowerSetting_Default; break;
|
||||
}
|
||||
|
||||
if (null != setting)
|
||||
{
|
||||
if (RunTestVariables.InRunTest && RunTestVariables.CacheVoltageSettingsInRunTest)
|
||||
{
|
||||
_cache[type] = setting;
|
||||
}
|
||||
return setting;
|
||||
}
|
||||
|
||||
throw new NotSupportedException($"unknown type: {type.ToString()}");
|
||||
}
|
||||
public static void SetSettingForHWType(HardwareTypes type,
|
||||
DasBatteryInputSettings setting)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case HardwareTypes.G5INDUMMY:
|
||||
Common.SerializedSettings.G5INDUMMY_PowerSetting = setting; break;
|
||||
case HardwareTypes.G5VDS:
|
||||
Common.SerializedSettings.G5VDS_PowerSetting = setting; break;
|
||||
case HardwareTypes.SLICE_Distributor:
|
||||
Common.SerializedSettings.SLICE_Distributor_PowerSetting = setting; break;
|
||||
case HardwareTypes.SLICE6DB: Common.SerializedSettings.SLICE6Db_PowerSetting = setting; break;
|
||||
case HardwareTypes.SLICE6DB3: Common.SerializedSettings.SLICE6Db3_PowerSetting = setting; break;
|
||||
case HardwareTypes.SLICE_Pro_Distributor: Common.SerializedSettings.SLICEPRODistributor_PowerSetting = setting; break;
|
||||
//case HardwareTypes.SLICE6DB_AIR: Common.SerializedSettings.SLICE6Db_AIR_PowerSetting = setting; break;
|
||||
case HardwareTypes.SLICE6DB_InDummy: Common.SerializedSettings.SLICE6Db_InDummy_PowerSetting = setting; break;
|
||||
case HardwareTypes.SLICE_Mini_Distributor:
|
||||
Common.SerializedSettings.SLICE_Mini_Distributor_PowerSetting = setting; break;
|
||||
case HardwareTypes.SLICE_EthernetController:
|
||||
Common.SerializedSettings.SLICE_EthernetController_PowerSetting = setting; break;
|
||||
case HardwareTypes.SLICE_LabEthernet:
|
||||
Common.SerializedSettings.SLICE_LabEthernet_PowerSetting = setting; break;
|
||||
case HardwareTypes.SLICE_Micro_Base:
|
||||
Common.SerializedSettings.SLICE_Micro_Base_PowerSetting = setting; break;
|
||||
case HardwareTypes.SLICE_NANO_Base:
|
||||
Common.SerializedSettings.SLICE_NANO_Base_PowerSetting = setting; break;
|
||||
case HardwareTypes.SLICE1_5_Micro_Base:
|
||||
Common.SerializedSettings.SLICE1_5_Micro_Base_PowerSetting = setting; break;
|
||||
case HardwareTypes.SLICE1_5_Nano_Base:
|
||||
Common.SerializedSettings.SLICE1_5_Nano_Base_PowerSetting = setting; break;
|
||||
case HardwareTypes.SLICE1_G5Stack:
|
||||
Common.SerializedSettings.SLICE1_G5Stack_PowerSetting = setting; break;
|
||||
case HardwareTypes.SLICE2_DIM:
|
||||
Common.SerializedSettings.SLICE2_DIM_PowerSetting = setting; break;
|
||||
case HardwareTypes.SLICE2_SIM:
|
||||
case HardwareTypes.SLICE2_Base:
|
||||
Common.SerializedSettings.SLICE2_SIM_PowerSetting = setting; break;
|
||||
case HardwareTypes.SLICE2_SLD:
|
||||
Common.SerializedSettings.SLICE2_SLD_PowerSetting = setting; break;
|
||||
case HardwareTypes.SLICE2_SLS:
|
||||
Common.SerializedSettings.SLICE2_SLS_PowerSetting = setting; break;
|
||||
case HardwareTypes.SLICE2_SLT:
|
||||
Common.SerializedSettings.SLICE2_SLT_PowerSetting = setting; break;
|
||||
case HardwareTypes.SLICE2_TOM:
|
||||
Common.SerializedSettings.SLICE2_TOM_PowerSetting = setting; break;
|
||||
case HardwareTypes.TDAS_Pro_Rack:
|
||||
case HardwareTypes.TDAS_LabRack:
|
||||
Common.SerializedSettings.TDAS_Pro_Rack_PowerSetting = setting; break;
|
||||
case HardwareTypes.SLICE6_Base:
|
||||
Common.SerializedSettings.SLICE6_PowerSetting = setting;
|
||||
break;
|
||||
case HardwareTypes.SLICE6_AIR:
|
||||
Common.SerializedSettings.SLICE6_AIR_PowerSetting = setting;
|
||||
break;
|
||||
case HardwareTypes.SLICE6_AIR_BR:
|
||||
Common.SerializedSettings.SLICE6_AIR_BR_PowerSetting = setting;
|
||||
break;
|
||||
case HardwareTypes.PowerPro:
|
||||
Common.SerializedSettings.PowerPRO_PowerSetting = setting;
|
||||
break;
|
||||
case HardwareTypes.TSR_AIR:
|
||||
case HardwareTypes.TSR_AIR_RevB:
|
||||
Common.SerializedSettings.TSRAIR_PowerSetting = setting;
|
||||
break;
|
||||
}
|
||||
}
|
||||
public static DasBatteryInputSettings GetSettingForHWType(HardwareTypes type)
|
||||
{
|
||||
if (RunTestVariables.InRunTest && RunTestVariables.CacheVoltageSettingsInRunTest)
|
||||
{
|
||||
if (_cache.ContainsKey(type))
|
||||
{
|
||||
return _cache[type];
|
||||
}
|
||||
}
|
||||
|
||||
DasBatteryInputSettings setting = null;
|
||||
switch (type)
|
||||
{
|
||||
case HardwareTypes.G5INDUMMY: setting = Common.SerializedSettings.G5INDUMMY_PowerSetting; break;
|
||||
case HardwareTypes.G5VDS: setting = Common.SerializedSettings.G5VDS_PowerSetting; break;
|
||||
|
||||
case HardwareTypes.SLICE_Distributor: setting = Common.SerializedSettings.SLICE_Distributor_PowerSetting; break;
|
||||
case HardwareTypes.SLICE_Mini_Distributor: setting = Common.SerializedSettings.SLICE_Mini_Distributor_PowerSetting; break;
|
||||
case HardwareTypes.SLICE_Pro_Distributor: setting = Common.SerializedSettings.SLICEPRODistributor_PowerSetting; break;
|
||||
case HardwareTypes.SLICE6DB: setting = Common.SerializedSettings.SLICE6Db_PowerSetting; break;
|
||||
case HardwareTypes.SLICE6DB3: setting = Common.SerializedSettings.SLICE6Db3_PowerSetting; break;
|
||||
case HardwareTypes.SLICE6DB_InDummy: setting = Common.SerializedSettings.SLICE6Db_InDummy_PowerSetting; break;
|
||||
case HardwareTypes.SLICE_EthernetController: setting = Common.SerializedSettings.SLICE_EthernetController_PowerSetting; break;
|
||||
case HardwareTypes.SLICE_LabEthernet: setting = Common.SerializedSettings.SLICE_LabEthernet_PowerSetting; break;
|
||||
|
||||
case HardwareTypes.SLICE_Micro_Base: setting = Common.SerializedSettings.SLICE_Micro_Base_PowerSetting; break;
|
||||
case HardwareTypes.SLICE_NANO_Base: setting = Common.SerializedSettings.SLICE_NANO_Base_PowerSetting; break;
|
||||
case HardwareTypes.SLICE1_5_Micro_Base: setting = Common.SerializedSettings.SLICE1_5_Micro_Base_PowerSetting; break;
|
||||
case HardwareTypes.SLICE1_5_Nano_Base: setting = Common.SerializedSettings.SLICE1_5_Nano_Base_PowerSetting; break;
|
||||
case HardwareTypes.SLICE1_G5Stack: setting = Common.SerializedSettings.SLICE1_G5Stack_PowerSetting; break;
|
||||
case HardwareTypes.SLICE2_DIM: setting = Common.SerializedSettings.SLICE2_DIM_PowerSetting; break;
|
||||
|
||||
case HardwareTypes.SLICE2_SIM:
|
||||
case HardwareTypes.SLICE2_Base:
|
||||
setting = Common.SerializedSettings.SLICE2_SIM_PowerSetting; break;
|
||||
case HardwareTypes.SLICE2_SLD: setting = Common.SerializedSettings.SLICE2_SLD_PowerSetting; break;
|
||||
case HardwareTypes.SLICE2_SLS: setting = Common.SerializedSettings.SLICE2_SLS_PowerSetting; break;
|
||||
case HardwareTypes.SLICE2_SLT: setting = Common.SerializedSettings.SLICE2_SLT_PowerSetting; break;
|
||||
case HardwareTypes.SLICE2_TOM: setting = Common.SerializedSettings.SLICE2_TOM_PowerSetting; break;
|
||||
case HardwareTypes.TDAS_Pro_Rack:
|
||||
case HardwareTypes.TDAS_LabRack:
|
||||
setting = Common.SerializedSettings.TDAS_Pro_Rack_PowerSetting; break;
|
||||
case HardwareTypes.DIM:
|
||||
case HardwareTypes.SIM:
|
||||
case HardwareTypes.TOM:
|
||||
//we are not expected to get here but if we do, just use the tdas default
|
||||
setting = Common.SerializedSettings.TDAS_Pro_Rack_PowerSetting; break;
|
||||
case HardwareTypes.Ribeye:
|
||||
case HardwareTypes.RibeyeLED:
|
||||
case HardwareTypes.SLICE_Base:
|
||||
case HardwareTypes.SLICE_Bridge:
|
||||
case HardwareTypes.SLICE_IEPE:
|
||||
case HardwareTypes.SLICE2_IEPE_Hi:
|
||||
case HardwareTypes.SLICE2_IEPE_Lo:
|
||||
//these are all never expected to get here, but are all slice types
|
||||
setting = Common.SerializedSettings.SLICE_NANO_Base_PowerSetting; break;
|
||||
case HardwareTypes.SLICE6_Base: setting = Common.SerializedSettings.SLICE6_PowerSetting; break;
|
||||
case HardwareTypes.SLICE6_AIR:
|
||||
case HardwareTypes.S6A_EthernetRecorder:
|
||||
setting = Common.SerializedSettings.SLICE6_AIR_PowerSetting; break;
|
||||
case HardwareTypes.SLICE6_AIR_BR:
|
||||
setting = Common.SerializedSettings.SLICE6_AIR_BR_PowerSetting; break;
|
||||
case HardwareTypes.PowerPro: setting = Common.SerializedSettings.PowerPRO_PowerSetting; break;
|
||||
case HardwareTypes.TSR_AIR:
|
||||
case HardwareTypes.TSR_AIR_RevB:
|
||||
setting = Common.SerializedSettings.TSRAIR_PowerSetting;
|
||||
break;
|
||||
case HardwareTypes.SLICE6_AIR_TC:
|
||||
setting = Common.SerializedSettings.SLICE6_AIR_TC_PowerSetting; break;
|
||||
case HardwareTypes.SLICE_PRO_CAN_FD:
|
||||
setting = Common.SerializedSettings.SPFD_PowerSetting; break;
|
||||
default:
|
||||
throw new NotSupportedException("unknown das type: " + type.ToString());
|
||||
}
|
||||
if (null != setting)
|
||||
{
|
||||
if (RunTestVariables.InRunTest && RunTestVariables.CacheVoltageSettingsInRunTest)
|
||||
{
|
||||
_cache[type] = setting;
|
||||
}
|
||||
}
|
||||
return setting;
|
||||
}
|
||||
public static double GetValue(HardwareTypes type, DasBatteryInputSettings.Settings setting)
|
||||
{
|
||||
return GetSettingForHWType(type).GetValue(setting);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
3983
Common/DTS.Common.DataModel/Classes/Hardware/DASHardware.cs
Normal file
3983
Common/DTS.Common.DataModel/Classes/Hardware/DASHardware.cs
Normal file
File diff suppressed because it is too large
Load Diff
341
Common/DTS.Common.DataModel/Classes/Hardware/DASHardwareList.cs
Normal file
341
Common/DTS.Common.DataModel/Classes/Hardware/DASHardwareList.cs
Normal file
@@ -0,0 +1,341 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using DataPROWin7.DataModel.Classes.TestTemplate;
|
||||
using DTS.Common.Base;
|
||||
using DTS.Common.DataModel;
|
||||
using DTS.Common.Interface.DASFactory.Diagnostics;
|
||||
using DTS.Common.Interface.DASFactory.Diagnostics.HardwareList;
|
||||
using DTS.Common.Interface.DataRecorders;
|
||||
using DTS.Common.Storage;
|
||||
|
||||
namespace DataPROWin7.DataModel.Classes.Hardware
|
||||
{
|
||||
public class DASHardwareList : BasePropertyChanged
|
||||
{
|
||||
private static DASHardwareList _list;
|
||||
|
||||
private static bool _cache = false;
|
||||
/// <summary>
|
||||
/// turns off queries to the db and starts using cached data instead
|
||||
/// this is done when a large number of test setups are validating, since each test setup
|
||||
/// will get a complete list of hardware from the db, which adds time when you have a lot of hardware and test setups
|
||||
/// </summary>
|
||||
public static bool Cache
|
||||
{
|
||||
get => _cache;
|
||||
set
|
||||
{
|
||||
_cache = value;
|
||||
if (!value)
|
||||
{
|
||||
_cachedDASHardware = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static DASHardwareList GetList()
|
||||
{
|
||||
if (null != _list) return _list;
|
||||
_list = new DASHardwareList();
|
||||
//_list.PopulateHardware();
|
||||
|
||||
return _list;
|
||||
}
|
||||
|
||||
public void ReloadAll()
|
||||
{
|
||||
//_list = new DASHardwareList();
|
||||
//_list.PopulateHardware();
|
||||
}
|
||||
private ICachedContainer _cachedHardware = null;
|
||||
|
||||
public void SetCache(ICachedContainer container)
|
||||
{
|
||||
_cachedHardware = container;
|
||||
}
|
||||
|
||||
public void ClearCache()
|
||||
{
|
||||
_cachedHardware = null;
|
||||
}
|
||||
public string GetDASSerialNumberFromId(int id)
|
||||
{
|
||||
//this could probably be improved, but rather than getting ALL HARDWARE and ALL channels
|
||||
//just to get a serial number for a database id
|
||||
//just get the hardware without the channels
|
||||
var hr = DbOperations.DASGet(null, null, out var records);
|
||||
if (0 == hr && null != records && records.Any())
|
||||
{
|
||||
var match = Array.Find(records, das => das.DASId == id);
|
||||
if (null != match) { return match.SerialNumber; }
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
public DASHardware GetHardware(int id)
|
||||
{
|
||||
var sn = GetDASSerialNumberFromId(id);
|
||||
return GetHardware(sn);
|
||||
}
|
||||
public DASHardware GetHardware(string id, bool bUseCache = true)
|
||||
{
|
||||
return GetHardware(id, true, out var bNotUsed, bUseCache);
|
||||
}
|
||||
|
||||
public DASHardware[] GetHardware(string[] ids, bool bUseCache = true)
|
||||
{
|
||||
List<DASHardware> dasHW = new List<DASHardware>();
|
||||
foreach (string id in ids)
|
||||
{
|
||||
var hw = GetHardware(id, bUseCache);
|
||||
if (null != hw)
|
||||
{
|
||||
dasHW.Add(hw);
|
||||
}
|
||||
}
|
||||
return dasHW.ToArray();
|
||||
}
|
||||
|
||||
public DASHardware GetHardware(string id, bool bThrowExceptionIfChanged, out bool changed, bool bUseCache = true)
|
||||
{
|
||||
if (null != _cachedHardware && bUseCache)
|
||||
{
|
||||
var tokens = id.Split('_');
|
||||
var h = _cachedHardware.GetCachedHardware(tokens[0]);
|
||||
if (null != h)
|
||||
{
|
||||
changed = false;
|
||||
return h;
|
||||
}
|
||||
if (null != _cachedDASHardware)
|
||||
{
|
||||
h = Array.Find(_cachedDASHardware, das => das.SerialNumber == id);
|
||||
if (null != h)
|
||||
{
|
||||
changed = false;
|
||||
return h;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var hardware = DTS.Common.ISO.Hardware.GetAllDAS(id, null);
|
||||
changed = false;
|
||||
if (null != hardware && hardware.Any())
|
||||
{
|
||||
return new DASHardware(hardware[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public class HardwareTypeChangedException : Exception
|
||||
{
|
||||
}
|
||||
|
||||
public DASHardware GetHardware(string serialNumber, string ipaddress)
|
||||
{
|
||||
return GetHardware(serialNumber);
|
||||
}
|
||||
|
||||
public void UpdateMaxMemory(DASHardware h, long newMaxMemory)
|
||||
{
|
||||
h.GetHardware().MaxMemory = newMaxMemory;
|
||||
h.GetHardware().Update();
|
||||
}
|
||||
|
||||
public DASHardware GetPrototypeHardware(string serial, int type)
|
||||
{
|
||||
//return new DASHardware();
|
||||
var key = $"{serial}_{type}";
|
||||
var das = DTS.Common.ISO.Hardware.GetAllDAS(key, DbOperations.DAS.PROTOTYPE_POSITION);
|
||||
if (null != das && das.Any())
|
||||
{
|
||||
das[0].CalDate = DateTime.MinValue;//if something is using the prototype, use a blank caldate
|
||||
return new DASHardware(das[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// holds a cache of all hardware this is done for speed reasons when there are a large number
|
||||
/// of test setups to validate, each one of them grabs all the hardware, which takes time
|
||||
/// </summary>
|
||||
private static DASHardware[] _cachedDASHardware = null;
|
||||
public static DASHardware[] GetAllHardware()
|
||||
{
|
||||
if (Cache && null != _cachedDASHardware) { return _cachedDASHardware; }
|
||||
var allHardware = DTS.Common.ISO.Hardware.GetAllDAS();
|
||||
var ret = allHardware.Select(h => new DASHardware(h)).ToArray();
|
||||
if (Cache) { _cachedDASHardware = ret; }
|
||||
return ret;
|
||||
}
|
||||
public static List<int> GetEmbeddedModules(IDASHardware[] hardware, int id)
|
||||
{
|
||||
var modules = new List<int>();
|
||||
|
||||
foreach (var hw in hardware)
|
||||
{
|
||||
if (hw.Connection.StartsWith(hardware.First(h => h.DASId == id).SerialNumber))
|
||||
{
|
||||
modules.Add(hw.DASId);
|
||||
}
|
||||
}
|
||||
|
||||
return modules;
|
||||
}
|
||||
public static Dictionary<string, double> GetEmbeddedModuleInfo(DASHardware[] hardware, int id)
|
||||
{
|
||||
var info = new Dictionary<string, double>();
|
||||
|
||||
foreach (var hw in hardware)
|
||||
{
|
||||
if (hw.Connection.StartsWith(hardware.First(h => h.DASId == id).SerialNumber))
|
||||
{
|
||||
info[hw.SerialNumber] = hw.GetMaxSampleRateDouble();
|
||||
}
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
public enum Tags
|
||||
{
|
||||
Hardware
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unassociate is used to indicate whether children das should be unassociated before commiting or not
|
||||
/// </summary>
|
||||
public void Commit(DASHardware hardware, bool bExisting = false, bool bCheckExisting = true, bool Unassociate = true)
|
||||
{
|
||||
//note when you are commiting a group of hardware that contains a SLICE6Db, you should
|
||||
//sort the hardware so that this call happens BEFORE we commit any child slice6
|
||||
if (hardware.IsPseudoRack() && Unassociate)
|
||||
{
|
||||
UnassociateParentDAS(hardware.SerialNumber);
|
||||
}
|
||||
|
||||
var iso = hardware.GetHardware();
|
||||
var h = new DTS.Common.ISO.Hardware
|
||||
{
|
||||
SerialNumber = hardware.SerialNumber,
|
||||
LocalOnly = hardware.LocalOnly,
|
||||
IsModule = hardware.IsModule(),
|
||||
CalDate = hardware.CalDate,
|
||||
DASType = hardware.GetHardwareTypeInt(),
|
||||
FirmwareVersion = hardware.Firmware,
|
||||
IPAddress = hardware.Connection,
|
||||
MaxMemory = hardware.GetMaxMemoryLong(),
|
||||
MaxModules = hardware.MaxModules,
|
||||
MaxSampleRate = hardware.GetMaxSampleRateDouble(),
|
||||
MinSampleRate = hardware.GetMinSampleRateDouble(),
|
||||
ProtocolVersion = hardware.ProtocolVersion,
|
||||
Channels = hardware.Channels.Length,
|
||||
LastModified = DateTime.Now,
|
||||
LastModifiedBy = ApplicationProperties.CurrentUser.UserName,
|
||||
IsReconfigurable = hardware.Reconfigurable,
|
||||
IsProgrammable = hardware.Reprogrammable,
|
||||
ChannelTypes = hardware.ChannelTypes,
|
||||
ParentDAS = hardware.ParentDAS,
|
||||
Port = hardware.PortOnDistributor,
|
||||
PositionOnChain = hardware.PositionOnChain,
|
||||
PositionOnDistributor = hardware.PositionOnDistributor,
|
||||
IsFirstUseValid = hardware.IsFirstUseValid,
|
||||
FirstUseDate = hardware.FirstUseDate,
|
||||
StandIn = iso.StandIn,
|
||||
MaxAAFRate = hardware.GetMaxAAFRateDouble(),
|
||||
TestId = iso.TestId,
|
||||
GroupId = iso.GroupId,
|
||||
LastUsed = iso.LastUsed,
|
||||
LastUsedBy = iso.LastUsedBy
|
||||
};
|
||||
|
||||
h.ISOChannels = hardware.Channels.Select(channel => new DTS.Common.ISO.HardwareChannel(channel.GetISOChannel(), h))
|
||||
.ToArray();
|
||||
hardware.SetHardware(h);
|
||||
|
||||
//if (null == _hardware)
|
||||
//{
|
||||
// PopulateHardware();
|
||||
//}
|
||||
|
||||
//10037 TDAS G5 module is detected as a TDAS G5 in a VDS, so if the existing serial number and ip address
|
||||
//already exists in the database
|
||||
if (bCheckExisting)
|
||||
{
|
||||
//22320 Unnecessary hardware retrieval
|
||||
bExisting = DASHardware.GetDataBaseID(hardware.SerialNumber) > 0;
|
||||
}
|
||||
if (!bExisting)
|
||||
{
|
||||
h.Insert();
|
||||
}
|
||||
else
|
||||
{
|
||||
h.Version = h.Version + 1;
|
||||
//10037 TDAS G5 module is detected as a TDAS G5 in a VDS
|
||||
//the id could change, so if we are doing an update, we should make sure to remove the old instance in the list
|
||||
//_hardware.Remove(existingHardware.GetHardware().GetId());
|
||||
//_hardware[hardware.GetHardware().GetId()] = hardware;
|
||||
h.Update();
|
||||
}
|
||||
OnPropertyChanged(Tags.Hardware.ToString());
|
||||
|
||||
//no longer need to mark groups incomplete
|
||||
}
|
||||
/// <summary>
|
||||
/// deletes the selected IHardware
|
||||
/// </summary>
|
||||
public void Delete(IHardware hardware)
|
||||
{
|
||||
if (hardware.Hardware is IISOHardware isoHW)
|
||||
{
|
||||
isoHW.Delete();
|
||||
}
|
||||
}
|
||||
public void Delete(DASHardware hardware)
|
||||
{
|
||||
var h = hardware?.GetHardware();
|
||||
if (h == null) { return; }
|
||||
h.Delete();
|
||||
|
||||
if (hardware.IsPseudoRack())
|
||||
{
|
||||
UnassociateParentDAS(hardware.SerialNumber);
|
||||
}
|
||||
OnPropertyChanged(Tags.Hardware.ToString());
|
||||
}
|
||||
/// <summary>
|
||||
/// iteratively deletes the given hardware
|
||||
/// </summary>
|
||||
public void Delete(IHardware[] hardware)
|
||||
{
|
||||
foreach (var h in hardware)
|
||||
{
|
||||
Delete(h);
|
||||
}
|
||||
}
|
||||
public void Delete(DASHardware[] hardware)
|
||||
{
|
||||
foreach (DASHardware hw in hardware)
|
||||
{
|
||||
Delete(hw);
|
||||
}
|
||||
}
|
||||
|
||||
public static void UnassociateParentDAS(string distributorSerialNumber)
|
||||
{
|
||||
using (var sql = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
sql.CommandType = System.Data.CommandType.StoredProcedure;
|
||||
sql.CommandText = DbOperationsEnum.StoredProcedure.sp_DASChildrenUnAssociate.ToString();
|
||||
DbOperations.CreateParam(sql, "@ParentSerialNumber", System.Data.SqlDbType.NVarChar,
|
||||
distributorSerialNumber);
|
||||
sql.ExecuteNonQuery();
|
||||
}
|
||||
finally { sql.Connection.Dispose(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
69
Common/DTS.Common.DataModel/Classes/Hardware/DASSettings.cs
Normal file
69
Common/DTS.Common.DataModel/Classes/Hardware/DASSettings.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using DTS.Common.Base;
|
||||
|
||||
namespace DataPROWin7.DataModel
|
||||
{
|
||||
/// <summary>
|
||||
/// this is a class for holding das specific settings in a test, for example sample rate or aaf
|
||||
/// it is serialized into tblTestSetupDASSettings
|
||||
/// </summary>
|
||||
public class DASSettings : BasePropertyChanged
|
||||
{
|
||||
public DASSettings()
|
||||
{
|
||||
}
|
||||
public DASSettings(DASSettings setting)
|
||||
{
|
||||
_DASSerialNumber = setting.DASSerialNumber;
|
||||
_sampleRate = setting.SampleRate;
|
||||
_excitationWarmupTimeMS = setting.ExcitationWarmupTimeMS;
|
||||
_aaf = setting.HardwareAAF;
|
||||
_preTriggerSeconds = setting.PreTriggerSeconds;
|
||||
_postTriggerSeconds = setting.PostTriggerSeconds;
|
||||
_statusLineCheck = setting.StatusLineCheck;
|
||||
_batteryCheck = setting.BatteryCheck;
|
||||
_inputVoltageMin = setting.InputVoltageMin;
|
||||
_inputVoltageMax = setting.InputVoltageMax;
|
||||
_batteryVoltageMin = setting.BatteryVoltageMin;
|
||||
_batteryVoltageMax = setting.BatteryVoltageMax;
|
||||
}
|
||||
private string _DASSerialNumber;
|
||||
public string DASSerialNumber { get => _DASSerialNumber; set => SetProperty(ref _DASSerialNumber, value, "DASSerialNumber"); }
|
||||
|
||||
private double _sampleRate;
|
||||
public double SampleRate { get => _sampleRate; set => SetProperty(ref _sampleRate, value, "SampleRate"); }
|
||||
|
||||
private int _excitationWarmupTimeMS;
|
||||
public int ExcitationWarmupTimeMS { get => _excitationWarmupTimeMS; set => SetProperty(ref _excitationWarmupTimeMS, value, "ExcitationWarmupTimeMS"); }
|
||||
|
||||
private double _aaf;
|
||||
public double HardwareAAF { get => _aaf; set => SetProperty(ref _aaf, value, "HardwareAAF"); }
|
||||
|
||||
private double _preTriggerSeconds;
|
||||
public double PreTriggerSeconds { get => _preTriggerSeconds; set => SetProperty(ref _preTriggerSeconds, value, "PreTriggerSeconds"); }
|
||||
|
||||
private double _postTriggerSeconds;
|
||||
public double PostTriggerSeconds { get => _postTriggerSeconds; set => SetProperty(ref _postTriggerSeconds, value, "PostTriggerSeconds"); }
|
||||
|
||||
private bool _statusLineCheck;
|
||||
public bool StatusLineCheck { get => _statusLineCheck; set => SetProperty(ref _statusLineCheck, value, "StatusLineCheck"); }
|
||||
|
||||
private bool _batteryCheck;
|
||||
public bool BatteryCheck { get => _batteryCheck; set => SetProperty(ref _batteryCheck, value, "BatteryCheck"); }
|
||||
|
||||
private double _inputVoltageMin;
|
||||
public double InputVoltageMin { get => _inputVoltageMin; set => SetProperty(ref _inputVoltageMin, value, "InputVoltageMin"); }
|
||||
|
||||
private double _inputVoltageMax;
|
||||
public double InputVoltageMax { get => _inputVoltageMax; set => SetProperty(ref _inputVoltageMax, value, "InputVoltageMax"); }
|
||||
|
||||
private double _batteryVoltageMin;
|
||||
public double BatteryVoltageMin { get => _batteryVoltageMin; set => SetProperty(ref _batteryVoltageMin, value, "BatteryVoltageMin"); }
|
||||
|
||||
private double _batteryVoltageMax;
|
||||
public double BatteryVoltageMax { get => _batteryVoltageMax; set => SetProperty(ref _batteryVoltageMax, value, "BatteryVoltageMax"); }
|
||||
}
|
||||
}
|
||||
1508
Common/DTS.Common.DataModel/Classes/Hardware/HardwareChannel.cs
Normal file
1508
Common/DTS.Common.DataModel/Classes/Hardware/HardwareChannel.cs
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user