diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index cb3946e..5d33683 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -265,7 +265,7 @@ - + diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index cb3946e..5d33683 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -265,7 +265,7 @@ - + diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index 4c897c0..51294cd 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -81,23 +81,23 @@ break; case 11293: //数据采集 - if (!FlowStatus.IsHydrophone) + if (!RuntimeCache.IsHydrophone) { HandleCorrelatorData(deviceId, tags); } break; case 30: - if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) + if (RuntimeCache.IsHydrophone && RuntimeCache.CanCollectData) { Application.Current.Dispatcher.Invoke(delegate { //显示点名弹窗 - if (!FlowStatus.IsShowing) + if (!RuntimeCache.IsShowing) { //因为是广播发的数据,所以会收到两条回复,但是只需要显示一次对话框 _eventAggregator.GetEvent().Publish(); - FlowStatus.IsShowing = true; + RuntimeCache.IsShowing = true; } }); } @@ -108,23 +108,23 @@ { int index = receiveData[15]; //取出seq,确定收到的是第几包数据 - FlowStatus.SeqCaches.Add(index); + RuntimeCache.SeqCaches.Add(index); var response = BitConverter.ToString(receiveData).Replace("-", ""); //收集数据 if (deviceId.Equals(DevCode.Dev1)) { //原始数据 - FlowStatus.RedSensorOriginalResp.Add(index, response); + RuntimeCache.RedSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.RedSensorResponseTags.Add(index, tags); + RuntimeCache.RedSensorResponseTags.Add(index, tags); } else { //原始数据 - FlowStatus.BlueSensorOriginalResp.Add(index, response); + RuntimeCache.BlueSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.BlueSensorResponseTags.Add(index, tags); + RuntimeCache.BlueSensorResponseTags.Add(index, tags); } } @@ -243,7 +243,7 @@ //左右两边接收到的数据时间差超过10s,认为不是同一次此指令返回的,舍弃 if (diffTime >= 10) return; - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; _eventAggregator.GetEvent().Publish(); } else @@ -273,13 +273,13 @@ } //保存听音数据 - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { - FlowStatus.RedSoundCaches.Add(pcm); + RuntimeCache.RedSoundCaches.Add(pcm); } else { - FlowStatus.BlueSoundCaches.Add(pcm); + RuntimeCache.BlueSoundCaches.Add(pcm); } //将pcm数据写入缓存 @@ -325,7 +325,7 @@ _dataModel.RightDeviceDataArray = doubleArrays.ToOneDimensionalArray(); } - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; "SerialPortServiceImpl".WriteLog(devCode + "数据处理完成"); } diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index cb3946e..5d33683 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -265,7 +265,7 @@ - + diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index 4c897c0..51294cd 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -81,23 +81,23 @@ break; case 11293: //数据采集 - if (!FlowStatus.IsHydrophone) + if (!RuntimeCache.IsHydrophone) { HandleCorrelatorData(deviceId, tags); } break; case 30: - if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) + if (RuntimeCache.IsHydrophone && RuntimeCache.CanCollectData) { Application.Current.Dispatcher.Invoke(delegate { //显示点名弹窗 - if (!FlowStatus.IsShowing) + if (!RuntimeCache.IsShowing) { //因为是广播发的数据,所以会收到两条回复,但是只需要显示一次对话框 _eventAggregator.GetEvent().Publish(); - FlowStatus.IsShowing = true; + RuntimeCache.IsShowing = true; } }); } @@ -108,23 +108,23 @@ { int index = receiveData[15]; //取出seq,确定收到的是第几包数据 - FlowStatus.SeqCaches.Add(index); + RuntimeCache.SeqCaches.Add(index); var response = BitConverter.ToString(receiveData).Replace("-", ""); //收集数据 if (deviceId.Equals(DevCode.Dev1)) { //原始数据 - FlowStatus.RedSensorOriginalResp.Add(index, response); + RuntimeCache.RedSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.RedSensorResponseTags.Add(index, tags); + RuntimeCache.RedSensorResponseTags.Add(index, tags); } else { //原始数据 - FlowStatus.BlueSensorOriginalResp.Add(index, response); + RuntimeCache.BlueSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.BlueSensorResponseTags.Add(index, tags); + RuntimeCache.BlueSensorResponseTags.Add(index, tags); } } @@ -243,7 +243,7 @@ //左右两边接收到的数据时间差超过10s,认为不是同一次此指令返回的,舍弃 if (diffTime >= 10) return; - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; _eventAggregator.GetEvent().Publish(); } else @@ -273,13 +273,13 @@ } //保存听音数据 - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { - FlowStatus.RedSoundCaches.Add(pcm); + RuntimeCache.RedSoundCaches.Add(pcm); } else { - FlowStatus.BlueSoundCaches.Add(pcm); + RuntimeCache.BlueSoundCaches.Add(pcm); } //将pcm数据写入缓存 @@ -325,7 +325,7 @@ _dataModel.RightDeviceDataArray = doubleArrays.ToOneDimensionalArray(); } - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; "SerialPortServiceImpl".WriteLog(devCode + "数据处理完成"); } diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8def641..43f84fd 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -74,7 +74,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -88,7 +88,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -105,7 +105,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -118,7 +118,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -230,7 +230,7 @@ { if (RedSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev1); _redResponseTimer.Start(); @@ -245,7 +245,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev1}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.RedSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.RedSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -257,7 +257,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.RedSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.RedSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { @@ -314,7 +314,7 @@ { if (BlueSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev2); _blueResponseTimer.Start(); @@ -328,7 +328,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev2}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.BlueSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.BlueSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -340,7 +340,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.BlueSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.BlueSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index cb3946e..5d33683 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -265,7 +265,7 @@ - + diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index 4c897c0..51294cd 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -81,23 +81,23 @@ break; case 11293: //数据采集 - if (!FlowStatus.IsHydrophone) + if (!RuntimeCache.IsHydrophone) { HandleCorrelatorData(deviceId, tags); } break; case 30: - if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) + if (RuntimeCache.IsHydrophone && RuntimeCache.CanCollectData) { Application.Current.Dispatcher.Invoke(delegate { //显示点名弹窗 - if (!FlowStatus.IsShowing) + if (!RuntimeCache.IsShowing) { //因为是广播发的数据,所以会收到两条回复,但是只需要显示一次对话框 _eventAggregator.GetEvent().Publish(); - FlowStatus.IsShowing = true; + RuntimeCache.IsShowing = true; } }); } @@ -108,23 +108,23 @@ { int index = receiveData[15]; //取出seq,确定收到的是第几包数据 - FlowStatus.SeqCaches.Add(index); + RuntimeCache.SeqCaches.Add(index); var response = BitConverter.ToString(receiveData).Replace("-", ""); //收集数据 if (deviceId.Equals(DevCode.Dev1)) { //原始数据 - FlowStatus.RedSensorOriginalResp.Add(index, response); + RuntimeCache.RedSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.RedSensorResponseTags.Add(index, tags); + RuntimeCache.RedSensorResponseTags.Add(index, tags); } else { //原始数据 - FlowStatus.BlueSensorOriginalResp.Add(index, response); + RuntimeCache.BlueSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.BlueSensorResponseTags.Add(index, tags); + RuntimeCache.BlueSensorResponseTags.Add(index, tags); } } @@ -243,7 +243,7 @@ //左右两边接收到的数据时间差超过10s,认为不是同一次此指令返回的,舍弃 if (diffTime >= 10) return; - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; _eventAggregator.GetEvent().Publish(); } else @@ -273,13 +273,13 @@ } //保存听音数据 - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { - FlowStatus.RedSoundCaches.Add(pcm); + RuntimeCache.RedSoundCaches.Add(pcm); } else { - FlowStatus.BlueSoundCaches.Add(pcm); + RuntimeCache.BlueSoundCaches.Add(pcm); } //将pcm数据写入缓存 @@ -325,7 +325,7 @@ _dataModel.RightDeviceDataArray = doubleArrays.ToOneDimensionalArray(); } - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; "SerialPortServiceImpl".WriteLog(devCode + "数据处理完成"); } diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8def641..43f84fd 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -74,7 +74,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -88,7 +88,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -105,7 +105,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -118,7 +118,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -230,7 +230,7 @@ { if (RedSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev1); _redResponseTimer.Start(); @@ -245,7 +245,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev1}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.RedSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.RedSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -257,7 +257,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.RedSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.RedSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { @@ -314,7 +314,7 @@ { if (BlueSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev2); _blueResponseTimer.Start(); @@ -328,7 +328,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev2}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.BlueSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.BlueSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -340,7 +340,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.BlueSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.BlueSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { diff --git a/Correlator/Util/CommandSender.cs b/Correlator/Util/CommandSender.cs index afb3b85..5efc675 100644 --- a/Correlator/Util/CommandSender.cs +++ b/Correlator/Util/CommandSender.cs @@ -119,7 +119,7 @@ }; //获取时间(年-月-日-时-分-秒),年号-2000 - FlowStatus.HydrophoneWakeUpTimeBytes = new[] + RuntimeCache.HydrophoneWakeUpTimeBytes = new[] { CalendarHub.Year, CalendarHub.Mon, CalendarHub.Day, CalendarHub.Hor, CalendarHub.Min, CalendarHub.Sec }; @@ -127,9 +127,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data @@ -226,9 +226,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data @@ -318,9 +318,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index cb3946e..5d33683 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -265,7 +265,7 @@ - + diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index 4c897c0..51294cd 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -81,23 +81,23 @@ break; case 11293: //数据采集 - if (!FlowStatus.IsHydrophone) + if (!RuntimeCache.IsHydrophone) { HandleCorrelatorData(deviceId, tags); } break; case 30: - if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) + if (RuntimeCache.IsHydrophone && RuntimeCache.CanCollectData) { Application.Current.Dispatcher.Invoke(delegate { //显示点名弹窗 - if (!FlowStatus.IsShowing) + if (!RuntimeCache.IsShowing) { //因为是广播发的数据,所以会收到两条回复,但是只需要显示一次对话框 _eventAggregator.GetEvent().Publish(); - FlowStatus.IsShowing = true; + RuntimeCache.IsShowing = true; } }); } @@ -108,23 +108,23 @@ { int index = receiveData[15]; //取出seq,确定收到的是第几包数据 - FlowStatus.SeqCaches.Add(index); + RuntimeCache.SeqCaches.Add(index); var response = BitConverter.ToString(receiveData).Replace("-", ""); //收集数据 if (deviceId.Equals(DevCode.Dev1)) { //原始数据 - FlowStatus.RedSensorOriginalResp.Add(index, response); + RuntimeCache.RedSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.RedSensorResponseTags.Add(index, tags); + RuntimeCache.RedSensorResponseTags.Add(index, tags); } else { //原始数据 - FlowStatus.BlueSensorOriginalResp.Add(index, response); + RuntimeCache.BlueSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.BlueSensorResponseTags.Add(index, tags); + RuntimeCache.BlueSensorResponseTags.Add(index, tags); } } @@ -243,7 +243,7 @@ //左右两边接收到的数据时间差超过10s,认为不是同一次此指令返回的,舍弃 if (diffTime >= 10) return; - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; _eventAggregator.GetEvent().Publish(); } else @@ -273,13 +273,13 @@ } //保存听音数据 - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { - FlowStatus.RedSoundCaches.Add(pcm); + RuntimeCache.RedSoundCaches.Add(pcm); } else { - FlowStatus.BlueSoundCaches.Add(pcm); + RuntimeCache.BlueSoundCaches.Add(pcm); } //将pcm数据写入缓存 @@ -325,7 +325,7 @@ _dataModel.RightDeviceDataArray = doubleArrays.ToOneDimensionalArray(); } - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; "SerialPortServiceImpl".WriteLog(devCode + "数据处理完成"); } diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8def641..43f84fd 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -74,7 +74,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -88,7 +88,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -105,7 +105,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -118,7 +118,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -230,7 +230,7 @@ { if (RedSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev1); _redResponseTimer.Start(); @@ -245,7 +245,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev1}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.RedSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.RedSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -257,7 +257,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.RedSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.RedSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { @@ -314,7 +314,7 @@ { if (BlueSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev2); _blueResponseTimer.Start(); @@ -328,7 +328,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev2}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.BlueSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.BlueSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -340,7 +340,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.BlueSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.BlueSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { diff --git a/Correlator/Util/CommandSender.cs b/Correlator/Util/CommandSender.cs index afb3b85..5efc675 100644 --- a/Correlator/Util/CommandSender.cs +++ b/Correlator/Util/CommandSender.cs @@ -119,7 +119,7 @@ }; //获取时间(年-月-日-时-分-秒),年号-2000 - FlowStatus.HydrophoneWakeUpTimeBytes = new[] + RuntimeCache.HydrophoneWakeUpTimeBytes = new[] { CalendarHub.Year, CalendarHub.Mon, CalendarHub.Day, CalendarHub.Hor, CalendarHub.Min, CalendarHub.Sec }; @@ -127,9 +127,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data @@ -226,9 +226,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data @@ -318,9 +318,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data diff --git a/Correlator/Util/FlowStatus.cs b/Correlator/Util/FlowStatus.cs deleted file mode 100644 index 384caec..0000000 --- a/Correlator/Util/FlowStatus.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System.Collections.Generic; -using Correlator.Model; -using Correlator.SensorHubTag; - -namespace Correlator.Util -{ - /// - /// 业务流程个节点状态 - /// - public class FlowStatus - { - /// - /// 是否可以收集数据 - /// - public static bool CanCollectData = false; - - /// - /// 红色传感器是否正常 - /// - public static bool RedSensorIsEnable = false; - - /// - /// 蓝色传感器是否正常 - /// - public static bool BlueSensorIsEnable = false; - - /// - /// 采集到的数据 - /// - public static CorrelatorDataModel CorrelatorData; - - /// - /// 水听器模式 - /// - public static bool IsHydrophone = false; - - /// - /// 点名对话框是否已显示 - /// - public static bool IsShowing = false; - - /// - /// 数据包index - /// - public static readonly List SeqCaches = new List(); - - /// - /// 水听器下发唤醒指令时间戳 - /// - public static byte[] HydrophoneWakeUpTimeBytes = new byte[6]; - - /// - /// 水听器红色信号接收器原始数据 - /// - public static readonly Dictionary RedSensorOriginalResp = new Dictionary(); - - /// - /// 水听器红色信号接收器解析之后的Tags - /// - public static readonly Dictionary> RedSensorResponseTags = new Dictionary>(); - - /// - /// 水听器红色信号接收器原始数据 - /// - public static readonly Dictionary BlueSensorOriginalResp = new Dictionary(); - - /// - /// 水听器蓝色信号接收器解析之后的Tags - /// - public static readonly Dictionary> BlueSensorResponseTags = new Dictionary>(); - - //听音数据 - public static readonly List RedSoundCaches = new List(); - public static readonly List BlueSoundCaches = new List(); - - /// - /// 正在听音的设备编号 - /// - public static string CurrentListenSoundDevCode = DevCode.Dev1; - - /// - /// 小于1K的音频文件全路径集合 - /// - public static readonly List SmallAudioFiles = new List(); - } -} \ No newline at end of file diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index cb3946e..5d33683 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -265,7 +265,7 @@ - + diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index 4c897c0..51294cd 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -81,23 +81,23 @@ break; case 11293: //数据采集 - if (!FlowStatus.IsHydrophone) + if (!RuntimeCache.IsHydrophone) { HandleCorrelatorData(deviceId, tags); } break; case 30: - if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) + if (RuntimeCache.IsHydrophone && RuntimeCache.CanCollectData) { Application.Current.Dispatcher.Invoke(delegate { //显示点名弹窗 - if (!FlowStatus.IsShowing) + if (!RuntimeCache.IsShowing) { //因为是广播发的数据,所以会收到两条回复,但是只需要显示一次对话框 _eventAggregator.GetEvent().Publish(); - FlowStatus.IsShowing = true; + RuntimeCache.IsShowing = true; } }); } @@ -108,23 +108,23 @@ { int index = receiveData[15]; //取出seq,确定收到的是第几包数据 - FlowStatus.SeqCaches.Add(index); + RuntimeCache.SeqCaches.Add(index); var response = BitConverter.ToString(receiveData).Replace("-", ""); //收集数据 if (deviceId.Equals(DevCode.Dev1)) { //原始数据 - FlowStatus.RedSensorOriginalResp.Add(index, response); + RuntimeCache.RedSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.RedSensorResponseTags.Add(index, tags); + RuntimeCache.RedSensorResponseTags.Add(index, tags); } else { //原始数据 - FlowStatus.BlueSensorOriginalResp.Add(index, response); + RuntimeCache.BlueSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.BlueSensorResponseTags.Add(index, tags); + RuntimeCache.BlueSensorResponseTags.Add(index, tags); } } @@ -243,7 +243,7 @@ //左右两边接收到的数据时间差超过10s,认为不是同一次此指令返回的,舍弃 if (diffTime >= 10) return; - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; _eventAggregator.GetEvent().Publish(); } else @@ -273,13 +273,13 @@ } //保存听音数据 - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { - FlowStatus.RedSoundCaches.Add(pcm); + RuntimeCache.RedSoundCaches.Add(pcm); } else { - FlowStatus.BlueSoundCaches.Add(pcm); + RuntimeCache.BlueSoundCaches.Add(pcm); } //将pcm数据写入缓存 @@ -325,7 +325,7 @@ _dataModel.RightDeviceDataArray = doubleArrays.ToOneDimensionalArray(); } - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; "SerialPortServiceImpl".WriteLog(devCode + "数据处理完成"); } diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8def641..43f84fd 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -74,7 +74,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -88,7 +88,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -105,7 +105,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -118,7 +118,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -230,7 +230,7 @@ { if (RedSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev1); _redResponseTimer.Start(); @@ -245,7 +245,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev1}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.RedSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.RedSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -257,7 +257,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.RedSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.RedSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { @@ -314,7 +314,7 @@ { if (BlueSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev2); _blueResponseTimer.Start(); @@ -328,7 +328,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev2}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.BlueSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.BlueSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -340,7 +340,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.BlueSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.BlueSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { diff --git a/Correlator/Util/CommandSender.cs b/Correlator/Util/CommandSender.cs index afb3b85..5efc675 100644 --- a/Correlator/Util/CommandSender.cs +++ b/Correlator/Util/CommandSender.cs @@ -119,7 +119,7 @@ }; //获取时间(年-月-日-时-分-秒),年号-2000 - FlowStatus.HydrophoneWakeUpTimeBytes = new[] + RuntimeCache.HydrophoneWakeUpTimeBytes = new[] { CalendarHub.Year, CalendarHub.Mon, CalendarHub.Day, CalendarHub.Hor, CalendarHub.Min, CalendarHub.Sec }; @@ -127,9 +127,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data @@ -226,9 +226,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data @@ -318,9 +318,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data diff --git a/Correlator/Util/FlowStatus.cs b/Correlator/Util/FlowStatus.cs deleted file mode 100644 index 384caec..0000000 --- a/Correlator/Util/FlowStatus.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System.Collections.Generic; -using Correlator.Model; -using Correlator.SensorHubTag; - -namespace Correlator.Util -{ - /// - /// 业务流程个节点状态 - /// - public class FlowStatus - { - /// - /// 是否可以收集数据 - /// - public static bool CanCollectData = false; - - /// - /// 红色传感器是否正常 - /// - public static bool RedSensorIsEnable = false; - - /// - /// 蓝色传感器是否正常 - /// - public static bool BlueSensorIsEnable = false; - - /// - /// 采集到的数据 - /// - public static CorrelatorDataModel CorrelatorData; - - /// - /// 水听器模式 - /// - public static bool IsHydrophone = false; - - /// - /// 点名对话框是否已显示 - /// - public static bool IsShowing = false; - - /// - /// 数据包index - /// - public static readonly List SeqCaches = new List(); - - /// - /// 水听器下发唤醒指令时间戳 - /// - public static byte[] HydrophoneWakeUpTimeBytes = new byte[6]; - - /// - /// 水听器红色信号接收器原始数据 - /// - public static readonly Dictionary RedSensorOriginalResp = new Dictionary(); - - /// - /// 水听器红色信号接收器解析之后的Tags - /// - public static readonly Dictionary> RedSensorResponseTags = new Dictionary>(); - - /// - /// 水听器红色信号接收器原始数据 - /// - public static readonly Dictionary BlueSensorOriginalResp = new Dictionary(); - - /// - /// 水听器蓝色信号接收器解析之后的Tags - /// - public static readonly Dictionary> BlueSensorResponseTags = new Dictionary>(); - - //听音数据 - public static readonly List RedSoundCaches = new List(); - public static readonly List BlueSoundCaches = new List(); - - /// - /// 正在听音的设备编号 - /// - public static string CurrentListenSoundDevCode = DevCode.Dev1; - - /// - /// 小于1K的音频文件全路径集合 - /// - public static readonly List SmallAudioFiles = new List(); - } -} \ No newline at end of file diff --git a/Correlator/Util/MethodExtensions.cs b/Correlator/Util/MethodExtensions.cs index 7d742ce..a8b0136 100644 --- a/Correlator/Util/MethodExtensions.cs +++ b/Correlator/Util/MethodExtensions.cs @@ -741,7 +741,7 @@ /// public static int GetPageSize(this int count) { - return (count + 8 - 1) / 8; + return (count + RuntimeCache.PerPageItemCount - 1) / RuntimeCache.PerPageItemCount; } } } \ No newline at end of file diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index cb3946e..5d33683 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -265,7 +265,7 @@ - + diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index 4c897c0..51294cd 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -81,23 +81,23 @@ break; case 11293: //数据采集 - if (!FlowStatus.IsHydrophone) + if (!RuntimeCache.IsHydrophone) { HandleCorrelatorData(deviceId, tags); } break; case 30: - if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) + if (RuntimeCache.IsHydrophone && RuntimeCache.CanCollectData) { Application.Current.Dispatcher.Invoke(delegate { //显示点名弹窗 - if (!FlowStatus.IsShowing) + if (!RuntimeCache.IsShowing) { //因为是广播发的数据,所以会收到两条回复,但是只需要显示一次对话框 _eventAggregator.GetEvent().Publish(); - FlowStatus.IsShowing = true; + RuntimeCache.IsShowing = true; } }); } @@ -108,23 +108,23 @@ { int index = receiveData[15]; //取出seq,确定收到的是第几包数据 - FlowStatus.SeqCaches.Add(index); + RuntimeCache.SeqCaches.Add(index); var response = BitConverter.ToString(receiveData).Replace("-", ""); //收集数据 if (deviceId.Equals(DevCode.Dev1)) { //原始数据 - FlowStatus.RedSensorOriginalResp.Add(index, response); + RuntimeCache.RedSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.RedSensorResponseTags.Add(index, tags); + RuntimeCache.RedSensorResponseTags.Add(index, tags); } else { //原始数据 - FlowStatus.BlueSensorOriginalResp.Add(index, response); + RuntimeCache.BlueSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.BlueSensorResponseTags.Add(index, tags); + RuntimeCache.BlueSensorResponseTags.Add(index, tags); } } @@ -243,7 +243,7 @@ //左右两边接收到的数据时间差超过10s,认为不是同一次此指令返回的,舍弃 if (diffTime >= 10) return; - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; _eventAggregator.GetEvent().Publish(); } else @@ -273,13 +273,13 @@ } //保存听音数据 - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { - FlowStatus.RedSoundCaches.Add(pcm); + RuntimeCache.RedSoundCaches.Add(pcm); } else { - FlowStatus.BlueSoundCaches.Add(pcm); + RuntimeCache.BlueSoundCaches.Add(pcm); } //将pcm数据写入缓存 @@ -325,7 +325,7 @@ _dataModel.RightDeviceDataArray = doubleArrays.ToOneDimensionalArray(); } - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; "SerialPortServiceImpl".WriteLog(devCode + "数据处理完成"); } diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8def641..43f84fd 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -74,7 +74,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -88,7 +88,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -105,7 +105,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -118,7 +118,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -230,7 +230,7 @@ { if (RedSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev1); _redResponseTimer.Start(); @@ -245,7 +245,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev1}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.RedSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.RedSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -257,7 +257,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.RedSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.RedSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { @@ -314,7 +314,7 @@ { if (BlueSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev2); _blueResponseTimer.Start(); @@ -328,7 +328,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev2}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.BlueSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.BlueSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -340,7 +340,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.BlueSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.BlueSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { diff --git a/Correlator/Util/CommandSender.cs b/Correlator/Util/CommandSender.cs index afb3b85..5efc675 100644 --- a/Correlator/Util/CommandSender.cs +++ b/Correlator/Util/CommandSender.cs @@ -119,7 +119,7 @@ }; //获取时间(年-月-日-时-分-秒),年号-2000 - FlowStatus.HydrophoneWakeUpTimeBytes = new[] + RuntimeCache.HydrophoneWakeUpTimeBytes = new[] { CalendarHub.Year, CalendarHub.Mon, CalendarHub.Day, CalendarHub.Hor, CalendarHub.Min, CalendarHub.Sec }; @@ -127,9 +127,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data @@ -226,9 +226,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data @@ -318,9 +318,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data diff --git a/Correlator/Util/FlowStatus.cs b/Correlator/Util/FlowStatus.cs deleted file mode 100644 index 384caec..0000000 --- a/Correlator/Util/FlowStatus.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System.Collections.Generic; -using Correlator.Model; -using Correlator.SensorHubTag; - -namespace Correlator.Util -{ - /// - /// 业务流程个节点状态 - /// - public class FlowStatus - { - /// - /// 是否可以收集数据 - /// - public static bool CanCollectData = false; - - /// - /// 红色传感器是否正常 - /// - public static bool RedSensorIsEnable = false; - - /// - /// 蓝色传感器是否正常 - /// - public static bool BlueSensorIsEnable = false; - - /// - /// 采集到的数据 - /// - public static CorrelatorDataModel CorrelatorData; - - /// - /// 水听器模式 - /// - public static bool IsHydrophone = false; - - /// - /// 点名对话框是否已显示 - /// - public static bool IsShowing = false; - - /// - /// 数据包index - /// - public static readonly List SeqCaches = new List(); - - /// - /// 水听器下发唤醒指令时间戳 - /// - public static byte[] HydrophoneWakeUpTimeBytes = new byte[6]; - - /// - /// 水听器红色信号接收器原始数据 - /// - public static readonly Dictionary RedSensorOriginalResp = new Dictionary(); - - /// - /// 水听器红色信号接收器解析之后的Tags - /// - public static readonly Dictionary> RedSensorResponseTags = new Dictionary>(); - - /// - /// 水听器红色信号接收器原始数据 - /// - public static readonly Dictionary BlueSensorOriginalResp = new Dictionary(); - - /// - /// 水听器蓝色信号接收器解析之后的Tags - /// - public static readonly Dictionary> BlueSensorResponseTags = new Dictionary>(); - - //听音数据 - public static readonly List RedSoundCaches = new List(); - public static readonly List BlueSoundCaches = new List(); - - /// - /// 正在听音的设备编号 - /// - public static string CurrentListenSoundDevCode = DevCode.Dev1; - - /// - /// 小于1K的音频文件全路径集合 - /// - public static readonly List SmallAudioFiles = new List(); - } -} \ No newline at end of file diff --git a/Correlator/Util/MethodExtensions.cs b/Correlator/Util/MethodExtensions.cs index 7d742ce..a8b0136 100644 --- a/Correlator/Util/MethodExtensions.cs +++ b/Correlator/Util/MethodExtensions.cs @@ -741,7 +741,7 @@ /// public static int GetPageSize(this int count) { - return (count + 8 - 1) / 8; + return (count + RuntimeCache.PerPageItemCount - 1) / RuntimeCache.PerPageItemCount; } } } \ No newline at end of file diff --git a/Correlator/Util/RuntimeCache.cs b/Correlator/Util/RuntimeCache.cs new file mode 100644 index 0000000..e91619c --- /dev/null +++ b/Correlator/Util/RuntimeCache.cs @@ -0,0 +1,91 @@ +using System.Collections.Generic; +using Correlator.Model; +using Correlator.SensorHubTag; + +namespace Correlator.Util +{ + /// + /// 业务流程个节点状态 + /// + public class RuntimeCache + { + /// + /// 是否可以收集数据 + /// + public static bool CanCollectData = false; + + /// + /// 红色传感器是否正常 + /// + public static bool RedSensorIsEnable = false; + + /// + /// 蓝色传感器是否正常 + /// + public static bool BlueSensorIsEnable = false; + + /// + /// 采集到的数据 + /// + public static CorrelatorDataModel CorrelatorData; + + /// + /// 水听器模式 + /// + public static bool IsHydrophone = false; + + /// + /// 点名对话框是否已显示 + /// + public static bool IsShowing = false; + + /// + /// 数据包index + /// + public static readonly List SeqCaches = new List(); + + /// + /// 水听器下发唤醒指令时间戳 + /// + public static byte[] HydrophoneWakeUpTimeBytes = new byte[6]; + + /// + /// 水听器红色信号接收器原始数据 + /// + public static readonly Dictionary RedSensorOriginalResp = new Dictionary(); + + /// + /// 水听器红色信号接收器解析之后的Tags + /// + public static readonly Dictionary> RedSensorResponseTags = new Dictionary>(); + + /// + /// 水听器红色信号接收器原始数据 + /// + public static readonly Dictionary BlueSensorOriginalResp = new Dictionary(); + + /// + /// 水听器蓝色信号接收器解析之后的Tags + /// + public static readonly Dictionary> BlueSensorResponseTags = new Dictionary>(); + + //听音数据 + public static readonly List RedSoundCaches = new List(); + public static readonly List BlueSoundCaches = new List(); + + /// + /// 正在听音的设备编号 + /// + public static string CurrentListenSoundDevCode = DevCode.Dev1; + + /// + /// 小于1K的音频文件全路径集合 + /// + public static readonly List SmallAudioFiles = new List(); + + /// + /// 列表每页条目数 + /// + public const int PerPageItemCount = 10; + } +} \ No newline at end of file diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index cb3946e..5d33683 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -265,7 +265,7 @@ - + diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index 4c897c0..51294cd 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -81,23 +81,23 @@ break; case 11293: //数据采集 - if (!FlowStatus.IsHydrophone) + if (!RuntimeCache.IsHydrophone) { HandleCorrelatorData(deviceId, tags); } break; case 30: - if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) + if (RuntimeCache.IsHydrophone && RuntimeCache.CanCollectData) { Application.Current.Dispatcher.Invoke(delegate { //显示点名弹窗 - if (!FlowStatus.IsShowing) + if (!RuntimeCache.IsShowing) { //因为是广播发的数据,所以会收到两条回复,但是只需要显示一次对话框 _eventAggregator.GetEvent().Publish(); - FlowStatus.IsShowing = true; + RuntimeCache.IsShowing = true; } }); } @@ -108,23 +108,23 @@ { int index = receiveData[15]; //取出seq,确定收到的是第几包数据 - FlowStatus.SeqCaches.Add(index); + RuntimeCache.SeqCaches.Add(index); var response = BitConverter.ToString(receiveData).Replace("-", ""); //收集数据 if (deviceId.Equals(DevCode.Dev1)) { //原始数据 - FlowStatus.RedSensorOriginalResp.Add(index, response); + RuntimeCache.RedSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.RedSensorResponseTags.Add(index, tags); + RuntimeCache.RedSensorResponseTags.Add(index, tags); } else { //原始数据 - FlowStatus.BlueSensorOriginalResp.Add(index, response); + RuntimeCache.BlueSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.BlueSensorResponseTags.Add(index, tags); + RuntimeCache.BlueSensorResponseTags.Add(index, tags); } } @@ -243,7 +243,7 @@ //左右两边接收到的数据时间差超过10s,认为不是同一次此指令返回的,舍弃 if (diffTime >= 10) return; - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; _eventAggregator.GetEvent().Publish(); } else @@ -273,13 +273,13 @@ } //保存听音数据 - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { - FlowStatus.RedSoundCaches.Add(pcm); + RuntimeCache.RedSoundCaches.Add(pcm); } else { - FlowStatus.BlueSoundCaches.Add(pcm); + RuntimeCache.BlueSoundCaches.Add(pcm); } //将pcm数据写入缓存 @@ -325,7 +325,7 @@ _dataModel.RightDeviceDataArray = doubleArrays.ToOneDimensionalArray(); } - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; "SerialPortServiceImpl".WriteLog(devCode + "数据处理完成"); } diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8def641..43f84fd 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -74,7 +74,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -88,7 +88,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -105,7 +105,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -118,7 +118,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -230,7 +230,7 @@ { if (RedSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev1); _redResponseTimer.Start(); @@ -245,7 +245,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev1}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.RedSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.RedSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -257,7 +257,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.RedSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.RedSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { @@ -314,7 +314,7 @@ { if (BlueSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev2); _blueResponseTimer.Start(); @@ -328,7 +328,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev2}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.BlueSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.BlueSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -340,7 +340,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.BlueSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.BlueSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { diff --git a/Correlator/Util/CommandSender.cs b/Correlator/Util/CommandSender.cs index afb3b85..5efc675 100644 --- a/Correlator/Util/CommandSender.cs +++ b/Correlator/Util/CommandSender.cs @@ -119,7 +119,7 @@ }; //获取时间(年-月-日-时-分-秒),年号-2000 - FlowStatus.HydrophoneWakeUpTimeBytes = new[] + RuntimeCache.HydrophoneWakeUpTimeBytes = new[] { CalendarHub.Year, CalendarHub.Mon, CalendarHub.Day, CalendarHub.Hor, CalendarHub.Min, CalendarHub.Sec }; @@ -127,9 +127,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data @@ -226,9 +226,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data @@ -318,9 +318,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data diff --git a/Correlator/Util/FlowStatus.cs b/Correlator/Util/FlowStatus.cs deleted file mode 100644 index 384caec..0000000 --- a/Correlator/Util/FlowStatus.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System.Collections.Generic; -using Correlator.Model; -using Correlator.SensorHubTag; - -namespace Correlator.Util -{ - /// - /// 业务流程个节点状态 - /// - public class FlowStatus - { - /// - /// 是否可以收集数据 - /// - public static bool CanCollectData = false; - - /// - /// 红色传感器是否正常 - /// - public static bool RedSensorIsEnable = false; - - /// - /// 蓝色传感器是否正常 - /// - public static bool BlueSensorIsEnable = false; - - /// - /// 采集到的数据 - /// - public static CorrelatorDataModel CorrelatorData; - - /// - /// 水听器模式 - /// - public static bool IsHydrophone = false; - - /// - /// 点名对话框是否已显示 - /// - public static bool IsShowing = false; - - /// - /// 数据包index - /// - public static readonly List SeqCaches = new List(); - - /// - /// 水听器下发唤醒指令时间戳 - /// - public static byte[] HydrophoneWakeUpTimeBytes = new byte[6]; - - /// - /// 水听器红色信号接收器原始数据 - /// - public static readonly Dictionary RedSensorOriginalResp = new Dictionary(); - - /// - /// 水听器红色信号接收器解析之后的Tags - /// - public static readonly Dictionary> RedSensorResponseTags = new Dictionary>(); - - /// - /// 水听器红色信号接收器原始数据 - /// - public static readonly Dictionary BlueSensorOriginalResp = new Dictionary(); - - /// - /// 水听器蓝色信号接收器解析之后的Tags - /// - public static readonly Dictionary> BlueSensorResponseTags = new Dictionary>(); - - //听音数据 - public static readonly List RedSoundCaches = new List(); - public static readonly List BlueSoundCaches = new List(); - - /// - /// 正在听音的设备编号 - /// - public static string CurrentListenSoundDevCode = DevCode.Dev1; - - /// - /// 小于1K的音频文件全路径集合 - /// - public static readonly List SmallAudioFiles = new List(); - } -} \ No newline at end of file diff --git a/Correlator/Util/MethodExtensions.cs b/Correlator/Util/MethodExtensions.cs index 7d742ce..a8b0136 100644 --- a/Correlator/Util/MethodExtensions.cs +++ b/Correlator/Util/MethodExtensions.cs @@ -741,7 +741,7 @@ /// public static int GetPageSize(this int count) { - return (count + 8 - 1) / 8; + return (count + RuntimeCache.PerPageItemCount - 1) / RuntimeCache.PerPageItemCount; } } } \ No newline at end of file diff --git a/Correlator/Util/RuntimeCache.cs b/Correlator/Util/RuntimeCache.cs new file mode 100644 index 0000000..e91619c --- /dev/null +++ b/Correlator/Util/RuntimeCache.cs @@ -0,0 +1,91 @@ +using System.Collections.Generic; +using Correlator.Model; +using Correlator.SensorHubTag; + +namespace Correlator.Util +{ + /// + /// 业务流程个节点状态 + /// + public class RuntimeCache + { + /// + /// 是否可以收集数据 + /// + public static bool CanCollectData = false; + + /// + /// 红色传感器是否正常 + /// + public static bool RedSensorIsEnable = false; + + /// + /// 蓝色传感器是否正常 + /// + public static bool BlueSensorIsEnable = false; + + /// + /// 采集到的数据 + /// + public static CorrelatorDataModel CorrelatorData; + + /// + /// 水听器模式 + /// + public static bool IsHydrophone = false; + + /// + /// 点名对话框是否已显示 + /// + public static bool IsShowing = false; + + /// + /// 数据包index + /// + public static readonly List SeqCaches = new List(); + + /// + /// 水听器下发唤醒指令时间戳 + /// + public static byte[] HydrophoneWakeUpTimeBytes = new byte[6]; + + /// + /// 水听器红色信号接收器原始数据 + /// + public static readonly Dictionary RedSensorOriginalResp = new Dictionary(); + + /// + /// 水听器红色信号接收器解析之后的Tags + /// + public static readonly Dictionary> RedSensorResponseTags = new Dictionary>(); + + /// + /// 水听器红色信号接收器原始数据 + /// + public static readonly Dictionary BlueSensorOriginalResp = new Dictionary(); + + /// + /// 水听器蓝色信号接收器解析之后的Tags + /// + public static readonly Dictionary> BlueSensorResponseTags = new Dictionary>(); + + //听音数据 + public static readonly List RedSoundCaches = new List(); + public static readonly List BlueSoundCaches = new List(); + + /// + /// 正在听音的设备编号 + /// + public static string CurrentListenSoundDevCode = DevCode.Dev1; + + /// + /// 小于1K的音频文件全路径集合 + /// + public static readonly List SmallAudioFiles = new List(); + + /// + /// 列表每页条目数 + /// + public const int PerPageItemCount = 10; + } +} \ No newline at end of file diff --git a/Correlator/ViewModels/AudioFileViewModel.cs b/Correlator/ViewModels/AudioFileViewModel.cs index f522a7a..1846bcc 100644 --- a/Correlator/ViewModels/AudioFileViewModel.cs +++ b/Correlator/ViewModels/AudioFileViewModel.cs @@ -142,7 +142,7 @@ //刷新数据 _totalFiles = GetTotalAudioFiles(); MaxPage = _totalFiles.Count.GetPageSize(); - AudioFiles = _totalFiles.Take(8).ToList(); + AudioFiles = _totalFiles.Take(RuntimeCache.PerPageItemCount).ToList(); } catch (IOException) { @@ -154,7 +154,10 @@ PageUpdatedCmd = new DelegateCommand>(args => { - AudioFiles = _totalFiles.Skip((args.Info - 1) * 8).Take(8).ToList(); + AudioFiles = _totalFiles + .Skip((args.Info - 1) * RuntimeCache.PerPageItemCount) + .Take(RuntimeCache.PerPageItemCount) + .ToList(); }); } @@ -171,7 +174,7 @@ { _totalFiles = GetTotalAudioFiles(); MaxPage = _totalFiles.Count.GetPageSize(); - AudioFiles = _totalFiles.Take(8).ToList(); + AudioFiles = _totalFiles.Take(RuntimeCache.PerPageItemCount).ToList(); } private static List GetTotalAudioFiles() @@ -184,7 +187,7 @@ { if (file.Length < 1024) { - FlowStatus.SmallAudioFiles.Add(file.FullName); + RuntimeCache.SmallAudioFiles.Add(file.FullName); } else { diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index cb3946e..5d33683 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -265,7 +265,7 @@ - + diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index 4c897c0..51294cd 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -81,23 +81,23 @@ break; case 11293: //数据采集 - if (!FlowStatus.IsHydrophone) + if (!RuntimeCache.IsHydrophone) { HandleCorrelatorData(deviceId, tags); } break; case 30: - if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) + if (RuntimeCache.IsHydrophone && RuntimeCache.CanCollectData) { Application.Current.Dispatcher.Invoke(delegate { //显示点名弹窗 - if (!FlowStatus.IsShowing) + if (!RuntimeCache.IsShowing) { //因为是广播发的数据,所以会收到两条回复,但是只需要显示一次对话框 _eventAggregator.GetEvent().Publish(); - FlowStatus.IsShowing = true; + RuntimeCache.IsShowing = true; } }); } @@ -108,23 +108,23 @@ { int index = receiveData[15]; //取出seq,确定收到的是第几包数据 - FlowStatus.SeqCaches.Add(index); + RuntimeCache.SeqCaches.Add(index); var response = BitConverter.ToString(receiveData).Replace("-", ""); //收集数据 if (deviceId.Equals(DevCode.Dev1)) { //原始数据 - FlowStatus.RedSensorOriginalResp.Add(index, response); + RuntimeCache.RedSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.RedSensorResponseTags.Add(index, tags); + RuntimeCache.RedSensorResponseTags.Add(index, tags); } else { //原始数据 - FlowStatus.BlueSensorOriginalResp.Add(index, response); + RuntimeCache.BlueSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.BlueSensorResponseTags.Add(index, tags); + RuntimeCache.BlueSensorResponseTags.Add(index, tags); } } @@ -243,7 +243,7 @@ //左右两边接收到的数据时间差超过10s,认为不是同一次此指令返回的,舍弃 if (diffTime >= 10) return; - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; _eventAggregator.GetEvent().Publish(); } else @@ -273,13 +273,13 @@ } //保存听音数据 - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { - FlowStatus.RedSoundCaches.Add(pcm); + RuntimeCache.RedSoundCaches.Add(pcm); } else { - FlowStatus.BlueSoundCaches.Add(pcm); + RuntimeCache.BlueSoundCaches.Add(pcm); } //将pcm数据写入缓存 @@ -325,7 +325,7 @@ _dataModel.RightDeviceDataArray = doubleArrays.ToOneDimensionalArray(); } - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; "SerialPortServiceImpl".WriteLog(devCode + "数据处理完成"); } diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8def641..43f84fd 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -74,7 +74,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -88,7 +88,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -105,7 +105,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -118,7 +118,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -230,7 +230,7 @@ { if (RedSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev1); _redResponseTimer.Start(); @@ -245,7 +245,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev1}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.RedSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.RedSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -257,7 +257,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.RedSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.RedSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { @@ -314,7 +314,7 @@ { if (BlueSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev2); _blueResponseTimer.Start(); @@ -328,7 +328,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev2}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.BlueSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.BlueSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -340,7 +340,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.BlueSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.BlueSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { diff --git a/Correlator/Util/CommandSender.cs b/Correlator/Util/CommandSender.cs index afb3b85..5efc675 100644 --- a/Correlator/Util/CommandSender.cs +++ b/Correlator/Util/CommandSender.cs @@ -119,7 +119,7 @@ }; //获取时间(年-月-日-时-分-秒),年号-2000 - FlowStatus.HydrophoneWakeUpTimeBytes = new[] + RuntimeCache.HydrophoneWakeUpTimeBytes = new[] { CalendarHub.Year, CalendarHub.Mon, CalendarHub.Day, CalendarHub.Hor, CalendarHub.Min, CalendarHub.Sec }; @@ -127,9 +127,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data @@ -226,9 +226,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data @@ -318,9 +318,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data diff --git a/Correlator/Util/FlowStatus.cs b/Correlator/Util/FlowStatus.cs deleted file mode 100644 index 384caec..0000000 --- a/Correlator/Util/FlowStatus.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System.Collections.Generic; -using Correlator.Model; -using Correlator.SensorHubTag; - -namespace Correlator.Util -{ - /// - /// 业务流程个节点状态 - /// - public class FlowStatus - { - /// - /// 是否可以收集数据 - /// - public static bool CanCollectData = false; - - /// - /// 红色传感器是否正常 - /// - public static bool RedSensorIsEnable = false; - - /// - /// 蓝色传感器是否正常 - /// - public static bool BlueSensorIsEnable = false; - - /// - /// 采集到的数据 - /// - public static CorrelatorDataModel CorrelatorData; - - /// - /// 水听器模式 - /// - public static bool IsHydrophone = false; - - /// - /// 点名对话框是否已显示 - /// - public static bool IsShowing = false; - - /// - /// 数据包index - /// - public static readonly List SeqCaches = new List(); - - /// - /// 水听器下发唤醒指令时间戳 - /// - public static byte[] HydrophoneWakeUpTimeBytes = new byte[6]; - - /// - /// 水听器红色信号接收器原始数据 - /// - public static readonly Dictionary RedSensorOriginalResp = new Dictionary(); - - /// - /// 水听器红色信号接收器解析之后的Tags - /// - public static readonly Dictionary> RedSensorResponseTags = new Dictionary>(); - - /// - /// 水听器红色信号接收器原始数据 - /// - public static readonly Dictionary BlueSensorOriginalResp = new Dictionary(); - - /// - /// 水听器蓝色信号接收器解析之后的Tags - /// - public static readonly Dictionary> BlueSensorResponseTags = new Dictionary>(); - - //听音数据 - public static readonly List RedSoundCaches = new List(); - public static readonly List BlueSoundCaches = new List(); - - /// - /// 正在听音的设备编号 - /// - public static string CurrentListenSoundDevCode = DevCode.Dev1; - - /// - /// 小于1K的音频文件全路径集合 - /// - public static readonly List SmallAudioFiles = new List(); - } -} \ No newline at end of file diff --git a/Correlator/Util/MethodExtensions.cs b/Correlator/Util/MethodExtensions.cs index 7d742ce..a8b0136 100644 --- a/Correlator/Util/MethodExtensions.cs +++ b/Correlator/Util/MethodExtensions.cs @@ -741,7 +741,7 @@ /// public static int GetPageSize(this int count) { - return (count + 8 - 1) / 8; + return (count + RuntimeCache.PerPageItemCount - 1) / RuntimeCache.PerPageItemCount; } } } \ No newline at end of file diff --git a/Correlator/Util/RuntimeCache.cs b/Correlator/Util/RuntimeCache.cs new file mode 100644 index 0000000..e91619c --- /dev/null +++ b/Correlator/Util/RuntimeCache.cs @@ -0,0 +1,91 @@ +using System.Collections.Generic; +using Correlator.Model; +using Correlator.SensorHubTag; + +namespace Correlator.Util +{ + /// + /// 业务流程个节点状态 + /// + public class RuntimeCache + { + /// + /// 是否可以收集数据 + /// + public static bool CanCollectData = false; + + /// + /// 红色传感器是否正常 + /// + public static bool RedSensorIsEnable = false; + + /// + /// 蓝色传感器是否正常 + /// + public static bool BlueSensorIsEnable = false; + + /// + /// 采集到的数据 + /// + public static CorrelatorDataModel CorrelatorData; + + /// + /// 水听器模式 + /// + public static bool IsHydrophone = false; + + /// + /// 点名对话框是否已显示 + /// + public static bool IsShowing = false; + + /// + /// 数据包index + /// + public static readonly List SeqCaches = new List(); + + /// + /// 水听器下发唤醒指令时间戳 + /// + public static byte[] HydrophoneWakeUpTimeBytes = new byte[6]; + + /// + /// 水听器红色信号接收器原始数据 + /// + public static readonly Dictionary RedSensorOriginalResp = new Dictionary(); + + /// + /// 水听器红色信号接收器解析之后的Tags + /// + public static readonly Dictionary> RedSensorResponseTags = new Dictionary>(); + + /// + /// 水听器红色信号接收器原始数据 + /// + public static readonly Dictionary BlueSensorOriginalResp = new Dictionary(); + + /// + /// 水听器蓝色信号接收器解析之后的Tags + /// + public static readonly Dictionary> BlueSensorResponseTags = new Dictionary>(); + + //听音数据 + public static readonly List RedSoundCaches = new List(); + public static readonly List BlueSoundCaches = new List(); + + /// + /// 正在听音的设备编号 + /// + public static string CurrentListenSoundDevCode = DevCode.Dev1; + + /// + /// 小于1K的音频文件全路径集合 + /// + public static readonly List SmallAudioFiles = new List(); + + /// + /// 列表每页条目数 + /// + public const int PerPageItemCount = 10; + } +} \ No newline at end of file diff --git a/Correlator/ViewModels/AudioFileViewModel.cs b/Correlator/ViewModels/AudioFileViewModel.cs index f522a7a..1846bcc 100644 --- a/Correlator/ViewModels/AudioFileViewModel.cs +++ b/Correlator/ViewModels/AudioFileViewModel.cs @@ -142,7 +142,7 @@ //刷新数据 _totalFiles = GetTotalAudioFiles(); MaxPage = _totalFiles.Count.GetPageSize(); - AudioFiles = _totalFiles.Take(8).ToList(); + AudioFiles = _totalFiles.Take(RuntimeCache.PerPageItemCount).ToList(); } catch (IOException) { @@ -154,7 +154,10 @@ PageUpdatedCmd = new DelegateCommand>(args => { - AudioFiles = _totalFiles.Skip((args.Info - 1) * 8).Take(8).ToList(); + AudioFiles = _totalFiles + .Skip((args.Info - 1) * RuntimeCache.PerPageItemCount) + .Take(RuntimeCache.PerPageItemCount) + .ToList(); }); } @@ -171,7 +174,7 @@ { _totalFiles = GetTotalAudioFiles(); MaxPage = _totalFiles.Count.GetPageSize(); - AudioFiles = _totalFiles.Take(8).ToList(); + AudioFiles = _totalFiles.Take(RuntimeCache.PerPageItemCount).ToList(); } private static List GetTotalAudioFiles() @@ -184,7 +187,7 @@ { if (file.Length < 1024) { - FlowStatus.SmallAudioFiles.Add(file.FullName); + RuntimeCache.SmallAudioFiles.Add(file.FullName); } else { diff --git a/Correlator/ViewModels/AuditionViewModel.cs b/Correlator/ViewModels/AuditionViewModel.cs index b334ec9..7945aa7 100644 --- a/Correlator/ViewModels/AuditionViewModel.cs +++ b/Correlator/ViewModels/AuditionViewModel.cs @@ -94,7 +94,7 @@ sts[outIndex++] = BitConverter.ToInt16(buffer, i) / 32768f; } - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { eventAggregator.GetEvent().Publish(sts); } @@ -117,7 +117,7 @@ CommandSender.SendSoundStopCmd(_serialPortService.Sp, _isRedSensor ? DevCode.Dev1 : DevCode.Dev2); _audioService.Stop(); _isStartRecording = false; - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { //TODO 保存原始PCM数据到文件 // using (var fs = new FileStream("C:\\Users\\Administrator\\Desktop\\input.pcm", @@ -129,13 +129,13 @@ // } // } - FlowStatus.RedSoundCaches.SaveSoundData(); - FlowStatus.RedSoundCaches.Clear(); + RuntimeCache.RedSoundCaches.SaveSoundData(); + RuntimeCache.RedSoundCaches.Clear(); } else { - FlowStatus.BlueSoundCaches.SaveSoundData(); - FlowStatus.BlueSoundCaches.Clear(); + RuntimeCache.BlueSoundCaches.SaveSoundData(); + RuntimeCache.BlueSoundCaches.Clear(); } //波形图停止模拟 @@ -146,7 +146,7 @@ var devCode = _isRedSensor ? DevCode.Dev1 : DevCode.Dev2; CommandSender.SendSoundCollectCmd(_serialPortService.Sp, devCode); - FlowStatus.CurrentListenSoundDevCode = devCode; + RuntimeCache.CurrentListenSoundDevCode = devCode; _audioService.Start(devCode); _isStartRecording = true; diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index cb3946e..5d33683 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -265,7 +265,7 @@ - + diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index 4c897c0..51294cd 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -81,23 +81,23 @@ break; case 11293: //数据采集 - if (!FlowStatus.IsHydrophone) + if (!RuntimeCache.IsHydrophone) { HandleCorrelatorData(deviceId, tags); } break; case 30: - if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) + if (RuntimeCache.IsHydrophone && RuntimeCache.CanCollectData) { Application.Current.Dispatcher.Invoke(delegate { //显示点名弹窗 - if (!FlowStatus.IsShowing) + if (!RuntimeCache.IsShowing) { //因为是广播发的数据,所以会收到两条回复,但是只需要显示一次对话框 _eventAggregator.GetEvent().Publish(); - FlowStatus.IsShowing = true; + RuntimeCache.IsShowing = true; } }); } @@ -108,23 +108,23 @@ { int index = receiveData[15]; //取出seq,确定收到的是第几包数据 - FlowStatus.SeqCaches.Add(index); + RuntimeCache.SeqCaches.Add(index); var response = BitConverter.ToString(receiveData).Replace("-", ""); //收集数据 if (deviceId.Equals(DevCode.Dev1)) { //原始数据 - FlowStatus.RedSensorOriginalResp.Add(index, response); + RuntimeCache.RedSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.RedSensorResponseTags.Add(index, tags); + RuntimeCache.RedSensorResponseTags.Add(index, tags); } else { //原始数据 - FlowStatus.BlueSensorOriginalResp.Add(index, response); + RuntimeCache.BlueSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.BlueSensorResponseTags.Add(index, tags); + RuntimeCache.BlueSensorResponseTags.Add(index, tags); } } @@ -243,7 +243,7 @@ //左右两边接收到的数据时间差超过10s,认为不是同一次此指令返回的,舍弃 if (diffTime >= 10) return; - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; _eventAggregator.GetEvent().Publish(); } else @@ -273,13 +273,13 @@ } //保存听音数据 - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { - FlowStatus.RedSoundCaches.Add(pcm); + RuntimeCache.RedSoundCaches.Add(pcm); } else { - FlowStatus.BlueSoundCaches.Add(pcm); + RuntimeCache.BlueSoundCaches.Add(pcm); } //将pcm数据写入缓存 @@ -325,7 +325,7 @@ _dataModel.RightDeviceDataArray = doubleArrays.ToOneDimensionalArray(); } - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; "SerialPortServiceImpl".WriteLog(devCode + "数据处理完成"); } diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8def641..43f84fd 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -74,7 +74,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -88,7 +88,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -105,7 +105,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -118,7 +118,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -230,7 +230,7 @@ { if (RedSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev1); _redResponseTimer.Start(); @@ -245,7 +245,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev1}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.RedSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.RedSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -257,7 +257,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.RedSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.RedSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { @@ -314,7 +314,7 @@ { if (BlueSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev2); _blueResponseTimer.Start(); @@ -328,7 +328,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev2}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.BlueSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.BlueSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -340,7 +340,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.BlueSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.BlueSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { diff --git a/Correlator/Util/CommandSender.cs b/Correlator/Util/CommandSender.cs index afb3b85..5efc675 100644 --- a/Correlator/Util/CommandSender.cs +++ b/Correlator/Util/CommandSender.cs @@ -119,7 +119,7 @@ }; //获取时间(年-月-日-时-分-秒),年号-2000 - FlowStatus.HydrophoneWakeUpTimeBytes = new[] + RuntimeCache.HydrophoneWakeUpTimeBytes = new[] { CalendarHub.Year, CalendarHub.Mon, CalendarHub.Day, CalendarHub.Hor, CalendarHub.Min, CalendarHub.Sec }; @@ -127,9 +127,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data @@ -226,9 +226,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data @@ -318,9 +318,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data diff --git a/Correlator/Util/FlowStatus.cs b/Correlator/Util/FlowStatus.cs deleted file mode 100644 index 384caec..0000000 --- a/Correlator/Util/FlowStatus.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System.Collections.Generic; -using Correlator.Model; -using Correlator.SensorHubTag; - -namespace Correlator.Util -{ - /// - /// 业务流程个节点状态 - /// - public class FlowStatus - { - /// - /// 是否可以收集数据 - /// - public static bool CanCollectData = false; - - /// - /// 红色传感器是否正常 - /// - public static bool RedSensorIsEnable = false; - - /// - /// 蓝色传感器是否正常 - /// - public static bool BlueSensorIsEnable = false; - - /// - /// 采集到的数据 - /// - public static CorrelatorDataModel CorrelatorData; - - /// - /// 水听器模式 - /// - public static bool IsHydrophone = false; - - /// - /// 点名对话框是否已显示 - /// - public static bool IsShowing = false; - - /// - /// 数据包index - /// - public static readonly List SeqCaches = new List(); - - /// - /// 水听器下发唤醒指令时间戳 - /// - public static byte[] HydrophoneWakeUpTimeBytes = new byte[6]; - - /// - /// 水听器红色信号接收器原始数据 - /// - public static readonly Dictionary RedSensorOriginalResp = new Dictionary(); - - /// - /// 水听器红色信号接收器解析之后的Tags - /// - public static readonly Dictionary> RedSensorResponseTags = new Dictionary>(); - - /// - /// 水听器红色信号接收器原始数据 - /// - public static readonly Dictionary BlueSensorOriginalResp = new Dictionary(); - - /// - /// 水听器蓝色信号接收器解析之后的Tags - /// - public static readonly Dictionary> BlueSensorResponseTags = new Dictionary>(); - - //听音数据 - public static readonly List RedSoundCaches = new List(); - public static readonly List BlueSoundCaches = new List(); - - /// - /// 正在听音的设备编号 - /// - public static string CurrentListenSoundDevCode = DevCode.Dev1; - - /// - /// 小于1K的音频文件全路径集合 - /// - public static readonly List SmallAudioFiles = new List(); - } -} \ No newline at end of file diff --git a/Correlator/Util/MethodExtensions.cs b/Correlator/Util/MethodExtensions.cs index 7d742ce..a8b0136 100644 --- a/Correlator/Util/MethodExtensions.cs +++ b/Correlator/Util/MethodExtensions.cs @@ -741,7 +741,7 @@ /// public static int GetPageSize(this int count) { - return (count + 8 - 1) / 8; + return (count + RuntimeCache.PerPageItemCount - 1) / RuntimeCache.PerPageItemCount; } } } \ No newline at end of file diff --git a/Correlator/Util/RuntimeCache.cs b/Correlator/Util/RuntimeCache.cs new file mode 100644 index 0000000..e91619c --- /dev/null +++ b/Correlator/Util/RuntimeCache.cs @@ -0,0 +1,91 @@ +using System.Collections.Generic; +using Correlator.Model; +using Correlator.SensorHubTag; + +namespace Correlator.Util +{ + /// + /// 业务流程个节点状态 + /// + public class RuntimeCache + { + /// + /// 是否可以收集数据 + /// + public static bool CanCollectData = false; + + /// + /// 红色传感器是否正常 + /// + public static bool RedSensorIsEnable = false; + + /// + /// 蓝色传感器是否正常 + /// + public static bool BlueSensorIsEnable = false; + + /// + /// 采集到的数据 + /// + public static CorrelatorDataModel CorrelatorData; + + /// + /// 水听器模式 + /// + public static bool IsHydrophone = false; + + /// + /// 点名对话框是否已显示 + /// + public static bool IsShowing = false; + + /// + /// 数据包index + /// + public static readonly List SeqCaches = new List(); + + /// + /// 水听器下发唤醒指令时间戳 + /// + public static byte[] HydrophoneWakeUpTimeBytes = new byte[6]; + + /// + /// 水听器红色信号接收器原始数据 + /// + public static readonly Dictionary RedSensorOriginalResp = new Dictionary(); + + /// + /// 水听器红色信号接收器解析之后的Tags + /// + public static readonly Dictionary> RedSensorResponseTags = new Dictionary>(); + + /// + /// 水听器红色信号接收器原始数据 + /// + public static readonly Dictionary BlueSensorOriginalResp = new Dictionary(); + + /// + /// 水听器蓝色信号接收器解析之后的Tags + /// + public static readonly Dictionary> BlueSensorResponseTags = new Dictionary>(); + + //听音数据 + public static readonly List RedSoundCaches = new List(); + public static readonly List BlueSoundCaches = new List(); + + /// + /// 正在听音的设备编号 + /// + public static string CurrentListenSoundDevCode = DevCode.Dev1; + + /// + /// 小于1K的音频文件全路径集合 + /// + public static readonly List SmallAudioFiles = new List(); + + /// + /// 列表每页条目数 + /// + public const int PerPageItemCount = 10; + } +} \ No newline at end of file diff --git a/Correlator/ViewModels/AudioFileViewModel.cs b/Correlator/ViewModels/AudioFileViewModel.cs index f522a7a..1846bcc 100644 --- a/Correlator/ViewModels/AudioFileViewModel.cs +++ b/Correlator/ViewModels/AudioFileViewModel.cs @@ -142,7 +142,7 @@ //刷新数据 _totalFiles = GetTotalAudioFiles(); MaxPage = _totalFiles.Count.GetPageSize(); - AudioFiles = _totalFiles.Take(8).ToList(); + AudioFiles = _totalFiles.Take(RuntimeCache.PerPageItemCount).ToList(); } catch (IOException) { @@ -154,7 +154,10 @@ PageUpdatedCmd = new DelegateCommand>(args => { - AudioFiles = _totalFiles.Skip((args.Info - 1) * 8).Take(8).ToList(); + AudioFiles = _totalFiles + .Skip((args.Info - 1) * RuntimeCache.PerPageItemCount) + .Take(RuntimeCache.PerPageItemCount) + .ToList(); }); } @@ -171,7 +174,7 @@ { _totalFiles = GetTotalAudioFiles(); MaxPage = _totalFiles.Count.GetPageSize(); - AudioFiles = _totalFiles.Take(8).ToList(); + AudioFiles = _totalFiles.Take(RuntimeCache.PerPageItemCount).ToList(); } private static List GetTotalAudioFiles() @@ -184,7 +187,7 @@ { if (file.Length < 1024) { - FlowStatus.SmallAudioFiles.Add(file.FullName); + RuntimeCache.SmallAudioFiles.Add(file.FullName); } else { diff --git a/Correlator/ViewModels/AuditionViewModel.cs b/Correlator/ViewModels/AuditionViewModel.cs index b334ec9..7945aa7 100644 --- a/Correlator/ViewModels/AuditionViewModel.cs +++ b/Correlator/ViewModels/AuditionViewModel.cs @@ -94,7 +94,7 @@ sts[outIndex++] = BitConverter.ToInt16(buffer, i) / 32768f; } - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { eventAggregator.GetEvent().Publish(sts); } @@ -117,7 +117,7 @@ CommandSender.SendSoundStopCmd(_serialPortService.Sp, _isRedSensor ? DevCode.Dev1 : DevCode.Dev2); _audioService.Stop(); _isStartRecording = false; - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { //TODO 保存原始PCM数据到文件 // using (var fs = new FileStream("C:\\Users\\Administrator\\Desktop\\input.pcm", @@ -129,13 +129,13 @@ // } // } - FlowStatus.RedSoundCaches.SaveSoundData(); - FlowStatus.RedSoundCaches.Clear(); + RuntimeCache.RedSoundCaches.SaveSoundData(); + RuntimeCache.RedSoundCaches.Clear(); } else { - FlowStatus.BlueSoundCaches.SaveSoundData(); - FlowStatus.BlueSoundCaches.Clear(); + RuntimeCache.BlueSoundCaches.SaveSoundData(); + RuntimeCache.BlueSoundCaches.Clear(); } //波形图停止模拟 @@ -146,7 +146,7 @@ var devCode = _isRedSensor ? DevCode.Dev1 : DevCode.Dev2; CommandSender.SendSoundCollectCmd(_serialPortService.Sp, devCode); - FlowStatus.CurrentListenSoundDevCode = devCode; + RuntimeCache.CurrentListenSoundDevCode = devCode; _audioService.Start(devCode); _isStartRecording = true; diff --git a/Correlator/ViewModels/CheckResponseDialogViewModel.cs b/Correlator/ViewModels/CheckResponseDialogViewModel.cs index e3b140f..a6dd527 100644 --- a/Correlator/ViewModels/CheckResponseDialogViewModel.cs +++ b/Correlator/ViewModels/CheckResponseDialogViewModel.cs @@ -16,7 +16,7 @@ { eventAggregator.GetEvent().Subscribe(delegate(IDialogResult result) { - FlowStatus.IsShowing = false; + RuntimeCache.IsShowing = false; RequestClose?.Invoke(result); }); } diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index cb3946e..5d33683 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -265,7 +265,7 @@ - + diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index 4c897c0..51294cd 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -81,23 +81,23 @@ break; case 11293: //数据采集 - if (!FlowStatus.IsHydrophone) + if (!RuntimeCache.IsHydrophone) { HandleCorrelatorData(deviceId, tags); } break; case 30: - if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) + if (RuntimeCache.IsHydrophone && RuntimeCache.CanCollectData) { Application.Current.Dispatcher.Invoke(delegate { //显示点名弹窗 - if (!FlowStatus.IsShowing) + if (!RuntimeCache.IsShowing) { //因为是广播发的数据,所以会收到两条回复,但是只需要显示一次对话框 _eventAggregator.GetEvent().Publish(); - FlowStatus.IsShowing = true; + RuntimeCache.IsShowing = true; } }); } @@ -108,23 +108,23 @@ { int index = receiveData[15]; //取出seq,确定收到的是第几包数据 - FlowStatus.SeqCaches.Add(index); + RuntimeCache.SeqCaches.Add(index); var response = BitConverter.ToString(receiveData).Replace("-", ""); //收集数据 if (deviceId.Equals(DevCode.Dev1)) { //原始数据 - FlowStatus.RedSensorOriginalResp.Add(index, response); + RuntimeCache.RedSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.RedSensorResponseTags.Add(index, tags); + RuntimeCache.RedSensorResponseTags.Add(index, tags); } else { //原始数据 - FlowStatus.BlueSensorOriginalResp.Add(index, response); + RuntimeCache.BlueSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.BlueSensorResponseTags.Add(index, tags); + RuntimeCache.BlueSensorResponseTags.Add(index, tags); } } @@ -243,7 +243,7 @@ //左右两边接收到的数据时间差超过10s,认为不是同一次此指令返回的,舍弃 if (diffTime >= 10) return; - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; _eventAggregator.GetEvent().Publish(); } else @@ -273,13 +273,13 @@ } //保存听音数据 - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { - FlowStatus.RedSoundCaches.Add(pcm); + RuntimeCache.RedSoundCaches.Add(pcm); } else { - FlowStatus.BlueSoundCaches.Add(pcm); + RuntimeCache.BlueSoundCaches.Add(pcm); } //将pcm数据写入缓存 @@ -325,7 +325,7 @@ _dataModel.RightDeviceDataArray = doubleArrays.ToOneDimensionalArray(); } - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; "SerialPortServiceImpl".WriteLog(devCode + "数据处理完成"); } diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8def641..43f84fd 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -74,7 +74,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -88,7 +88,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -105,7 +105,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -118,7 +118,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -230,7 +230,7 @@ { if (RedSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev1); _redResponseTimer.Start(); @@ -245,7 +245,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev1}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.RedSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.RedSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -257,7 +257,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.RedSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.RedSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { @@ -314,7 +314,7 @@ { if (BlueSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev2); _blueResponseTimer.Start(); @@ -328,7 +328,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev2}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.BlueSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.BlueSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -340,7 +340,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.BlueSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.BlueSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { diff --git a/Correlator/Util/CommandSender.cs b/Correlator/Util/CommandSender.cs index afb3b85..5efc675 100644 --- a/Correlator/Util/CommandSender.cs +++ b/Correlator/Util/CommandSender.cs @@ -119,7 +119,7 @@ }; //获取时间(年-月-日-时-分-秒),年号-2000 - FlowStatus.HydrophoneWakeUpTimeBytes = new[] + RuntimeCache.HydrophoneWakeUpTimeBytes = new[] { CalendarHub.Year, CalendarHub.Mon, CalendarHub.Day, CalendarHub.Hor, CalendarHub.Min, CalendarHub.Sec }; @@ -127,9 +127,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data @@ -226,9 +226,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data @@ -318,9 +318,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data diff --git a/Correlator/Util/FlowStatus.cs b/Correlator/Util/FlowStatus.cs deleted file mode 100644 index 384caec..0000000 --- a/Correlator/Util/FlowStatus.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System.Collections.Generic; -using Correlator.Model; -using Correlator.SensorHubTag; - -namespace Correlator.Util -{ - /// - /// 业务流程个节点状态 - /// - public class FlowStatus - { - /// - /// 是否可以收集数据 - /// - public static bool CanCollectData = false; - - /// - /// 红色传感器是否正常 - /// - public static bool RedSensorIsEnable = false; - - /// - /// 蓝色传感器是否正常 - /// - public static bool BlueSensorIsEnable = false; - - /// - /// 采集到的数据 - /// - public static CorrelatorDataModel CorrelatorData; - - /// - /// 水听器模式 - /// - public static bool IsHydrophone = false; - - /// - /// 点名对话框是否已显示 - /// - public static bool IsShowing = false; - - /// - /// 数据包index - /// - public static readonly List SeqCaches = new List(); - - /// - /// 水听器下发唤醒指令时间戳 - /// - public static byte[] HydrophoneWakeUpTimeBytes = new byte[6]; - - /// - /// 水听器红色信号接收器原始数据 - /// - public static readonly Dictionary RedSensorOriginalResp = new Dictionary(); - - /// - /// 水听器红色信号接收器解析之后的Tags - /// - public static readonly Dictionary> RedSensorResponseTags = new Dictionary>(); - - /// - /// 水听器红色信号接收器原始数据 - /// - public static readonly Dictionary BlueSensorOriginalResp = new Dictionary(); - - /// - /// 水听器蓝色信号接收器解析之后的Tags - /// - public static readonly Dictionary> BlueSensorResponseTags = new Dictionary>(); - - //听音数据 - public static readonly List RedSoundCaches = new List(); - public static readonly List BlueSoundCaches = new List(); - - /// - /// 正在听音的设备编号 - /// - public static string CurrentListenSoundDevCode = DevCode.Dev1; - - /// - /// 小于1K的音频文件全路径集合 - /// - public static readonly List SmallAudioFiles = new List(); - } -} \ No newline at end of file diff --git a/Correlator/Util/MethodExtensions.cs b/Correlator/Util/MethodExtensions.cs index 7d742ce..a8b0136 100644 --- a/Correlator/Util/MethodExtensions.cs +++ b/Correlator/Util/MethodExtensions.cs @@ -741,7 +741,7 @@ /// public static int GetPageSize(this int count) { - return (count + 8 - 1) / 8; + return (count + RuntimeCache.PerPageItemCount - 1) / RuntimeCache.PerPageItemCount; } } } \ No newline at end of file diff --git a/Correlator/Util/RuntimeCache.cs b/Correlator/Util/RuntimeCache.cs new file mode 100644 index 0000000..e91619c --- /dev/null +++ b/Correlator/Util/RuntimeCache.cs @@ -0,0 +1,91 @@ +using System.Collections.Generic; +using Correlator.Model; +using Correlator.SensorHubTag; + +namespace Correlator.Util +{ + /// + /// 业务流程个节点状态 + /// + public class RuntimeCache + { + /// + /// 是否可以收集数据 + /// + public static bool CanCollectData = false; + + /// + /// 红色传感器是否正常 + /// + public static bool RedSensorIsEnable = false; + + /// + /// 蓝色传感器是否正常 + /// + public static bool BlueSensorIsEnable = false; + + /// + /// 采集到的数据 + /// + public static CorrelatorDataModel CorrelatorData; + + /// + /// 水听器模式 + /// + public static bool IsHydrophone = false; + + /// + /// 点名对话框是否已显示 + /// + public static bool IsShowing = false; + + /// + /// 数据包index + /// + public static readonly List SeqCaches = new List(); + + /// + /// 水听器下发唤醒指令时间戳 + /// + public static byte[] HydrophoneWakeUpTimeBytes = new byte[6]; + + /// + /// 水听器红色信号接收器原始数据 + /// + public static readonly Dictionary RedSensorOriginalResp = new Dictionary(); + + /// + /// 水听器红色信号接收器解析之后的Tags + /// + public static readonly Dictionary> RedSensorResponseTags = new Dictionary>(); + + /// + /// 水听器红色信号接收器原始数据 + /// + public static readonly Dictionary BlueSensorOriginalResp = new Dictionary(); + + /// + /// 水听器蓝色信号接收器解析之后的Tags + /// + public static readonly Dictionary> BlueSensorResponseTags = new Dictionary>(); + + //听音数据 + public static readonly List RedSoundCaches = new List(); + public static readonly List BlueSoundCaches = new List(); + + /// + /// 正在听音的设备编号 + /// + public static string CurrentListenSoundDevCode = DevCode.Dev1; + + /// + /// 小于1K的音频文件全路径集合 + /// + public static readonly List SmallAudioFiles = new List(); + + /// + /// 列表每页条目数 + /// + public const int PerPageItemCount = 10; + } +} \ No newline at end of file diff --git a/Correlator/ViewModels/AudioFileViewModel.cs b/Correlator/ViewModels/AudioFileViewModel.cs index f522a7a..1846bcc 100644 --- a/Correlator/ViewModels/AudioFileViewModel.cs +++ b/Correlator/ViewModels/AudioFileViewModel.cs @@ -142,7 +142,7 @@ //刷新数据 _totalFiles = GetTotalAudioFiles(); MaxPage = _totalFiles.Count.GetPageSize(); - AudioFiles = _totalFiles.Take(8).ToList(); + AudioFiles = _totalFiles.Take(RuntimeCache.PerPageItemCount).ToList(); } catch (IOException) { @@ -154,7 +154,10 @@ PageUpdatedCmd = new DelegateCommand>(args => { - AudioFiles = _totalFiles.Skip((args.Info - 1) * 8).Take(8).ToList(); + AudioFiles = _totalFiles + .Skip((args.Info - 1) * RuntimeCache.PerPageItemCount) + .Take(RuntimeCache.PerPageItemCount) + .ToList(); }); } @@ -171,7 +174,7 @@ { _totalFiles = GetTotalAudioFiles(); MaxPage = _totalFiles.Count.GetPageSize(); - AudioFiles = _totalFiles.Take(8).ToList(); + AudioFiles = _totalFiles.Take(RuntimeCache.PerPageItemCount).ToList(); } private static List GetTotalAudioFiles() @@ -184,7 +187,7 @@ { if (file.Length < 1024) { - FlowStatus.SmallAudioFiles.Add(file.FullName); + RuntimeCache.SmallAudioFiles.Add(file.FullName); } else { diff --git a/Correlator/ViewModels/AuditionViewModel.cs b/Correlator/ViewModels/AuditionViewModel.cs index b334ec9..7945aa7 100644 --- a/Correlator/ViewModels/AuditionViewModel.cs +++ b/Correlator/ViewModels/AuditionViewModel.cs @@ -94,7 +94,7 @@ sts[outIndex++] = BitConverter.ToInt16(buffer, i) / 32768f; } - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { eventAggregator.GetEvent().Publish(sts); } @@ -117,7 +117,7 @@ CommandSender.SendSoundStopCmd(_serialPortService.Sp, _isRedSensor ? DevCode.Dev1 : DevCode.Dev2); _audioService.Stop(); _isStartRecording = false; - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { //TODO 保存原始PCM数据到文件 // using (var fs = new FileStream("C:\\Users\\Administrator\\Desktop\\input.pcm", @@ -129,13 +129,13 @@ // } // } - FlowStatus.RedSoundCaches.SaveSoundData(); - FlowStatus.RedSoundCaches.Clear(); + RuntimeCache.RedSoundCaches.SaveSoundData(); + RuntimeCache.RedSoundCaches.Clear(); } else { - FlowStatus.BlueSoundCaches.SaveSoundData(); - FlowStatus.BlueSoundCaches.Clear(); + RuntimeCache.BlueSoundCaches.SaveSoundData(); + RuntimeCache.BlueSoundCaches.Clear(); } //波形图停止模拟 @@ -146,7 +146,7 @@ var devCode = _isRedSensor ? DevCode.Dev1 : DevCode.Dev2; CommandSender.SendSoundCollectCmd(_serialPortService.Sp, devCode); - FlowStatus.CurrentListenSoundDevCode = devCode; + RuntimeCache.CurrentListenSoundDevCode = devCode; _audioService.Start(devCode); _isStartRecording = true; diff --git a/Correlator/ViewModels/CheckResponseDialogViewModel.cs b/Correlator/ViewModels/CheckResponseDialogViewModel.cs index e3b140f..a6dd527 100644 --- a/Correlator/ViewModels/CheckResponseDialogViewModel.cs +++ b/Correlator/ViewModels/CheckResponseDialogViewModel.cs @@ -16,7 +16,7 @@ { eventAggregator.GetEvent().Subscribe(delegate(IDialogResult result) { - FlowStatus.IsShowing = false; + RuntimeCache.IsShowing = false; RequestClose?.Invoke(result); }); } diff --git a/Correlator/ViewModels/ImportResponseDialogViewModel.cs b/Correlator/ViewModels/ImportResponseDialogViewModel.cs index a914f66..5b6c1f3 100644 --- a/Correlator/ViewModels/ImportResponseDialogViewModel.cs +++ b/Correlator/ViewModels/ImportResponseDialogViewModel.cs @@ -343,7 +343,7 @@ private void Worker_OnRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { //赋值给缓存 - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; } /// diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index cb3946e..5d33683 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -265,7 +265,7 @@ - + diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index 4c897c0..51294cd 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -81,23 +81,23 @@ break; case 11293: //数据采集 - if (!FlowStatus.IsHydrophone) + if (!RuntimeCache.IsHydrophone) { HandleCorrelatorData(deviceId, tags); } break; case 30: - if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) + if (RuntimeCache.IsHydrophone && RuntimeCache.CanCollectData) { Application.Current.Dispatcher.Invoke(delegate { //显示点名弹窗 - if (!FlowStatus.IsShowing) + if (!RuntimeCache.IsShowing) { //因为是广播发的数据,所以会收到两条回复,但是只需要显示一次对话框 _eventAggregator.GetEvent().Publish(); - FlowStatus.IsShowing = true; + RuntimeCache.IsShowing = true; } }); } @@ -108,23 +108,23 @@ { int index = receiveData[15]; //取出seq,确定收到的是第几包数据 - FlowStatus.SeqCaches.Add(index); + RuntimeCache.SeqCaches.Add(index); var response = BitConverter.ToString(receiveData).Replace("-", ""); //收集数据 if (deviceId.Equals(DevCode.Dev1)) { //原始数据 - FlowStatus.RedSensorOriginalResp.Add(index, response); + RuntimeCache.RedSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.RedSensorResponseTags.Add(index, tags); + RuntimeCache.RedSensorResponseTags.Add(index, tags); } else { //原始数据 - FlowStatus.BlueSensorOriginalResp.Add(index, response); + RuntimeCache.BlueSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.BlueSensorResponseTags.Add(index, tags); + RuntimeCache.BlueSensorResponseTags.Add(index, tags); } } @@ -243,7 +243,7 @@ //左右两边接收到的数据时间差超过10s,认为不是同一次此指令返回的,舍弃 if (diffTime >= 10) return; - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; _eventAggregator.GetEvent().Publish(); } else @@ -273,13 +273,13 @@ } //保存听音数据 - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { - FlowStatus.RedSoundCaches.Add(pcm); + RuntimeCache.RedSoundCaches.Add(pcm); } else { - FlowStatus.BlueSoundCaches.Add(pcm); + RuntimeCache.BlueSoundCaches.Add(pcm); } //将pcm数据写入缓存 @@ -325,7 +325,7 @@ _dataModel.RightDeviceDataArray = doubleArrays.ToOneDimensionalArray(); } - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; "SerialPortServiceImpl".WriteLog(devCode + "数据处理完成"); } diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8def641..43f84fd 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -74,7 +74,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -88,7 +88,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -105,7 +105,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -118,7 +118,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -230,7 +230,7 @@ { if (RedSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev1); _redResponseTimer.Start(); @@ -245,7 +245,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev1}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.RedSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.RedSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -257,7 +257,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.RedSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.RedSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { @@ -314,7 +314,7 @@ { if (BlueSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev2); _blueResponseTimer.Start(); @@ -328,7 +328,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev2}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.BlueSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.BlueSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -340,7 +340,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.BlueSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.BlueSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { diff --git a/Correlator/Util/CommandSender.cs b/Correlator/Util/CommandSender.cs index afb3b85..5efc675 100644 --- a/Correlator/Util/CommandSender.cs +++ b/Correlator/Util/CommandSender.cs @@ -119,7 +119,7 @@ }; //获取时间(年-月-日-时-分-秒),年号-2000 - FlowStatus.HydrophoneWakeUpTimeBytes = new[] + RuntimeCache.HydrophoneWakeUpTimeBytes = new[] { CalendarHub.Year, CalendarHub.Mon, CalendarHub.Day, CalendarHub.Hor, CalendarHub.Min, CalendarHub.Sec }; @@ -127,9 +127,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data @@ -226,9 +226,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data @@ -318,9 +318,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data diff --git a/Correlator/Util/FlowStatus.cs b/Correlator/Util/FlowStatus.cs deleted file mode 100644 index 384caec..0000000 --- a/Correlator/Util/FlowStatus.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System.Collections.Generic; -using Correlator.Model; -using Correlator.SensorHubTag; - -namespace Correlator.Util -{ - /// - /// 业务流程个节点状态 - /// - public class FlowStatus - { - /// - /// 是否可以收集数据 - /// - public static bool CanCollectData = false; - - /// - /// 红色传感器是否正常 - /// - public static bool RedSensorIsEnable = false; - - /// - /// 蓝色传感器是否正常 - /// - public static bool BlueSensorIsEnable = false; - - /// - /// 采集到的数据 - /// - public static CorrelatorDataModel CorrelatorData; - - /// - /// 水听器模式 - /// - public static bool IsHydrophone = false; - - /// - /// 点名对话框是否已显示 - /// - public static bool IsShowing = false; - - /// - /// 数据包index - /// - public static readonly List SeqCaches = new List(); - - /// - /// 水听器下发唤醒指令时间戳 - /// - public static byte[] HydrophoneWakeUpTimeBytes = new byte[6]; - - /// - /// 水听器红色信号接收器原始数据 - /// - public static readonly Dictionary RedSensorOriginalResp = new Dictionary(); - - /// - /// 水听器红色信号接收器解析之后的Tags - /// - public static readonly Dictionary> RedSensorResponseTags = new Dictionary>(); - - /// - /// 水听器红色信号接收器原始数据 - /// - public static readonly Dictionary BlueSensorOriginalResp = new Dictionary(); - - /// - /// 水听器蓝色信号接收器解析之后的Tags - /// - public static readonly Dictionary> BlueSensorResponseTags = new Dictionary>(); - - //听音数据 - public static readonly List RedSoundCaches = new List(); - public static readonly List BlueSoundCaches = new List(); - - /// - /// 正在听音的设备编号 - /// - public static string CurrentListenSoundDevCode = DevCode.Dev1; - - /// - /// 小于1K的音频文件全路径集合 - /// - public static readonly List SmallAudioFiles = new List(); - } -} \ No newline at end of file diff --git a/Correlator/Util/MethodExtensions.cs b/Correlator/Util/MethodExtensions.cs index 7d742ce..a8b0136 100644 --- a/Correlator/Util/MethodExtensions.cs +++ b/Correlator/Util/MethodExtensions.cs @@ -741,7 +741,7 @@ /// public static int GetPageSize(this int count) { - return (count + 8 - 1) / 8; + return (count + RuntimeCache.PerPageItemCount - 1) / RuntimeCache.PerPageItemCount; } } } \ No newline at end of file diff --git a/Correlator/Util/RuntimeCache.cs b/Correlator/Util/RuntimeCache.cs new file mode 100644 index 0000000..e91619c --- /dev/null +++ b/Correlator/Util/RuntimeCache.cs @@ -0,0 +1,91 @@ +using System.Collections.Generic; +using Correlator.Model; +using Correlator.SensorHubTag; + +namespace Correlator.Util +{ + /// + /// 业务流程个节点状态 + /// + public class RuntimeCache + { + /// + /// 是否可以收集数据 + /// + public static bool CanCollectData = false; + + /// + /// 红色传感器是否正常 + /// + public static bool RedSensorIsEnable = false; + + /// + /// 蓝色传感器是否正常 + /// + public static bool BlueSensorIsEnable = false; + + /// + /// 采集到的数据 + /// + public static CorrelatorDataModel CorrelatorData; + + /// + /// 水听器模式 + /// + public static bool IsHydrophone = false; + + /// + /// 点名对话框是否已显示 + /// + public static bool IsShowing = false; + + /// + /// 数据包index + /// + public static readonly List SeqCaches = new List(); + + /// + /// 水听器下发唤醒指令时间戳 + /// + public static byte[] HydrophoneWakeUpTimeBytes = new byte[6]; + + /// + /// 水听器红色信号接收器原始数据 + /// + public static readonly Dictionary RedSensorOriginalResp = new Dictionary(); + + /// + /// 水听器红色信号接收器解析之后的Tags + /// + public static readonly Dictionary> RedSensorResponseTags = new Dictionary>(); + + /// + /// 水听器红色信号接收器原始数据 + /// + public static readonly Dictionary BlueSensorOriginalResp = new Dictionary(); + + /// + /// 水听器蓝色信号接收器解析之后的Tags + /// + public static readonly Dictionary> BlueSensorResponseTags = new Dictionary>(); + + //听音数据 + public static readonly List RedSoundCaches = new List(); + public static readonly List BlueSoundCaches = new List(); + + /// + /// 正在听音的设备编号 + /// + public static string CurrentListenSoundDevCode = DevCode.Dev1; + + /// + /// 小于1K的音频文件全路径集合 + /// + public static readonly List SmallAudioFiles = new List(); + + /// + /// 列表每页条目数 + /// + public const int PerPageItemCount = 10; + } +} \ No newline at end of file diff --git a/Correlator/ViewModels/AudioFileViewModel.cs b/Correlator/ViewModels/AudioFileViewModel.cs index f522a7a..1846bcc 100644 --- a/Correlator/ViewModels/AudioFileViewModel.cs +++ b/Correlator/ViewModels/AudioFileViewModel.cs @@ -142,7 +142,7 @@ //刷新数据 _totalFiles = GetTotalAudioFiles(); MaxPage = _totalFiles.Count.GetPageSize(); - AudioFiles = _totalFiles.Take(8).ToList(); + AudioFiles = _totalFiles.Take(RuntimeCache.PerPageItemCount).ToList(); } catch (IOException) { @@ -154,7 +154,10 @@ PageUpdatedCmd = new DelegateCommand>(args => { - AudioFiles = _totalFiles.Skip((args.Info - 1) * 8).Take(8).ToList(); + AudioFiles = _totalFiles + .Skip((args.Info - 1) * RuntimeCache.PerPageItemCount) + .Take(RuntimeCache.PerPageItemCount) + .ToList(); }); } @@ -171,7 +174,7 @@ { _totalFiles = GetTotalAudioFiles(); MaxPage = _totalFiles.Count.GetPageSize(); - AudioFiles = _totalFiles.Take(8).ToList(); + AudioFiles = _totalFiles.Take(RuntimeCache.PerPageItemCount).ToList(); } private static List GetTotalAudioFiles() @@ -184,7 +187,7 @@ { if (file.Length < 1024) { - FlowStatus.SmallAudioFiles.Add(file.FullName); + RuntimeCache.SmallAudioFiles.Add(file.FullName); } else { diff --git a/Correlator/ViewModels/AuditionViewModel.cs b/Correlator/ViewModels/AuditionViewModel.cs index b334ec9..7945aa7 100644 --- a/Correlator/ViewModels/AuditionViewModel.cs +++ b/Correlator/ViewModels/AuditionViewModel.cs @@ -94,7 +94,7 @@ sts[outIndex++] = BitConverter.ToInt16(buffer, i) / 32768f; } - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { eventAggregator.GetEvent().Publish(sts); } @@ -117,7 +117,7 @@ CommandSender.SendSoundStopCmd(_serialPortService.Sp, _isRedSensor ? DevCode.Dev1 : DevCode.Dev2); _audioService.Stop(); _isStartRecording = false; - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { //TODO 保存原始PCM数据到文件 // using (var fs = new FileStream("C:\\Users\\Administrator\\Desktop\\input.pcm", @@ -129,13 +129,13 @@ // } // } - FlowStatus.RedSoundCaches.SaveSoundData(); - FlowStatus.RedSoundCaches.Clear(); + RuntimeCache.RedSoundCaches.SaveSoundData(); + RuntimeCache.RedSoundCaches.Clear(); } else { - FlowStatus.BlueSoundCaches.SaveSoundData(); - FlowStatus.BlueSoundCaches.Clear(); + RuntimeCache.BlueSoundCaches.SaveSoundData(); + RuntimeCache.BlueSoundCaches.Clear(); } //波形图停止模拟 @@ -146,7 +146,7 @@ var devCode = _isRedSensor ? DevCode.Dev1 : DevCode.Dev2; CommandSender.SendSoundCollectCmd(_serialPortService.Sp, devCode); - FlowStatus.CurrentListenSoundDevCode = devCode; + RuntimeCache.CurrentListenSoundDevCode = devCode; _audioService.Start(devCode); _isStartRecording = true; diff --git a/Correlator/ViewModels/CheckResponseDialogViewModel.cs b/Correlator/ViewModels/CheckResponseDialogViewModel.cs index e3b140f..a6dd527 100644 --- a/Correlator/ViewModels/CheckResponseDialogViewModel.cs +++ b/Correlator/ViewModels/CheckResponseDialogViewModel.cs @@ -16,7 +16,7 @@ { eventAggregator.GetEvent().Subscribe(delegate(IDialogResult result) { - FlowStatus.IsShowing = false; + RuntimeCache.IsShowing = false; RequestClose?.Invoke(result); }); } diff --git a/Correlator/ViewModels/ImportResponseDialogViewModel.cs b/Correlator/ViewModels/ImportResponseDialogViewModel.cs index a914f66..5b6c1f3 100644 --- a/Correlator/ViewModels/ImportResponseDialogViewModel.cs +++ b/Correlator/ViewModels/ImportResponseDialogViewModel.cs @@ -343,7 +343,7 @@ private void Worker_OnRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { //赋值给缓存 - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; } /// diff --git a/Correlator/ViewModels/MainWindowViewModel.cs b/Correlator/ViewModels/MainWindowViewModel.cs index 3de31b7..bec9b09 100644 --- a/Correlator/ViewModels/MainWindowViewModel.cs +++ b/Correlator/ViewModels/MainWindowViewModel.cs @@ -495,7 +495,7 @@ RedTransmitterBattery = Convert.ToInt32(dev.Cell); RedTransmitterSignalIntensity = 5; RedTransmitterState = true; - FlowStatus.RedSensorIsEnable = true; + RuntimeCache.RedSensorIsEnable = true; }); _eventAggregator.GetEvent().Subscribe(delegate(DevStatus dev) @@ -506,7 +506,7 @@ BlueTransmitterBattery = Convert.ToInt32(dev.Cell); BlueTransmitterSignalIntensity = 5; BlueTransmitterState = true; - FlowStatus.BlueSensorIsEnable = true; + RuntimeCache.BlueSensorIsEnable = true; }); //加速度计 @@ -561,8 +561,8 @@ DialogHub.Get.ShowLoadingDialog(_mainWindow, "数据计算中,请稍后..."); //开始计算就不收集收据了且不能点击开始按钮 StartButtonEnabled = false; - FlowStatus.CanCollectData = false; - if (!FlowStatus.IsHydrophone) + RuntimeCache.CanCollectData = false; + if (!RuntimeCache.IsHydrophone) { //开始计算停止收集指令 _accelerometerCommandTimer.Stop(); @@ -597,7 +597,7 @@ /// private void CalculateData() { - var dataModel = FlowStatus.CorrelatorData; + var dataModel = RuntimeCache.CorrelatorData; if (dataModel.LeftDeviceDataArray != null && dataModel.RightDeviceDataArray != null) { Console.WriteLine(@"MainWindowViewModel => 开始计算"); @@ -628,7 +628,7 @@ _eventAggregator.GetEvent().Publish(array); var time = DateTime.Now.ToString("HHmmss"); - if (FlowStatus.IsHydrophone) + if (RuntimeCache.IsHydrophone) { //保存参数 var paramConfigFile = $"{_locateDataDir}\\参数配置.{_locateTimes}.{time}.json"; @@ -647,12 +647,12 @@ _runningTimer.Stop(); StartButtonEnabled = true; //清空缓存 - FlowStatus.RedSensorOriginalResp.Clear(); - FlowStatus.BlueSensorOriginalResp.Clear(); - FlowStatus.RedSensorResponseTags.Clear(); - FlowStatus.BlueSensorResponseTags.Clear(); - FlowStatus.RedSensorIsEnable = false; - FlowStatus.BlueSensorIsEnable = false; + RuntimeCache.RedSensorOriginalResp.Clear(); + RuntimeCache.BlueSensorOriginalResp.Clear(); + RuntimeCache.RedSensorResponseTags.Clear(); + RuntimeCache.BlueSensorResponseTags.Clear(); + RuntimeCache.RedSensorIsEnable = false; + RuntimeCache.BlueSensorIsEnable = false; DialogHub.Get.DismissLoadingDialog(); } @@ -686,19 +686,19 @@ if (_serialPortService.Sp.IsOpen) { //实时显示信号电量 - if (!FlowStatus.RedSensorIsEnable && !FlowStatus.BlueSensorIsEnable) + if (!RuntimeCache.RedSensorIsEnable && !RuntimeCache.BlueSensorIsEnable) { _devId = (byte)(_devId == 0x02 ? 0x01 : 0x02); _serialPortService.ShowSignal(_devId); } else { - if (!FlowStatus.RedSensorIsEnable) + if (!RuntimeCache.RedSensorIsEnable) { _serialPortService.ShowSignal(0x01); } - if (!FlowStatus.BlueSensorIsEnable) + if (!RuntimeCache.BlueSensorIsEnable) { _serialPortService.ShowSignal(0x02); } @@ -758,7 +758,7 @@ //加速度计下发指令Timer _accelerometerCommandTimer.Tick += delegate { - if (FlowStatus.CanCollectData) + if (RuntimeCache.CanCollectData) { CommandSender.SendCorrelatorWakeUpCmd(_serialPortService.Sp); } @@ -788,13 +788,13 @@ Console.WriteLine(@"MainWindowViewModel => 加载"); it.AccelerationRadioButton.Checked += delegate { - FlowStatus.IsHydrophone = false; + RuntimeCache.IsHydrophone = false; FrequencyInterval = "100 ~ 3000Hz"; }; it.HydrophonesRadioButton.Checked += delegate { - FlowStatus.IsHydrophone = true; + RuntimeCache.IsHydrophone = true; FrequencyInterval = "10 ~ 300Hz"; }; }); @@ -816,12 +816,12 @@ } //删除小于1K的音频 - foreach (var file in FlowStatus.SmallAudioFiles) + foreach (var file in RuntimeCache.SmallAudioFiles) { File.Delete(file); } - FlowStatus.SmallAudioFiles.Clear(); + RuntimeCache.SmallAudioFiles.Clear(); _mainWindow.Close(); } ); @@ -890,7 +890,7 @@ //导入数据 ImportDataCommand = new DelegateCommand(delegate { - if (FlowStatus.IsHydrophone) + if (RuntimeCache.IsHydrophone) { _dialogService.ShowDialog("ImportResponseDialog", null, delegate(IDialogResult result) { @@ -946,18 +946,18 @@ //将采集的数据转为音频并保存 SaveAudioCommand = new DelegateCommand(delegate { - if (FlowStatus.CorrelatorData != null) + if (RuntimeCache.CorrelatorData != null) { var filePath = $"{DirectoryManager.GetAudioDir()}\\音频_{DateTime.Now.ToString("yyyyMMddHHmmss")}.wav"; filePath.SaveWavFile( - FlowStatus.CorrelatorData.LeftDeviceDataArray, - FlowStatus.CorrelatorData.RightDeviceDataArray + RuntimeCache.CorrelatorData.LeftDeviceDataArray, + RuntimeCache.CorrelatorData.RightDeviceDataArray ); Growl.Success("音频已保存"); //清空上次的缓存 - FlowStatus.CorrelatorData = null; + RuntimeCache.CorrelatorData = null; } else { @@ -1011,9 +1011,9 @@ //每次计算之前都需要判断是否已经完成之前的计算,然后清空上一次的计算数据 ResetParam(); - FlowStatus.CanCollectData = true; + RuntimeCache.CanCollectData = true; //开始数据采集 - if (FlowStatus.IsHydrophone) + if (RuntimeCache.IsHydrophone) { CommandSender.SendHydrophoneWakeUpCmd(_serialPortService.Sp); } @@ -1058,12 +1058,12 @@ _eventAggregator.GetEvent().Publish(); - if (!FlowStatus.IsHydrophone) + if (!RuntimeCache.IsHydrophone) { _accelerometerCommandTimer.Stop(); } - FlowStatus.CanCollectData = false; + RuntimeCache.CanCollectData = false; } /// @@ -1146,7 +1146,7 @@ var low = Convert.ToInt32(_lowFrequency); var high = Convert.ToInt32(_highFrequency); - if (FlowStatus.IsHydrophone) + if (RuntimeCache.IsHydrophone) { if (low < 10 || low > 300 || high < 10 || high > 300 || low >= high) { diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index cb3946e..5d33683 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -265,7 +265,7 @@ - + diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index 4c897c0..51294cd 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -81,23 +81,23 @@ break; case 11293: //数据采集 - if (!FlowStatus.IsHydrophone) + if (!RuntimeCache.IsHydrophone) { HandleCorrelatorData(deviceId, tags); } break; case 30: - if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) + if (RuntimeCache.IsHydrophone && RuntimeCache.CanCollectData) { Application.Current.Dispatcher.Invoke(delegate { //显示点名弹窗 - if (!FlowStatus.IsShowing) + if (!RuntimeCache.IsShowing) { //因为是广播发的数据,所以会收到两条回复,但是只需要显示一次对话框 _eventAggregator.GetEvent().Publish(); - FlowStatus.IsShowing = true; + RuntimeCache.IsShowing = true; } }); } @@ -108,23 +108,23 @@ { int index = receiveData[15]; //取出seq,确定收到的是第几包数据 - FlowStatus.SeqCaches.Add(index); + RuntimeCache.SeqCaches.Add(index); var response = BitConverter.ToString(receiveData).Replace("-", ""); //收集数据 if (deviceId.Equals(DevCode.Dev1)) { //原始数据 - FlowStatus.RedSensorOriginalResp.Add(index, response); + RuntimeCache.RedSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.RedSensorResponseTags.Add(index, tags); + RuntimeCache.RedSensorResponseTags.Add(index, tags); } else { //原始数据 - FlowStatus.BlueSensorOriginalResp.Add(index, response); + RuntimeCache.BlueSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.BlueSensorResponseTags.Add(index, tags); + RuntimeCache.BlueSensorResponseTags.Add(index, tags); } } @@ -243,7 +243,7 @@ //左右两边接收到的数据时间差超过10s,认为不是同一次此指令返回的,舍弃 if (diffTime >= 10) return; - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; _eventAggregator.GetEvent().Publish(); } else @@ -273,13 +273,13 @@ } //保存听音数据 - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { - FlowStatus.RedSoundCaches.Add(pcm); + RuntimeCache.RedSoundCaches.Add(pcm); } else { - FlowStatus.BlueSoundCaches.Add(pcm); + RuntimeCache.BlueSoundCaches.Add(pcm); } //将pcm数据写入缓存 @@ -325,7 +325,7 @@ _dataModel.RightDeviceDataArray = doubleArrays.ToOneDimensionalArray(); } - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; "SerialPortServiceImpl".WriteLog(devCode + "数据处理完成"); } diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8def641..43f84fd 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -74,7 +74,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -88,7 +88,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -105,7 +105,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -118,7 +118,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -230,7 +230,7 @@ { if (RedSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev1); _redResponseTimer.Start(); @@ -245,7 +245,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev1}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.RedSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.RedSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -257,7 +257,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.RedSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.RedSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { @@ -314,7 +314,7 @@ { if (BlueSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev2); _blueResponseTimer.Start(); @@ -328,7 +328,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev2}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.BlueSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.BlueSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -340,7 +340,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.BlueSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.BlueSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { diff --git a/Correlator/Util/CommandSender.cs b/Correlator/Util/CommandSender.cs index afb3b85..5efc675 100644 --- a/Correlator/Util/CommandSender.cs +++ b/Correlator/Util/CommandSender.cs @@ -119,7 +119,7 @@ }; //获取时间(年-月-日-时-分-秒),年号-2000 - FlowStatus.HydrophoneWakeUpTimeBytes = new[] + RuntimeCache.HydrophoneWakeUpTimeBytes = new[] { CalendarHub.Year, CalendarHub.Mon, CalendarHub.Day, CalendarHub.Hor, CalendarHub.Min, CalendarHub.Sec }; @@ -127,9 +127,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data @@ -226,9 +226,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data @@ -318,9 +318,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data diff --git a/Correlator/Util/FlowStatus.cs b/Correlator/Util/FlowStatus.cs deleted file mode 100644 index 384caec..0000000 --- a/Correlator/Util/FlowStatus.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System.Collections.Generic; -using Correlator.Model; -using Correlator.SensorHubTag; - -namespace Correlator.Util -{ - /// - /// 业务流程个节点状态 - /// - public class FlowStatus - { - /// - /// 是否可以收集数据 - /// - public static bool CanCollectData = false; - - /// - /// 红色传感器是否正常 - /// - public static bool RedSensorIsEnable = false; - - /// - /// 蓝色传感器是否正常 - /// - public static bool BlueSensorIsEnable = false; - - /// - /// 采集到的数据 - /// - public static CorrelatorDataModel CorrelatorData; - - /// - /// 水听器模式 - /// - public static bool IsHydrophone = false; - - /// - /// 点名对话框是否已显示 - /// - public static bool IsShowing = false; - - /// - /// 数据包index - /// - public static readonly List SeqCaches = new List(); - - /// - /// 水听器下发唤醒指令时间戳 - /// - public static byte[] HydrophoneWakeUpTimeBytes = new byte[6]; - - /// - /// 水听器红色信号接收器原始数据 - /// - public static readonly Dictionary RedSensorOriginalResp = new Dictionary(); - - /// - /// 水听器红色信号接收器解析之后的Tags - /// - public static readonly Dictionary> RedSensorResponseTags = new Dictionary>(); - - /// - /// 水听器红色信号接收器原始数据 - /// - public static readonly Dictionary BlueSensorOriginalResp = new Dictionary(); - - /// - /// 水听器蓝色信号接收器解析之后的Tags - /// - public static readonly Dictionary> BlueSensorResponseTags = new Dictionary>(); - - //听音数据 - public static readonly List RedSoundCaches = new List(); - public static readonly List BlueSoundCaches = new List(); - - /// - /// 正在听音的设备编号 - /// - public static string CurrentListenSoundDevCode = DevCode.Dev1; - - /// - /// 小于1K的音频文件全路径集合 - /// - public static readonly List SmallAudioFiles = new List(); - } -} \ No newline at end of file diff --git a/Correlator/Util/MethodExtensions.cs b/Correlator/Util/MethodExtensions.cs index 7d742ce..a8b0136 100644 --- a/Correlator/Util/MethodExtensions.cs +++ b/Correlator/Util/MethodExtensions.cs @@ -741,7 +741,7 @@ /// public static int GetPageSize(this int count) { - return (count + 8 - 1) / 8; + return (count + RuntimeCache.PerPageItemCount - 1) / RuntimeCache.PerPageItemCount; } } } \ No newline at end of file diff --git a/Correlator/Util/RuntimeCache.cs b/Correlator/Util/RuntimeCache.cs new file mode 100644 index 0000000..e91619c --- /dev/null +++ b/Correlator/Util/RuntimeCache.cs @@ -0,0 +1,91 @@ +using System.Collections.Generic; +using Correlator.Model; +using Correlator.SensorHubTag; + +namespace Correlator.Util +{ + /// + /// 业务流程个节点状态 + /// + public class RuntimeCache + { + /// + /// 是否可以收集数据 + /// + public static bool CanCollectData = false; + + /// + /// 红色传感器是否正常 + /// + public static bool RedSensorIsEnable = false; + + /// + /// 蓝色传感器是否正常 + /// + public static bool BlueSensorIsEnable = false; + + /// + /// 采集到的数据 + /// + public static CorrelatorDataModel CorrelatorData; + + /// + /// 水听器模式 + /// + public static bool IsHydrophone = false; + + /// + /// 点名对话框是否已显示 + /// + public static bool IsShowing = false; + + /// + /// 数据包index + /// + public static readonly List SeqCaches = new List(); + + /// + /// 水听器下发唤醒指令时间戳 + /// + public static byte[] HydrophoneWakeUpTimeBytes = new byte[6]; + + /// + /// 水听器红色信号接收器原始数据 + /// + public static readonly Dictionary RedSensorOriginalResp = new Dictionary(); + + /// + /// 水听器红色信号接收器解析之后的Tags + /// + public static readonly Dictionary> RedSensorResponseTags = new Dictionary>(); + + /// + /// 水听器红色信号接收器原始数据 + /// + public static readonly Dictionary BlueSensorOriginalResp = new Dictionary(); + + /// + /// 水听器蓝色信号接收器解析之后的Tags + /// + public static readonly Dictionary> BlueSensorResponseTags = new Dictionary>(); + + //听音数据 + public static readonly List RedSoundCaches = new List(); + public static readonly List BlueSoundCaches = new List(); + + /// + /// 正在听音的设备编号 + /// + public static string CurrentListenSoundDevCode = DevCode.Dev1; + + /// + /// 小于1K的音频文件全路径集合 + /// + public static readonly List SmallAudioFiles = new List(); + + /// + /// 列表每页条目数 + /// + public const int PerPageItemCount = 10; + } +} \ No newline at end of file diff --git a/Correlator/ViewModels/AudioFileViewModel.cs b/Correlator/ViewModels/AudioFileViewModel.cs index f522a7a..1846bcc 100644 --- a/Correlator/ViewModels/AudioFileViewModel.cs +++ b/Correlator/ViewModels/AudioFileViewModel.cs @@ -142,7 +142,7 @@ //刷新数据 _totalFiles = GetTotalAudioFiles(); MaxPage = _totalFiles.Count.GetPageSize(); - AudioFiles = _totalFiles.Take(8).ToList(); + AudioFiles = _totalFiles.Take(RuntimeCache.PerPageItemCount).ToList(); } catch (IOException) { @@ -154,7 +154,10 @@ PageUpdatedCmd = new DelegateCommand>(args => { - AudioFiles = _totalFiles.Skip((args.Info - 1) * 8).Take(8).ToList(); + AudioFiles = _totalFiles + .Skip((args.Info - 1) * RuntimeCache.PerPageItemCount) + .Take(RuntimeCache.PerPageItemCount) + .ToList(); }); } @@ -171,7 +174,7 @@ { _totalFiles = GetTotalAudioFiles(); MaxPage = _totalFiles.Count.GetPageSize(); - AudioFiles = _totalFiles.Take(8).ToList(); + AudioFiles = _totalFiles.Take(RuntimeCache.PerPageItemCount).ToList(); } private static List GetTotalAudioFiles() @@ -184,7 +187,7 @@ { if (file.Length < 1024) { - FlowStatus.SmallAudioFiles.Add(file.FullName); + RuntimeCache.SmallAudioFiles.Add(file.FullName); } else { diff --git a/Correlator/ViewModels/AuditionViewModel.cs b/Correlator/ViewModels/AuditionViewModel.cs index b334ec9..7945aa7 100644 --- a/Correlator/ViewModels/AuditionViewModel.cs +++ b/Correlator/ViewModels/AuditionViewModel.cs @@ -94,7 +94,7 @@ sts[outIndex++] = BitConverter.ToInt16(buffer, i) / 32768f; } - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { eventAggregator.GetEvent().Publish(sts); } @@ -117,7 +117,7 @@ CommandSender.SendSoundStopCmd(_serialPortService.Sp, _isRedSensor ? DevCode.Dev1 : DevCode.Dev2); _audioService.Stop(); _isStartRecording = false; - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { //TODO 保存原始PCM数据到文件 // using (var fs = new FileStream("C:\\Users\\Administrator\\Desktop\\input.pcm", @@ -129,13 +129,13 @@ // } // } - FlowStatus.RedSoundCaches.SaveSoundData(); - FlowStatus.RedSoundCaches.Clear(); + RuntimeCache.RedSoundCaches.SaveSoundData(); + RuntimeCache.RedSoundCaches.Clear(); } else { - FlowStatus.BlueSoundCaches.SaveSoundData(); - FlowStatus.BlueSoundCaches.Clear(); + RuntimeCache.BlueSoundCaches.SaveSoundData(); + RuntimeCache.BlueSoundCaches.Clear(); } //波形图停止模拟 @@ -146,7 +146,7 @@ var devCode = _isRedSensor ? DevCode.Dev1 : DevCode.Dev2; CommandSender.SendSoundCollectCmd(_serialPortService.Sp, devCode); - FlowStatus.CurrentListenSoundDevCode = devCode; + RuntimeCache.CurrentListenSoundDevCode = devCode; _audioService.Start(devCode); _isStartRecording = true; diff --git a/Correlator/ViewModels/CheckResponseDialogViewModel.cs b/Correlator/ViewModels/CheckResponseDialogViewModel.cs index e3b140f..a6dd527 100644 --- a/Correlator/ViewModels/CheckResponseDialogViewModel.cs +++ b/Correlator/ViewModels/CheckResponseDialogViewModel.cs @@ -16,7 +16,7 @@ { eventAggregator.GetEvent().Subscribe(delegate(IDialogResult result) { - FlowStatus.IsShowing = false; + RuntimeCache.IsShowing = false; RequestClose?.Invoke(result); }); } diff --git a/Correlator/ViewModels/ImportResponseDialogViewModel.cs b/Correlator/ViewModels/ImportResponseDialogViewModel.cs index a914f66..5b6c1f3 100644 --- a/Correlator/ViewModels/ImportResponseDialogViewModel.cs +++ b/Correlator/ViewModels/ImportResponseDialogViewModel.cs @@ -343,7 +343,7 @@ private void Worker_OnRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { //赋值给缓存 - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; } /// diff --git a/Correlator/ViewModels/MainWindowViewModel.cs b/Correlator/ViewModels/MainWindowViewModel.cs index 3de31b7..bec9b09 100644 --- a/Correlator/ViewModels/MainWindowViewModel.cs +++ b/Correlator/ViewModels/MainWindowViewModel.cs @@ -495,7 +495,7 @@ RedTransmitterBattery = Convert.ToInt32(dev.Cell); RedTransmitterSignalIntensity = 5; RedTransmitterState = true; - FlowStatus.RedSensorIsEnable = true; + RuntimeCache.RedSensorIsEnable = true; }); _eventAggregator.GetEvent().Subscribe(delegate(DevStatus dev) @@ -506,7 +506,7 @@ BlueTransmitterBattery = Convert.ToInt32(dev.Cell); BlueTransmitterSignalIntensity = 5; BlueTransmitterState = true; - FlowStatus.BlueSensorIsEnable = true; + RuntimeCache.BlueSensorIsEnable = true; }); //加速度计 @@ -561,8 +561,8 @@ DialogHub.Get.ShowLoadingDialog(_mainWindow, "数据计算中,请稍后..."); //开始计算就不收集收据了且不能点击开始按钮 StartButtonEnabled = false; - FlowStatus.CanCollectData = false; - if (!FlowStatus.IsHydrophone) + RuntimeCache.CanCollectData = false; + if (!RuntimeCache.IsHydrophone) { //开始计算停止收集指令 _accelerometerCommandTimer.Stop(); @@ -597,7 +597,7 @@ /// private void CalculateData() { - var dataModel = FlowStatus.CorrelatorData; + var dataModel = RuntimeCache.CorrelatorData; if (dataModel.LeftDeviceDataArray != null && dataModel.RightDeviceDataArray != null) { Console.WriteLine(@"MainWindowViewModel => 开始计算"); @@ -628,7 +628,7 @@ _eventAggregator.GetEvent().Publish(array); var time = DateTime.Now.ToString("HHmmss"); - if (FlowStatus.IsHydrophone) + if (RuntimeCache.IsHydrophone) { //保存参数 var paramConfigFile = $"{_locateDataDir}\\参数配置.{_locateTimes}.{time}.json"; @@ -647,12 +647,12 @@ _runningTimer.Stop(); StartButtonEnabled = true; //清空缓存 - FlowStatus.RedSensorOriginalResp.Clear(); - FlowStatus.BlueSensorOriginalResp.Clear(); - FlowStatus.RedSensorResponseTags.Clear(); - FlowStatus.BlueSensorResponseTags.Clear(); - FlowStatus.RedSensorIsEnable = false; - FlowStatus.BlueSensorIsEnable = false; + RuntimeCache.RedSensorOriginalResp.Clear(); + RuntimeCache.BlueSensorOriginalResp.Clear(); + RuntimeCache.RedSensorResponseTags.Clear(); + RuntimeCache.BlueSensorResponseTags.Clear(); + RuntimeCache.RedSensorIsEnable = false; + RuntimeCache.BlueSensorIsEnable = false; DialogHub.Get.DismissLoadingDialog(); } @@ -686,19 +686,19 @@ if (_serialPortService.Sp.IsOpen) { //实时显示信号电量 - if (!FlowStatus.RedSensorIsEnable && !FlowStatus.BlueSensorIsEnable) + if (!RuntimeCache.RedSensorIsEnable && !RuntimeCache.BlueSensorIsEnable) { _devId = (byte)(_devId == 0x02 ? 0x01 : 0x02); _serialPortService.ShowSignal(_devId); } else { - if (!FlowStatus.RedSensorIsEnable) + if (!RuntimeCache.RedSensorIsEnable) { _serialPortService.ShowSignal(0x01); } - if (!FlowStatus.BlueSensorIsEnable) + if (!RuntimeCache.BlueSensorIsEnable) { _serialPortService.ShowSignal(0x02); } @@ -758,7 +758,7 @@ //加速度计下发指令Timer _accelerometerCommandTimer.Tick += delegate { - if (FlowStatus.CanCollectData) + if (RuntimeCache.CanCollectData) { CommandSender.SendCorrelatorWakeUpCmd(_serialPortService.Sp); } @@ -788,13 +788,13 @@ Console.WriteLine(@"MainWindowViewModel => 加载"); it.AccelerationRadioButton.Checked += delegate { - FlowStatus.IsHydrophone = false; + RuntimeCache.IsHydrophone = false; FrequencyInterval = "100 ~ 3000Hz"; }; it.HydrophonesRadioButton.Checked += delegate { - FlowStatus.IsHydrophone = true; + RuntimeCache.IsHydrophone = true; FrequencyInterval = "10 ~ 300Hz"; }; }); @@ -816,12 +816,12 @@ } //删除小于1K的音频 - foreach (var file in FlowStatus.SmallAudioFiles) + foreach (var file in RuntimeCache.SmallAudioFiles) { File.Delete(file); } - FlowStatus.SmallAudioFiles.Clear(); + RuntimeCache.SmallAudioFiles.Clear(); _mainWindow.Close(); } ); @@ -890,7 +890,7 @@ //导入数据 ImportDataCommand = new DelegateCommand(delegate { - if (FlowStatus.IsHydrophone) + if (RuntimeCache.IsHydrophone) { _dialogService.ShowDialog("ImportResponseDialog", null, delegate(IDialogResult result) { @@ -946,18 +946,18 @@ //将采集的数据转为音频并保存 SaveAudioCommand = new DelegateCommand(delegate { - if (FlowStatus.CorrelatorData != null) + if (RuntimeCache.CorrelatorData != null) { var filePath = $"{DirectoryManager.GetAudioDir()}\\音频_{DateTime.Now.ToString("yyyyMMddHHmmss")}.wav"; filePath.SaveWavFile( - FlowStatus.CorrelatorData.LeftDeviceDataArray, - FlowStatus.CorrelatorData.RightDeviceDataArray + RuntimeCache.CorrelatorData.LeftDeviceDataArray, + RuntimeCache.CorrelatorData.RightDeviceDataArray ); Growl.Success("音频已保存"); //清空上次的缓存 - FlowStatus.CorrelatorData = null; + RuntimeCache.CorrelatorData = null; } else { @@ -1011,9 +1011,9 @@ //每次计算之前都需要判断是否已经完成之前的计算,然后清空上一次的计算数据 ResetParam(); - FlowStatus.CanCollectData = true; + RuntimeCache.CanCollectData = true; //开始数据采集 - if (FlowStatus.IsHydrophone) + if (RuntimeCache.IsHydrophone) { CommandSender.SendHydrophoneWakeUpCmd(_serialPortService.Sp); } @@ -1058,12 +1058,12 @@ _eventAggregator.GetEvent().Publish(); - if (!FlowStatus.IsHydrophone) + if (!RuntimeCache.IsHydrophone) { _accelerometerCommandTimer.Stop(); } - FlowStatus.CanCollectData = false; + RuntimeCache.CanCollectData = false; } /// @@ -1146,7 +1146,7 @@ var low = Convert.ToInt32(_lowFrequency); var high = Convert.ToInt32(_highFrequency); - if (FlowStatus.IsHydrophone) + if (RuntimeCache.IsHydrophone) { if (low < 10 || low > 300 || high < 10 || high > 300 || low >= high) { diff --git a/Correlator/ViewModels/PictureFileViewModel.cs b/Correlator/ViewModels/PictureFileViewModel.cs index 785f031..792d6b8 100644 --- a/Correlator/ViewModels/PictureFileViewModel.cs +++ b/Correlator/ViewModels/PictureFileViewModel.cs @@ -104,7 +104,7 @@ //刷新数据 _totalFiles = GetTotalPictureFiles(); MaxPage = _totalFiles.Count.GetPageSize(); - PictureFiles = _totalFiles.Take(8).ToList(); + PictureFiles = _totalFiles.Take(RuntimeCache.PerPageItemCount).ToList(); } catch (IOException) { @@ -116,7 +116,10 @@ PageUpdatedCmd = new DelegateCommand>(args => { - PictureFiles = _totalFiles.Skip((args.Info - 1) * 8).Take(8).ToList(); + PictureFiles = _totalFiles + .Skip((args.Info - 1) * RuntimeCache.PerPageItemCount) + .Take(RuntimeCache.PerPageItemCount) + .ToList(); }); } @@ -133,7 +136,7 @@ { _totalFiles = GetTotalPictureFiles(); MaxPage = _totalFiles.Count.GetPageSize(); - PictureFiles = _totalFiles.Take(8).ToList(); + PictureFiles = _totalFiles.Take(RuntimeCache.PerPageItemCount).ToList(); } private static List GetTotalPictureFiles() diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index cb3946e..5d33683 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -265,7 +265,7 @@ - + diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index 4c897c0..51294cd 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -81,23 +81,23 @@ break; case 11293: //数据采集 - if (!FlowStatus.IsHydrophone) + if (!RuntimeCache.IsHydrophone) { HandleCorrelatorData(deviceId, tags); } break; case 30: - if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) + if (RuntimeCache.IsHydrophone && RuntimeCache.CanCollectData) { Application.Current.Dispatcher.Invoke(delegate { //显示点名弹窗 - if (!FlowStatus.IsShowing) + if (!RuntimeCache.IsShowing) { //因为是广播发的数据,所以会收到两条回复,但是只需要显示一次对话框 _eventAggregator.GetEvent().Publish(); - FlowStatus.IsShowing = true; + RuntimeCache.IsShowing = true; } }); } @@ -108,23 +108,23 @@ { int index = receiveData[15]; //取出seq,确定收到的是第几包数据 - FlowStatus.SeqCaches.Add(index); + RuntimeCache.SeqCaches.Add(index); var response = BitConverter.ToString(receiveData).Replace("-", ""); //收集数据 if (deviceId.Equals(DevCode.Dev1)) { //原始数据 - FlowStatus.RedSensorOriginalResp.Add(index, response); + RuntimeCache.RedSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.RedSensorResponseTags.Add(index, tags); + RuntimeCache.RedSensorResponseTags.Add(index, tags); } else { //原始数据 - FlowStatus.BlueSensorOriginalResp.Add(index, response); + RuntimeCache.BlueSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.BlueSensorResponseTags.Add(index, tags); + RuntimeCache.BlueSensorResponseTags.Add(index, tags); } } @@ -243,7 +243,7 @@ //左右两边接收到的数据时间差超过10s,认为不是同一次此指令返回的,舍弃 if (diffTime >= 10) return; - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; _eventAggregator.GetEvent().Publish(); } else @@ -273,13 +273,13 @@ } //保存听音数据 - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { - FlowStatus.RedSoundCaches.Add(pcm); + RuntimeCache.RedSoundCaches.Add(pcm); } else { - FlowStatus.BlueSoundCaches.Add(pcm); + RuntimeCache.BlueSoundCaches.Add(pcm); } //将pcm数据写入缓存 @@ -325,7 +325,7 @@ _dataModel.RightDeviceDataArray = doubleArrays.ToOneDimensionalArray(); } - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; "SerialPortServiceImpl".WriteLog(devCode + "数据处理完成"); } diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8def641..43f84fd 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -74,7 +74,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -88,7 +88,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -105,7 +105,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -118,7 +118,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -230,7 +230,7 @@ { if (RedSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev1); _redResponseTimer.Start(); @@ -245,7 +245,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev1}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.RedSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.RedSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -257,7 +257,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.RedSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.RedSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { @@ -314,7 +314,7 @@ { if (BlueSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev2); _blueResponseTimer.Start(); @@ -328,7 +328,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev2}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.BlueSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.BlueSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -340,7 +340,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.BlueSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.BlueSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { diff --git a/Correlator/Util/CommandSender.cs b/Correlator/Util/CommandSender.cs index afb3b85..5efc675 100644 --- a/Correlator/Util/CommandSender.cs +++ b/Correlator/Util/CommandSender.cs @@ -119,7 +119,7 @@ }; //获取时间(年-月-日-时-分-秒),年号-2000 - FlowStatus.HydrophoneWakeUpTimeBytes = new[] + RuntimeCache.HydrophoneWakeUpTimeBytes = new[] { CalendarHub.Year, CalendarHub.Mon, CalendarHub.Day, CalendarHub.Hor, CalendarHub.Min, CalendarHub.Sec }; @@ -127,9 +127,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data @@ -226,9 +226,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data @@ -318,9 +318,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data diff --git a/Correlator/Util/FlowStatus.cs b/Correlator/Util/FlowStatus.cs deleted file mode 100644 index 384caec..0000000 --- a/Correlator/Util/FlowStatus.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System.Collections.Generic; -using Correlator.Model; -using Correlator.SensorHubTag; - -namespace Correlator.Util -{ - /// - /// 业务流程个节点状态 - /// - public class FlowStatus - { - /// - /// 是否可以收集数据 - /// - public static bool CanCollectData = false; - - /// - /// 红色传感器是否正常 - /// - public static bool RedSensorIsEnable = false; - - /// - /// 蓝色传感器是否正常 - /// - public static bool BlueSensorIsEnable = false; - - /// - /// 采集到的数据 - /// - public static CorrelatorDataModel CorrelatorData; - - /// - /// 水听器模式 - /// - public static bool IsHydrophone = false; - - /// - /// 点名对话框是否已显示 - /// - public static bool IsShowing = false; - - /// - /// 数据包index - /// - public static readonly List SeqCaches = new List(); - - /// - /// 水听器下发唤醒指令时间戳 - /// - public static byte[] HydrophoneWakeUpTimeBytes = new byte[6]; - - /// - /// 水听器红色信号接收器原始数据 - /// - public static readonly Dictionary RedSensorOriginalResp = new Dictionary(); - - /// - /// 水听器红色信号接收器解析之后的Tags - /// - public static readonly Dictionary> RedSensorResponseTags = new Dictionary>(); - - /// - /// 水听器红色信号接收器原始数据 - /// - public static readonly Dictionary BlueSensorOriginalResp = new Dictionary(); - - /// - /// 水听器蓝色信号接收器解析之后的Tags - /// - public static readonly Dictionary> BlueSensorResponseTags = new Dictionary>(); - - //听音数据 - public static readonly List RedSoundCaches = new List(); - public static readonly List BlueSoundCaches = new List(); - - /// - /// 正在听音的设备编号 - /// - public static string CurrentListenSoundDevCode = DevCode.Dev1; - - /// - /// 小于1K的音频文件全路径集合 - /// - public static readonly List SmallAudioFiles = new List(); - } -} \ No newline at end of file diff --git a/Correlator/Util/MethodExtensions.cs b/Correlator/Util/MethodExtensions.cs index 7d742ce..a8b0136 100644 --- a/Correlator/Util/MethodExtensions.cs +++ b/Correlator/Util/MethodExtensions.cs @@ -741,7 +741,7 @@ /// public static int GetPageSize(this int count) { - return (count + 8 - 1) / 8; + return (count + RuntimeCache.PerPageItemCount - 1) / RuntimeCache.PerPageItemCount; } } } \ No newline at end of file diff --git a/Correlator/Util/RuntimeCache.cs b/Correlator/Util/RuntimeCache.cs new file mode 100644 index 0000000..e91619c --- /dev/null +++ b/Correlator/Util/RuntimeCache.cs @@ -0,0 +1,91 @@ +using System.Collections.Generic; +using Correlator.Model; +using Correlator.SensorHubTag; + +namespace Correlator.Util +{ + /// + /// 业务流程个节点状态 + /// + public class RuntimeCache + { + /// + /// 是否可以收集数据 + /// + public static bool CanCollectData = false; + + /// + /// 红色传感器是否正常 + /// + public static bool RedSensorIsEnable = false; + + /// + /// 蓝色传感器是否正常 + /// + public static bool BlueSensorIsEnable = false; + + /// + /// 采集到的数据 + /// + public static CorrelatorDataModel CorrelatorData; + + /// + /// 水听器模式 + /// + public static bool IsHydrophone = false; + + /// + /// 点名对话框是否已显示 + /// + public static bool IsShowing = false; + + /// + /// 数据包index + /// + public static readonly List SeqCaches = new List(); + + /// + /// 水听器下发唤醒指令时间戳 + /// + public static byte[] HydrophoneWakeUpTimeBytes = new byte[6]; + + /// + /// 水听器红色信号接收器原始数据 + /// + public static readonly Dictionary RedSensorOriginalResp = new Dictionary(); + + /// + /// 水听器红色信号接收器解析之后的Tags + /// + public static readonly Dictionary> RedSensorResponseTags = new Dictionary>(); + + /// + /// 水听器红色信号接收器原始数据 + /// + public static readonly Dictionary BlueSensorOriginalResp = new Dictionary(); + + /// + /// 水听器蓝色信号接收器解析之后的Tags + /// + public static readonly Dictionary> BlueSensorResponseTags = new Dictionary>(); + + //听音数据 + public static readonly List RedSoundCaches = new List(); + public static readonly List BlueSoundCaches = new List(); + + /// + /// 正在听音的设备编号 + /// + public static string CurrentListenSoundDevCode = DevCode.Dev1; + + /// + /// 小于1K的音频文件全路径集合 + /// + public static readonly List SmallAudioFiles = new List(); + + /// + /// 列表每页条目数 + /// + public const int PerPageItemCount = 10; + } +} \ No newline at end of file diff --git a/Correlator/ViewModels/AudioFileViewModel.cs b/Correlator/ViewModels/AudioFileViewModel.cs index f522a7a..1846bcc 100644 --- a/Correlator/ViewModels/AudioFileViewModel.cs +++ b/Correlator/ViewModels/AudioFileViewModel.cs @@ -142,7 +142,7 @@ //刷新数据 _totalFiles = GetTotalAudioFiles(); MaxPage = _totalFiles.Count.GetPageSize(); - AudioFiles = _totalFiles.Take(8).ToList(); + AudioFiles = _totalFiles.Take(RuntimeCache.PerPageItemCount).ToList(); } catch (IOException) { @@ -154,7 +154,10 @@ PageUpdatedCmd = new DelegateCommand>(args => { - AudioFiles = _totalFiles.Skip((args.Info - 1) * 8).Take(8).ToList(); + AudioFiles = _totalFiles + .Skip((args.Info - 1) * RuntimeCache.PerPageItemCount) + .Take(RuntimeCache.PerPageItemCount) + .ToList(); }); } @@ -171,7 +174,7 @@ { _totalFiles = GetTotalAudioFiles(); MaxPage = _totalFiles.Count.GetPageSize(); - AudioFiles = _totalFiles.Take(8).ToList(); + AudioFiles = _totalFiles.Take(RuntimeCache.PerPageItemCount).ToList(); } private static List GetTotalAudioFiles() @@ -184,7 +187,7 @@ { if (file.Length < 1024) { - FlowStatus.SmallAudioFiles.Add(file.FullName); + RuntimeCache.SmallAudioFiles.Add(file.FullName); } else { diff --git a/Correlator/ViewModels/AuditionViewModel.cs b/Correlator/ViewModels/AuditionViewModel.cs index b334ec9..7945aa7 100644 --- a/Correlator/ViewModels/AuditionViewModel.cs +++ b/Correlator/ViewModels/AuditionViewModel.cs @@ -94,7 +94,7 @@ sts[outIndex++] = BitConverter.ToInt16(buffer, i) / 32768f; } - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { eventAggregator.GetEvent().Publish(sts); } @@ -117,7 +117,7 @@ CommandSender.SendSoundStopCmd(_serialPortService.Sp, _isRedSensor ? DevCode.Dev1 : DevCode.Dev2); _audioService.Stop(); _isStartRecording = false; - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { //TODO 保存原始PCM数据到文件 // using (var fs = new FileStream("C:\\Users\\Administrator\\Desktop\\input.pcm", @@ -129,13 +129,13 @@ // } // } - FlowStatus.RedSoundCaches.SaveSoundData(); - FlowStatus.RedSoundCaches.Clear(); + RuntimeCache.RedSoundCaches.SaveSoundData(); + RuntimeCache.RedSoundCaches.Clear(); } else { - FlowStatus.BlueSoundCaches.SaveSoundData(); - FlowStatus.BlueSoundCaches.Clear(); + RuntimeCache.BlueSoundCaches.SaveSoundData(); + RuntimeCache.BlueSoundCaches.Clear(); } //波形图停止模拟 @@ -146,7 +146,7 @@ var devCode = _isRedSensor ? DevCode.Dev1 : DevCode.Dev2; CommandSender.SendSoundCollectCmd(_serialPortService.Sp, devCode); - FlowStatus.CurrentListenSoundDevCode = devCode; + RuntimeCache.CurrentListenSoundDevCode = devCode; _audioService.Start(devCode); _isStartRecording = true; diff --git a/Correlator/ViewModels/CheckResponseDialogViewModel.cs b/Correlator/ViewModels/CheckResponseDialogViewModel.cs index e3b140f..a6dd527 100644 --- a/Correlator/ViewModels/CheckResponseDialogViewModel.cs +++ b/Correlator/ViewModels/CheckResponseDialogViewModel.cs @@ -16,7 +16,7 @@ { eventAggregator.GetEvent().Subscribe(delegate(IDialogResult result) { - FlowStatus.IsShowing = false; + RuntimeCache.IsShowing = false; RequestClose?.Invoke(result); }); } diff --git a/Correlator/ViewModels/ImportResponseDialogViewModel.cs b/Correlator/ViewModels/ImportResponseDialogViewModel.cs index a914f66..5b6c1f3 100644 --- a/Correlator/ViewModels/ImportResponseDialogViewModel.cs +++ b/Correlator/ViewModels/ImportResponseDialogViewModel.cs @@ -343,7 +343,7 @@ private void Worker_OnRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { //赋值给缓存 - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; } /// diff --git a/Correlator/ViewModels/MainWindowViewModel.cs b/Correlator/ViewModels/MainWindowViewModel.cs index 3de31b7..bec9b09 100644 --- a/Correlator/ViewModels/MainWindowViewModel.cs +++ b/Correlator/ViewModels/MainWindowViewModel.cs @@ -495,7 +495,7 @@ RedTransmitterBattery = Convert.ToInt32(dev.Cell); RedTransmitterSignalIntensity = 5; RedTransmitterState = true; - FlowStatus.RedSensorIsEnable = true; + RuntimeCache.RedSensorIsEnable = true; }); _eventAggregator.GetEvent().Subscribe(delegate(DevStatus dev) @@ -506,7 +506,7 @@ BlueTransmitterBattery = Convert.ToInt32(dev.Cell); BlueTransmitterSignalIntensity = 5; BlueTransmitterState = true; - FlowStatus.BlueSensorIsEnable = true; + RuntimeCache.BlueSensorIsEnable = true; }); //加速度计 @@ -561,8 +561,8 @@ DialogHub.Get.ShowLoadingDialog(_mainWindow, "数据计算中,请稍后..."); //开始计算就不收集收据了且不能点击开始按钮 StartButtonEnabled = false; - FlowStatus.CanCollectData = false; - if (!FlowStatus.IsHydrophone) + RuntimeCache.CanCollectData = false; + if (!RuntimeCache.IsHydrophone) { //开始计算停止收集指令 _accelerometerCommandTimer.Stop(); @@ -597,7 +597,7 @@ /// private void CalculateData() { - var dataModel = FlowStatus.CorrelatorData; + var dataModel = RuntimeCache.CorrelatorData; if (dataModel.LeftDeviceDataArray != null && dataModel.RightDeviceDataArray != null) { Console.WriteLine(@"MainWindowViewModel => 开始计算"); @@ -628,7 +628,7 @@ _eventAggregator.GetEvent().Publish(array); var time = DateTime.Now.ToString("HHmmss"); - if (FlowStatus.IsHydrophone) + if (RuntimeCache.IsHydrophone) { //保存参数 var paramConfigFile = $"{_locateDataDir}\\参数配置.{_locateTimes}.{time}.json"; @@ -647,12 +647,12 @@ _runningTimer.Stop(); StartButtonEnabled = true; //清空缓存 - FlowStatus.RedSensorOriginalResp.Clear(); - FlowStatus.BlueSensorOriginalResp.Clear(); - FlowStatus.RedSensorResponseTags.Clear(); - FlowStatus.BlueSensorResponseTags.Clear(); - FlowStatus.RedSensorIsEnable = false; - FlowStatus.BlueSensorIsEnable = false; + RuntimeCache.RedSensorOriginalResp.Clear(); + RuntimeCache.BlueSensorOriginalResp.Clear(); + RuntimeCache.RedSensorResponseTags.Clear(); + RuntimeCache.BlueSensorResponseTags.Clear(); + RuntimeCache.RedSensorIsEnable = false; + RuntimeCache.BlueSensorIsEnable = false; DialogHub.Get.DismissLoadingDialog(); } @@ -686,19 +686,19 @@ if (_serialPortService.Sp.IsOpen) { //实时显示信号电量 - if (!FlowStatus.RedSensorIsEnable && !FlowStatus.BlueSensorIsEnable) + if (!RuntimeCache.RedSensorIsEnable && !RuntimeCache.BlueSensorIsEnable) { _devId = (byte)(_devId == 0x02 ? 0x01 : 0x02); _serialPortService.ShowSignal(_devId); } else { - if (!FlowStatus.RedSensorIsEnable) + if (!RuntimeCache.RedSensorIsEnable) { _serialPortService.ShowSignal(0x01); } - if (!FlowStatus.BlueSensorIsEnable) + if (!RuntimeCache.BlueSensorIsEnable) { _serialPortService.ShowSignal(0x02); } @@ -758,7 +758,7 @@ //加速度计下发指令Timer _accelerometerCommandTimer.Tick += delegate { - if (FlowStatus.CanCollectData) + if (RuntimeCache.CanCollectData) { CommandSender.SendCorrelatorWakeUpCmd(_serialPortService.Sp); } @@ -788,13 +788,13 @@ Console.WriteLine(@"MainWindowViewModel => 加载"); it.AccelerationRadioButton.Checked += delegate { - FlowStatus.IsHydrophone = false; + RuntimeCache.IsHydrophone = false; FrequencyInterval = "100 ~ 3000Hz"; }; it.HydrophonesRadioButton.Checked += delegate { - FlowStatus.IsHydrophone = true; + RuntimeCache.IsHydrophone = true; FrequencyInterval = "10 ~ 300Hz"; }; }); @@ -816,12 +816,12 @@ } //删除小于1K的音频 - foreach (var file in FlowStatus.SmallAudioFiles) + foreach (var file in RuntimeCache.SmallAudioFiles) { File.Delete(file); } - FlowStatus.SmallAudioFiles.Clear(); + RuntimeCache.SmallAudioFiles.Clear(); _mainWindow.Close(); } ); @@ -890,7 +890,7 @@ //导入数据 ImportDataCommand = new DelegateCommand(delegate { - if (FlowStatus.IsHydrophone) + if (RuntimeCache.IsHydrophone) { _dialogService.ShowDialog("ImportResponseDialog", null, delegate(IDialogResult result) { @@ -946,18 +946,18 @@ //将采集的数据转为音频并保存 SaveAudioCommand = new DelegateCommand(delegate { - if (FlowStatus.CorrelatorData != null) + if (RuntimeCache.CorrelatorData != null) { var filePath = $"{DirectoryManager.GetAudioDir()}\\音频_{DateTime.Now.ToString("yyyyMMddHHmmss")}.wav"; filePath.SaveWavFile( - FlowStatus.CorrelatorData.LeftDeviceDataArray, - FlowStatus.CorrelatorData.RightDeviceDataArray + RuntimeCache.CorrelatorData.LeftDeviceDataArray, + RuntimeCache.CorrelatorData.RightDeviceDataArray ); Growl.Success("音频已保存"); //清空上次的缓存 - FlowStatus.CorrelatorData = null; + RuntimeCache.CorrelatorData = null; } else { @@ -1011,9 +1011,9 @@ //每次计算之前都需要判断是否已经完成之前的计算,然后清空上一次的计算数据 ResetParam(); - FlowStatus.CanCollectData = true; + RuntimeCache.CanCollectData = true; //开始数据采集 - if (FlowStatus.IsHydrophone) + if (RuntimeCache.IsHydrophone) { CommandSender.SendHydrophoneWakeUpCmd(_serialPortService.Sp); } @@ -1058,12 +1058,12 @@ _eventAggregator.GetEvent().Publish(); - if (!FlowStatus.IsHydrophone) + if (!RuntimeCache.IsHydrophone) { _accelerometerCommandTimer.Stop(); } - FlowStatus.CanCollectData = false; + RuntimeCache.CanCollectData = false; } /// @@ -1146,7 +1146,7 @@ var low = Convert.ToInt32(_lowFrequency); var high = Convert.ToInt32(_highFrequency); - if (FlowStatus.IsHydrophone) + if (RuntimeCache.IsHydrophone) { if (low < 10 || low > 300 || high < 10 || high > 300 || low >= high) { diff --git a/Correlator/ViewModels/PictureFileViewModel.cs b/Correlator/ViewModels/PictureFileViewModel.cs index 785f031..792d6b8 100644 --- a/Correlator/ViewModels/PictureFileViewModel.cs +++ b/Correlator/ViewModels/PictureFileViewModel.cs @@ -104,7 +104,7 @@ //刷新数据 _totalFiles = GetTotalPictureFiles(); MaxPage = _totalFiles.Count.GetPageSize(); - PictureFiles = _totalFiles.Take(8).ToList(); + PictureFiles = _totalFiles.Take(RuntimeCache.PerPageItemCount).ToList(); } catch (IOException) { @@ -116,7 +116,10 @@ PageUpdatedCmd = new DelegateCommand>(args => { - PictureFiles = _totalFiles.Skip((args.Info - 1) * 8).Take(8).ToList(); + PictureFiles = _totalFiles + .Skip((args.Info - 1) * RuntimeCache.PerPageItemCount) + .Take(RuntimeCache.PerPageItemCount) + .ToList(); }); } @@ -133,7 +136,7 @@ { _totalFiles = GetTotalPictureFiles(); MaxPage = _totalFiles.Count.GetPageSize(); - PictureFiles = _totalFiles.Take(8).ToList(); + PictureFiles = _totalFiles.Take(RuntimeCache.PerPageItemCount).ToList(); } private static List GetTotalPictureFiles() diff --git a/Correlator/ViewModels/SimplyAuditionDialogViewModel.cs b/Correlator/ViewModels/SimplyAuditionDialogViewModel.cs index b67086d..1b2d14a 100644 --- a/Correlator/ViewModels/SimplyAuditionDialogViewModel.cs +++ b/Correlator/ViewModels/SimplyAuditionDialogViewModel.cs @@ -121,8 +121,8 @@ CommandSender.SendSoundStopCmd(_serialPortService.Sp, DevCode.Dev1); audioService.Stop(); IsRedRecording = false; - FlowStatus.RedSoundCaches.SaveSoundData(); - FlowStatus.RedSoundCaches.Clear(); + RuntimeCache.RedSoundCaches.SaveSoundData(); + RuntimeCache.RedSoundCaches.Clear(); } else { @@ -173,8 +173,8 @@ CommandSender.SendSoundStopCmd(_serialPortService.Sp, DevCode.Dev2); audioService.Stop(); IsBlueRecording = false; - FlowStatus.BlueSoundCaches.SaveSoundData(); - FlowStatus.BlueSoundCaches.Clear(); + RuntimeCache.BlueSoundCaches.SaveSoundData(); + RuntimeCache.BlueSoundCaches.Clear(); } else { diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index cb3946e..5d33683 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -265,7 +265,7 @@ - + diff --git a/Correlator/DataService/SerialPortServiceImpl.cs b/Correlator/DataService/SerialPortServiceImpl.cs index 4c897c0..51294cd 100644 --- a/Correlator/DataService/SerialPortServiceImpl.cs +++ b/Correlator/DataService/SerialPortServiceImpl.cs @@ -81,23 +81,23 @@ break; case 11293: //数据采集 - if (!FlowStatus.IsHydrophone) + if (!RuntimeCache.IsHydrophone) { HandleCorrelatorData(deviceId, tags); } break; case 30: - if (FlowStatus.IsHydrophone && FlowStatus.CanCollectData) + if (RuntimeCache.IsHydrophone && RuntimeCache.CanCollectData) { Application.Current.Dispatcher.Invoke(delegate { //显示点名弹窗 - if (!FlowStatus.IsShowing) + if (!RuntimeCache.IsShowing) { //因为是广播发的数据,所以会收到两条回复,但是只需要显示一次对话框 _eventAggregator.GetEvent().Publish(); - FlowStatus.IsShowing = true; + RuntimeCache.IsShowing = true; } }); } @@ -108,23 +108,23 @@ { int index = receiveData[15]; //取出seq,确定收到的是第几包数据 - FlowStatus.SeqCaches.Add(index); + RuntimeCache.SeqCaches.Add(index); var response = BitConverter.ToString(receiveData).Replace("-", ""); //收集数据 if (deviceId.Equals(DevCode.Dev1)) { //原始数据 - FlowStatus.RedSensorOriginalResp.Add(index, response); + RuntimeCache.RedSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.RedSensorResponseTags.Add(index, tags); + RuntimeCache.RedSensorResponseTags.Add(index, tags); } else { //原始数据 - FlowStatus.BlueSensorOriginalResp.Add(index, response); + RuntimeCache.BlueSensorOriginalResp.Add(index, response); //解析之后的数据 - FlowStatus.BlueSensorResponseTags.Add(index, tags); + RuntimeCache.BlueSensorResponseTags.Add(index, tags); } } @@ -243,7 +243,7 @@ //左右两边接收到的数据时间差超过10s,认为不是同一次此指令返回的,舍弃 if (diffTime >= 10) return; - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; _eventAggregator.GetEvent().Publish(); } else @@ -273,13 +273,13 @@ } //保存听音数据 - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { - FlowStatus.RedSoundCaches.Add(pcm); + RuntimeCache.RedSoundCaches.Add(pcm); } else { - FlowStatus.BlueSoundCaches.Add(pcm); + RuntimeCache.BlueSoundCaches.Add(pcm); } //将pcm数据写入缓存 @@ -325,7 +325,7 @@ _dataModel.RightDeviceDataArray = doubleArrays.ToOneDimensionalArray(); } - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; "SerialPortServiceImpl".WriteLog(devCode + "数据处理完成"); } diff --git a/Correlator/Dialog/CheckResponseDialog.xaml.cs b/Correlator/Dialog/CheckResponseDialog.xaml.cs index 8def641..43f84fd 100644 --- a/Correlator/Dialog/CheckResponseDialog.xaml.cs +++ b/Correlator/Dialog/CheckResponseDialog.xaml.cs @@ -74,7 +74,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -88,7 +88,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -105,7 +105,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (RedResponsePanel.Children[i - 1] is Ellipse child) { @@ -118,7 +118,7 @@ { for (var i = 1; i <= 60; i++) { - if (FlowStatus.SeqCaches.Contains(i)) + if (RuntimeCache.SeqCaches.Contains(i)) { if (BlueResponsePanel.Children[i - 1] is Ellipse child) { @@ -230,7 +230,7 @@ { if (RedSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev1); _redResponseTimer.Start(); @@ -245,7 +245,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev1}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.RedSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.RedSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -257,7 +257,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.RedSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.RedSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { @@ -314,7 +314,7 @@ { if (BlueSensorStepBar.StepIndex == 1) { - FlowStatus.SeqCaches.Clear(); + RuntimeCache.SeqCaches.Clear(); CommandSender.StartCheckResponse(_serialPortService.Sp, DevCode.Dev2); _blueResponseTimer.Start(); @@ -328,7 +328,7 @@ var fileName = $"{locateDataDir}\\原始数据.{DevCode.Dev2}.txt"; //将Dictionary按照index排序 - var sortResult = from pair in FlowStatus.BlueSensorOriginalResp orderby pair.Key select pair; + var sortResult = from pair in RuntimeCache.BlueSensorOriginalResp orderby pair.Key select pair; //Dictionary排序结果转List var result = sortResult.Select(valuePair => valuePair.Value).ToList(); @@ -340,7 +340,7 @@ #region 处理数据 //将Dictionary按照index排序 - var tagsSortResult = from pair in FlowStatus.BlueSensorResponseTags orderby pair.Key select pair; + var tagsSortResult = from pair in RuntimeCache.BlueSensorResponseTags orderby pair.Key select pair; var tags = new List(); foreach (var valuePair in tagsSortResult) { diff --git a/Correlator/Util/CommandSender.cs b/Correlator/Util/CommandSender.cs index afb3b85..5efc675 100644 --- a/Correlator/Util/CommandSender.cs +++ b/Correlator/Util/CommandSender.cs @@ -119,7 +119,7 @@ }; //获取时间(年-月-日-时-分-秒),年号-2000 - FlowStatus.HydrophoneWakeUpTimeBytes = new[] + RuntimeCache.HydrophoneWakeUpTimeBytes = new[] { CalendarHub.Year, CalendarHub.Mon, CalendarHub.Day, CalendarHub.Hor, CalendarHub.Min, CalendarHub.Sec }; @@ -127,9 +127,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data @@ -226,9 +226,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data @@ -318,9 +318,9 @@ { 0x10, 0x00, 0x00, 0x51, 0x00, 0x06, - FlowStatus.HydrophoneWakeUpTimeBytes[0], FlowStatus.HydrophoneWakeUpTimeBytes[1], - FlowStatus.HydrophoneWakeUpTimeBytes[2], FlowStatus.HydrophoneWakeUpTimeBytes[3], - FlowStatus.HydrophoneWakeUpTimeBytes[4], FlowStatus.HydrophoneWakeUpTimeBytes[5] + RuntimeCache.HydrophoneWakeUpTimeBytes[0], RuntimeCache.HydrophoneWakeUpTimeBytes[1], + RuntimeCache.HydrophoneWakeUpTimeBytes[2], RuntimeCache.HydrophoneWakeUpTimeBytes[3], + RuntimeCache.HydrophoneWakeUpTimeBytes[4], RuntimeCache.HydrophoneWakeUpTimeBytes[5] }; //时间oid //wrap the whole data diff --git a/Correlator/Util/FlowStatus.cs b/Correlator/Util/FlowStatus.cs deleted file mode 100644 index 384caec..0000000 --- a/Correlator/Util/FlowStatus.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System.Collections.Generic; -using Correlator.Model; -using Correlator.SensorHubTag; - -namespace Correlator.Util -{ - /// - /// 业务流程个节点状态 - /// - public class FlowStatus - { - /// - /// 是否可以收集数据 - /// - public static bool CanCollectData = false; - - /// - /// 红色传感器是否正常 - /// - public static bool RedSensorIsEnable = false; - - /// - /// 蓝色传感器是否正常 - /// - public static bool BlueSensorIsEnable = false; - - /// - /// 采集到的数据 - /// - public static CorrelatorDataModel CorrelatorData; - - /// - /// 水听器模式 - /// - public static bool IsHydrophone = false; - - /// - /// 点名对话框是否已显示 - /// - public static bool IsShowing = false; - - /// - /// 数据包index - /// - public static readonly List SeqCaches = new List(); - - /// - /// 水听器下发唤醒指令时间戳 - /// - public static byte[] HydrophoneWakeUpTimeBytes = new byte[6]; - - /// - /// 水听器红色信号接收器原始数据 - /// - public static readonly Dictionary RedSensorOriginalResp = new Dictionary(); - - /// - /// 水听器红色信号接收器解析之后的Tags - /// - public static readonly Dictionary> RedSensorResponseTags = new Dictionary>(); - - /// - /// 水听器红色信号接收器原始数据 - /// - public static readonly Dictionary BlueSensorOriginalResp = new Dictionary(); - - /// - /// 水听器蓝色信号接收器解析之后的Tags - /// - public static readonly Dictionary> BlueSensorResponseTags = new Dictionary>(); - - //听音数据 - public static readonly List RedSoundCaches = new List(); - public static readonly List BlueSoundCaches = new List(); - - /// - /// 正在听音的设备编号 - /// - public static string CurrentListenSoundDevCode = DevCode.Dev1; - - /// - /// 小于1K的音频文件全路径集合 - /// - public static readonly List SmallAudioFiles = new List(); - } -} \ No newline at end of file diff --git a/Correlator/Util/MethodExtensions.cs b/Correlator/Util/MethodExtensions.cs index 7d742ce..a8b0136 100644 --- a/Correlator/Util/MethodExtensions.cs +++ b/Correlator/Util/MethodExtensions.cs @@ -741,7 +741,7 @@ /// public static int GetPageSize(this int count) { - return (count + 8 - 1) / 8; + return (count + RuntimeCache.PerPageItemCount - 1) / RuntimeCache.PerPageItemCount; } } } \ No newline at end of file diff --git a/Correlator/Util/RuntimeCache.cs b/Correlator/Util/RuntimeCache.cs new file mode 100644 index 0000000..e91619c --- /dev/null +++ b/Correlator/Util/RuntimeCache.cs @@ -0,0 +1,91 @@ +using System.Collections.Generic; +using Correlator.Model; +using Correlator.SensorHubTag; + +namespace Correlator.Util +{ + /// + /// 业务流程个节点状态 + /// + public class RuntimeCache + { + /// + /// 是否可以收集数据 + /// + public static bool CanCollectData = false; + + /// + /// 红色传感器是否正常 + /// + public static bool RedSensorIsEnable = false; + + /// + /// 蓝色传感器是否正常 + /// + public static bool BlueSensorIsEnable = false; + + /// + /// 采集到的数据 + /// + public static CorrelatorDataModel CorrelatorData; + + /// + /// 水听器模式 + /// + public static bool IsHydrophone = false; + + /// + /// 点名对话框是否已显示 + /// + public static bool IsShowing = false; + + /// + /// 数据包index + /// + public static readonly List SeqCaches = new List(); + + /// + /// 水听器下发唤醒指令时间戳 + /// + public static byte[] HydrophoneWakeUpTimeBytes = new byte[6]; + + /// + /// 水听器红色信号接收器原始数据 + /// + public static readonly Dictionary RedSensorOriginalResp = new Dictionary(); + + /// + /// 水听器红色信号接收器解析之后的Tags + /// + public static readonly Dictionary> RedSensorResponseTags = new Dictionary>(); + + /// + /// 水听器红色信号接收器原始数据 + /// + public static readonly Dictionary BlueSensorOriginalResp = new Dictionary(); + + /// + /// 水听器蓝色信号接收器解析之后的Tags + /// + public static readonly Dictionary> BlueSensorResponseTags = new Dictionary>(); + + //听音数据 + public static readonly List RedSoundCaches = new List(); + public static readonly List BlueSoundCaches = new List(); + + /// + /// 正在听音的设备编号 + /// + public static string CurrentListenSoundDevCode = DevCode.Dev1; + + /// + /// 小于1K的音频文件全路径集合 + /// + public static readonly List SmallAudioFiles = new List(); + + /// + /// 列表每页条目数 + /// + public const int PerPageItemCount = 10; + } +} \ No newline at end of file diff --git a/Correlator/ViewModels/AudioFileViewModel.cs b/Correlator/ViewModels/AudioFileViewModel.cs index f522a7a..1846bcc 100644 --- a/Correlator/ViewModels/AudioFileViewModel.cs +++ b/Correlator/ViewModels/AudioFileViewModel.cs @@ -142,7 +142,7 @@ //刷新数据 _totalFiles = GetTotalAudioFiles(); MaxPage = _totalFiles.Count.GetPageSize(); - AudioFiles = _totalFiles.Take(8).ToList(); + AudioFiles = _totalFiles.Take(RuntimeCache.PerPageItemCount).ToList(); } catch (IOException) { @@ -154,7 +154,10 @@ PageUpdatedCmd = new DelegateCommand>(args => { - AudioFiles = _totalFiles.Skip((args.Info - 1) * 8).Take(8).ToList(); + AudioFiles = _totalFiles + .Skip((args.Info - 1) * RuntimeCache.PerPageItemCount) + .Take(RuntimeCache.PerPageItemCount) + .ToList(); }); } @@ -171,7 +174,7 @@ { _totalFiles = GetTotalAudioFiles(); MaxPage = _totalFiles.Count.GetPageSize(); - AudioFiles = _totalFiles.Take(8).ToList(); + AudioFiles = _totalFiles.Take(RuntimeCache.PerPageItemCount).ToList(); } private static List GetTotalAudioFiles() @@ -184,7 +187,7 @@ { if (file.Length < 1024) { - FlowStatus.SmallAudioFiles.Add(file.FullName); + RuntimeCache.SmallAudioFiles.Add(file.FullName); } else { diff --git a/Correlator/ViewModels/AuditionViewModel.cs b/Correlator/ViewModels/AuditionViewModel.cs index b334ec9..7945aa7 100644 --- a/Correlator/ViewModels/AuditionViewModel.cs +++ b/Correlator/ViewModels/AuditionViewModel.cs @@ -94,7 +94,7 @@ sts[outIndex++] = BitConverter.ToInt16(buffer, i) / 32768f; } - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { eventAggregator.GetEvent().Publish(sts); } @@ -117,7 +117,7 @@ CommandSender.SendSoundStopCmd(_serialPortService.Sp, _isRedSensor ? DevCode.Dev1 : DevCode.Dev2); _audioService.Stop(); _isStartRecording = false; - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { //TODO 保存原始PCM数据到文件 // using (var fs = new FileStream("C:\\Users\\Administrator\\Desktop\\input.pcm", @@ -129,13 +129,13 @@ // } // } - FlowStatus.RedSoundCaches.SaveSoundData(); - FlowStatus.RedSoundCaches.Clear(); + RuntimeCache.RedSoundCaches.SaveSoundData(); + RuntimeCache.RedSoundCaches.Clear(); } else { - FlowStatus.BlueSoundCaches.SaveSoundData(); - FlowStatus.BlueSoundCaches.Clear(); + RuntimeCache.BlueSoundCaches.SaveSoundData(); + RuntimeCache.BlueSoundCaches.Clear(); } //波形图停止模拟 @@ -146,7 +146,7 @@ var devCode = _isRedSensor ? DevCode.Dev1 : DevCode.Dev2; CommandSender.SendSoundCollectCmd(_serialPortService.Sp, devCode); - FlowStatus.CurrentListenSoundDevCode = devCode; + RuntimeCache.CurrentListenSoundDevCode = devCode; _audioService.Start(devCode); _isStartRecording = true; diff --git a/Correlator/ViewModels/CheckResponseDialogViewModel.cs b/Correlator/ViewModels/CheckResponseDialogViewModel.cs index e3b140f..a6dd527 100644 --- a/Correlator/ViewModels/CheckResponseDialogViewModel.cs +++ b/Correlator/ViewModels/CheckResponseDialogViewModel.cs @@ -16,7 +16,7 @@ { eventAggregator.GetEvent().Subscribe(delegate(IDialogResult result) { - FlowStatus.IsShowing = false; + RuntimeCache.IsShowing = false; RequestClose?.Invoke(result); }); } diff --git a/Correlator/ViewModels/ImportResponseDialogViewModel.cs b/Correlator/ViewModels/ImportResponseDialogViewModel.cs index a914f66..5b6c1f3 100644 --- a/Correlator/ViewModels/ImportResponseDialogViewModel.cs +++ b/Correlator/ViewModels/ImportResponseDialogViewModel.cs @@ -343,7 +343,7 @@ private void Worker_OnRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { //赋值给缓存 - FlowStatus.CorrelatorData = _dataModel; + RuntimeCache.CorrelatorData = _dataModel; } /// diff --git a/Correlator/ViewModels/MainWindowViewModel.cs b/Correlator/ViewModels/MainWindowViewModel.cs index 3de31b7..bec9b09 100644 --- a/Correlator/ViewModels/MainWindowViewModel.cs +++ b/Correlator/ViewModels/MainWindowViewModel.cs @@ -495,7 +495,7 @@ RedTransmitterBattery = Convert.ToInt32(dev.Cell); RedTransmitterSignalIntensity = 5; RedTransmitterState = true; - FlowStatus.RedSensorIsEnable = true; + RuntimeCache.RedSensorIsEnable = true; }); _eventAggregator.GetEvent().Subscribe(delegate(DevStatus dev) @@ -506,7 +506,7 @@ BlueTransmitterBattery = Convert.ToInt32(dev.Cell); BlueTransmitterSignalIntensity = 5; BlueTransmitterState = true; - FlowStatus.BlueSensorIsEnable = true; + RuntimeCache.BlueSensorIsEnable = true; }); //加速度计 @@ -561,8 +561,8 @@ DialogHub.Get.ShowLoadingDialog(_mainWindow, "数据计算中,请稍后..."); //开始计算就不收集收据了且不能点击开始按钮 StartButtonEnabled = false; - FlowStatus.CanCollectData = false; - if (!FlowStatus.IsHydrophone) + RuntimeCache.CanCollectData = false; + if (!RuntimeCache.IsHydrophone) { //开始计算停止收集指令 _accelerometerCommandTimer.Stop(); @@ -597,7 +597,7 @@ /// private void CalculateData() { - var dataModel = FlowStatus.CorrelatorData; + var dataModel = RuntimeCache.CorrelatorData; if (dataModel.LeftDeviceDataArray != null && dataModel.RightDeviceDataArray != null) { Console.WriteLine(@"MainWindowViewModel => 开始计算"); @@ -628,7 +628,7 @@ _eventAggregator.GetEvent().Publish(array); var time = DateTime.Now.ToString("HHmmss"); - if (FlowStatus.IsHydrophone) + if (RuntimeCache.IsHydrophone) { //保存参数 var paramConfigFile = $"{_locateDataDir}\\参数配置.{_locateTimes}.{time}.json"; @@ -647,12 +647,12 @@ _runningTimer.Stop(); StartButtonEnabled = true; //清空缓存 - FlowStatus.RedSensorOriginalResp.Clear(); - FlowStatus.BlueSensorOriginalResp.Clear(); - FlowStatus.RedSensorResponseTags.Clear(); - FlowStatus.BlueSensorResponseTags.Clear(); - FlowStatus.RedSensorIsEnable = false; - FlowStatus.BlueSensorIsEnable = false; + RuntimeCache.RedSensorOriginalResp.Clear(); + RuntimeCache.BlueSensorOriginalResp.Clear(); + RuntimeCache.RedSensorResponseTags.Clear(); + RuntimeCache.BlueSensorResponseTags.Clear(); + RuntimeCache.RedSensorIsEnable = false; + RuntimeCache.BlueSensorIsEnable = false; DialogHub.Get.DismissLoadingDialog(); } @@ -686,19 +686,19 @@ if (_serialPortService.Sp.IsOpen) { //实时显示信号电量 - if (!FlowStatus.RedSensorIsEnable && !FlowStatus.BlueSensorIsEnable) + if (!RuntimeCache.RedSensorIsEnable && !RuntimeCache.BlueSensorIsEnable) { _devId = (byte)(_devId == 0x02 ? 0x01 : 0x02); _serialPortService.ShowSignal(_devId); } else { - if (!FlowStatus.RedSensorIsEnable) + if (!RuntimeCache.RedSensorIsEnable) { _serialPortService.ShowSignal(0x01); } - if (!FlowStatus.BlueSensorIsEnable) + if (!RuntimeCache.BlueSensorIsEnable) { _serialPortService.ShowSignal(0x02); } @@ -758,7 +758,7 @@ //加速度计下发指令Timer _accelerometerCommandTimer.Tick += delegate { - if (FlowStatus.CanCollectData) + if (RuntimeCache.CanCollectData) { CommandSender.SendCorrelatorWakeUpCmd(_serialPortService.Sp); } @@ -788,13 +788,13 @@ Console.WriteLine(@"MainWindowViewModel => 加载"); it.AccelerationRadioButton.Checked += delegate { - FlowStatus.IsHydrophone = false; + RuntimeCache.IsHydrophone = false; FrequencyInterval = "100 ~ 3000Hz"; }; it.HydrophonesRadioButton.Checked += delegate { - FlowStatus.IsHydrophone = true; + RuntimeCache.IsHydrophone = true; FrequencyInterval = "10 ~ 300Hz"; }; }); @@ -816,12 +816,12 @@ } //删除小于1K的音频 - foreach (var file in FlowStatus.SmallAudioFiles) + foreach (var file in RuntimeCache.SmallAudioFiles) { File.Delete(file); } - FlowStatus.SmallAudioFiles.Clear(); + RuntimeCache.SmallAudioFiles.Clear(); _mainWindow.Close(); } ); @@ -890,7 +890,7 @@ //导入数据 ImportDataCommand = new DelegateCommand(delegate { - if (FlowStatus.IsHydrophone) + if (RuntimeCache.IsHydrophone) { _dialogService.ShowDialog("ImportResponseDialog", null, delegate(IDialogResult result) { @@ -946,18 +946,18 @@ //将采集的数据转为音频并保存 SaveAudioCommand = new DelegateCommand(delegate { - if (FlowStatus.CorrelatorData != null) + if (RuntimeCache.CorrelatorData != null) { var filePath = $"{DirectoryManager.GetAudioDir()}\\音频_{DateTime.Now.ToString("yyyyMMddHHmmss")}.wav"; filePath.SaveWavFile( - FlowStatus.CorrelatorData.LeftDeviceDataArray, - FlowStatus.CorrelatorData.RightDeviceDataArray + RuntimeCache.CorrelatorData.LeftDeviceDataArray, + RuntimeCache.CorrelatorData.RightDeviceDataArray ); Growl.Success("音频已保存"); //清空上次的缓存 - FlowStatus.CorrelatorData = null; + RuntimeCache.CorrelatorData = null; } else { @@ -1011,9 +1011,9 @@ //每次计算之前都需要判断是否已经完成之前的计算,然后清空上一次的计算数据 ResetParam(); - FlowStatus.CanCollectData = true; + RuntimeCache.CanCollectData = true; //开始数据采集 - if (FlowStatus.IsHydrophone) + if (RuntimeCache.IsHydrophone) { CommandSender.SendHydrophoneWakeUpCmd(_serialPortService.Sp); } @@ -1058,12 +1058,12 @@ _eventAggregator.GetEvent().Publish(); - if (!FlowStatus.IsHydrophone) + if (!RuntimeCache.IsHydrophone) { _accelerometerCommandTimer.Stop(); } - FlowStatus.CanCollectData = false; + RuntimeCache.CanCollectData = false; } /// @@ -1146,7 +1146,7 @@ var low = Convert.ToInt32(_lowFrequency); var high = Convert.ToInt32(_highFrequency); - if (FlowStatus.IsHydrophone) + if (RuntimeCache.IsHydrophone) { if (low < 10 || low > 300 || high < 10 || high > 300 || low >= high) { diff --git a/Correlator/ViewModels/PictureFileViewModel.cs b/Correlator/ViewModels/PictureFileViewModel.cs index 785f031..792d6b8 100644 --- a/Correlator/ViewModels/PictureFileViewModel.cs +++ b/Correlator/ViewModels/PictureFileViewModel.cs @@ -104,7 +104,7 @@ //刷新数据 _totalFiles = GetTotalPictureFiles(); MaxPage = _totalFiles.Count.GetPageSize(); - PictureFiles = _totalFiles.Take(8).ToList(); + PictureFiles = _totalFiles.Take(RuntimeCache.PerPageItemCount).ToList(); } catch (IOException) { @@ -116,7 +116,10 @@ PageUpdatedCmd = new DelegateCommand>(args => { - PictureFiles = _totalFiles.Skip((args.Info - 1) * 8).Take(8).ToList(); + PictureFiles = _totalFiles + .Skip((args.Info - 1) * RuntimeCache.PerPageItemCount) + .Take(RuntimeCache.PerPageItemCount) + .ToList(); }); } @@ -133,7 +136,7 @@ { _totalFiles = GetTotalPictureFiles(); MaxPage = _totalFiles.Count.GetPageSize(); - PictureFiles = _totalFiles.Take(8).ToList(); + PictureFiles = _totalFiles.Take(RuntimeCache.PerPageItemCount).ToList(); } private static List GetTotalPictureFiles() diff --git a/Correlator/ViewModels/SimplyAuditionDialogViewModel.cs b/Correlator/ViewModels/SimplyAuditionDialogViewModel.cs index b67086d..1b2d14a 100644 --- a/Correlator/ViewModels/SimplyAuditionDialogViewModel.cs +++ b/Correlator/ViewModels/SimplyAuditionDialogViewModel.cs @@ -121,8 +121,8 @@ CommandSender.SendSoundStopCmd(_serialPortService.Sp, DevCode.Dev1); audioService.Stop(); IsRedRecording = false; - FlowStatus.RedSoundCaches.SaveSoundData(); - FlowStatus.RedSoundCaches.Clear(); + RuntimeCache.RedSoundCaches.SaveSoundData(); + RuntimeCache.RedSoundCaches.Clear(); } else { @@ -173,8 +173,8 @@ CommandSender.SendSoundStopCmd(_serialPortService.Sp, DevCode.Dev2); audioService.Stop(); IsBlueRecording = false; - FlowStatus.BlueSoundCaches.SaveSoundData(); - FlowStatus.BlueSoundCaches.Clear(); + RuntimeCache.BlueSoundCaches.SaveSoundData(); + RuntimeCache.BlueSoundCaches.Clear(); } else { diff --git a/Correlator/Views/AuditionView.xaml.cs b/Correlator/Views/AuditionView.xaml.cs index 9fca3f0..3f2a986 100644 --- a/Correlator/Views/AuditionView.xaml.cs +++ b/Correlator/Views/AuditionView.xaml.cs @@ -29,7 +29,7 @@ eventAggregator.GetEvent().Subscribe(delegate(float[] floats) { //更新波形图Y轴 - if (FlowStatus.CurrentListenSoundDevCode == DevCode.Dev1) + if (RuntimeCache.CurrentListenSoundDevCode == DevCode.Dev1) { RedSensorScottPlotChart.Plot.Clear(); RedSensorScottPlotChart.Refresh();