diff --git a/Correlator/ViewModel/HomePageProViewModel.cs b/Correlator/ViewModel/HomePageProViewModel.cs index 421f6c8..77c5762 100644 --- a/Correlator/ViewModel/HomePageProViewModel.cs +++ b/Correlator/ViewModel/HomePageProViewModel.cs @@ -556,7 +556,7 @@ int.Parse(_pipeLength), int.Parse(_soundSpeed), 0, 0, 0, 0, - "铸铁", + _pipeName, int.Parse(_pipeDiameter), int.Parse(_pipeDiameter), 1, -1, -1, -1, @@ -712,62 +712,65 @@ ImportDataCommand = new RelayCommand(delegate { - var fileDialog = new OpenFileDialog + if (CheckParamLegitimacy()) { - // 设置默认格式 - 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++) + var fileDialog = new OpenFileDialog { - try - { - leftCacheData[i - 1] = Convert.ToDouble(dataFromFile[i]); - } - catch (FormatException e) - { - Console.WriteLine(e); - Debug.WriteLine($"HomePageProViewModel => {dataFromFile[i]}"); - throw; - } - } - - 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++) + // 设置默认格式 + DefaultExt = ".txt", + Filter = "发射机数据文件(*.txt)|*.txt" + }; + var result = fileDialog.ShowDialog(); + if (result == true) { - try + 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++) { - rightCacheData[i - 450002] = Convert.ToDouble(dataFromFile[i]); + try + { + leftCacheData[i - 1] = Convert.ToDouble(dataFromFile[i]); + } + catch (FormatException e) + { + Console.WriteLine(e); + Debug.WriteLine($"HomePageProViewModel => {dataFromFile[i]}"); + throw; + } } - catch (FormatException e) + + 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++) { - Console.WriteLine(e); - Debug.WriteLine($"HomePageProViewModel => {dataFromFile[i]}"); - throw; + try + { + rightCacheData[i - 450002] = Convert.ToDouble(dataFromFile[i]); + } + catch (FormatException e) + { + Console.WriteLine(e); + Debug.WriteLine($"HomePageProViewModel => {dataFromFile[i]}"); + throw; + } } + + dataModel.DevCode = DevCode.Dev2; + dataModel.RightReceiveDataTime = DateTime.Now; + dataModel.RightDeviceDataArray = rightCacheData; + + //赋值给缓存,比用消息传递更直接 + FlowStatus.CorrelatorData = dataModel; + + Messenger.Default.Send("", MessengerToken.HomePageDeviceData); } - - dataModel.DevCode = DevCode.Dev2; - dataModel.RightReceiveDataTime = DateTime.Now; - dataModel.RightDeviceDataArray = rightCacheData; - - //赋值给缓存,比用消息传递更直接 - FlowStatus.CorrelatorData = dataModel; - - Messenger.Default.Send("", MessengerToken.HomePageDeviceData); } }); @@ -814,80 +817,28 @@ return; } - if (string.IsNullOrEmpty(_pipeName)) + if (CheckParamLegitimacy()) { - MessageBox.Show("请选择管道材料", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } + _isResetParam = false; + StartButtonEnabled = false; - if (string.IsNullOrEmpty(_pipeDiameter)) - { - MessageBox.Show("请输入管道直径", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } + //每次计算之前都需要判断是否已经完成之前的计算,然后清空上一次的计算数据 + ResetParam(); - if (string.IsNullOrEmpty(_pipeLength)) - { - MessageBox.Show("请输入管道长度", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - if (string.IsNullOrEmpty(_lowFrequency) || string.IsNullOrEmpty(_highFrequency)) - { - MessageBox.Show("请输入完整的干扰频段", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - if (!(Regex.IsMatch(_lowFrequency, "^([1-9][0-9]*)$") && - Regex.IsMatch(_highFrequency, "^([1-9][0-9]*)$"))) - { - MessageBox.Show("输入格式错误,请重新输入", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - var low = Convert.ToInt32(_lowFrequency); - var high = Convert.ToInt32(_highFrequency); - - if (FlowStatus.IsHydrophone) - { - if (low < 10 || low > 300 || high < 10 || high > 300 || low >= high) + FlowStatus.CanCollectData = true; + //开始数据采集 + if (FlowStatus.IsHydrophone) { - MessageBox.Show("频段范围10 ~ 300Hz,请重新输入", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; + CommandSender.SendHydrophoneWakeUpCmd(SerialPortManager.Get.Sp); } - } - else - { - if (low < 100 || low > 3000 || high < 100 || high > 3000 || low >= high) + else { - MessageBox.Show("频段范围100 ~ 3000Hz,请重新输入", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; + _accelerometerCommandTimer.Start(); } + + //记录计算时间 + _runningTimer.Start(); } - - _isResetParam = false; - StartButtonEnabled = false; - - //声速 - var soundVelocity = _soundSpeedDataService.GetSoundVelocity(_pipeName, Convert.ToInt32(_pipeDiameter)); - SoundSpeed = soundVelocity.ToString(); - - //每次计算之前都需要判断是否已经完成之前的计算,然后清空上一次的计算数据 - ResetParam(); - - FlowStatus.CanCollectData = true; - //开始数据采集 - if (FlowStatus.IsHydrophone) - { - CommandSender.SendHydrophoneWakeUpCmd(SerialPortManager.Get.Sp); - } - else - { - _accelerometerCommandTimer.Start(); - } - - //记录计算时间 - _runningTimer.Start(); }); } @@ -932,5 +883,69 @@ FlowStatus.CanCollectData = false; } + + /// + /// 参数检查 + /// + /// + private bool CheckParamLegitimacy() + { + if (string.IsNullOrEmpty(_pipeName)) + { + MessageBox.Show("请选择管道材料", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return false; + } + + if (string.IsNullOrEmpty(_pipeDiameter)) + { + MessageBox.Show("请输入管道直径", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return false; + } + + if (string.IsNullOrEmpty(_pipeLength)) + { + MessageBox.Show("请输入管道长度", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return false; + } + + if (string.IsNullOrEmpty(_lowFrequency) || string.IsNullOrEmpty(_highFrequency)) + { + MessageBox.Show("请输入完整的干扰频段", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return false; + } + + if (!(Regex.IsMatch(_lowFrequency, "^([1-9][0-9]*)$") && + Regex.IsMatch(_highFrequency, "^([1-9][0-9]*)$"))) + { + MessageBox.Show("输入格式错误,请重新输入", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return false; + } + + var low = Convert.ToInt32(_lowFrequency); + var high = Convert.ToInt32(_highFrequency); + + if (FlowStatus.IsHydrophone) + { + if (low < 10 || low > 300 || high < 10 || high > 300 || low >= high) + { + MessageBox.Show("频段范围10 ~ 300Hz,请重新输入", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return false; + } + } + else + { + if (low < 100 || low > 3000 || high < 100 || high > 3000 || low >= high) + { + MessageBox.Show("频段范围100 ~ 3000Hz,请重新输入", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return false; + } + } + + + //声速 + var soundVelocity = _soundSpeedDataService.GetSoundVelocity(_pipeName, Convert.ToInt32(_pipeDiameter)); + SoundSpeed = soundVelocity.ToString(); + return true; + } } } \ No newline at end of file