diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 09453b0..bbac218 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -233,7 +233,6 @@ - AudioFileWindow.xaml diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 09453b0..bbac218 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -233,7 +233,6 @@ - AudioFileWindow.xaml diff --git a/Correlator/Dialog/CheckResponseDialog.xaml b/Correlator/Dialog/CheckResponseDialog.xaml index 6e916f3..1b216ef 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml +++ b/Correlator/Dialog/CheckResponseDialog.xaml @@ -11,7 +11,6 @@ AllowsTransparency="True" Background="Transparent" Closed="CheckResponseDialog_OnClosed" - DataContext="{Binding CheckResponse, Source={StaticResource Locator}}" Loaded="CheckResponseDialog_OnLoaded" ResizeMode="NoResize" ShowInTaskbar="False" @@ -111,7 +110,8 @@ Grid.Row="1" Margin="0,10" VerticalAlignment="Top" - Content="下一步" /> + Content="下一步" + Style="{StaticResource ButtonPrimary}" /> + IsEnabled="{Binding ElementName=RedSensorStepBar, Path=StepIndex, Converter={StaticResource StepButtonStateConverter}}" + Style="{StaticResource ButtonPrimary}" /> - AudioFileWindow.xaml diff --git a/Correlator/Dialog/CheckResponseDialog.xaml b/Correlator/Dialog/CheckResponseDialog.xaml index 6e916f3..1b216ef 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml +++ b/Correlator/Dialog/CheckResponseDialog.xaml @@ -11,7 +11,6 @@ AllowsTransparency="True" Background="Transparent" Closed="CheckResponseDialog_OnClosed" - DataContext="{Binding CheckResponse, Source={StaticResource Locator}}" Loaded="CheckResponseDialog_OnLoaded" ResizeMode="NoResize" ShowInTaskbar="False" @@ -111,7 +110,8 @@ Grid.Row="1" Margin="0,10" VerticalAlignment="Top" - Content="下一步" /> + Content="下一步" + Style="{StaticResource ButtonPrimary}" /> + IsEnabled="{Binding ElementName=RedSensorStepBar, Path=StepIndex, Converter={StaticResource StepButtonStateConverter}}" + Style="{StaticResource ButtonPrimary}" /> + Foreground="Red" + Text="样品数据计算中,请稍后......0s" /> diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 09453b0..bbac218 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -233,7 +233,6 @@ - AudioFileWindow.xaml diff --git a/Correlator/Dialog/CheckResponseDialog.xaml b/Correlator/Dialog/CheckResponseDialog.xaml index 6e916f3..1b216ef 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml +++ b/Correlator/Dialog/CheckResponseDialog.xaml @@ -11,7 +11,6 @@ AllowsTransparency="True" Background="Transparent" Closed="CheckResponseDialog_OnClosed" - DataContext="{Binding CheckResponse, Source={StaticResource Locator}}" Loaded="CheckResponseDialog_OnLoaded" ResizeMode="NoResize" ShowInTaskbar="False" @@ -111,7 +110,8 @@ Grid.Row="1" Margin="0,10" VerticalAlignment="Top" - Content="下一步" /> + Content="下一步" + Style="{StaticResource ButtonPrimary}" /> + IsEnabled="{Binding ElementName=RedSensorStepBar, Path=StepIndex, Converter={StaticResource StepButtonStateConverter}}" + Style="{StaticResource ButtonPrimary}" /> + Foreground="Red" + Text="样品数据计算中,请稍后......0s" /> diff --git a/Correlator/Dialog/LoadingDialog.xaml.cs b/Correlator/Dialog/LoadingDialog.xaml.cs index bebd85e..db1659f 100644 --- a/Correlator/Dialog/LoadingDialog.xaml.cs +++ b/Correlator/Dialog/LoadingDialog.xaml.cs @@ -1,12 +1,37 @@ -using System.Windows; +using System; +using System.Windows; +using System.Windows.Threading; namespace Correlator.Dialog { public partial class LoadingDialog : Window { - public LoadingDialog() + //运行时间Timer + private readonly DispatcherTimer _runningTimer = new DispatcherTimer + { + Interval = TimeSpan.FromSeconds(1) + }; + + //计算时间 + private int _runningSeconds; + + public LoadingDialog(string message) { InitializeComponent(); + _runningTimer.Tick += delegate + { + _runningSeconds++; + Application.Current.Dispatcher.Invoke(delegate + { + MessageTextBlock.Text = message + $"{_runningSeconds}s"; + }); + }; + _runningTimer.Start(); + } + + private void LoadingDialog_OnClosed(object sender, EventArgs e) + { + _runningTimer.Stop(); } } } \ No newline at end of file diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 09453b0..bbac218 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -233,7 +233,6 @@ - AudioFileWindow.xaml diff --git a/Correlator/Dialog/CheckResponseDialog.xaml b/Correlator/Dialog/CheckResponseDialog.xaml index 6e916f3..1b216ef 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml +++ b/Correlator/Dialog/CheckResponseDialog.xaml @@ -11,7 +11,6 @@ AllowsTransparency="True" Background="Transparent" Closed="CheckResponseDialog_OnClosed" - DataContext="{Binding CheckResponse, Source={StaticResource Locator}}" Loaded="CheckResponseDialog_OnLoaded" ResizeMode="NoResize" ShowInTaskbar="False" @@ -111,7 +110,8 @@ Grid.Row="1" Margin="0,10" VerticalAlignment="Top" - Content="下一步" /> + Content="下一步" + Style="{StaticResource ButtonPrimary}" /> + IsEnabled="{Binding ElementName=RedSensorStepBar, Path=StepIndex, Converter={StaticResource StepButtonStateConverter}}" + Style="{StaticResource ButtonPrimary}" /> + Foreground="Red" + Text="样品数据计算中,请稍后......0s" /> diff --git a/Correlator/Dialog/LoadingDialog.xaml.cs b/Correlator/Dialog/LoadingDialog.xaml.cs index bebd85e..db1659f 100644 --- a/Correlator/Dialog/LoadingDialog.xaml.cs +++ b/Correlator/Dialog/LoadingDialog.xaml.cs @@ -1,12 +1,37 @@ -using System.Windows; +using System; +using System.Windows; +using System.Windows.Threading; namespace Correlator.Dialog { public partial class LoadingDialog : Window { - public LoadingDialog() + //运行时间Timer + private readonly DispatcherTimer _runningTimer = new DispatcherTimer + { + Interval = TimeSpan.FromSeconds(1) + }; + + //计算时间 + private int _runningSeconds; + + public LoadingDialog(string message) { InitializeComponent(); + _runningTimer.Tick += delegate + { + _runningSeconds++; + Application.Current.Dispatcher.Invoke(delegate + { + MessageTextBlock.Text = message + $"{_runningSeconds}s"; + }); + }; + _runningTimer.Start(); + } + + private void LoadingDialog_OnClosed(object sender, EventArgs e) + { + _runningTimer.Stop(); } } } \ No newline at end of file diff --git a/Correlator/Fonts/iconfont.ttf b/Correlator/Fonts/iconfont.ttf index c875962..1039796 100644 --- a/Correlator/Fonts/iconfont.ttf +++ b/Correlator/Fonts/iconfont.ttf Binary files differ diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 09453b0..bbac218 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -233,7 +233,6 @@ - AudioFileWindow.xaml diff --git a/Correlator/Dialog/CheckResponseDialog.xaml b/Correlator/Dialog/CheckResponseDialog.xaml index 6e916f3..1b216ef 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml +++ b/Correlator/Dialog/CheckResponseDialog.xaml @@ -11,7 +11,6 @@ AllowsTransparency="True" Background="Transparent" Closed="CheckResponseDialog_OnClosed" - DataContext="{Binding CheckResponse, Source={StaticResource Locator}}" Loaded="CheckResponseDialog_OnLoaded" ResizeMode="NoResize" ShowInTaskbar="False" @@ -111,7 +110,8 @@ Grid.Row="1" Margin="0,10" VerticalAlignment="Top" - Content="下一步" /> + Content="下一步" + Style="{StaticResource ButtonPrimary}" /> + IsEnabled="{Binding ElementName=RedSensorStepBar, Path=StepIndex, Converter={StaticResource StepButtonStateConverter}}" + Style="{StaticResource ButtonPrimary}" /> + Foreground="Red" + Text="样品数据计算中,请稍后......0s" /> diff --git a/Correlator/Dialog/LoadingDialog.xaml.cs b/Correlator/Dialog/LoadingDialog.xaml.cs index bebd85e..db1659f 100644 --- a/Correlator/Dialog/LoadingDialog.xaml.cs +++ b/Correlator/Dialog/LoadingDialog.xaml.cs @@ -1,12 +1,37 @@ -using System.Windows; +using System; +using System.Windows; +using System.Windows.Threading; namespace Correlator.Dialog { public partial class LoadingDialog : Window { - public LoadingDialog() + //运行时间Timer + private readonly DispatcherTimer _runningTimer = new DispatcherTimer + { + Interval = TimeSpan.FromSeconds(1) + }; + + //计算时间 + private int _runningSeconds; + + public LoadingDialog(string message) { InitializeComponent(); + _runningTimer.Tick += delegate + { + _runningSeconds++; + Application.Current.Dispatcher.Invoke(delegate + { + MessageTextBlock.Text = message + $"{_runningSeconds}s"; + }); + }; + _runningTimer.Start(); + } + + private void LoadingDialog_OnClosed(object sender, EventArgs e) + { + _runningTimer.Stop(); } } } \ No newline at end of file diff --git a/Correlator/Fonts/iconfont.ttf b/Correlator/Fonts/iconfont.ttf index c875962..1039796 100644 --- a/Correlator/Fonts/iconfont.ttf +++ b/Correlator/Fonts/iconfont.ttf Binary files differ diff --git a/Correlator/Util/DialogHub.cs b/Correlator/Util/DialogHub.cs index ec6f735..fa0ee21 100644 --- a/Correlator/Util/DialogHub.cs +++ b/Correlator/Util/DialogHub.cs @@ -25,10 +25,9 @@ { Application.Current.Dispatcher.Invoke(delegate { - _loadingDialog = new LoadingDialog + _loadingDialog = new LoadingDialog(message) { - Owner = owner, - MessageTextBlock = { Text = message } + Owner = owner }; _loadingDialog.Show(); }); diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 09453b0..bbac218 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -233,7 +233,6 @@ - AudioFileWindow.xaml diff --git a/Correlator/Dialog/CheckResponseDialog.xaml b/Correlator/Dialog/CheckResponseDialog.xaml index 6e916f3..1b216ef 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml +++ b/Correlator/Dialog/CheckResponseDialog.xaml @@ -11,7 +11,6 @@ AllowsTransparency="True" Background="Transparent" Closed="CheckResponseDialog_OnClosed" - DataContext="{Binding CheckResponse, Source={StaticResource Locator}}" Loaded="CheckResponseDialog_OnLoaded" ResizeMode="NoResize" ShowInTaskbar="False" @@ -111,7 +110,8 @@ Grid.Row="1" Margin="0,10" VerticalAlignment="Top" - Content="下一步" /> + Content="下一步" + Style="{StaticResource ButtonPrimary}" /> + IsEnabled="{Binding ElementName=RedSensorStepBar, Path=StepIndex, Converter={StaticResource StepButtonStateConverter}}" + Style="{StaticResource ButtonPrimary}" /> + Foreground="Red" + Text="样品数据计算中,请稍后......0s" /> diff --git a/Correlator/Dialog/LoadingDialog.xaml.cs b/Correlator/Dialog/LoadingDialog.xaml.cs index bebd85e..db1659f 100644 --- a/Correlator/Dialog/LoadingDialog.xaml.cs +++ b/Correlator/Dialog/LoadingDialog.xaml.cs @@ -1,12 +1,37 @@ -using System.Windows; +using System; +using System.Windows; +using System.Windows.Threading; namespace Correlator.Dialog { public partial class LoadingDialog : Window { - public LoadingDialog() + //运行时间Timer + private readonly DispatcherTimer _runningTimer = new DispatcherTimer + { + Interval = TimeSpan.FromSeconds(1) + }; + + //计算时间 + private int _runningSeconds; + + public LoadingDialog(string message) { InitializeComponent(); + _runningTimer.Tick += delegate + { + _runningSeconds++; + Application.Current.Dispatcher.Invoke(delegate + { + MessageTextBlock.Text = message + $"{_runningSeconds}s"; + }); + }; + _runningTimer.Start(); + } + + private void LoadingDialog_OnClosed(object sender, EventArgs e) + { + _runningTimer.Stop(); } } } \ No newline at end of file diff --git a/Correlator/Fonts/iconfont.ttf b/Correlator/Fonts/iconfont.ttf index c875962..1039796 100644 --- a/Correlator/Fonts/iconfont.ttf +++ b/Correlator/Fonts/iconfont.ttf Binary files differ diff --git a/Correlator/Util/DialogHub.cs b/Correlator/Util/DialogHub.cs index ec6f735..fa0ee21 100644 --- a/Correlator/Util/DialogHub.cs +++ b/Correlator/Util/DialogHub.cs @@ -25,10 +25,9 @@ { Application.Current.Dispatcher.Invoke(delegate { - _loadingDialog = new LoadingDialog + _loadingDialog = new LoadingDialog(message) { - Owner = owner, - MessageTextBlock = { Text = message } + Owner = owner }; _loadingDialog.Show(); }); diff --git a/Correlator/Util/StringUtil.cs b/Correlator/Util/StringUtil.cs index 616aeea..e6bfb33 100644 --- a/Correlator/Util/StringUtil.cs +++ b/Correlator/Util/StringUtil.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Globalization; using System.IO; using System.Text; @@ -33,18 +34,40 @@ builder.Append(DateTime.Now.ToString(CultureInfo.InvariantCulture)).Append("\r\n"); foreach (var d in it.LeftDeviceDataArray) { - builder.Append(d.AppendEndZero()).Append("\r\n"); + builder.Append(d).Append("\r\n"); } builder.Append("===============").Append("\r\n"); - foreach (var d in it.RightDeviceDataArray) + for (var i = 0; i < it.RightDeviceDataArray.Length; i++) { - builder.Append(d.AppendEndZero()).Append("\r\n"); + var d = it.RightDeviceDataArray[i]; + if (i == it.RightDeviceDataArray.Length - 1) + { + builder.Append(d); + } + else + { + builder.Append(d).Append("\r\n"); + } } File.AppendAllText(fileName, builder.ToString()); } + public static List ReadFromFile(this string filePath) + { + var list = new List(); + var streamReader = new StreamReader(filePath); + string line; + while ((line = streamReader.ReadLine()) != null) + { + list.Add(line); + } + + streamReader.Close(); + return list; + } + public static byte Year => byte.Parse(DateTime.Now.ToString("yy")); public static byte Mon => byte.Parse(DateTime.Now.ToString("MM")); diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 09453b0..bbac218 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -233,7 +233,6 @@ - AudioFileWindow.xaml diff --git a/Correlator/Dialog/CheckResponseDialog.xaml b/Correlator/Dialog/CheckResponseDialog.xaml index 6e916f3..1b216ef 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml +++ b/Correlator/Dialog/CheckResponseDialog.xaml @@ -11,7 +11,6 @@ AllowsTransparency="True" Background="Transparent" Closed="CheckResponseDialog_OnClosed" - DataContext="{Binding CheckResponse, Source={StaticResource Locator}}" Loaded="CheckResponseDialog_OnLoaded" ResizeMode="NoResize" ShowInTaskbar="False" @@ -111,7 +110,8 @@ Grid.Row="1" Margin="0,10" VerticalAlignment="Top" - Content="下一步" /> + Content="下一步" + Style="{StaticResource ButtonPrimary}" /> + IsEnabled="{Binding ElementName=RedSensorStepBar, Path=StepIndex, Converter={StaticResource StepButtonStateConverter}}" + Style="{StaticResource ButtonPrimary}" /> + Foreground="Red" + Text="样品数据计算中,请稍后......0s" /> diff --git a/Correlator/Dialog/LoadingDialog.xaml.cs b/Correlator/Dialog/LoadingDialog.xaml.cs index bebd85e..db1659f 100644 --- a/Correlator/Dialog/LoadingDialog.xaml.cs +++ b/Correlator/Dialog/LoadingDialog.xaml.cs @@ -1,12 +1,37 @@ -using System.Windows; +using System; +using System.Windows; +using System.Windows.Threading; namespace Correlator.Dialog { public partial class LoadingDialog : Window { - public LoadingDialog() + //运行时间Timer + private readonly DispatcherTimer _runningTimer = new DispatcherTimer + { + Interval = TimeSpan.FromSeconds(1) + }; + + //计算时间 + private int _runningSeconds; + + public LoadingDialog(string message) { InitializeComponent(); + _runningTimer.Tick += delegate + { + _runningSeconds++; + Application.Current.Dispatcher.Invoke(delegate + { + MessageTextBlock.Text = message + $"{_runningSeconds}s"; + }); + }; + _runningTimer.Start(); + } + + private void LoadingDialog_OnClosed(object sender, EventArgs e) + { + _runningTimer.Stop(); } } } \ No newline at end of file diff --git a/Correlator/Fonts/iconfont.ttf b/Correlator/Fonts/iconfont.ttf index c875962..1039796 100644 --- a/Correlator/Fonts/iconfont.ttf +++ b/Correlator/Fonts/iconfont.ttf Binary files differ diff --git a/Correlator/Util/DialogHub.cs b/Correlator/Util/DialogHub.cs index ec6f735..fa0ee21 100644 --- a/Correlator/Util/DialogHub.cs +++ b/Correlator/Util/DialogHub.cs @@ -25,10 +25,9 @@ { Application.Current.Dispatcher.Invoke(delegate { - _loadingDialog = new LoadingDialog + _loadingDialog = new LoadingDialog(message) { - Owner = owner, - MessageTextBlock = { Text = message } + Owner = owner }; _loadingDialog.Show(); }); diff --git a/Correlator/Util/StringUtil.cs b/Correlator/Util/StringUtil.cs index 616aeea..e6bfb33 100644 --- a/Correlator/Util/StringUtil.cs +++ b/Correlator/Util/StringUtil.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Globalization; using System.IO; using System.Text; @@ -33,18 +34,40 @@ builder.Append(DateTime.Now.ToString(CultureInfo.InvariantCulture)).Append("\r\n"); foreach (var d in it.LeftDeviceDataArray) { - builder.Append(d.AppendEndZero()).Append("\r\n"); + builder.Append(d).Append("\r\n"); } builder.Append("===============").Append("\r\n"); - foreach (var d in it.RightDeviceDataArray) + for (var i = 0; i < it.RightDeviceDataArray.Length; i++) { - builder.Append(d.AppendEndZero()).Append("\r\n"); + var d = it.RightDeviceDataArray[i]; + if (i == it.RightDeviceDataArray.Length - 1) + { + builder.Append(d); + } + else + { + builder.Append(d).Append("\r\n"); + } } File.AppendAllText(fileName, builder.ToString()); } + public static List ReadFromFile(this string filePath) + { + var list = new List(); + var streamReader = new StreamReader(filePath); + string line; + while ((line = streamReader.ReadLine()) != null) + { + list.Add(line); + } + + streamReader.Close(); + return list; + } + public static byte Year => byte.Parse(DateTime.Now.ToString("yy")); public static byte Mon => byte.Parse(DateTime.Now.ToString("MM")); diff --git a/Correlator/View/HomePageProWindow.xaml b/Correlator/View/HomePageProWindow.xaml index 834aa58..86d21d0 100644 --- a/Correlator/View/HomePageProWindow.xaml +++ b/Correlator/View/HomePageProWindow.xaml @@ -301,6 +301,59 @@ Text="声速设置" /> + + - AudioFileWindow.xaml diff --git a/Correlator/Dialog/CheckResponseDialog.xaml b/Correlator/Dialog/CheckResponseDialog.xaml index 6e916f3..1b216ef 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml +++ b/Correlator/Dialog/CheckResponseDialog.xaml @@ -11,7 +11,6 @@ AllowsTransparency="True" Background="Transparent" Closed="CheckResponseDialog_OnClosed" - DataContext="{Binding CheckResponse, Source={StaticResource Locator}}" Loaded="CheckResponseDialog_OnLoaded" ResizeMode="NoResize" ShowInTaskbar="False" @@ -111,7 +110,8 @@ Grid.Row="1" Margin="0,10" VerticalAlignment="Top" - Content="下一步" /> + Content="下一步" + Style="{StaticResource ButtonPrimary}" /> + IsEnabled="{Binding ElementName=RedSensorStepBar, Path=StepIndex, Converter={StaticResource StepButtonStateConverter}}" + Style="{StaticResource ButtonPrimary}" /> + Foreground="Red" + Text="样品数据计算中,请稍后......0s" /> diff --git a/Correlator/Dialog/LoadingDialog.xaml.cs b/Correlator/Dialog/LoadingDialog.xaml.cs index bebd85e..db1659f 100644 --- a/Correlator/Dialog/LoadingDialog.xaml.cs +++ b/Correlator/Dialog/LoadingDialog.xaml.cs @@ -1,12 +1,37 @@ -using System.Windows; +using System; +using System.Windows; +using System.Windows.Threading; namespace Correlator.Dialog { public partial class LoadingDialog : Window { - public LoadingDialog() + //运行时间Timer + private readonly DispatcherTimer _runningTimer = new DispatcherTimer + { + Interval = TimeSpan.FromSeconds(1) + }; + + //计算时间 + private int _runningSeconds; + + public LoadingDialog(string message) { InitializeComponent(); + _runningTimer.Tick += delegate + { + _runningSeconds++; + Application.Current.Dispatcher.Invoke(delegate + { + MessageTextBlock.Text = message + $"{_runningSeconds}s"; + }); + }; + _runningTimer.Start(); + } + + private void LoadingDialog_OnClosed(object sender, EventArgs e) + { + _runningTimer.Stop(); } } } \ No newline at end of file diff --git a/Correlator/Fonts/iconfont.ttf b/Correlator/Fonts/iconfont.ttf index c875962..1039796 100644 --- a/Correlator/Fonts/iconfont.ttf +++ b/Correlator/Fonts/iconfont.ttf Binary files differ diff --git a/Correlator/Util/DialogHub.cs b/Correlator/Util/DialogHub.cs index ec6f735..fa0ee21 100644 --- a/Correlator/Util/DialogHub.cs +++ b/Correlator/Util/DialogHub.cs @@ -25,10 +25,9 @@ { Application.Current.Dispatcher.Invoke(delegate { - _loadingDialog = new LoadingDialog + _loadingDialog = new LoadingDialog(message) { - Owner = owner, - MessageTextBlock = { Text = message } + Owner = owner }; _loadingDialog.Show(); }); diff --git a/Correlator/Util/StringUtil.cs b/Correlator/Util/StringUtil.cs index 616aeea..e6bfb33 100644 --- a/Correlator/Util/StringUtil.cs +++ b/Correlator/Util/StringUtil.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Globalization; using System.IO; using System.Text; @@ -33,18 +34,40 @@ builder.Append(DateTime.Now.ToString(CultureInfo.InvariantCulture)).Append("\r\n"); foreach (var d in it.LeftDeviceDataArray) { - builder.Append(d.AppendEndZero()).Append("\r\n"); + builder.Append(d).Append("\r\n"); } builder.Append("===============").Append("\r\n"); - foreach (var d in it.RightDeviceDataArray) + for (var i = 0; i < it.RightDeviceDataArray.Length; i++) { - builder.Append(d.AppendEndZero()).Append("\r\n"); + var d = it.RightDeviceDataArray[i]; + if (i == it.RightDeviceDataArray.Length - 1) + { + builder.Append(d); + } + else + { + builder.Append(d).Append("\r\n"); + } } File.AppendAllText(fileName, builder.ToString()); } + public static List ReadFromFile(this string filePath) + { + var list = new List(); + var streamReader = new StreamReader(filePath); + string line; + while ((line = streamReader.ReadLine()) != null) + { + list.Add(line); + } + + streamReader.Close(); + return list; + } + public static byte Year => byte.Parse(DateTime.Now.ToString("yy")); public static byte Mon => byte.Parse(DateTime.Now.ToString("MM")); diff --git a/Correlator/View/HomePageProWindow.xaml b/Correlator/View/HomePageProWindow.xaml index 834aa58..86d21d0 100644 --- a/Correlator/View/HomePageProWindow.xaml +++ b/Correlator/View/HomePageProWindow.xaml @@ -301,6 +301,59 @@ Text="声速设置" /> + + - AudioFileWindow.xaml diff --git a/Correlator/Dialog/CheckResponseDialog.xaml b/Correlator/Dialog/CheckResponseDialog.xaml index 6e916f3..1b216ef 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml +++ b/Correlator/Dialog/CheckResponseDialog.xaml @@ -11,7 +11,6 @@ AllowsTransparency="True" Background="Transparent" Closed="CheckResponseDialog_OnClosed" - DataContext="{Binding CheckResponse, Source={StaticResource Locator}}" Loaded="CheckResponseDialog_OnLoaded" ResizeMode="NoResize" ShowInTaskbar="False" @@ -111,7 +110,8 @@ Grid.Row="1" Margin="0,10" VerticalAlignment="Top" - Content="下一步" /> + Content="下一步" + Style="{StaticResource ButtonPrimary}" /> + IsEnabled="{Binding ElementName=RedSensorStepBar, Path=StepIndex, Converter={StaticResource StepButtonStateConverter}}" + Style="{StaticResource ButtonPrimary}" /> + Foreground="Red" + Text="样品数据计算中,请稍后......0s" /> diff --git a/Correlator/Dialog/LoadingDialog.xaml.cs b/Correlator/Dialog/LoadingDialog.xaml.cs index bebd85e..db1659f 100644 --- a/Correlator/Dialog/LoadingDialog.xaml.cs +++ b/Correlator/Dialog/LoadingDialog.xaml.cs @@ -1,12 +1,37 @@ -using System.Windows; +using System; +using System.Windows; +using System.Windows.Threading; namespace Correlator.Dialog { public partial class LoadingDialog : Window { - public LoadingDialog() + //运行时间Timer + private readonly DispatcherTimer _runningTimer = new DispatcherTimer + { + Interval = TimeSpan.FromSeconds(1) + }; + + //计算时间 + private int _runningSeconds; + + public LoadingDialog(string message) { InitializeComponent(); + _runningTimer.Tick += delegate + { + _runningSeconds++; + Application.Current.Dispatcher.Invoke(delegate + { + MessageTextBlock.Text = message + $"{_runningSeconds}s"; + }); + }; + _runningTimer.Start(); + } + + private void LoadingDialog_OnClosed(object sender, EventArgs e) + { + _runningTimer.Stop(); } } } \ No newline at end of file diff --git a/Correlator/Fonts/iconfont.ttf b/Correlator/Fonts/iconfont.ttf index c875962..1039796 100644 --- a/Correlator/Fonts/iconfont.ttf +++ b/Correlator/Fonts/iconfont.ttf Binary files differ diff --git a/Correlator/Util/DialogHub.cs b/Correlator/Util/DialogHub.cs index ec6f735..fa0ee21 100644 --- a/Correlator/Util/DialogHub.cs +++ b/Correlator/Util/DialogHub.cs @@ -25,10 +25,9 @@ { Application.Current.Dispatcher.Invoke(delegate { - _loadingDialog = new LoadingDialog + _loadingDialog = new LoadingDialog(message) { - Owner = owner, - MessageTextBlock = { Text = message } + Owner = owner }; _loadingDialog.Show(); }); diff --git a/Correlator/Util/StringUtil.cs b/Correlator/Util/StringUtil.cs index 616aeea..e6bfb33 100644 --- a/Correlator/Util/StringUtil.cs +++ b/Correlator/Util/StringUtil.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Globalization; using System.IO; using System.Text; @@ -33,18 +34,40 @@ builder.Append(DateTime.Now.ToString(CultureInfo.InvariantCulture)).Append("\r\n"); foreach (var d in it.LeftDeviceDataArray) { - builder.Append(d.AppendEndZero()).Append("\r\n"); + builder.Append(d).Append("\r\n"); } builder.Append("===============").Append("\r\n"); - foreach (var d in it.RightDeviceDataArray) + for (var i = 0; i < it.RightDeviceDataArray.Length; i++) { - builder.Append(d.AppendEndZero()).Append("\r\n"); + var d = it.RightDeviceDataArray[i]; + if (i == it.RightDeviceDataArray.Length - 1) + { + builder.Append(d); + } + else + { + builder.Append(d).Append("\r\n"); + } } File.AppendAllText(fileName, builder.ToString()); } + public static List ReadFromFile(this string filePath) + { + var list = new List(); + var streamReader = new StreamReader(filePath); + string line; + while ((line = streamReader.ReadLine()) != null) + { + list.Add(line); + } + + streamReader.Close(); + return list; + } + public static byte Year => byte.Parse(DateTime.Now.ToString("yy")); public static byte Mon => byte.Parse(DateTime.Now.ToString("MM")); diff --git a/Correlator/View/HomePageProWindow.xaml b/Correlator/View/HomePageProWindow.xaml index 834aa58..86d21d0 100644 --- a/Correlator/View/HomePageProWindow.xaml +++ b/Correlator/View/HomePageProWindow.xaml @@ -301,6 +301,59 @@ Text="声速设置" /> + + WindowLoadedCommand { set; get; } public RelayCommand PipeItemSelectedCommand { set; get; } + public RelayCommand SoundSettingsCommand { private set; get; } + public RelayCommand ImportDataCommand { private set; get; } public RelayCommand SaveAudioCommand { private set; get; } public RelayCommand ResetParamCommand { private set; get; } public RelayCommand SnapShotCommand { private set; get; } @@ -490,8 +493,9 @@ }); //计算测试数据 - Messenger.Default.Register(this, MessengerToken.HomePageDeviceData, - StartCalculateData); + Messenger.Default.Register( + this, MessengerToken.HomePageDeviceData, StartCalculateData + ); //水听器 Messenger.Default.Register(this, MessengerToken.ShowCheckResponseDialog, s => @@ -502,8 +506,12 @@ }); } - private async void StartCalculateData(CorrelatorDataModel it) + private void StartCalculateData(CorrelatorDataModel it) { + DialogHub.Get.ShowLoadingDialog(_homePageWindow, "样品数据计算中,请稍后..."); + //开始计算就不收集收据了 + FlowStatus.CanCollectData = false; + //开始计算停止收集指令 if (!FlowStatus.IsHydrophone) { @@ -525,53 +533,71 @@ var pipeIndex = configModel.Date.Equals(today) ? configModel.Pipe : 1; _locateDataDir = Constant.GetLocateDataDir(pipeIndex); _locateTimes = configModel.LocateTimes; + //插入新纪录 + configModel.Pipe++; + configModel.LocateTimes++; + manager.Insert(configModel); + } - //计算 - try + //计算 + //异步计算数据 + var backgroundScheduler = TaskScheduler.Default; + var uiScheduler = TaskScheduler.Current; + Task.Factory + .StartNew(delegate { CalculateData(it); }, backgroundScheduler) + .ContinueWith(delegate { - DialogHub.Get.ShowLoadingDialog(_homePageWindow, "样品数据计算中,请稍后..."); - //开始计算就不收集收据了 - FlowStatus.CanCollectData = false; - - //异步计算数据 - var array = await GetCalculateResult(it); - if (array == null) return; - - //数据绑定 - var snr = Convert.ToDouble(array[0].ToString()); //信噪比 - Snr = snr.ToString("0.0") + ":1"; - RedTransmitterDistance = Convert.ToDouble(array[1].ToString()); //距离A - BlueTransmitterDistance = Convert.ToDouble(array[2].ToString()); //距离B - - //将数据发送到HomePageWindow.xaml.cs页面进行渲染 - Messenger.Default.Send(array, MessengerToken.RenderOscillogram); - - var maxFreLowOut = Convert.ToInt32(array[6].ToString()); //低频 - var maxFreHighOut = Convert.ToInt32(array[7].ToString()); //高频 - - FilterValue = maxFreLowOut + " ~ " + maxFreHighOut + "Hz"; + //计算结束保存定位数据 + var fileName = _locateDataDir + "\\测试数据." + _locateTimes + "." + + DateTime.Now.ToString("HHmmss") + ".txt"; + StringUtil.SaveLocateData(it, fileName); + "HomePageViewModel".WriteLog("定位数据路径:" + fileName); + }, backgroundScheduler) + .ContinueWith(delegate + { + //计算结束保存截图,需要等待Task出结果并且渲染完成,才能保存截图 + _snapShotPath = _locateDataDir + "\\快照." + _locateTimes + "." + + DateTime.Now.ToString("HHmmss") + ".png"; + _snapShotTimer.Start(); _runningTimer.Stop(); StartButtonEnabled = true; FlowStatus.RedSensorIsEnable = false; FlowStatus.BlueSensorIsEnable = false; DialogHub.Get.DismissLoadingDialog(); + }, uiScheduler, TaskContinuationOptions.OnlyOnRanToCompletion); + } - //同步保存截图,需要等待Task出结果并且渲染完成,才能保存截图 - _snapShotPath = _locateDataDir + "\\快照." + _locateTimes + "." + DateTime.Now.ToString("HHmmss") + - ".png"; - _snapShotTimer.Start(); + /// + /// 算法计算 + /// + /// + private void CalculateData(CorrelatorDataModel dataModel) + { + var array = _correlator.locating(11, + (MWNumericArray)dataModel.LeftDeviceDataArray, (MWNumericArray)dataModel.RightDeviceDataArray, + Constant.SamplingRate, + 150, 1130, + 0, 0, + 0, 0, + "铸铁", + 300, 300, + 1, -1, + -1, -1, + 10, 300); - //插入新纪录 - configModel.Pipe++; - configModel.LocateTimes++; - manager.Insert(configModel); - } - catch (Exception e) - { - "HomePageViewModel".WriteLog(e.Message); - } - } + //数据绑定 + var snr = Convert.ToDouble(array[0].ToString()); //信噪比 + Snr = snr.ToString("0.0") + ":1"; + RedTransmitterDistance = Convert.ToDouble(array[1].ToString()); //距离A + BlueTransmitterDistance = Convert.ToDouble(array[2].ToString()); //距离B + + var maxFreLowOut = Convert.ToInt32(array[6].ToString()); //低频 + var maxFreHighOut = Convert.ToInt32(array[7].ToString()); //高频 + + FilterValue = maxFreLowOut + " ~ " + maxFreHighOut + "Hz"; + + Messenger.Default.Send(array, MessengerToken.RenderOscillogram); } /// @@ -674,6 +700,46 @@ speedDialog.ShowDialog(); }); + ImportDataCommand = new RelayCommand(delegate + { + var fileDialog = new OpenFileDialog + { + // 设置默认格式 + DefaultExt = ".txt", + Filter = "发射机数据文件(*.txt)|*.txt" + }; + var result = fileDialog.ShowDialog(); + if (result == true) + { + var dataModel = new CorrelatorDataModel(); + var dataFromFile = fileDialog.FileName.ReadFromFile(); + var index = dataFromFile.IndexOf("==============="); + + var leftCacheData = new double[7500 * 60]; + for (var i = 1; i < index; i++) + { + leftCacheData[i - 1] = Convert.ToDouble(dataFromFile[i]); + } + + dataModel.DevCode = DevCode.Dev1; + dataModel.LeftReceiveDataTime = DateTime.Now; + dataModel.LeftDeviceDataArray = leftCacheData; + + var rightCacheData = new double[7500 * 60]; + //450001 - 900000 + for (var i = index + 1; i < dataFromFile.Count; i++) + { + rightCacheData[i - 450002] = Convert.ToDouble(dataFromFile[i]); + } + + dataModel.DevCode = DevCode.Dev2; + dataModel.RightReceiveDataTime = DateTime.Now; + dataModel.RightDeviceDataArray = rightCacheData; + + Messenger.Default.Send(dataModel, MessengerToken.HomePageDeviceData); + } + }); + SaveAudioCommand = new RelayCommand(delegate { if (FlowStatus.CorrelatorData != null) @@ -835,35 +901,5 @@ FlowStatus.CanCollectData = false; } - - /// - /// Matlab计算过程 - /// - /// 收集到的传感器数据 - /// 计算结果 - private Task GetCalculateResult(CorrelatorDataModel dataModel) - { - var task = Task.Run(delegate - { - //异步保存定位数据 - var fileName = _locateDataDir + "\\测试数据." + _locateTimes + "." + DateTime.Now.ToString("HHmmss") + ".txt"; - StringUtil.SaveLocateData(dataModel, fileName); - "HomePageViewModel".WriteLog("定位数据路径:" + fileName); - - var array = _correlator.locating(11, - (MWNumericArray)dataModel.LeftDeviceDataArray, (MWNumericArray)dataModel.RightDeviceDataArray, - Constant.SamplingRate, - int.Parse(_pipeLength), int.Parse(_soundSpeed), - 0, 0, - 0, 0, - _pipeName, - int.Parse(_pipeDiameter), int.Parse(_pipeDiameter), - 1, -1, - -1, -1, - int.Parse(_lowFrequency), int.Parse(_highFrequency)); - return array; - }); - return task; - } } } \ No newline at end of file diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 09453b0..bbac218 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -233,7 +233,6 @@ - AudioFileWindow.xaml diff --git a/Correlator/Dialog/CheckResponseDialog.xaml b/Correlator/Dialog/CheckResponseDialog.xaml index 6e916f3..1b216ef 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml +++ b/Correlator/Dialog/CheckResponseDialog.xaml @@ -11,7 +11,6 @@ AllowsTransparency="True" Background="Transparent" Closed="CheckResponseDialog_OnClosed" - DataContext="{Binding CheckResponse, Source={StaticResource Locator}}" Loaded="CheckResponseDialog_OnLoaded" ResizeMode="NoResize" ShowInTaskbar="False" @@ -111,7 +110,8 @@ Grid.Row="1" Margin="0,10" VerticalAlignment="Top" - Content="下一步" /> + Content="下一步" + Style="{StaticResource ButtonPrimary}" /> + IsEnabled="{Binding ElementName=RedSensorStepBar, Path=StepIndex, Converter={StaticResource StepButtonStateConverter}}" + Style="{StaticResource ButtonPrimary}" /> + Foreground="Red" + Text="样品数据计算中,请稍后......0s" /> diff --git a/Correlator/Dialog/LoadingDialog.xaml.cs b/Correlator/Dialog/LoadingDialog.xaml.cs index bebd85e..db1659f 100644 --- a/Correlator/Dialog/LoadingDialog.xaml.cs +++ b/Correlator/Dialog/LoadingDialog.xaml.cs @@ -1,12 +1,37 @@ -using System.Windows; +using System; +using System.Windows; +using System.Windows.Threading; namespace Correlator.Dialog { public partial class LoadingDialog : Window { - public LoadingDialog() + //运行时间Timer + private readonly DispatcherTimer _runningTimer = new DispatcherTimer + { + Interval = TimeSpan.FromSeconds(1) + }; + + //计算时间 + private int _runningSeconds; + + public LoadingDialog(string message) { InitializeComponent(); + _runningTimer.Tick += delegate + { + _runningSeconds++; + Application.Current.Dispatcher.Invoke(delegate + { + MessageTextBlock.Text = message + $"{_runningSeconds}s"; + }); + }; + _runningTimer.Start(); + } + + private void LoadingDialog_OnClosed(object sender, EventArgs e) + { + _runningTimer.Stop(); } } } \ No newline at end of file diff --git a/Correlator/Fonts/iconfont.ttf b/Correlator/Fonts/iconfont.ttf index c875962..1039796 100644 --- a/Correlator/Fonts/iconfont.ttf +++ b/Correlator/Fonts/iconfont.ttf Binary files differ diff --git a/Correlator/Util/DialogHub.cs b/Correlator/Util/DialogHub.cs index ec6f735..fa0ee21 100644 --- a/Correlator/Util/DialogHub.cs +++ b/Correlator/Util/DialogHub.cs @@ -25,10 +25,9 @@ { Application.Current.Dispatcher.Invoke(delegate { - _loadingDialog = new LoadingDialog + _loadingDialog = new LoadingDialog(message) { - Owner = owner, - MessageTextBlock = { Text = message } + Owner = owner }; _loadingDialog.Show(); }); diff --git a/Correlator/Util/StringUtil.cs b/Correlator/Util/StringUtil.cs index 616aeea..e6bfb33 100644 --- a/Correlator/Util/StringUtil.cs +++ b/Correlator/Util/StringUtil.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Globalization; using System.IO; using System.Text; @@ -33,18 +34,40 @@ builder.Append(DateTime.Now.ToString(CultureInfo.InvariantCulture)).Append("\r\n"); foreach (var d in it.LeftDeviceDataArray) { - builder.Append(d.AppendEndZero()).Append("\r\n"); + builder.Append(d).Append("\r\n"); } builder.Append("===============").Append("\r\n"); - foreach (var d in it.RightDeviceDataArray) + for (var i = 0; i < it.RightDeviceDataArray.Length; i++) { - builder.Append(d.AppendEndZero()).Append("\r\n"); + var d = it.RightDeviceDataArray[i]; + if (i == it.RightDeviceDataArray.Length - 1) + { + builder.Append(d); + } + else + { + builder.Append(d).Append("\r\n"); + } } File.AppendAllText(fileName, builder.ToString()); } + public static List ReadFromFile(this string filePath) + { + var list = new List(); + var streamReader = new StreamReader(filePath); + string line; + while ((line = streamReader.ReadLine()) != null) + { + list.Add(line); + } + + streamReader.Close(); + return list; + } + public static byte Year => byte.Parse(DateTime.Now.ToString("yy")); public static byte Mon => byte.Parse(DateTime.Now.ToString("MM")); diff --git a/Correlator/View/HomePageProWindow.xaml b/Correlator/View/HomePageProWindow.xaml index 834aa58..86d21d0 100644 --- a/Correlator/View/HomePageProWindow.xaml +++ b/Correlator/View/HomePageProWindow.xaml @@ -301,6 +301,59 @@ Text="声速设置" /> + + WindowLoadedCommand { set; get; } public RelayCommand PipeItemSelectedCommand { set; get; } + public RelayCommand SoundSettingsCommand { private set; get; } + public RelayCommand ImportDataCommand { private set; get; } public RelayCommand SaveAudioCommand { private set; get; } public RelayCommand ResetParamCommand { private set; get; } public RelayCommand SnapShotCommand { private set; get; } @@ -490,8 +493,9 @@ }); //计算测试数据 - Messenger.Default.Register(this, MessengerToken.HomePageDeviceData, - StartCalculateData); + Messenger.Default.Register( + this, MessengerToken.HomePageDeviceData, StartCalculateData + ); //水听器 Messenger.Default.Register(this, MessengerToken.ShowCheckResponseDialog, s => @@ -502,8 +506,12 @@ }); } - private async void StartCalculateData(CorrelatorDataModel it) + private void StartCalculateData(CorrelatorDataModel it) { + DialogHub.Get.ShowLoadingDialog(_homePageWindow, "样品数据计算中,请稍后..."); + //开始计算就不收集收据了 + FlowStatus.CanCollectData = false; + //开始计算停止收集指令 if (!FlowStatus.IsHydrophone) { @@ -525,53 +533,71 @@ var pipeIndex = configModel.Date.Equals(today) ? configModel.Pipe : 1; _locateDataDir = Constant.GetLocateDataDir(pipeIndex); _locateTimes = configModel.LocateTimes; + //插入新纪录 + configModel.Pipe++; + configModel.LocateTimes++; + manager.Insert(configModel); + } - //计算 - try + //计算 + //异步计算数据 + var backgroundScheduler = TaskScheduler.Default; + var uiScheduler = TaskScheduler.Current; + Task.Factory + .StartNew(delegate { CalculateData(it); }, backgroundScheduler) + .ContinueWith(delegate { - DialogHub.Get.ShowLoadingDialog(_homePageWindow, "样品数据计算中,请稍后..."); - //开始计算就不收集收据了 - FlowStatus.CanCollectData = false; - - //异步计算数据 - var array = await GetCalculateResult(it); - if (array == null) return; - - //数据绑定 - var snr = Convert.ToDouble(array[0].ToString()); //信噪比 - Snr = snr.ToString("0.0") + ":1"; - RedTransmitterDistance = Convert.ToDouble(array[1].ToString()); //距离A - BlueTransmitterDistance = Convert.ToDouble(array[2].ToString()); //距离B - - //将数据发送到HomePageWindow.xaml.cs页面进行渲染 - Messenger.Default.Send(array, MessengerToken.RenderOscillogram); - - var maxFreLowOut = Convert.ToInt32(array[6].ToString()); //低频 - var maxFreHighOut = Convert.ToInt32(array[7].ToString()); //高频 - - FilterValue = maxFreLowOut + " ~ " + maxFreHighOut + "Hz"; + //计算结束保存定位数据 + var fileName = _locateDataDir + "\\测试数据." + _locateTimes + "." + + DateTime.Now.ToString("HHmmss") + ".txt"; + StringUtil.SaveLocateData(it, fileName); + "HomePageViewModel".WriteLog("定位数据路径:" + fileName); + }, backgroundScheduler) + .ContinueWith(delegate + { + //计算结束保存截图,需要等待Task出结果并且渲染完成,才能保存截图 + _snapShotPath = _locateDataDir + "\\快照." + _locateTimes + "." + + DateTime.Now.ToString("HHmmss") + ".png"; + _snapShotTimer.Start(); _runningTimer.Stop(); StartButtonEnabled = true; FlowStatus.RedSensorIsEnable = false; FlowStatus.BlueSensorIsEnable = false; DialogHub.Get.DismissLoadingDialog(); + }, uiScheduler, TaskContinuationOptions.OnlyOnRanToCompletion); + } - //同步保存截图,需要等待Task出结果并且渲染完成,才能保存截图 - _snapShotPath = _locateDataDir + "\\快照." + _locateTimes + "." + DateTime.Now.ToString("HHmmss") + - ".png"; - _snapShotTimer.Start(); + /// + /// 算法计算 + /// + /// + private void CalculateData(CorrelatorDataModel dataModel) + { + var array = _correlator.locating(11, + (MWNumericArray)dataModel.LeftDeviceDataArray, (MWNumericArray)dataModel.RightDeviceDataArray, + Constant.SamplingRate, + 150, 1130, + 0, 0, + 0, 0, + "铸铁", + 300, 300, + 1, -1, + -1, -1, + 10, 300); - //插入新纪录 - configModel.Pipe++; - configModel.LocateTimes++; - manager.Insert(configModel); - } - catch (Exception e) - { - "HomePageViewModel".WriteLog(e.Message); - } - } + //数据绑定 + var snr = Convert.ToDouble(array[0].ToString()); //信噪比 + Snr = snr.ToString("0.0") + ":1"; + RedTransmitterDistance = Convert.ToDouble(array[1].ToString()); //距离A + BlueTransmitterDistance = Convert.ToDouble(array[2].ToString()); //距离B + + var maxFreLowOut = Convert.ToInt32(array[6].ToString()); //低频 + var maxFreHighOut = Convert.ToInt32(array[7].ToString()); //高频 + + FilterValue = maxFreLowOut + " ~ " + maxFreHighOut + "Hz"; + + Messenger.Default.Send(array, MessengerToken.RenderOscillogram); } /// @@ -674,6 +700,46 @@ speedDialog.ShowDialog(); }); + ImportDataCommand = new RelayCommand(delegate + { + var fileDialog = new OpenFileDialog + { + // 设置默认格式 + DefaultExt = ".txt", + Filter = "发射机数据文件(*.txt)|*.txt" + }; + var result = fileDialog.ShowDialog(); + if (result == true) + { + var dataModel = new CorrelatorDataModel(); + var dataFromFile = fileDialog.FileName.ReadFromFile(); + var index = dataFromFile.IndexOf("==============="); + + var leftCacheData = new double[7500 * 60]; + for (var i = 1; i < index; i++) + { + leftCacheData[i - 1] = Convert.ToDouble(dataFromFile[i]); + } + + dataModel.DevCode = DevCode.Dev1; + dataModel.LeftReceiveDataTime = DateTime.Now; + dataModel.LeftDeviceDataArray = leftCacheData; + + var rightCacheData = new double[7500 * 60]; + //450001 - 900000 + for (var i = index + 1; i < dataFromFile.Count; i++) + { + rightCacheData[i - 450002] = Convert.ToDouble(dataFromFile[i]); + } + + dataModel.DevCode = DevCode.Dev2; + dataModel.RightReceiveDataTime = DateTime.Now; + dataModel.RightDeviceDataArray = rightCacheData; + + Messenger.Default.Send(dataModel, MessengerToken.HomePageDeviceData); + } + }); + SaveAudioCommand = new RelayCommand(delegate { if (FlowStatus.CorrelatorData != null) @@ -835,35 +901,5 @@ FlowStatus.CanCollectData = false; } - - /// - /// Matlab计算过程 - /// - /// 收集到的传感器数据 - /// 计算结果 - private Task GetCalculateResult(CorrelatorDataModel dataModel) - { - var task = Task.Run(delegate - { - //异步保存定位数据 - var fileName = _locateDataDir + "\\测试数据." + _locateTimes + "." + DateTime.Now.ToString("HHmmss") + ".txt"; - StringUtil.SaveLocateData(dataModel, fileName); - "HomePageViewModel".WriteLog("定位数据路径:" + fileName); - - var array = _correlator.locating(11, - (MWNumericArray)dataModel.LeftDeviceDataArray, (MWNumericArray)dataModel.RightDeviceDataArray, - Constant.SamplingRate, - int.Parse(_pipeLength), int.Parse(_soundSpeed), - 0, 0, - 0, 0, - _pipeName, - int.Parse(_pipeDiameter), int.Parse(_pipeDiameter), - 1, -1, - -1, -1, - int.Parse(_lowFrequency), int.Parse(_highFrequency)); - return array; - }); - return task; - } } } \ No newline at end of file diff --git a/Correlator/ViewModel/ViewModelLocator.cs b/Correlator/ViewModel/ViewModelLocator.cs index 60ad9ed..0171da5 100644 --- a/Correlator/ViewModel/ViewModelLocator.cs +++ b/Correlator/ViewModel/ViewModelLocator.cs @@ -48,7 +48,6 @@ SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); - SimpleIoc.Default.Register(); #endregion } @@ -60,7 +59,6 @@ public SoundSpeedViewModel SoundSpeed => ServiceLocator.Current.GetInstance(); public AddSoundSpeedViewModel AddSoundSpeed => ServiceLocator.Current.GetInstance(); public EditSoundSpeedViewModel EditSoundSpeed => ServiceLocator.Current.GetInstance(); - public CheckResponseViewModel CheckResponse => ServiceLocator.Current.GetInstance(); public static void Cleanup() {