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,57 @@
using DTS.Common.Classes.DSP;
using System.ComponentModel.DataAnnotations;
using System;
using System.ComponentModel;
namespace DTS.Common.Classes.ClockSync
{
public class ClockSyncProfile : IClockSyncProfile
{
public int ProfileId { get; set; }
public string ProfileName { get; set; }
public string ProfileDesc { get; set; }
public int DisplayOrder { get; set; }
public bool Visible { get; set; }
public DASRestriction[] FilterRestrictions { get; set; }
public ClockSyncProfile() { }
public ClockSyncProfile(int profileId, string profileName, string profileDesc, int displayOrder, bool visible, DASRestriction[] filterRestrictions)
{
Initialize(profileId, profileName, profileDesc, displayOrder, visible, filterRestrictions);
}
public ClockSyncProfile(ClockSyncProfileCollection.ClockSyncProfileDefaults defaults, DASRestriction[] restrictions)
{
GetProfileInfo(defaults, out var displayName, out var description, out var profileId, out var displayOrder, out var visible);
Initialize(profileId, displayName, description, displayOrder, visible, restrictions);
}
private void Initialize(int profileId, string profileName, string profileDesc, int displayOrder, bool visible, DASRestriction[] filterRestrictions)
{
ProfileId = profileId;
ProfileName = profileName;
ProfileDesc = profileDesc;
DisplayOrder = displayOrder;
Visible = visible;
FilterRestrictions = filterRestrictions;
}
private static void GetProfileInfo(ClockSyncProfileCollection.ClockSyncProfileDefaults profile, out string displayName, out string description, out int profileId,
out int displayOrder, out bool visible)
{
profileId = (int)profile;
var enumType = typeof(ClockSyncProfileCollection.ClockSyncProfileDefaults);
var memberInfos = enumType.GetMember(profile.ToString());
var enumValueMemberInfo = Array.Find(memberInfos, m => m.DeclaringType == enumType);
var valueAttributes = enumValueMemberInfo.GetCustomAttributes(typeof(DisplayAttribute), false);
description = ((DisplayAttribute)valueAttributes[0]).GetDescription();
displayName = ((DisplayAttribute)valueAttributes[0]).GetName();
displayOrder = ((DisplayAttribute)valueAttributes[0]).GetOrder() ?? int.MaxValue;
valueAttributes = enumValueMemberInfo.GetCustomAttributes(typeof(BrowsableAttribute), false);
visible = ((BrowsableAttribute)valueAttributes[0]).Browsable;
}
public override string ToString()
{
return ProfileName;
}
}
}

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];
}
}
}

View File

@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
namespace DTS.Common.Classes.ClockSync
{
/// <summary>
/// this converter is used for displaying StreamingFilterCollection/array in property grids
/// </summary>
public class ClockSyncProfileConverter : ArrayConverter
{
private ClockSyncProfileCollection _collection = null;
private static readonly object MyLock = new object();
private ClockSyncProfile[] _values = null;
private ClockSyncProfileCollection GetCollection()
{
lock (MyLock)
{
if (null == _collection)
{
_collection = ClockSyncProfileCollection.GetCollection();
}
return _collection;
}
}
public ClockSyncProfile[] Values
{
get
{
lock (MyLock)
{
if (null == _values)
{
var collection = GetCollection();
var list = new List<ClockSyncProfile>();
using (var e = collection.GetEnumerator())
{
while (e.MoveNext())
{
if( null != e.Current && e.Current.Visible)
{
list.Add(e.Current);
}
}
}
list.Sort((x,y) => { return x.DisplayOrder.CompareTo(y.DisplayOrder); });
_values = list.ToArray();
}
}
return _values;
}
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string)) { return true; }
return base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
var result = Array.Find(Values, x => x.ProfileName == (string)value);
if (result != null) { return result; }
return base.ConvertFrom(context, culture, value);
}
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return true;
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
var collection = GetCollection();
return new StandardValuesCollection(collection);
}
}
}

View File

@@ -0,0 +1,14 @@
using DTS.Common.Classes.DSP;
namespace DTS.Common.Classes.ClockSync
{
public interface IClockSyncProfile
{
int ProfileId { get; set; }
string ProfileName { get; set; }
string ProfileDesc { get; set; }
int DisplayOrder { get; set; }
bool Visible { get; set; }
DASRestriction[] FilterRestrictions { get; set; }
}
}