现场优化2

This commit is contained in:
2026-08-13 13:35:43 +08:00
parent 30f5f6f8d6
commit e392527592
4 changed files with 203 additions and 161 deletions
+28
View File
@@ -347,6 +347,7 @@ namespace CANModule.ViewModels
DeleteDcAutoLoadCommand = new DelegateCommand(DeleteDcAutoLoad);
SendCustomMessageCommand = new DelegateCommand(SendCustomMessage);
_canfd.OnDbcMessageDecoded += OnDbcMessageDecoded;
_canfd.OnRawMessageReceived += OnRawMessageReceived;
LoadCommand = new DelegateCommand(Load);
}
@@ -368,6 +369,7 @@ namespace CANModule.ViewModels
if (_canfd != null)
{
_canfd.OnDbcMessageDecoded -= OnDbcMessageDecoded;
_canfd.OnRawMessageReceived -= OnRawMessageReceived;
}
_refreshCts?.Cancel();
}
@@ -627,6 +629,32 @@ namespace CANModule.ViewModels
});
}
private void OnRawMessageReceived(uint channel, uint canId, byte[] data, ulong timestamp, bool isFD, byte dlcLength)
{
// 原始报文回调:不依赖 DBC,自定义报文也能收到
Application.Current.Dispatcher.BeginInvoke(() =>
{
// 提取实际 CAN ID(去掉扩展帧标志位)
int actualId = (int)(canId & 0x1FFFFFFF);
var find = CanMessageList.FirstOrDefault(s => s.ID == actualId && s. == channel);
if (find != null)
{
find. = (ulong)DateTimeOffset.Now.ToUnixTimeMilliseconds();
find. = dlcLength;
}
else
{
CanMessageList.Add(new CanMessageShowVM
{
= (byte)channel,
ID = actualId,
= (ulong)DateTimeOffset.Now.ToUnixTimeMilliseconds(),
= dlcLength
});
}
});
}
private string (System.Span<byte> s)
{
if (s == null || s.Length == 0)