diff --git a/StartServerWPF.Assets/GlobalData.cs b/StartServerWPF.Assets/GlobalData.cs
new file mode 100644
index 0000000..f98d261
--- /dev/null
+++ b/StartServerWPF.Assets/GlobalData.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Cryptography.X509Certificates;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace StartServerWPF.Assets
+{
+ public class GlobalData
+ {
+ public static string[] StationNames { get; set; }
+ }
+}
diff --git a/StartServerWPF.Assets/StartServerWPF.Assets.csproj b/StartServerWPF.Assets/StartServerWPF.Assets.csproj
index 8d0b5b3..4a17d71 100644
--- a/StartServerWPF.Assets/StartServerWPF.Assets.csproj
+++ b/StartServerWPF.Assets/StartServerWPF.Assets.csproj
@@ -84,6 +84,7 @@
+
Code
diff --git a/StartServerWPF.Modules.Main/JsonParser.cs b/StartServerWPF.Modules.Main/JsonParser.cs
index cd46ea1..fb734c1 100644
--- a/StartServerWPF.Modules.Main/JsonParser.cs
+++ b/StartServerWPF.Modules.Main/JsonParser.cs
@@ -148,7 +148,8 @@ namespace StartServerWPF.Modules.Main
JsonTextReader reader = new JsonTextReader(sr);
JObject jobj = (JObject)JToken.ReadFrom(reader);
- JObject jordb = JObject.Parse(jobj["channels"].ToString());
+ var jor = jobj["channels"].First;
+ JObject jordb = JObject.Parse(jor.ToString());
string sta = jordb["station"].ToString();
diff --git a/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs
index 2ff11ab..9aa2c4c 100644
--- a/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs
+++ b/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs
@@ -53,6 +53,8 @@ namespace StartServerWPF.Modules.Main.ViewModels
_websocket.WebsocketError = WebSocket_Error;
_websocket.WebSocketMessageReceived = WebSocket4Net_MessageReceived;
+ GlobalData.StationNames = JsonParser.ReadApmsJson(sc.proApms.ProPath + sc.proApms.JsonPath);
+
DialogParameters param = new DialogParameters();
param.Add("type", 1);// 编辑
_dialogService.ShowDialog(
diff --git a/StartServerWPF.Modules.MseedChart/Models/WavesModel.cs b/StartServerWPF.Modules.MseedChart/Models/WavesModel.cs
index 2f500b0..ef3e3b7 100644
--- a/StartServerWPF.Modules.MseedChart/Models/WavesModel.cs
+++ b/StartServerWPF.Modules.MseedChart/Models/WavesModel.cs
@@ -25,7 +25,7 @@ namespace StartServerWPF.Modules.MseedChart.Models
//添加Z分量波形
if (item.dz.Count > 0)
{
- axisY.SetRange(0, 6000);
+ axisY.SetRange(2000, 5000);
}
axisY.Title.Text = string.Format("Ch{0}.Z", item.Name);
axisY.Title.DistanceToAxis = distancetoX;
@@ -34,7 +34,7 @@ namespace StartServerWPF.Modules.MseedChart.Models
axisY = new AxisY(curChart.ViewXY);
if (item.dn.Count > 0)
{
- axisY.SetRange(0, 6000);
+ axisY.SetRange(2000, 5000);
}
axisY.Title.Text = string.Format("Ch{0}.N", item.Name);
axisY.Title.DistanceToAxis = distancetoX;
diff --git a/StartServerWPF.Modules.MseedChart/Service/RedisListService.cs b/StartServerWPF.Modules.MseedChart/Service/RedisListService.cs
index cb3f14d..c6b3420 100644
--- a/StartServerWPF.Modules.MseedChart/Service/RedisListService.cs
+++ b/StartServerWPF.Modules.MseedChart/Service/RedisListService.cs
@@ -258,10 +258,6 @@ namespace ZhaoXi.Advanced.MyRedis.Service
Console.WriteLine($"取消订阅 {c}");
Console.WriteLine();
};
- subscription.OnMessage += (c, s) =>
- {
- // actionOnMessage(c, s, subscription);
- };
subscription.OnMessageBytes += (c, s) =>
{
// ByteToFile(s, "test.mseed");
@@ -275,6 +271,7 @@ namespace ZhaoXi.Advanced.MyRedis.Service
{
var subscription = base.iClient.CreateSubscription();
subscription.UnSubscribeFromChannels(channel);
+ //subscription.UnSubscribeFromAllChannels();
}
public static bool ByteToFile(byte[] byteArray, string fileName)
diff --git a/StartServerWPF.Modules.MseedChart/ViewModels/ChartPlotRealDataViewModel.cs b/StartServerWPF.Modules.MseedChart/ViewModels/ChartPlotRealDataViewModel.cs
index 2c836e7..18ada42 100644
--- a/StartServerWPF.Modules.MseedChart/ViewModels/ChartPlotRealDataViewModel.cs
+++ b/StartServerWPF.Modules.MseedChart/ViewModels/ChartPlotRealDataViewModel.cs
@@ -39,6 +39,8 @@ using ServiceStack;
using ServiceStack.Redis;
using Arction.Licensing;
using System.Runtime.InteropServices;
+using StartServerWPF.Assets;
+using ServiceStack.Text;
namespace StartServerWPF.Modules.MseedChart.ViewModels
{
@@ -51,7 +53,7 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
_dispatcher = Application.Current.Dispatcher;
_wavesModel = new WavesModel();
(Application.Current.MainWindow as System.Windows.Window).Closing += ApplicationClosingDispose;
- IntervalTime=100;
+ IntervalTime=1000;
CreateChart();
loopCallback = new Mseed2asciiApi.LoopCallbackHandler(Mseed2AsciiEvent);
Mseed2asciiApi.MseedDatasCallFun(loopCallback);
@@ -59,6 +61,7 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
}
#region 字段
+ System.Timers.Timer time=new System.Timers.Timer(1000);
Dispatcher _dispatcher;
public int CurPoints;
int _channelCount = 0;
@@ -68,8 +71,6 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
public ConcurrentQueue smList=new ConcurrentQueue();
public List _chartAxisY=new List();
-
- private DispatcherTimer dispatcherTimer=new DispatcherTimer();
#endregion
#region 属性
@@ -191,7 +192,7 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
}
}
- private int _IntervalTime=10;
+ private int _IntervalTime=1000;
public int IntervalTime
{
@@ -200,7 +201,7 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
{
if (value >=10)
{
- dispatcherTimer.Interval = TimeSpan.FromMilliseconds(value);
+ // time.Interval = value;
}
SetProperty(ref _IntervalTime, value);
}
@@ -263,14 +264,24 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
private void Loaded()
{
//N08,N25,N26
- string station = "N02,N05,N06,N08,N09,N10,N11,N12,N13,N14,N15,N16,N19,N20,N22,N23,N24,N25,N26";//,N07,N08,N09,N10,N11,N12,N13,N14,N15,N16,N17,N18,N19,N20,N21,N22,N23,N24,N25,N26,N27";
- var stations = station.Split(',');
+ string station = "N05,N10";
+ var stations = GlobalData.StationNames;// station.Split(',');
smList = _wavesModel.ReadWavesFromJson(stations);
}
private void UnLoaded()
{
-
+ time.Stop();
+ using (RedisListService service = new RedisListService())
+ {
+ if (subNameList != null)
+ {
+ foreach (var subName in subNameList)
+ {
+ service.UnSubscribeFromChannels(subName.Key);
+ }
+ }
+ }
}
private void AxesYVisible(object isCheck)
@@ -495,16 +506,16 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
_lChartAll.BeginUpdate();
if (isStartRealData)
{
- _data = CreateInputData(_channelCount, _samplingFrequency);
+ _data = new double[smList.Count * 3][];
StartChart();
//Set real-time monitoring automatic old data destruction
LChartALL.ViewXY.DropOldSeriesData = true;
_pointsAppended = LChartALL.ViewXY.XAxes[0].Minimum;
- dispatcherTimer.Tick -= CompositionTarget_Rendering;
- dispatcherTimer.Tick += CompositionTarget_Rendering;
+
+ time.Elapsed -= CompositionTarget_Rendering;
+ time.Elapsed += CompositionTarget_Rendering;
LChartALL.ViewXY.XAxes[0].ScrollMode = XAxisScrollMode.Scrolling;
- dispatcherTimer.Start();
-
+ time.Start();
using (RedisListService service = new RedisListService())
{
foreach (var subName in subNameList)
@@ -521,7 +532,6 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
{
service.Subscribe(subName.Key, (c, message, iRedisSubscription) =>
{
- Debug.WriteLine($"注册{1}{c}");
Mseed2asciiApi.bufferMseedData(message.Length, message);
});
}
@@ -530,9 +540,9 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
}
else
{
- dispatcherTimer.Stop();
+ time.Stop();
+ time.Elapsed -= CompositionTarget_Rendering;
LChartALL.ViewXY.XAxes[0].ScrollMode = XAxisScrollMode.None;
- dispatcherTimer.Tick -= CompositionTarget_Rendering;
using (RedisListService service = new RedisListService())
{
foreach (var subName in subNameList)
@@ -548,16 +558,19 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
private void Mseed2AsciiEvent(AsciiDataStruct asciiData)
{
+ DateTime startTime= Convert.ToDateTime(asciiData.endtime).AddHours(8);
+ DateTime endTime = Convert.ToDateTime(asciiData.endtime).AddHours(8);
+ Debug.WriteLine($"注册{asciiData.sid}:{startTime}");
+ var time = endTime - startTime;
byte[] bytes = new byte[asciiData.numsamples * asciiData.samplesize];
// IntPtr bufferHandler = Marshal.AllocHGlobal((int)asciiData.datasize);
Marshal.Copy(asciiData.datasamples, bytes, 0, bytes.Length);
List lines = new List();
-
+ //时间添加到开始
+ lines.Add(startTime.ToOADate());
string[] sid = asciiData.sid.Split('_');
string name = $"HA.{sid[1]}.{sid[2]}.{sid[3]}{sid[4]}{sid[5]}";
-
-
if (asciiData.sampletype == 'i')
{
for (int index = 0; index < bytes.Length; index += 4)
@@ -566,29 +579,27 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
lines.Add(a);
}
}
- string lineStr= String.Join(",", lines);
-
- //else if (asciiData.sampletype == 'f')
- //{
- // for (int index = 0; index < bytes.Length; index += 4)
- // {
- // var b = BitConverter.ToSingle(bytes, index);
- // lines.Add(b);
- // }
- //}
- //else if (asciiData.sampletype == 'd')
- //{
- // for (int index = 0; index < bytes.Length; index += 8)
- // {
- // var b = BitConverter.ToDouble(bytes, index);
- // lines.Add(b);
- // }
- //}
+ else if (asciiData.sampletype == 'f')
+ {
+ for (int index = 0; index < bytes.Length; index += 4)
+ {
+ var b = BitConverter.ToSingle(bytes, index);
+ lines.Add(b);
+ }
+ }
+ else if (asciiData.sampletype == 'd')
+ {
+ for (int index = 0; index < bytes.Length; index += 8)
+ {
+ var b = BitConverter.ToDouble(bytes, index);
+ lines.Add(b);
+ }
+ }
+ string lineStr= String.Join(",", lines);
using (RedisListService service = new RedisListService())
{
- // string data = System.Text.Encoding.ASCII.GetString(bytes);
- service.RPush(name, lineStr);
+ service.LPush(name, lineStr);
}
}
@@ -852,67 +863,62 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
}
#region 实时数据
- private void CompositionTarget_Rendering(object sender, EventArgs e)
+ private void CompositionTarget_Rendering(object sender, System.Timers.ElapsedEventArgs e)
{
RenderNextFrame();
}
private void RenderNextFrame()
{
+ Debug.WriteLine("timeFrame:{0}", DateTime.Now);
if (_lChartAll == null)
{
return;
}
-
- _dispatcher.Invoke(() =>
- {
- //FeedData(/*chartTitleText*/);
- });
- }
- int _iRound = 0;
- double _pointsAppended = 0;
- double[][] _data;
- int PreGenerateDataForRoundCount = 6;
-
-
- //Y axis minimum
- private const double YMin = 0;
- //Y axis maximum
- private const double YMax = 10;
- private double[][] CreateInputData(int seriesCount, int appendCountPerRound)
- {
- //Create input data for all series.
- double[][] data = new double[seriesCount][];
- // System.Threading.Tasks.Parallel.For(0, seriesCount, (seriesIndex) =>
- for (int seriesIndex = 0; seriesIndex < seriesCount; seriesIndex++)
+ using (RedisListService service = new RedisListService())
{
-
- int dataPointCount = PreGenerateDataForRoundCount * appendCountPerRound;
- double[] seriesData = new double[dataPointCount];
- double seriesIndexPlus1 = seriesIndex + 1;
- Random rand = new Random((int)DateTime.Now.Ticks / (seriesIndex + 1));
-
- double y = 50;
- for (int i = 0; i < dataPointCount; i++)
+ foreach (var item in subNameList)
{
- y = y - 0.05 + rand.NextDouble() / 10.0;
- if (y > YMax)
+ List dataDouList = new List();
+ var data = service.Get(item.Key, 0, 0).FirstOrDefault();
+ if( data != null)
{
- y = YMax;
- }
-
- if (y < YMin)
+ IEnumerable datasStr = data.Split(',').Select(a => Convert.ToDouble(a));
+ double oaTime = datasStr.First();
+ if (oaTime < DateTime.Now.AddSeconds(-3).ToOADate())
+ {
+ //取出队列数据
+ service.RemoveStartFromList(item.Key);
+ var DouData = data.Split(',').Select(a => Convert.ToDouble(a)).ToList();
+ DouData.RemoveAt(0);
+ dataDouList.AddRange(DouData);
+ }
+ else
+ {
+ break;
+ }
+ //继续查看数据
+ // data = service.Get(item.Key, 0, 0).FirstOrDefault();
+ }
+ // data =service.BlockingDequeueItemFromList(item.Key, TimeSpan.FromMilliseconds(5));
+ if (dataDouList.Count!=0)
{
- y = YMin;
+ _data[item.Value] =dataDouList.ToArray();
}
-
- seriesData[i] = (float)y;
}
- data[seriesIndex] = seriesData;
- }//);
+ }
+ // if (_data.ToList().Any(d => d != null))
+ {
+ _dispatcher.Invoke(() =>
+ {
+ FeedData(/*chartTitleText*/);
+ });
+ }
- return data;
}
-
+ int _iRound = 0;
+ double _pointsAppended = 0;
+ double[][] _data;
+
private void FeedData()
{
if (_lChartAll != null)
@@ -920,40 +926,21 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
_lChartAll.BeginUpdate();
//Append data to series
- using (RedisListService service = new RedisListService())
+ for (int seriesIndex = 0; seriesIndex < _channelCount; seriesIndex++)
{
- foreach (var item in subNameList)
- {
- string data= service.BlockingDequeueItemFromList(item.Key, TimeSpan.FromMilliseconds(500));
- if(data == null)
- {
- System.Diagnostics.Debug.WriteLine("***********注册:{0},没有收到数据,time:{1}", item.Key, DateTime.Now);
- continue;
- }
- // byte[] bytes = System.Text.Encoding.ASCII.GetBytes(data);
- // List thisSeriesData = new List();
-
- var thisSeriesData = data.Split(',').Select(a=>Convert.ToDouble(a)).ToArray();
- // if (asciiData.sampletype == 'i')
- {
- //for (int index = 0; index < bytes.Length; index += 4)
- //{
- // int a = BitConverter.ToInt32(bytes, index);
- // thisSeriesData.Add(a);
- //}
-
- }
- _lChartAll.ViewXY.SampleDataSeries[subNameList[item.Key]].AddSamples(thisSeriesData, false);
- System.Diagnostics.Debug.WriteLine("***********index:{0}, pointCount:{1},time:{2}", subNameList[item.Key],
- _lChartAll.ViewXY.SampleDataSeries[subNameList[item.Key]].PointCount, DateTime.Now);
- }
+ double[] thisSeriesData = _data[seriesIndex];
+ if (thisSeriesData == null) continue;
+ _lChartAll.ViewXY.SampleDataSeries[seriesIndex].AddSamples(thisSeriesData, false);
+ _data[seriesIndex] = null;
+ System.Diagnostics.Debug.WriteLine("***********index:{0}, pointCount:{1},time:{2}", seriesIndex,
+ _lChartAll.ViewXY.SampleDataSeries[seriesIndex].PointCount, DateTime.Now);
}
-
//System.Threading.Tasks.Parallel.For(0, _channelCount, (seriesIndex) =>
//{
// double[] thisSeriesData = _data[seriesIndex];
// double[] dataToAppendNow = new double[_samplingFrequency];
// Array.Copy(thisSeriesData, 0, dataToAppendNow, 0, _samplingFrequency);
+ // _lChartAll.ViewXY.SampleDataSeries[seriesIndex].AddSamples(_data[seriesIndex], false);
// System.Diagnostics.Debug.WriteLine("***********index:{0}, pointCount:{1},time:{2}", seriesIndex,
// _lChartAll.ViewXY.SampleDataSeries[seriesIndex].PointCount, DateTime.Now);
//});
diff --git a/StartServerWPF/Views/MainWindow.xaml b/StartServerWPF/Views/MainWindow.xaml
index d269b46..27ebfd5 100644
--- a/StartServerWPF/Views/MainWindow.xaml
+++ b/StartServerWPF/Views/MainWindow.xaml
@@ -1,8 +1,8 @@
diff --git a/StartServerWPF/Views/MainWindow.xaml.cs b/StartServerWPF/Views/MainWindow.xaml.cs
index 981524a..adcddfb 100644
--- a/StartServerWPF/Views/MainWindow.xaml.cs
+++ b/StartServerWPF/Views/MainWindow.xaml.cs
@@ -14,6 +14,7 @@ namespace StartServerWPF.Views
public MainWindow()
{
InitializeComponent();
+
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
@@ -30,5 +31,9 @@ namespace StartServerWPF.Views
//}
}
+ private void Window_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
+ {
+ this.DragMove();
+ }
}
}