117 lines
6.5 KiB
Markdown
117 lines
6.5 KiB
Markdown
|
|
---
|
||
|
|
source_files:
|
||
|
|
- DataPRO/SensorDB/TDM/TDMCSVImport.cs
|
||
|
|
generated_at: "2026-04-17T15:59:59.064474+00:00"
|
||
|
|
model: "zai-org/GLM-5-FP8"
|
||
|
|
schema_version: 1
|
||
|
|
sha256: "163b7877035d65a4"
|
||
|
|
---
|
||
|
|
|
||
|
|
# TDMCSVImport Documentation
|
||
|
|
|
||
|
|
## 1. Purpose
|
||
|
|
|
||
|
|
`TDMCSVImport` is a parser that converts TDM (Test Data Management) CSV sensor configuration files into `DTS.SensorDB.SensorData` objects. It handles the mapping between CSV column labels and internal system enums, performs data validation, applies default values for missing/invalid fields, and transforms measurement types, filter settings, and calibration parameters into the system's sensor data model. The class exists to support legacy TDM CSV file formats in the sensor database import workflow.
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 2. Public Interface
|
||
|
|
|
||
|
|
### Enum: `TDMCSVImport.TAGS`
|
||
|
|
Defines all recognized CSV column identifiers used in TDM sensor import files.
|
||
|
|
|
||
|
|
**Values:**
|
||
|
|
- `SENSOR_CSV_LABEL_SERIAL_NO`, `SENSOR_CSV_LABEL_COMMENT`, `SENSOR_CSV_LABEL_EID`, `SENSOR_CSV_LABEL_CALDATE`, `SENSOR_CSV_LABEL_MANUFACTURER`, `SENSOR_CSV_LABEL_SENSOR_TYPE`, `SENSOR_CSV_LABEL_UNITS`, `SENSOR_CSV_LABEL_CAPACITY_EU`, `SENSOR_CSV_LABEL_MEASUREMENT_TYPE`, `SENSOR_CSV_LABEL_EXCITATION_VOLTS`, `SENSOR_CSV_LABEL_SENSITIVITY`, `SENSOR_CSV_LABEL_SENSITIVITY_UNITS`, `SENSOR_CSV_LABEL_INVERT`, `SENSOR_CSV_LABEL_USE_SHUNT_CAL`, `SENSOR_CSV_LABEL_BRIDGE_RESISTANCE_OHMS`, `SENSOR_CSV_LABEL_ZMO_MV`, `SENSOR_CSV_LABEL_ZMO_UPDATE_MV`, `SENSOR_CSV_LABEL_ZMO_TOLERANCE_MV`, `SENSOR_CSV_LABEL_REMOVE_ZMO_OFFSET`, `SENSOR_CSV_LABEL_TEST_DEVICE`, `SENSOR_CSV_LABEL_TEST_DEVICE_TYPE`, `SENSOR_CSV_LABEL_CODE`, `SENSOR_CSV_LABEL_JCODE`, `SENSOR_CSV_LABEL_FILTER_TYPE`, `SENSOR_CSV_LABEL_FILTER_FREQUENCY`, `SENSOR_CSV_LABEL_RANGE_0`, `SENSOR_CSV_LABEL_RANGE_1`, `SENSOR_CSV_LABEL_RANGE_2`, `SENSOR_CSV_LABEL_RANGE_3`, `SENSOR_CSV_LABEL_TOYOTA_CALC_1`, `SENSOR_CSV_LABEL_TOYOTA_CALC_2`, `SENSOR_CSV_LABEL_TOYOTA_CALC_3`, `SENSOR_CSV_LABEL_ZERO_METHOD`, `SENSOR_CSV_LABEL_ZERO_INITIAL_EU`, `SENSOR_CSV_LABEL_ZERO_TIME_START_MSEC`, `SENSOR_CSV_LABEL_ZERO_TIME_END_MSEC`, `SENSOR_CSV_LABEL_FLAGS`, `UNKNOWN`
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### Method: `LabelToTag`
|
||
|
|
```csharp
|
||
|
|
public static TAGS LabelToTag(string label)
|
||
|
|
```
|
||
|
|
Converts a CSV column header string to its corresponding `TAGS` enum value. Throws `NotSupportedException` for unrecognized labels.
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### Method: `GetSensor`
|
||
|
|
```csharp
|
||
|
|
public static DTS.SensorDB.SensorData GetSensor(
|
||
|
|
string[] tokens,
|
||
|
|
TAGS[] tagOrder,
|
||
|
|
ref List<string> errors,
|
||
|
|
Dictionary<string, string> sensorTypeToDimension)
|
||
|
|
```
|
||
|
|
Parses a single CSV row into a `SensorData` object.
|
||
|
|
|
||
|
|
**Parameters:**
|
||
|
|
- `tokens` - Array of string values from a single CSV row
|
||
|
|
- `tagOrder` - Array of `TAGS` indicating which column each token corresponds to (must be parallel to `tokens`)
|
||
|
|
- `errors` - Reference to a list that will collect parsing error/warning messages
|
||
|
|
- `sensorTypeToDimension` - Dictionary mapping sensor type strings to physical dimension strings
|
||
|
|
|
||
|
|
**Returns:** A populated `SensorData` object with `Calibration` initialized.
|
||
|
|
|
||
|
|
**Behavior:**
|
||
|
|
- Iterates through tokens in parallel with `tagOrder`
|
||
|
|
- Strips leading `=` and surrounding `"` characters from token values
|
||
|
|
- Parses each field according to its tag type
|
||
|
|
- Applies default values for missing/invalid capacity (defaults to 1) and units (defaults to "g")
|
||
|
|
- Sets `UUID` to the serial number value
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 3. Invariants
|
||
|
|
|
||
|
|
1. **Parallel Array Assumption**: `tokens` and `tagOrder` arrays must have corresponding indices; iteration stops at the shorter length (`i < tokens.Length && i < tagOrder.Length`).
|
||
|
|
|
||
|
|
2. **Invariant Culture Parsing**: All numeric parsing uses `CultureInfo.InvariantCulture` except for `SENSOR_CSV_LABEL_SENSITIVITY` which uses current culture.
|
||
|
|
|
||
|
|
3. **Calibration Initialization**: The returned `SensorData` always has `sd.Calibration` initialized to a new `SensorCalibration` instance.
|
||
|
|
|
||
|
|
4. **UUID Assignment**: `sd.UUID` is always set equal to `sd.SerialNumber` at the end of parsing.
|
||
|
|
|
||
|
|
5. **Minimum Capacity**: If `Capacity < 1`, it is forced to `1` with an error message added.
|
||
|
|
|
||
|
|
6. **Default Display Unit**: If `DisplayUnit` is null or whitespace, it defaults to `"g"` with an error message added.
|
||
|
|
|
||
|
|
7. **Excitation Voltage Default**: An excitation voltage of `0` is treated as `5.0` (for "Voltage Insertion" mode).
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 4. Dependencies
|
||
|
|
|
||
|
|
### This Module Depends On:
|
||
|
|
- `DTS.Common.Classes.Sensors` - Provides `SensorConstants`
|
||
|
|
- `DTS.Common.DAS.Concepts` - Provides `ExcitationVoltageOptions`, `FilterClass`, `FilterClassType`, `NonLinearStyles`, `InitialOffsets`, `InitialOffset`
|
||
|
|
- `DTS.Common.Enums` - Provides `ShuntMode`
|
||
|
|
- `DTS.Common.Enums.Sensors` - Provides `ZeroMethodType`
|
||
|
|
- `DTS.SensorDB` - Provides `SensorData`, `SensorCalibration`
|
||
|
|
- `System.Data.SqlTypes` - Used for `SqlDateTime.MinValue` as fallback date
|
||
|
|
|
||
|
|
### What Depends On This Module:
|
||
|
|
- **Unclear from source alone** - No direct consumers are visible in this file.
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 5. Gotchas
|
||
|
|
|
||
|
|
1. **Misleading Class Name/Comment**: The class is named `TDMCSVImport` but the XML doc comment states it "handles logic of TDM CSV export" — this appears to be a documentation error.
|
||
|
|
|
||
|
|
2. **FIR100 Filter Not Supported**: `FILTERTYPE_FIR100` is converted to `FilterClassType.CFC180` with an error message added; the comment notes "FIR100 not supported by SLICE code currently?"
|
||
|
|
|
||
|
|
3. **Unused Fields**: Several fields are parsed but not utilized:
|
||
|
|
- `SENSOR_CSV_LABEL_ZMO_MV` - Parsed but no action taken
|
||
|
|
- `SENSOR_CSV_LABEL_ZMO_UPDATE_MV` - Parsed but no action taken
|
||
|
|
- `SENSOR_CSV_LABEL_TEST_DEVICE` - Marked "not currently used"
|
||
|
|
- `SENSOR_CSV_LABEL_TEST_DEVICE_TYPE` - Marked "not currently used"
|
||
|
|
- `SENSOR_CSV_LABEL_RANGE_3` - Case body is commented out entirely
|
||
|
|
|
||
|
|
4. **Inconsistent Date Parsing**: Dates with `/` separator expect `MM/DD/YYYY` format, while dates with `-` separator expect `YYYY-MM-DD` format. Double-slash `//` is replaced with single `/`.
|
||
|
|
|
||
|
|
5. **Sensitivity Parsing Inconsistency**: `SENSOR_CSV_LABEL_SENSITIVITY` uses `double.TryParse(sItem.Trim(), out d)` without specifying `NumberStyles` or `CultureInfo`, unlike all other numeric fields which use `InvariantCulture`.
|
||
|
|
|
||
|
|
6. **Quarter Bridge Not Supported**: The XML comment notes "the existing TDM code doesn't appear to consider 1/4 bridge."
|
||
|
|
|
||
|
|
7. **Toyota Calc Values**: `calc1`, `calc2`, `calc3` are concatenated into `UserValue3` using the invariant culture's list separator, but the purpose is unclear from this file alone.
|
||
|
|
|
||
|
|
8. **IRTRACC Special Handling**: `MEASTYPE_IRTRACC` triggers special calibration setup including `NonLinear = true` and specific polynomial coefficients (`LinearizationExponent = -75D / 175D`, `MMPerV = 1000D / dSensitivity`), and sets sensitivity to 0.
|