diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index 5fd31ae..e18210e 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -17,7 +17,7 @@ private readonly IAudioService _audioService; private readonly DevStatus _devStatus = new DevStatus(); - + private int _checkResponseState; public SerialPort Sp { get; set; } = new SerialPort(); //左右传感器设备数据 @@ -144,46 +144,48 @@ case 30: if (RuntimeCache.IsHydrophone) { + "SerialPortServiceImpl".WriteLog("收到显示点名框指令" + BitConverter.ToString(receivedData)); + _checkResponseState++; Application.Current.Dispatcher.Invoke(delegate { //显示点名弹窗 - if (!RuntimeCache.IsShowing) + if (_checkResponseState == 2) { //因为是广播发的数据,所以会收到两条回复,但是只需要显示一次对话框 _eventAggregator.GetEvent().Publish(); - RuntimeCache.IsShowing = true; + _checkResponseState = 0; } }); } break; case 22543: - if (receivedData[0] == 0xA3 && receivedData[1] == 0x20) - { - int index = receivedData[15]; - //取出seq,确定收到的是第几包数据 - RuntimeCache.SeqCaches.Add(index); - - var response = BitConverter.ToString(receivedData).Replace("-", ""); - //收集数据 - if (deviceId.Equals(RuntimeCache.Dev1)) - { - //原始数据 - RuntimeCache.RedSensorOriginalResp.Add(index, response); - //解析之后的数据 - RuntimeCache.RedSensorResponseTags.Add(index, tags); - } - else - { - //原始数据 - RuntimeCache.BlueSensorOriginalResp.Add(index, response); - //解析之后的数据 - RuntimeCache.BlueSensorResponseTags.Add(index, tags); - } - } + // if (receivedData[0] == 0xA3 && receivedData[1] == 0x20) + // { + // int index = receivedData[15]; + // //取出seq,确定收到的是第几包数据 + // RuntimeCache.SeqCaches.Add(index); + // + // var response = BitConverter.ToString(receivedData).Replace("-", ""); + // //收集数据 + // if (deviceId.Equals(RuntimeCache.Dev1)) + // { + // //原始数据 + // RuntimeCache.RedSensorOriginalResp.Add(index, response); + // //解析之后的数据 + // RuntimeCache.RedSensorResponseTags.Add(index, tags); + // } + // else + // { + // //原始数据 + // RuntimeCache.BlueSensorOriginalResp.Add(index, response); + // //解析之后的数据 + // RuntimeCache.BlueSensorResponseTags.Add(index, tags); + // } + // } //TODO 采用水听器数据,但是模式是加速度计模式 - // HandleCorrelatorData(deviceId, tags); + HandleCorrelatorData(deviceId, tags); break; case 15024: //听音 HandleListenData(tags); diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index 5fd31ae..e18210e 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -17,7 +17,7 @@ private readonly IAudioService _audioService; private readonly DevStatus _devStatus = new DevStatus(); - + private int _checkResponseState; public SerialPort Sp { get; set; } = new SerialPort(); //左右传感器设备数据 @@ -144,46 +144,48 @@ case 30: if (RuntimeCache.IsHydrophone) { + "SerialPortServiceImpl".WriteLog("收到显示点名框指令" + BitConverter.ToString(receivedData)); + _checkResponseState++; Application.Current.Dispatcher.Invoke(delegate { //显示点名弹窗 - if (!RuntimeCache.IsShowing) + if (_checkResponseState == 2) { //因为是广播发的数据,所以会收到两条回复,但是只需要显示一次对话框 _eventAggregator.GetEvent().Publish(); - RuntimeCache.IsShowing = true; + _checkResponseState = 0; } }); } break; case 22543: - if (receivedData[0] == 0xA3 && receivedData[1] == 0x20) - { - int index = receivedData[15]; - //取出seq,确定收到的是第几包数据 - RuntimeCache.SeqCaches.Add(index); - - var response = BitConverter.ToString(receivedData).Replace("-", ""); - //收集数据 - if (deviceId.Equals(RuntimeCache.Dev1)) - { - //原始数据 - RuntimeCache.RedSensorOriginalResp.Add(index, response); - //解析之后的数据 - RuntimeCache.RedSensorResponseTags.Add(index, tags); - } - else - { - //原始数据 - RuntimeCache.BlueSensorOriginalResp.Add(index, response); - //解析之后的数据 - RuntimeCache.BlueSensorResponseTags.Add(index, tags); - } - } + // if (receivedData[0] == 0xA3 && receivedData[1] == 0x20) + // { + // int index = receivedData[15]; + // //取出seq,确定收到的是第几包数据 + // RuntimeCache.SeqCaches.Add(index); + // + // var response = BitConverter.ToString(receivedData).Replace("-", ""); + // //收集数据 + // if (deviceId.Equals(RuntimeCache.Dev1)) + // { + // //原始数据 + // RuntimeCache.RedSensorOriginalResp.Add(index, response); + // //解析之后的数据 + // RuntimeCache.RedSensorResponseTags.Add(index, tags); + // } + // else + // { + // //原始数据 + // RuntimeCache.BlueSensorOriginalResp.Add(index, response); + // //解析之后的数据 + // RuntimeCache.BlueSensorResponseTags.Add(index, tags); + // } + // } //TODO 采用水听器数据,但是模式是加速度计模式 - // HandleCorrelatorData(deviceId, tags); + HandleCorrelatorData(deviceId, tags); break; case 15024: //听音 HandleListenData(tags); diff --git a/Correlator/Dialog/SimplyAuditionDialog.xaml.cs b/Correlator/Dialog/SimplyAuditionDialog.xaml.cs index 286b1a4..90746e4 100644 --- a/Correlator/Dialog/SimplyAuditionDialog.xaml.cs +++ b/Correlator/Dialog/SimplyAuditionDialog.xaml.cs @@ -110,8 +110,11 @@ var color2 = _allColors[(_colorIndex + 200) % _allColors.Length]; var bassArea = AudioDataHub.Get.TakeSpectrumOfFrequency( - _spectrumData, RuntimeCache.AudioSampleRate, 250 + _spectrumData, + RuntimeCache.IsHydrophone ? RuntimeCache.HydrophoneSampleRate : RuntimeCache.CommonSampleRate, + 250 ); + var bassScale = bassArea.Average() * 100; //低音区 //波形曲线 diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index 5fd31ae..e18210e 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -17,7 +17,7 @@ private readonly IAudioService _audioService; private readonly DevStatus _devStatus = new DevStatus(); - + private int _checkResponseState; public SerialPort Sp { get; set; } = new SerialPort(); //左右传感器设备数据 @@ -144,46 +144,48 @@ case 30: if (RuntimeCache.IsHydrophone) { + "SerialPortServiceImpl".WriteLog("收到显示点名框指令" + BitConverter.ToString(receivedData)); + _checkResponseState++; Application.Current.Dispatcher.Invoke(delegate { //显示点名弹窗 - if (!RuntimeCache.IsShowing) + if (_checkResponseState == 2) { //因为是广播发的数据,所以会收到两条回复,但是只需要显示一次对话框 _eventAggregator.GetEvent().Publish(); - RuntimeCache.IsShowing = true; + _checkResponseState = 0; } }); } break; case 22543: - if (receivedData[0] == 0xA3 && receivedData[1] == 0x20) - { - int index = receivedData[15]; - //取出seq,确定收到的是第几包数据 - RuntimeCache.SeqCaches.Add(index); - - var response = BitConverter.ToString(receivedData).Replace("-", ""); - //收集数据 - if (deviceId.Equals(RuntimeCache.Dev1)) - { - //原始数据 - RuntimeCache.RedSensorOriginalResp.Add(index, response); - //解析之后的数据 - RuntimeCache.RedSensorResponseTags.Add(index, tags); - } - else - { - //原始数据 - RuntimeCache.BlueSensorOriginalResp.Add(index, response); - //解析之后的数据 - RuntimeCache.BlueSensorResponseTags.Add(index, tags); - } - } + // if (receivedData[0] == 0xA3 && receivedData[1] == 0x20) + // { + // int index = receivedData[15]; + // //取出seq,确定收到的是第几包数据 + // RuntimeCache.SeqCaches.Add(index); + // + // var response = BitConverter.ToString(receivedData).Replace("-", ""); + // //收集数据 + // if (deviceId.Equals(RuntimeCache.Dev1)) + // { + // //原始数据 + // RuntimeCache.RedSensorOriginalResp.Add(index, response); + // //解析之后的数据 + // RuntimeCache.RedSensorResponseTags.Add(index, tags); + // } + // else + // { + // //原始数据 + // RuntimeCache.BlueSensorOriginalResp.Add(index, response); + // //解析之后的数据 + // RuntimeCache.BlueSensorResponseTags.Add(index, tags); + // } + // } //TODO 采用水听器数据,但是模式是加速度计模式 - // HandleCorrelatorData(deviceId, tags); + HandleCorrelatorData(deviceId, tags); break; case 15024: //听音 HandleListenData(tags); diff --git a/Correlator/Dialog/SimplyAuditionDialog.xaml.cs b/Correlator/Dialog/SimplyAuditionDialog.xaml.cs index 286b1a4..90746e4 100644 --- a/Correlator/Dialog/SimplyAuditionDialog.xaml.cs +++ b/Correlator/Dialog/SimplyAuditionDialog.xaml.cs @@ -110,8 +110,11 @@ var color2 = _allColors[(_colorIndex + 200) % _allColors.Length]; var bassArea = AudioDataHub.Get.TakeSpectrumOfFrequency( - _spectrumData, RuntimeCache.AudioSampleRate, 250 + _spectrumData, + RuntimeCache.IsHydrophone ? RuntimeCache.HydrophoneSampleRate : RuntimeCache.CommonSampleRate, + 250 ); + var bassScale = bassArea.Average() * 100; //低音区 //波形曲线 diff --git a/Correlator/Util/RuntimeCache.cs b/Correlator/Util/RuntimeCache.cs index e27c8ff..fe54a0e 100644 --- a/Correlator/Util/RuntimeCache.cs +++ b/Correlator/Util/RuntimeCache.cs @@ -35,11 +35,6 @@ public static bool IsHydrophone = false; /// - /// 点名对话框是否已显示 - /// - public static bool IsShowing = false; - - /// /// 数据包index /// public static readonly List SeqCaches = new List(); @@ -83,9 +78,11 @@ public const int PerPageItemCount = 8; /// - /// 采样率 + /// 采样率,水听器和加速度计 /// - public const int AudioSampleRate = 7500; + public const int HydrophoneSampleRate = 1000; + + public const int CommonSampleRate = 7500; /// /// 设备1(红色的) diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index 5fd31ae..e18210e 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -17,7 +17,7 @@ private readonly IAudioService _audioService; private readonly DevStatus _devStatus = new DevStatus(); - + private int _checkResponseState; public SerialPort Sp { get; set; } = new SerialPort(); //左右传感器设备数据 @@ -144,46 +144,48 @@ case 30: if (RuntimeCache.IsHydrophone) { + "SerialPortServiceImpl".WriteLog("收到显示点名框指令" + BitConverter.ToString(receivedData)); + _checkResponseState++; Application.Current.Dispatcher.Invoke(delegate { //显示点名弹窗 - if (!RuntimeCache.IsShowing) + if (_checkResponseState == 2) { //因为是广播发的数据,所以会收到两条回复,但是只需要显示一次对话框 _eventAggregator.GetEvent().Publish(); - RuntimeCache.IsShowing = true; + _checkResponseState = 0; } }); } break; case 22543: - if (receivedData[0] == 0xA3 && receivedData[1] == 0x20) - { - int index = receivedData[15]; - //取出seq,确定收到的是第几包数据 - RuntimeCache.SeqCaches.Add(index); - - var response = BitConverter.ToString(receivedData).Replace("-", ""); - //收集数据 - if (deviceId.Equals(RuntimeCache.Dev1)) - { - //原始数据 - RuntimeCache.RedSensorOriginalResp.Add(index, response); - //解析之后的数据 - RuntimeCache.RedSensorResponseTags.Add(index, tags); - } - else - { - //原始数据 - RuntimeCache.BlueSensorOriginalResp.Add(index, response); - //解析之后的数据 - RuntimeCache.BlueSensorResponseTags.Add(index, tags); - } - } + // if (receivedData[0] == 0xA3 && receivedData[1] == 0x20) + // { + // int index = receivedData[15]; + // //取出seq,确定收到的是第几包数据 + // RuntimeCache.SeqCaches.Add(index); + // + // var response = BitConverter.ToString(receivedData).Replace("-", ""); + // //收集数据 + // if (deviceId.Equals(RuntimeCache.Dev1)) + // { + // //原始数据 + // RuntimeCache.RedSensorOriginalResp.Add(index, response); + // //解析之后的数据 + // RuntimeCache.RedSensorResponseTags.Add(index, tags); + // } + // else + // { + // //原始数据 + // RuntimeCache.BlueSensorOriginalResp.Add(index, response); + // //解析之后的数据 + // RuntimeCache.BlueSensorResponseTags.Add(index, tags); + // } + // } //TODO 采用水听器数据,但是模式是加速度计模式 - // HandleCorrelatorData(deviceId, tags); + HandleCorrelatorData(deviceId, tags); break; case 15024: //听音 HandleListenData(tags); diff --git a/Correlator/Dialog/SimplyAuditionDialog.xaml.cs b/Correlator/Dialog/SimplyAuditionDialog.xaml.cs index 286b1a4..90746e4 100644 --- a/Correlator/Dialog/SimplyAuditionDialog.xaml.cs +++ b/Correlator/Dialog/SimplyAuditionDialog.xaml.cs @@ -110,8 +110,11 @@ var color2 = _allColors[(_colorIndex + 200) % _allColors.Length]; var bassArea = AudioDataHub.Get.TakeSpectrumOfFrequency( - _spectrumData, RuntimeCache.AudioSampleRate, 250 + _spectrumData, + RuntimeCache.IsHydrophone ? RuntimeCache.HydrophoneSampleRate : RuntimeCache.CommonSampleRate, + 250 ); + var bassScale = bassArea.Average() * 100; //低音区 //波形曲线 diff --git a/Correlator/Util/RuntimeCache.cs b/Correlator/Util/RuntimeCache.cs index e27c8ff..fe54a0e 100644 --- a/Correlator/Util/RuntimeCache.cs +++ b/Correlator/Util/RuntimeCache.cs @@ -35,11 +35,6 @@ public static bool IsHydrophone = false; /// - /// 点名对话框是否已显示 - /// - public static bool IsShowing = false; - - /// /// 数据包index /// public static readonly List SeqCaches = new List(); @@ -83,9 +78,11 @@ public const int PerPageItemCount = 8; /// - /// 采样率 + /// 采样率,水听器和加速度计 /// - public const int AudioSampleRate = 7500; + public const int HydrophoneSampleRate = 1000; + + public const int CommonSampleRate = 7500; /// /// 设备1(红色的) diff --git a/Correlator/ViewModels/CheckResponseDialogViewModel.cs b/Correlator/ViewModels/CheckResponseDialogViewModel.cs index a6dd527..acfd65e 100644 --- a/Correlator/ViewModels/CheckResponseDialogViewModel.cs +++ b/Correlator/ViewModels/CheckResponseDialogViewModel.cs @@ -1,6 +1,5 @@ using System; using Correlator.Events; -using Correlator.Util; using Prism.Events; using Prism.Services.Dialogs; @@ -16,7 +15,6 @@ { eventAggregator.GetEvent().Subscribe(delegate(IDialogResult result) { - RuntimeCache.IsShowing = false; RequestClose?.Invoke(result); }); } diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index 5fd31ae..e18210e 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -17,7 +17,7 @@ private readonly IAudioService _audioService; private readonly DevStatus _devStatus = new DevStatus(); - + private int _checkResponseState; public SerialPort Sp { get; set; } = new SerialPort(); //左右传感器设备数据 @@ -144,46 +144,48 @@ case 30: if (RuntimeCache.IsHydrophone) { + "SerialPortServiceImpl".WriteLog("收到显示点名框指令" + BitConverter.ToString(receivedData)); + _checkResponseState++; Application.Current.Dispatcher.Invoke(delegate { //显示点名弹窗 - if (!RuntimeCache.IsShowing) + if (_checkResponseState == 2) { //因为是广播发的数据,所以会收到两条回复,但是只需要显示一次对话框 _eventAggregator.GetEvent().Publish(); - RuntimeCache.IsShowing = true; + _checkResponseState = 0; } }); } break; case 22543: - if (receivedData[0] == 0xA3 && receivedData[1] == 0x20) - { - int index = receivedData[15]; - //取出seq,确定收到的是第几包数据 - RuntimeCache.SeqCaches.Add(index); - - var response = BitConverter.ToString(receivedData).Replace("-", ""); - //收集数据 - if (deviceId.Equals(RuntimeCache.Dev1)) - { - //原始数据 - RuntimeCache.RedSensorOriginalResp.Add(index, response); - //解析之后的数据 - RuntimeCache.RedSensorResponseTags.Add(index, tags); - } - else - { - //原始数据 - RuntimeCache.BlueSensorOriginalResp.Add(index, response); - //解析之后的数据 - RuntimeCache.BlueSensorResponseTags.Add(index, tags); - } - } + // if (receivedData[0] == 0xA3 && receivedData[1] == 0x20) + // { + // int index = receivedData[15]; + // //取出seq,确定收到的是第几包数据 + // RuntimeCache.SeqCaches.Add(index); + // + // var response = BitConverter.ToString(receivedData).Replace("-", ""); + // //收集数据 + // if (deviceId.Equals(RuntimeCache.Dev1)) + // { + // //原始数据 + // RuntimeCache.RedSensorOriginalResp.Add(index, response); + // //解析之后的数据 + // RuntimeCache.RedSensorResponseTags.Add(index, tags); + // } + // else + // { + // //原始数据 + // RuntimeCache.BlueSensorOriginalResp.Add(index, response); + // //解析之后的数据 + // RuntimeCache.BlueSensorResponseTags.Add(index, tags); + // } + // } //TODO 采用水听器数据,但是模式是加速度计模式 - // HandleCorrelatorData(deviceId, tags); + HandleCorrelatorData(deviceId, tags); break; case 15024: //听音 HandleListenData(tags); diff --git a/Correlator/Dialog/SimplyAuditionDialog.xaml.cs b/Correlator/Dialog/SimplyAuditionDialog.xaml.cs index 286b1a4..90746e4 100644 --- a/Correlator/Dialog/SimplyAuditionDialog.xaml.cs +++ b/Correlator/Dialog/SimplyAuditionDialog.xaml.cs @@ -110,8 +110,11 @@ var color2 = _allColors[(_colorIndex + 200) % _allColors.Length]; var bassArea = AudioDataHub.Get.TakeSpectrumOfFrequency( - _spectrumData, RuntimeCache.AudioSampleRate, 250 + _spectrumData, + RuntimeCache.IsHydrophone ? RuntimeCache.HydrophoneSampleRate : RuntimeCache.CommonSampleRate, + 250 ); + var bassScale = bassArea.Average() * 100; //低音区 //波形曲线 diff --git a/Correlator/Util/RuntimeCache.cs b/Correlator/Util/RuntimeCache.cs index e27c8ff..fe54a0e 100644 --- a/Correlator/Util/RuntimeCache.cs +++ b/Correlator/Util/RuntimeCache.cs @@ -35,11 +35,6 @@ public static bool IsHydrophone = false; /// - /// 点名对话框是否已显示 - /// - public static bool IsShowing = false; - - /// /// 数据包index /// public static readonly List SeqCaches = new List(); @@ -83,9 +78,11 @@ public const int PerPageItemCount = 8; /// - /// 采样率 + /// 采样率,水听器和加速度计 /// - public const int AudioSampleRate = 7500; + public const int HydrophoneSampleRate = 1000; + + public const int CommonSampleRate = 7500; /// /// 设备1(红色的) diff --git a/Correlator/ViewModels/CheckResponseDialogViewModel.cs b/Correlator/ViewModels/CheckResponseDialogViewModel.cs index a6dd527..acfd65e 100644 --- a/Correlator/ViewModels/CheckResponseDialogViewModel.cs +++ b/Correlator/ViewModels/CheckResponseDialogViewModel.cs @@ -1,6 +1,5 @@ using System; using Correlator.Events; -using Correlator.Util; using Prism.Events; using Prism.Services.Dialogs; @@ -16,7 +15,6 @@ { eventAggregator.GetEvent().Subscribe(delegate(IDialogResult result) { - RuntimeCache.IsShowing = false; RequestClose?.Invoke(result); }); } diff --git a/Correlator/ViewModels/MainWindowViewModel.cs b/Correlator/ViewModels/MainWindowViewModel.cs index c5cdbce..4fc6096 100644 --- a/Correlator/ViewModels/MainWindowViewModel.cs +++ b/Correlator/ViewModels/MainWindowViewModel.cs @@ -922,19 +922,19 @@ var dataValue = tag.DataValue; //PCM数据 var pcm = new byte[7500 * 3]; //每个采样点2字节 - + for (var i = 0; i < 7500; i++) { pcm[i * 3 + 2] = dataValue[i * 2 + 0]; pcm[i * 3 + 1] = dataValue[i * 2 + 1]; pcm[i * 3 + 0] = 0x00; } - + redPcmArray.Add(pcm); } - + _audioService.Write(_locateDataDir, "音频_红", redPcmArray); - + var blueValueSortResult = from pair in RuntimeCache.BlueSensorOriginalResp orderby pair.Key select pair; @@ -946,17 +946,17 @@ var dataValue = tag.DataValue; //PCM数据 var pcm = new byte[7500 * 3]; //每个采样点2字节 - + for (var i = 0; i < 7500; i++) { pcm[i * 3 + 2] = dataValue[i * 2 + 0]; pcm[i * 3 + 1] = dataValue[i * 2 + 1]; pcm[i * 3 + 0] = 0x00; } - + bluePcmArray.Add(pcm); } - + _audioService.Write(_locateDataDir, "音频_蓝", bluePcmArray); Growl.Success("音频已保存"); } @@ -1040,7 +1040,7 @@ BlueTransmitterDistance = 0; CorrelatorData = new CorrelatorDataModel(); ClearCache(); - + _runningSeconds = 0; _runningTimer.Stop(); @@ -1138,7 +1138,7 @@ 11, (MWNumericArray)_correlatorData.LeftDeviceDataArray, (MWNumericArray)_correlatorData.RightDeviceDataArray, - RuntimeCache.AudioSampleRate, + RuntimeCache.IsHydrophone ? RuntimeCache.HydrophoneSampleRate : RuntimeCache.CommonSampleRate, int.Parse(_pipeLength), int.Parse(_soundSpeed), 0, 0, 0, 0,