This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1,120 @@
using DTS.Common.Classes.DSP;
using DTS.Common.Enums.Hardware;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Serialization;
namespace DTS.Common.Classes.ClockSync
{
/// <summary>
/// collection for all dsp filters
/// </summary>
public class ClockSyncProfileCollection : Collection<ClockSyncProfile>
{
private static readonly object MyLock = new object();
private static ClockSyncProfileCollection _instance = null;
public static ClockSyncProfileCollection GetCollection()
{
lock (MyLock)
{
if (null != _instance) { return _instance; }
WriteDefaultFileIfMissing(CLOCKSYNC_PROFILE_XML_FILE);
_instance = ReadFile(CLOCKSYNC_PROFILE_XML_FILE);
}
return _instance;
}
private const string CLOCKSYNC_PROFILE_XML_FILE = "ClockSyncProfiles.xml";
private ClockSyncProfileCollection(ClockSyncProfile[] profiles)
{
foreach (var profile in profiles) { Add(profile); }
}
public ClockSyncProfileCollection() { }
public const string NONE_NAME = "None";
public const string PTPIEEE1588_NAME = "PTP IEEE 1588";
public const string IRIGB1PPS_NAME = "IRIG B + 1PPS";
public const string GPS1PPS_NAME = "GPS + 1PPS";
public const string IRIGB_NAME = "IRIG B";
public const string _1PPS_NAME = "1PPS";
public enum ClockSyncProfileDefaults
{
[Display(Name = NONE_NAME, Description = "No master clock input type - RTC from PC only", Order = 0)]
[Browsable(true)]
None = 0,
[Display(Name = PTPIEEE1588_NAME, Description = "Master clock set using Precision Time Protocol IEEE 1588", Order = 1)]
[Browsable(true)]
PTPIEEE1588 = 1 << 0,
[Display(Name = IRIGB1PPS_NAME, Description = "Master clock set using IRIG B on 1 pulse per second", Order = 2)]
[Browsable(true)]
IRIGB1PPS = 1 << 1,
[Display(Name = GPS1PPS_NAME, Description = "Master clock set using GPS on 1 pulse per second", Order = 3)]
[Browsable(true)]
GPS1PPS = 1 << 2,
[Display(Name = IRIGB_NAME, Description ="Master clock set using IRIG B", Order =4)]
[Browsable(true)]
IRIGB = 1 << 3,
[Display(Name = _1PPS_NAME, Description ="Master clock set using 1 pulse per second", Order = 5)]
[Browsable(true)]
_1PPS = 1 << 4
};
private static ClockSyncProfileCollection CreateDefaultCollection()
{
var list = new List<ClockSyncProfile>
{
new ClockSyncProfile(ClockSyncProfileDefaults.None, new DASRestriction[] { new DASRestriction() }),
new ClockSyncProfile(ClockSyncProfileDefaults.PTPIEEE1588, new DASRestriction []{new DASRestriction() }),
new ClockSyncProfile(ClockSyncProfileDefaults.IRIGB1PPS, new DASRestriction[]{new DASRestriction() }),
new ClockSyncProfile(ClockSyncProfileDefaults.GPS1PPS, new DASRestriction[]{new DASRestriction() }),
new ClockSyncProfile(ClockSyncProfileDefaults.IRIGB, new DASRestriction[]{new DASRestriction() }),
new ClockSyncProfile(ClockSyncProfileDefaults._1PPS, new DASRestriction[]{new DASRestriction() }),
};
var collection = new ClockSyncProfileCollection(list.ToArray());
return collection;
}
private static void WriteDefaultFileIfMissing(string filePath)
{
if (File.Exists(filePath)) { return; }
var collection = CreateDefaultCollection();
var serializer = new XmlSerializer(typeof(ClockSyncProfileCollection));
var settings = new XmlWriterSettings() { Indent = true };
using (var writer = XmlWriter.Create(filePath, settings))
{
serializer.Serialize(writer, collection);
}
}
private static ClockSyncProfileCollection ReadFile(string filePath)
{
var deserializer = new XmlSerializer(typeof(ClockSyncProfileCollection));
using (var fs = new FileStream(filePath, FileMode.Open))
{
var cs = (ClockSyncProfileCollection)deserializer.Deserialize(fs);
return cs;
}
}
/// <summary>
/// returns the matching filter, or None if not found, or if none isn't found then the first entry
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public ClockSyncProfile GetClockSyncProfile(string s)
{
var match = Items.FirstOrDefault(x => x.ProfileName == s);
if (null != match) { return match; }
match = Items.FirstOrDefault(x => x.ProfileId == 0);
if (null != match) { return match; }
return Items[0];
}
}
}