周立功换同星

This commit is contained in:
“hsc”
2026-07-29 14:20:32 +08:00
parent d8a22a15b1
commit 3bf33bb561
29 changed files with 1913 additions and 3255 deletions

View File

@@ -4,8 +4,8 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TSMasterCAN;
using UIShare.PubEvent;
using ZLGUSBCANFD;
namespace UIShare.GlobalVariable
{
@@ -22,8 +22,7 @@ namespace UIShare.GlobalVariable
private bool _disposed;
/// <summary>已订阅解码事件的 CANFD 实例 → 委托 映射</summary>
private readonly Dictionary<ZLGCANFD, Action<uint, ZDBC.DBCMessage>> _handlers = new();
private readonly Dictionary<CAN, Action<uint, DBCMessage>> _handlers = new();
public CANSignalBroadcaster(GlobalInfo globalInfo, IEventAggregator eventAggregator)
{
_globalInfo = globalInfo;
@@ -48,7 +47,7 @@ namespace UIShare.GlobalVariable
if (_handlers.ContainsKey(canfd)) continue;
// 使用闭包捕获指纹,回调时即可区分不同 CAN 卡
Action<uint, ZDBC.DBCMessage> handler = (channel, msg) => OnDbcMessageDecoded(fingerprint, channel, msg);
Action<uint, DBCMessage> handler = (channel, msg) => OnDbcMessageDecoded(fingerprint, channel, msg);
canfd.OnDbcMessageDecoded += handler;
_handlers[canfd] = handler;
}
@@ -65,7 +64,7 @@ namespace UIShare.GlobalVariable
/// <summary>
/// DBC 解码回调:提取所有信号,向引用该 CAN 设备的作用域广播,并检查报警。
/// </summary>
private void OnDbcMessageDecoded(string canFingerprint, uint channel, ZDBC.DBCMessage msg)
private void OnDbcMessageDecoded(string canFingerprint, uint channel, DBCMessage msg)
{
if (_disposed) return;

View File

@@ -10,9 +10,10 @@ using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Reflection;
using TSMasterCAN;
using UIShare.PubEvent;
using UIShare.UIViewModel;
using ZLGUSBCANFD;
using TSMasterCAN;
namespace UIShare.GlobalVariable
{
@@ -34,7 +35,7 @@ namespace UIShare.GlobalVariable
/// <summary>类名 → Type 的反射缓存(仅扫描一次)。</summary>
private static readonly IReadOnlyDictionary<string, Type> _deviceTypeMap = BuildDeviceTypeMap();
public ZLGCANFD CANFD { get; set; }
public CAN CANFD { get; set; }
public IOBoardGroup IOGroup { get; set; }
public DeviceManager(SystemConfig systemConfig, GlobalInfo globalInfo, IEventAggregator eventAggregator)
@@ -116,10 +117,10 @@ namespace UIShare.GlobalVariable
try
{
// 按指纹全局唯一创建 ZLGCANFD 实例maxChannels 默认 4对应 USBCANFD-400U
// 按指纹全局唯一创建同星 CAN 实例maxChannels 默认 4对应 USBCANFD-400U
// 波特率与终端电阻从 CANConfigVM 传入,初始化并启动通道 时直接使用
var canLazy = _globalInfo.CanPool.GetOrAdd(fingerprint, key => new Lazy<ZLGCANFD>(() =>
new ZLGCANFD(config.CANConfig.DeviceType, config.CANConfig.DeviceIndex, 4,
var canLazy = _globalInfo.CanPool.GetOrAdd(fingerprint, key => new Lazy<CAN>(() =>
new CAN(config.CANConfig.DeviceType, config.CANConfig.DeviceIndex, 4,
config.CANConfig.ABitBaud, config.CANConfig.DBitBaud, config.CANConfig.EnableTerminalResistance)));
_systemConfig.CANFD = canLazy.Value;

View File

@@ -5,7 +5,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZLGUSBCANFD;
using TSMasterCAN;
namespace UIShare.GlobalVariable
{
@@ -21,7 +21,7 @@ namespace UIShare.GlobalVariable
public ConcurrentDictionary<string, Lazy<IBaseInterface>> HardwarePool { get; set; }
/// <summary>CAN 硬件指纹 → ZLGCANFD 实例的并发池,确保同一 CAN 卡全局只创建一个驱动实例。</summary>
public ConcurrentDictionary<string, Lazy<ZLGCANFD>> CanPool { get; set; }
public ConcurrentDictionary<string, Lazy<CAN>> CanPool { get; set; }
/// <summary>硬件指纹 → 正在使用该设备的作用域名称列表,用于引用计数与安全销毁。</summary>
public ConcurrentDictionary<string, Lazy<List<string>>> DeviceAndScopeDic { get; set; }
@@ -49,7 +49,7 @@ namespace UIShare.GlobalVariable
ConfigDic = new();
ScopeDic = new();
HardwarePool = new ConcurrentDictionary<string, Lazy<IBaseInterface>>(StringComparer.OrdinalIgnoreCase);
CanPool = new ConcurrentDictionary<string, Lazy<ZLGCANFD>>(StringComparer.OrdinalIgnoreCase);
CanPool = new ConcurrentDictionary<string, Lazy<CAN>>(StringComparer.OrdinalIgnoreCase);
DeviceAndScopeDic = new ConcurrentDictionary<string, Lazy<List<string>>>(StringComparer.OrdinalIgnoreCase);
CurrentScope = "default";
}

View File

@@ -8,8 +8,8 @@ using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using TSMasterCAN;
using UIShare.UIViewModel;
using ZLGUSBCANFD;
using static UIShare.UIViewModel.ParameterVM;
namespace UIShare.GlobalVariable
@@ -40,7 +40,7 @@ namespace UIShare.GlobalVariable
/// 监测通道持久化配置列表(包含 Fingerprint、MethodName、IsDisplayed
/// </summary>
public ObservableCollection<MonitorChannelConfig> MonitorChannels = new();
public ZLGCANFD CANFD = new();
public CAN CANFD = new();
[JsonIgnore]
public ObservableCollection<ParameterVM> ParameterList = new()
{