9.6 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |||
|---|---|---|---|---|---|---|---|
|
2026-04-16T03:47:17.202169+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 095345d9b2c6bf7d |
TDASCommands
Documentation: TDAS Test Trigger Commands Module
1. Purpose
This module implements command classes for interacting with TDAS hardware modules to perform test trigger operations—specifically, arming, querying status, and disabling the trigger. It provides two public command types: TestTrigger (single-module, unicast) and TestTriggerBroadcast (single-module broadcast, unicast to a specific module index). These commands construct and send ASCII-based protocol commands (TESTTRIG or *<N>TESTTRIG) to TDAS devices and parse the ASCII response to extract the trigger status (ARMED or OFF). The module relies on the shared CommandBase and TDASCommandPacketBase infrastructure for communication, sequencing, and response handling.
2. Public Interface
TestTrigger class
Public, concrete command class for single-module test trigger operations.
-
int ModuleIndex
Gets or sets the module index (0–9). Setting it enforces<10and disablesRackCommand. -
SubCommandValues SubCommand
Gets/sets the subcommand to send:ARM,STATUS, orOFF.- Getter parses
_CommandString.SubCommandasSubCommandValues. - Setter writes the enum value as a string into
_CommandString.SubCommand.
- Getter parses
-
StatusValues TriggerStatus
Gets the parsed trigger status from the last response:ARMEDorOFF.- Getter parses
_CommandString.StatusasStatusValues. - Value is populated during
ProcessData().
- Getter parses
-
TestTrigger(ICommunication sock)
Constructor with default 30s timeout. InitializesTDASCommandPacketBasewithTestTriggerCommandString, setsRebuildBytes = true,RackCommand = false, and defaultSubCommand = STATUS. -
TestTrigger(ICommunication sock, int msTimeout)
Constructor with configurable timeout. Same initialization as above, but uses provided timeout.
TestTriggerBroadcast class
Public, concrete command class for broadcast test trigger to a specific module.
-
SubCommandValues SubCommand
Same semantics asTestTrigger.SubCommand, operating on_CommandString.SubCommandof the underlyingTestTriggerBroadcastCommandString. -
TestTriggerBroadcast(ICommunication sock, int moduleIndex)
Constructor with default timeout. InitializesTDASCommandPacketBasewithTestTriggerBroadcastCommandString(moduleIndex), setsRackCommand = false,RebuildBytes = true, and defaultSubCommand = STATUS. -
TestTriggerBroadcast(ICommunication sock, int moduleIndex, int msTimeout)
Constructor with configurable timeout. Same initialization as above.
Internal helper classes (not part of public API, but referenced for completeness)
-
TestTriggerCommandString
Internal subclass ofCommandString._CommandString => "TESTTRIG"_CommandDescription => "Test trigger"SubCommandandStatusproperties (string) store subcommand and response status.GetParameters()returns" <SubCommand>"as ASCII bytes.
-
TestTriggerBroadcastCommandString
Internal subclass ofCommandString._CommandString => "*<N>TESTTRIG"(ifModuleIndex >= 0) or"*TESTTRIG"otherwise._CommandDescriptionmirrors_CommandString.ModuleIndex,SubCommandproperties.- Constructor accepts
moduleIndex. GetParameters()same asTestTriggerCommandString.
3. Invariants
-
ModuleIndex constraint:
ModuleIndexmust be<10(enforced inTDASCommandPacketBase.ModuleIndexsetter). Setting it to>=10throws an exception. -
RackCommand mutual exclusion:
SettingModuleIndexinTDASCommandPacketBasesetsRackCommand = false.RackCommandis onlytruewhenModuleIndexis unset (default' 'space) and not explicitly set to a digit. -
Default subcommand:
All constructors initialize_CommandString.SubCommand = "STATUS". -
Response parsing invariant:
ProcessData()inTestTriggerparses the response into tokens; status is assigned fromtokens[1]iftokens.Length >= 2. If parsing fails,_CommandString.Statusremains unchanged. -
Response format assumption:
TDAS responses are ASCII, newline-terminated (\r\n), and contain the command string followed by a space and status (e.g.,TESTTRIG ARMED\r\n). Parsing assumes this format. -
RebuildBytes = true:
AllTestTrigger*constructors setRebuildBytes = true, ensuringCommandString.GetBytes()regenerates the byte array on eachToBytes()call (critical for dynamicSubCommandchanges).
4. Dependencies
Imports / References (from source):
DTS.Common.ICommunication→ICommunicationinterface for socket communication.DTS.DASLib.Command.TDASnamespace:CommandBase(base class for all commands, providesProcessData,ResponseData,SyncExecute, throttling).TDASCommandPacketBase(packet construction, verification, MDB mode support).CommandString(abstract base for command strings).
System.Text.Encoding(ASCII encoding/decoding).System.Threading(used inCommandBaseforSemaphoreSlimthrottling).
Inferred callers:
- Likely instantiated by higher-level test or configuration logic (e.g., test harnesses, calibration tools).
- Uses
CommandBaseinfrastructure, so depends on:APILogger(for logging errors and command/response).- Throttling via
CommandBase.InitializeSemaphore()(default: 3 concurrent operations, 100ms delay).
Dependencies on other modules:
TDASCommandPacketBase→ depends onMDB_BLOCK(for data mode parsing),CommandPacketBase(base), andCommandString.CommandBase→ depends on logging infrastructure (TextLogger,APILogger), threading (SemaphoreSlim), andAbstractCommandBase.
5. Gotchas
-
ModuleIndexparsing is fragile:
ModuleIndexgetter inTDASCommandPacketBaseusesint.Parse(new string(_moduleIndex, 1)). If_moduleIndexis' '(space), this throwsFormatException. This is avoided inTestTriggerconstructors becauseModuleIndexis never explicitly set, but if used directly, it may fail. -
TriggerStatusmay be stale or empty:
TriggerStatusreads_CommandString.Status, which is only updated inProcessData(). IfResponseDatais accessed beforeProcessData()runs (e.g., viaResponseDatagetter),ProcessData()executes—but if the response is malformed or missing,_CommandString.Statusmay remainnullor unchanged, causingEnum.Parseto throw. -
ProcessData()inTestTriggeris custom and narrow:
UnlikeCommandBase.ProcessData(),TestTrigger.ProcessData()manually parses the response usingGetCommandPortion()andResponseData.Split. It assumes the response contains the command string followed by a space and status. Deviations (e.g., extra whitespace, different order) may cause parsing failure. -
No validation of
SubCommandenum values in setter:
SubCommandsetter directly assignsvalue.ToString()to_CommandString.SubCommand. If an invalid enum value is passed (e.g., via reflection or cast), no validation occurs—thoughEnum.Parsein getter may throw. -
TestTriggerBroadcastCommandString.ModuleIndexis not validated:
The broadcast command accepts anymoduleIndex, but the command string uses*<N>TESTTRIG. IfmoduleIndex < 0, it falls back to*TESTTRIG(broadcast to all modules). This may be unintended. -
Throttling is global and static:
CommandBaseuses static_pooland_semaphoreDelay. IfInitializeSemaphore()is not called, defaults (spots=3,delay=100ms) apply. This affects allTestTrigger/TestTriggerBroadcastinstances. -
RebuildBytesmust betruefor dynamic updates:
IfRebuildBytesis accidentally set tofalse, changingSubCommandwill not affect the outgoing command bytes untilRebuildBytes = trueorcs.RebuildBytes()is called. -
No error handling in
ProcessData()for malformed responses:
IfResponseDatadoes not contain the expected format (e.g., missing\r\n, insufficient tokens),ProcessData()silently returns without updating_CommandString.Status. This may lead to stale status values. -
GetParameters()returns a leading space:
BothTestTriggerCommandStringandTestTriggerBroadcastCommandStringreturn" <SubCommand>"(note leading space). This matches TDAS protocol expectations but is non-obvious. -
ModuleIndexsetter inTDASCommandPacketBasethrows on>=10:
This is a hard constraint. If future hardware supports >10 modules, this will break. -
ExpectsData = trueby default inCommandString:
TestTrigger/TestTriggerBroadcastdo not override this, soExpectsData = true. If the TDAS response forTESTTRIGis status-only (no data),VerifyPacket()may behave unexpectedly (seeTDASCommandPacketBase.VerifyPacket()logic). -
ToCommandString()strips control characters:
ToCommandString()removes\r\nand\0, which may obscure debugging if raw bytes are needed. -
CommandBase.ProcessData()may throw:
IfResponseDatacontains"ERR",ProcessData()throwsInvalidOperationException. This is caught only if the caller handles it. -
TestTriggerBroadcastdoes not exposeModuleIndex:
ThemoduleIndexis stored in the internalTestTriggerBroadcastCommandString, but not exposed as a property. Callers must track it externally.
End of documentation.