8.1 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||||
|---|---|---|---|---|---|---|---|---|
|
2026-04-16T03:15:09.204079+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | e412b56844d5af45 |
ClockSync
Documentation: Clock Sync Profile Module
1. Purpose
This module defines and manages clock synchronization profiles for the DTS system, enabling configuration of different master clock input sources (e.g., PTP IEEE 1588, IRIG-B, GPS, 1PPS). It provides a singleton collection (ClockSyncProfileCollection) that loads profile definitions from an XML file (ClockSyncProfiles.xml), falling back to a default set if the file is missing. Profiles are represented by the ClockSyncProfile class, which implements the IClockSyncProfile interface and supports metadata-driven initialization from an enum (ClockSyncProfileDefaults). The module also includes a type converter (ClockSyncProfileConverter) for UI integration (e.g., property grids), ensuring only visible profiles are exposed and sorted by display order.
2. Public Interface
IClockSyncProfile (Interface)
int ProfileId { get; set; }
Unique integer identifier for the profile.string ProfileName { get; set; }
Human-readable name of the profile (e.g.,"PTP IEEE 1588").string ProfileDesc { get; set; }
Description of the profile’s behavior or purpose.int DisplayOrder { get; set; }
Integer priority for ordering profiles in UI (lower values appear first).bool Visible { get; set; }
Flag indicating whether the profile should be shown in UI (e.g., property grids).DASRestriction[] FilterRestrictions { get; set; }
Array of restrictions (of typeDASRestriction) applied to the profile; used to filter applicable DAS configurations.
ClockSyncProfile (Concrete Implementation)
ClockSyncProfile()
Parameterless constructor for deserialization.ClockSyncProfile(int profileId, string profileName, string profileDesc, int displayOrder, bool visible, DASRestriction[] filterRestrictions)
Initializes a profile with explicit values viaInitialize().ClockSyncProfile(ClockSyncProfileCollection.ClockSyncProfileDefaults defaults, DASRestriction[] restrictions)
Initializes a profile by extracting metadata (name, description, order, visibility) from theClockSyncProfileDefaultsenum using reflection on[Display]and[Browsable]attributes, then callsInitialize().override string ToString()
ReturnsProfileName.
ClockSyncProfileConverter (Type Converter)
ClockSyncProfile[] Values { get; }
Lazily-initialized array of visible profiles from the singleton collection, sorted byDisplayOrder. Thread-safe vialock.override bool CanConvertFrom(...)
ReturnstrueifsourceType == typeof(string)(enables string-to-profile conversion by name).override object ConvertFrom(...)
Converts a string (profile name) to aClockSyncProfileinstance by matchingProfileNameinValues. Returnsnullif no match.override bool GetStandardValuesSupported(...)
Returnstrue(indicates standard values are available).override bool GetStandardValuesExclusive(...)
Returnstrue(indicates only standard values are valid; no free-text input).override StandardValuesCollection GetStandardValues(...)
Returns aStandardValuesCollectioncontaining all profiles from the singleton collection (including non-visible ones).
ClockSyncProfileCollection (Singleton Collection)
static ClockSyncProfileCollection GetCollection()
Thread-safe singleton accessor. Loads profiles fromClockSyncProfiles.xml(creating it with defaults if missing).ClockSyncProfile GetClockSyncProfile(string s)
Returns the first profile matchingProfileName == s. If no match, returns the profile withProfileId == 0(typically"None"). If neither exists, returns the first item in the collection.- Constants:
NONE_NAME,PTPIEEE1588_NAME,IRIGB1PPS_NAME,GPS1PPS_NAME,IRIGB_NAME,_1PPS_NAME
Hardcoded string constants for profile names (e.g.,"PTP IEEE 1588").
ClockSyncProfileDefaultsEnum:
Defines default profile types with[Display]and[Browsable]attributes:None(ID=0)PTPIEEE1588(ID=1)IRIGB1PPS(ID=2)GPS1PPS(ID=4)IRIGB(ID=8)_1PPS(ID=16)
Values use bit-shifted powers of two (e.g.,1 << 0,1 << 1), but IDs are cast tointdirectly inGetProfileInfo().
3. Invariants
- Singleton Consistency:
GetCollection()always returns the same instance after first initialization. - Profile Visibility Filtering:
ClockSyncProfileConverter.Valuesonly includes profiles whereVisible == true. - Display Order Sorting:
ClockSyncProfileConverter.Valuesis sorted ascending byDisplayOrder(usingint.MaxValueas fallback for missing order). - Fallback Profile Selection:
GetClockSyncProfile(string)prioritizes exact name match, thenProfileId == 0, then first item. - XML File Handling:
ClockSyncProfiles.xmlis auto-generated with defaults if missing; existing file is never overwritten. - Enum Metadata Dependency:
ClockSyncProfile’s enum-based constructor relies on[Display]and[Browsable]attributes being present onClockSyncProfileDefaultsmembers. Missing attributes cause runtime exceptions (e.g.,IndexOutOfRangeExceptiononvalueAttributes[0]).
4. Dependencies
- Internal Dependencies:
DTS.Common.Classes.DSP.DASRestriction(used inFilterRestrictions).System.ComponentModel.DataAnnotations(for[Display],[Browsable]).System.Xml.Serialization(for XML serialization/deserialization).System.Collections.ObjectModel.Collection<T>(base class).
- External Dependencies:
ClockSyncProfileCollectiondepends onDASRestrictiontype (defined elsewhere inDTS.Common).ClockSyncProfileConverterdepends onClockSyncProfileCollection(singleton access).
- Depended Upon By:
- UI components (e.g., property grids) via
ClockSyncProfileConverter. - Other modules requiring clock sync configuration (e.g., DSP configuration logic).
- UI components (e.g., property grids) via
5. Gotchas
- Enum ID Mismatch:
ClockSyncProfileDefaultsuses bit-shifted values (e.g.,1 << 0 = 1,1 << 1 = 2), butGetProfileInfo()casts the enum value directly tointforprofileId. This meansIRIGB1PPShasProfileId = 2, not1. Ensure downstream logic does not assume sequential IDs. - Attribute Dependency: If
[Display]or[Browsable]attributes are missing on aClockSyncProfileDefaultsmember,GetProfileInfo()throwsIndexOutOfRangeException(accessingvalueAttributes[0]without null checks). - Thread-Safe Lazy Initialization:
ClockSyncProfileConverter.Valuesuses double-checked locking but reinitializes_valuesonly once per app domain. Subsequent modifications to the collection (e.g., viaGetCollection().Add(...)) will not update_valuesuntil the converter is recreated. - Non-Visible Profiles in StandardValues:
GetStandardValues()returns all profiles (including non-visible ones), whileValuesreturns only visible ones. This inconsistency may confuse consumers expecting uniform filtering. - Hardcoded XML Filename:
CLOCKSYNC_PROFILE_XML_FILE = "ClockSyncProfiles.xml"is hardcoded; no configuration override is provided. - No Validation on
FilterRestrictions:FilterRestrictionsis aDASRestriction[]with no null-checking or validation in constructors. Passingnullmay causeNullReferenceExceptiondownstream. - No Profile Modification Support: The collection is read-only after initialization (via
Collection<T>base). Adding/removing profiles at runtime requires direct manipulation ofItems, which bypasses validation.
None identified beyond these.