From 92776e6a97bba2d95b1d8d733677ff82d6da27b8 Mon Sep 17 00:00:00 2001 From: mzhifa Date: Wed, 6 Mar 2024 21:19:37 +0800 Subject: [PATCH] =?UTF-8?q?1=E4=BF=AE=E6=94=B9=E9=92=89=E9=92=89=E5=8F=91?= =?UTF-8?q?=E9=80=81=E9=97=AE=E9=A2=98=EF=BC=88client=E9=87=8D=E8=BF=9E?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E7=99=BB=E5=BD=95=EF=BC=89=EF=BC=8C=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E9=9C=87=E7=BA=A7=E9=98=88=E5=80=BC=202=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0mseedC.dll=E5=90=8C=E6=97=B6=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=9B=203=E4=BF=AE=E6=94=B9=E6=B3=A2?= =?UTF-8?q?=E5=BD=A2=E6=97=B6=E9=97=B4=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- StartServerWPF.Models/WorkareaModel.cs | 5 +++ .../ViewModels/MainViewModel.cs | 8 ++-- .../Views/SetParamView.xaml | 4 +- .../WebsocketClient.cs | 41 +++++++++++-------- .../Models/WavesModel.cs | 18 ++++---- .../Mseed2asciiApi.cs | 15 ++++++- .../ViewModels/ChartPlotRealDataViewModel.cs | 20 ++++----- .../ViewModels/ChartPlotViewModel.cs | 17 ++++---- StartServerWPF/App.xaml.cs | 6 ++- .../serverprogram/workarea/Workarea.json | 1 + 10 files changed, 86 insertions(+), 49 deletions(-) diff --git a/StartServerWPF.Models/WorkareaModel.cs b/StartServerWPF.Models/WorkareaModel.cs index 2a2a046..d96690f 100644 --- a/StartServerWPF.Models/WorkareaModel.cs +++ b/StartServerWPF.Models/WorkareaModel.cs @@ -31,6 +31,7 @@ namespace StartServerWPF.Models private string chartsavepath1; private string apmsavepath1; private string toolsavepath1; + private double apmpush2ddmag1; private int delayTime1; private ApmsModel apmModel1; @@ -54,6 +55,10 @@ namespace StartServerWPF.Models [JsonProperty("toolpush2wx")] public bool toolpush2wx { get => toolpush2wx1; set => SetProperty(ref toolpush2wx1, value); } + + [JsonProperty("apmpush2ddmag")] + public double apmpush2ddmag { get => apmpush2ddmag1; set => SetProperty(ref apmpush2ddmag1, value); } + [JsonProperty("delayTime")] public int delayTime { get => delayTime1; set => SetProperty(ref delayTime1, value); } diff --git a/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs index aa5df88..9854bff 100644 --- a/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs +++ b/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs @@ -29,11 +29,12 @@ namespace StartServerWPF.Modules.Main.ViewModels { public class MainViewModel : BindableBase { - public MainViewModel(SystemConfigModel systemConfig, IDialogService dialogService, WebsocketClient websocket, LoginViewDialogViewModel loginViewDialogViewModel) + public MainViewModel(SystemConfigModel systemConfig, WorkareaModel workareaModel, IDialogService dialogService, WebsocketClient websocket, LoginViewDialogViewModel loginViewDialogViewModel) { Message = "View A" ; Console.WriteLine(System.Environment.CurrentDirectory + "\\" + JsonParser.systemConfigPath); _systemConfig = systemConfig; + this._workareaModel = workareaModel; ApmsIsEnable = _systemConfig.proApms.IsEnable; ToolsIsEnable= _systemConfig.proTools.IsEnable; DingdingIsEnable = _systemConfig.remoteDb.DingdingIsEnable; @@ -523,7 +524,7 @@ namespace StartServerWPF.Modules.Main.ViewModels public bool vpnStatus = false; private SystemConfigModel _systemConfig; - + private readonly WorkareaModel _workareaModel; private DispatcherTimer timer1= new DispatcherTimer(); private readonly IDialogService _dialogService; private readonly WebsocketClient _websocket; @@ -627,7 +628,8 @@ namespace StartServerWPF.Modules.Main.ViewModels message = outLine.Data, }; string jsonStr = JsonSerializer.Serialize(cSDevicePublish); - if (_systemConfig.remoteDb.DingdingIsEnable) + //判断震级大小设置值 + if (_systemConfig.remoteDb.DingdingIsEnable && (ms.ML >= _workareaModel.apmpush2ddmag)) { _websocket.SendMes(jsonStr); } diff --git a/StartServerWPF.Modules.Main/Views/SetParamView.xaml b/StartServerWPF.Modules.Main/Views/SetParamView.xaml index a139be8..18dd4cc 100644 --- a/StartServerWPF.Modules.Main/Views/SetParamView.xaml +++ b/StartServerWPF.Modules.Main/Views/SetParamView.xaml @@ -82,13 +82,15 @@ - + + + diff --git a/StartServerWPF.Modules.Main/WebsocketClient.cs b/StartServerWPF.Modules.Main/WebsocketClient.cs index 526cf07..693be87 100644 --- a/StartServerWPF.Modules.Main/WebsocketClient.cs +++ b/StartServerWPF.Modules.Main/WebsocketClient.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Security.Principal; using System.Text; using System.Text.Json; using System.Threading; @@ -25,20 +26,25 @@ namespace StartServerWPF.Modules.Main webSocket4Net.Opened += WebSocket4Net_Opened; webSocket4Net.Error += new EventHandler(WebSocket_Error); webSocket4Net.MessageReceived += WebSocket4Net_MessageReceived; - webSocket4Net.Open(); + Debug.WriteLine("客户端连接成功!"); // thread.Start(); } + private string name = string.Empty; + private string pwd = string.Empty; public void SiginServer(string account,string password) { - isHeartbeat = false; - string jsonstr= JsonSerializer.Serialize(new CSUserSigin { type = CSMessage.sigin, utype = "device", account=account,password=password}); - SendMes(jsonstr); + isHeartbeat = false; + name = account; + pwd = password; + webSocket4Net.Open(); + // string jsonstr= JsonSerializer.Serialize(new CSUserSigin { type = CSMessage.sigin, utype = "device", account=account,password=password}); + // SendMes(jsonstr); Task.Run(async () =>{ await Task.Delay(2000); - isHeartbeat = true; + isHeartbeat = true; SendHeartbeat(); }); } @@ -58,22 +64,21 @@ namespace StartServerWPF.Modules.Main { while (isHeartbeat) { - //Console.WriteLine($"客户端发送数据{i++}"); - if (webSocket4Net.State == WebSocketState.Open) + try { - webSocket4Net.Send("{\"type\":\"heartbeat\",\"utype\":\"device\"}"); - } - else if (webSocket4Net.State == WebSocketState.Closed) - { - try + if (webSocket4Net.State == WebSocketState.Open) { - webSocket4Net.Open(); + webSocket4Net.Send("{\"type\":\"heartbeat\",\"utype\":\"device\"}"); } - catch (Exception ex) + else if (webSocket4Net.State == WebSocketState.Closed) { - Debug.WriteLine(ex.ToString()); + webSocket4Net.Open(); } - Thread.Sleep(TimeSpan.FromSeconds(20)); + } + catch (Exception ex) + { + Debug.WriteLine("连接报错:"+ ex.ToString()); + Thread.Sleep(TimeSpan.FromSeconds(10)); } Thread.Sleep(TimeSpan.FromSeconds(5)); } @@ -86,7 +91,9 @@ namespace StartServerWPF.Modules.Main private void WebSocket4Net_Opened(object sender, EventArgs e) { - + Debug.WriteLine("连接websocket成功****************"); + string jsonstr = JsonSerializer.Serialize(new CSUserSigin { type = CSMessage.sigin, utype = "device", account = name, password = pwd }); + SendMes(jsonstr); } void WebSocket_Error(object sender, ErrorEventArgs e) { diff --git a/StartServerWPF.Modules.MseedChart/Models/WavesModel.cs b/StartServerWPF.Modules.MseedChart/Models/WavesModel.cs index 22b9c31..f3eacb5 100644 --- a/StartServerWPF.Modules.MseedChart/Models/WavesModel.cs +++ b/StartServerWPF.Modules.MseedChart/Models/WavesModel.cs @@ -15,6 +15,8 @@ namespace StartServerWPF.Modules.MseedChart.Models { public class WavesModel { + public const int lineTextX = 60; + public const int lineTextY = -5; public List CreateYAxisChart(List stationModels, LightningChart curChart) { List axisYList = new List(); @@ -90,14 +92,14 @@ namespace StartServerWPF.Modules.MseedChart.Models lineCollection.LineStyle.Color = System.Windows.Media.Colors.Red; lineCollection.Title.Text = chartV.YAxes[assignYAxisIndex].Title.Text + ph.atime.ToString(); lineCollection.Title.Visible = true; - lineCollection.Title.Font.Size = 10; + lineCollection.Title.Font.Size = 12; lineCollection.Title.Shadow.DropColor = System.Windows.Media.Colors.Transparent; //lineCollection.Title.Shadow.ContrastColor = System.Windows.Media.Colors.Transparent; lineCollection.Title.AutoPlacement = false; lineCollection.Title.HorizontalAlign = AlignmentHorizontal.Left; - var b = chartV.XAxes[0].ValueToCoordD(chartV.XAxes[0].DateTimeToAxisValue(ph.atime))-80; - lineCollection.Title.Offset.SetValues((int)b, 3); - lineCollection.Title.Color = System.Windows.Media.Colors.Red; + var b = chartV.XAxes[0].ValueToCoordD(chartV.XAxes[0].DateTimeToAxisValue(ph.atime))- WavesModel.lineTextX; + lineCollection.Title.Offset.SetValues((int)b, WavesModel.lineTextY); + lineCollection.Title.Color = System.Windows.Media.Colors.Blue; chartV.LineCollections.Add(lineCollection); } @@ -121,14 +123,14 @@ namespace StartServerWPF.Modules.MseedChart.Models lineCollection.LineStyle.Color = System.Windows.Media.Colors.Red; lineCollection.Title.Text = chartV.YAxes[assignYAxisIndex].Title.Text+ " "+ am.atime.ToString("HH:mm:ss.fff"); lineCollection.Title.Visible = true; - lineCollection.Title.Font.Size = 10; + lineCollection.Title.Font.Size = 12; lineCollection.Title.Shadow.DropColor = System.Windows.Media.Colors.Transparent; // lineCollection.Title.Shadow.ContrastColor = System.Windows.Media.Colors.Transparent; lineCollection.Title.AutoPlacement = false; lineCollection.Title.HorizontalAlign = AlignmentHorizontal.Left; - var b= chartV.XAxes[0].ValueToCoordD(chartV.XAxes[0].DateTimeToAxisValue(am.atime))-80; - lineCollection.Title.Offset.SetValues((int)b,3); - lineCollection.Title.Color = System.Windows.Media.Colors.Red; + var b= chartV.XAxes[0].ValueToCoordD(chartV.XAxes[0].DateTimeToAxisValue(am.atime))- WavesModel.lineTextX; + lineCollection.Title.Offset.SetValues((int)b, WavesModel.lineTextY); + lineCollection.Title.Color = System.Windows.Media.Colors.Blue; chartV.LineCollections.Add(lineCollection); } return new List(); diff --git a/StartServerWPF.Modules.MseedChart/Mseed2asciiApi.cs b/StartServerWPF.Modules.MseedChart/Mseed2asciiApi.cs index 67ffd5c..f6704f2 100644 --- a/StartServerWPF.Modules.MseedChart/Mseed2asciiApi.cs +++ b/StartServerWPF.Modules.MseedChart/Mseed2asciiApi.cs @@ -24,7 +24,20 @@ namespace StartServerWPF.Modules.MseedChart [DllImport("mseedC.dll")] public static extern void MseedDatasCallFun(LoopCallbackHandler callback); } - + //实时波形调用,确定切换页面时数据继续接收 + public class MseedReal2asciiApi + { + public delegate void LoopCallbackHandler(AsciiDataStruct asciiData); + [DllImport("mseedCReal.dll", EntryPoint = "MseedDatas")] + public extern static int MseedDatas(int a, string[] name); + //public extern static int MseedDatas(Byte[] bytes, int lenght); + [DllImport("mseedCReal.dll", EntryPoint = "bufferMseedData")] + public extern static int bufferMseedData(int length, Byte[] data); + [DllImport("mseedCReal.dll", EntryPoint = "testc")] + public extern static int testc(int a, int b); + [DllImport("mseedCReal.dll")] + public static extern void MseedDatasCallFun(LoopCallbackHandler callback); + } [StructLayout(LayoutKind.Sequential)] public struct AsciiDataStruct { diff --git a/StartServerWPF.Modules.MseedChart/ViewModels/ChartPlotRealDataViewModel.cs b/StartServerWPF.Modules.MseedChart/ViewModels/ChartPlotRealDataViewModel.cs index 64b3614..5519982 100644 --- a/StartServerWPF.Modules.MseedChart/ViewModels/ChartPlotRealDataViewModel.cs +++ b/StartServerWPF.Modules.MseedChart/ViewModels/ChartPlotRealDataViewModel.cs @@ -33,17 +33,17 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels public class ChartPlotRealDataViewModel : BindableBase, INavigationAware { - Mseed2asciiApi.LoopCallbackHandler loopCallback; + MseedReal2asciiApi.LoopCallbackHandler loopCallback; WorkareaModel workarea; - public ChartPlotRealDataViewModel(SystemConfigModel configModel,WorkareaModel workareaModel, IDialogService dialogService) + public ChartPlotRealDataViewModel(SystemConfigModel configModel, WorkareaModel workareaModel, IDialogService dialogService) { (Application.Current.MainWindow as System.Windows.Window).Closing += ApplicationClosingDispose; _dispatcher = Application.Current.Dispatcher; - IntervalTime =1000; - loopCallback = new Mseed2asciiApi.LoopCallbackHandler(Mseed2AsciiEvent); - - GC.KeepAlive(loopCallback); - workarea= workareaModel; + IntervalTime = 1000; + loopCallback = new MseedReal2asciiApi.LoopCallbackHandler(Mseed2AsciiEvent); + MseedReal2asciiApi.MseedDatasCallFun(loopCallback); + GC.KeepAlive(loopCallback); + workarea = workareaModel; _wavesModel = new WavesModel(); CreateChart(); if (workarea.StationConfig.Stations != null) @@ -281,12 +281,12 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels private void Loaded() { - Mseed2asciiApi.MseedDatasCallFun(loopCallback); + } private void UnLoaded() { - Mseed2asciiApi.MseedDatasCallFun(null); + } private void Sure() @@ -574,7 +574,7 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels { iRedisSubscription.UnSubscribeFromChannels(subNameList.Keys.ToArray()); } - Mseed2asciiApi.bufferMseedData(message.Length, message); + MseedReal2asciiApi.bufferMseedData(message.Length, message); }, subNameList.Keys.ToArray()); } }); diff --git a/StartServerWPF.Modules.MseedChart/ViewModels/ChartPlotViewModel.cs b/StartServerWPF.Modules.MseedChart/ViewModels/ChartPlotViewModel.cs index 6d02d81..3cbf699 100644 --- a/StartServerWPF.Modules.MseedChart/ViewModels/ChartPlotViewModel.cs +++ b/StartServerWPF.Modules.MseedChart/ViewModels/ChartPlotViewModel.cs @@ -50,6 +50,7 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels IntervalTime=100; CreateChart(); loopCallback = new Mseed2asciiApi.LoopCallbackHandler(Mseed2AsciiEvent); + Mseed2asciiApi.MseedDatasCallFun(loopCallback); GC.KeepAlive(loopCallback); } @@ -324,12 +325,12 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels private void Loaded() { - Mseed2asciiApi.MseedDatasCallFun(loopCallback); + } private void UnLoaded() { - Mseed2asciiApi.MseedDatasCallFun(null); + } private void AxesYVisible(object isCheck) { @@ -698,8 +699,8 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels { foreach (var item in LChartALL.ViewXY.LineCollections) { - double b = LChartALL.ViewXY.XAxes[0].ValueToCoordD(item.Lines[0].AX) - 80; - item.Title.Offset.SetValues((int)b, 3); + double b = LChartALL.ViewXY.XAxes[0].ValueToCoordD(item.Lines[0].AX) - WavesModel.lineTextX; + item.Title.Offset.SetValues((int)b, WavesModel.lineTextY); } } @@ -707,8 +708,8 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels { foreach (var item in LChartALL.ViewXY.LineCollections) { - double b = LChartALL.ViewXY.XAxes[0].ValueToCoordD(item.Lines[0].AX) - 80; - item.Title.Offset.SetValues((int)b, 3); + double b = LChartALL.ViewXY.XAxes[0].ValueToCoordD(item.Lines[0].AX) - WavesModel.lineTextX; + item.Title.Offset.SetValues((int)b, WavesModel.lineTextY); } } @@ -721,8 +722,8 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels } foreach (var item in LChartALL.ViewXY.LineCollections) { - double b = LChartALL.ViewXY.XAxes[0].ValueToCoordD(item.Lines[0].AX)-80; - item.Title.Offset.SetValues((int)b, 3); + double b = LChartALL.ViewXY.XAxes[0].ValueToCoordD(item.Lines[0].AX)- WavesModel.lineTextX; + item.Title.Offset.SetValues((int)b, WavesModel.lineTextY); } } diff --git a/StartServerWPF/App.xaml.cs b/StartServerWPF/App.xaml.cs index e80f6e9..0aa4e7f 100644 --- a/StartServerWPF/App.xaml.cs +++ b/StartServerWPF/App.xaml.cs @@ -29,7 +29,11 @@ namespace StartServerWPF { System.AppDomain.CurrentDomain.UnhandledException += new System.UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; - // AddSecurity(@"C:\ProgramData\Microsoft\Network\Connections"); + // AddSecurity(@"C:\ProgramData\Microsoft\Network\Connections"); + if(File.Exists("mseedC.dll")) + { + File.Copy("mseedC.dll", "mseedCReal.dll",true); + } } /// diff --git a/StartServerWPF/serverprogram/workarea/Workarea.json b/StartServerWPF/serverprogram/workarea/Workarea.json index 1fe608a..84b6981 100644 --- a/StartServerWPF/serverprogram/workarea/Workarea.json +++ b/StartServerWPF/serverprogram/workarea/Workarea.json @@ -6,6 +6,7 @@ "toolsavepath": "Post", "apmpush2wx": false, "toolpush2wx": false, + "apmpush2ddmag": -1.2, "delayTime": 10, "apmModel": { "station": "N2107_1116.csv",