diff --git a/JiangsuEarthquake/.vs/JiangsuEarthquake/DesignTimeBuild/.dtbcache.v2 b/JiangsuEarthquake/.vs/JiangsuEarthquake/DesignTimeBuild/.dtbcache.v2 index 5cf8cb3..d5ec4b6 100644 Binary files a/JiangsuEarthquake/.vs/JiangsuEarthquake/DesignTimeBuild/.dtbcache.v2 and b/JiangsuEarthquake/.vs/JiangsuEarthquake/DesignTimeBuild/.dtbcache.v2 differ diff --git a/JiangsuEarthquake/.vs/JiangsuEarthquake/v17/.futdcache.v2 b/JiangsuEarthquake/.vs/JiangsuEarthquake/v17/.futdcache.v2 index 73f963a..a8b00e4 100644 Binary files a/JiangsuEarthquake/.vs/JiangsuEarthquake/v17/.futdcache.v2 and b/JiangsuEarthquake/.vs/JiangsuEarthquake/v17/.futdcache.v2 differ diff --git a/JiangsuEarthquake/.vs/JiangsuEarthquake/v17/.suo b/JiangsuEarthquake/.vs/JiangsuEarthquake/v17/.suo index d2994e9..f1b5904 100644 Binary files a/JiangsuEarthquake/.vs/JiangsuEarthquake/v17/.suo and b/JiangsuEarthquake/.vs/JiangsuEarthquake/v17/.suo differ diff --git a/JiangsuEarthquake/.vs/JiangsuEarthquake/v17/DocumentLayout.json b/JiangsuEarthquake/.vs/JiangsuEarthquake/v17/DocumentLayout.json index b7f0d7d..dc74826 100644 --- a/JiangsuEarthquake/.vs/JiangsuEarthquake/v17/DocumentLayout.json +++ b/JiangsuEarthquake/.vs/JiangsuEarthquake/v17/DocumentLayout.json @@ -7,7 +7,7 @@ "RelativeMoniker": "D:0:0:{51CD2C1B-B7CD-4AC0-8087-846E14D316AD}|JiangsuEarthquake\\JiangsuEarthquake.csproj|solutionrelative:jiangsuearthquake\\models\\seismographmodel.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" }, { - "AbsoluteMoniker": "D:0:0:{51CD2C1B-B7CD-4AC0-8087-846E14D316AD}|JiangsuEarthquake\\JiangsuEarthquake.csproj|f:\\code\\jseq\\20240301_jseq_upperpc\\jiangsuearthquake\\jiangsuearthquake\\models\\volcurcollectormodel.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", + "AbsoluteMoniker": "D:0:0:{51CD2C1B-B7CD-4AC0-8087-846E14D316AD}|JiangsuEarthquake\\JiangsuEarthquake.csproj|F:\\Code\\JSEQ\\20240301_JSEQ_upperpc\\JiangsuEarthquake\\jiangsuearthquake\\models\\volcurcollectormodel.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", "RelativeMoniker": "D:0:0:{51CD2C1B-B7CD-4AC0-8087-846E14D316AD}|JiangsuEarthquake\\JiangsuEarthquake.csproj|solutionrelative:jiangsuearthquake\\models\\volcurcollectormodel.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" }, { @@ -59,8 +59,7 @@ "ViewState": "AQIAAA8AAAAAAAAAAAAAACgAAAAaAAAA", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000601|", "WhenOpened": "2024-04-24T08:54:53.626Z", - "IsPinned": true, - "EditorCaption": "" + "IsPinned": true }, { "$type": "Document", @@ -70,7 +69,7 @@ "RelativeDocumentMoniker": "JiangsuEarthquake\\Models\\VolCurCollectorModel.cs", "ToolTip": "F:\\Code\\JSEQ\\20240301_JSEQ_upperpc\\JiangsuEarthquake\\JiangsuEarthquake\\Models\\VolCurCollectorModel.cs", "RelativeToolTip": "JiangsuEarthquake\\Models\\VolCurCollectorModel.cs", - "ViewState": "AQIAAAoAAAAAAAAAAAAkwBkAAABAAAAA", + "ViewState": "AQIAAC4AAAAAAAAAAAAkwEAAAAAtAAAA", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", "WhenOpened": "2024-04-25T08:11:58.297Z", "EditorCaption": "" @@ -83,7 +82,7 @@ "RelativeDocumentMoniker": "JiangsuEarthquake\\Models\\SeismographModel.cs", "ToolTip": "F:\\Code\\JSEQ\\20240301_JSEQ_upperpc\\JiangsuEarthquake\\JiangsuEarthquake\\Models\\SeismographModel.cs", "RelativeToolTip": "JiangsuEarthquake\\Models\\SeismographModel.cs", - "ViewState": "AQIAAAAAAAAAAAAAAAAAAAQAAAAdAAAA", + "ViewState": "AQIAAGsAAAAAAAAAAAAuwIQAAAAcAAAA", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", "WhenOpened": "2024-04-25T08:11:19.51Z", "EditorCaption": "" @@ -96,7 +95,7 @@ "RelativeDocumentMoniker": "JiangsuEarthquake\\Common\\Tools.cs", "ToolTip": "F:\\Code\\JSEQ\\20240301_JSEQ_upperpc\\JiangsuEarthquake\\JiangsuEarthquake\\Common\\Tools.cs", "RelativeToolTip": "JiangsuEarthquake\\Common\\Tools.cs", - "ViewState": "AQIAAOUAAAAAAAAAAAAywBIBAAAxAAAA", + "ViewState": "AQIAAOQAAAAAAAAAAAAuwBIBAAAxAAAA", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", "WhenOpened": "2024-04-24T07:18:22.772Z", "EditorCaption": "" @@ -111,8 +110,7 @@ "RelativeToolTip": "JiangsuEarthquake\\Models\\ClientModel.cs", "ViewState": "AQIAAFcAAAAAAAAAAAAAAGYAAACDAAAA", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", - "WhenOpened": "2024-04-22T06:58:22.442Z", - "EditorCaption": "" + "WhenOpened": "2024-04-22T06:58:22.442Z" }, { "$type": "Document", @@ -135,8 +133,7 @@ "ToolTip": "F:\\Code\\JSEQ\\20240301_JSEQ_upperpc\\JiangsuEarthquake\\JiangsuEarthquake\\Views\\SystemControlView.xaml", "RelativeToolTip": "JiangsuEarthquake\\Views\\SystemControlView.xaml", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.003549|", - "WhenOpened": "2024-04-15T03:01:04.303Z", - "EditorCaption": "" + "WhenOpened": "2024-04-15T03:01:04.303Z" }, { "$type": "Document", @@ -148,8 +145,7 @@ "RelativeToolTip": "JiangsuEarthquake\\ViewModels\\MainViewModel.cs", "ViewState": "AQIAAB4FAAAAAAAAAAAkwCcBAAAAAAAA", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", - "WhenOpened": "2024-03-12T06:03:03.53Z", - "EditorCaption": "" + "WhenOpened": "2024-03-12T06:03:03.53Z" }, { "$type": "Document", @@ -160,8 +156,7 @@ "ToolTip": "F:\\Code\\JSEQ\\20240301_JSEQ_upperpc\\JiangsuEarthquake\\JiangsuEarthquake\\MainWindow.xaml", "RelativeToolTip": "JiangsuEarthquake\\MainWindow.xaml", "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.003549|", - "WhenOpened": "2024-03-11T05:49:43.074Z", - "EditorCaption": "" + "WhenOpened": "2024-03-11T05:49:43.074Z" } ] } diff --git a/JiangsuEarthquake/.vs/ProjectEvaluation/jiangsuearthquake.metadata.v7.bin b/JiangsuEarthquake/.vs/ProjectEvaluation/jiangsuearthquake.metadata.v7.bin index 4e354ed..d0048b0 100644 Binary files a/JiangsuEarthquake/.vs/ProjectEvaluation/jiangsuearthquake.metadata.v7.bin and b/JiangsuEarthquake/.vs/ProjectEvaluation/jiangsuearthquake.metadata.v7.bin differ diff --git a/JiangsuEarthquake/.vs/ProjectEvaluation/jiangsuearthquake.projects.v7.bin b/JiangsuEarthquake/.vs/ProjectEvaluation/jiangsuearthquake.projects.v7.bin index 84aef93..3519b0b 100644 Binary files a/JiangsuEarthquake/.vs/ProjectEvaluation/jiangsuearthquake.projects.v7.bin and b/JiangsuEarthquake/.vs/ProjectEvaluation/jiangsuearthquake.projects.v7.bin differ diff --git a/JiangsuEarthquake/JiangsuEarthquake/Models/SeismographModel.cs b/JiangsuEarthquake/JiangsuEarthquake/Models/SeismographModel.cs index c5fd7a5..3453b62 100644 --- a/JiangsuEarthquake/JiangsuEarthquake/Models/SeismographModel.cs +++ b/JiangsuEarthquake/JiangsuEarthquake/Models/SeismographModel.cs @@ -1,4 +1,6 @@ -using System; +using JiangsuEarthquake.Common; +using JiangsuEarthquake.DataAccess; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,11 +10,142 @@ namespace JiangsuEarthquake.Models { public class SeismographModel { - private byte[] sync { get; set; } = new byte[4]; + private byte[] syncSend { get; set; } = new byte[4] { 0xBF, 0x13, 0x97, 0x74 }; //同步字,为0xbf139774 + + private byte[] cmdSend { get; set; } = new byte[2]; //帧标志 + + private byte[] cmdRecv { get; set; } = new byte[2]; //帧标志 + + private byte[] lengthSend { get; set; } = new byte[2]; //从DATA开始的帧长度,单位:字节 + + private byte[] lengthRecv { get; set; } = new byte[2]; //从DATA开始的帧长度,单位:字节 + + private List dataSend { get; set; } = new List(); //数据部分 + + private List dataRecv { get; set; } = new List(); //数据部分 + + private byte[] checkCode { get; set; } = new byte[2]; //从CMD到DATA结束的CRC16校验和 + + private List checkByte { get; set; } = new List(); //校验码Byte public void ParsingData(List byteList, int id) { + if (byteList.Count == 0) + return; + //原始数据存储 + string sql = $"insert into earthquakeoriginaldata(StationID,RecordTime,OriginalData) values('{id}','{DateTime.Now}','{BitConverter.ToString(byteList.ToArray())}');"; + DBHelper.ExecuteNonQuery(sql, 1); + + //同步字校验 + if (byteList[0] != 0xBF || byteList[1] != 0x13 || byteList[2] != 0x97 || byteList[3] != 0x74) + return; + + checkByte.Clear(); + //CRC16校验和校验 + for (int i = 4; i < byteList.Count - 2; i++) + checkByte.Add(byteList[i]); + if (!Tools.CompareByte(new byte[] { byteList[^2], byteList[^1] }, Tools.CRCCalc(checkCode.ToArray()))) + return; + + //长度校验 + int length = BitConverter.ToInt16(new byte[] { byteList[7], byteList[6] }, 0); + if (length != byteList.Count - 8) + return; + + cmdRecv = new byte[] { byteList[4], byteList[5] }; + + dataRecv.Clear(); + for (int i = 8; i < byteList.Count - 2; i++) + dataRecv.Add(byteList[i]); + + if (Tools.CompareByte(cmdRecv, new byte[] { 0x77, 0x00 })) //用于客户端与状态流服务器建立链接过程中消息交换 + { + if (dataRecv.Count != 2) + return; + + int response = BitConverter.ToInt16(new byte[2] { dataRecv[1], dataRecv[0] }, 0); + + if (response == 100) + { + //有空闲连接时应答 + //发送用户认证帧 + cmdSend = new byte[] { 0x77, 0x00 }; + lengthSend = new byte[] { 0x00, 0x04 }; + + string User = "Admin"; + byte[] userByte = System.Text.Encoding.ASCII.GetBytes(User); + byte[] userByteArray = new byte[16]; + if(userByte.Length != 16) + { + for (int i = 0; i < 16; i++) + { + userByteArray[i] = 0; + } + + Array.Copy(userByte, 0, userByteArray, 16, userByte.Length); + } + else + { + userByteArray = userByte; + } + + string Password = "Admin"; + byte[] passwordByte = System.Text.Encoding.ASCII.GetBytes(Password); + byte[] passwordByteArray = new byte[40]; + if (passwordByte.Length != 40) + { + for (int i = 0; i < 40; i++) + { + passwordByteArray[i] = 0; + } + + Array.Copy(passwordByte, 0, passwordByteArray, 40, passwordByte.Length); + } + else + { + passwordByteArray = passwordByte; + } + + dataSend.Clear(); + dataSend.AddRange(userByteArray); + dataSend.AddRange(passwordByteArray); + + checkByte.Clear(); + checkByte.AddRange(cmdSend); + checkByte.AddRange(lengthSend); + checkByte.AddRange(userByteArray); + checkByte.AddRange(passwordByteArray); + checkCode = Tools.CRCCalc(checkByte.ToArray()); + + dataSend.AddRange(checkCode); + if(id == 1) + { + MainWindow.mainViewModel.clientModelDZY1.SendMessage(dataSend.ToArray()); + } + else + { + MainWindow.mainViewModel.clientModelDZY2.SendMessage(dataSend.ToArray()); + } + } + else if (response == 405) + { + //没有空闲连接 + //继续尝试连接 + + } + else if (response == 200) + { + //认证成功 + //连接成功 + + } + else if (response == 400) + { + //认证失败 + //重新尝试连接 + } + } } } } diff --git a/JiangsuEarthquake/JiangsuEarthquake/obj/Debug/net6.0-windows/JiangsuEarthquake.AssemblyInfo.cs b/JiangsuEarthquake/JiangsuEarthquake/obj/Debug/net6.0-windows/JiangsuEarthquake.AssemblyInfo.cs index 758fc4c..ec7c2a1 100644 --- a/JiangsuEarthquake/JiangsuEarthquake/obj/Debug/net6.0-windows/JiangsuEarthquake.AssemblyInfo.cs +++ b/JiangsuEarthquake/JiangsuEarthquake/obj/Debug/net6.0-windows/JiangsuEarthquake.AssemblyInfo.cs @@ -14,7 +14,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("JiangsuEarthquake")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+926529723ad8107d15696f2632640ee9669778e9")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+14e7fe49e9e6d49082ec0ec1a0839f6ce7695faa")] [assembly: System.Reflection.AssemblyProductAttribute("JiangsuEarthquake")] [assembly: System.Reflection.AssemblyTitleAttribute("JiangsuEarthquake")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/JiangsuEarthquake/JiangsuEarthquake/obj/Debug/net6.0-windows/JiangsuEarthquake.AssemblyInfoInputs.cache b/JiangsuEarthquake/JiangsuEarthquake/obj/Debug/net6.0-windows/JiangsuEarthquake.AssemblyInfoInputs.cache index 5904e40..ad1dabd 100644 --- a/JiangsuEarthquake/JiangsuEarthquake/obj/Debug/net6.0-windows/JiangsuEarthquake.AssemblyInfoInputs.cache +++ b/JiangsuEarthquake/JiangsuEarthquake/obj/Debug/net6.0-windows/JiangsuEarthquake.AssemblyInfoInputs.cache @@ -1 +1 @@ -1100140aceac37e666b2696684d73d82f9991b6ee5e8275f46763dbd563b3877 +d85f7398275725d03be5e8ee96488b3727df451ccd9d9c93184d66ccb7d2bf32