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

6.6 KiB
Raw Permalink Blame History

source_files, generated_at, model, schema_version, sha256
source_files generated_at model schema_version sha256
DataPRO/IService/Classes/InputRangeAttributes/GainDisabledAttribute.cs
DataPRO/IService/Classes/InputRangeAttributes/MaxInputRangeAttribute.cs
DataPRO/IService/Classes/InputRangeAttributes/GainAvailableUnmodifiedAttribute.cs
DataPRO/IService/Classes/InputRangeAttributes/MinInputRangeAttribute.cs
DataPRO/IService/Classes/InputRangeAttributes/FirmwareInputRangeAttribute.cs
2026-04-16T03:57:34.431495+00:00 Qwen/Qwen3-Coder-Next-FP8 1 9e76f2c3f64de0c9

InputRangeAttributes

Documentation: Input Range Attribute Classes

1. Purpose

This module defines a set of custom attribute classes used to annotate gain enumerations (likely in an input range configuration system) with metadata that controls gain behavior, availability, and interface constraints. Specifically, it enables fine-grained control over gain disablement, maximum/minimum input ranges (in mV), firmware-specific input ranges, and availability for unmodified hardware variants (e.g., Gen 3 SPS). These attributes are applied at compile-time via reflection and queried at runtime to enforce system-level constraints without hardcoding logic, supporting flexibility for calibration, hardware variants, and future tuning.

2. Public Interface

All classes reside in the DTS.DASLib.Service namespace and derive from System.Attribute. Each provides a static method to query the attribute value from an enum field (passed as object), and a constructor to set the attributes value.

  • GainDisabledAttribute

    • GainDisabledAttribute(bool disabled)
      Constructor. Sets _bDisabled to the provided value.
    • static bool IsGainDisabled(object o)
      Returns true if o is non-null, represents a valid enum field, and that field has a GainDisabledAttribute with _bDisabled == true. Returns false otherwise (including for null, missing members, or missing attribute).
  • MaxInputRangeAttribute

    • MaxInputRangeAttribute(double maxInputRangemV)
      Constructor. Sets _maximumInputRangemV to the provided value (in mV).
    • static double GetMaxInputRangemV(object o)
      Returns _maximumInputRangemV if o is non-null, represents a valid enum field, and that field has a MaxInputRangeAttribute. Returns 0D otherwise.
  • GainAvailableUnmodifiedAttribute

    • GainAvailableUnmodifiedAttribute(bool available)
      Constructor. Sets _bAvailable to the provided value.
    • static bool IsGainAvailableToUnmodified(object o)
      Returns false only if o is non-null, represents a valid enum field, and that field has a GainAvailableUnmodifiedAttribute with _bAvailable == false. Returns true otherwise (including for null, missing members, or missing attribute).
  • MinInputRangeAttribute

    • MinInputRangeAttribute(double minInputRangemV)
      Constructor. Sets _minimumInputRangemV to the provided value (in mV).
    • static double GetMinInputRangemV(object o)
      Returns _minimumInputRangemV if o is non-null, represents a valid enum field, and that field has a MinInputRangeAttribute. Returns 0D otherwise.
  • FirmwareInputRangeAttribute

    • FirmwareInputRangeAttribute(double firmwareInputRangemV)
      Constructor. Sets _firmwareInputRangeAttribute to the provided value (in mV).
    • static double GetFirmwareInputRangemV(object o)
      Returns _firmwareInputRangeAttribute if o is non-null, represents a valid enum field, and that field has a FirmwareInputRangeAttribute. Returns 0D otherwise.

3. Invariants

  • All attributes are optional by design: if an enum field lacks a given attribute, default values apply (e.g., IsGainDisabledfalse, IsGainAvailableToUnmodifiedtrue, range getters → 0D).
  • The static query methods assume the input o is an enum value (or null). They use o.ToString() to look up the corresponding MemberInfo via reflection (GetMember(o.ToString())).
  • Attribute values are immutable after construction (_bDisabled, _maximumInputRangemV, etc. are readonly).
  • Range values are interpreted as millivolts (mV).
  • The FirmwareInputRangeAttribute is intended to represent a firmware-selectable range, possibly derived from neighboring gain steps (e.g., midpoint between adjacent gains), to avoid unintended gain-step changes during operation.

4. Dependencies

  • Dependencies:
    • System (for Attribute, Type, reflection APIs).
    • Implicit dependency on the enum type(s) that these attributes annotate (e.g., InputRangeGain or similar). These attributes are meaningless without such enums.
  • Depended upon by:
    • Unknown from source alone. Likely used by input configuration, calibration, or firmware interface modules that inspect gain enums at runtime via reflection (e.g., to determine valid ranges or skip disabled gains).
    • All attributes reference the same FogBugz ticket (10080), suggesting a shared context (likely gain/range configuration for a specific hardware platform).

5. Gotchas

  • Reflection-based lookup is fragile:
    • GetMember(o.ToString()) assumes the enum field name matches ToString(). If the enum uses Display attributes or custom ToString() overrides, this may fail or return incorrect members.
    • If o.ToString() returns a non-field name (e.g., due to Flags enum formatting like "A, B"), GetMember may return an empty array → default values.
  • FirmwareInputRangeAttribute field name typo:
    • The private field is named _firmwareInputRangeAttribute (note: Attribute suffix), while the property/constructor parameter uses firmwareInputRangemV. This is likely a typo but is preserved as-is in the source.
  • No validation of range values:
    • No checks ensure MinInputRangeAttributeMaxInputRangeAttribute, or that FirmwareInputRangeAttribute lies between them. Consumers must enforce this.
  • 0D as sentinel value:
    • A return value of 0D from range getters could mean either: (a) the attribute is absent, or (b) the attribute was explicitly set to 0. Ambiguity may cause misinterpretation.
  • No documentation of enum usage:
    • The source files do not show how these attributes are applied (e.g., public enum Gain { [GainDisabled(true)] High = 3 }). Without concrete examples, it is unclear if attributes are applied to fields, values, or types.
  • No thread-safety guarantees:
    • Reflection calls (GetMember, GetCustomAttribute) are not inherently thread-safe in older .NET versions, though modern runtimes typically handle this robustly. Not explicitly documented.
  • None identified from source alone.