现场优化2
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user