Files
DP44/enriched-qwen3-coder-next/Common/DTS.Common/Interface/Channels.md
2026-04-17 14:55:32 -04:00

185 lines
15 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
source_files:
- Common/DTS.Common/Interface/Channels/IChannelSettingRecord.cs
- Common/DTS.Common/Interface/Channels/IGroupChannelSettingRecord.cs
- Common/DTS.Common/Interface/Channels/IChannelCode.cs
- Common/DTS.Common/Interface/Channels/IChannelSetting.cs
- Common/DTS.Common/Interface/Channels/IChannelDbRecord.cs
- Common/DTS.Common/Interface/Channels/IGroupChannel.cs
generated_at: "2026-04-16T03:04:46.817731+00:00"
model: "Qwen/Qwen3-Coder-Next-FP8"
schema_version: 1
sha256: "84120b73a95d6917"
---
# Documentation: Channel Interfaces Module (`DTS.Common.Interface.Channels`)
## 1. Purpose
This module defines a set of interfaces that model channels in a data acquisition system (DAS), including their database representation (`IChannelDbRecord`), configuration settings (`IChannelSetting`, `IChannelSettingRecord`, `IGroupChannelSettingRecord`), and logical grouping within test setups (`IGroupChannel`). It serves as the foundational abstraction layer for channel management across UI, business logic, and data persistence layers—enabling consistent handling of physical measurement channels (analog, digital, CAN, UART, etc.), sensor assignments, hardware mapping, and channel-specific settings like range, polarity, filters, and protocol-specific parameters (e.g., CAN bitrates, UART config). The interfaces support both data transfer (e.g., records) and runtime behavior (e.g., `IGroupChannel` with UI state and validation).
## 2. Public Interface
### `IChannelSettingRecord`
- **`int Id { get; set; }`** Unique identifier for the setting type.
- **`string SettingName { get; set; }`** Human-readable name of the setting (e.g., "Range", "Polarity").
- **`string DefaultValue { get; set; }`** Default value for the setting as a string.
> *Represents a static, reusable channel setting definition (e.g., a setting template).*
### `IGroupChannelSettingRecord`
- **`long ChannelId { get; set; }`** Foreign key to the channel (`IChannelDbRecord.Id`).
- **`int SettingId { get; set; }`** Foreign key to `IChannelSettingRecord.Id`.
- **`string SettingValue { get; set; }`** Actual value assigned to the setting for this channel.
> *Represents a specific assignment of a setting to a channel instance.*
### `IChannelCode`
- **`int Id { get; }`** Unique identifier for the channel code.
- **`string Code { get; }`** Short code string (e.g., "A1", "CH1").
- **`string Name { get; }`** Descriptive name (e.g., "Accelerometer Front Left").
- **`ChannelEnumsAndConstants.ChannelCodeType CodeType { get; }`** Enumerated type of the code (e.g., ISO, User, DAS).
> *Encapsulates metadata about a channels identifying codes (used for labeling/organization).*
### `IChannelSetting`
- **`long ChannelId { get; set; }`** ID of the channel this setting belongs to.
- **`int SettingTypeId { get; }`** ID of the setting type (links to `IChannelSettingRecord.Id`).
- **`string SettingName { get; }`** Name of the setting (mirrors `IChannelSettingRecord.SettingName`).
- **`string DefaultValue { get; }`** Default value (mirrors `IChannelSettingRecord.DefaultValue`).
- **`string Value { get; set; }`** Current value as string (generic fallback).
- **`int IntValue { get; set; }`** Current value as integer (for numeric settings).
- **`double DoubleValue { get; set; }`** Current value as double (for numeric settings).
- **`bool BoolValue { get; set; }`** Current value as boolean (for toggle settings).
- **`IChannelSetting Clone()`** Deep copy of the setting instance.
> *Represents a *runtime* setting instance attached to a channel, supporting type-specific accessors.*
### `IChannelDbRecord`
- **`long Id { get; set; }`** Primary key (DB record ID).
- **`int GroupId { get; set; }`** Foreign key to group.
- **`string IsoCode { get; set; }`** ISO-standard channel code.
- **`string IsoChannelName { get; set; }`** ISO-standard channel name.
- **`string UserCode { get; set; }`** User-defined channel code.
- **`string UserChannelName { get; set; }`** User-defined channel name.
- **`int DASId { get; set; }`** ID of the DAS device.
- **`int DASChannelIndex { get; set; }`** Physical channel index on the DAS.
- **`int GroupChannelOrder { get; set; }`** Order within the group.
- **`int TestSetupOrder { get; set; }`** Order in the test setup.
- **`int SensorId { get; set; }`** Foreign key to sensor.
- **`bool Disabled { get; set; }`** Whether the channel is disabled.
- **`DateTime LastModified { get; set; }`** Timestamp of last DB modification.
- **`string LastModifiedBy { get; set; }`** User who last modified the record.
> *Database mapping interface for channel records (EF Core style).*
### `IGroupChannel`
- **Extends `IChannelDbRecord`** (inherits all DB record properties).
- **`SensorConstants.AvailableRangesLowG RangeLowG { get; set; }`** Low-G sensor range enum.
- **`bool VoltageInsertionSensor { get; }`** Whether channel has a voltage-insertion sensor.
- **`bool RangeModifiableSensorLowG { get; }`** Whether channel has a low-G sensor with modifiable range.
- **`bool RangeModifiableSensorARS { get; }`** Whether channel has an ARS sensor with modifiable range.
- **`InitialOffset[] AvailableInitialOffsets { get; set; }`** Available initial offset options.
- **`string IEPESupport { get; }`** IEPE support status (e.g., "Supported", "N/A").
- **`IGroup Group { get; set; }`** Parent group.
- **`string GroupName { get; set; }`** Display name of parent group.
- **`bool GroupNameValid { get; set; }`** Whether `GroupName` is set.
- **`bool IsoCodeValid { get; set; }`** Whether `IsoCode` is set (not validated for correctness).
- **`bool IsoChannelNameValid { get; set; }`** Whether `IsoChannelName` is set.
- **`bool UserCodeValid { get; set; }`** Whether `UserCode` is set.
- **`bool UserChannelNameValid { get; set; }`** Whether `UserChannelName` is set.
- **`bool HardwareValid { get; }`** Whether hardware is assigned.
- **`string HardwareId { get; set; }`** Legacy hardware identifier (`[das serial]:[channel index]`).
- **`double TestSampleRate { get; set; }`** Sample rate of associated DAS.
- **`bool SensorValid { get; }`** Whether a sensor is assigned.
- **`bool IsDisabled { get; set; }`** Whether channel is disabled for data collection.
- **`long ChannelId { get; set; }`** Channel instance ID (distinct from `IChannelDbRecord.Id`? See *Gotchas*).
- **`void SetHardwareChannel(IHardwareChannel hardwareChannel)`** Assigns hardware channel.
- **`void SetSensor(IDragAndDropItem sensor, IChannelSetting[] channelDefaults, bool applySensorDataToBlankChannels)`** Assigns sensor and optionally applies defaults.
- **`bool CompareValue(string property)`** Compares current value of `property` to a reference (e.g., for diff detection).
- **`bool SetDifferent(string property)`** / **`void SetNotDifferent()`** Marks/unmarks property as "different" (UI state).
- **`void SetRange(CACOption option)`** Sets range based on CAC option enum.
- **`bool CanMoveUp { get; set; }`** / **`bool CanMoveDown { get; set; }`** UI state for reordering.
- **`bool DeleteShouldBeEnabled { get; set; }`** UI state for delete button.
- **`System.Windows.Visibility RemoveSensorVisibility { get; set; }`** UI visibility for sensor removal control.
- **`bool IsBlank()`** Whether channel is unconfigured (no hardware/sensor).
- **`void Clear()`** Clears hardware and sensor assignments.
- **`bool Filter(string term)`** Whether channel matches search term.
- **`ICommand PasteCommand { get; set; }`** Command for paste operations.
- **`IChannelSetting[] ChannelSettings { get; set; }`** Collection of channel settings.
- **`void AdjustCANSettings(bool canIsFD)`** / **`void AdjustCANSources(bool canIsFD, int canArbBaseBitrate, int canDataBitrate)`** Adjusts CAN settings for FD vs classic.
- **`string GetChannelName(IsoViewMode isoViewMode)`** / **`string GetChannelCode(IsoViewMode isoViewMode)`** Returns name/code based on view mode.
- **`void Copy(IGroupChannel groupChannel)`** Copies state from another channel.
- **`string Hardware { get; set; }`** UI display string for hardware.
- **`string Sensor { get; }`** UI display string for sensor.
- **`ISensorData SensorData { get; }`** Sensor metadata.
- **`IHardwareChannel HardwareChannel { get; }`** Hardware channel object.
- **`IDragAndDropItem DragAndDropItem { get; }`** Drag-and-drop source item.
- **`ISensorCalibration SensorCalibration { get; }`** Sensor calibration data.
- **`void SetSensorCalibration(ISensorCalibration calibration)`** / **`void SetSensorData(...)`** Assigns sensor data/calibration.
- **`bool HasEID { get; }`** Whether channel has EID (Event ID) support.
- **`bool IsAnalog { get; }`** / **`bool IsSquib { get; }`** / **`bool IsDigitalIn { get; }`** / **`bool IsDigitalOut { get; }`** / **`bool IsClock { get; }`** / **`bool IsUart { get; }`** / **`bool IsStreamIn { get; }`** / **`bool IsStreamOut { get; }`** / **`bool IsCan { get; }`** Sensor type flags.
- **`double Range { get; set; }`** Current range setting.
- **`double Capacity { get; }`** Sensor capacity.
- **`IFilterClass FilterClass { get; set; }`** Filter class (e.g., FB 13120).
- **`string Polarity { get; set; }`** Polarity setting.
- **`string Units { get; }`** Sensor units.
- **`ZeroMethodType ZeroMethod { get; set; }`** Zeroing method.
- **`double ZeroMethodStart { get; set; }`** / **`double ZeroMethodEnd { get; set; }`** Zeroing window.
- **`string Sensitivity { get; }`** Sensor sensitivity.
- **`InitialOffset InitialOffset { get; set; }`** Initial offset value.
- **`bool SquibLimitDuration { get; set; }`** / **`double SquibDuration { get; set; }`** / **`double? SquibDelay { get; set; }`** / **`double SquibCurrent { get; set; }`** Squib-specific settings.
- **`bool DigitalOutLimitDuration { get; set; }`** / **`double DigitalOutDuration { get; set; }`** / **`double DigitalOutDurationMax { get; set; }`** / **`double DigitalOutDelay { get; set; }`** Digital output settings.
- **`DigitalOutputModes DigitalOutputMode { get; set; }`** / **`SquibFireMode SquibFireMode { get; set; }`** / **`DigitalInputModes DigitalInputMode { get; set; }`** Mode enums.
- **`string ActiveValue { get; set; }`** / **`string DefaultValue { get; set; }`** Digital output values.
- **`uint UartBaudRate { get; set; }`** / **`uint UartDataBits { get; set; }`** / **`StopBits UartStopBits { get; set; }`** / **`Parity UartParity { get; set; }`** / **`Handshake UartFlowControl { get; }`** / **`UartDataFormat UartDataFormat { get; set; }`** UART settings.
- **`string StreamInUDPAddress { get; set; }`** / **`UDPStreamProfile StreamOutUDPProfile { get; set; }`** / **`string StreamOutUDPAddress { get; set; }`** / **`ushort StreamOutUDPTimeChannelId { get; set; }`** / **`ushort StreamOutUDPDataChannelId { get; set; }`** / **`string StreamOutUDPTmNSConfig { get; set; }`** / **`ushort StreamOutIRIGTimeDataPacketIntervalMs { get; set; }`** / **`ushort StreamOutTMATSIntervalMs { get; set; }`** Stream settings.
- **`bool CanIsFD { get; set; }`** / **`int CanArbBaseBitrate { get; set; }`** / **`int CanArbBaseSJW { get; set; }`** / **`int CanDataBitrate { get; set; }`** / **`int CanDataSJW { get; set; }`** / **`string CanFileType { get; set; }`** CAN settings.
- **`IFilterClass GetFilterClassFromISOCode(ISoftwareFilter[] filters, string isoCode)`** Retrieves filter class from ISO code.
- **`CoerceISOCodeDelegate CoerceISOCodeFunc { get; }`** Function to coerce/normalize ISO codes.
- **`UIItemStatus ChannelStatus { get; }`** Combined status (e.g., "Complete", "Missing Sensor").
- **`void SetSettingsFromSensor(ISensorData sd)`** Applies sensor defaults to channel settings.
- **`string GetChangeList(ISensorData sensor)`** Returns list of differences between sensor and channel settings.
- **`bool IsRangeDifferent { get; set; }`** / **`bool IsFilterClassDifferent { get; set; }`** / ... (many `Is...Different` properties) UI state flags for setting changes.
> *Core runtime interface for a channel in a group. Combines DB record data, hardware/sensor state, settings, and UI metadata.*
## 3. Invariants
- **`IChannelDbRecord`**:
- `Id`, `GroupId`, `DASId`, `DASChannelIndex`, `GroupChannelOrder`, `TestSetupOrder`, and `SensorId` must be non-null and valid (e.g., `SensorId > 0` if a sensor is assigned).
- `Disabled` implies the channel should not be used for data collection.
- `LastModified` and `LastModifiedBy` must be set on every update.
- **`IGroupChannel`**:
- `IsBlank()` returns `true` only if both hardware and sensor are unassigned.
- `SensorValid`, `HardwareValid`, `IsAnalog`, `IsSquib`, etc., are mutually exclusive and consistent with assigned sensor/hardware types.
- `ChannelStatus` reflects `IsComplete` and sensor calibration validity.
- `Is...Different` properties are UI state flags and do not affect data integrity.
- `ChannelId` (from `IGroupChannel`) is distinct from `Id` (from `IChannelDbRecord`)—see *Gotchas*.
- **`IChannelSetting`**:
- Only one of `Value`, `IntValue`, `DoubleValue`, or `BoolValue` should be actively used per setting instance (type-specific).
- `Clone()` must produce a deep copy (no shared mutable references).
## 4. Dependencies
- **Depends on**:
- `DTS.Common.Enums.Channels` (`ChannelCodeType`)
- `System.ComponentModel.DataAnnotations` (`Key`, `Column`)
- `System` (`DateTime`)
- `DTS.Common.Interface.DataRecorders` (`IHardwareChannel`)
- `DTS.Common.Interface.Sensors.SensorsList` (`IDragAndDropItem`)
- `DTS.Common.Interface.Sensors` (`ISensorData`, `ISensorCalibration`)
- `DTS.Common.Interface.Groups.GroupList` (`IGroup`)
- `DTS.Common.Enums` (e.g., `InitialOffset`, `ZeroMethodType`, `DigitalOutputModes`, `SquibFireMode`, `DigitalInputModes`)
- `DTS.Common.Classes.ChannelCodes` (`CoerceISOCodeDelegate`)
- `DTS.Common.Interface.Sensors.SoftwareFilters` (`IFilterClass`, `ISoftwareFilter`)
- `System.IO.Ports` (`StopBits`, `Parity`, `Handshake`)
- `System.Windows.Input` (`ICommand`)
- `System.Windows` (`Visibility`)
- **Depended on by**:
- UI layers (WPF) for channel configuration, validation, and binding.
- Data persistence layers (e.g., EF Core) for `IChannelDbRecord` mapping.
- Sensor/hardware assignment logic (e.g., `SetSensor`, `SetHardwareChannel`).
- Test setup and data collection orchestration (e.g., `IsDisabled`, `ChannelStatus`).
## 5. Gotchas
- **`ChannelId` vs `Id`**: `IGroupChannel` inherits `IChannelDbRecord.Id` (DB primary key) but *also* declares its own `long ChannelId { get; set; }`. The purpose of `ChannelId` is unclear from the source—comments suggest it may be a legacy identifier or used for UI grouping. **Do not assume `ChannelId == Id`.**
- **`HardwareId` is deprecated**: The comment explicitly states this is an old identifier (`[das serial]:[channel index]`) and questions why it coexists with `HardwareChannel`. Prefer `Hardware