|
|
|
@ -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<StationModel> smList=new ConcurrentQueue<StationModel>();
|
|
|
|
|
|
|
|
|
|
public List<AxisY> _chartAxisY=new List<AxisY>();
|
|
|
|
|
|
|
|
|
|
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<double> lines = new List<double>();
|
|
|
|
|
|
|
|
|
|
//时间添加到开始
|
|
|
|
|
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<double> dataDouList = new List<double>();
|
|
|
|
|
var data = service.Get(item.Key, 0, 0).FirstOrDefault();
|
|
|
|
|
if( data != null)
|
|
|
|
|
{
|
|
|
|
|
y = YMax;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (y < YMin)
|
|
|
|
|
IEnumerable<double> 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<double> thisSeriesData = new List<double>();
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
//});
|
|
|
|
|