--- source_files: - Common/DTS.Common.Serialization/IRIGCH10/Chapter10.File.cs - Common/DTS.Common.Serialization/IRIGCH10/WriteTest.cs - Common/DTS.Common.Serialization/IRIGCH10/CH10AnalogStreamDecode.cs - Common/DTS.Common.Serialization/IRIGCH10/Chapter10File.cs - Common/DTS.Common.Serialization/IRIGCH10/Chapter10.File.Writer.cs generated_at: "2026-04-17T15:37:12.585375+00:00" model: "zai-org/GLM-5-FP8" schema_version: 1 sha256: "1f5b2482ec8c69d4" --- # Documentation: DTS.Serialization.IRIGCH10 ## 1. Purpose This module provides serialization support for the IRIG 106 Chapter 10 (CH10) data format, enabling both parsing of CH10 binary files and writing new CH10 files from test data. It handles packet-level parsing with CRC validation, real-time UDP multicast stream decoding for live data acquisition, and TMATS (Telemetry Attributes Transfer Standard) document generation. The module supports both PCM and Analog data formats for export operations. --- ## 2. Public Interface ### `File` (partial class) - `Chapter10.File.cs` A partial class extending `Serialization.File` that provides CH10 file handling capabilities. ```csharp public File() // Constructor - initializes base with "Chapter10" type public IWriter Exporter { get; } // Lazy-initialized writer instance ``` ### `CH10AnalogStreamDecode` - `CH10AnalogStreamDecode.cs` Listens for UDP multicast streams containing CH10 packet data and dispatches parsed packets to registered handlers. ```csharp // Properties public string MulticastReceiveAddress { get; set; } // Default: MulticastCommandBase.DEFAULT_RECEIVE_ADDRESS public int ResponsePort { get; set; } // Default: (int)MulticastCommandBase.Ports.Response public IPAddress BindToAdapterIPAddress { get; set; } // Default: IPAddress.Any // Methods public void StartListening() // Starts UDP listener on background thread public void StopListening() // Signals listener to stop // Delegate types public delegate void TimePacketDelegate(TimePacketFormat2 packet); public delegate void AnalogDataPacketDelegate(AnalogDataFormat1Packet packet); public delegate void TMATSPacketDelegate(TMATSPacket packet); public delegate void BadCRCDelegate(IPacketHeader packet); // Event handlers (assign to receive callbacks) public BadCRCDelegate OnBadCRC; public TimePacketDelegate OnTimePacket; public AnalogDataPacketDelegate OnAnalogPacket; public TMATSPacketDelegate OnTMATSPacket; ``` ### `Chapter10File` - `Chapter10File.cs` Parses CH10 binary data and provides access to extracted headers and packets. Also contains static methods for writing CH10 files. ```csharp // Constructor - parses all packets from byte array public Chapter10File(byte[] bytes) // Accessors for parsed data public ITransportStreamHeader[] GetTransportHeaders() public IPacketHeader[] GetPacketHeaders() public ISecondaryTimeFormatHeader[] GetSecondaryTimeHeaders() public byte[] GetBytesForPacket(IPacketHeader packet) // Properties public int GoodPackets { get; } // Count of successfully parsed packets public int RejectedPackets { get; } // Count of packets failing validation // Static methods public static long ReadChapter10PacketHeader(byte[] bytes, long startIndex, out IPacketHeader packetHeader) public static long GetIndexOfNextPacket(byte[] bytes, long startIndex) // Static write methods public static void WriteFilePCM(string tmats, GetNextSampleDelegate getNextSample, GetChannelLengthDelegate getChannelLength, int totalChannels, int nanoseconds, int seconds, double sampleRate, bool includeSecondaryHeader, string fileName, TickEventHandler tickEventHandler, object tickObject) public static void WriteFileAnalog(string tmats, GetNextSampleDelegate getNextSample, GetChannelLengthDelegate getChannelLength, int totalChannels, int nanoseconds, int seconds, double sampleRate, bool includeSecondaryHeader, string fileName, TickEventHandler tickEventHandler, object tickObject) // Delegates for write operations public delegate short GetNextSampleDelegate(int channelIdx); public delegate long GetChannelLengthDelegate(int channelIndex); ``` ### `File.Writer` (nested class) - `Chapter10.File.Writer.cs` Implements `IWriter` for exporting test data to CH10 format. ```csharp // Constructor (internal) internal Writer(File fileType, int encoding) // Properties public bool IncludeSecondaryHeader { get; set; } // Default: true public bool UseAnalogFormat { get; set; } // Default: true public bool UsePCMFormat { get; set; } // Default: false public double Start { get; set; } public double Stop { get; set; } public bool Filtered { get; set; } // Constants public const long BASE_RTC = 141989612500056L; // Methods public void Write(string pathname, string id, string dataFolder, Test test, bool bFiltering, bool includeGroupNameInISOExport, FilteredData fd, Channel tmChannel, int channelNumber, BeginEventHandler beginEventHandler, CancelEventHandler cancelEventHandler, EndEventHandler endEventHandler, TickEventHandler tickEventHandler, ErrorEventHandler errorEventHandler, CancelRequested cancelRequested, double minStartTime, int dataCollectionLength) public void Initialize(string pathname, string id, string dataFolder, Test test, bool bFiltering, bool includeGroupNameInISOExport, FilteredData fd, Channel tmChannel, int channelNumber, BeginEventHandler beginEventHandler, CancelEventHandler cancelEventHandler, EndEventHandler endEventHandler, TickEventHandler tickEventHandler, ErrorEventHandler errorEventHandler, CancelRequested cancelRequested) ``` --- ## 3. Invariants - **Sync Pattern Validation**: All valid CH10 packets must have `PacketHeader.EXPECTED_SYNC_PATTERN` at their sync pattern field. - **Checksum Validation**: `packetHeader.CheckSum` must equal `packetHeader.ComputeCheckSum()` for a packet to be considered valid. - **RTC Frequency**: Relative Time Counter operates at 10MHz (`RTC_PER_SECOND = 10000000`). - **Time Packet Boundary**: `TimePacketFormat1` packets must always start on a second boundary. - **Packet Ordering**: Transport headers, packet headers, and secondary time headers are stored in the order they are read. - **Thread Safety**: `CH10AnalogStreamDecode` uses locks (`MyLock`, `LEFT_OVER_BYTES_LOCK`) for thread-safe operations. - **Packet Target Size**: Write operations target 100ms of data per packet (sample rate divided by 10). --- ## 4. Dependencies ### This module depends on: - `DTS.Common.Utilities.Logging` - `APILogger` for logging - `DTS.Common.Utils` - `FileUtils`, `NetworkUtils`, `PTP1588Timestamps` - `DTS.Common` - `Constants.NANOS_PER_SECOND` - `DTS.DASLib.Command.SLICE.MulticastCommands` - `MulticastCommandBase` for default multicast settings - `DTS.Serialization.IRIGCH10.Packets` - Packet types (`TMATSPacket`, `AnalogDataFormat1Packet`, `TimePacketFormat1`, `TimePacketFormat2`, `PCMDataPacket`, etc.) - `DTS.Common.DAS.Concepts` - `Channel`, `AnalogInputChannel` - `DTS.Common.Enums` - `IsoViewMode` - `IRIGCh10` - External library for CH10 types - `SliceRaw.File.Reader` - `GetDataScaler` method for channel data scaling - File system templates at `TMTTemplates\` directory ### What depends on this module: - Cannot be determined from source alone; no downstream consumers are visible in these files. --- ## 5. Gotchas 1. **NotImplementedException**: The `Write(string pathname, string id, Test test, ...)` overload in `File.Writer` throws `NotImplementedException`. Use the full overload with all parameters instead. 2. **Arbitrary RTC Base**: `BASE_RTC` (141989612500056L) is documented as "made up" and arbitrary. The comment states: "we don't really have an RTC, so we make up one with an arbitrary value." 3. **File Template Dependency**: TMATS generation depends on external template files: - `TMTTemplates\S6ATMTTemplate_PCM_ExportBase.tmt` - `TMTTemplates\S6ATMTTemplate_PCM_ExportChannel.tmt` - `TMTTemplates\S6ATMTTemplate_ANALOG_ExportBase.tmt` - `TMTTemplates\S6ATMTTemplate_ANALOG_ExportChannel.tmt` These must exist at runtime or TMATS generation will fail. 4. **Channel Naming Side Effect**: `GetChannelName()` depends on `IsoViewModeStatic.ViewMode`, a static/global state that affects channel naming behavior. 5. **BinaryReader Cleanup**: The `Write` method opens `BinaryReader` instances per channel. If an exception occurs before `CloseAndDisposeReaders` is called, readers may leak. The method does attempt cleanup in a finally block via `endEventHandler` invocation, but explicit reader disposal is not guaranteed on all error paths. 6. **Leftover Bytes Handling**: `CH10AnalogStreamDecode.QueueBytes()` has a bug - it copies data into `newBytes` but then assigns `bytes` (the input parameter) to `_leftOvertBytes` instead of `newBytes`. This may cause data loss in stream parsing. 7. **WriteTest.cs is Commented Out**: The entire `WriteTest` class is commented out, suggesting it may be obsolete or under development.