81 lines
5.0 KiB
Markdown
81 lines
5.0 KiB
Markdown
---
|
||
source_files:
|
||
- DataPRO/DASFactoryDb/ARM/ARM.cs
|
||
generated_at: "2026-04-16T03:53:10.384931+00:00"
|
||
model: "Qwen/Qwen3-Coder-Next-FP8"
|
||
schema_version: 1
|
||
sha256: "dd0ee32e99af1e4e"
|
||
---
|
||
|
||
# ARM
|
||
|
||
### **Purpose**
|
||
This module provides a centralized static interface for updating the ARM (Armed/Recording Monitor) status of a Data Acquisition System (DAS) record in the database. It acts as a thin data-access wrapper that translates in-memory ARM state flags, metrics, and metadata into a stored procedure call (`sp_ArmStatusSet`) to persist the current operational state of a DAS unit—such as armed status, triggering, fault conditions, recording progress, and sensor readings—ensuring consistency between the application’s runtime state and the persisted state in the database.
|
||
|
||
---
|
||
|
||
### **Public Interface**
|
||
|
||
#### `ARM.SetArmStatus(...)`
|
||
```csharp
|
||
public static void SetArmStatus(
|
||
int iDASRecordId,
|
||
bool isArmed,
|
||
bool isTriggered,
|
||
bool isTriggerShorted,
|
||
bool isStartShorted,
|
||
bool isRecording,
|
||
bool isFaulted,
|
||
bool isInRealtime,
|
||
bool isInFlashWrite,
|
||
bool isUndefined,
|
||
bool isInPostTestDiagnostics,
|
||
double timeRemainingSeconds,
|
||
double percentComplete,
|
||
ulong totalSamples,
|
||
ulong currentSample,
|
||
uint sampleRate,
|
||
double? inputMilliVolts,
|
||
double? batteryMilliVolts,
|
||
int? eventNumber,
|
||
int recordingMode,
|
||
string faultMessage,
|
||
bool isRearming,
|
||
bool hasBeenRecording,
|
||
double? timeLeftInArm
|
||
)
|
||
```
|
||
**Behavior**: Updates the ARM status for the DAS record identified by `iDASRecordId` by invoking the stored procedure `sp_ArmStatusSet`. All parameters map directly to corresponding database columns/parameters. If the database connection is not active (`!DbWrapper.Connected`), the method returns early without executing the procedure. It handles nullable types by substituting defaults (`0` for numerics, `""` for strings) before passing to SQL. It captures and processes output parameters (`@errorNumber`, `@errorMessage`, `@new_id`) via `DbWrapper.ProcessReturn`, and ensures the command connection is disposed in a `finally` block.
|
||
|
||
---
|
||
|
||
### **Invariants**
|
||
- **Connection requirement**: The method performs no operation if `DbWrapper.Connected` is `false`.
|
||
- **Non-nullability enforcement**: Nullable parameters (`double?`, `int?`) are coalesced to non-null defaults (`0` or `""`) before being passed to SQL—no `NULL` values are sent for any parameter.
|
||
- **Stored procedure contract**: Assumes `sp_ArmStatusSet` exists and accepts the exact 24 parameters listed (including 3 output parameters).
|
||
- **Resource cleanup**: The underlying `SqlCommand.Connection` is explicitly disposed after execution, regardless of success or failure.
|
||
- **No return value**: The method does not expose the output values (`@errorNumber`, `@errorMessage`, `@new_id`) to callers—processing is delegated entirely to `DbWrapper.ProcessReturn`.
|
||
|
||
---
|
||
|
||
### **Dependencies**
|
||
- **Internal dependencies**:
|
||
- `DbWrapper.Connected` (property) and `DbWrapper.GetDASFactoryCommand()` (method) — used to check connectivity and obtain a configured `SqlCommand`.
|
||
- `DbWrapper.ProcessReturn(...)` — processes output parameters from the stored procedure call.
|
||
- **External dependencies**:
|
||
- `System.Data` and `System.Data.SqlClient` — for `SqlDbType`, `CommandType`, `SqlParameter`, `ParameterDirection`, and `IDbCommand`.
|
||
- Database: Requires the stored procedure `sp_ArmStatusSet` to exist in the DASFactory database with the exact parameter list and types.
|
||
|
||
**Depended on by**: Presumably other components in the DAS system that need to update ARM status (e.g., recording state machines, fault handlers, telemetry services)—though not visible in this file.
|
||
|
||
---
|
||
|
||
### **Gotchas**
|
||
- **Silent no-op on disconnect**: If `DbWrapper.Connected` is `false`, the method returns without logging or raising an exception—this may mask connectivity issues.
|
||
- **Loss of null semantics**: Nullable parameters (`inputMilliVolts`, `batteryMilliVolts`, `eventNumber`, `timeLeftInArm`) are converted to `0` or `""` when `null`, potentially overwriting meaningful `NULL` states in the database (e.g., “unknown” vs. “zero”).
|
||
- **`ulong` → `int` truncation risk**: `totalSamples`, `currentSample` (`ulong`) are passed as `SqlDbType.Int` (signed 32-bit), which may cause silent overflow or incorrect values for large sample counts (> 2³¹−1).
|
||
- **Hardcoded stored procedure name**: The procedure name `"sp_ArmStatusSet"` is hardcoded—no abstraction or configuration layer.
|
||
- **No validation of input values**: No checks for invalid combinations (e.g., `isRecording == true` but `isArmed == false`)—assumes caller maintains logical consistency.
|
||
- **Output parameters unused by caller**: Though `@new_id` is declared and returned, its value is not exposed—suggests possible legacy or incomplete implementation.
|
||
|
||
*None identified from source alone.* — *Note: The above gotchas are inferred from observed behavior and type mismatches; no explicit documentation or comments exist in the source.* |