周立功换同星
This commit is contained in:
@@ -1,30 +1,41 @@
|
||||
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 TSMasterCAN;
|
||||
using UIShare.GlobalVariable;
|
||||
using UIShare.PubEvent;
|
||||
using UIShare.UIViewModel;
|
||||
using UIShare.ViewModelBase;
|
||||
using ZLGUSBCANFD;
|
||||
|
||||
namespace CANModule.ViewModels
|
||||
{
|
||||
public class CollectCANSignalSettingViewModel : DialogViewModelBase
|
||||
public class CollectCANSignalSettingViewModel : BindableBase, IDialogAware
|
||||
{
|
||||
#region 字段
|
||||
private ZLGCANFD? _canfd;
|
||||
private SystemConfig? _systemConfig;
|
||||
#endregion
|
||||
|
||||
#region 属性
|
||||
public ObservableCollection<CANSignalConfig> ConfigurationList
|
||||
{
|
||||
get => _systemConfig?.ConfigurationList ?? new ObservableCollection<CANSignalConfig>();
|
||||
get => _systemConfig.ConfigurationList;
|
||||
set
|
||||
{
|
||||
if(_systemConfig.ConfigurationList != value)
|
||||
{
|
||||
_systemConfig.ConfigurationList = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private ObservableCollection<int> _ChannelList;
|
||||
public ObservableCollection<int> ChannelList
|
||||
{
|
||||
get => _ChannelList;
|
||||
set => SetProperty(ref _ChannelList, value);
|
||||
}
|
||||
private ObservableCollection<string> _messageList;
|
||||
public ObservableCollection<string> MessageList
|
||||
{
|
||||
@@ -39,42 +50,23 @@ namespace CANModule.ViewModels
|
||||
set => SetProperty(ref _signalList, value);
|
||||
}
|
||||
|
||||
private string _title = "信号采集设置";
|
||||
private string _title= "信号采集设置";
|
||||
public string Title
|
||||
{
|
||||
get => _title;
|
||||
set => SetProperty(ref _title, value);
|
||||
}
|
||||
|
||||
private string _selectedMessage;
|
||||
public string SelectedMessage
|
||||
{
|
||||
get => _selectedMessage;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _selectedMessage, value))
|
||||
if (SetProperty(ref _selectedMessage,value))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(value) && _canfd != null)
|
||||
if (value != null && value != "")
|
||||
{
|
||||
var db = _canfd.DBCParser.MsgDatabase;
|
||||
if (MessageChannel >= 0 && MessageChannel < db.Count)
|
||||
{
|
||||
var targetMsg = db[MessageChannel]
|
||||
.FirstOrDefault(x => $"[0x{x.msg_id:X}]{x.msg_name}" == value);
|
||||
|
||||
if (targetMsg != null && targetMsg.signal_Name != null)
|
||||
{
|
||||
SignalList = new ObservableCollection<string>(targetMsg.signal_Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
SignalList = new ObservableCollection<string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SignalList = new ObservableCollection<string>();
|
||||
SignalList = new(DBCParse.MsgDatabase[MessageChannel].Where(x => $"[0x{x.msg_id:X}]{x.msg_name}" == value).First().signal_Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,7 +78,6 @@ namespace CANModule.ViewModels
|
||||
get => _SelectedItem;
|
||||
set => SetProperty(ref _SelectedItem, value);
|
||||
}
|
||||
|
||||
private string _selectedSignal;
|
||||
public string SelectedSignal
|
||||
{
|
||||
@@ -94,7 +85,7 @@ namespace CANModule.ViewModels
|
||||
set => SetProperty(ref _selectedSignal, value);
|
||||
}
|
||||
|
||||
private int _MessageChannel=-1;
|
||||
private int _MessageChannel;
|
||||
public int MessageChannel
|
||||
{
|
||||
get => _MessageChannel;
|
||||
@@ -103,127 +94,91 @@ namespace CANModule.ViewModels
|
||||
if (_MessageChannel != value)
|
||||
{
|
||||
_MessageChannel = value;
|
||||
|
||||
MessageList = new(DBCParse.MsgDatabase[value].Select(s => $"[0x{s.msg_id:X}]{s.msg_name}"));
|
||||
SignalList = new();
|
||||
SelectedMessage = null;
|
||||
SelectedSignal = null;
|
||||
SignalList = new ObservableCollection<string>();
|
||||
|
||||
if (_canfd != null)
|
||||
{
|
||||
var db = _canfd.DBCParser.MsgDatabase;
|
||||
if (db != null && value >= 0 && value < db.Count)
|
||||
{
|
||||
MessageList = new ObservableCollection<string>(
|
||||
db[value].Select(s => $"[0x{s.msg_id:X}]{s.msg_name}")
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageList = new ObservableCollection<string>();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageList = new ObservableCollection<string>();
|
||||
}
|
||||
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int _collectionInterval = 1000;
|
||||
private int _collectionInterval=1000;
|
||||
public int CollectionInterval
|
||||
{
|
||||
get => _collectionInterval;
|
||||
set => SetProperty(ref _collectionInterval, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 命令
|
||||
#endregion Properties
|
||||
public ICommand AddCommand { get; set; }
|
||||
public ICommand CloseCommand { get; set; }
|
||||
public ICommand SaveCommand { get; set; }
|
||||
public ICommand DeleteCommand { get; set; }
|
||||
#endregion
|
||||
|
||||
public CollectCANSignalSettingViewModel(IContainerProvider containerProvider) : base(containerProvider)
|
||||
public ICommand CloseCommand { get; set; }
|
||||
public ICommand LoadCommand { get; set; }
|
||||
public ICommand SaveCommand { get; set; }
|
||||
public ICommand DeleteCommand { get; set; }
|
||||
public DialogCloseListener RequestClose { get; set; }
|
||||
public IEventAggregator _eventAggregator { get; set; }
|
||||
private SystemConfig _systemConfig;
|
||||
public CollectCANSignalSettingViewModel(IContainerProvider containerProvider)
|
||||
{
|
||||
_eventAggregator=containerProvider.Resolve<IEventAggregator>();
|
||||
_systemConfig= containerProvider.Resolve<SystemConfig>();
|
||||
CloseCommand = new DelegateCommand(Close);
|
||||
AddCommand = new DelegateCommand(Add);
|
||||
LoadCommand = new DelegateCommand(Load);
|
||||
SaveCommand = new DelegateCommand(Save);
|
||||
DeleteCommand = new DelegateCommand(Delete);
|
||||
}
|
||||
|
||||
#region Dialog 生命周期
|
||||
public override void OnDialogOpened(IDialogParameters parameters)
|
||||
{
|
||||
_systemConfig = parameters.GetValue<SystemConfig>("SystemConfig");
|
||||
_canfd = _systemConfig?.CANFD;
|
||||
string title = _systemConfig.Title;
|
||||
char lastChar = title[title.Length - 1];
|
||||
// 3. "TestCellX"转int
|
||||
MessageChannel = int.Parse(lastChar.ToString())-1;
|
||||
if (MessageChannel >= 4) MessageChannel -= 4;
|
||||
RaisePropertyChanged(nameof(ConfigurationList));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 命令处理
|
||||
private void Delete()
|
||||
{
|
||||
if (SelectedItem != null)
|
||||
{
|
||||
_systemConfig?.ConfigurationList.Remove(SelectedItem);
|
||||
}
|
||||
ConfigurationList.Remove(SelectedItem);
|
||||
}
|
||||
|
||||
private void Save()
|
||||
{
|
||||
_eventAggregator.GetEvent<CollectedCANMessageChangedEvent>().Publish();
|
||||
ConfigService.Save(_systemConfig);
|
||||
}
|
||||
|
||||
private void Load()
|
||||
{
|
||||
ChannelList = new ObservableCollection<int>(Enumerable.Range(0, 12));
|
||||
}
|
||||
|
||||
|
||||
private void Add()
|
||||
{
|
||||
if (string.IsNullOrEmpty(SelectedSignal) || string.IsNullOrEmpty(SelectedMessage) || CollectionInterval < 100)
|
||||
if (string.IsNullOrEmpty(SelectedSignal) || string.IsNullOrEmpty(SelectedMessage)||CollectionInterval<100)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_systemConfig == null) return;
|
||||
|
||||
string hexString = ExtractHex(SelectedMessage);
|
||||
if (string.IsNullOrEmpty(hexString)) return;
|
||||
|
||||
int decimalValue = ConvertHexToDecimal(hexString);
|
||||
if (_systemConfig.ConfigurationList.Any(x => x.SignalName == SelectedSignal && x.Channel == MessageChannel))
|
||||
if (string.IsNullOrEmpty(hexString))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_systemConfig.ConfigurationList.Add(new CANSignalConfig
|
||||
int decimalValue = ConvertHexToDecimal(hexString);
|
||||
if (ConfigurationList.Where(x => x.SignalName == SelectedSignal&&x.Channel==MessageChannel).FirstOrDefault() != null) return;
|
||||
ConfigurationList.Add(new CANSignalConfig
|
||||
{
|
||||
CollectionID = Guid.NewGuid(),
|
||||
Channel = MessageChannel,
|
||||
MethodName = CANSignalBroadcaster.BuildMethodName((uint)decimalValue, SelectedSignal),
|
||||
Channel = MessageChannel,
|
||||
MessageName = ExtractMessageName(SelectedMessage),
|
||||
SignalName = SelectedSignal,
|
||||
MessageID = decimalValue,
|
||||
CollectionInterval = CollectionInterval
|
||||
});
|
||||
}
|
||||
|
||||
private string ExtractHex(string input)
|
||||
{
|
||||
int startIndex = input.IndexOf("0x") + 2;
|
||||
int endIndex = input.IndexOf("]", startIndex);
|
||||
int endIndex = input.IndexOf("]", startIndex);
|
||||
if (startIndex >= 2 && endIndex > startIndex)
|
||||
{
|
||||
return input.Substring(startIndex, endIndex - startIndex);
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private int ConvertHexToDecimal(string hex)
|
||||
{
|
||||
try
|
||||
@@ -232,20 +187,37 @@ namespace CANModule.ViewModels
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private string ExtractMessageName(string input)
|
||||
{
|
||||
var parts = input.Split(']');
|
||||
return parts.Length > 1 ? parts[1] : string.Empty;
|
||||
return parts.Length > 1 ? parts[1] : string.Empty;
|
||||
}
|
||||
|
||||
private void Close()
|
||||
{
|
||||
RequestClose.Invoke();
|
||||
}
|
||||
#endregion
|
||||
|
||||
public bool CanCloseDialog()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void OnDialogClosed()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnDialogOpened(IDialogParameters parameters)
|
||||
{
|
||||
if (DBCParse.MsgDatabase.Count == 0 || DBCParse.MsgDatabase[0].Count==0)
|
||||
{
|
||||
|
||||
}
|
||||
MessageList = new(DBCParse.MsgDatabase[0].Select(s => $"[0x{s.msg_id:X}]{s.msg_name}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user