11 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
2026-04-16T03:38:54.525487+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 8202fee238e4de73 |
TDAS Serialization Module Documentation
1. Purpose
This module provides serialization and deserialization support for TDAS (Test Data Acquisition System) files, specifically handling .tlf (text-based metadata) and .BIN (binary channel data) file formats used by Diversified Technical Systems, Inc. It defines core types—including File, Writer, Reader, PersistentChannel, and supporting classes like TDASBinaryChannelHeader—to manage test metadata, channel headers, and raw data. The module enables structured export/import of test data with support for channel-specific metadata (e.g., acquisition rate, calibration levels, signal-to-noise ratio), CRC validation, and exception handling for common file-level and data-level errors.
2. Public Interface
Exception Types
All exception types are nested within File or File.PersistentChannel and extend Exception or ApplicationException. Each provides three constructors: parameterless, string msg, and string msg, Exception innerEx.
-
File.Reader.BadCrcException
Thrown when a CRC validation failure occurs during file reading (e.g., corrupted binary channel data or header). -
File.Reader.MissingFileException
Thrown when an expected file (e.g.,.tlfor.BIN) is not found during deserialization. -
File.Reader.TooManyFilesException
Thrown when the number of channel files exceeds an internal limit during deserialization. -
File.PersistentChannel.NotInitializedException
Thrown when attempting to access a property ofPersistentChannelthat has not yet been initialized (e.g., readingDatabefore it's loaded). -
File.PersistentChannel.DataTooBigForArrayException
Thrown when attempting to materialize a large dataset into an array that exceeds safe memory constraints.
Core Types
-
File
Main entry point for TDAS file operations. ExtendsSerialization.Fileand implementsIWritable<Test>.static string Extension => ".tlf"
The file extension for the primary metadata file.static string TestFileExtension => ".tlf"
Alias forExtension; used for test metadata files.static string ChannelFileExtension => ".BIN"
File extension for binary channel data files.static string CalculatedChannelFileExtension => ".cchn"
File extension for calculated channel files.IWriter<Test> Exporter
Lazily-initialized writer instance for serializingTestobjects.IReader<Test> Importer
Lazily-initialized reader instance for deserializingTestobjects.int GetChannelNumberFromChannelFileName(string channelFileName)
Extracts the 3-digit channel number from a channel filename (e.g.,"test.tlf001.BIN"→1). Throws if parsing fails.
-
File.TDASBinaryChannelHeader
ImplementsIChannelHeaderand encapsulates binary channel header fields. Used to serialize/deserialize header metadata and compute CRCs.- Properties (get/set):
AcquisitionRate,NumberOfPreT0DataPoints,NumberOfPostT0DataPoints,
PreZeroLevelInCnts,PreCalLevelInCnts,SignalToNoiseRatioInDb,
PostZeroLevelInCnts,PostCalLevelInCnts,DataZeroLevelInCnts,
ScaleFactorMVPerCnt,ScaleFactorEUPerCnt. UInt32 Crc32 { get; }
Computes CRC32 over all header fields (no EU string padding stripping).UInt32 UnpaddedEuCrc32 { get; }
Computes CRC32 with EU string padding stripped.UInt32 UnpaddedEuStringPaddedEuLengthCrc32 { get; }
Computes CRC32 with EU string stripped but EU length field included.private UInt32 CalculateCrc32(bool stripEuPadding, bool bKeepEuLength)
Internal CRC calculation usingUtils.Math_DoCRC16Stepon 16-bit word pairs of header data.
- Properties (get/set):
-
File.Writer
Internal class implementingIWriter<Test>for writingTestobjects to disk.void Write(string pathname, string id, string dataFolder, Test test, ...)
Writes aTestto disk:- Serializes metadata to
<pathname>.tlfusingTLFclass. - Creates backup copy of
.tlffile. - Writes binary channel data to
<pathname>.NNN.BINfiles (.BINextension), whereNNNis a 3-digit channel number. - Supports event callbacks (
beginEventHandler,tickEventHandler,errorEventHandler, etc.). - Throws
NotSupportedExceptionfor the 5-parameter overload.
- Serializes metadata to
void Initialize(...)
Currently a no-op stub.
-
IChannelHeader
Interface defining contract for channel header metadata (implemented byTDASBinaryChannelHeader).
All properties are get/set; seeTDASBinaryChannelHeaderfor descriptions. -
TLFBin
Helper class for serializing binary channel data with resampling and scaling.- Properties (get/set):
AcquisitionRate,PreTriggerDataPoints,PostTriggerDataPoints,
PreZeroLevel,PreCalLevel,SignalToNoiseRatio,
PostZeroLevel,PostCalLevel,SuperSampleRate. TLFBin(Test.Module.Channel channel, double superSampleRate)
Constructor computes header fields and scaling parameters fromchannelandsuperSampleRate.PreCalLevelis hardcoded to0.7 * short.MaxValue(10922).SignalToNoiseRatiocomputed fromNoiseAsPercentageOfFullScaleand full-scale ADC range.PostZeroLevelandPostCalLevelare currently unimplemented (set to0).
void Serialize(BinaryWriter bw, Test.Module.Channel channel)
Writes binary data toBinaryWriter:- Writes header (11 fields:
SuperSampleRate,PreTriggerDataPoints, ...,ScaleFactorEUPerCnt). - Writes resampled ADC values (16-bit signed) for each sample, with interpolation.
- For digital inputs (
Bridge == DigitalInput), writes 16-bit digital values based onDigitalModeandDigitalMultiplier. - For linearized sensors, constrains
newADCtoshort.MinValue/short.MaxValueto avoid underflow.
- Writes header (11 fields:
- Properties (get/set):
3. Invariants
-
File Naming Convention:
Channel binary files follow<base>.NNN.BIN, whereNNNis a 3-digit channel number (e.g.,001,002,901for squib channels). Channel numbers are extracted viaGetChannelNumberFromChannelFileName, which assumes the last 3 characters before.BINare digits. -
CRC Computation:
CRC32 is computed over 16-bit words (little-endian) of header data. Padding is added if data length is odd. UsesUtils.Math_DoCRC16Step(not standard CRC32), and the result is returned asUInt32. -
Data Resampling:
TLFBin.Serializeresamples data toSuperSampleRateusing linear interpolation. The resampling factorrate = ceil(SuperSampleRate / AcquisitionRate)is applied per sample. -
Digital Input Handling:
Digital channels output 16-bit values based onDigitalMode(e.g.,CCNC,TLH) and thresholds (breakPoint). Values are determined per interpolated step. -
Linearization Constraints:
For linearized sensors,newADCis clamped toshort.MinValue/short.MaxValueto prevent overflow/underflow during serialization (seeTLFBin.Serialize).
4. Dependencies
-
Internal Dependencies:
DTS.Common.Utilities.DotNetProgrammingConstructs.Property<T>(used inFilefor static extension properties).DTS.Common.Utilities.Logging.APILogger(used inFile.Writer.Writefor error logging).DTS.Common.ConstantandDTS.Common.Enums.Sensors.SensorConstants(used inTLFBinconstructor forBridgeType.DigitalInput).DTS.Common.Enums.DigitalInputModes(used inTLFBin.Serializefor digital input mode handling).SliceRaw.File.Reader.GetDataScaler(used inTLFBin.Serializeto obtain scaling parameters).Utils.Math_DoCRC16Step(used inTDASBinaryChannelHeader.CalculateCrc32).Serialization.File,IWriter<Test>,IReader<Test>(base types forFile,Writer, andReader).
-
External Dependencies:
System,System.IO,System.Linq,System.Text,System.Collections.Generic(standard .NET libraries).DTS.Serialization.Testand its nested types (Test.Module.Channel,Test.Module.AnalogInputChannel,Test.Module.Channel.PersistentChannelInfo).FilteredData,BeginEventHandler,CancelEventHandler, etc. (event delegates for progress/error callbacks).
5. Gotchas
-
TDASBinaryChannelHeader.CalculateCrc32uses CRC16, not CRC32:
Despite the property names (Crc32,UnpaddedEuCrc32, etc.), the implementation computes a 16-bit CRC usingMath_DoCRC16Stepand returns it asUInt32. This is likely a historical naming inconsistency. -
PreCalLevelis hardcoded:
InTLFBinconstructor,PreCalLevelis set to0.7 * short.MaxValue(10922) instead of a configurable value. The comment suggests this is a placeholder. -
PostZeroLevelandPostCalLevelare unimplemented:
Both are set to0inTLFBinconstructor with@TODOcomments indicating missing data sources. -
Digital input
breakPointlogic is complex and mode-dependent:
Thresholds differ byDigitalMode(e.g.,CCNCvsTLH) and input type (current vs voltage). Misconfiguration may lead to incorrect digital output values. -
TLFBin.Serializemay produce out-of-range values for linearized sensors:
AlthoughnewADCis clamped toshort.MinValue/short.MaxValue, the comment notes this was added to fix underflow in bug #14496. Ensure scaling factors and sensor capacities are valid to avoid unexpected clamping. -
Channel number extraction is fragile:
GetChannelNumberFromChannelFileNameassumes filenames end with.BINor.binand that the 3 characters before the extension are digits. Filenames like_C001.BINare handled, but edge cases (e.g.,.BINin middle of name) may cause errors. -
File.Writer.Writehas two overloads, only one implemented:
The 5-parameter overload throwsNotSupportedException. Ensure callers use the 15-parameter version. -
No public
Readerclass defined in source:
WhileFile.ImporterreturnsIReader<Test>, theReaderclass is not defined in the provided files. Its implementation is likely inTDAS.File.Reader.cs(referenced in comments but not included). -
Encoding assumptions:
File.Writer.WriteusesEncoding.Defaultfor.tlfserialization. This may cause portability issues across systems with different default encodings.