CAN驱动修改优化
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using CANModule.ViewModels;
|
||||
using CANModule.Views;
|
||||
|
||||
namespace CANModule
|
||||
@@ -12,7 +13,9 @@ namespace CANModule
|
||||
{
|
||||
containerRegistry.RegisterDialog<SelectCanMessageView>("SelectCanMessageView");
|
||||
containerRegistry.RegisterDialog<CollectCANSignalSettingView>("CollectCANSignalSettingView");
|
||||
containerRegistry.RegisterDialog<DBCInfoView>("DBCInfo");
|
||||
containerRegistry.RegisterForNavigation<CANView>("CANView");
|
||||
containerRegistry.Register<CANViewModel>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,11 @@ using System.Windows.Threading;
|
||||
using TSMasterCAN;
|
||||
using UIShare.GlobalVariable;
|
||||
using UIShare.UIViewModel;
|
||||
using UIShare.ViewModelBase;
|
||||
|
||||
namespace CANModule.ViewModels
|
||||
{
|
||||
public class CANViewModel : BindableBase, IDialogAware
|
||||
public class CANViewModel : NavigateViewModelBase
|
||||
{
|
||||
|
||||
#region 属性
|
||||
@@ -269,17 +270,15 @@ namespace CANModule.ViewModels
|
||||
|
||||
#endregion
|
||||
private IEventAggregator _eventAggregator { get; set; }
|
||||
private CAN? _canfd;
|
||||
private SystemConfig? _systemConfig;
|
||||
private readonly DeviceManager _deviceManager;
|
||||
private IDialogService _dialogService { get; set; }
|
||||
CancellationTokenSource cts = new CancellationTokenSource();
|
||||
public CANViewModel(IContainerProvider containerProvider)
|
||||
public CANViewModel(IContainerProvider containerProvider) : base(containerProvider)
|
||||
{
|
||||
_eventAggregator = containerProvider.Resolve<IEventAggregator>();
|
||||
_systemConfig = containerProvider.Resolve<SystemConfig>();
|
||||
_deviceManager = containerProvider.Resolve<DeviceManager>();
|
||||
_canfd = _deviceManager.CANFD;
|
||||
_dialogService = containerProvider.Resolve<IDialogService>();
|
||||
SelectBLFPathCommand = new DelegateCommand(SelectBLFPath);
|
||||
SaveBLFPathCommand = new DelegateCommand(SaveBLFPath);
|
||||
@@ -299,6 +298,7 @@ namespace CANModule.ViewModels
|
||||
LoadMessageCommand = new DelegateCommand(LoadMessage);
|
||||
DeleteDcAutoLoadCommand = new DelegateCommand(DeleteDcAutoLoad);
|
||||
SendCustomMessageCommand = new DelegateCommand(SendCustomMessage);
|
||||
Task.Run(() => Refresh(cts.Token), cts.Token);
|
||||
}
|
||||
|
||||
#region 命令
|
||||
@@ -496,7 +496,7 @@ namespace CANModule.ViewModels
|
||||
{
|
||||
while (ct.IsCancellationRequested == false)
|
||||
{
|
||||
var temp = CAN.RealTimeMessages.Select(s => s.Value).ToArray();
|
||||
var temp = _deviceManager._CANMonitoringService.RealTimeMessages.Select(s => s.Value).ToArray();
|
||||
foreach (var item in temp)
|
||||
{
|
||||
var find = CanMessageList.FirstOrDefault(s => s.报文ID == item.FIdentifier);
|
||||
@@ -571,6 +571,10 @@ namespace CANModule.ViewModels
|
||||
}
|
||||
|
||||
public void OnDialogOpened(IDialogParameters parameters)
|
||||
{
|
||||
|
||||
}
|
||||
public override void OnNavigatedTo(NavigationContext context)
|
||||
{
|
||||
Task.Run(() => Refresh(cts.Token), cts.Token);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Model;
|
||||
using Model.Models;
|
||||
using TSMasterCAN;
|
||||
using UIShare.GlobalVariable;
|
||||
using UIShare.PubEvent;
|
||||
using UIShare.UIViewModel;
|
||||
|
||||
namespace CANModule.ViewModels
|
||||
{
|
||||
public class DBCInfoViewModel :BindableBase, IDialogAware
|
||||
{
|
||||
private can_network _can_Network;
|
||||
|
||||
public required can_network can_Network
|
||||
{
|
||||
get { return _can_Network; }
|
||||
set { SetProperty(ref _can_Network, value); }
|
||||
}
|
||||
private List<_Msg_> _MessageInfo;
|
||||
|
||||
public required List<_Msg_> MessageInfo
|
||||
{
|
||||
get { return _MessageInfo; }
|
||||
set { SetProperty(ref _MessageInfo, value); }
|
||||
}
|
||||
private ObservableCollection<InstructionNode> _CanNetWorkNode = new();
|
||||
public ObservableCollection<InstructionNode> CanNetWorkNode
|
||||
{
|
||||
get => _CanNetWorkNode;
|
||||
set => SetProperty(ref _CanNetWorkNode, value);
|
||||
}
|
||||
private ObservableCollection<InstructionNode> _MessgaeNode = new();
|
||||
public ObservableCollection<InstructionNode> MessgaeNode
|
||||
{
|
||||
get => _MessgaeNode;
|
||||
set => SetProperty(ref _MessgaeNode, value);
|
||||
}
|
||||
public ICommand CloseCommand { get; set; }
|
||||
public DialogCloseListener RequestClose { get; set; }
|
||||
public DBCInfoViewModel()
|
||||
{
|
||||
CloseCommand = new DelegateCommand(Close);
|
||||
}
|
||||
|
||||
private void Close()
|
||||
{
|
||||
RequestClose.Invoke();
|
||||
}
|
||||
|
||||
public bool CanCloseDialog()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void OnDialogClosed()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnDialogOpened(IDialogParameters parameters)
|
||||
{
|
||||
if (parameters.ContainsKey("can_Network"))
|
||||
{
|
||||
can_Network = parameters.GetValue<can_network>("can_Network");
|
||||
}
|
||||
|
||||
if (parameters.ContainsKey("MsgDatabase"))
|
||||
{
|
||||
MessageInfo = parameters.GetValue<List<_Msg_>>("MsgDatabase");
|
||||
}
|
||||
InitTreeNode();
|
||||
}
|
||||
|
||||
private void InitTreeNode()
|
||||
{
|
||||
foreach(var item in can_Network.can_nodes)
|
||||
{
|
||||
var tx = new ObservableCollection<InstructionNode>();
|
||||
var rx = new ObservableCollection<InstructionNode>();
|
||||
foreach (var can_Message in item.rx_can_Messages)
|
||||
{
|
||||
rx.Add(new InstructionNode
|
||||
{
|
||||
Name = can_Message.message_name
|
||||
});
|
||||
}
|
||||
foreach (var can_Message in item.tx_can_Messages)
|
||||
{
|
||||
tx.Add(new InstructionNode
|
||||
{
|
||||
Name = can_Message.message_name
|
||||
});
|
||||
}
|
||||
var children = new ObservableCollection<InstructionNode>();
|
||||
children.Add(new InstructionNode
|
||||
{
|
||||
Name = "TX",
|
||||
Children = tx
|
||||
});
|
||||
children.Add(new InstructionNode
|
||||
{
|
||||
Name = "RX",
|
||||
Children = rx
|
||||
});
|
||||
CanNetWorkNode.Add(new InstructionNode
|
||||
{
|
||||
Name = item.node_name,
|
||||
Children = children
|
||||
});
|
||||
}
|
||||
foreach(var item in MessageInfo)
|
||||
{
|
||||
var children = new ObservableCollection<InstructionNode>();
|
||||
foreach(var Signalname in item.signal_Name)
|
||||
{
|
||||
children.Add(new InstructionNode
|
||||
{
|
||||
Name = Signalname
|
||||
});
|
||||
}
|
||||
string hexValue = "[0x" + item.msg_id.ToString("X") + "]";
|
||||
MessgaeNode.Add(new InstructionNode
|
||||
{
|
||||
Name = hexValue+item.msg_name,
|
||||
Children=children
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,12 +34,12 @@
|
||||
Foreground="White"
|
||||
VerticalAlignment="Center"
|
||||
Margin="5,0,10,0" />
|
||||
<Button Content="关闭"
|
||||
<!--<Button Content="关闭"
|
||||
Grid.Column="2"
|
||||
Margin="150 0 0 0"
|
||||
Width="60"
|
||||
Command="{Binding CloseCommand}"
|
||||
Height="25" />
|
||||
Height="25" />-->
|
||||
</Grid>
|
||||
</GroupBox.Header>
|
||||
<Grid>
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
<UserControl x:Class="CANModule.Views.DBCInfoView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:oxy="http://oxyplot.org/wpf"
|
||||
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
mc:Ignorable="d"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
xmlns:cons="clr-namespace:UIShare.Converters;assembly=UIShare"
|
||||
Background="White"
|
||||
xmlns:model="clr-namespace:Model.Models;assembly=Model"
|
||||
prism:ViewModelLocator.AutoWireViewModel="True"
|
||||
Height="400"
|
||||
Width="800">
|
||||
<prism:Dialog.WindowStyle>
|
||||
<Style BasedOn="{StaticResource DialogUserManageStyle}"
|
||||
TargetType="Window" />
|
||||
</prism:Dialog.WindowStyle>
|
||||
<GroupBox MouseLeftButtonDown="MouseLeftButtonDown">
|
||||
<GroupBox.Header>
|
||||
<Grid Margin="0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="CAN报文查看"
|
||||
|
||||
Foreground="White"
|
||||
VerticalAlignment="Center"
|
||||
Margin="5,0,10,0" />
|
||||
<Button Content="关闭"
|
||||
Grid.Column="2"
|
||||
Margin="150 0 0 0"
|
||||
Width="60"
|
||||
Command="{Binding CloseCommand}"
|
||||
Height="25"
|
||||
/>
|
||||
</Grid>
|
||||
</GroupBox.Header>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="2*" />
|
||||
<ColumnDefinition Width="5" />
|
||||
<!-- Splitter 列 -->
|
||||
<ColumnDefinition Width="2*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TreeView ItemsSource="{Binding MessgaeNode}">
|
||||
<TreeView.Resources>
|
||||
<HierarchicalDataTemplate DataType="{x:Type model:InstructionNode}"
|
||||
ItemsSource="{Binding Children}">
|
||||
<TextBlock Text="{Binding Name}" />
|
||||
</HierarchicalDataTemplate>
|
||||
</TreeView.Resources>
|
||||
</TreeView>
|
||||
<GridSplitter Grid.Column="1"
|
||||
Width="5"
|
||||
Background="Gray"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
ResizeBehavior="PreviousAndNext"
|
||||
ShowsPreview="True" />
|
||||
<TreeView Grid.Column="2"
|
||||
ItemsSource="{Binding CanNetWorkNode}">
|
||||
<TreeView.Resources>
|
||||
<HierarchicalDataTemplate DataType="{x:Type model:InstructionNode}"
|
||||
ItemsSource="{Binding Children}">
|
||||
<TextBlock Text="{Binding Name}" />
|
||||
</HierarchicalDataTemplate>
|
||||
</TreeView.Resources>
|
||||
</TreeView>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace CANModule.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// DBCInfoView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class DBCInfoView : UserControl
|
||||
{
|
||||
public DBCInfoView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
Window.GetWindow(this)?.DragMove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user