208 lines
13 KiB
Markdown
208 lines
13 KiB
Markdown
|
|
---
|
|||
|
|
source_files:
|
|||
|
|
- DataPRO/SensorDB/StreamInputSettingDefaults.cs
|
|||
|
|
- DataPRO/SensorDB/FactorySensorModel.cs
|
|||
|
|
- DataPRO/SensorDB/ThermocouplerSetting.cs
|
|||
|
|
- DataPRO/SensorDB/DigitalOutputDefaults.cs
|
|||
|
|
- DataPRO/SensorDB/CANSetting.cs
|
|||
|
|
- DataPRO/SensorDB/StreamInputSetting.cs
|
|||
|
|
- DataPRO/SensorDB/StreamOutputSetting.cs
|
|||
|
|
- DataPRO/SensorDB/CanSettingDefaults.cs
|
|||
|
|
- DataPRO/SensorDB/StringResources.Designer.cs
|
|||
|
|
- DataPRO/SensorDB/SensorRange.cs
|
|||
|
|
- DataPRO/SensorDB/UartSetting.cs
|
|||
|
|
- DataPRO/SensorDB/DigitalInputSensorDefault.cs
|
|||
|
|
- DataPRO/SensorDB/SquibSettingDefaults.cs
|
|||
|
|
- DataPRO/SensorDB/SquibSetting.cs
|
|||
|
|
- DataPRO/SensorDB/UartSettingDefaults.cs
|
|||
|
|
- DataPRO/SensorDB/DigitalOutputSetting.cs
|
|||
|
|
- DataPRO/SensorDB/SensorDBBase.cs
|
|||
|
|
generated_at: "2026-04-16T03:47:59.601565+00:00"
|
|||
|
|
model: "Qwen/Qwen3-Coder-Next-FP8"
|
|||
|
|
schema_version: 1
|
|||
|
|
sha256: "2cf9d8723752dc92"
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
# Documentation: `DTS.SensorDB` Module — Sensor Configuration Defaults and Settings
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 1. Purpose
|
|||
|
|
|
|||
|
|
This module provides a centralized abstraction for managing sensor-specific default configurations and persistent settings in the DataPRO system. It defines concrete types for various sensor input/output types (e.g., UDP stream, CAN, UART, digital I/O, squib, thermocouple), encapsulates their default values, and offers static methods to load, validate, commit, and restore defaults—either per-user (via `TestSetupDefaults`) or globally (via `SettingsDB`). The module serves as the bridge between high-level UI/configuration logic and low-level database/storage layers (`DbOperations`, `SensorsCollection`), ensuring consistent handling of sensor metadata, calibration parameters, and operational modes.
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 2. Public Interface
|
|||
|
|
|
|||
|
|
### Classes
|
|||
|
|
|
|||
|
|
#### `StreamInputSettingDefaults`
|
|||
|
|
- **`string UDPAddress { get; set; }`**
|
|||
|
|
Gets/sets the UDP address for stream input. Backed by `_defaultStreamInput.StreamInUDPAddress`.
|
|||
|
|
- **`bool Validate()`**
|
|||
|
|
Returns `true` if `UDPAddress` starts with `"udp"` (case-insensitive) and is a well-formed absolute URI; otherwise `false`.
|
|||
|
|
- **`static void CommitChange(StreamInputSettingDefaults settingDefaults, int userID)`**
|
|||
|
|
Commits `UDPAddress` to user-specific settings using `TestSetupDefaults.SetUserSetting` with key `PropertyEnums.PropertyIds.DefaultUDPStreamAddress`.
|
|||
|
|
- **`static StreamInputSettingDefaults GetStreamInputSettingsDefault(int userID)`**
|
|||
|
|
Loads `StreamInUDPAddress` from user settings via `TestSetupDefaults.GetUserSettingValueString`, wraps it in a new `SensorData`, and returns a `StreamInputSettingDefaults` instance.
|
|||
|
|
- **`static StreamInputSettingDefaults GetStreamInputSettingsDefault(string user)`**
|
|||
|
|
Retrieves a sensor by serial number `SensorConstants.TEST_SPECIFIC_STREAM_IN_SERIAL` from `SensorsCollection.SensorsList`, wraps it in a `SensorData`, and returns a `StreamInputSettingDefaults` instance.
|
|||
|
|
|
|||
|
|
#### `DigitalOutputDefaults`
|
|||
|
|
- **`DigitalOutputModes OutputMode { get; set; }`**
|
|||
|
|
Gets/sets digital output mode via `_defaultOut.DigitalOutputMode`.
|
|||
|
|
- **`DigitalOutputModes[] AvailableModes { get; }`**
|
|||
|
|
Returns fixed array: `{ CCNC, CCNO, FVHL, FVLH }`.
|
|||
|
|
- **`double DelayMS { get; set; }`**
|
|||
|
|
Gets/sets `DigitalOutputDelayMS`.
|
|||
|
|
- **`bool LimitDuration { get; set; }`**
|
|||
|
|
Gets/sets `DigitalOutputLimitDuration`; raises `OnPropertyChanged("LimitDuration")`.
|
|||
|
|
- **`double DurationMS { get; set; }`**
|
|||
|
|
Gets/sets `DigitalOutputDurationMS`.
|
|||
|
|
- **`static void CommitChange(DigitalOutputDefaults settingDefaults, string user)`**
|
|||
|
|
Commits `_defaultOut` (cast to `SensorData`) via `SensorsCollection.SensorsList.Commit`.
|
|||
|
|
- **`static DigitalOutputDefaults GetDigitalOutDefault(string user)`**
|
|||
|
|
Retrieves sensor by serial number `SensorConstants.TEST_SPECIFIC_DIGITAL_OUT_SERIAL`, wraps in `ISensorData`, and returns `DigitalOutputDefaults`.
|
|||
|
|
|
|||
|
|
#### `CanSettingDefaults`
|
|||
|
|
- **Properties**: `IsFD`, `ArbBaseBitrate`, `ArbBaseSJW`, `DataBitrate`, `DataSJW`, `FileType` — all get/set via `_defaultCan`’s corresponding fields.
|
|||
|
|
- **`bool Validate()`**
|
|||
|
|
Always returns `true`.
|
|||
|
|
- **`static void CommitChange(CanSettingDefaults settingDefaults, int userID)`**
|
|||
|
|
Commits each property to user settings using `TestSetupDefaults.SetUserSetting` with keys from `PropertyEnums.PropertyIds.DefaultCAN*`.
|
|||
|
|
- **`static CanSettingDefaults GetCanSettingsDefault(int userID)`**
|
|||
|
|
Loads all CAN properties from user settings via `TestSetupDefaults.GetUserSettingValue*`, wraps in `SensorData`, and returns `CanSettingDefaults`.
|
|||
|
|
- **`static void RestoreDefaults(ICanSettingDefaults sensorDefaults)`**
|
|||
|
|
Resets all properties to constants from `EmbeddedSensors` (e.g., `CANISFD_DEFAULT`, `CANFD_ARB_BASE_BITRATE_DEFAULT`, etc.).
|
|||
|
|
|
|||
|
|
#### `UartSettingDefaults`
|
|||
|
|
- **Properties**: `BaudRate`, `DataBits`, `StopBits`, `Parity`, `FlowControl`, `DataFormat`.
|
|||
|
|
- **`StopBits[] AvailableStopBits { get; }`**
|
|||
|
|
`{ None, One, OnePointFive, Two }`.
|
|||
|
|
- **`Parity[] AvailableParities { get; }`**
|
|||
|
|
`{ None, Odd, Even, Mark, Space }`.
|
|||
|
|
- **`Handshake[] AvailableFlowControls { get; }`**
|
|||
|
|
`{ None }` — `FlowControl` is hardcoded to `Handshake.None` per comment `//FB 30486`.
|
|||
|
|
- **`bool Validate()`**
|
|||
|
|
Always returns `true`.
|
|||
|
|
- **`static void CommitChange(UartSettingDefaults settingDefaults, int userID)`**
|
|||
|
|
Commits all properties to user settings via `TestSetupDefaults.SetUserSetting`.
|
|||
|
|
- **`static UartSettingDefaults GetUartSettingsDefault(int userID)`**
|
|||
|
|
Loads properties from user settings, parses enums (`StopBits`, `Parity`, `DataFormat`) from strings, wraps in `SensorData`, returns instance.
|
|||
|
|
- **`static void RestoreDefaults(IUartSettingDefaults sensorDefaults)`**
|
|||
|
|
Resets to constants from `UARTRecord` and `EmbeddedSensors`.
|
|||
|
|
|
|||
|
|
#### `DigitalInputSensorDefault`
|
|||
|
|
- **`double ConstantCurrentBreakpointADC { get; set; }`**
|
|||
|
|
Breakpoint for CCNO/CCNC modes.
|
|||
|
|
- **`double VoltageBreakpointADC { get; set; }`**
|
|||
|
|
Breakpoint for THL/TLH modes.
|
|||
|
|
- **`bool DisplaySPDADC { get; set; }`**
|
|||
|
|
Whether to display analog SLICE PRO DIGITAL ADC data.
|
|||
|
|
- **`bool Validate()`**
|
|||
|
|
Always returns `true`.
|
|||
|
|
- **`static IDigitalInputDefaults GetDigitalInputDefaults(string user)`**
|
|||
|
|
Loads breakpoint values and `DisplaySPDADC` from `SettingsDB` with fallback defaults from `DTS.Common.Constant.DigitalInputs`.
|
|||
|
|
- **`static void Save(IDigitalInputDefaults defaults)`**
|
|||
|
|
Persists values to `SettingsDB` and updates corresponding static fields in `DTS.Common.Constant.DigitalInputs`.
|
|||
|
|
- **`static void RestoreDefaults(IDigitalInputDefaults sensorDefaults)`**
|
|||
|
|
Resets to default constants from `DTS.Common.Constant.DigitalInputs`.
|
|||
|
|
|
|||
|
|
#### `SquibSettingDefaults`
|
|||
|
|
- **Properties**: `ToleranceLowDefault`, `ToleranceHighDefault`, `OutputCurrentDefault`, `MeasurementTypeDefault`, `FireModeDefault`, `LimitDurationDefault`, `FireDurationMS`, `FireDelayMS`.
|
|||
|
|
- **`SquibFireMode[] AvailableModes { get; }`**
|
|||
|
|
`{ CAP, CONSTANT }`.
|
|||
|
|
- **`bool IsConstantCurrent { get; }`**
|
|||
|
|
`true` if `FireModeDefault == SquibFireMode.CONSTANT`.
|
|||
|
|
- **`bool ToleranceValid { get; }`**
|
|||
|
|
`true` if `ToleranceLowDefault < ToleranceHighDefault`.
|
|||
|
|
- **`bool Validate()`**
|
|||
|
|
Returns `ToleranceValid`.
|
|||
|
|
- **`static void CommitChange(SquibSettingDefaults settingDefaults, string user)`**
|
|||
|
|
Commits `_defaultSquib` (cast to `SensorData`) via `SensorsCollection.SensorsList.Commit`.
|
|||
|
|
- **`static SquibSettingDefaults GetSquibSettingsDefault(string user)`**
|
|||
|
|
Retrieves sensor by serial number `SensorConstants.TEST_SPECIFIC_SQUIB_SERIAL`, wraps in `ISensorData`, returns instance.
|
|||
|
|
|
|||
|
|
#### `ThermocouplerSetting`, `CanSetting`, `StreamInputSetting`, `StreamOutputSetting`, `UartSetting`, `DigitalOutputSetting`, `SquibSetting`
|
|||
|
|
All are concrete `SensorData` subclasses with:
|
|||
|
|
- **`SetDefaults(SensorData sd)`** — static method that initializes sensor metadata (e.g., `Bridge`, `Manufacturer`, `Model`, `BridgeResistance`, `SupportedExcitation`, etc.) to type-specific defaults.
|
|||
|
|
- **`Commit(SensorData setting)`** — static method that calls `SetDefaults`, wraps in a record type (`ICANRecord`, `IStreamInputRecord`, etc.), invokes `DbOperations.Sensors*UpdateInsert`, and sets `setting.DatabaseId` on success (`hr == 0`).
|
|||
|
|
- **Constructors**:
|
|||
|
|
- Default (`: base()`)
|
|||
|
|
- Copy (`: base(copy)`)
|
|||
|
|
- Record-based (`ICANRecord`, `IStreamInputRecord`, `ISquibDbRecord`, etc.) — populates fields from database record; logs exceptions via `APILogger`.
|
|||
|
|
|
|||
|
|
#### `SensorRange`
|
|||
|
|
- **`double Low`, `Medium`, `High`** — range values.
|
|||
|
|
- **`SensorRange(string value)`**
|
|||
|
|
Parses comma-separated string (e.g., `"1.0,2.0,3.0"`); throws `InvalidDataException` if not exactly 3 values.
|
|||
|
|
- **`string ToSerializeString()`**
|
|||
|
|
Returns `"Low,Medium,High"` using invariant culture.
|
|||
|
|
- **`SensorRange(XElement elem, string prefix, string tblName, string id)`**
|
|||
|
|
Parses `<prefix-SensorRange>` element with `Low`, `Medium`, `High` attributes; throws if missing.
|
|||
|
|
- **`XElement ToXElement(string prefix)`**
|
|||
|
|
Creates `<prefix-SensorRange>` with attributes.
|
|||
|
|
- **`void Update(XElement elem, string prefix)`**
|
|||
|
|
Updates existing element’s attributes.
|
|||
|
|
|
|||
|
|
#### `FactorySensorModel`
|
|||
|
|
- **`static SensorModel CreateModelFromSensor(SensorData sd, SensorCalibration sc, User currentUser)`**
|
|||
|
|
Copies all relevant fields from `sd` and `sc` into a new `SensorModel`, including `LastModified = DateTime.Now`, `LastUpdatedBy = currentUser.UserName`.
|
|||
|
|
|
|||
|
|
#### `SensorDBBase`
|
|||
|
|
- **`static XElement GetTagValue(XElement elem, string tag, string id, string TableName)`**
|
|||
|
|
Returns element; throws if missing.
|
|||
|
|
- **`static XElement GetTagValueSafe(XElement elem, string tag, string id, string TableName)`**
|
|||
|
|
Returns element or `null`.
|
|||
|
|
- **`static void GetValue<T>(...)`** — generic overloads to extract values (string, int, double, bool, enums like `SensorStatus`, `BridgeType`, `ShuntMode`, `ExcitationVoltageOption`, `FilterClassType`, `ZeroMethodType`) from XML elements, with safe parsing and fallbacks (e.g., `double.NaN`, `ExcitationVoltageOption.Undefined` → `Volt5`).
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 3. Invariants
|
|||
|
|
|
|||
|
|
- **`StreamInputSettingDefaults.UDPAddress`** must be a well-formed absolute URI starting with `"udp"` (case-insensitive) for `Validate()` to return `true`.
|
|||
|
|
- **`SquibSettingDefaults.ToleranceValid`** requires `ToleranceLowDefault < ToleranceHighDefault`.
|
|||
|
|
- **`DigitalOutputDefaults.FlowControl`** is *always* `Handshake.None` (hardcoded per comment).
|
|||
|
|
- **`UartSettingDefaults.FlowControl`** is *always* `Handshake.None` (hardcoded per comment).
|
|||
|
|
- All `*Setting` types call `SetDefaults(...)` during construction and `Commit(...)`, ensuring consistent metadata (e.g., `Bridge`, `Manufacturer`, `Model`) before persistence.
|
|||
|
|
- `SensorDBBase.GetValue<T>` methods are designed to be resilient: enums parse with fallbacks, `double` parsing falls back to `NaN`, and XML parsing throws descriptive exceptions.
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 4. Dependencies
|
|||
|
|
|
|||
|
|
### Dependencies *of* this module:
|
|||
|
|
- **`DTS.Common.*`**:
|
|||
|
|
- `DTS.Common.Base.BasePropertyChanged` (base for property-change-aware classes)
|
|||
|
|
- `DTS.Common.Enums.*` (`ExcitationVoltageOptions`, `DigitalOutputModes`, `SquibFireMode`, `BridgeType`, `ShuntMode`, etc.)
|
|||
|
|
- `DTS.Common.Interface.Sensors` (`ISensorData`, `IThermocouplerRecord`, `ICANRecord`, etc.)
|
|||
|
|
- `DTS.Common.Classes.Sensors` (`SensorData`, `SensorCalibration`, `SensorModel`)
|
|||
|
|
- `DTS.Common.Storage` (`DbOperations`, `CANRecord`, `StreamInputRecord`, etc.)
|
|||
|
|
- `DTS.Common.Utilities.Logging` (`APILogger`)
|
|||
|
|
- `DTS.Common.Constant.*` (`DigitalInputs`, `EmbeddedSensors`)
|
|||
|
|
- **`DTS.Slice.Users.UserSettings`** (`TestSetupDefaults`, `PropertyEnums`)
|
|||
|
|
- **`DTS.Slice.Users`** (`User`)
|
|||
|
|
- **`DTS.SensorDB.SensorsCollection`** (used in `DigitalOutputDefaults`, `SquibSettingDefaults`, `DigitalOutputSetting`)
|
|||
|
|
- **`System.*`**: `System.Xml.Linq`, `System.IO.Ports`, `System.Data`, `System.Data.SqlClient`
|
|||
|
|
|
|||
|
|
### Dependencies *on* this module:
|
|||
|
|
- UI/configuration layers likely consume `*SettingDefaults` types to populate forms and commit changes.
|
|||
|
|
- `DbOperations` and `SensorsCollection` depend on record types (`*Record`) defined in `DTS.Common.Storage` (not shown here), which are instantiated by `*Setting.Commit(...)`.
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 5. Gotchas
|
|||
|
|
|
|||
|
|
- **`StreamInputSettingDefaults.Validate()`** only checks `UDPAddress` format; it does *not* verify network reachability or correctness of port/protocol beyond `"udp"` prefix.
|
|||
|
|
- **`CanSettingDefaults.Validate()`** and others (e.g., `UartSettingDefaults`, `DigitalInputSensorDefault`) always return `true`—no validation logic is implemented beyond `SquibSettingDefaults`.
|
|||
|
|
- **Hardcoded `FlowControl = Handshake.None`** in `UartSettingDefaults` and `DigitalOutputDefaults` is explicitly commented (`//FB 30486`); changing this would require code modification.
|
|||
|
|
- **`SensorDBBase.GetValue<T>` for `ExcitationVoltageOption`** normalizes strings like `"2.5"` → `"Volt2_5"` and falls back to `Volt5` on parse failure—this may mask invalid input.
|
|||
|
|
- **`SquibSetting.SquibDescription`** is a wrapper around `SerialNumber`; changing it updates `SerialNumber`.
|
|||
|
|
- **`SquibSetting.Comment`** defaults to `SerialNumber` or `UserValue1`; `UserValue1` is also used for `ArticleId`/`EID` in some contexts.
|
|||
|
|
- **`DigitalOutputSetting` and `SquibSetting` constructors accept `IDigitalOutDbRecord`/`ISquibDbRecord` and `IDataRecord`—these are likely used during database loading but may not be thread-safe or idempotent.
|
|||
|
|
- **`StreamInputSettingDefaults.GetStreamInputSettingsDefault(string user)`** ignores the `user` parameter and uses a constant serial number—this may be intentional for test-specific defaults.
|
|||
|
|
- **`StringResources.Designer.cs`** is auto-generated; manual edits will be overwritten.
|
|||
|
|
- **`SensorRange`** uses invariant culture for parsing/formatting—assumes decimal separator is `.`.
|
|||
|
|
|
|||
|
|
None identified beyond the above.
|