using SSPCTester.Devices.Interfaces; namespace SSPCTester.Devices.Config; /// /// 根设备配置节点。对应 appsettings.json 中的 "Devices" 段。 /// public sealed class DeviceOptions { public const string SectionName = "Devices"; /// 旧版全局开关,仅用于兼容读取旧配置。 public bool MockMode { get; set; } public SspcOptions Sspc { get; set; } = new(); public PowerSupplyOptions PowerSupply { get; set; } = new(); public LoadOptions Load { get; set; } = new(); public DaqOptions Daq { get; set; } = new(); public Pci2312Options Pci2312 { get; set; } = new(); } /// /// SSPC(24 路 = 3 模块 × 8 路)的串口与 Modbus 配置。 /// public sealed class SspcOptions { public bool UseMock { get; set; } public bool AutoConnect { get; set; } = true; public string PortName { get; set; } = "COM1"; public int BaudRate { get; set; } = 9600; public int DataBits { get; set; } = 8; public string Parity { get; set; } = "None"; public string StopBits { get; set; } = "One"; public int ReadTimeoutMs { get; set; } = 500; public int Retry { get; set; } = 2; public string DeviceProfilePath { get; set; } = "Config/device-profile.json"; public bool CloseAllRelaysOnDisconnect { get; set; } public bool LogRawFrames { get; set; } = true; // 旧字段保留用于兼容历史 appsettings,业务通道数固定为 24。 public byte[] ModuleAddresses { get; set; } = new byte[] { 1, 2, 3 }; public int ChannelsPerModule { get; set; } = 8; } public sealed class PowerSupplyOptions { public bool UseMock { get; set; } public bool AutoConnect { get; set; } = true; public string PortName { get; set; } = "COM2"; public int BaudRate { get; set; } = 9600; public string Host { get; set; } = "192.168.6.5"; public int Port { get; set; } = 5025; public double TimeoutSeconds { get; set; } = 2; public bool RequirePingBeforeConnect { get; set; } = true; public string Terminator { get; set; } = "\n"; public string IdnCommand { get; set; } = "*IDN?"; public string VoltageCommand { get; set; } = "MEASure:VOLTage?"; public string CurrentCommand { get; set; } = "MEASure:CURRent?"; } public enum LoadQueryMode { Combined, Separate } public sealed class LoadOptions { public bool UseMock { get; set; } public bool AutoConnect { get; set; } = true; public string PortName { get; set; } = "COM3"; public int BaudRate { get; set; } = 9600; public string Host { get; set; } = "192.168.200.100"; public int Port { get; set; } = 30000; public double TimeoutSeconds { get; set; } = 3; public string Terminator { get; set; } = "\n"; public int Channel { get; set; } = 1; public bool UseFetch { get; set; } = true; public LoadQueryMode QueryMode { get; set; } = LoadQueryMode.Combined; } public sealed class DaqOptions { public bool UseMock { get; set; } public bool AutoConnect { get; set; } = true; public int LogicalDeviceId { get; set; } public int ChannelCount { get; set; } = 1; public string InputRange { get; set; } = "PlusMinus5V"; public int ClockDivider { get; set; } = 1_000; public double PreTriggerMs { get; set; } = 3; public double PostTriggerMs { get; set; } = 100; public List Channels { get; set; } = Enumerable.Range(0, 8).Select(i => new DaqChannelOptions { PhysicalChannel = i, Role = i == 0 ? nameof(DaqChannelRole.OutputVoltage) : nameof(DaqChannelRole.Unconfigured), Name = i == 0 ? "输出电压" : $"CH{i}", IsCalibrated = i == 0 }).ToList(); [System.Text.Json.Serialization.JsonIgnore] public int DeviceIndex { get => LogicalDeviceId; set => LogicalDeviceId = value; } [System.Text.Json.Serialization.JsonIgnore] public int SampleRateHz { get => (int)Math.Round(ActualSampleRateHz); set => ClockDivider = value > 0 ? Math.Max(1, (int)Math.Round(100_000_000.0 / value)) : 1_000; } [System.Text.Json.Serialization.JsonIgnore] public double DurationSec => (PreTriggerMs + PostTriggerMs) / 1_000.0; [System.Text.Json.Serialization.JsonIgnore] public double ActualSampleRateHz => 100_000_000.0 / Math.Max(1, ClockDivider); } public sealed class DaqChannelOptions { public int PhysicalChannel { get; set; } public string Role { get; set; } = "Unconfigured"; public string Name { get; set; } = ""; public double Scale { get; set; } = 1; public double Offset { get; set; } public bool IsCalibrated { get; set; } } public sealed class Pci2312Options { public bool Enabled { get; set; } = true; public bool UseMock { get; set; } public bool AutoConnect { get; set; } = true; public int DeviceId { get; set; } public int EmergencyInputChannel { get; set; } public bool EmergencyInputActiveHigh { get; set; } = true; public int AlarmOutputChannel { get; set; } public bool AlarmOutputActiveHigh { get; set; } = true; public int PollIntervalMs { get; set; } = 100; }