diff --git a/Correlator/View/HomePageProWindow.xaml b/Correlator/View/HomePageProWindow.xaml
index 06c59cf..76ccb97 100644
--- a/Correlator/View/HomePageProWindow.xaml
+++ b/Correlator/View/HomePageProWindow.xaml
@@ -8,14 +8,12 @@
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:input="clr-namespace:System.Windows.Input;assembly=PresentationCore"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- Title="相关仪"
MinWidth="1366"
MinHeight="768"
d:DesignHeight="1080"
d:DesignWidth="1920"
Background="#EBECF0"
DataContext="{Binding HomePagePro, Source={StaticResource Locator}}"
- Icon="/Correlator;component/Image/favicon.ico"
WindowStartupLocation="CenterScreen"
WindowState="Maximized"
WindowStyle="None"
@@ -33,9 +31,6 @@
-
-
-
@@ -557,7 +552,7 @@
+ Text="{Binding ApplicationVersion}" />
-
-
-
@@ -557,7 +552,7 @@
+ Text="{Binding ApplicationVersion}" />
_comboBoxIsEnabled;
- set
- {
- _comboBoxIsEnabled = value;
- RaisePropertyChanged();
- }
- }
-
private string _pipeDiameter = string.Empty;
public string PipeDiameter
@@ -391,6 +409,18 @@
}
}
+ private string _applicationVersion = "Ver 1.0.0.0";
+
+ public string ApplicationVersion
+ {
+ get => _applicationVersion;
+ private set
+ {
+ _applicationVersion = value;
+ RaisePropertyChanged();
+ }
+ }
+
#endregion
#region PC电量状态
@@ -415,6 +445,9 @@
{
_soundSpeedDataService = soundSpeedDataService;
+ //获取版本号
+ ApplicationVersion = "Ver " + Application.ResourceAssembly.GetName().Version;
+
RegisterMessage();
TimerTick();
@@ -427,8 +460,6 @@
}
InitRelayCommand();
-
- InitDefaultValue();
}
///
@@ -457,6 +488,74 @@
BlueTransmitterState = true;
FlowStatus.BlueSensorIsEnable = true;
});
+
+ //计算测试数据
+ Messenger.Default.Register(this, MessengerToken.HomePageDeviceData, it =>
+ {
+ //开始计算停止收集指令
+ if (FlowStatus.IsHydrophone)
+ {
+ _hydrophoneCommandTimer.Stop();
+ }
+ else
+ {
+ _accelerometerCommandTimer.Stop();
+ }
+
+ //给音频数据赋值
+ FlowStatus.CorrelatorData = it;
+ using (var manager = new DataBaseManager())
+ {
+ var today = DateTime.Now.ToString("yyyyMMdd");
+ var configModel = manager
+ .Table()
+ .Where(x => x.Date == today)
+ .OrderBy(x => x.Date)
+ .LastOrDefault() ?? new CorrelatorConfigModel
+ {
+ Date = today,
+ Pipe = 1,
+ LocateTimes = 1,
+ ListenTimes = 1
+ };
+
+ //如果配置里面的日期相同,则取配置里面的Pipe作为index,如果配置里面的日期不相同,则默认index=1
+ var pipeIndex = configModel.Date.Equals(today) ? configModel.Pipe : 1;
+ _locateDataDir = Constant.GetLocateDataDir(pipeIndex);
+ _locateTimes = configModel.LocateTimes;
+
+ //计算
+ try
+ {
+ var task = new Task(() => CalculateData(it));
+ task.Start();
+
+ //异步保存定位数据
+ var fileName = _locateDataDir + "\\测试数据." + _locateTimes + "."
+ + DateTime.Now.ToString("HHmmss") + ".txt";
+ StringUtil.SaveLocateData(it, fileName);
+ "HomePageViewModel".WriteLog("定位数据路径:" + fileName);
+
+ //同步保存截图,需要等待Task出结果并且渲染完成,才能保存截图
+ _snapShotPath = _locateDataDir + "\\快照." + _locateTimes + "." +
+ DateTime.Now.ToString("HHmmss") + ".png";
+
+ if (task.Result)
+ {
+ _snapShotTimer.Start();
+ }
+
+ //插入新纪录
+ configModel.Pipe++;
+ configModel.LocateTimes++;
+ manager.Insert(configModel);
+ }
+ catch (Exception e)
+ {
+ "HomePageViewModel".WriteLog(e.Message);
+ }
+ }
+ });
}
///
@@ -501,6 +600,35 @@
MessageBox.Show("接收不到数据,请点击复位并重新开始采集数据", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error);
}
};
+
+ //加速度计下发指令Timer
+ _accelerometerCommandTimer.Tick += delegate
+ {
+ if (FlowStatus.CanCollectData)
+ {
+ CommandSender.SendCorrelatorWakeUpCmd(SerialPortManager.Get.Sp);
+ }
+ };
+
+ //水听器下发指令Timer
+ _hydrophoneCommandTimer.Tick += delegate
+ {
+ if (FlowStatus.CanCollectData)
+ {
+ CommandSender.SendHydrophoneWakeUpCmd(SerialPortManager.Get.Sp);
+ }
+ };
+
+ //自动截屏Timer
+ _snapShotTimer.Tick += delegate
+ {
+ _snapShotTimer.Stop();
+ if (!string.IsNullOrEmpty(_snapShotPath))
+ {
+ _snapShotPath.SnapShot();
+ "HomePageProViewModel".WriteLog("截屏路径:" + _snapShotPath);
+ }
+ };
}
///
@@ -510,6 +638,7 @@
{
WindowLoadedCommand = new RelayCommand(it =>
{
+ _homePageWindow = it;
Debug.WriteLine("HomePageProViewModel => 加载");
it.AccelerationRadioButton.Checked += delegate
{
@@ -633,20 +762,21 @@
//每次计算之前都需要判断是否已经完成之前的计算,然后清空上一次的计算数据
ResetParam();
- Debug.WriteLine("_pipeName => " + _pipeName);
- Debug.WriteLine("_pipeDiameter => " + _pipeDiameter);
- Debug.WriteLine("_pipeLength => " + _pipeLength);
- Debug.WriteLine("_lowFrequency => " + _lowFrequency);
- Debug.WriteLine("_highFrequency => " + _highFrequency);
- Debug.WriteLine("soundVelocity => " + soundVelocity);
- });
- }
+ //信号收发器正常之后就可以下发收集数据的指令了
+ FlowStatus.CanCollectData = true;
+ //开始数据采集
+ if (FlowStatus.IsHydrophone)
+ {
+ _hydrophoneCommandTimer.Start();
+ }
+ else
+ {
+ _accelerometerCommandTimer.Start();
+ }
- ///
- /// 设置默认值
- ///
- private void InitDefaultValue()
- {
+ //记录计算时间
+ _runningTimer.Start();
+ });
}
///
@@ -678,16 +808,65 @@
Messenger.Default.Send("", MessengerToken.ClearOscillogram);
- // StartState = false;
- // FlowStatus.CanCollectData = false;
- // if (FlowStatus.IsHydrophone)
- // {
- // _hydrophoneCommandTimer.Stop();
- // }
- // else
- // {
- // _accelerometerCommandTimer.Stop();
- // }
+ if (FlowStatus.IsHydrophone)
+ {
+ _hydrophoneCommandTimer.Stop();
+ }
+ else
+ {
+ _accelerometerCommandTimer.Stop();
+ }
+
+ FlowStatus.CanCollectData = false;
+ }
+
+ ///
+ /// Matlab计算过程
+ ///
+ /// 收集到的传感器数据
+ /// 计算结果
+ private bool CalculateData(CorrelatorDataModel dataModel)
+ {
+ DialogHub.Get.ShowLoadingDialog(_homePageWindow, "样品数据计算中,请稍后...");
+ 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));
+
+ //数据绑定
+ 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 maxCorrelationCoefficient = Convert.ToDouble(array[3].ToString());
+
+ //时间差
+ var timeDiff = Convert.ToDouble(array[6].ToString());
+
+ //将数据发送到HomePageWindow.xaml.cs页面进行渲染
+ Messenger.Default.Send(array, MessengerToken.RenderOscillogram);
+
+ var maxFreLowOut = Convert.ToInt32(array[6].ToString()); //低频
+ var maxFreHighOut = Convert.ToInt32(array[7].ToString()); //高频
+ var flag = Convert.ToBoolean(Convert.ToInt32(array[8].ToString())); //是否泄漏
+ var totalNum = Convert.ToInt32(array[9].ToString()); //总的调用次数
+
+ FilterValue = maxFreLowOut + " ~ " + maxFreHighOut + "Hz";
+
+ _runningTimer.Stop();
+ StartButtonEnabled = true;
+ //开始计算就不收集收据了
+ FlowStatus.CanCollectData = false;
+ DialogHub.Get.DismissLoadingDialog();
+ return true;
}
}
}
\ No newline at end of file
diff --git a/Correlator/View/HomePageProWindow.xaml b/Correlator/View/HomePageProWindow.xaml
index 06c59cf..76ccb97 100644
--- a/Correlator/View/HomePageProWindow.xaml
+++ b/Correlator/View/HomePageProWindow.xaml
@@ -8,14 +8,12 @@
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:input="clr-namespace:System.Windows.Input;assembly=PresentationCore"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- Title="相关仪"
MinWidth="1366"
MinHeight="768"
d:DesignHeight="1080"
d:DesignWidth="1920"
Background="#EBECF0"
DataContext="{Binding HomePagePro, Source={StaticResource Locator}}"
- Icon="/Correlator;component/Image/favicon.ico"
WindowStartupLocation="CenterScreen"
WindowState="Maximized"
WindowStyle="None"
@@ -33,9 +31,6 @@
-
-
-
@@ -557,7 +552,7 @@
+ Text="{Binding ApplicationVersion}" />
_comboBoxIsEnabled;
- set
- {
- _comboBoxIsEnabled = value;
- RaisePropertyChanged();
- }
- }
-
private string _pipeDiameter = string.Empty;
public string PipeDiameter
@@ -391,6 +409,18 @@
}
}
+ private string _applicationVersion = "Ver 1.0.0.0";
+
+ public string ApplicationVersion
+ {
+ get => _applicationVersion;
+ private set
+ {
+ _applicationVersion = value;
+ RaisePropertyChanged();
+ }
+ }
+
#endregion
#region PC电量状态
@@ -415,6 +445,9 @@
{
_soundSpeedDataService = soundSpeedDataService;
+ //获取版本号
+ ApplicationVersion = "Ver " + Application.ResourceAssembly.GetName().Version;
+
RegisterMessage();
TimerTick();
@@ -427,8 +460,6 @@
}
InitRelayCommand();
-
- InitDefaultValue();
}
///
@@ -457,6 +488,74 @@
BlueTransmitterState = true;
FlowStatus.BlueSensorIsEnable = true;
});
+
+ //计算测试数据
+ Messenger.Default.Register(this, MessengerToken.HomePageDeviceData, it =>
+ {
+ //开始计算停止收集指令
+ if (FlowStatus.IsHydrophone)
+ {
+ _hydrophoneCommandTimer.Stop();
+ }
+ else
+ {
+ _accelerometerCommandTimer.Stop();
+ }
+
+ //给音频数据赋值
+ FlowStatus.CorrelatorData = it;
+ using (var manager = new DataBaseManager())
+ {
+ var today = DateTime.Now.ToString("yyyyMMdd");
+ var configModel = manager
+ .Table()
+ .Where(x => x.Date == today)
+ .OrderBy(x => x.Date)
+ .LastOrDefault() ?? new CorrelatorConfigModel
+ {
+ Date = today,
+ Pipe = 1,
+ LocateTimes = 1,
+ ListenTimes = 1
+ };
+
+ //如果配置里面的日期相同,则取配置里面的Pipe作为index,如果配置里面的日期不相同,则默认index=1
+ var pipeIndex = configModel.Date.Equals(today) ? configModel.Pipe : 1;
+ _locateDataDir = Constant.GetLocateDataDir(pipeIndex);
+ _locateTimes = configModel.LocateTimes;
+
+ //计算
+ try
+ {
+ var task = new Task(() => CalculateData(it));
+ task.Start();
+
+ //异步保存定位数据
+ var fileName = _locateDataDir + "\\测试数据." + _locateTimes + "."
+ + DateTime.Now.ToString("HHmmss") + ".txt";
+ StringUtil.SaveLocateData(it, fileName);
+ "HomePageViewModel".WriteLog("定位数据路径:" + fileName);
+
+ //同步保存截图,需要等待Task出结果并且渲染完成,才能保存截图
+ _snapShotPath = _locateDataDir + "\\快照." + _locateTimes + "." +
+ DateTime.Now.ToString("HHmmss") + ".png";
+
+ if (task.Result)
+ {
+ _snapShotTimer.Start();
+ }
+
+ //插入新纪录
+ configModel.Pipe++;
+ configModel.LocateTimes++;
+ manager.Insert(configModel);
+ }
+ catch (Exception e)
+ {
+ "HomePageViewModel".WriteLog(e.Message);
+ }
+ }
+ });
}
///
@@ -501,6 +600,35 @@
MessageBox.Show("接收不到数据,请点击复位并重新开始采集数据", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error);
}
};
+
+ //加速度计下发指令Timer
+ _accelerometerCommandTimer.Tick += delegate
+ {
+ if (FlowStatus.CanCollectData)
+ {
+ CommandSender.SendCorrelatorWakeUpCmd(SerialPortManager.Get.Sp);
+ }
+ };
+
+ //水听器下发指令Timer
+ _hydrophoneCommandTimer.Tick += delegate
+ {
+ if (FlowStatus.CanCollectData)
+ {
+ CommandSender.SendHydrophoneWakeUpCmd(SerialPortManager.Get.Sp);
+ }
+ };
+
+ //自动截屏Timer
+ _snapShotTimer.Tick += delegate
+ {
+ _snapShotTimer.Stop();
+ if (!string.IsNullOrEmpty(_snapShotPath))
+ {
+ _snapShotPath.SnapShot();
+ "HomePageProViewModel".WriteLog("截屏路径:" + _snapShotPath);
+ }
+ };
}
///
@@ -510,6 +638,7 @@
{
WindowLoadedCommand = new RelayCommand(it =>
{
+ _homePageWindow = it;
Debug.WriteLine("HomePageProViewModel => 加载");
it.AccelerationRadioButton.Checked += delegate
{
@@ -633,20 +762,21 @@
//每次计算之前都需要判断是否已经完成之前的计算,然后清空上一次的计算数据
ResetParam();
- Debug.WriteLine("_pipeName => " + _pipeName);
- Debug.WriteLine("_pipeDiameter => " + _pipeDiameter);
- Debug.WriteLine("_pipeLength => " + _pipeLength);
- Debug.WriteLine("_lowFrequency => " + _lowFrequency);
- Debug.WriteLine("_highFrequency => " + _highFrequency);
- Debug.WriteLine("soundVelocity => " + soundVelocity);
- });
- }
+ //信号收发器正常之后就可以下发收集数据的指令了
+ FlowStatus.CanCollectData = true;
+ //开始数据采集
+ if (FlowStatus.IsHydrophone)
+ {
+ _hydrophoneCommandTimer.Start();
+ }
+ else
+ {
+ _accelerometerCommandTimer.Start();
+ }
- ///
- /// 设置默认值
- ///
- private void InitDefaultValue()
- {
+ //记录计算时间
+ _runningTimer.Start();
+ });
}
///
@@ -678,16 +808,65 @@
Messenger.Default.Send("", MessengerToken.ClearOscillogram);
- // StartState = false;
- // FlowStatus.CanCollectData = false;
- // if (FlowStatus.IsHydrophone)
- // {
- // _hydrophoneCommandTimer.Stop();
- // }
- // else
- // {
- // _accelerometerCommandTimer.Stop();
- // }
+ if (FlowStatus.IsHydrophone)
+ {
+ _hydrophoneCommandTimer.Stop();
+ }
+ else
+ {
+ _accelerometerCommandTimer.Stop();
+ }
+
+ FlowStatus.CanCollectData = false;
+ }
+
+ ///
+ /// Matlab计算过程
+ ///
+ /// 收集到的传感器数据
+ /// 计算结果
+ private bool CalculateData(CorrelatorDataModel dataModel)
+ {
+ DialogHub.Get.ShowLoadingDialog(_homePageWindow, "样品数据计算中,请稍后...");
+ 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));
+
+ //数据绑定
+ 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 maxCorrelationCoefficient = Convert.ToDouble(array[3].ToString());
+
+ //时间差
+ var timeDiff = Convert.ToDouble(array[6].ToString());
+
+ //将数据发送到HomePageWindow.xaml.cs页面进行渲染
+ Messenger.Default.Send(array, MessengerToken.RenderOscillogram);
+
+ var maxFreLowOut = Convert.ToInt32(array[6].ToString()); //低频
+ var maxFreHighOut = Convert.ToInt32(array[7].ToString()); //高频
+ var flag = Convert.ToBoolean(Convert.ToInt32(array[8].ToString())); //是否泄漏
+ var totalNum = Convert.ToInt32(array[9].ToString()); //总的调用次数
+
+ FilterValue = maxFreLowOut + " ~ " + maxFreHighOut + "Hz";
+
+ _runningTimer.Stop();
+ StartButtonEnabled = true;
+ //开始计算就不收集收据了
+ FlowStatus.CanCollectData = false;
+ DialogHub.Get.DismissLoadingDialog();
+ return true;
}
}
}
\ No newline at end of file
diff --git a/Correlator/ViewModel/HomePageViewModel.cs b/Correlator/ViewModel/HomePageViewModel.cs
index 2a30889..300092f 100644
--- a/Correlator/ViewModel/HomePageViewModel.cs
+++ b/Correlator/ViewModel/HomePageViewModel.cs
@@ -776,6 +776,17 @@
private bool CalculateData(CorrelatorDataModel dataModel)
{
DialogHub.Get.ShowLoadingDialog(_homePageWindow, "样品数据计算中,请稍后...");
+ // {
+ // "Id": 1,
+ // "EnglishMaterial": null,
+ // "ChineseMaterial": "铸铁",
+ // "Diameter": 300.0,
+ // "Length": 150.0,
+ // "SoundSpeed": 1130,
+ // "LowFrequency": 100,
+ // "HighFrequency": 3000,
+ // "IsReady": true
+ // }
var array = _correlator.locating(11,
(MWNumericArray)dataModel.LeftDeviceDataArray, (MWNumericArray)dataModel.RightDeviceDataArray,
Constant.SamplingRate,