15 KiB
15 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
2026-04-16T03:47:13.107401+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 054bcdedfc9b5182 |
SLICEDB Command Library Documentation
1. Purpose
This module provides a structured command framework for interacting with the SLICE DB (Data Acquisition System Electronics) hardware device over a communication interface. It defines an extensible hierarchy of command classes—each representing a specific operation (e.g., querying voltage, setting IP address, arming the system)—that encapsulate protocol-specific details such as command type, sequence numbering, parameter encoding/decoding, and response parsing. The library enables type-safe, consistent, and testable command construction and execution within the DAS (Data Acquisition System) ecosystem.
2. Public Interface
Core Base Classes
CommandBase
- Namespace:
DTS.DASLib.Command.SLICEDB - Inherits:
SliceCommandBase - Constructors:
CommandBase(ICommunication sock)
Initializes a new command instance using the provided communication socket.CommandBase(ICommunication sock, int TimeoutMillisec)
Initializes with a custom timeout (in milliseconds).
- Protected Overrides:
GetCommandPacket()→CommandPacketBase
Returns a new emptyCommandPacket.GetCommandPacket(byte[] buffer)→CommandPacketBase
Returns aCommandPacketinitialized from raw bytes.
CommandPacket
- Namespace:
DTS.DASLib.Command.SLICEDB - Inherits:
SliceCommandPacketBase - Nested Types:
CommandTypeenum:
Reserved = 0x00,Diagnostics,GPIO,Information,Network,Power,Arm
- Static Members:
GlobalSequenceNumber(UInt16): Thread-safe global sequence counter.GlobalSequenceNumberLock(object): Lock object for sequence number increment.
- Constructors:
CommandPacket()
Default constructor.CommandPacket(byte[] Bytes)
Constructor from raw byte buffer.
- Overrides:
GetNextSequenceNumber()
Atomically assigns the currentGlobalSequenceNumbertoSequenceNumber, then increments the global counter.ConvertByteToCommandType(byte b)→object
Casts the byte to aCommandTypeenum value.
Command Category Abstractions (Abstract Classes)
DiagnosticsCommands
- Namespace:
DTS.DASLib.Command.SLICEDB - Inherits:
CommandBase - Nested Enums:
Measurements:V1,BatteryVoltage,BatteryChargeCurrent,SliceBusCurrent,SliceBusVoltageCommands:Reserved,QueryOffset = 0x01,SetOffset = 0x02,QueryMultiplier = 0x03,SetMultiplier = 0x04
- Constructors:
DiagnosticsCommands(ICommunication sock)DiagnosticsCommands(ICommunication sock, int TimeoutMillisec)
Setscommand.Type = CommandType.Diagnostics.
- Note: Concrete command classes (
QueryOffset,SetOffset, etc.) are commented out in source.
PowerCommands
- Namespace:
DTS.DASLib.Command.SLICEDB - Inherits:
CommandBase - Nested Enum:
Commands: Includes query/set commands for voltages, currents, thresholds, delays, and overvoltage/overcurrent limits (e.g.,QueryV1VoltageMV = 0x01,SetSliceBusVoltageMV = 0x06,QueryBatteryChargeCurrentOvercurrentLimitMA = 0x17, etc.)
- Abstract Members:
_Command(Commands): Must be implemented by derived classes to specify the command.
- Constructors:
PowerCommands(ICommunication sock)PowerCommands(ICommunication sock, int TimeoutMillisec)
Setscommand.Type = CommandType.Power, and callscommand.SetCommand((byte)_Command, _Command.ToString()).
- Overrides:
CommandToString(ref List<List<string>> lines)
Appendsrecorder.ConnectStringto first line.ResponseToString(ref List<List<string>> lines)
Appendsrecorder.ConnectStringto first line.
Concrete Power Commands (Examples)
QueryV1VoltageMV_Command:Commands.QueryV1VoltageMVV1VoltageMV(uint): Input voltage (+V1 on P1) in millivolts.WholePackage(): Parses response parameter 0 into_val.
QueryBatteryVoltageMV_Command:Commands.QueryBatteryVoltageMVBatteryVoltageMV(uint): Battery voltage (+BAT on J1) in millivolts.- Sets
MinimumProtocolVersionviasock.GetMinProto(...).
QueryBatteryChargeCurrentMA_Command:Commands.QueryBatteryChargeCurrentMABatteryChargeCurrentMA(uint): Battery charge current in milliamps.
QuerySliceBusInputCurrentMA_Command:Commands.QuerySliceBusInputCurrentMASliceBusInputCurrentMA(uint): Slice bus current in milliamps.
QuerySliceBusVoltageMV_Command:Commands.QuerySliceBusVoltageMVSliceBusVoltageMV(uint): Slice bus voltage in millivolts.
SetSliceBusVoltageMV_Command:Commands.SetSliceBusVoltageMVSliceBusVoltageMV(uint, get/set): Setscommand.Parameterto 4-byte value.
ArmCommands
- Namespace:
DTS.DASLib.Command.SLICEDB - Inherits:
CommandBase - Nested Enum:
Commands:arm_reserved,arm_arm = 0x01,arm_disarm = 0x02,arm_enablefaultchecking = 0x03,arm_disablefaultchecking = 0x04,arm_setinverttriggerpolarity = 0x05,arm_setinvertstartpolarity = 0x06,arm_setrecordingmode = 0x07,arm_setpretriggersec = 0x08,arm_setposttriggersec = 0x09,arm_setmaxevent = 0x0A,arm_setonoverride = 0x0B
- Abstract Members:
_Command(Commands): Must be implemented.
- Constructors:
ArmCommands(ICommunication sock)ArmCommands(ICommunication sock, int TimeoutMillisec)
Setscommand.Type = CommandType.Arm, and callscommand.SetCommand(...).
- Overrides:
CommandToString(ref List<List<string>> list)
Appendsrecorder.SerialNumberto first line.
Concrete Arm Commands (Examples)
Arm_Command:Commands.arm_arm- Sets
MinimumProtocolVersionviasock.GetMinProto(ProtocolLimitedCommands.Arm).
Disarm_Command:Commands.arm_disarm- Sets
MinimumProtocolVersionviasock.GetMinProto(ProtocolLimitedCommands.Arm).
EnableFaultChecking_Command:Commands.arm_enablefaultchecking- Sets
MinimumProtocolVersionviasock.GetMinProto(ProtocolLimitedCommands.EnableFaultChecking).
DisableFaultChecking_Command:Commands.arm_disablefaultchecking- Sets
MinimumProtocolVersionviasock.GetMinProto(ProtocolLimitedCommands.EnableFaultChecking).
SetRecordingMode_Command:Commands.arm_setrecordingmodeValue(byte, get/set): Setscommand.Parameterto 1-byte value.
SetPostTriggerSec_Command:Commands.arm_setposttriggersecValue(float, get/set): Setscommand.Parameterto 4-byte float.
SetONOverride_Command:Commands.arm_setonoverrideValue(bool, get/set): Converts to/from byte forcommand.Parameter.
SetInvertTriggerPolarity,SetInvertStartPolarity- Similar to
SetONOverride, withbool Valueproperty.
- Similar to
NetworkCommands
- Namespace:
DTS.DASLib.Command.SLICEDB - Inherits:
CommandBase - Nested Enum:
Commands:Reserved,QueryIPAddress = 0x01,SetIPAddress = 0x02,QueryNetmask = 0x03,SetNetmask = 0x04,QueryDefaultRoute = 0x05,SetDefaultRoute = 0x06,QueryMACAddress = 0x07,SetMACAddress = 0x08
- Abstract Members:
_Command(Commands): Must be implemented.
- Constructors:
NetworkCommands(ICommunication sock)NetworkCommands(ICommunication sock, int TimeoutMillisec)
Setscommand.Type = CommandType.Network, and callscommand.SetCommand(...).
- Overrides:
CommandToString(ref List<List<string>> list)
Appendsrecorder.ConnectStringto first line.ResponseToString(ref List<List<string>> lines)
Appendsrecorder.ConnectStringto first line.
Concrete Network Commands (Examples)
QueryIPAddress,SetIPAddressIPAddress(string): Read-only for query, read/write for set. Set allocatescommand.Parameterasnew byte[value.Length + 1].
QueryNetmask,SetNetmaskNetmask(string): Same pattern as IP.
QueryDefaultRoute,SetDefaultRouteDefaultRoute(string): Same pattern.
QueryMACAddress,SetMACAddressMACAddress(string): Same pattern.
InformationCommands
- Namespace:
DTS.DASLib.Command.SLICEDB - Inherits:
CommandBase - Nested Enum:
Commands:Reserved,QuerySerialNumber = 0x01,SetSerialNumber = 0x02,QueryFirmwareVersion = 0x03,QueryTime = 0x04,SetTime = 0x05,QueryDebugLevel = 0x06,SetDebugLevel = 0x07,QueryKernelVersion = 0x08,QueryMSPFirmwareVersion = 0x09,QueryProtocolVersion = 0x0A,QueryCalibrationDaysSince1970_01_01 = 0x0F,SetCalibrationDaysSince1970_01_01 = 0x10
- Abstract Members:
_Command(Commands): Must be implemented.
- Constructors:
InformationCommands(ICommunication sock)InformationCommands(ICommunication sock, int TimeoutMillisec)
Setscommand.Type = CommandType.Information, and callscommand.SetCommand(...).
- Overrides:
CommandToString(ref List<List<string>> list)
Appendsrecorder.SerialNumberto first line.
Concrete Information Commands (Examples)
QuerySerialNumber,SetSerialNumberSerialNumber(string): Read-only for query, read/write for set. Set allocatescommand.Parameterasnew byte[value.Length + 1].
QueryFirmwareVersion,QueryKernelVersion,QueryMSPFirmwareVersionFirmwareVersion,KernelFirmwareVersion,MSPFirmwareVersion(string): Read-only, parsed from response parameter 0.
QueryTime,SetTimeCurrentTime(DateTime): Query parses seconds/microseconds from parameters 0/4 into aDateTime(epoch-based). Set convertsDateTimeto seconds/microseconds and writes tocommand.Parameter.
QueryProtocolVersionProtocolVersion(byte): Read-only, parsed from parameter 0.
QueryCalibrationDaysSince1970_01_01,SetCalibrationDaysSince1970_01_01CalibrationDaysSince1970_01_01(string): Read-only for query, read/write for set. Set allocatescommand.Parameterasnew byte[value.Length + 1].
3. Invariants
- Sequence Numbering: Sequence numbers are globally unique and monotonically increasing across all command instances due to the
lockaroundGlobalSequenceNumberinGetNextSequenceNumber(). - Command Type Assignment: All concrete command classes must set
command.Typeto the appropriateCommandPacket.CommandType(e.g.,Power,Arm,Network) in their base constructor. - Command Code Assignment: All concrete command classes must call
command.SetCommand((byte)_Command, _Command.ToString())in their base constructor. - Parameter Encoding for Strings: For commands accepting string parameters (e.g.,
SetIPAddress,SetSerialNumber), the parameter buffer is allocated asnew byte[value.Length + 1]to accommodate a null terminator. - Parameter Encoding for Numeric Types:
uintparameters usesizeof(uint)(4 bytes).floatparameters usesizeof(float)(4 bytes).byte/boolparameters usesizeof(byte)(1 byte).
- Protocol Version Handling: Commands that require minimum protocol versions (e.g.,
QueryBatteryVoltageMV,Arm) setMinimumProtocolVersionviasock.GetMinProto(...)in their constructors. - Response Parsing: All
WholePackage()overrides parse response parameters only whenresponse.Status == CommandStatus.StatusNoError; otherwise, they initialize output fields to default values (e.g.,0,string.Empty,DateTime(1970,1,1)). - Thread Safety: Sequence number generation is thread-safe via
lock (GlobalSequenceNumberLock).
4. Dependencies
External Dependencies (from imports):
System.*: Core .NET libraries (System,System.Collections.Generic,System.Text,System.Threading,System.Reflection,System.IO,System.Diagnostics).DTS.Common.ICommunication: ProvidesICommunicationinterface.DTS.Common.Interface.DASFactory: ProvidesICommunication(redundant import) andDASFactorytypes.DTS.Common.Enums.DASFactory: ProvidesDFConstantsAndEnums.CommandStatusandDFConstantsAndEnums.ProtocolLimitedCommands.
Internal Dependencies:
- Inherits from
SliceCommandBaseandSliceCommandPacketBase(not shown in source, but referenced). - Uses
recorderobject (inferred fromrecorder.ConnectString,recorder.SerialNumber), likely a property of the base class. - Uses
responseandcommandobjects (inferred from base class and usage), likely properties ofSliceCommandBase.
Inferred Usage:
- This module is used by higher-level components that construct and execute commands via
ICommunication. - The
CommandBasehierarchy is the primary public interface for command execution.
5. Gotchas
- Duplicate Class Name:
SetCalibrationDaysSince1970_01_01andQueryCalibrationDaysSince1970_01_01are defined twice inInformationCommands.cs(lines 1 and 2), both with identical names and implementations. This will cause compilation errors unless one is commented out or renamed. - Incorrect ResponseToString in QueryProtocolVersion: Outputs
"Firmware Version: {ProtocolVersion}"instead of"Protocol Version: {ProtocolVersion}". - Incorrect ResponseToString in QueryKernelVersion & QueryMSPFirmwareVersion: Both output
"Firmware Version: {Version}"instead of distinguishing"Kernel Firmware Version"or"MSP Firmware Version". - String Parameter Allocation: All string-setting commands allocate
new byte[value.Length + 1], but there is no validation thatvalueis non-null or within expected length limits. Passingnullwill throw aNullReferenceException. - Float Parameter Precision:
SetPostTriggerSecconvertsfloattocommand.Parameterwithout rounding or validation; floating-point precision errors may occur. - Epoch Assumption:
QueryTimeandSetTimeassume Unix epoch (1970-01-01 00:00:00 UTC) and do not account for time zones or leap seconds. - Missing Concrete Commands:
DiagnosticsCommandsdefinesQueryOffset,SetOffset, etc., but their implementations are commented out—no concrete classes exist for these. - Protocol Version Mismatch:
DisableFaultCheckingusesProtocolLimitedCommands.EnableFaultCheckingforMinimumProtocolVersion, likely a copy-paste error. - Redundant
ICommunicationImport:InformationCommands.csimports bothDTS.Common.ICommunicationandDTS.Common.Interface.DASFactory, and usesICommunicationdirectly inSetCalibrationDaysSince1970_01_01constructor—suggests inconsistent usage or legacy code. - No Error Handling in
WholePackage(): SomeWholePackage()methods (e.g.,QueryBatteryChargeCurrentMA) checkStatusNoErroronly for success path, but others (e.g.,QueryV1VoltageMV) do not—leading to inconsistent behavior on error.