Files
DP44/DataPRO/Modules/DatabaseImporter/DatabaseImport/SerializedSettings.cs

262 lines
11 KiB
C#
Raw Normal View History

2026-04-17 14:55:32 -04:00
using System;
using System.Collections.Generic;
namespace DatabaseImport
{
public sealed class SerializedSettings
{
public enum Keys
{
IgnorePowerMode,
UseUserCodes,
NumberRealtimeCharts,
UseCircBufTriggerCheck,
TriggerCheckPostRealtime,
DeriveROIFromAll,
// ReSharper disable once InconsistentNaming
CRIBCOM,
LastEventStartTime,
ExportINIFile,
ShowISOCodes,
UseMeterModeTable,
AutoArmDiagLevel,
AutoArmDiagDelayMS,
RealtimeSampleRates,
RealtimeSampleRate,
OverheadPercent,
AutozeroRealtime,
AllowCalculatedChannels,
AllowLevelTriggerUI,
TDASCalPeriod,
G5CalPeriod,
Slice1CalPeriod,
Slice1_5CalPeriod,
Slice2_CalPeriod,
CalWarningPeriod,
CalHWGracePeriod,
HardwareCalPolicy,
DefaultRecordingMode,
DefaultIsoChannelSensorCompatibilityLevel,
AllowAdvancedRecordingModes,
AllowTSRAIRRecordingModes,
IncludeGroupNameInISOExport,
WarnIfTestCancelledWithoutExport,
DiademChannelName200Option,
DiademUserComment201Option,
StartingTestSetup,
SensitivityDisplayFormat,
TriggerSecondsDisplayFormat,
NonLinearDisplayFormat,
CapacityRangeDisplayFormat,
TestSetupDefaultAutomaticMode,
CommonStatusLine,
AutomaticModeDelayMS,
IsoSupportLevel,
TriggerCheckQuickMode,
Diagnostics_TDAS_TimeoutSec,
Diagnostics_SLICE_TimeoutSec,
ResolveChannels_TDAS_QueryDownloadTimeoutSec,
ResolveChannels_SLICE_QueryDownloadTimeoutSec,
ResolveChannels_TDAS_QueryConfigTimeoutSec,
ResolveChannels_SLICE_QueryConfigTimeoutSec,
SLICE_CONNECT_ALLOWED_SECONDS,
TDAS_CONNECT_ALLOWED_SECONDS,
ISOSupport_Allow_Transitional,
ISOSupport_Allow_NonISO,
TestSetup_AllowQuickTestSetup,
Graphs_PFSZoomValues,
AutoAdd_ArmChecklist,
TESTSETUP_WARNBATFAIL,
TESTSETUPDEFAULT_DONTALLOWOUTOFCALSENSOR,
SPSINDICE_COUNT,
TDAS_MAXAAFRATE,
G5_MAXAAFRATE,
DefaultDigitalOutMode,
DownloadMode,
SLICE_Distributor_PowerSetting,
TDAS_Pro_Rack_PowerSetting,
G5VDS_PowerSetting,
SLICE1_5_Nano_Base_PowerSetting,
SLICE_Micro_Base_PowerSetting,
SLICE_NANO_Base_PowerSetting,
SLICE2_SIM_PowerSetting,
SLICE2_DIM_PowerSetting,
SLICE2_TOM_PowerSetting,
G5INDUMMY_PowerSetting,
SLICE_EthernetController_PowerSetting,
SLICE1_5_Micro_Base_PowerSetting,
SLICE_LabEthernet_PowerSetting,
SLICE2_SLS_PowerSetting,
SLICE1_G5Stack_PowerSetting,
SLICE2_SLT_PowerSetting,
SLICE2_SLD_PowerSetting,
RealtimeSampleRateSliceUSB,
RealtimeSampleRateSliceIP,
RealtimeSampleRateTDASG5,
MaxParallelTDASDownloads,
UseTestSetupNameForTestIDHeaderInCSVExport,
TestIDPrefixSuffixValues,
SLICE6_PowerSetting,
SLICE6_CalPeriod,
WarnOnEIDPositionSwap,
AllowEIDSensorsOutOfPlace,
SLICE6MulticastResponsePort,
SLICE6MulticastCommandPort,
SLICE6MulticastAddress,
ClearDBBeforeTSFImport,
SLICE6Db_PowerSetting,
UseLegacyTOMCFC,
UseLegacyTDCSoftwareFilterAdjustment,
AllowModify,
ApplyShiftT0ModsTestOnly,
POWERPRO_CalPeriod,
SLICE6Air_CalPeriod,
SLICE6DB_CalPeriod,
TSRAir_CalPeriod,
LevelTriggerMaxPercentage,
LevelTriggerMinPercentage
}
public const string ExportINIFileDefault = "";
/// <summary>
/// the location of the export INI file in use.
/// This is used by GMMilford to control the directories of some export files
/// </summary>
public static string ExportINIFile
{
get => SettingsDB.GetGlobalValue(Keys.ExportINIFile.ToString(), ExportINIFileDefault);
set => SettingsDB.SetGlobalValue(Keys.ExportINIFile.ToString(), value);
}
public static IsoChannelSensorCompatibilityLevels IsoChannelSensorCompatibilityLevelDefault = IsoChannelSensorCompatibilityLevels.Warn;
public static IsoChannelSensorCompatibilityLevels IsoChannelSensorCompatibilityLevel
{
get
{
var s = SettingsDB.GetGlobalValue(Keys.DefaultIsoChannelSensorCompatibilityLevel.ToString(), IsoChannelSensorCompatibilityLevelDefault.ToString());
return !Enum.TryParse(s, out IsoChannelSensorCompatibilityLevels isoChannelSensorCompatibilityLevel) ? IsoChannelSensorCompatibilityLevelDefault : isoChannelSensorCompatibilityLevel;
}
set => SettingsDB.SetGlobalValue(Keys.DefaultIsoChannelSensorCompatibilityLevel.ToString(), value.ToString());
}
public enum ISOSupportLevels
{
ISO_ONLY, //channels named by iso
TRANSITORY, //UserValue1 for JCODE/Chimchim/etc, which takes the place of isocode in multiple places
NO_ISO //channels named by user only
}
public const ISOSupportLevels ISOSupportLevelDefault = ISOSupportLevels.ISO_ONLY;
public static ISOSupportLevels ISOSupportLevel
{
get
{
var s = SettingsDB.GetGlobalValue(Keys.IsoSupportLevel.ToString(), ISOSupportLevelDefault.ToString());
ISOSupportLevels level;
return !Enum.TryParse(s, out level) ? ISOSupportLevels.ISO_ONLY : level;
}
set => SettingsDB.SetGlobalValue(Keys.IsoSupportLevel.ToString(), value.ToString());
}
/// <summary>
/// returns a dictionary of sensor type to iso physical dimension
/// </summary>
/// <returns></returns>
public static Dictionary<string, string> GetAllSensorTypeToDimensionMappings()
{
var d = new Dictionary<string, string>();
foreach (var m in AllSensorTypeToDimensions)
{
if (!d.ContainsKey(m.Code)) { d[m.Code] = m.Dimension; }
}
return d;
}
// key for how many mappings are present
private const string NUM_SENSORTYPE_MAPPINGS = "NUM_SENSORTYPE_MAPPINGS";
// key for each individual mapping
private const string SENSORTYPE_MAPPING_PRE = "SENSORTYPE_";
/// <summary>
/// returns all Sensor type to ISO physical dimension mappings
/// </summary>
public static SensorTypeToDimension[] AllSensorTypeToDimensions
{
get
{
var sMappings = SettingsDB.GetGlobalValue(NUM_SENSORTYPE_MAPPINGS, "7");
var iMappings = 7;
int.TryParse(sMappings, out iMappings);
var mappings = new List<SensorTypeToDimension>();
for (var i = 0; i < iMappings; i++)
{
var s = GetSensorTypeMapping(i);
if (null != s) { mappings.Add(s); }
}
return mappings.ToArray();
}
set
{
for (var i = 0; i < value.Length; i++) { SetSensorTypeMapping(i, value[i]); }
SettingsDB.SetGlobalValue(NUM_SENSORTYPE_MAPPINGS, value.Length.ToString());
}
}
/// <summary>
/// stores one sensor type to iso physical dimension
/// used by AllSensorTypeToDimensions
/// </summary>
/// <param name="index"></param>
/// <param name="dim"></param>
private static void SetSensorTypeMapping(int index, SensorTypeToDimension dim)
{
var s = string.Format("{0}{1}{2}{1}{3}", dim.Code, (char)149, dim.Name, dim.Dimension);
SettingsDB.SetGlobalValue(string.Format("{0}{1}", SENSORTYPE_MAPPING_PRE, index), s);
}
private static SensorTypeToDimension GetSensorTypeMapping(int index)
{
switch (index)
{
case 0: return GetSensorTypeMapping(index, "D", "Acceleration", "AC");
case 1: return GetSensorTypeMapping(index, "F", "Force", "FO");
case 2: return GetSensorTypeMapping(index, "M", "Momentum", "MO");
case 3: return GetSensorTypeMapping(index, "S", "Displacement", "DS");
case 4: return GetSensorTypeMapping(index, "W", "Angular Acceleration", "AA");
case 5: return GetSensorTypeMapping(index, "A", "Angle", "AN");
case 6: return GetSensorTypeMapping(index, "B", "Voltage", "VO");
default: return GetSensorTypeMapping(index, "", "", "");
}
}
/// <summary>
/// retrieves an individual sensor type to iso code mapping (or null if there isn't such a mapping)
/// </summary>
/// <param name="index"></param>
/// <param name="code"></param>
/// <param name="name"></param>
/// <param name="dimension"></param>
/// <returns></returns>
private static SensorTypeToDimension GetSensorTypeMapping(int index, string code, string name, string dimension)
{
var s = SettingsDB.GetGlobalValue(string.Format("{0}{1}", SENSORTYPE_MAPPING_PRE, index), string.Format("{0}{1}{2}{1}{3}", code, (char)149, name, dimension));
var tokens = s.Split(new char[] { (char)149 });
if (tokens.Length < 3) { return null; }
var s1 = tokens[0];
var s2 = tokens[1];
var s3 = tokens[2];
if (string.IsNullOrWhiteSpace(s1) || string.IsNullOrWhiteSpace(s2) || string.IsNullOrWhiteSpace(s3)) { return null; }
return new SensorTypeToDimension(code, name, dimension);
}
public class SensorTypeToDimension : Tuple<string, string, string>
{
public SensorTypeToDimension(string sensorType, string name, string dimension) : base(sensorType, name, dimension) { }
public string Code => Item1;
public string Name => Item2;
public string Dimension => Item3;
}
public const bool TestSetupDefaultDontAllowOutOfCalSensorsDefault = false;
public static bool TestSetupDefaultDontAllowOutOfCalSensors
{
get => SettingsDB.GetGlobalValueBool(Keys.TESTSETUPDEFAULT_DONTALLOWOUTOFCALSENSOR.ToString(), TestSetupDefaultDontAllowOutOfCalSensorsDefault);
set => SettingsDB.SetGlobalValueBoolean(Keys.TESTSETUPDEFAULT_DONTALLOWOUTOFCALSENSOR.ToString(), value);
}
}
}