Files
DP44/docs/ai/DataPRO/SLICEDBCommands.md

272 lines
16 KiB
Markdown
Raw Permalink Normal View History

2026-04-17 14:55:32 -04:00
---
source_files:
- DataPRO/SLICEDBCommands/CommandBase.cs
- DataPRO/SLICEDBCommands/CommandPacket.cs
- DataPRO/SLICEDBCommands/CalibrationCommands.cs
- DataPRO/SLICEDBCommands/PowerCommands.cs
- DataPRO/SLICEDBCommands/ArmCommands.cs
- DataPRO/SLICEDBCommands/NetworkCommands.cs
- DataPRO/SLICEDBCommands/InformationCommands.cs
generated_at: "2026-04-17T15:50:07.536950+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "64be47562bf23e82"
---
# SLICEDBCommands Module Documentation
## 1. Purpose
This module implements a command pattern architecture for communicating with SLICE DB hardware devices. It provides a hierarchical class structure for constructing, sending, and receiving command packets over a communication interface (`ICommunication`). The module handles various device operations including power management (voltage/current queries and configuration), network settings (IP, MAC, netmask), device arming/disarming for data acquisition, and device information queries (serial number, firmware versions, time synchronization). Commands are organized by functional category, each inheriting from a category-specific abstract base class that itself inherits from `CommandBase`.
---
## 2. Public Interface
### CommandBase (Abstract)
**File:** `CommandBase.cs`
**Namespace:** `DTS.DASLib.Command.SLICEDB`
Base class for all SLICE DB commands. Inherits from `SliceCommandBase`.
| Constructor | Description |
|-------------|-------------|
| `CommandBase(DTS.Common.Interface.DASFactory.ICommunication sock)` | Initializes with default timeout and creates a new `CommandPacket`. |
| `CommandBase(DTS.Common.Interface.DASFactory.ICommunication sock, int TimeoutMillisec)` | Initializes with specified timeout in milliseconds. |
| Method | Signature | Description |
|--------|-----------|-------------|
| `GetCommandPacket()` | `protected override CommandPacketBase GetCommandPacket()` | Factory method returning a new `CommandPacket`. |
| `GetCommandPacket(byte[] buffer)` | `protected override CommandPacketBase GetCommandPacket(byte[] buffer)` | Factory method returning a `CommandPacket` constructed from byte buffer. |
---
### CommandPacket
**File:** `CommandPacket.cs`
**Namespace:** `DTS.DASLib.Command.SLICEDB`
Represents a command packet for SLICE DB communication. Inherits from `SliceCommandPacketBase`.
| Constructor | Description |
|-------------|-------------|
| `CommandPacket()` | Creates an empty command packet. |
| `CommandPacket(byte[] Bytes)` | Creates a command packet from raw byte data. |
| Enum | Values |
|------|--------|
| `CommandType` | `Reserved = 0x00`, `Diagnostics`, `GPIO`, `Information`, `Network`, `Power`, `Arm` |
| Method | Signature | Description |
|--------|-----------|-------------|
| `GetNextSequenceNumber()` | `public override void GetNextSequenceNumber()` | Thread-safe assignment of a globally incrementing sequence number to `SequenceNumber`. |
| `ConvertByteToCommandType(byte b)` | `public override object ConvertByteToCommandType(byte b)` | Converts a byte to `CommandType` enum. |
---
### DiagnosticsCommands (Abstract)
**File:** `CalibrationCommands.cs`
**Namespace:** `DTS.DASLib.Command.SLICEDB`
Base class for diagnostics-related commands.
| Enum | Values |
|------|--------|
| `Measurements` | `V1`, `BatteryVoltage`, `BatteryChargeCurrent`, `SliceBusCurrent`, `SliceBusVoltage` |
| `Commands` (protected) | `Reserved = 0x00`, `QueryOffset = 0x01`, `SetOffset = 0x02`, `QueryMultiplier = 0x03`, `SetMultiplier = 0x04` |
| Constructor | Description |
|-------------|-------------|
| `DiagnosticsCommands(DTS.Common.Interface.DASFactory.ICommunication sock)` | Sets `command.Type` to `CommandType.Diagnostics`. |
| `DiagnosticsCommands(DTS.Common.Interface.DASFactory.ICommunication sock, int TimeoutMillisec)` | Sets `command.Type` to `CommandType.Diagnostics` with custom timeout. |
**Note:** Concrete implementations (`QueryOffset`, `SetOffset`, `QueryMultiplier`, `SetMultiplier`) are commented out in the source.
---
### PowerCommands (Abstract)
**File:** `PowerCommands.cs`
**Namespace:** `DTS.DASLib.Command.SLICEDB`
Base class for power-related commands.
| Property | Signature | Description |
|----------|-----------|-------------|
| `_Command` | `protected abstract Commands _Command { get; }` | Abstract property defining the specific power command. |
| Constructor | Description |
|-------------|-------------|
| `PowerCommands(DTS.Common.Interface.DASFactory.ICommunication sock)` | Sets `command.Type` to `CommandType.Power` and initializes command via `SetCommand`. |
| `PowerCommands(DTS.Common.Interface.DASFactory.ICommunication sock, int TimeoutMillisec)` | Same as above with custom timeout. |
| Method | Signature | Description |
|--------|-----------|-------------|
| `CommandToString` | `public override void CommandToString(ref List<List<string>> lines)` | Appends `recorder.ConnectString` to output. |
| `ResponseToString` | `public override void ResponseToString(ref List<List<string>> lines)` | Appends `recorder.ConnectString` to output. |
#### Concrete Power Command Classes
| Class | `_Command` Value | Public Property | Description |
|-------|------------------|-----------------|-------------|
| `QueryV1VoltageMV` | `Commands.QueryV1VoltageMV` | `uint V1VoltageMV { get; }` | Queries +V1 input voltage in millivolts. |
| `QueryBatteryVoltageMV` | `Commands.QueryBatteryVoltageMV` | `uint BatteryVoltageMV { get; }` | Queries battery voltage in millivolts. Sets `MinimumProtocolVersion` via `GetMinProto(QueryBatteryVoltage)`. |
| `QueryBatteryChargeCurrentMA` | `Commands.QueryBatteryChargeCurrentMA` | `uint BatteryChargeCurrentMA { get; }` | Queries battery charge current in milliamps. |
| `QuerySliceBusInputCurrentMA` | `Commands.QuerySliceBusInputCurrentMA` | `uint SliceBusInputCurrentMA { get; }` | Queries SLICE bus current in milliamps. |
| `QuerySliceBusVoltageMV` | `Commands.QuerySliceBusVoltageMV` | `uint SliceBusVoltageMV { get; }` | Queries SLICE bus voltage in millivolts. |
| `SetSliceBusVoltageMV` | `Commands.SetSliceBusVoltageMV` | `uint SliceBusVoltageMV { get; set; }` | Sets SLICE bus voltage in millivolts. Setter allocates `sizeof(uint)` parameter buffer. |
Each concrete class provides two constructors matching the base class pattern and overrides `WholePackage()` to parse response data.
---
### ArmCommands (Abstract)
**File:** `ArmCommands.cs`
**Namespace:** `DTS.DASLib.Command.SLICEDB`
Base class for arming/disarming commands.
| Property | Signature | Description |
|----------|-----------|-------------|
| `_Command` | `protected abstract Commands _Command { get; }` | Abstract property defining the specific arm command. |
| Constructor | Description |
|-------------|-------------|
| `ArmCommands(DTS.Common.Interface.DASFactory.ICommunication sock)` | Sets `command.Type` to `CommandType.Arm` and initializes command via `SetCommand`. |
| `ArmCommands(DTS.Common.Interface.DASFactory.ICommunication sock, int TimeoutMillisec)` | Same as above with custom timeout. |
#### Concrete Arm Command Classes
| Class | `_Command` Value | Public Property | Protocol Limit |
|-------|------------------|-----------------|----------------|
| `Arm` | `Commands.arm_arm` | None | `ProtocolLimitedCommands.Arm` |
| `Disarm` | `Commands.arm_disarm` | None | `ProtocolLimitedCommands.Arm` |
| `EnableFaultChecking` | `Commands.arm_enablefaultchecking` | None | `ProtocolLimitedCommands.EnableFaultChecking` |
| `DisableFaultChecking` | `Commands.arm_disablefaultchecking` | None | `ProtocolLimitedCommands.EnableFaultChecking` |
| `SetRecordingMode` | `Commands.arm_setrecordingmode` | `byte Value { get; set; }` | `ProtocolLimitedCommands.Arm` |
| `SetPostTriggerSec` | `Commands.arm_setposttriggersec` | `float Value { get; set; }` | `ProtocolLimitedCommands.Arm` |
| `SetONOverride` | `Commands.arm_setonoverride` | `bool Value { get; set; }` | `ProtocolLimitedCommands.OnOverride` |
| `SetInvertTriggerPolarity` | `Commands.arm_setinverttriggerpolarity` | `bool Value { get; set; }` | `ProtocolLimitedCommands.Arm` |
| `SetInvertStartPolarity` | `Commands.arm_setinvertstartpolarity` | `bool Value { get; set; }` | `ProtocolLimitedCommands.Arm` |
All concrete classes provide two constructors matching the base class pattern.
---
### NetworkCommands (Abstract)
**File:** `NetworkCommands.cs`
**Namespace:** `DTS.DASLib.Command.SLICEDB`
Base class for network configuration commands.
| Property | Signature | Description |
|----------|-----------|-------------|
| `_Command` | `protected abstract Commands _Command { get; }` | Abstract property defining the specific network command. |
| Constructor | Description |
|-------------|-------------|
| `NetworkCommands(DTS.Common.Interface.DASFactory.ICommunication sock)` | Sets `command.Type` to `CommandType.Network` and initializes command via `SetCommand`. |
| `NetworkCommands(DTS.Common.Interface.DASFactory.ICommunication sock, int TimeoutMillisec)` | Same as above with custom timeout. |
#### Concrete Network Command Classes
| Class | `_Command` Value | Public Property | Direction |
|-------|------------------|-----------------|-----------|
| `QueryIPAddress` | `Commands.QueryIPAddress` | `string IPAddress { get; }` | Query |
| `SetIPAddress` | `Commands.SetIPAddress` | `string IPAddress { get; set; }` | Set |
| `QueryNetmask` | `Commands.QueryNetmask` | `string Netmask { get; }` | Query |
| `SetNetmask` | `Commands.SetNetmask` | `string Netmask { get; set; }` | Set |
| `QueryDefaultRoute` | `Commands.QueryDefaultRoute` | `string DefaultRoute { get; }` | Query |
| `SetDefaultRoute` | `Commands.SetDefaultRoute` | `string DefaultRoute { get; set; }` | Set |
| `QueryMACAddress` | `Commands.QueryMACAddress` | `string MACAddress { get; }` | Query |
| `SetMACAddress` | `Commands.SetMACAddress` | `string MACAddress { get; set; }` | Set |
**Setter behavior:** String setters allocate `value.Length + 1` bytes for null-terminated parameter.
---
### InformationCommands (Abstract)
**File:** `InformationCommands.cs`
**Namespace:** `DTS.DASLib.Command.SLICEDB`
Base class for device information commands.
| Property | Signature | Description |
|----------|-----------|-------------|
| `_Command` | `protected abstract Commands _Command { get; }` | Abstract property defining the specific information command. |
| Constructor | Description |
|-------------|-------------|
| `InformationCommands(DTS.Common.Interface.DASFactory.ICommunication sock)` | Sets `command.Type` to `CommandType.Information` and initializes command via `SetCommand`. |
| `InformationCommands(DTS.Common.Interface.DASFactory.ICommunication sock, int TimeoutMillisec)` | Same as above with custom timeout. |
#### Concrete Information Command Classes
| Class | `_Command` Value | Public Property | Description |
|-------|------------------|-----------------|-------------|
| `QuerySerialNumber` | `Commands.QuerySerialNumber` | `string SerialNumber { get; }` | Queries device serial number. |
| `SetSerialNumber` | `Commands.SetSerialNumber` | `string SerialNumber { get; set; }` | Sets device serial number. |
| `QueryFirmwareVersion` | `Commands.QueryFirmwareVersion` | `string FirmwareVersion { get; }` | Queries firmware version. |
| `QueryTime` | `Commands.QueryTime` | `DateTime CurrentTime { get; }` | Queries device time (epoch-based, returns `DateTime`). |
| `SetTime` | `Commands.SetTime` | `DateTime CurrentTime { get; set; }` | Sets device time (converts to epoch seconds + microseconds). |
| `QueryProtocolVersion` | `Commands.QueryProtocolVersion` | `byte ProtocolVersion { get; }` | Queries protocol version. |
| `QueryKernelVersion` | `Commands.QueryKernelVersion` | `string KernelFirmwareVersion { get; }` | Queries kernel firmware version. |
| `QueryMSPFirmwareVersion` | `Commands.QueryMSPFirmwareVersion` | `string MSPFirmwareVersion { get; }` | Queries MSP firmware version. |
| `QueryCalibrationDaysSince1970_01_01` | `Commands.QueryCalibrationDaysSince1970_01_01` | `string CalibrationDaysSince1970_01_01 { get; }` | Queries calibration date. |
| `SetCalibrationDaysSince1970_01_01` | `Commands.SetCalibrationDaysSince1970_01_01` | `string CalibrationDaysSince1970_01_01 { get; set; }` | Sets calibration date. |
---
## 3. Invariants
1. **Sequence Number Uniqueness:** `CommandPacket.GlobalSequenceNumber` is incremented atomically under `GlobalSequenceNumberLock` to ensure thread-safe unique sequence numbers across all command packets.
2. **Command Type Assignment:** All concrete command classes must set `command.Type` to the appropriate `CommandPacket.CommandType` value in their constructor (e.g., `PowerCommands` sets `CommandType.Power`).
3. **Abstract Command Property:** All concrete command classes inheriting from category base classes (`PowerCommands`, `ArmCommands`, `NetworkCommands`, `InformationCommands`) must override the abstract `_Command` property.
4. **Parameter Buffer Allocation:** Setters that modify command parameters must allocate the `command.Parameter` byte array before calling `command.SetParameter()`.
5. **Protocol Version Enforcement:** Certain commands (e.g., `QueryBatteryVoltageMV`, `Arm`, `Disarm`) set `MinimumProtocolVersion` via `sock.GetMinProto()` to ensure firmware compatibility.
6. **Time Representation:** `QueryTime` and `SetTime` use Unix epoch (1970-01-01) with seconds and microseconds components stored as `UInt32` values.
---
## 4. Dependencies
### This Module Depends On:
- `DTS.Common.ICommunication` - Communication interface types
- `DTS.Common.Enums.DASFactory` - `DFConstantsAndEnums.CommandStatus`, `DFConstantsAndEnums.ProtocolLimitedCommands`
- `DTS.Common.Interface.DASFactory` - `ICommunication` interface
- `SliceCommandBase` (inferred from inheritance) - Base class for `CommandBase`
- `SliceCommandPacketBase` (inferred from inheritance) - Base class for `CommandPacket`
- `CommandPacketBase` (inferred from return types) - Return type of `GetCommandPacket()`
### External Types Referenced:
- `CommandReceiveAction` - Enum used in `WholePackage()` return values
- `recorder` object with `ConnectString` and `SerialNumber` properties (inherited from base)
---
## 5. Gotchas
1. **Duplicate Enum Values in PowerCommands.Commands:** The `Commands` enum in `PowerCommands.cs` contains duplicate values:
- `QuerySliceBusInputCurrentOvercurrentLimitMA = 0x17` and `QueryBatteryChargeCurrentOvercurrentLimitMA = 0x17`
- `SetSliceBusInputCurrentOvercurrentLimitMA = 0x18` and `SetBatteryChargeCurrentOvercurrentLimitMA = 0x18`
- `QuerySliceBusInputCurrentOvercurrentCount = 0x19` and `QueryBatteryChargeCurrentOvercurrentCount = 0x19`
- `SetSliceBusInputCurrentOvercurrentCount = 0x1A` and `SetBatteryChargeCurrentOvercurrentCount = 0x1A`
This appears to be a bug or copy-paste error. No concrete implementations exist for these commands in the provided source.
2. **Commented-Out Implementation Classes:** `CalibrationCommands.cs` contains commented-out stub classes (`QueryOffset`, `SetOffset`, `QueryMultiplier`, `SetMultiplier`), suggesting incomplete implementation.
3. **Misleading XML Documentation:** Several XML comments are inaccurate:
- `SetRecordingMode.Value`: Comment says "The current Dat0 reg of the SLICE DB" but property is `byte` for recording mode.
- `SetPostTriggerSec.Value`: Same incorrect comment about "Dat0 reg".
- `SetONOverride.Value`: Comment says "The current StatusLED reg of the SLICE DB" but property is `bool`.
- `SetCalibrationDaysSince1970_01_01.CalibrationDaysSince1970_01_01`: Comment says "The serial number of the SLICE DB".
- `QueryProtocolVersion.ResponseToString`: Formats string as "Firmware Version" instead of "Protocol Version".
- `QueryKernelVersion.ResponseToString` and `QueryMSPFirmwareVersion.ResponseToString`: Both format as "Firmware Version" without distinguishing kernel vs MSP.
4. **Typo in Enum Value:** `SetBattteryVoltageOvervoltageLimitMV` has three 't's in "Batttery" (value `0x14`).
5. **Inconsistent Status Checking:** Some `WholePackage()` implementations check `response.Status != StatusNoError` and return early, while others check `response.Status == StatusNoError` before processing. The behavior differs slightly in whether the output property gets set to a default value.