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

319 lines
12 KiB
Markdown
Raw Permalink Normal View History

2026-04-17 14:55:32 -04:00
---
source_files:
- DataPRO/SLICECommands/StackSetupCommands.cs
- DataPRO/SLICECommands/CommandBase.cs
- DataPRO/SLICECommands/CommandPacket.cs
- DataPRO/SLICECommands/StackUtilityCommands.cs
- DataPRO/SLICECommands/FirmwareUpdateCommands.cs
- DataPRO/SLICECommands/Ptp1588Commands.cs
generated_at: "2026-04-17T15:48:00.912898+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "ae149525b5d620e6"
---
# SLICE Commands Module Documentation
## 1. Purpose
This module provides a command hierarchy for communicating with SLICE hardware devices in the DataPRO system. It implements a command pattern where each operation (firmware updates, PTP1588 clock synchronization, stack utilities, etc.) is encapsulated as a discrete command object that manages its own serialization, transmission, and response handling. The module serves as the protocol layer between the application and SLICE hardware, handling command packet construction, sequence number management, and response parsing.
---
## 2. Public Interface
### CommandPacket (DTS.DASLib.Command.SLICE)
**Constructors:**
- `CommandPacket()` - Creates an empty command packet
- `CommandPacket(byte[] Bytes)` - Creates a command packet from raw bytes
**Public Methods:**
- `override void GetNextSequenceNumber()` - Thread-safely assigns the next global sequence number to this packet
- `override object ConvertByteToCommandType(byte b)` - Converts a byte to a `CommandType` enum value
**Public Types:**
```csharp
public enum CommandType
{
Reserved = 0,
Arm = 1,
Attribute = 2,
Diagnostics = 3,
EventData = 4,
FirmwareUpdate = 5,
Information = 6,
QAandUtility = 7,
Realtime = 8,
Bulk = 9,
StackFirmwareUpdate = 10,
Ptp1588 = 11,
Multicast = 12,
}
```
---
### CommandBase (DTS.DASLib.Command.SLICE)
Abstract base class for all SLICE commands.
**Constructors:**
- `CommandBase(DTS.Common.Interface.DASFactory.ICommunication sock)`
- `CommandBase(DTS.Common.Interface.DASFactory.ICommunication sock, int TimeoutMillisec)`
**Protected Methods:**
- `override CommandPacketBase GetCommandPacket()`
- `override CommandPacketBase GetCommandPacket(byte[] buffer)`
---
### BusPowerControl (DTS.DASLib.Command.SLICE)
Controls bus power to SLICE devices.
**Constructors:**
- `BusPowerControl(ICommunication sock)`
- `BusPowerControl(ICommunication sock, int TimeoutMillisec)`
**Properties:**
- `bool PowerOn` - Gets or sets the bus power state; setter encodes parameter as byte 0 or 1
**Methods:**
- `override string CommandToString()` - Returns command description
- `override string ResponseToString()` - Returns response description
---
### ForceEnumeration (DTS.DASLib.Command.SLICE)
Forces device enumeration on the stack.
**Constructors:**
- `ForceEnumeration(ICommunication sock)`
- `ForceEnumeration(ICommunication sock, int TimeoutMillisec)`
**Properties:**
- `int SLICECount` - Gets the count of enumerated SLICE devices from response
**Protected Methods:**
- `override CommandReceiveAction WholePackage()` - Parses response to extract SLICE count
---
### Firmware Update Commands
#### QueryFirmwareUpdateBlockSize
**Properties:** `ushort BlockSize` - Block size from response
#### QueryBootloaderVersion
**Properties:** `string Version` - Bootloader version string from response
#### SwitchToFirmwareUpdateMode
No additional properties; signals device to enter firmware update mode.
#### BeginFirmwareUpdate
No additional properties; initiates firmware update process.
#### ProgramFirmwareUpdateBlock
**Properties:**
- `uint BlockBaseAddress` - Block address (parameter offset 0)
- `ushort BlockSize` - Data block size (parameter offset 4)
- `ushort BlockCRC16` - CRC16 of block (parameter offset 6)
- `bool Upper` - Upper/lower flag (parameter offset 8)
- `byte[] Data` - Firmware data bytes (starting at parameter offset 10)
#### FinishFirmwareUpdate
**Properties:**
- `ushort ImageCRC16` - CRC16 of entire firmware image (parameter offset 0)
#### Reboot
No additional properties; reboots the device.
#### QueryInFirmwareUpdateMode
**Properties:**
- `bool InUpdateMode` - True if not in FW mode
- `bool IsFwMode` - True if in firmware mode
- `bool IsBlMode` - True if in bootloader mode
- `bool IsBllMode` - True if in secondary bootloader mode
- `FirmwareMode Mode` - Current firmware mode enum value
#### Load_SliceProStackFirmwareImage
**Properties:**
- `uint StartByteCount` - Byte offset for this block (parameter offset 2)
- `byte[] Data` - Firmware data (max `MAX_FILE_LENGTH` = 400 bytes)
- `int Size` - Data size
- `int MaximumFileStreamBytes` - Returns 400
**Methods:**
- `void LogResponse()` - Logs command response
#### Start_SliceProStackFirmwareUpdate
No additional properties; starts stack firmware update process.
#### Set_SliceProStackFirmwareUpdateMode
**Properties:**
- `int SliceModuleCount` - Number of slice modules
- `byte[] SliceModuledateMode` - Update mode per module
#### Get_SliceProStackFirmwareUpdateMode
**Properties:**
- `int SliceModuleCount` - Count from response
- `byte[] SliceModuledateMode` - Mode per module from response
---
### PTP1588 Commands
#### Ptp1588SetMode
**Methods:**
- `void SetClockType(PtpClockType clockType)` - Sets clock type (parameter offset 0)
- `void SetDelayMechanism(PtpDelayMechanism delayMechanism)` - Sets delay mechanism (parameter offset 2)
#### Ptp1588GetMode
**Properties:**
- `PtpClockType ClockType` - Clock type from response
- `PtpDelayMechanism DelayMechanism` - Delay mechanism from response
#### Ptp1588GetSyncStatus
**Properties:**
- `PtpSyncStatus SyncStatus` - Synchronization status
- `int OFM` - Offset from master (nanoseconds)
- `int FreqAdj` - Frequency adjustment
#### Ptp1588SetTime / Ptp1588SetAutoTriggerTime
**Methods:**
- `void SetSeconds(uint seconds)` - Sets seconds component (parameter offset 0)
- `void SetNanoseconds(uint ns)` - Sets nanoseconds component (parameter offset 4)
#### Ptp1588GetTime / Ptp1588GetAutoTriggerTime
**Properties:**
- `uint Seconds` - Seconds from response
- `uint Nanoseconds` - Nanoseconds from response
- `string Timestamp` - Formatted timestamp string
#### Ptp1588GetTimestamp
**Properties:**
- `PtpTimestampUnits TimestampUnit` - Sets timestamp unit to query (parameter offset 0)
- `uint Seconds`, `uint Nanoseconds`, `bool IsValid`, `string Timestamp` - From response
#### Ptp1588SetEnableTimestamping
**Methods:**
- `void SetEnable(bool enable)` - Enables/disables timestamping
#### Ptp1588SetAdcClockFrequency
**Properties:**
- `uint RequestedFrequency` - Sets requested frequency (parameter offset 0)
- Actual frequency returned in response (accessible via `WholePackage()`)
#### Ptp1588RunClockAdjustmentCalibration
**Methods:**
- `void SetDuration(ushort duration)` - Calibration duration in seconds (parameter offset 0)
- `void SetSaveAttribute(bool b)` - Whether to save calibration (parameter offset 2)
#### QueryClockSyncStatus
**Properties:**
- `byte InputState`, `byte OutputState`, `byte SyncStatus`
- `ClockSyncProfile ClockSyncProfile`
- `List<InputClockSource> InputSources`
- `List<OutputClockSource> OutputSources`
- `IDictionary<InputClockSource, bool> InputSyncStatus`
#### SetClockSyncConfig
Configuration setter; response indicates success/failure.
---
### Static Utility
**Ptp1588Commands.ToTimestampString(uint s, uint ns)**
Returns formatted timestamp string: `"{seconds}.{nanoseconds:000000000}"`
---
## 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 constructors.
3. **Parameter Array Initialization**: Commands must initialize `command.Parameter` to an appropriately sized byte array before setting parameters.
4. **Protocol Version Requirements**: Commands using `MinimumProtocolVersion` (e.g., `Load_SliceProStackFirmwareImage`, `QueryClockSyncStatus`, `SetClockSyncConfig`) must retrieve the minimum protocol version via `sock.GetMinProto()`.
5. **Firmware Data Size Limit**: `Load_SliceProStackFirmwareImage.Data` must not exceed `MAX_FILE_LENGTH` (400 bytes); throws `NotImplementedException` if exceeded.
6. **Response Parsing Guard**: All `WholePackage()` overrides check `response.Status == CommandStatus.StatusNoError` before parsing response parameters.
---
## 4. Dependencies
### This module depends on:
- `DTS.DASLib.Communication` - `ICommunication` interface
- `DTS.DASLib.Utility` - Utility functions
- `DTS.Common.ICommunication` - Communication interfaces
- `DTS.Common.Utilities.Logging` - Logging infrastructure
- `DTS.Common.Enums.DASFactory` - `DFConstantsAndEnums`, `ProtocolLimitedCommands`
- `DTS.Common` - `ClockSyncProfile`, `InputClockSource`, `OutputClockSource` types
- Base classes `SliceCommandBase` and `SliceCommandPacketBase` (location not shown in source)
### Inheritance Hierarchy:
```
SliceCommandPacketBase
└── CommandPacket
SliceCommandBase
└── CommandBase
├── Commands_Stack_Setup
├── Commands_Stack_Utility
│ ├── BusPowerControl
│ └── ForceEnumeration
├── FirmwareUpdateCommands
│ ├── QueryFirmwareUpdateBlockSize
│ ├── QueryBootloaderVersion
│ ├── SwitchToFirmwareUpdateMode
│ ├── BeginFirmwareUpdate
│ ├── ProgramFirmwareUpdateBlock
│ ├── FinishFirmwareUpdate
│ ├── Reboot
│ ├── QueryInFirmwareUpdateMode
│ ├── Load_SliceProStackFirmwareImage
│ ├── Start_SliceProStackFirmwareUpdate
│ ├── Set_SliceProStackFirmwareUpdateMode
│ └── Get_SliceProStackFirmwareUpdateMode
└── Ptp1588Commands
├── Ptp1588SetMode
├── Ptp1588GetMode
├── Ptp1588GetSyncStatus
├── Ptp1588SetTime
├── Ptp1588GetTime
├── Ptp1588SetAutoTriggerTime
├── Ptp1588GetAutoTriggerTime
├── Ptp1588GetTimestamp
├── Ptp1588SetEnableTimestamping
├── Ptp1588SetAdcClockFrequency
├── Ptp1588RunClockAdjustmentCalibration
├── QueryClockSyncStatus
└── SetClockSyncConfig
```
---
## 5. Gotchas
1. **Empty Commands Enum**: `Commands_Stack_Setup` defines a `Commands` enum with no members. This appears to be incomplete—no concrete implementations derive from this class in the provided source.
2. **Typo in Property Name**: `Set_SliceProStackFirmwareUpdateMode.SliceModuledateMode` and `Get_SliceProStackFirmwareUpdateMode.SliceModuledateMode` appear to have a typo ("date" instead of "Update").
3. **Typo in Command Enum**: `Ptp1588Commands.Commands.SetAdcClockFrquency` is misspelled (missing 'e' in "Frequency").
4. **Inconsistent ICommunication Types**: Some classes use `DTS.DASLib.Communication.ICommunication` while others use `DTS.Common.Interface.DASFactory.ICommunication`. The relationship between these interfaces is unclear from the source.
5. **Logging Disabled for Firmware Load**: `Load_SliceProStackFirmwareImage` sets `command.ShouldLog = false` in its constructor, meaning these commands won't be logged by default—likely due to high volume during firmware uploads.
6. **Hardcoded File ID**: `Load_SliceProStackFirmwareImage` hardcodes `_fileID = 20` with no way to change it via public interface.
7. **NotImplementedException for Oversized Data**: `Load_SliceProStackFirmwareImage.Data` throws `NotImplementedException` rather than `ArgumentException` when data exceeds 400 bytes—an unusual exception choice for a validation error.
8. **Protocol Version Required but Not Enforced**: Commands like `Load_SliceProStackFirmwareImage` set `MinimumProtocolVersion` but the source does not show how this is enforced or validated before command execution.