9.7 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||
|---|---|---|---|---|---|---|
|
2026-04-16T03:56:57.762497+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 49767c75e3daaeaa |
CAN
Documentation: CAN Configuration Module (DTS.DASLib.Service)
1. Purpose
This module provides XML-based serialization and deserialization for CAN (Controller Area Network) hardware configuration data in the DAS (Data Acquisition System) service layer. It enables persistent storage and retrieval of system-wide CAN module configurations (CANConfig) and per-module settings (CANModuleConfig), including channel definitions, recording parameters, and firmware metadata. The classes implement IXmlSerializable to support custom XML formatting, allowing configuration files to be stored in a human-readable and version-tolerant manner under the DASConfigs subdirectory relative to the executing assembly.
2. Public Interface
CANConfig class
-
public Dictionary<string, CANModuleConfig> Modules { get; }
Read-only dictionary mapping module serial numbers (string keys) toCANModuleConfiginstances. Represents all configured CAN modules. -
public string FileName { get; }
Full path to the XML file from which thisCANConfiginstance was loaded (or to which it will be written). Set only during construction. -
public CANConfig()
Default constructor. Initializes an empty configuration with no modules or file association. -
public CANConfig(string fileName, bool deleteIfPresent)
Constructor that attempts to load configuration fromfileName(relative toDASConfigs/subdirectory). IfdeleteIfPresentistrue, the file is deleted before loading (resulting in an empty config). Iffalse, the file is read viaReadXml. Exceptions during file I/O or XML parsing are logged viaAPILogger. -
public void SetModule(CANModuleConfig module)
Inserts or updates a module in the_modulesdictionary usingmodule.SerialNumberas the key. No validation beyond key existence. -
public CANModuleConfig GetModule(CANModuleConfig module)
Returns the module stored undermodule.SerialNumber. If not present, inserts the providedmoduleinstance into the dictionary and returns it. Note: This mutates the config even when the module is not yet known. -
public XmlSchema GetSchema()
Returnsnull. Required byIXmlSerializablebut unused. -
public void ReadXml(XmlReader reader)
Deserializes XML starting at<CANConfig>root. Reads a<Modules>section containing multiple<CANModule>elements. Each<CANModule>is deserialized into aCANModuleConfigand added viaSetModule. -
public void WriteXml(XmlWriter writer)
Serializes the configuration as<CANConfig><Modules>...</Modules></CANConfig>. EachCANModuleConfigis written via its ownWriteXmlmethod, withwriter.Flush()called after writing the<Modules>start tag and after each module.
CANModuleConfig class
-
public string SerialNumber { get; set; }
Unique identifier for the CAN module (used as dictionary key inCANConfig.Modules). -
public string TestId { get; set; }
Identifier for the test associated with this module. -
public string TestDescription { get; set; }
Human-readable description of the test. -
public DFConstantsAndEnums.RecordingMode RecordingMode { get; set; }
Recording mode enum (e.g., continuous, event-triggered). Defaults toInvalidArmMode. -
public float AAFilterRateHz { get; set; }
Anti-aliasing filter rate in Hz. Default0. -
public double PreTriggerSeconds { get; set; }
Duration (seconds) of data to capture before a trigger event. Default0. -
public double PostTriggerSeconds { get; set; }
Duration (seconds) of data to capture after a trigger event. Default0. -
public string FirmwareVersion { get; set; }
Firmware version string reported by the module. -
public UInt64? MaxEventStorageSpaceInBytes { get; set; }
Optional maximum storage space (in bytes) for event-triggered recordings. Nullable; defaults to0. -
public int ModuleArrayIndex { get; set; }
Index of the module in a logical array (e.g., for ordering). Default0. -
public string FileName { get; }
Full path to the XML file from which this module config was loaded. Set only during construction. -
public CANModuleConfig()
Default constructor. Initializes all properties to defaults. -
public CANModuleConfig(string fileName)
Constructor that loads configuration fromfileName(relative toDASConfigs/). Logs errors on failure. -
public void SetChannel(CANInputDASChannel channel)
Inserts or updates a channel in the internal_channelsdictionary usingchannel.ModuleChannelNumberas the key. -
public CANInputDASChannel GetChannel(CANInputDASChannel channel)
Returns the channel stored underchannel.ModuleChannelNumber. If not present, inserts the providedchanneland returns it. Note: Mutates config on miss. -
public XmlSchema GetSchema()
Returnsnull. Required byIXmlSerializablebut unused. -
public void ReadXml(XmlReader reader)
Deserializes XML starting at<CANModule>. Reads scalar properties (SerialNumber,TestId, etc.) and the<Channels>section. ForRecordingMode,AAFilterRateHz,PreTriggerSeconds,PostTriggerSeconds, andMaxEventStorageSpaceInBytes, parsing errors are logged and defaults retained.ModuleArrayIndexis read viaReadModuleArray, which silently ignores errors (for backward compatibility with older config files). -
public void WriteXml(XmlWriter writer)
Serializes the module as<CANModule>...</CANModule>. Writes all scalar properties and the<Channels>section. For each channel, callsWriteElementStart,WriteXml, andWriteElementEndon the channel object. -
public virtual void WriteElementStart(XmlWriter writer)
Writes<CANModule xsi:type="...">where...is the runtime type name (e.g.,CANInputDASChannel). Allows polymorphic deserialization. -
public virtual void WriteElementEnd(XmlWriter writer)
Writes</CANModule>.
3. Invariants
SerialNumberuniqueness: Within aCANConfig.Modulesdictionary, keys areSerialNumberstrings. Duplicate keys are overwritten (not rejected).ModuleChannelNumberuniqueness: Within aCANModuleConfig._channelsdictionary, keys areModuleChannelNumberintegers. Duplicate keys are overwritten.- XML structure:
CANConfigXML root is<CANConfig>, containing<Modules>with nested<CANModule>elements.CANModuleConfigXML root is<CANModule>. - Backward compatibility:
ReadModuleArraysilently ignores missing or malformedModuleArrayIndexelements, assuming older config files may lack them. - Default values: All numeric/string properties have non-null defaults (e.g.,
""for strings,0for numerics,InvalidArmModeforRecordingMode).MaxEventStorageSpaceInBytesdefaults to0(notnull). - File paths: All file paths are constructed relative to the executing assembly’s directory, under
DASConfigs/<fileName>.
4. Dependencies
-
Internal dependencies:
DTS.Common.Utilities.Logging.APILoggerfor error logging (used in constructors,ReadXml,WriteXml, andReadModuleArray).DTS.Common.Enums.DASFactory.DFConstantsAndEnums.RecordingModeenum (used inRecordingModeproperty).DASChannel(base class) andCANInputDASChannel(concrete channel type) for channel storage and serialization. Note:DASChannelis referenced but not defined in the provided sources.
-
External dependencies:
System.Xml,System.Xml.Serialization,System.IO,System.Reflection(standard .NET libraries).- File system access (for reading/writing XML files in
DASConfigs/).
-
Depended upon by:
Unknown from source alone. Likely consumed by higher-level DAS service components (e.g., configuration managers, CAN interface drivers) that initialize or update CAN module settings.
5. Gotchas
GetModule/GetChannelmutate on miss: Both methods add the provided module/channel to the internal dictionary if not found, which may be unintended (e.g., during read-only queries). Consider renaming or clarifying intent.- No validation on
SerialNumber/ModuleChannelNumber: Duplicates are silently overwritten. No uniqueness enforcement beyond dictionary semantics. ReadModuleArrayswallows errors: Thecatchblock inReadModuleArrayignores all exceptions, potentially masking real issues (e.g., malformed XML). This is intentional for backward compatibility but may complicate debugging.MaxEventStorageSpaceInBytesrange check is incomplete: The conditiond >= 0 && d < ulong.MaxValueallowsd == ulong.MaxValue, butConvert.ToUInt64(d)will throw ford == ulong.MaxValue(sincedoublemay not represent it exactly). Should used <= ulong.MaxValue - 1or similar.- No
WriteXmloverride for baseDASChannel: TheWriteXmlmethod iterates over_channels.ValuesasDASChannel, but onlyCANInputDASChannelis instantiated inReadXml. If otherDASChannelsubclasses exist,WriteElementStart/WriteElementEndmust be overridden appropriately. - Hardcoded path construction:
Path.Combine(Path.GetDirectoryName(...), "DASConfigs", fileName)assumesDASConfigsis a subdirectory of the assembly directory. May fail in non-standard deployment scenarios (e.g., single-file publish). - No XML validation schema:
GetSchema()returnsnull, so no schema validation occurs during deserialization. Malformed XML may cause runtime errors or silent data loss.
None identified beyond the above.