7.1 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |||||
|---|---|---|---|---|---|---|---|---|---|
|
2026-04-16T04:24:35.181988+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 19e719e00bdf4549 |
StateMachine Module Documentation
1. Purpose
This module implements a finite state machine (FSM) for managing the operational states of a data acquisition system (DAS), with states such as HardwareDiscovery, Configure, Diagnose, Realtime, and their transition points (e.g., RealtimeStart, HardwareDiscoveryStart). It enables deterministic state transitions based on runtime status and configuration parameters, ensuring the system progresses through initialization, configuration, diagnostics, and real-time operation phases in a controlled manner. The tests validate the behavior of individual state classes and their StateSelector() logic, which determines the next state based on current status flags and parameters.
2. Public Interface
The following classes are defined in the DTS.DASLib.Service.StateMachine namespace (inferred from test imports). Each class represents a state in the state machine and exposes a StateSelector() method to determine the next state.
Realtime
- Constructor:
Realtime()
Initializes the state; setsStateproperty toState.Realtime. - Property:
State→State
Returns the current state identifier (State.Realtime). - Method:
StateSelector()→DASState(not tested directly, but implied by pattern)
Behavior inferred from other states: returns the next state based on status/params. Not directly exercised in provided tests.
Configure
- Constructor:
Configure()
Initializes the state. - Method:
StateSelector()→DASState
Returns aDASStatewithStateset toState.ConfigureStart.
RealtimeStart
- Constructor:
RealtimeStart()
Initializes the state. - Property:
Status→Status(exposesRealtimeStatus)
ContainsRealtimeStatus.CouldNotStartRealtime(boolean). - Method:
StateSelector()→DASState- If
RealtimeStatus.CouldNotStartRealtime == true, returnsState.RealtimeStart. - If
RealtimeStatus.CouldNotStartRealtime == false, returnsState.Realtime.
- If
Diagnose
- Constructor:
Diagnose()
Initializes the state. - Property:
Status→Status(exposesDiagnoseParams)
Contains:DiagnoseParams.ProceedToRealtimeWhenDone(bool)DiagnoseParams.RequireAllUnitsPassDiagnostic(bool)DiagnoseParams.AllUnitsPassedDiagnostic(bool)
- Method:
StateSelector()→DASState
Returns:State.RealtimeStartifProceedToRealtimeWhenDone == trueand
(RequireAllUnitsPassDiagnostic == falseorAllUnitsPassedDiagnostic == true).State.Diagnoseotherwise (e.g., whenProceedToRealtimeWhenDone == false, or whenRequireAllUnitsPassDiagnostic == trueandAllUnitsPassedDiagnostic == false).
HardwareDiscoveryStart
- Constructor:
HardwareDiscoveryStart()
Initializes the state; setsStateproperty toState.HardwareDiscoveryStart. - Property:
State→State
ReturnsState.HardwareDiscoveryStart. - Property:
Status→Status(exposesHardwareDiscoveryParamsandHardwareDiscoveryStatusInfo)
Contains:HardwareDiscoveryParams.ProceedWhenDone(bool)HardwareDiscoveryParams.RequireAllDASFound(bool)HardwareDiscoveryParams.GoToDownload(bool)HardwareDiscoveryStatusInfo.AllDASFound(bool)HardwareDiscoveryStatusInfo.SomeUnitsInArmState(bool)
- Method:
StateSelector()→DASState
Returns the next state based on:- If
ProceedWhenDone == true:State.DownloadifGoToDownload == trueandAllDASFound == true(andRequireAllDASFound == true).State.ConfigureifGoToDownload == falseand eitherAllDASFound == trueorRequireAllDASFound == false.State.ArmifAllDASFound == false,RequireAllDASFound == true,GoToDownload == false, andSomeUnitsInArmState == true.State.HardwareDiscoveryifAllDASFound == false,RequireAllDASFound == true,GoToDownload == false, andSomeUnitsInArmState == false.
- If
3. Invariants
- Each state class’s
Stateproperty (where exposed) must return the correspondingStateenum value (e.g.,Realtime.State == State.Realtime). StateSelector()must return a non-nullDASStateobject with a validStatefield.- Transitions are deterministic: given identical
Statusand parameter values,StateSelector()must return the same next state. HardwareDiscoveryStart.StateSelector()only evaluates transitions whenProceedWhenDone == true(based on test arrangements); behavior whenProceedWhenDone == falseis not specified in tests.
4. Dependencies
- Internal Dependencies:
DTS.DASLib.Service.StateMachinenamespace (contains state classes andStateenum).Statustype (contains nestedRealtimeStatus,DiagnoseParams,HardwareDiscoveryParams,HardwareDiscoveryStatusInfo).DASStatetype (returned byStateSelector()).Stateenum (defines state identifiers:Realtime,ConfigureStart,RealtimeStart,Diagnose,HardwareDiscoveryStart,HardwareDiscovery,Arm,Download,Configure).
- Test Dependencies:
NUnitfor test framework ([TestFixture],[Test],Assert.That).NSubstitute(used inHardwareDiscoveryStartShouldtests, though not instantiated in provided snippets).
- Inferred Consumers:
A higher-level state machine controller (not shown) likely instantiates these state classes and callsStateSelector()to drive transitions.
5. Gotchas
- Ambiguous
StatusType: TheStatusproperty’s full structure (e.g.,RealtimeStatus,DiagnoseParams,HardwareDiscoveryParams) is inferred from test usage but not defined in the source. Its exact shape and default values are unknown. - Missing
StateSelector()Implementation Details: The tests do not cover edge cases (e.g.,ProceedWhenDone == falseinHardwareDiscoveryStart, or invalid parameter combinations). Behavior in untested scenarios is unspecified. - Redundant Test for
DiagnoseShould.State_ShouldBeRealtime: This test instantiatesnew Realtime()but assertssut.State == State.Realtime, which is identical toRealtimeShould.State_ShouldBeRealtime. Likely a copy-paste error in tests. - No Error Handling Tests: No tests verify behavior when
Statusis null, or when parameters conflict (e.g.,RequireAllUnitsPassDiagnostic == trueandAllUnitsPassedDiagnostic == truebutProceedToRealtimeWhenDone == false—though this is covered inDiagnoseShould). - State Names vs. Class Names: The class
RealtimeStartcorresponds toState.RealtimeStart, butConfigureclass returnsState.ConfigureStart(notState.Configure). This mismatch may cause confusion.
None identified beyond the above.