Files
2026-04-17 14:55:32 -04:00

75 lines
7.0 KiB
Markdown
Raw Permalink 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.DataModel/Classes/Configuration/Configuration.cs
generated_at: "2026-04-16T03:32:33.762922+00:00"
model: "Qwen/Qwen3-Coder-Next-FP8"
schema_version: 1
sha256: "3e9a6cf2611db268"
---
# Configuration
### **Purpose**
This `Configuration` class is responsible for applying hardware-specific voltage thresholds and configuration settings to a list of Data Acquisition System (DAS) units (`IDASCommunication` instances) prior to test execution or diagnostics. It orchestrates the configuration process by reading threshold values from a centralized settings store (`BatteryAndInputVoltageDefaults`), applying them to each DAS object, resetting hardware lines to a known state, and then invoking `ConfigurationService.SetConfiguration` to push the updated configuration to the hardware. It also ensures that the resulting configuration files are persisted locally per test by copying them from a global configuration directory to the current tests directory.
---
### **Public Interface**
#### **`public void SetConfig(DataModel.TestTemplate currentTest, List<IDASCommunication> dasList, bool calledDuringDiagnostics, StatusHelpers.SetProgressValueDelegate setProgressFunction)`**
- **Behavior**: Applies DAS-specific voltage thresholds (input and battery) based on hardware type, using different thresholds depending on whether the call is for diagnostics (`calledDuringDiagnostics == true`) or normal operation. After setting thresholds on each `IDASCommunication` object, it resets hardware lines via `ConfigurationService.ResetHardwareLines`, then calls `ConfigurationService.SetConfiguration` to commit the configuration to hardware. Progress is reported via `StatusHelpers.SetStatus2`. On success, it copies DAS and module configuration XML files to the test directory. Thread-safe via `lock` on `DASHardware.GetArmStatusLock`.
- **Parameters**:
- `currentTest`: The active test context; used to determine the destination directory for config file copying.
- `dasList`: List of DAS units to configure.
- `calledDuringDiagnostics`: If `true`, uses *diagnostic* thresholds (e.g., `BatteryHighDiagnosticsThreshold`); otherwise uses *armed* thresholds (e.g., `BatteryHighArmedThreshold`).
- `setProgressFunction`: Delegate used to report progress during configuration.
#### **`public static DialogResult ErrorCallback(string errorString, string units)`**
- **Behavior**: A static callback used by `ConfigurationService.SetConfiguration` to handle configuration errors. Logs the error via `APILogger.Log`, and currently returns `DialogResult.OK` (commented as a TODO: “Fix this”).
- **Note**: Does not throw or re-raise the error; caller must rely on exception handling in `SetConfig` to detect failure.
---
### **Invariants**
- **Thread Safety**: The entire `SetConfig` method body is guarded by `lock (DASHardware.GetArmStatusLock)`, ensuring only one configuration operation occurs at a time.
- **Voltage Threshold Assignment**: For each `IDASCommunication das` in `dasList`, the following six properties are *always* set:
- `MinimumValidInputVoltage`, `MaximumValidInputVoltage`
- `MinimumValidBatteryVoltage`, `MaximumValidBatteryVoltage`
- `BatteryHighVoltage`, `BatteryMediumVoltage`, `BatteryLowVoltage`
- `InputHighVoltage`, `InputMediumVoltage`, `InputLowVoltage`
The values are derived from `BatteryAndInputVoltageDefaults.InputAndBatterySettings.GetValue(type.ToString(), ...)`, where `type = das.GetHardwareType()`.
- **Hardware Reset Precedes Configuration**: `ConfigurationService.ResetHardwareLines` is *always* called before `SetConfiguration`, per the comment: “setting the configuration checks the hardware lines so make sure we reset them prior to setting configuration.”
- **Config File Copying**: After successful configuration, XML files for each DAS and its modules are copied from a global `Constants.DAS_CONFIGS` directory to `currentTest.TestDirectory`, overwriting existing files.
---
### **Dependencies**
- **Imports/Usings**:
- `DTS.Common.Interface.DASFactory.IDASCommunication`: Interface for DAS communication objects.
- `DTS.DASLib.Service.ConfigurationService`: Core service used to perform hardware reset and configuration.
- `DTS.Common.DataModel.Common.StatusHelpers`: Provides `SetStatus2` and `SetProgressValueDelegate`.
- `DTS.Common.Utilities.Logging.APILogger`: Used for logging errors and exceptions.
- `DTS.Common.DataModel.Classes.TSRAIRGo.TSRAIRGoStatus`: Defines `StatusTypes.UPDATING_DAS_CONFIG`.
- `DTS.Common.Enums.TSRAIRGo`: Enum namespace (used via `TSRAIRGoStatus`).
- `System.Windows.Forms.DialogResult`: Used in `ErrorCallback`.
- `DTS.Common.DataModel.Common.DataModel.BatteryAndInputVoltageDefaults`: Static source of voltage thresholds.
- `DTS.Common.Constants`: Defines `DAS_CONFIGS` (directory name).
- `DTS.Common.SerializedSettings`: Provides `MaxAAFRate_TDAS`, `MaxAAFRate_G5`, and `GetDefaultDSP()`.
- **External Dependencies**:
- `DASHardware.GetArmStatusLock`: A static lock object used for synchronization.
- `Environment.CurrentDirectory`: Base path for global config directory.
- File system: Requires existence of `DAS_CONFIGS` directory (via `Constants.DAS_CONFIGS`) and read access to XML files.
- **Called By**: Presumably invoked by higher-level test orchestration logic (e.g., before test start or diagnostics run). Not referenced in source, but usage is implied by test context (`currentTest`) and progress reporting.
---
### **Gotchas**
- **Hardcoded Threshold Keys**: Threshold keys (e.g., `"BatteryHighDiagnosticsThreshold"`) are string literals; no compile-time safety. A mismatch in key names in `BatteryAndInputVoltageDefaults` will result in default fallback values (via `GetValue`s second parameter), potentially leading to incorrect thresholds.
- **Blocking Wait Loop**: The `while (!done.WaitOne(50, false)) { elapsed += 50; }` loop is a polling-based wait. While functional, it may be inefficient or mask timing issues; no timeout is enforced beyond the loops implicit duration (no `elapsed`-based timeout check).
- **`ErrorCallback` Does Not Propagate Errors**: Returns `DialogResult.OK` unconditionally; actual failure detection relies on exceptions thrown in `SetConfig` or `SetConfiguration`. If `SetConfiguration` fails silently (e.g., via `CallbackStatus.Failure` without throwing), this may go unnoticed.
- **Assumes `das.DASInfo` is `InfoResult`**: In `CopyGlobalConfigsToLocalFolder`, `((InfoResult)das.DASInfo).OwningDAS` and `module.SerialNumber` are cast without type checking. If `das.DASInfo` is not an `InfoResult`, this will throw at runtime.
- **No Validation of `dasList`**: `SetConfig` does not check for null or empty `dasList`, which could lead to no-op or unexpected behavior.
- **`AggregateProgress = false`**: Indicates per-DAS progress reporting is expected, but the callback logic uses `cbd.Target` (a DAS instance) to report progress—this is consistent, but the setting may be easy to overlook.
- **Commented TODO**: `//Fix this` next to `return DialogResult.OK;` in `ErrorCallback` indicates known technical debt.