--- source_files: - Common/DTS.Common.Serialization/FtssCsv/FtssCsv.File.cs - Common/DTS.Common.Serialization/FtssCsv/FtssTsv.File.cs - Common/DTS.Common.Serialization/FtssCsv/FtssTsv.File.Writer.cs generated_at: "2026-04-17T15:38:52.319168+00:00" model: "zai-org/GLM-5-FP8" schema_version: 1 sha256: "75b02305d1c7a319" --- # Documentation: DTS.Serialization.FtssCsv / FtssTsv ## 1. Purpose This module provides file serialization support for FTSS (presumably "Flight Test Data System" or similar) CSV and TSV (Tab-Separated Values) export formats. It enables writing `Test` objects to delimited text files with extensive metadata headers and channel data. The module implements a writer pattern with progress reporting events and supports features like data filtering, subsampling, and disk space verification before export. --- ## 2. Public Interface ### FtssCsv.File Class **Namespace:** `DTS.Serialization.FtssCsv` **Inheritance:** `Serialization.File`, `IWritable` | Member | Signature | Description | |--------|-----------|-------------| | `File()` | `public File()` | Constructor initializing the file with "CSV" format type. | | `Extension` | `public static string Extension` | Static property returning `".csv"`. | | `Exporter` | `public IWriter Exporter` | Lazily instantiates and returns a `Writer` for exporting test data. Uses `DefaultEncoding`. | ### FtssTsv.File Class **Namespace:** `DTS.Serialization.FtssTsv` **Inheritance:** `Serialization.File`, `IWritable` | Member | Signature | Description | |--------|-----------|-------------| | `File()` | `public File()` | Constructor initializing the file with "TSV" format type. | | `Extension` | `public static string Extension` | Static property returning `".tsv"`. | | `Exporter` | `public IWriter Exporter` | Lazily instantiates and returns a `Writer` for exporting test data. Uses `DefaultEncoding`. | ### FtssTsv.File.Writer Class **Namespace:** `DTS.Serialization.FtssTsv` **Inheritance:** `Writer`, `IWriter` #### Constructor | Signature | Description | |-----------|-------------| | `internal Writer(File fileType, int encoding)` | Internal constructor; requires associated `File` instance and encoding integer. | #### Enum: ExportMode ```csharp public enum ExportMode { FtssExcel, Ttc, Standard, } ``` #### Events | Event | Type | Description | |-------|------|-------------| | `OnBegin` | `BeginEventHandler` | Notifies subscribers that write is starting. | | `OnEnd` | `EndEventHandler` | Notifies subscribers that write is finished. | | `OnTick` | `TickEventHandler` | Notifies subscribers of progress (one tick per 1000 data samples). | | `OnCancel` | `CancelEventHandler` | Notifies subscribers that write was cancelled. | | `OnError` | `ErrorEventHandler` | Notifies subscribers of fatal errors. | #### Properties | Property | Type | Description | |----------|------|-------------| | `CurrentExportMode` | `ExportMode` | Gets/sets the current export format. Defaults to `ExportMode.FtssExcel`. | | `FilteredChannelData` | `List` | Filtered channel data to use instead of raw data. | | `DataChannelFilename` | `string` | Filename identifying the data channel to export. | | `LaboratoryName` | `string` | Laboratory metadata for header. | | `LaboratoryContactName` | `string` | Contact name for header. | | `LaboratoryContactPhone` | `string` | Contact phone for header. | | `LaboratoryContactEmail` | `string` | Contact email for header. | | `TestEngineerName` | `string` | Engineer name for header. | | `TestEngineerPhone` | `string` | Engineer phone for header. | | `TestEngineerEmail` | `string` | Engineer email for header. | | `NumChannelsWritten` | `int` | Counter for channels written. | | `UseISOCodeFilterMapping` | `bool` | Whether to adjust ISO codes based on filter class. | | `UseZeroForUnfiltered` | `bool` | Whether to use zero for unfiltered data in ISO code mapping. | | `Start` | `double` | Export start time (default: 0D). | | `Stop` | `double` | Export stop time (default: 0D). | | `SubSampleInterval` | `ushort` | Subsampling interval for data export. | | `Filtered` | `bool` | Whether filtered data is being exported. | #### Methods | Method | Signature | Description | |--------|-----------|-------------| | `Write` | `public void Write(string pathname, string id, Test test, bool bFiltering, bool includeGroupNameInISOExport, double minStartTime, int dataCollectionLength)` | Simplified write method delegating to the full overload. | | `Write` | `public void Write(string pathname, string id, string dataFolder, Test test, bool bFiltering, bool includeGroupNameInISOExport, FilteredData fd, Test.Module.Channel tmChannel, int channelNumber, BeginEventHandler beginEventHandler, CancelEventHandler cancelEventHandler, EndEventHandler endEventHandler, TickEventHandler tickEventHandler, ErrorEventHandler errorEventHandler, CancelRequested cancelRequested, double minStartTime, int dataCollectionLength)` | Full write method with all parameters. Creates directory if needed, deletes existing file, writes header and data. Only `ExportMode.FtssExcel` is currently supported. | | `Initialize` | `public void Initialize(...)` | Empty implementation (no-op). | | `WriteChannelInfo` | `protected void WriteChannelInfo(StreamWriter fileWriter, string id, Test test, List filteredData, string targetPath, TickEventHandler tickEventHandler, uint totalWriteTicksNeeded, ref uint totalWriteTicksDispatched, CancelRequested cancelRequested, int channelNumber, double minStartTime, int dataCollectionLength)` | Writes header lines and channel data to the stream. Handles subsampling, scaling, and filtering. | #### Enum: FtssHeaderLine (Private) Defines 31 header line types including: `Headers`, `TestDate`, `TestTime`, `TestId`, `TestDescription`, `LaboratoryName`, `SampleRate`, `HardwareAntiAliasFilter`, `DataChannelName`, `IsoCode`, `ChannelDescription`, `ChannelLocation`, `SensorSerialNumber`, `SoftwareFilter`, `SoftwareFilterDb`, `EngineeringUnits`, `UserComment`, `PreZero`, `PostZero`, `DataZero`, `ScaleEu`, `ScaleMv`, `DataStart`, `Labels`. --- ## 3. Invariants 1. **Exporter Lazy Initialization**: The `_Exporter` field is lazily initialized; once created, it is reused for subsequent accesses. 2. **Only FtssExcel ExportMode Supported**: The `Write` method throws `NotSupportedException` for any `CurrentExportMode` other than `ExportMode.FtssExcel`. 3. **Tab Separator**: The TSV format uses `"\t"` (TAB) as the list separator constant. 4. **Number Format**: All numeric data values are formatted using `"F8"` (8 decimal places). 5. **Progress Granularity**: Progress ticks are dispatched every 1000 data samples (`DataSamplesPerTick`). 6. **Single Channel Export**: The `WriteChannelInfo` method exports only the channel whose filename matches `DataChannelFilename`; it breaks after finding the first match. 7. **Directory Creation**: If the target directory does not exist, it will be created automatically during `Write`. 8. **File Overwrite**: If the target file exists, it will be deleted (or moved if deletion fails) before writing. --- ## 4. Dependencies ### This Module Depends On: - `System` (Collections.Generic, ComponentModel, Linq, IO, Text) - `DTS.Common.DAS.Concepts` (including `DTS.Common.DAS.Concepts.DAS.Channel`) - `DTS.Common.Utilities` - `DTS.Common.Utilities.DotNetProgrammingConstructs` - `DTS.Common.Utilities.Logging` - `DTS.Common` - `DTS.Common.Enums.Sensors` - `DTS.Common.Utils` - `System.Windows.Forms.Application` (for `DoEvents()` during progress reporting) - Base class `Serialization.File` (inferred from inheritance) - Interface `IWritable` (inferred from implementation) - Types: `Test`, `Test.Module.Channel`, `Test.Module.AnalogInputChannel`, `FilteredData`, `DataScaler`, `NHTSASubSample`, `Property`, `DescriptionAttributeCoder`, `DiskUtility`, `FileUtils`, `APILogger`, `UserException`, `Exception` (custom DTS type) ### What Depends On This Module: - Not determinable from the provided source alone. --- ## 5. Gotchas 1. **UI Thread Coupling**: The `WriteChannelInfo` method calls `System.Windows.Forms.Application.DoEvents()` during the write loop, creating a dependency on Windows Forms and implying the write may be intended to run on a UI thread. 2. **Empty Initialize Method**: The `Initialize` method has an empty body despite accepting numerous parameters. It is unclear if this is intentional or incomplete. 3. **Unused ExportMode Values**: `ExportMode.Ttc` and `ExportMode.Standard` are defined but throw `NotSupportedException` if used. 4. **Exception Wrapping**: All exceptions are caught and re-thrown wrapped in a custom `Exception` type with descriptive messages, potentially obscuring original stack traces. 5. **Hardcoded Channel Selection**: The `WriteChannelInfo` method filters channels by comparing `Path.GetFileName(((Test.Module.AnalogInputChannel)ch).FileName)` to `DataChannelFilename`. If no channel matches, the export proceeds with empty channel data. 6. **Subsampling Side Effect**: When `SubSampleInterval > 1`, the method modifies `FilteredChannelData[iChannel].Data` and `ChannelList[iChannel].PersistentChannelInfo.Data` in-place, mutating the input test data. 7. **PreZero/PostZero Calculation Edge Cases**: The code clamps `preTriggerSamples` to be non-negative, not exceed `NumberOfSamples`, and not exceed `Start * sampleRate`, but the logic may produce unexpected results if `Start` is not properly set. 8. **Missing CSV Writer Implementation**: The `FtssCsv.File` class references a `Writer` class, but no `FtssCsv.File.Writer.cs` is provided. It is unclear whether this shares the TSV writer or has a separate implementation.