提交数据

master
mzhifa 1 year ago
parent e3a1a1fb24
commit bf42d19e39

@ -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; }
}
}

@ -84,6 +84,7 @@
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="GlobalData.cs" />
<Compile Include="LogHelper.cs" /> <Compile Include="LogHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs"> <Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType> <SubType>Code</SubType>

@ -148,7 +148,8 @@ namespace StartServerWPF.Modules.Main
JsonTextReader reader = new JsonTextReader(sr); JsonTextReader reader = new JsonTextReader(sr);
JObject jobj = (JObject)JToken.ReadFrom(reader); 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(); string sta = jordb["station"].ToString();

@ -53,6 +53,8 @@ namespace StartServerWPF.Modules.Main.ViewModels
_websocket.WebsocketError = WebSocket_Error; _websocket.WebsocketError = WebSocket_Error;
_websocket.WebSocketMessageReceived = WebSocket4Net_MessageReceived; _websocket.WebSocketMessageReceived = WebSocket4Net_MessageReceived;
GlobalData.StationNames = JsonParser.ReadApmsJson(sc.proApms.ProPath + sc.proApms.JsonPath);
DialogParameters param = new DialogParameters(); DialogParameters param = new DialogParameters();
param.Add("type", 1);// 编辑 param.Add("type", 1);// 编辑
_dialogService.ShowDialog( _dialogService.ShowDialog(

@ -25,7 +25,7 @@ namespace StartServerWPF.Modules.MseedChart.Models
//添加Z分量波形 //添加Z分量波形
if (item.dz.Count > 0) 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.Text = string.Format("Ch{0}.Z", item.Name);
axisY.Title.DistanceToAxis = distancetoX; axisY.Title.DistanceToAxis = distancetoX;
@ -34,7 +34,7 @@ namespace StartServerWPF.Modules.MseedChart.Models
axisY = new AxisY(curChart.ViewXY); axisY = new AxisY(curChart.ViewXY);
if (item.dn.Count > 0) 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.Text = string.Format("Ch{0}.N", item.Name);
axisY.Title.DistanceToAxis = distancetoX; axisY.Title.DistanceToAxis = distancetoX;

@ -258,10 +258,6 @@ namespace ZhaoXi.Advanced.MyRedis.Service
Console.WriteLine($"取消订阅 {c}"); Console.WriteLine($"取消订阅 {c}");
Console.WriteLine(); Console.WriteLine();
}; };
subscription.OnMessage += (c, s) =>
{
// actionOnMessage(c, s, subscription);
};
subscription.OnMessageBytes += (c, s) => subscription.OnMessageBytes += (c, s) =>
{ {
// ByteToFile(s, "test.mseed"); // ByteToFile(s, "test.mseed");
@ -275,6 +271,7 @@ namespace ZhaoXi.Advanced.MyRedis.Service
{ {
var subscription = base.iClient.CreateSubscription(); var subscription = base.iClient.CreateSubscription();
subscription.UnSubscribeFromChannels(channel); subscription.UnSubscribeFromChannels(channel);
//subscription.UnSubscribeFromAllChannels();
} }
public static bool ByteToFile(byte[] byteArray, string fileName) public static bool ByteToFile(byte[] byteArray, string fileName)

@ -39,6 +39,8 @@ using ServiceStack;
using ServiceStack.Redis; using ServiceStack.Redis;
using Arction.Licensing; using Arction.Licensing;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using StartServerWPF.Assets;
using ServiceStack.Text;
namespace StartServerWPF.Modules.MseedChart.ViewModels namespace StartServerWPF.Modules.MseedChart.ViewModels
{ {
@ -51,7 +53,7 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
_dispatcher = Application.Current.Dispatcher; _dispatcher = Application.Current.Dispatcher;
_wavesModel = new WavesModel(); _wavesModel = new WavesModel();
(Application.Current.MainWindow as System.Windows.Window).Closing += ApplicationClosingDispose; (Application.Current.MainWindow as System.Windows.Window).Closing += ApplicationClosingDispose;
IntervalTime=100; IntervalTime=1000;
CreateChart(); CreateChart();
loopCallback = new Mseed2asciiApi.LoopCallbackHandler(Mseed2AsciiEvent); loopCallback = new Mseed2asciiApi.LoopCallbackHandler(Mseed2AsciiEvent);
Mseed2asciiApi.MseedDatasCallFun(loopCallback); Mseed2asciiApi.MseedDatasCallFun(loopCallback);
@ -59,6 +61,7 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
} }
#region 字段 #region 字段
System.Timers.Timer time=new System.Timers.Timer(1000);
Dispatcher _dispatcher; Dispatcher _dispatcher;
public int CurPoints; public int CurPoints;
int _channelCount = 0; int _channelCount = 0;
@ -68,8 +71,6 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
public ConcurrentQueue<StationModel> smList=new ConcurrentQueue<StationModel>(); public ConcurrentQueue<StationModel> smList=new ConcurrentQueue<StationModel>();
public List<AxisY> _chartAxisY=new List<AxisY>(); public List<AxisY> _chartAxisY=new List<AxisY>();
private DispatcherTimer dispatcherTimer=new DispatcherTimer();
#endregion #endregion
#region 属性 #region 属性
@ -191,7 +192,7 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
} }
} }
private int _IntervalTime=10; private int _IntervalTime=1000;
public int IntervalTime public int IntervalTime
{ {
@ -200,7 +201,7 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
{ {
if (value >=10) if (value >=10)
{ {
dispatcherTimer.Interval = TimeSpan.FromMilliseconds(value); // time.Interval = value;
} }
SetProperty(ref _IntervalTime, value); SetProperty(ref _IntervalTime, value);
} }
@ -263,14 +264,24 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
private void Loaded() private void Loaded()
{ {
//N08,N25,N26 //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"; string station = "N05,N10";
var stations = station.Split(','); var stations = GlobalData.StationNames;// station.Split(',');
smList = _wavesModel.ReadWavesFromJson(stations); smList = _wavesModel.ReadWavesFromJson(stations);
} }
private void UnLoaded() 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) private void AxesYVisible(object isCheck)
@ -495,16 +506,16 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
_lChartAll.BeginUpdate(); _lChartAll.BeginUpdate();
if (isStartRealData) if (isStartRealData)
{ {
_data = CreateInputData(_channelCount, _samplingFrequency); _data = new double[smList.Count * 3][];
StartChart(); StartChart();
//Set real-time monitoring automatic old data destruction //Set real-time monitoring automatic old data destruction
LChartALL.ViewXY.DropOldSeriesData = true; LChartALL.ViewXY.DropOldSeriesData = true;
_pointsAppended = LChartALL.ViewXY.XAxes[0].Minimum; _pointsAppended = LChartALL.ViewXY.XAxes[0].Minimum;
dispatcherTimer.Tick -= CompositionTarget_Rendering;
dispatcherTimer.Tick += CompositionTarget_Rendering;
LChartALL.ViewXY.XAxes[0].ScrollMode = XAxisScrollMode.Scrolling;
dispatcherTimer.Start();
time.Elapsed -= CompositionTarget_Rendering;
time.Elapsed += CompositionTarget_Rendering;
LChartALL.ViewXY.XAxes[0].ScrollMode = XAxisScrollMode.Scrolling;
time.Start();
using (RedisListService service = new RedisListService()) using (RedisListService service = new RedisListService())
{ {
foreach (var subName in subNameList) foreach (var subName in subNameList)
@ -521,7 +532,6 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
{ {
service.Subscribe(subName.Key, (c, message, iRedisSubscription) => service.Subscribe(subName.Key, (c, message, iRedisSubscription) =>
{ {
Debug.WriteLine($"注册{1}{c}");
Mseed2asciiApi.bufferMseedData(message.Length, message); Mseed2asciiApi.bufferMseedData(message.Length, message);
}); });
} }
@ -530,9 +540,9 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
} }
else else
{ {
dispatcherTimer.Stop(); time.Stop();
time.Elapsed -= CompositionTarget_Rendering;
LChartALL.ViewXY.XAxes[0].ScrollMode = XAxisScrollMode.None; LChartALL.ViewXY.XAxes[0].ScrollMode = XAxisScrollMode.None;
dispatcherTimer.Tick -= CompositionTarget_Rendering;
using (RedisListService service = new RedisListService()) using (RedisListService service = new RedisListService())
{ {
foreach (var subName in subNameList) foreach (var subName in subNameList)
@ -548,16 +558,19 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
private void Mseed2AsciiEvent(AsciiDataStruct asciiData) 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]; byte[] bytes = new byte[asciiData.numsamples * asciiData.samplesize];
// IntPtr bufferHandler = Marshal.AllocHGlobal((int)asciiData.datasize); // IntPtr bufferHandler = Marshal.AllocHGlobal((int)asciiData.datasize);
Marshal.Copy(asciiData.datasamples, bytes, 0, bytes.Length); Marshal.Copy(asciiData.datasamples, bytes, 0, bytes.Length);
List<double> lines = new List<double>(); List<double> lines = new List<double>();
//时间添加到开始
lines.Add(startTime.ToOADate());
string[] sid = asciiData.sid.Split('_'); string[] sid = asciiData.sid.Split('_');
string name = $"HA.{sid[1]}.{sid[2]}.{sid[3]}{sid[4]}{sid[5]}"; string name = $"HA.{sid[1]}.{sid[2]}.{sid[3]}{sid[4]}{sid[5]}";
if (asciiData.sampletype == 'i') if (asciiData.sampletype == 'i')
{ {
for (int index = 0; index < bytes.Length; index += 4) for (int index = 0; index < bytes.Length; index += 4)
@ -566,29 +579,27 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
lines.Add(a); lines.Add(a);
} }
} }
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); 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);
// }
//}
using (RedisListService service = new RedisListService()) using (RedisListService service = new RedisListService())
{ {
// string data = System.Text.Encoding.ASCII.GetString(bytes); service.LPush(name, lineStr);
service.RPush(name, lineStr);
} }
} }
@ -852,66 +863,61 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
} }
#region 实时数据 #region 实时数据
private void CompositionTarget_Rendering(object sender, EventArgs e) private void CompositionTarget_Rendering(object sender, System.Timers.ElapsedEventArgs e)
{ {
RenderNextFrame(); RenderNextFrame();
} }
private void RenderNextFrame() private void RenderNextFrame()
{ {
Debug.WriteLine("timeFrame:{0}", DateTime.Now);
if (_lChartAll == null) if (_lChartAll == null)
{ {
return; return;
} }
using (RedisListService service = new RedisListService())
_dispatcher.Invoke(() =>
{ {
//FeedData(/*chartTitleText*/); foreach (var item in subNameList)
});
}
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. List<double> dataDouList = new List<double>();
double[][] data = new double[seriesCount][]; var data = service.Get(item.Key, 0, 0).FirstOrDefault();
// System.Threading.Tasks.Parallel.For(0, seriesCount, (seriesIndex) => if( data != null)
for (int seriesIndex = 0; seriesIndex < seriesCount; seriesIndex++)
{ {
IEnumerable<double> datasStr = data.Split(',').Select(a => Convert.ToDouble(a));
int dataPointCount = PreGenerateDataForRoundCount * appendCountPerRound; double oaTime = datasStr.First();
double[] seriesData = new double[dataPointCount]; if (oaTime < DateTime.Now.AddSeconds(-3).ToOADate())
double seriesIndexPlus1 = seriesIndex + 1;
Random rand = new Random((int)DateTime.Now.Ticks / (seriesIndex + 1));
double y = 50;
for (int i = 0; i < dataPointCount; i++)
{ {
y = y - 0.05 + rand.NextDouble() / 10.0; //取出队列数据
if (y > YMax) service.RemoveStartFromList(item.Key);
var DouData = data.Split(',').Select(a => Convert.ToDouble(a)).ToList();
DouData.RemoveAt(0);
dataDouList.AddRange(DouData);
}
else
{ {
y = YMax; break;
} }
//继续查看数据
if (y < YMin) // 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() private void FeedData()
{ {
@ -920,40 +926,21 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
_lChartAll.BeginUpdate(); _lChartAll.BeginUpdate();
//Append data to series //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)); double[] thisSeriesData = _data[seriesIndex];
if(data == null) if (thisSeriesData == null) continue;
{ _lChartAll.ViewXY.SampleDataSeries[seriesIndex].AddSamples(thisSeriesData, false);
System.Diagnostics.Debug.WriteLine("***********注册:{0},没有收到数据,time:{1}", item.Key, DateTime.Now); _data[seriesIndex] = null;
continue; System.Diagnostics.Debug.WriteLine("***********index:{0}, pointCount:{1},time:{2}", seriesIndex,
_lChartAll.ViewXY.SampleDataSeries[seriesIndex].PointCount, DateTime.Now);
} }
// 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);
}
}
//System.Threading.Tasks.Parallel.For(0, _channelCount, (seriesIndex) => //System.Threading.Tasks.Parallel.For(0, _channelCount, (seriesIndex) =>
//{ //{
// double[] thisSeriesData = _data[seriesIndex]; // double[] thisSeriesData = _data[seriesIndex];
// double[] dataToAppendNow = new double[_samplingFrequency]; // double[] dataToAppendNow = new double[_samplingFrequency];
// Array.Copy(thisSeriesData, 0, dataToAppendNow, 0, _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, // System.Diagnostics.Debug.WriteLine("***********index:{0}, pointCount:{1},time:{2}", seriesIndex,
// _lChartAll.ViewXY.SampleDataSeries[seriesIndex].PointCount, DateTime.Now); // _lChartAll.ViewXY.SampleDataSeries[seriesIndex].PointCount, DateTime.Now);
//}); //});

@ -1,8 +1,8 @@
<Window x:Class="StartServerWPF.Views.MainWindow" <Window x:Class="StartServerWPF.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/" xmlns:prism="http://prismlibrary.com/" WindowState="Maximized"
WindowStyle="None" WindowStartupLocation="CenterScreen" WindowStyle="None" WindowStartupLocation="CenterScreen" MouseDown="Window_MouseDown"
prism:ViewModelLocator.AutoWireViewModel="True" Closing="Window_Closing" prism:ViewModelLocator.AutoWireViewModel="True" Closing="Window_Closing"
Title="{Binding Title}" Height="900" Width="1700" > Title="{Binding Title}" Height="900" Width="1700" >
<Window.Resources> <Window.Resources>

@ -14,6 +14,7 @@ namespace StartServerWPF.Views
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
} }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) 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();
}
} }
} }

Loading…
Cancel
Save