diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index eadefec..e5597ff 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -204,6 +204,9 @@ FilterUserControl.xaml + + NoiseUserControl.xaml + MenuUserControl.xaml @@ -244,6 +247,7 @@ + @@ -273,6 +277,9 @@ + + Designer + Designer MSBuild:Compile @@ -474,6 +481,7 @@ + diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index eadefec..e5597ff 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -204,6 +204,9 @@ FilterUserControl.xaml + + NoiseUserControl.xaml + MenuUserControl.xaml @@ -244,6 +247,7 @@ + @@ -273,6 +277,9 @@ + + Designer + Designer MSBuild:Compile @@ -474,6 +481,7 @@ + diff --git a/Correlator/Image/b_icon8.png b/Correlator/Image/b_icon8.png new file mode 100644 index 0000000..02f20ff --- /dev/null +++ b/Correlator/Image/b_icon8.png Binary files differ diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index eadefec..e5597ff 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -204,6 +204,9 @@ FilterUserControl.xaml + + NoiseUserControl.xaml + MenuUserControl.xaml @@ -244,6 +247,7 @@ + @@ -273,6 +277,9 @@ + + Designer + Designer MSBuild:Compile @@ -474,6 +481,7 @@ + diff --git a/Correlator/Image/b_icon8.png b/Correlator/Image/b_icon8.png new file mode 100644 index 0000000..02f20ff --- /dev/null +++ b/Correlator/Image/b_icon8.png Binary files differ diff --git a/Correlator/UserControlPage/FilterUserControl.xaml b/Correlator/UserControlPage/FilterUserControl.xaml index c654bb0..fe46f06 100644 --- a/Correlator/UserControlPage/FilterUserControl.xaml +++ b/Correlator/UserControlPage/FilterUserControl.xaml @@ -2,20 +2,16 @@ x:Class="Correlator.UserControlPage.FilterUserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:converter="clr-namespace:Correlator.Converter" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="768" d:DesignWidth="1366" + Background="{StaticResource PopupBackgroundColor}" DataContext="{Binding Filter, Source={StaticResource Locator}}" mc:Ignorable="d"> - - - - - @@ -55,13 +51,13 @@ VerticalAlignment="Bottom" FontSize="22" Foreground="#6c6c6c" - Text="干扰频段采集" /> + Text="频段筛选" /> + Text="Frequency Band Screening" /> @@ -91,15 +87,8 @@ BorderThickness="0" FontSize="22" Foreground="#545454" - IsEnabled="False"> - - - - - - - - + IsEnabled="False" + Text="{Binding Path=Value, ElementName=LowPreviewSlider, StringFormat=0}" /> - - - - - - - - + IsEnabled="False" + Text="{Binding Path=Value, ElementName=HighPreviewSlider, StringFormat=0}" /> @@ -161,158 +143,88 @@ - - - - - - - - + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - + + + + - - - - + + + + - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - + + Text="{Binding Path=Maximum, ElementName=LowPreviewSlider, StringFormat=0Hz}" /> @@ -321,164 +233,92 @@ - - - - - - - - + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - + + + + - - - - + + + + - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + HorizontalAlignment="Center" + Maximum="3000" + Minimum="100" + Orientation="Horizontal" + Value="{Binding MaxCurrentValue}"> + + + - + + Text="{Binding Path=Maximum, ElementName=HighPreviewSlider, StringFormat=0Hz}" /> - \ No newline at end of file + diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index eadefec..e5597ff 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -204,6 +204,9 @@ FilterUserControl.xaml + + NoiseUserControl.xaml + MenuUserControl.xaml @@ -244,6 +247,7 @@ + @@ -273,6 +277,9 @@ + + Designer + Designer MSBuild:Compile @@ -474,6 +481,7 @@ + diff --git a/Correlator/Image/b_icon8.png b/Correlator/Image/b_icon8.png new file mode 100644 index 0000000..02f20ff --- /dev/null +++ b/Correlator/Image/b_icon8.png Binary files differ diff --git a/Correlator/UserControlPage/FilterUserControl.xaml b/Correlator/UserControlPage/FilterUserControl.xaml index c654bb0..fe46f06 100644 --- a/Correlator/UserControlPage/FilterUserControl.xaml +++ b/Correlator/UserControlPage/FilterUserControl.xaml @@ -2,20 +2,16 @@ x:Class="Correlator.UserControlPage.FilterUserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:converter="clr-namespace:Correlator.Converter" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="768" d:DesignWidth="1366" + Background="{StaticResource PopupBackgroundColor}" DataContext="{Binding Filter, Source={StaticResource Locator}}" mc:Ignorable="d"> - - - - - @@ -55,13 +51,13 @@ VerticalAlignment="Bottom" FontSize="22" Foreground="#6c6c6c" - Text="干扰频段采集" /> + Text="频段筛选" /> + Text="Frequency Band Screening" /> @@ -91,15 +87,8 @@ BorderThickness="0" FontSize="22" Foreground="#545454" - IsEnabled="False"> - - - - - - - - + IsEnabled="False" + Text="{Binding Path=Value, ElementName=LowPreviewSlider, StringFormat=0}" /> - - - - - - - - + IsEnabled="False" + Text="{Binding Path=Value, ElementName=HighPreviewSlider, StringFormat=0}" /> @@ -161,158 +143,88 @@ - - - - - - - - + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - + + + + - - - - + + + + - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - + + Text="{Binding Path=Maximum, ElementName=LowPreviewSlider, StringFormat=0Hz}" /> @@ -321,164 +233,92 @@ - - - - - - - - + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - + + + + - - - - + + + + - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + HorizontalAlignment="Center" + Maximum="3000" + Minimum="100" + Orientation="Horizontal" + Value="{Binding MaxCurrentValue}"> + + + - + + Text="{Binding Path=Maximum, ElementName=HighPreviewSlider, StringFormat=0Hz}" /> - \ No newline at end of file + diff --git a/Correlator/UserControlPage/NoiseUserControl.xaml b/Correlator/UserControlPage/NoiseUserControl.xaml new file mode 100644 index 0000000..ac31b48 --- /dev/null +++ b/Correlator/UserControlPage/NoiseUserControl.xaml @@ -0,0 +1,484 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -583,8 +572,8 @@ Height="100" HorizontalAlignment="Left" BorderBrush="Transparent" - Command="{Binding FilterCommand}"> - + Command="{Binding NoiseCommand}"> + diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index eadefec..e5597ff 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -204,6 +204,9 @@ FilterUserControl.xaml + + NoiseUserControl.xaml + MenuUserControl.xaml @@ -244,6 +247,7 @@ + @@ -273,6 +277,9 @@ + + Designer + Designer MSBuild:Compile @@ -474,6 +481,7 @@ + diff --git a/Correlator/Image/b_icon8.png b/Correlator/Image/b_icon8.png new file mode 100644 index 0000000..02f20ff --- /dev/null +++ b/Correlator/Image/b_icon8.png Binary files differ diff --git a/Correlator/UserControlPage/FilterUserControl.xaml b/Correlator/UserControlPage/FilterUserControl.xaml index c654bb0..fe46f06 100644 --- a/Correlator/UserControlPage/FilterUserControl.xaml +++ b/Correlator/UserControlPage/FilterUserControl.xaml @@ -2,20 +2,16 @@ x:Class="Correlator.UserControlPage.FilterUserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:converter="clr-namespace:Correlator.Converter" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="768" d:DesignWidth="1366" + Background="{StaticResource PopupBackgroundColor}" DataContext="{Binding Filter, Source={StaticResource Locator}}" mc:Ignorable="d"> - - - - - @@ -55,13 +51,13 @@ VerticalAlignment="Bottom" FontSize="22" Foreground="#6c6c6c" - Text="干扰频段采集" /> + Text="频段筛选" /> + Text="Frequency Band Screening" /> @@ -91,15 +87,8 @@ BorderThickness="0" FontSize="22" Foreground="#545454" - IsEnabled="False"> - - - - - - - - + IsEnabled="False" + Text="{Binding Path=Value, ElementName=LowPreviewSlider, StringFormat=0}" /> - - - - - - - - + IsEnabled="False" + Text="{Binding Path=Value, ElementName=HighPreviewSlider, StringFormat=0}" /> @@ -161,158 +143,88 @@ - - - - - - - - + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - + + + + - - - - + + + + - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - + + Text="{Binding Path=Maximum, ElementName=LowPreviewSlider, StringFormat=0Hz}" /> @@ -321,164 +233,92 @@ - - - - - - - - + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - + + + + - - - - + + + + - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + HorizontalAlignment="Center" + Maximum="3000" + Minimum="100" + Orientation="Horizontal" + Value="{Binding MaxCurrentValue}"> + + + - + + Text="{Binding Path=Maximum, ElementName=HighPreviewSlider, StringFormat=0Hz}" /> - \ No newline at end of file + diff --git a/Correlator/UserControlPage/NoiseUserControl.xaml b/Correlator/UserControlPage/NoiseUserControl.xaml new file mode 100644 index 0000000..ac31b48 --- /dev/null +++ b/Correlator/UserControlPage/NoiseUserControl.xaml @@ -0,0 +1,484 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -583,8 +572,8 @@ Height="100" HorizontalAlignment="Left" BorderBrush="Transparent" - Command="{Binding FilterCommand}"> - + Command="{Binding NoiseCommand}"> + diff --git a/Correlator/View/HomePageWindow.xaml.cs b/Correlator/View/HomePageWindow.xaml.cs index 191a6b8..77d0163 100644 --- a/Correlator/View/HomePageWindow.xaml.cs +++ b/Correlator/View/HomePageWindow.xaml.cs @@ -14,12 +14,18 @@ Messenger.Default.Register(this, MessengerToken.CloseHomePageWindow, s => { Close(); }); - //干扰采集 + //频段过滤 Messenger.Default.Register(this, MessengerToken.AddFilter, s => { HomePageContentGrid.Children.Add(UserControlManager.UserControlMap["filterUserControl"]); }); Messenger.Default.Register(this, MessengerToken.RemoveFilter, s => { HomePageContentGrid.Children.Remove(UserControlManager.UserControlMap["filterUserControl"]); }); + //干扰采集 + Messenger.Default.Register(this, MessengerToken.AddNoise, + s => { HomePageContentGrid.Children.Add(UserControlManager.UserControlMap["noiseUserControl"]); }); + Messenger.Default.Register(this, MessengerToken.RemoveNoise, + s => { HomePageContentGrid.Children.Remove(UserControlManager.UserControlMap["noiseUserControl"]); }); + //听音 Messenger.Default.Register(this, MessengerToken.AddAudition, s => { HomePageContentGrid.Children.Add(UserControlManager.UserControlMap["auditionUserControl"]); }); diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index eadefec..e5597ff 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -204,6 +204,9 @@ FilterUserControl.xaml + + NoiseUserControl.xaml + MenuUserControl.xaml @@ -244,6 +247,7 @@ + @@ -273,6 +277,9 @@ + + Designer + Designer MSBuild:Compile @@ -474,6 +481,7 @@ + diff --git a/Correlator/Image/b_icon8.png b/Correlator/Image/b_icon8.png new file mode 100644 index 0000000..02f20ff --- /dev/null +++ b/Correlator/Image/b_icon8.png Binary files differ diff --git a/Correlator/UserControlPage/FilterUserControl.xaml b/Correlator/UserControlPage/FilterUserControl.xaml index c654bb0..fe46f06 100644 --- a/Correlator/UserControlPage/FilterUserControl.xaml +++ b/Correlator/UserControlPage/FilterUserControl.xaml @@ -2,20 +2,16 @@ x:Class="Correlator.UserControlPage.FilterUserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:converter="clr-namespace:Correlator.Converter" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="768" d:DesignWidth="1366" + Background="{StaticResource PopupBackgroundColor}" DataContext="{Binding Filter, Source={StaticResource Locator}}" mc:Ignorable="d"> - - - - - @@ -55,13 +51,13 @@ VerticalAlignment="Bottom" FontSize="22" Foreground="#6c6c6c" - Text="干扰频段采集" /> + Text="频段筛选" /> + Text="Frequency Band Screening" /> @@ -91,15 +87,8 @@ BorderThickness="0" FontSize="22" Foreground="#545454" - IsEnabled="False"> - - - - - - - - + IsEnabled="False" + Text="{Binding Path=Value, ElementName=LowPreviewSlider, StringFormat=0}" /> - - - - - - - - + IsEnabled="False" + Text="{Binding Path=Value, ElementName=HighPreviewSlider, StringFormat=0}" /> @@ -161,158 +143,88 @@ - - - - - - - - + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - + + + + - - - - + + + + - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - + + Text="{Binding Path=Maximum, ElementName=LowPreviewSlider, StringFormat=0Hz}" /> @@ -321,164 +233,92 @@ - - - - - - - - + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - + + + + - - - - + + + + - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + HorizontalAlignment="Center" + Maximum="3000" + Minimum="100" + Orientation="Horizontal" + Value="{Binding MaxCurrentValue}"> + + + - + + Text="{Binding Path=Maximum, ElementName=HighPreviewSlider, StringFormat=0Hz}" /> - \ No newline at end of file + diff --git a/Correlator/UserControlPage/NoiseUserControl.xaml b/Correlator/UserControlPage/NoiseUserControl.xaml new file mode 100644 index 0000000..ac31b48 --- /dev/null +++ b/Correlator/UserControlPage/NoiseUserControl.xaml @@ -0,0 +1,484 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -583,8 +572,8 @@ Height="100" HorizontalAlignment="Left" BorderBrush="Transparent" - Command="{Binding FilterCommand}"> - + Command="{Binding NoiseCommand}"> + diff --git a/Correlator/View/HomePageWindow.xaml.cs b/Correlator/View/HomePageWindow.xaml.cs index 191a6b8..77d0163 100644 --- a/Correlator/View/HomePageWindow.xaml.cs +++ b/Correlator/View/HomePageWindow.xaml.cs @@ -14,12 +14,18 @@ Messenger.Default.Register(this, MessengerToken.CloseHomePageWindow, s => { Close(); }); - //干扰采集 + //频段过滤 Messenger.Default.Register(this, MessengerToken.AddFilter, s => { HomePageContentGrid.Children.Add(UserControlManager.UserControlMap["filterUserControl"]); }); Messenger.Default.Register(this, MessengerToken.RemoveFilter, s => { HomePageContentGrid.Children.Remove(UserControlManager.UserControlMap["filterUserControl"]); }); + //干扰采集 + Messenger.Default.Register(this, MessengerToken.AddNoise, + s => { HomePageContentGrid.Children.Add(UserControlManager.UserControlMap["noiseUserControl"]); }); + Messenger.Default.Register(this, MessengerToken.RemoveNoise, + s => { HomePageContentGrid.Children.Remove(UserControlManager.UserControlMap["noiseUserControl"]); }); + //听音 Messenger.Default.Register(this, MessengerToken.AddAudition, s => { HomePageContentGrid.Children.Add(UserControlManager.UserControlMap["auditionUserControl"]); }); diff --git a/Correlator/ViewModel/FilterViewModel.cs b/Correlator/ViewModel/FilterViewModel.cs index 0279280..bfe6c07 100644 --- a/Correlator/ViewModel/FilterViewModel.cs +++ b/Correlator/ViewModel/FilterViewModel.cs @@ -1,166 +1,81 @@ using System; -using System.Threading.Tasks; -using System.Windows.Threading; +using System.Windows; using Correlator.Util; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Messaging; using LiveCharts; using LiveCharts.Defaults; +using MessageBox = HandyControl.Controls.MessageBox; namespace Correlator.ViewModel { public class FilterViewModel : ViewModelBase { - #region 属性绑定 + #region RelayCommand - /// - /// X轴起始频率 - /// - private double _minValue; - - public double MinValue - { - get => _minValue; - set - { - _minValue = value; - RaisePropertyChanged(() => MinValue); - } - } - - /// - /// X轴最大频率 - /// - private double _maxValue; - - public double MaxValue - { - get => _maxValue; - set - { - _maxValue = value; - RaisePropertyChanged(() => MaxValue); - } - } - - /// - /// 高值 - /// - private double _highValue; - - public double HighValue - { - get => _highValue; - set - { - _highValue = value; - RaisePropertyChanged(() => HighValue); - } - } - - /// - /// 低值 - /// - private double _lowValue; - - public double LowValue - { - get => _lowValue; - set - { - _lowValue = value; - RaisePropertyChanged(() => LowValue); - } - } - - /// - /// 传感器A信号强度0-5 - /// - private int _sensorASignalIntensity; - - public int SensorASignalIntensity - { - get => _sensorASignalIntensity; - set - { - _sensorASignalIntensity = value; - RaisePropertyChanged(() => SensorASignalIntensity); - } - } - - /// - /// 传感器B信号强度0-5 - /// - private int _sensorBSignalIntensity; - - public int SensorBSignalIntensity - { - get => _sensorBSignalIntensity; - set - { - _sensorBSignalIntensity = value; - RaisePropertyChanged(() => SensorBSignalIntensity); - } - } - - - /// - /// 红色直线显示状态 - /// - private string _lineRedVisibility = "Hidden"; - - public string LineRedVisibility - { - get => _lineRedVisibility; - set - { - _lineRedVisibility = value; - RaisePropertyChanged(() => LineRedVisibility); - } - } - - /// - /// 蓝色直线显示状态 - /// - private string _lineBlueVisibility = "Hidden"; - - public string LineBlueVisibility - { - get => _lineBlueVisibility; - set - { - _lineBlueVisibility = value; - RaisePropertyChanged(() => LineBlueVisibility); - } - } - - public IChartValues ColumnValuesA { get; set; } = new ChartValues(); - public IChartValues ColumnValuesB { get; set; } = new ChartValues(); + public RelayCommand GoBackCommand { get; set; } + public RelayCommand StartCalculateCommand { get; set; } #endregion - public RelayCommand GoBackCommand { get; set; } - public RelayCommand StartCollectDataCommand { get; set; } + #region VM属性 - private readonly DispatcherTimer _statusTimer = new DispatcherTimer + private int _minCurrentValue = 100; + + public int MinCurrentValue { - Interval = TimeSpan.FromSeconds(1) - }; + get => _minCurrentValue; + set + { + _minCurrentValue = value; + RaisePropertyChanged(() => MinCurrentValue); + } + } + + private int _maxCurrentValue = 100; + + public int MaxCurrentValue + { + get => _maxCurrentValue; + set + { + _maxCurrentValue = value; + RaisePropertyChanged(() => MaxCurrentValue); + } + } + + private IChartValues _columnValuesA; + + public IChartValues ColumnValuesA + { + get => _columnValuesA; + set + { + _columnValuesA = value; + RaisePropertyChanged(() => ColumnValuesA); + } + } + + private IChartValues _columnValuesB; + + public IChartValues ColumnValuesB + { + get => _columnValuesB; + set + { + _columnValuesB = value; + RaisePropertyChanged(() => ColumnValuesB); + } + } + + #endregion public FilterViewModel() { - GoBackCommand = new RelayCommand(() => { Messenger.Default.Send("", MessengerToken.RemoveFilter); }); - StartCollectDataCommand = new RelayCommand(StartCollectData); - - //默认值 - HighValue = 600; - LowValue = 100; - MaxValue = 3000; - MinValue = 20; - var random = new Random(); - for (var i = 0; i < 300; i++) + ColumnValuesA = new ChartValues(); + for (var i = 0; i < 100; i++) { var p = new ObservablePoint { @@ -171,7 +86,8 @@ ColumnValuesA.Add(p); } - for (var i = 0; i < 300; i++) + ColumnValuesB = new ChartValues(); + for (var i = 0; i < 100; i++) { var p = new ObservablePoint { @@ -181,76 +97,23 @@ ColumnValuesB.Add(p); } - - //每秒查询信号状态 - _statusTimer.Tick += delegate + + GoBackCommand = new RelayCommand(() => { Messenger.Default.Send("", MessengerToken.RemoveFilter); }); + StartCalculateCommand = new RelayCommand(() => { - SensorASignalIntensity = FlowStatus.SensorASignalIntensity; - SensorBSignalIntensity = FlowStatus.SensorBSignalIntensity; - }; - _statusTimer.Start(); - } - - private void StartCollectData() - { - var collectDataTask = new Task(() => - { - // while (FlowStatus.CanCollectData) - // { - // SenderClass.SendCorrelatorWakeUpCmd(SerialPortManager.Instance.SerialPort); - // Task.Delay(10 * 1000); - // } - - return true; - }); - collectDataTask.Start(); - - var getFreWaveTask = new Task(() => - { - // var num = 0; - // - // while (!CorrelatorDataSaveThread.devDataValueMap.ContainsKey(DevCode.Dev1) || - // !CorrelatorDataSaveThread.devDataValueMap.ContainsKey(DevCode.Dev2)) - // { - // Task.Delay(100); - // if (num++ >= 600) - // { - // MessageBox.Show("接收不到数据,请检查设备是否开启", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - // FlowStatus.IsRedCollectComplete = false; - // FlowStatus.IsBlueCollectComplete = false; - // return false; - // } - // } - // - // FlowStatus.CanCollectData = false; //停止下发采集指令 - // FlowStatus.CanGetSignal = true; //开始状态采集指令的发送 - // - // ClassCalculate calculate = ClassCalculate.Instance; - // calculate.Device1 = DevCode.Dev1; - // calculate.Device2 = DevCode.Dev2; - // - // calculate.GetFreWave(); - - FlowStatus.IsRedCollectComplete = true; - FlowStatus.IsBlueCollectComplete = true; - return true; - }); - getFreWaveTask.Start(); - - //显示Loading - - if (collectDataTask.Result && getFreWaveTask.Result) - { - //取消Loading - if (FlowStatus.IsRedCollectComplete && FlowStatus.IsBlueCollectComplete) + //将高低频作为参数重新计算相关系数 + if (_minCurrentValue > _maxCurrentValue) { - FlowStatus.IsRedCollectComplete = false; - FlowStatus.IsBlueCollectComplete = false; - - LineRedVisibility = "Visible"; - LineBlueVisibility = "Visible"; + MessageBox.Show("高频不能低于低频,请重新筛选", "错误", MessageBoxButton.OK, MessageBoxImage.Error); + return; } - } + + var param = new int[2]; + param[0] = _minCurrentValue; + param[1] = _maxCurrentValue; + Messenger.Default.Send(param, MessengerToken.ReStartCalculate); + Messenger.Default.Send("", MessengerToken.RemoveFilter); + }); } } } \ No newline at end of file diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index eadefec..e5597ff 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -204,6 +204,9 @@ FilterUserControl.xaml + + NoiseUserControl.xaml + MenuUserControl.xaml @@ -244,6 +247,7 @@ + @@ -273,6 +277,9 @@ + + Designer + Designer MSBuild:Compile @@ -474,6 +481,7 @@ + diff --git a/Correlator/Image/b_icon8.png b/Correlator/Image/b_icon8.png new file mode 100644 index 0000000..02f20ff --- /dev/null +++ b/Correlator/Image/b_icon8.png Binary files differ diff --git a/Correlator/UserControlPage/FilterUserControl.xaml b/Correlator/UserControlPage/FilterUserControl.xaml index c654bb0..fe46f06 100644 --- a/Correlator/UserControlPage/FilterUserControl.xaml +++ b/Correlator/UserControlPage/FilterUserControl.xaml @@ -2,20 +2,16 @@ x:Class="Correlator.UserControlPage.FilterUserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:converter="clr-namespace:Correlator.Converter" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="768" d:DesignWidth="1366" + Background="{StaticResource PopupBackgroundColor}" DataContext="{Binding Filter, Source={StaticResource Locator}}" mc:Ignorable="d"> - - - - - @@ -55,13 +51,13 @@ VerticalAlignment="Bottom" FontSize="22" Foreground="#6c6c6c" - Text="干扰频段采集" /> + Text="频段筛选" /> + Text="Frequency Band Screening" /> @@ -91,15 +87,8 @@ BorderThickness="0" FontSize="22" Foreground="#545454" - IsEnabled="False"> - - - - - - - - + IsEnabled="False" + Text="{Binding Path=Value, ElementName=LowPreviewSlider, StringFormat=0}" /> - - - - - - - - + IsEnabled="False" + Text="{Binding Path=Value, ElementName=HighPreviewSlider, StringFormat=0}" /> @@ -161,158 +143,88 @@ - - - - - - - - + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - + + + + - - - - + + + + - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - + + Text="{Binding Path=Maximum, ElementName=LowPreviewSlider, StringFormat=0Hz}" /> @@ -321,164 +233,92 @@ - - - - - - - - + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - + + + + - - - - + + + + - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + HorizontalAlignment="Center" + Maximum="3000" + Minimum="100" + Orientation="Horizontal" + Value="{Binding MaxCurrentValue}"> + + + - + + Text="{Binding Path=Maximum, ElementName=HighPreviewSlider, StringFormat=0Hz}" /> - \ No newline at end of file + diff --git a/Correlator/UserControlPage/NoiseUserControl.xaml b/Correlator/UserControlPage/NoiseUserControl.xaml new file mode 100644 index 0000000..ac31b48 --- /dev/null +++ b/Correlator/UserControlPage/NoiseUserControl.xaml @@ -0,0 +1,484 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -583,8 +572,8 @@ Height="100" HorizontalAlignment="Left" BorderBrush="Transparent" - Command="{Binding FilterCommand}"> - + Command="{Binding NoiseCommand}"> + diff --git a/Correlator/View/HomePageWindow.xaml.cs b/Correlator/View/HomePageWindow.xaml.cs index 191a6b8..77d0163 100644 --- a/Correlator/View/HomePageWindow.xaml.cs +++ b/Correlator/View/HomePageWindow.xaml.cs @@ -14,12 +14,18 @@ Messenger.Default.Register(this, MessengerToken.CloseHomePageWindow, s => { Close(); }); - //干扰采集 + //频段过滤 Messenger.Default.Register(this, MessengerToken.AddFilter, s => { HomePageContentGrid.Children.Add(UserControlManager.UserControlMap["filterUserControl"]); }); Messenger.Default.Register(this, MessengerToken.RemoveFilter, s => { HomePageContentGrid.Children.Remove(UserControlManager.UserControlMap["filterUserControl"]); }); + //干扰采集 + Messenger.Default.Register(this, MessengerToken.AddNoise, + s => { HomePageContentGrid.Children.Add(UserControlManager.UserControlMap["noiseUserControl"]); }); + Messenger.Default.Register(this, MessengerToken.RemoveNoise, + s => { HomePageContentGrid.Children.Remove(UserControlManager.UserControlMap["noiseUserControl"]); }); + //听音 Messenger.Default.Register(this, MessengerToken.AddAudition, s => { HomePageContentGrid.Children.Add(UserControlManager.UserControlMap["auditionUserControl"]); }); diff --git a/Correlator/ViewModel/FilterViewModel.cs b/Correlator/ViewModel/FilterViewModel.cs index 0279280..bfe6c07 100644 --- a/Correlator/ViewModel/FilterViewModel.cs +++ b/Correlator/ViewModel/FilterViewModel.cs @@ -1,166 +1,81 @@ using System; -using System.Threading.Tasks; -using System.Windows.Threading; +using System.Windows; using Correlator.Util; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Messaging; using LiveCharts; using LiveCharts.Defaults; +using MessageBox = HandyControl.Controls.MessageBox; namespace Correlator.ViewModel { public class FilterViewModel : ViewModelBase { - #region 属性绑定 + #region RelayCommand - /// - /// X轴起始频率 - /// - private double _minValue; - - public double MinValue - { - get => _minValue; - set - { - _minValue = value; - RaisePropertyChanged(() => MinValue); - } - } - - /// - /// X轴最大频率 - /// - private double _maxValue; - - public double MaxValue - { - get => _maxValue; - set - { - _maxValue = value; - RaisePropertyChanged(() => MaxValue); - } - } - - /// - /// 高值 - /// - private double _highValue; - - public double HighValue - { - get => _highValue; - set - { - _highValue = value; - RaisePropertyChanged(() => HighValue); - } - } - - /// - /// 低值 - /// - private double _lowValue; - - public double LowValue - { - get => _lowValue; - set - { - _lowValue = value; - RaisePropertyChanged(() => LowValue); - } - } - - /// - /// 传感器A信号强度0-5 - /// - private int _sensorASignalIntensity; - - public int SensorASignalIntensity - { - get => _sensorASignalIntensity; - set - { - _sensorASignalIntensity = value; - RaisePropertyChanged(() => SensorASignalIntensity); - } - } - - /// - /// 传感器B信号强度0-5 - /// - private int _sensorBSignalIntensity; - - public int SensorBSignalIntensity - { - get => _sensorBSignalIntensity; - set - { - _sensorBSignalIntensity = value; - RaisePropertyChanged(() => SensorBSignalIntensity); - } - } - - - /// - /// 红色直线显示状态 - /// - private string _lineRedVisibility = "Hidden"; - - public string LineRedVisibility - { - get => _lineRedVisibility; - set - { - _lineRedVisibility = value; - RaisePropertyChanged(() => LineRedVisibility); - } - } - - /// - /// 蓝色直线显示状态 - /// - private string _lineBlueVisibility = "Hidden"; - - public string LineBlueVisibility - { - get => _lineBlueVisibility; - set - { - _lineBlueVisibility = value; - RaisePropertyChanged(() => LineBlueVisibility); - } - } - - public IChartValues ColumnValuesA { get; set; } = new ChartValues(); - public IChartValues ColumnValuesB { get; set; } = new ChartValues(); + public RelayCommand GoBackCommand { get; set; } + public RelayCommand StartCalculateCommand { get; set; } #endregion - public RelayCommand GoBackCommand { get; set; } - public RelayCommand StartCollectDataCommand { get; set; } + #region VM属性 - private readonly DispatcherTimer _statusTimer = new DispatcherTimer + private int _minCurrentValue = 100; + + public int MinCurrentValue { - Interval = TimeSpan.FromSeconds(1) - }; + get => _minCurrentValue; + set + { + _minCurrentValue = value; + RaisePropertyChanged(() => MinCurrentValue); + } + } + + private int _maxCurrentValue = 100; + + public int MaxCurrentValue + { + get => _maxCurrentValue; + set + { + _maxCurrentValue = value; + RaisePropertyChanged(() => MaxCurrentValue); + } + } + + private IChartValues _columnValuesA; + + public IChartValues ColumnValuesA + { + get => _columnValuesA; + set + { + _columnValuesA = value; + RaisePropertyChanged(() => ColumnValuesA); + } + } + + private IChartValues _columnValuesB; + + public IChartValues ColumnValuesB + { + get => _columnValuesB; + set + { + _columnValuesB = value; + RaisePropertyChanged(() => ColumnValuesB); + } + } + + #endregion public FilterViewModel() { - GoBackCommand = new RelayCommand(() => { Messenger.Default.Send("", MessengerToken.RemoveFilter); }); - StartCollectDataCommand = new RelayCommand(StartCollectData); - - //默认值 - HighValue = 600; - LowValue = 100; - MaxValue = 3000; - MinValue = 20; - var random = new Random(); - for (var i = 0; i < 300; i++) + ColumnValuesA = new ChartValues(); + for (var i = 0; i < 100; i++) { var p = new ObservablePoint { @@ -171,7 +86,8 @@ ColumnValuesA.Add(p); } - for (var i = 0; i < 300; i++) + ColumnValuesB = new ChartValues(); + for (var i = 0; i < 100; i++) { var p = new ObservablePoint { @@ -181,76 +97,23 @@ ColumnValuesB.Add(p); } - - //每秒查询信号状态 - _statusTimer.Tick += delegate + + GoBackCommand = new RelayCommand(() => { Messenger.Default.Send("", MessengerToken.RemoveFilter); }); + StartCalculateCommand = new RelayCommand(() => { - SensorASignalIntensity = FlowStatus.SensorASignalIntensity; - SensorBSignalIntensity = FlowStatus.SensorBSignalIntensity; - }; - _statusTimer.Start(); - } - - private void StartCollectData() - { - var collectDataTask = new Task(() => - { - // while (FlowStatus.CanCollectData) - // { - // SenderClass.SendCorrelatorWakeUpCmd(SerialPortManager.Instance.SerialPort); - // Task.Delay(10 * 1000); - // } - - return true; - }); - collectDataTask.Start(); - - var getFreWaveTask = new Task(() => - { - // var num = 0; - // - // while (!CorrelatorDataSaveThread.devDataValueMap.ContainsKey(DevCode.Dev1) || - // !CorrelatorDataSaveThread.devDataValueMap.ContainsKey(DevCode.Dev2)) - // { - // Task.Delay(100); - // if (num++ >= 600) - // { - // MessageBox.Show("接收不到数据,请检查设备是否开启", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - // FlowStatus.IsRedCollectComplete = false; - // FlowStatus.IsBlueCollectComplete = false; - // return false; - // } - // } - // - // FlowStatus.CanCollectData = false; //停止下发采集指令 - // FlowStatus.CanGetSignal = true; //开始状态采集指令的发送 - // - // ClassCalculate calculate = ClassCalculate.Instance; - // calculate.Device1 = DevCode.Dev1; - // calculate.Device2 = DevCode.Dev2; - // - // calculate.GetFreWave(); - - FlowStatus.IsRedCollectComplete = true; - FlowStatus.IsBlueCollectComplete = true; - return true; - }); - getFreWaveTask.Start(); - - //显示Loading - - if (collectDataTask.Result && getFreWaveTask.Result) - { - //取消Loading - if (FlowStatus.IsRedCollectComplete && FlowStatus.IsBlueCollectComplete) + //将高低频作为参数重新计算相关系数 + if (_minCurrentValue > _maxCurrentValue) { - FlowStatus.IsRedCollectComplete = false; - FlowStatus.IsBlueCollectComplete = false; - - LineRedVisibility = "Visible"; - LineBlueVisibility = "Visible"; + MessageBox.Show("高频不能低于低频,请重新筛选", "错误", MessageBoxButton.OK, MessageBoxImage.Error); + return; } - } + + var param = new int[2]; + param[0] = _minCurrentValue; + param[1] = _maxCurrentValue; + Messenger.Default.Send(param, MessengerToken.ReStartCalculate); + Messenger.Default.Send("", MessengerToken.RemoveFilter); + }); } } } \ No newline at end of file diff --git a/Correlator/ViewModel/HomePageViewModel.cs b/Correlator/ViewModel/HomePageViewModel.cs index e92a5c4..9ae0e0d 100644 --- a/Correlator/ViewModel/HomePageViewModel.cs +++ b/Correlator/ViewModel/HomePageViewModel.cs @@ -32,6 +32,7 @@ public RelayCommand LeftSensorCommand { get; set; } public RelayCommand RightSensorCommand { get; set; } public RelayCommand FilterCommand { get; set; } + public RelayCommand NoiseCommand { get; set; } public RelayCommand AudioCommand { get; set; } public RelayCommand SnapShotCommand { get; set; } public RelayCommand ResetParamCommand { get; set; } @@ -235,15 +236,15 @@ /// /// 绑定干扰频段值 /// - private string _interfereValue = string.Empty; + private string _noiseValue = string.Empty; - public string InterfereValue + public string NoiseValue { - get => _interfereValue; + get => _noiseValue; set { - _interfereValue = value; - RaisePropertyChanged(() => InterfereValue); + _noiseValue = value; + RaisePropertyChanged(() => NoiseValue); } } @@ -461,17 +462,13 @@ Interval = TimeSpan.FromSeconds(5) }; + private string _locateDataDir; + private int _locateTimes; private string _snapShotPath = string.Empty; - //用户设置的管材 - private PipeMaterialModel _materialModel; - //Matlab算法 private readonly CorrelatorSingle.Correlator _correlator = new CorrelatorSingle.Correlator(); - //采集到的音频数据 - private CorrelatorDataModel _soundData; - public HomePageViewModel() { ShutDownCommand = new RelayCommand(() => @@ -517,7 +514,7 @@ //管道数值展示 PipeLine = "未设置"; //干扰频段 - InterfereValue = "未设置"; + NoiseValue = "未设置"; //声速数值展示 SoundSpeed = "0"; //经过了数值展示 @@ -567,10 +564,28 @@ return; } + if (FlowStatus.SelectedMaterialModel == null || FlowStatus.CorrelatorData == null) + { + MessageBox.Show("还未采集数据,无法进行频段筛选", "错误", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } + var filterUserControl = new FilterUserControl(); UserControlManager.UserControlMap["filterUserControl"] = filterUserControl; Messenger.Default.Send("", MessengerToken.AddFilter); }); + NoiseCommand = new RelayCommand(() => + { + if (!SerialPortManager.Instance.PortIsReady()) + { + MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } + + var noiseUserControl = new NoiseUserControl(); + UserControlManager.UserControlMap["noiseUserControl"] = noiseUserControl; + Messenger.Default.Send("", MessengerToken.AddNoise); + }); AudioCommand = new RelayCommand(() => { if (!SerialPortManager.Instance.PortIsReady()) @@ -608,7 +623,7 @@ }); SaveAudioCommand = new RelayCommand(() => { - if (_soundData != null) + if (FlowStatus.CorrelatorData != null) { SaveAudio(); } @@ -735,7 +750,7 @@ if (!it.IsReady) return; LogWithConsole.WriteLine("需要测算的管材是:" + JsonConvert.SerializeObject(it), "HomePageViewModel"); - _materialModel = it; + FlowStatus.SelectedMaterialModel = it; //{"Id":0,"EnglishMaterial":null,"ChineseMaterial":"球铁","Diameter":20.0,"Length":150.0,"SoundSpeed":1320,"LowFrequency":100,"HighFrequency":1000,"IsReady":true} StartState = true; //收集数据期间不允许收集信号 @@ -745,7 +760,7 @@ //绑定设置的参数 PipeLine = it.Diameter + "mm, " + it.Length + "m" + it.ChineseMaterial; SoundSpeed = it.SoundSpeed.ToString(); - InterfereValue = it.LowFrequency + "-" + it.HighFrequency + "Hz"; + NoiseValue = it.LowFrequency + "-" + it.HighFrequency + "Hz"; //数据采集Task new Task(CollectData).Start(); @@ -758,7 +773,7 @@ Messenger.Default.Register(this, MessengerToken.HomePageDeviceData, it => { //给音频数据赋值 - _soundData = it; + FlowStatus.CorrelatorData = it; using (var manager = new DataBaseManager()) { var today = DateTime.Now.ToString("yyyyMMdd"); @@ -776,8 +791,8 @@ //如果配置里面的日期相同,则取配置里面的Pipe作为index,如果配置里面的日期不相同,则默认index=1 var pipeIndex = configModel.Date.Equals(today) ? configModel.Pipe : 1; - var locateDataDir = Constant.GetLocateDataDir(pipeIndex); - var locateTimes = configModel.LocateTimes; + _locateDataDir = Constant.GetLocateDataDir(pipeIndex); + _locateTimes = configModel.LocateTimes; //计算 try @@ -786,13 +801,13 @@ task.Start(); //异步保存定位数据 - var fileName = locateDataDir + "\\测试数据." + locateTimes + "." + var fileName = _locateDataDir + "\\测试数据." + _locateTimes + "." + DateTime.Now.ToString("HHmmss") + ".txt"; StringUtil.SaveLocateData(it, fileName); LogWithConsole.WriteLine("定位数据路径:" + fileName, "HomePageViewModel"); //同步保存截图,需要等待Task出结果并且渲染完成,才能保存截图 - _snapShotPath = locateDataDir + "\\快照." + configModel.LocateTimes + "." + + _snapShotPath = _locateDataDir + "\\快照." + _locateTimes + "." + DateTime.Now.ToString("HHmmss") + ".png"; if (task.Result) { @@ -810,6 +825,27 @@ } } }); + + Messenger.Default.Register(this, MessengerToken.ReStartCalculate, frequency => + { + FlowStatus.SelectedMaterialModel.LowFrequency = frequency[0]; + FlowStatus.SelectedMaterialModel.HighFrequency = frequency[1]; + + LogWithConsole.WriteLine("需要重新测算的管材是:" + JsonConvert.SerializeObject(FlowStatus.SelectedMaterialModel), + "HomePageViewModel"); + + var task = new Task(() => CalculateData(FlowStatus.CorrelatorData)); + task.Start(); + + //重新计算需要把截屏次数自增 + _locateTimes++; + _snapShotPath = _locateDataDir + "\\快照." + _locateTimes + "." + DateTime.Now.ToString("HHmmss") + + ".png"; + if (task.Result) + { + _snapShotTimer.Start(); + } + }); } /// @@ -823,7 +859,7 @@ Snr = ""; PipeLine = "未设置"; SoundSpeed = "0"; - InterfereValue = "未设置"; + NoiseValue = "未设置"; PassTime = "0"; //复位时将波形图数据清空 ColumnValues?.Clear(); @@ -840,7 +876,8 @@ var filePath = Constant.GetAudioDir() + "\\音频_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".wav"; var stream = wavFile.CreateEmpty(filePath); - wavFile.WriteFilestream(stream, _soundData.LeftDeviceDataArray, _soundData.RightDeviceDataArray); + wavFile.WriteFilestream(stream, FlowStatus.CorrelatorData.LeftDeviceDataArray, + FlowStatus.CorrelatorData.RightDeviceDataArray); //写入数据,测试多轮时候保存数据采用下面方式 // for (var i = 0; i < CorrelatorDataSaveThread.devDataValueMap[DevCode.Dev2].Count; i++) @@ -853,7 +890,7 @@ wavFile.WriteHeader(stream, 7500, 2); Growl.Success("音频已保存"); //清空上次的缓存 - _soundData = null; + FlowStatus.CorrelatorData = null; } /// @@ -879,15 +916,15 @@ var array = _correlator.locating(11, (MWNumericArray)dataModel.LeftDeviceDataArray, (MWNumericArray)dataModel.RightDeviceDataArray, Constant.SamplingRate, - _materialModel.Length, _materialModel.SoundSpeed, + FlowStatus.SelectedMaterialModel.Length, FlowStatus.SelectedMaterialModel.SoundSpeed, 0, 0, 0, 0, - _materialModel.ChineseMaterial, - _materialModel.Diameter, - _materialModel.Diameter, + FlowStatus.SelectedMaterialModel.ChineseMaterial, + FlowStatus.SelectedMaterialModel.Diameter, + FlowStatus.SelectedMaterialModel.Diameter, 1, -1, -1, -1, - _materialModel.LowFrequency, - _materialModel.HighFrequency); + FlowStatus.SelectedMaterialModel.LowFrequency, + FlowStatus.SelectedMaterialModel.HighFrequency); //数据绑定 var snr = Convert.ToDouble(array[0].ToString()); //信噪比 diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index eadefec..e5597ff 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -204,6 +204,9 @@ FilterUserControl.xaml + + NoiseUserControl.xaml + MenuUserControl.xaml @@ -244,6 +247,7 @@ + @@ -273,6 +277,9 @@ + + Designer + Designer MSBuild:Compile @@ -474,6 +481,7 @@ + diff --git a/Correlator/Image/b_icon8.png b/Correlator/Image/b_icon8.png new file mode 100644 index 0000000..02f20ff --- /dev/null +++ b/Correlator/Image/b_icon8.png Binary files differ diff --git a/Correlator/UserControlPage/FilterUserControl.xaml b/Correlator/UserControlPage/FilterUserControl.xaml index c654bb0..fe46f06 100644 --- a/Correlator/UserControlPage/FilterUserControl.xaml +++ b/Correlator/UserControlPage/FilterUserControl.xaml @@ -2,20 +2,16 @@ x:Class="Correlator.UserControlPage.FilterUserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:converter="clr-namespace:Correlator.Converter" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="768" d:DesignWidth="1366" + Background="{StaticResource PopupBackgroundColor}" DataContext="{Binding Filter, Source={StaticResource Locator}}" mc:Ignorable="d"> - - - - - @@ -55,13 +51,13 @@ VerticalAlignment="Bottom" FontSize="22" Foreground="#6c6c6c" - Text="干扰频段采集" /> + Text="频段筛选" /> + Text="Frequency Band Screening" /> @@ -91,15 +87,8 @@ BorderThickness="0" FontSize="22" Foreground="#545454" - IsEnabled="False"> - - - - - - - - + IsEnabled="False" + Text="{Binding Path=Value, ElementName=LowPreviewSlider, StringFormat=0}" /> - - - - - - - - + IsEnabled="False" + Text="{Binding Path=Value, ElementName=HighPreviewSlider, StringFormat=0}" /> @@ -161,158 +143,88 @@ - - - - - - - - + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - + + + + - - - - + + + + - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - + + Text="{Binding Path=Maximum, ElementName=LowPreviewSlider, StringFormat=0Hz}" /> @@ -321,164 +233,92 @@ - - - - - - - - + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - + + + + - - - - + + + + - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + HorizontalAlignment="Center" + Maximum="3000" + Minimum="100" + Orientation="Horizontal" + Value="{Binding MaxCurrentValue}"> + + + - + + Text="{Binding Path=Maximum, ElementName=HighPreviewSlider, StringFormat=0Hz}" /> - \ No newline at end of file + diff --git a/Correlator/UserControlPage/NoiseUserControl.xaml b/Correlator/UserControlPage/NoiseUserControl.xaml new file mode 100644 index 0000000..ac31b48 --- /dev/null +++ b/Correlator/UserControlPage/NoiseUserControl.xaml @@ -0,0 +1,484 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -583,8 +572,8 @@ Height="100" HorizontalAlignment="Left" BorderBrush="Transparent" - Command="{Binding FilterCommand}"> - + Command="{Binding NoiseCommand}"> + diff --git a/Correlator/View/HomePageWindow.xaml.cs b/Correlator/View/HomePageWindow.xaml.cs index 191a6b8..77d0163 100644 --- a/Correlator/View/HomePageWindow.xaml.cs +++ b/Correlator/View/HomePageWindow.xaml.cs @@ -14,12 +14,18 @@ Messenger.Default.Register(this, MessengerToken.CloseHomePageWindow, s => { Close(); }); - //干扰采集 + //频段过滤 Messenger.Default.Register(this, MessengerToken.AddFilter, s => { HomePageContentGrid.Children.Add(UserControlManager.UserControlMap["filterUserControl"]); }); Messenger.Default.Register(this, MessengerToken.RemoveFilter, s => { HomePageContentGrid.Children.Remove(UserControlManager.UserControlMap["filterUserControl"]); }); + //干扰采集 + Messenger.Default.Register(this, MessengerToken.AddNoise, + s => { HomePageContentGrid.Children.Add(UserControlManager.UserControlMap["noiseUserControl"]); }); + Messenger.Default.Register(this, MessengerToken.RemoveNoise, + s => { HomePageContentGrid.Children.Remove(UserControlManager.UserControlMap["noiseUserControl"]); }); + //听音 Messenger.Default.Register(this, MessengerToken.AddAudition, s => { HomePageContentGrid.Children.Add(UserControlManager.UserControlMap["auditionUserControl"]); }); diff --git a/Correlator/ViewModel/FilterViewModel.cs b/Correlator/ViewModel/FilterViewModel.cs index 0279280..bfe6c07 100644 --- a/Correlator/ViewModel/FilterViewModel.cs +++ b/Correlator/ViewModel/FilterViewModel.cs @@ -1,166 +1,81 @@ using System; -using System.Threading.Tasks; -using System.Windows.Threading; +using System.Windows; using Correlator.Util; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Messaging; using LiveCharts; using LiveCharts.Defaults; +using MessageBox = HandyControl.Controls.MessageBox; namespace Correlator.ViewModel { public class FilterViewModel : ViewModelBase { - #region 属性绑定 + #region RelayCommand - /// - /// X轴起始频率 - /// - private double _minValue; - - public double MinValue - { - get => _minValue; - set - { - _minValue = value; - RaisePropertyChanged(() => MinValue); - } - } - - /// - /// X轴最大频率 - /// - private double _maxValue; - - public double MaxValue - { - get => _maxValue; - set - { - _maxValue = value; - RaisePropertyChanged(() => MaxValue); - } - } - - /// - /// 高值 - /// - private double _highValue; - - public double HighValue - { - get => _highValue; - set - { - _highValue = value; - RaisePropertyChanged(() => HighValue); - } - } - - /// - /// 低值 - /// - private double _lowValue; - - public double LowValue - { - get => _lowValue; - set - { - _lowValue = value; - RaisePropertyChanged(() => LowValue); - } - } - - /// - /// 传感器A信号强度0-5 - /// - private int _sensorASignalIntensity; - - public int SensorASignalIntensity - { - get => _sensorASignalIntensity; - set - { - _sensorASignalIntensity = value; - RaisePropertyChanged(() => SensorASignalIntensity); - } - } - - /// - /// 传感器B信号强度0-5 - /// - private int _sensorBSignalIntensity; - - public int SensorBSignalIntensity - { - get => _sensorBSignalIntensity; - set - { - _sensorBSignalIntensity = value; - RaisePropertyChanged(() => SensorBSignalIntensity); - } - } - - - /// - /// 红色直线显示状态 - /// - private string _lineRedVisibility = "Hidden"; - - public string LineRedVisibility - { - get => _lineRedVisibility; - set - { - _lineRedVisibility = value; - RaisePropertyChanged(() => LineRedVisibility); - } - } - - /// - /// 蓝色直线显示状态 - /// - private string _lineBlueVisibility = "Hidden"; - - public string LineBlueVisibility - { - get => _lineBlueVisibility; - set - { - _lineBlueVisibility = value; - RaisePropertyChanged(() => LineBlueVisibility); - } - } - - public IChartValues ColumnValuesA { get; set; } = new ChartValues(); - public IChartValues ColumnValuesB { get; set; } = new ChartValues(); + public RelayCommand GoBackCommand { get; set; } + public RelayCommand StartCalculateCommand { get; set; } #endregion - public RelayCommand GoBackCommand { get; set; } - public RelayCommand StartCollectDataCommand { get; set; } + #region VM属性 - private readonly DispatcherTimer _statusTimer = new DispatcherTimer + private int _minCurrentValue = 100; + + public int MinCurrentValue { - Interval = TimeSpan.FromSeconds(1) - }; + get => _minCurrentValue; + set + { + _minCurrentValue = value; + RaisePropertyChanged(() => MinCurrentValue); + } + } + + private int _maxCurrentValue = 100; + + public int MaxCurrentValue + { + get => _maxCurrentValue; + set + { + _maxCurrentValue = value; + RaisePropertyChanged(() => MaxCurrentValue); + } + } + + private IChartValues _columnValuesA; + + public IChartValues ColumnValuesA + { + get => _columnValuesA; + set + { + _columnValuesA = value; + RaisePropertyChanged(() => ColumnValuesA); + } + } + + private IChartValues _columnValuesB; + + public IChartValues ColumnValuesB + { + get => _columnValuesB; + set + { + _columnValuesB = value; + RaisePropertyChanged(() => ColumnValuesB); + } + } + + #endregion public FilterViewModel() { - GoBackCommand = new RelayCommand(() => { Messenger.Default.Send("", MessengerToken.RemoveFilter); }); - StartCollectDataCommand = new RelayCommand(StartCollectData); - - //默认值 - HighValue = 600; - LowValue = 100; - MaxValue = 3000; - MinValue = 20; - var random = new Random(); - for (var i = 0; i < 300; i++) + ColumnValuesA = new ChartValues(); + for (var i = 0; i < 100; i++) { var p = new ObservablePoint { @@ -171,7 +86,8 @@ ColumnValuesA.Add(p); } - for (var i = 0; i < 300; i++) + ColumnValuesB = new ChartValues(); + for (var i = 0; i < 100; i++) { var p = new ObservablePoint { @@ -181,76 +97,23 @@ ColumnValuesB.Add(p); } - - //每秒查询信号状态 - _statusTimer.Tick += delegate + + GoBackCommand = new RelayCommand(() => { Messenger.Default.Send("", MessengerToken.RemoveFilter); }); + StartCalculateCommand = new RelayCommand(() => { - SensorASignalIntensity = FlowStatus.SensorASignalIntensity; - SensorBSignalIntensity = FlowStatus.SensorBSignalIntensity; - }; - _statusTimer.Start(); - } - - private void StartCollectData() - { - var collectDataTask = new Task(() => - { - // while (FlowStatus.CanCollectData) - // { - // SenderClass.SendCorrelatorWakeUpCmd(SerialPortManager.Instance.SerialPort); - // Task.Delay(10 * 1000); - // } - - return true; - }); - collectDataTask.Start(); - - var getFreWaveTask = new Task(() => - { - // var num = 0; - // - // while (!CorrelatorDataSaveThread.devDataValueMap.ContainsKey(DevCode.Dev1) || - // !CorrelatorDataSaveThread.devDataValueMap.ContainsKey(DevCode.Dev2)) - // { - // Task.Delay(100); - // if (num++ >= 600) - // { - // MessageBox.Show("接收不到数据,请检查设备是否开启", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - // FlowStatus.IsRedCollectComplete = false; - // FlowStatus.IsBlueCollectComplete = false; - // return false; - // } - // } - // - // FlowStatus.CanCollectData = false; //停止下发采集指令 - // FlowStatus.CanGetSignal = true; //开始状态采集指令的发送 - // - // ClassCalculate calculate = ClassCalculate.Instance; - // calculate.Device1 = DevCode.Dev1; - // calculate.Device2 = DevCode.Dev2; - // - // calculate.GetFreWave(); - - FlowStatus.IsRedCollectComplete = true; - FlowStatus.IsBlueCollectComplete = true; - return true; - }); - getFreWaveTask.Start(); - - //显示Loading - - if (collectDataTask.Result && getFreWaveTask.Result) - { - //取消Loading - if (FlowStatus.IsRedCollectComplete && FlowStatus.IsBlueCollectComplete) + //将高低频作为参数重新计算相关系数 + if (_minCurrentValue > _maxCurrentValue) { - FlowStatus.IsRedCollectComplete = false; - FlowStatus.IsBlueCollectComplete = false; - - LineRedVisibility = "Visible"; - LineBlueVisibility = "Visible"; + MessageBox.Show("高频不能低于低频,请重新筛选", "错误", MessageBoxButton.OK, MessageBoxImage.Error); + return; } - } + + var param = new int[2]; + param[0] = _minCurrentValue; + param[1] = _maxCurrentValue; + Messenger.Default.Send(param, MessengerToken.ReStartCalculate); + Messenger.Default.Send("", MessengerToken.RemoveFilter); + }); } } } \ No newline at end of file diff --git a/Correlator/ViewModel/HomePageViewModel.cs b/Correlator/ViewModel/HomePageViewModel.cs index e92a5c4..9ae0e0d 100644 --- a/Correlator/ViewModel/HomePageViewModel.cs +++ b/Correlator/ViewModel/HomePageViewModel.cs @@ -32,6 +32,7 @@ public RelayCommand LeftSensorCommand { get; set; } public RelayCommand RightSensorCommand { get; set; } public RelayCommand FilterCommand { get; set; } + public RelayCommand NoiseCommand { get; set; } public RelayCommand AudioCommand { get; set; } public RelayCommand SnapShotCommand { get; set; } public RelayCommand ResetParamCommand { get; set; } @@ -235,15 +236,15 @@ /// /// 绑定干扰频段值 /// - private string _interfereValue = string.Empty; + private string _noiseValue = string.Empty; - public string InterfereValue + public string NoiseValue { - get => _interfereValue; + get => _noiseValue; set { - _interfereValue = value; - RaisePropertyChanged(() => InterfereValue); + _noiseValue = value; + RaisePropertyChanged(() => NoiseValue); } } @@ -461,17 +462,13 @@ Interval = TimeSpan.FromSeconds(5) }; + private string _locateDataDir; + private int _locateTimes; private string _snapShotPath = string.Empty; - //用户设置的管材 - private PipeMaterialModel _materialModel; - //Matlab算法 private readonly CorrelatorSingle.Correlator _correlator = new CorrelatorSingle.Correlator(); - //采集到的音频数据 - private CorrelatorDataModel _soundData; - public HomePageViewModel() { ShutDownCommand = new RelayCommand(() => @@ -517,7 +514,7 @@ //管道数值展示 PipeLine = "未设置"; //干扰频段 - InterfereValue = "未设置"; + NoiseValue = "未设置"; //声速数值展示 SoundSpeed = "0"; //经过了数值展示 @@ -567,10 +564,28 @@ return; } + if (FlowStatus.SelectedMaterialModel == null || FlowStatus.CorrelatorData == null) + { + MessageBox.Show("还未采集数据,无法进行频段筛选", "错误", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } + var filterUserControl = new FilterUserControl(); UserControlManager.UserControlMap["filterUserControl"] = filterUserControl; Messenger.Default.Send("", MessengerToken.AddFilter); }); + NoiseCommand = new RelayCommand(() => + { + if (!SerialPortManager.Instance.PortIsReady()) + { + MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } + + var noiseUserControl = new NoiseUserControl(); + UserControlManager.UserControlMap["noiseUserControl"] = noiseUserControl; + Messenger.Default.Send("", MessengerToken.AddNoise); + }); AudioCommand = new RelayCommand(() => { if (!SerialPortManager.Instance.PortIsReady()) @@ -608,7 +623,7 @@ }); SaveAudioCommand = new RelayCommand(() => { - if (_soundData != null) + if (FlowStatus.CorrelatorData != null) { SaveAudio(); } @@ -735,7 +750,7 @@ if (!it.IsReady) return; LogWithConsole.WriteLine("需要测算的管材是:" + JsonConvert.SerializeObject(it), "HomePageViewModel"); - _materialModel = it; + FlowStatus.SelectedMaterialModel = it; //{"Id":0,"EnglishMaterial":null,"ChineseMaterial":"球铁","Diameter":20.0,"Length":150.0,"SoundSpeed":1320,"LowFrequency":100,"HighFrequency":1000,"IsReady":true} StartState = true; //收集数据期间不允许收集信号 @@ -745,7 +760,7 @@ //绑定设置的参数 PipeLine = it.Diameter + "mm, " + it.Length + "m" + it.ChineseMaterial; SoundSpeed = it.SoundSpeed.ToString(); - InterfereValue = it.LowFrequency + "-" + it.HighFrequency + "Hz"; + NoiseValue = it.LowFrequency + "-" + it.HighFrequency + "Hz"; //数据采集Task new Task(CollectData).Start(); @@ -758,7 +773,7 @@ Messenger.Default.Register(this, MessengerToken.HomePageDeviceData, it => { //给音频数据赋值 - _soundData = it; + FlowStatus.CorrelatorData = it; using (var manager = new DataBaseManager()) { var today = DateTime.Now.ToString("yyyyMMdd"); @@ -776,8 +791,8 @@ //如果配置里面的日期相同,则取配置里面的Pipe作为index,如果配置里面的日期不相同,则默认index=1 var pipeIndex = configModel.Date.Equals(today) ? configModel.Pipe : 1; - var locateDataDir = Constant.GetLocateDataDir(pipeIndex); - var locateTimes = configModel.LocateTimes; + _locateDataDir = Constant.GetLocateDataDir(pipeIndex); + _locateTimes = configModel.LocateTimes; //计算 try @@ -786,13 +801,13 @@ task.Start(); //异步保存定位数据 - var fileName = locateDataDir + "\\测试数据." + locateTimes + "." + var fileName = _locateDataDir + "\\测试数据." + _locateTimes + "." + DateTime.Now.ToString("HHmmss") + ".txt"; StringUtil.SaveLocateData(it, fileName); LogWithConsole.WriteLine("定位数据路径:" + fileName, "HomePageViewModel"); //同步保存截图,需要等待Task出结果并且渲染完成,才能保存截图 - _snapShotPath = locateDataDir + "\\快照." + configModel.LocateTimes + "." + + _snapShotPath = _locateDataDir + "\\快照." + _locateTimes + "." + DateTime.Now.ToString("HHmmss") + ".png"; if (task.Result) { @@ -810,6 +825,27 @@ } } }); + + Messenger.Default.Register(this, MessengerToken.ReStartCalculate, frequency => + { + FlowStatus.SelectedMaterialModel.LowFrequency = frequency[0]; + FlowStatus.SelectedMaterialModel.HighFrequency = frequency[1]; + + LogWithConsole.WriteLine("需要重新测算的管材是:" + JsonConvert.SerializeObject(FlowStatus.SelectedMaterialModel), + "HomePageViewModel"); + + var task = new Task(() => CalculateData(FlowStatus.CorrelatorData)); + task.Start(); + + //重新计算需要把截屏次数自增 + _locateTimes++; + _snapShotPath = _locateDataDir + "\\快照." + _locateTimes + "." + DateTime.Now.ToString("HHmmss") + + ".png"; + if (task.Result) + { + _snapShotTimer.Start(); + } + }); } /// @@ -823,7 +859,7 @@ Snr = ""; PipeLine = "未设置"; SoundSpeed = "0"; - InterfereValue = "未设置"; + NoiseValue = "未设置"; PassTime = "0"; //复位时将波形图数据清空 ColumnValues?.Clear(); @@ -840,7 +876,8 @@ var filePath = Constant.GetAudioDir() + "\\音频_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".wav"; var stream = wavFile.CreateEmpty(filePath); - wavFile.WriteFilestream(stream, _soundData.LeftDeviceDataArray, _soundData.RightDeviceDataArray); + wavFile.WriteFilestream(stream, FlowStatus.CorrelatorData.LeftDeviceDataArray, + FlowStatus.CorrelatorData.RightDeviceDataArray); //写入数据,测试多轮时候保存数据采用下面方式 // for (var i = 0; i < CorrelatorDataSaveThread.devDataValueMap[DevCode.Dev2].Count; i++) @@ -853,7 +890,7 @@ wavFile.WriteHeader(stream, 7500, 2); Growl.Success("音频已保存"); //清空上次的缓存 - _soundData = null; + FlowStatus.CorrelatorData = null; } /// @@ -879,15 +916,15 @@ var array = _correlator.locating(11, (MWNumericArray)dataModel.LeftDeviceDataArray, (MWNumericArray)dataModel.RightDeviceDataArray, Constant.SamplingRate, - _materialModel.Length, _materialModel.SoundSpeed, + FlowStatus.SelectedMaterialModel.Length, FlowStatus.SelectedMaterialModel.SoundSpeed, 0, 0, 0, 0, - _materialModel.ChineseMaterial, - _materialModel.Diameter, - _materialModel.Diameter, + FlowStatus.SelectedMaterialModel.ChineseMaterial, + FlowStatus.SelectedMaterialModel.Diameter, + FlowStatus.SelectedMaterialModel.Diameter, 1, -1, -1, -1, - _materialModel.LowFrequency, - _materialModel.HighFrequency); + FlowStatus.SelectedMaterialModel.LowFrequency, + FlowStatus.SelectedMaterialModel.HighFrequency); //数据绑定 var snr = Convert.ToDouble(array[0].ToString()); //信噪比 diff --git a/Correlator/ViewModel/NoiseViewModel.cs b/Correlator/ViewModel/NoiseViewModel.cs new file mode 100644 index 0000000..29e3997 --- /dev/null +++ b/Correlator/ViewModel/NoiseViewModel.cs @@ -0,0 +1,256 @@ +using System; +using System.Threading.Tasks; +using System.Windows.Threading; +using Correlator.Util; +using GalaSoft.MvvmLight; +using GalaSoft.MvvmLight.Command; +using GalaSoft.MvvmLight.Messaging; +using LiveCharts; +using LiveCharts.Defaults; + +namespace Correlator.ViewModel +{ + public class NoiseViewModel : ViewModelBase + { + #region 属性绑定 + + /// + /// X轴起始频率 + /// + private double _minValue; + + public double MinValue + { + get => _minValue; + set + { + _minValue = value; + RaisePropertyChanged(() => MinValue); + } + } + + /// + /// X轴最大频率 + /// + private double _maxValue; + + public double MaxValue + { + get => _maxValue; + set + { + _maxValue = value; + RaisePropertyChanged(() => MaxValue); + } + } + + /// + /// 高值 + /// + private double _highValue; + + public double HighValue + { + get => _highValue; + set + { + _highValue = value; + RaisePropertyChanged(() => HighValue); + } + } + + /// + /// 低值 + /// + private double _lowValue; + + public double LowValue + { + get => _lowValue; + set + { + _lowValue = value; + RaisePropertyChanged(() => LowValue); + } + } + + /// + /// 传感器A信号强度0-5 + /// + private int _sensorASignalIntensity; + + public int SensorASignalIntensity + { + get => _sensorASignalIntensity; + set + { + _sensorASignalIntensity = value; + RaisePropertyChanged(() => SensorASignalIntensity); + } + } + + /// + /// 传感器B信号强度0-5 + /// + private int _sensorBSignalIntensity; + + public int SensorBSignalIntensity + { + get => _sensorBSignalIntensity; + set + { + _sensorBSignalIntensity = value; + RaisePropertyChanged(() => SensorBSignalIntensity); + } + } + + + /// + /// 红色直线显示状态 + /// + private string _lineRedVisibility = "Hidden"; + + public string LineRedVisibility + { + get => _lineRedVisibility; + set + { + _lineRedVisibility = value; + RaisePropertyChanged(() => LineRedVisibility); + } + } + + /// + /// 蓝色直线显示状态 + /// + private string _lineBlueVisibility = "Hidden"; + + public string LineBlueVisibility + { + get => _lineBlueVisibility; + set + { + _lineBlueVisibility = value; + RaisePropertyChanged(() => LineBlueVisibility); + } + } + + public IChartValues ColumnValuesA { get; set; } = new ChartValues(); + public IChartValues ColumnValuesB { get; set; } = new ChartValues(); + + #endregion + + public RelayCommand GoBackCommand { get; set; } + public RelayCommand StartCollectDataCommand { get; set; } + + private readonly DispatcherTimer _statusTimer = new DispatcherTimer + { + Interval = TimeSpan.FromSeconds(1) + }; + + public NoiseViewModel() + { + GoBackCommand = new RelayCommand(() => { Messenger.Default.Send("", MessengerToken.RemoveNoise); }); + StartCollectDataCommand = new RelayCommand(StartCollectData); + + //默认值 + HighValue = 600; + LowValue = 100; + MaxValue = 3000; + MinValue = 20; + + var random = new Random(); + for (var i = 0; i < 300; i++) + { + var p = new ObservablePoint + { + X = i * 10, + Y = random.Next(0, 100) + }; + + ColumnValuesA.Add(p); + } + + for (var i = 0; i < 300; i++) + { + var p = new ObservablePoint + { + X = i * 10, + Y = random.Next(0, 100) + }; + + ColumnValuesB.Add(p); + } + + //每秒查询信号状态 + _statusTimer.Tick += delegate + { + SensorASignalIntensity = FlowStatus.SensorASignalIntensity; + SensorBSignalIntensity = FlowStatus.SensorBSignalIntensity; + }; + _statusTimer.Start(); + } + + private void StartCollectData() + { + var collectDataTask = new Task(() => + { + // while (FlowStatus.CanCollectData) + // { + // SenderClass.SendCorrelatorWakeUpCmd(SerialPortManager.Instance.SerialPort); + // Task.Delay(10 * 1000); + // } + + return true; + }); + collectDataTask.Start(); + + var getFreWaveTask = new Task(() => + { + // var num = 0; + // + // while (!CorrelatorDataSaveThread.devDataValueMap.ContainsKey(DevCode.Dev1) || + // !CorrelatorDataSaveThread.devDataValueMap.ContainsKey(DevCode.Dev2)) + // { + // Task.Delay(100); + // if (num++ >= 600) + // { + // MessageBox.Show("接收不到数据,请检查设备是否开启", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // FlowStatus.IsRedCollectComplete = false; + // FlowStatus.IsBlueCollectComplete = false; + // return false; + // } + // } + // + // FlowStatus.CanCollectData = false; //停止下发采集指令 + // FlowStatus.CanGetSignal = true; //开始状态采集指令的发送 + // + // ClassCalculate calculate = ClassCalculate.Instance; + // calculate.Device1 = DevCode.Dev1; + // calculate.Device2 = DevCode.Dev2; + // + // calculate.GetFreWave(); + + FlowStatus.IsRedCollectComplete = true; + FlowStatus.IsBlueCollectComplete = true; + return true; + }); + getFreWaveTask.Start(); + + //显示Loading + + if (collectDataTask.Result && getFreWaveTask.Result) + { + //取消Loading + if (FlowStatus.IsRedCollectComplete && FlowStatus.IsBlueCollectComplete) + { + FlowStatus.IsRedCollectComplete = false; + FlowStatus.IsBlueCollectComplete = false; + + LineRedVisibility = "Visible"; + LineBlueVisibility = "Visible"; + } + } + } + } +} \ No newline at end of file diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index eadefec..e5597ff 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -204,6 +204,9 @@ FilterUserControl.xaml + + NoiseUserControl.xaml + MenuUserControl.xaml @@ -244,6 +247,7 @@ + @@ -273,6 +277,9 @@ + + Designer + Designer MSBuild:Compile @@ -474,6 +481,7 @@ + diff --git a/Correlator/Image/b_icon8.png b/Correlator/Image/b_icon8.png new file mode 100644 index 0000000..02f20ff --- /dev/null +++ b/Correlator/Image/b_icon8.png Binary files differ diff --git a/Correlator/UserControlPage/FilterUserControl.xaml b/Correlator/UserControlPage/FilterUserControl.xaml index c654bb0..fe46f06 100644 --- a/Correlator/UserControlPage/FilterUserControl.xaml +++ b/Correlator/UserControlPage/FilterUserControl.xaml @@ -2,20 +2,16 @@ x:Class="Correlator.UserControlPage.FilterUserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:converter="clr-namespace:Correlator.Converter" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="768" d:DesignWidth="1366" + Background="{StaticResource PopupBackgroundColor}" DataContext="{Binding Filter, Source={StaticResource Locator}}" mc:Ignorable="d"> - - - - - @@ -55,13 +51,13 @@ VerticalAlignment="Bottom" FontSize="22" Foreground="#6c6c6c" - Text="干扰频段采集" /> + Text="频段筛选" /> + Text="Frequency Band Screening" /> @@ -91,15 +87,8 @@ BorderThickness="0" FontSize="22" Foreground="#545454" - IsEnabled="False"> - - - - - - - - + IsEnabled="False" + Text="{Binding Path=Value, ElementName=LowPreviewSlider, StringFormat=0}" /> - - - - - - - - + IsEnabled="False" + Text="{Binding Path=Value, ElementName=HighPreviewSlider, StringFormat=0}" /> @@ -161,158 +143,88 @@ - - - - - - - - + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - + + + + - - - - + + + + - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - + + Text="{Binding Path=Maximum, ElementName=LowPreviewSlider, StringFormat=0Hz}" /> @@ -321,164 +233,92 @@ - - - - - - - - + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - + + + + - - - - + + + + - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + HorizontalAlignment="Center" + Maximum="3000" + Minimum="100" + Orientation="Horizontal" + Value="{Binding MaxCurrentValue}"> + + + - + + Text="{Binding Path=Maximum, ElementName=HighPreviewSlider, StringFormat=0Hz}" /> - \ No newline at end of file + diff --git a/Correlator/UserControlPage/NoiseUserControl.xaml b/Correlator/UserControlPage/NoiseUserControl.xaml new file mode 100644 index 0000000..ac31b48 --- /dev/null +++ b/Correlator/UserControlPage/NoiseUserControl.xaml @@ -0,0 +1,484 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -583,8 +572,8 @@ Height="100" HorizontalAlignment="Left" BorderBrush="Transparent" - Command="{Binding FilterCommand}"> - + Command="{Binding NoiseCommand}"> + diff --git a/Correlator/View/HomePageWindow.xaml.cs b/Correlator/View/HomePageWindow.xaml.cs index 191a6b8..77d0163 100644 --- a/Correlator/View/HomePageWindow.xaml.cs +++ b/Correlator/View/HomePageWindow.xaml.cs @@ -14,12 +14,18 @@ Messenger.Default.Register(this, MessengerToken.CloseHomePageWindow, s => { Close(); }); - //干扰采集 + //频段过滤 Messenger.Default.Register(this, MessengerToken.AddFilter, s => { HomePageContentGrid.Children.Add(UserControlManager.UserControlMap["filterUserControl"]); }); Messenger.Default.Register(this, MessengerToken.RemoveFilter, s => { HomePageContentGrid.Children.Remove(UserControlManager.UserControlMap["filterUserControl"]); }); + //干扰采集 + Messenger.Default.Register(this, MessengerToken.AddNoise, + s => { HomePageContentGrid.Children.Add(UserControlManager.UserControlMap["noiseUserControl"]); }); + Messenger.Default.Register(this, MessengerToken.RemoveNoise, + s => { HomePageContentGrid.Children.Remove(UserControlManager.UserControlMap["noiseUserControl"]); }); + //听音 Messenger.Default.Register(this, MessengerToken.AddAudition, s => { HomePageContentGrid.Children.Add(UserControlManager.UserControlMap["auditionUserControl"]); }); diff --git a/Correlator/ViewModel/FilterViewModel.cs b/Correlator/ViewModel/FilterViewModel.cs index 0279280..bfe6c07 100644 --- a/Correlator/ViewModel/FilterViewModel.cs +++ b/Correlator/ViewModel/FilterViewModel.cs @@ -1,166 +1,81 @@ using System; -using System.Threading.Tasks; -using System.Windows.Threading; +using System.Windows; using Correlator.Util; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Messaging; using LiveCharts; using LiveCharts.Defaults; +using MessageBox = HandyControl.Controls.MessageBox; namespace Correlator.ViewModel { public class FilterViewModel : ViewModelBase { - #region 属性绑定 + #region RelayCommand - /// - /// X轴起始频率 - /// - private double _minValue; - - public double MinValue - { - get => _minValue; - set - { - _minValue = value; - RaisePropertyChanged(() => MinValue); - } - } - - /// - /// X轴最大频率 - /// - private double _maxValue; - - public double MaxValue - { - get => _maxValue; - set - { - _maxValue = value; - RaisePropertyChanged(() => MaxValue); - } - } - - /// - /// 高值 - /// - private double _highValue; - - public double HighValue - { - get => _highValue; - set - { - _highValue = value; - RaisePropertyChanged(() => HighValue); - } - } - - /// - /// 低值 - /// - private double _lowValue; - - public double LowValue - { - get => _lowValue; - set - { - _lowValue = value; - RaisePropertyChanged(() => LowValue); - } - } - - /// - /// 传感器A信号强度0-5 - /// - private int _sensorASignalIntensity; - - public int SensorASignalIntensity - { - get => _sensorASignalIntensity; - set - { - _sensorASignalIntensity = value; - RaisePropertyChanged(() => SensorASignalIntensity); - } - } - - /// - /// 传感器B信号强度0-5 - /// - private int _sensorBSignalIntensity; - - public int SensorBSignalIntensity - { - get => _sensorBSignalIntensity; - set - { - _sensorBSignalIntensity = value; - RaisePropertyChanged(() => SensorBSignalIntensity); - } - } - - - /// - /// 红色直线显示状态 - /// - private string _lineRedVisibility = "Hidden"; - - public string LineRedVisibility - { - get => _lineRedVisibility; - set - { - _lineRedVisibility = value; - RaisePropertyChanged(() => LineRedVisibility); - } - } - - /// - /// 蓝色直线显示状态 - /// - private string _lineBlueVisibility = "Hidden"; - - public string LineBlueVisibility - { - get => _lineBlueVisibility; - set - { - _lineBlueVisibility = value; - RaisePropertyChanged(() => LineBlueVisibility); - } - } - - public IChartValues ColumnValuesA { get; set; } = new ChartValues(); - public IChartValues ColumnValuesB { get; set; } = new ChartValues(); + public RelayCommand GoBackCommand { get; set; } + public RelayCommand StartCalculateCommand { get; set; } #endregion - public RelayCommand GoBackCommand { get; set; } - public RelayCommand StartCollectDataCommand { get; set; } + #region VM属性 - private readonly DispatcherTimer _statusTimer = new DispatcherTimer + private int _minCurrentValue = 100; + + public int MinCurrentValue { - Interval = TimeSpan.FromSeconds(1) - }; + get => _minCurrentValue; + set + { + _minCurrentValue = value; + RaisePropertyChanged(() => MinCurrentValue); + } + } + + private int _maxCurrentValue = 100; + + public int MaxCurrentValue + { + get => _maxCurrentValue; + set + { + _maxCurrentValue = value; + RaisePropertyChanged(() => MaxCurrentValue); + } + } + + private IChartValues _columnValuesA; + + public IChartValues ColumnValuesA + { + get => _columnValuesA; + set + { + _columnValuesA = value; + RaisePropertyChanged(() => ColumnValuesA); + } + } + + private IChartValues _columnValuesB; + + public IChartValues ColumnValuesB + { + get => _columnValuesB; + set + { + _columnValuesB = value; + RaisePropertyChanged(() => ColumnValuesB); + } + } + + #endregion public FilterViewModel() { - GoBackCommand = new RelayCommand(() => { Messenger.Default.Send("", MessengerToken.RemoveFilter); }); - StartCollectDataCommand = new RelayCommand(StartCollectData); - - //默认值 - HighValue = 600; - LowValue = 100; - MaxValue = 3000; - MinValue = 20; - var random = new Random(); - for (var i = 0; i < 300; i++) + ColumnValuesA = new ChartValues(); + for (var i = 0; i < 100; i++) { var p = new ObservablePoint { @@ -171,7 +86,8 @@ ColumnValuesA.Add(p); } - for (var i = 0; i < 300; i++) + ColumnValuesB = new ChartValues(); + for (var i = 0; i < 100; i++) { var p = new ObservablePoint { @@ -181,76 +97,23 @@ ColumnValuesB.Add(p); } - - //每秒查询信号状态 - _statusTimer.Tick += delegate + + GoBackCommand = new RelayCommand(() => { Messenger.Default.Send("", MessengerToken.RemoveFilter); }); + StartCalculateCommand = new RelayCommand(() => { - SensorASignalIntensity = FlowStatus.SensorASignalIntensity; - SensorBSignalIntensity = FlowStatus.SensorBSignalIntensity; - }; - _statusTimer.Start(); - } - - private void StartCollectData() - { - var collectDataTask = new Task(() => - { - // while (FlowStatus.CanCollectData) - // { - // SenderClass.SendCorrelatorWakeUpCmd(SerialPortManager.Instance.SerialPort); - // Task.Delay(10 * 1000); - // } - - return true; - }); - collectDataTask.Start(); - - var getFreWaveTask = new Task(() => - { - // var num = 0; - // - // while (!CorrelatorDataSaveThread.devDataValueMap.ContainsKey(DevCode.Dev1) || - // !CorrelatorDataSaveThread.devDataValueMap.ContainsKey(DevCode.Dev2)) - // { - // Task.Delay(100); - // if (num++ >= 600) - // { - // MessageBox.Show("接收不到数据,请检查设备是否开启", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - // FlowStatus.IsRedCollectComplete = false; - // FlowStatus.IsBlueCollectComplete = false; - // return false; - // } - // } - // - // FlowStatus.CanCollectData = false; //停止下发采集指令 - // FlowStatus.CanGetSignal = true; //开始状态采集指令的发送 - // - // ClassCalculate calculate = ClassCalculate.Instance; - // calculate.Device1 = DevCode.Dev1; - // calculate.Device2 = DevCode.Dev2; - // - // calculate.GetFreWave(); - - FlowStatus.IsRedCollectComplete = true; - FlowStatus.IsBlueCollectComplete = true; - return true; - }); - getFreWaveTask.Start(); - - //显示Loading - - if (collectDataTask.Result && getFreWaveTask.Result) - { - //取消Loading - if (FlowStatus.IsRedCollectComplete && FlowStatus.IsBlueCollectComplete) + //将高低频作为参数重新计算相关系数 + if (_minCurrentValue > _maxCurrentValue) { - FlowStatus.IsRedCollectComplete = false; - FlowStatus.IsBlueCollectComplete = false; - - LineRedVisibility = "Visible"; - LineBlueVisibility = "Visible"; + MessageBox.Show("高频不能低于低频,请重新筛选", "错误", MessageBoxButton.OK, MessageBoxImage.Error); + return; } - } + + var param = new int[2]; + param[0] = _minCurrentValue; + param[1] = _maxCurrentValue; + Messenger.Default.Send(param, MessengerToken.ReStartCalculate); + Messenger.Default.Send("", MessengerToken.RemoveFilter); + }); } } } \ No newline at end of file diff --git a/Correlator/ViewModel/HomePageViewModel.cs b/Correlator/ViewModel/HomePageViewModel.cs index e92a5c4..9ae0e0d 100644 --- a/Correlator/ViewModel/HomePageViewModel.cs +++ b/Correlator/ViewModel/HomePageViewModel.cs @@ -32,6 +32,7 @@ public RelayCommand LeftSensorCommand { get; set; } public RelayCommand RightSensorCommand { get; set; } public RelayCommand FilterCommand { get; set; } + public RelayCommand NoiseCommand { get; set; } public RelayCommand AudioCommand { get; set; } public RelayCommand SnapShotCommand { get; set; } public RelayCommand ResetParamCommand { get; set; } @@ -235,15 +236,15 @@ /// /// 绑定干扰频段值 /// - private string _interfereValue = string.Empty; + private string _noiseValue = string.Empty; - public string InterfereValue + public string NoiseValue { - get => _interfereValue; + get => _noiseValue; set { - _interfereValue = value; - RaisePropertyChanged(() => InterfereValue); + _noiseValue = value; + RaisePropertyChanged(() => NoiseValue); } } @@ -461,17 +462,13 @@ Interval = TimeSpan.FromSeconds(5) }; + private string _locateDataDir; + private int _locateTimes; private string _snapShotPath = string.Empty; - //用户设置的管材 - private PipeMaterialModel _materialModel; - //Matlab算法 private readonly CorrelatorSingle.Correlator _correlator = new CorrelatorSingle.Correlator(); - //采集到的音频数据 - private CorrelatorDataModel _soundData; - public HomePageViewModel() { ShutDownCommand = new RelayCommand(() => @@ -517,7 +514,7 @@ //管道数值展示 PipeLine = "未设置"; //干扰频段 - InterfereValue = "未设置"; + NoiseValue = "未设置"; //声速数值展示 SoundSpeed = "0"; //经过了数值展示 @@ -567,10 +564,28 @@ return; } + if (FlowStatus.SelectedMaterialModel == null || FlowStatus.CorrelatorData == null) + { + MessageBox.Show("还未采集数据,无法进行频段筛选", "错误", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } + var filterUserControl = new FilterUserControl(); UserControlManager.UserControlMap["filterUserControl"] = filterUserControl; Messenger.Default.Send("", MessengerToken.AddFilter); }); + NoiseCommand = new RelayCommand(() => + { + if (!SerialPortManager.Instance.PortIsReady()) + { + MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } + + var noiseUserControl = new NoiseUserControl(); + UserControlManager.UserControlMap["noiseUserControl"] = noiseUserControl; + Messenger.Default.Send("", MessengerToken.AddNoise); + }); AudioCommand = new RelayCommand(() => { if (!SerialPortManager.Instance.PortIsReady()) @@ -608,7 +623,7 @@ }); SaveAudioCommand = new RelayCommand(() => { - if (_soundData != null) + if (FlowStatus.CorrelatorData != null) { SaveAudio(); } @@ -735,7 +750,7 @@ if (!it.IsReady) return; LogWithConsole.WriteLine("需要测算的管材是:" + JsonConvert.SerializeObject(it), "HomePageViewModel"); - _materialModel = it; + FlowStatus.SelectedMaterialModel = it; //{"Id":0,"EnglishMaterial":null,"ChineseMaterial":"球铁","Diameter":20.0,"Length":150.0,"SoundSpeed":1320,"LowFrequency":100,"HighFrequency":1000,"IsReady":true} StartState = true; //收集数据期间不允许收集信号 @@ -745,7 +760,7 @@ //绑定设置的参数 PipeLine = it.Diameter + "mm, " + it.Length + "m" + it.ChineseMaterial; SoundSpeed = it.SoundSpeed.ToString(); - InterfereValue = it.LowFrequency + "-" + it.HighFrequency + "Hz"; + NoiseValue = it.LowFrequency + "-" + it.HighFrequency + "Hz"; //数据采集Task new Task(CollectData).Start(); @@ -758,7 +773,7 @@ Messenger.Default.Register(this, MessengerToken.HomePageDeviceData, it => { //给音频数据赋值 - _soundData = it; + FlowStatus.CorrelatorData = it; using (var manager = new DataBaseManager()) { var today = DateTime.Now.ToString("yyyyMMdd"); @@ -776,8 +791,8 @@ //如果配置里面的日期相同,则取配置里面的Pipe作为index,如果配置里面的日期不相同,则默认index=1 var pipeIndex = configModel.Date.Equals(today) ? configModel.Pipe : 1; - var locateDataDir = Constant.GetLocateDataDir(pipeIndex); - var locateTimes = configModel.LocateTimes; + _locateDataDir = Constant.GetLocateDataDir(pipeIndex); + _locateTimes = configModel.LocateTimes; //计算 try @@ -786,13 +801,13 @@ task.Start(); //异步保存定位数据 - var fileName = locateDataDir + "\\测试数据." + locateTimes + "." + var fileName = _locateDataDir + "\\测试数据." + _locateTimes + "." + DateTime.Now.ToString("HHmmss") + ".txt"; StringUtil.SaveLocateData(it, fileName); LogWithConsole.WriteLine("定位数据路径:" + fileName, "HomePageViewModel"); //同步保存截图,需要等待Task出结果并且渲染完成,才能保存截图 - _snapShotPath = locateDataDir + "\\快照." + configModel.LocateTimes + "." + + _snapShotPath = _locateDataDir + "\\快照." + _locateTimes + "." + DateTime.Now.ToString("HHmmss") + ".png"; if (task.Result) { @@ -810,6 +825,27 @@ } } }); + + Messenger.Default.Register(this, MessengerToken.ReStartCalculate, frequency => + { + FlowStatus.SelectedMaterialModel.LowFrequency = frequency[0]; + FlowStatus.SelectedMaterialModel.HighFrequency = frequency[1]; + + LogWithConsole.WriteLine("需要重新测算的管材是:" + JsonConvert.SerializeObject(FlowStatus.SelectedMaterialModel), + "HomePageViewModel"); + + var task = new Task(() => CalculateData(FlowStatus.CorrelatorData)); + task.Start(); + + //重新计算需要把截屏次数自增 + _locateTimes++; + _snapShotPath = _locateDataDir + "\\快照." + _locateTimes + "." + DateTime.Now.ToString("HHmmss") + + ".png"; + if (task.Result) + { + _snapShotTimer.Start(); + } + }); } /// @@ -823,7 +859,7 @@ Snr = ""; PipeLine = "未设置"; SoundSpeed = "0"; - InterfereValue = "未设置"; + NoiseValue = "未设置"; PassTime = "0"; //复位时将波形图数据清空 ColumnValues?.Clear(); @@ -840,7 +876,8 @@ var filePath = Constant.GetAudioDir() + "\\音频_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".wav"; var stream = wavFile.CreateEmpty(filePath); - wavFile.WriteFilestream(stream, _soundData.LeftDeviceDataArray, _soundData.RightDeviceDataArray); + wavFile.WriteFilestream(stream, FlowStatus.CorrelatorData.LeftDeviceDataArray, + FlowStatus.CorrelatorData.RightDeviceDataArray); //写入数据,测试多轮时候保存数据采用下面方式 // for (var i = 0; i < CorrelatorDataSaveThread.devDataValueMap[DevCode.Dev2].Count; i++) @@ -853,7 +890,7 @@ wavFile.WriteHeader(stream, 7500, 2); Growl.Success("音频已保存"); //清空上次的缓存 - _soundData = null; + FlowStatus.CorrelatorData = null; } /// @@ -879,15 +916,15 @@ var array = _correlator.locating(11, (MWNumericArray)dataModel.LeftDeviceDataArray, (MWNumericArray)dataModel.RightDeviceDataArray, Constant.SamplingRate, - _materialModel.Length, _materialModel.SoundSpeed, + FlowStatus.SelectedMaterialModel.Length, FlowStatus.SelectedMaterialModel.SoundSpeed, 0, 0, 0, 0, - _materialModel.ChineseMaterial, - _materialModel.Diameter, - _materialModel.Diameter, + FlowStatus.SelectedMaterialModel.ChineseMaterial, + FlowStatus.SelectedMaterialModel.Diameter, + FlowStatus.SelectedMaterialModel.Diameter, 1, -1, -1, -1, - _materialModel.LowFrequency, - _materialModel.HighFrequency); + FlowStatus.SelectedMaterialModel.LowFrequency, + FlowStatus.SelectedMaterialModel.HighFrequency); //数据绑定 var snr = Convert.ToDouble(array[0].ToString()); //信噪比 diff --git a/Correlator/ViewModel/NoiseViewModel.cs b/Correlator/ViewModel/NoiseViewModel.cs new file mode 100644 index 0000000..29e3997 --- /dev/null +++ b/Correlator/ViewModel/NoiseViewModel.cs @@ -0,0 +1,256 @@ +using System; +using System.Threading.Tasks; +using System.Windows.Threading; +using Correlator.Util; +using GalaSoft.MvvmLight; +using GalaSoft.MvvmLight.Command; +using GalaSoft.MvvmLight.Messaging; +using LiveCharts; +using LiveCharts.Defaults; + +namespace Correlator.ViewModel +{ + public class NoiseViewModel : ViewModelBase + { + #region 属性绑定 + + /// + /// X轴起始频率 + /// + private double _minValue; + + public double MinValue + { + get => _minValue; + set + { + _minValue = value; + RaisePropertyChanged(() => MinValue); + } + } + + /// + /// X轴最大频率 + /// + private double _maxValue; + + public double MaxValue + { + get => _maxValue; + set + { + _maxValue = value; + RaisePropertyChanged(() => MaxValue); + } + } + + /// + /// 高值 + /// + private double _highValue; + + public double HighValue + { + get => _highValue; + set + { + _highValue = value; + RaisePropertyChanged(() => HighValue); + } + } + + /// + /// 低值 + /// + private double _lowValue; + + public double LowValue + { + get => _lowValue; + set + { + _lowValue = value; + RaisePropertyChanged(() => LowValue); + } + } + + /// + /// 传感器A信号强度0-5 + /// + private int _sensorASignalIntensity; + + public int SensorASignalIntensity + { + get => _sensorASignalIntensity; + set + { + _sensorASignalIntensity = value; + RaisePropertyChanged(() => SensorASignalIntensity); + } + } + + /// + /// 传感器B信号强度0-5 + /// + private int _sensorBSignalIntensity; + + public int SensorBSignalIntensity + { + get => _sensorBSignalIntensity; + set + { + _sensorBSignalIntensity = value; + RaisePropertyChanged(() => SensorBSignalIntensity); + } + } + + + /// + /// 红色直线显示状态 + /// + private string _lineRedVisibility = "Hidden"; + + public string LineRedVisibility + { + get => _lineRedVisibility; + set + { + _lineRedVisibility = value; + RaisePropertyChanged(() => LineRedVisibility); + } + } + + /// + /// 蓝色直线显示状态 + /// + private string _lineBlueVisibility = "Hidden"; + + public string LineBlueVisibility + { + get => _lineBlueVisibility; + set + { + _lineBlueVisibility = value; + RaisePropertyChanged(() => LineBlueVisibility); + } + } + + public IChartValues ColumnValuesA { get; set; } = new ChartValues(); + public IChartValues ColumnValuesB { get; set; } = new ChartValues(); + + #endregion + + public RelayCommand GoBackCommand { get; set; } + public RelayCommand StartCollectDataCommand { get; set; } + + private readonly DispatcherTimer _statusTimer = new DispatcherTimer + { + Interval = TimeSpan.FromSeconds(1) + }; + + public NoiseViewModel() + { + GoBackCommand = new RelayCommand(() => { Messenger.Default.Send("", MessengerToken.RemoveNoise); }); + StartCollectDataCommand = new RelayCommand(StartCollectData); + + //默认值 + HighValue = 600; + LowValue = 100; + MaxValue = 3000; + MinValue = 20; + + var random = new Random(); + for (var i = 0; i < 300; i++) + { + var p = new ObservablePoint + { + X = i * 10, + Y = random.Next(0, 100) + }; + + ColumnValuesA.Add(p); + } + + for (var i = 0; i < 300; i++) + { + var p = new ObservablePoint + { + X = i * 10, + Y = random.Next(0, 100) + }; + + ColumnValuesB.Add(p); + } + + //每秒查询信号状态 + _statusTimer.Tick += delegate + { + SensorASignalIntensity = FlowStatus.SensorASignalIntensity; + SensorBSignalIntensity = FlowStatus.SensorBSignalIntensity; + }; + _statusTimer.Start(); + } + + private void StartCollectData() + { + var collectDataTask = new Task(() => + { + // while (FlowStatus.CanCollectData) + // { + // SenderClass.SendCorrelatorWakeUpCmd(SerialPortManager.Instance.SerialPort); + // Task.Delay(10 * 1000); + // } + + return true; + }); + collectDataTask.Start(); + + var getFreWaveTask = new Task(() => + { + // var num = 0; + // + // while (!CorrelatorDataSaveThread.devDataValueMap.ContainsKey(DevCode.Dev1) || + // !CorrelatorDataSaveThread.devDataValueMap.ContainsKey(DevCode.Dev2)) + // { + // Task.Delay(100); + // if (num++ >= 600) + // { + // MessageBox.Show("接收不到数据,请检查设备是否开启", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // FlowStatus.IsRedCollectComplete = false; + // FlowStatus.IsBlueCollectComplete = false; + // return false; + // } + // } + // + // FlowStatus.CanCollectData = false; //停止下发采集指令 + // FlowStatus.CanGetSignal = true; //开始状态采集指令的发送 + // + // ClassCalculate calculate = ClassCalculate.Instance; + // calculate.Device1 = DevCode.Dev1; + // calculate.Device2 = DevCode.Dev2; + // + // calculate.GetFreWave(); + + FlowStatus.IsRedCollectComplete = true; + FlowStatus.IsBlueCollectComplete = true; + return true; + }); + getFreWaveTask.Start(); + + //显示Loading + + if (collectDataTask.Result && getFreWaveTask.Result) + { + //取消Loading + if (FlowStatus.IsRedCollectComplete && FlowStatus.IsBlueCollectComplete) + { + FlowStatus.IsRedCollectComplete = false; + FlowStatus.IsBlueCollectComplete = false; + + LineRedVisibility = "Visible"; + LineBlueVisibility = "Visible"; + } + } + } + } +} \ No newline at end of file diff --git a/Correlator/ViewModel/ViewModelLocator.cs b/Correlator/ViewModel/ViewModelLocator.cs index dcd1ce3..d360603 100644 --- a/Correlator/ViewModel/ViewModelLocator.cs +++ b/Correlator/ViewModel/ViewModelLocator.cs @@ -33,6 +33,7 @@ SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); + SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); @@ -49,6 +50,7 @@ public HomePageViewModel HomePage => ServiceLocator.Current.GetInstance(); public MenuViewModel Menu => ServiceLocator.Current.GetInstance(); public FilterViewModel Filter => ServiceLocator.Current.GetInstance(); + public NoiseViewModel Noise => ServiceLocator.Current.GetInstance(); public AudioFileViewModel AudioFile => ServiceLocator.Current.GetInstance(); public PictureFileViewModel PictureFile => ServiceLocator.Current.GetInstance(); public BigPictureViewModel BigPicture => ServiceLocator.Current.GetInstance();