diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1400_0x1402Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1400_0x1402Test.cs index 2520607..47f2760 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1400_0x1402Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1400_0x1402Test.cs @@ -7,6 +7,7 @@ using JT809.Protocol.JT809Extensions; using JT809.Protocol.JT809MessageBody; using JT809.Protocol.JT809Exceptions; using JT809.Protocol.JT809SubMessageBody; +using JT809.Protocol.JT809Enums; namespace JT809.Protocol.Test.JT809SubMessageBody { @@ -18,23 +19,23 @@ namespace JT809.Protocol.Test.JT809SubMessageBody JT809_0x1400_0x1402 jT809_0x1400_0x1402 = new JT809_0x1400_0x1402 { WarnSrc= JT809Enums.JT809WarnSrc.车载终端, - WarnType = 18, + WarnType = JT809WarnType.偏离路线报警, WarnTime=DateTime.Parse("2018-09-26"), InfoContent = "gfdf454553", InfoID = 3344, }; var hex = JT809Serializer.Serialize(jT809_0x1400_0x1402).ToHexString(); - // "00 00 12 00 00 00 00 5B AA 5B 80 00 00 0D 10 00 00 00 0A 67 66 64 66 34 35 34 35 35 33" + // "01 00 0B 00 00 00 00 5B AA 5B 80 00 00 0D 10 00 00 00 0A 67 66 64 66 34 35 34 35 35 33" } [Fact] public void Test2() { - var bytes = "00 00 12 00 00 00 00 5B AA 5B 80 00 00 0D 10 00 00 00 0A 67 66 64 66 34 35 34 35 35 33".ToHexBytes(); + var bytes = "01 00 0B 00 00 00 00 5B AA 5B 80 00 00 0D 10 00 00 00 0A 67 66 64 66 34 35 34 35 35 33".ToHexBytes(); JT809_0x1400_0x1402 jT809_0x1400_0x1402 = JT809Serializer.Deserialize(bytes); Assert.Equal(JT809Enums.JT809WarnSrc.车载终端, jT809_0x1400_0x1402.WarnSrc); Assert.Equal("gfdf454553", jT809_0x1400_0x1402.InfoContent); - Assert.Equal((uint)18, jT809_0x1400_0x1402.WarnType); + Assert.Equal(JT809WarnType.偏离路线报警, jT809_0x1400_0x1402.WarnType); Assert.Equal((uint)3344, jT809_0x1400_0x1402.InfoID); Assert.Equal((uint)10, jT809_0x1400_0x1402.InfoLength); Assert.Equal(DateTime.Parse("2018-09-26"), jT809_0x1400_0x1402.WarnTime); diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1400_0x1403Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1400_0x1403Test.cs new file mode 100644 index 0000000..8b17dc9 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1400_0x1403Test.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.JT809Extensions; +using JT809.Protocol.JT809MessageBody; +using JT809.Protocol.JT809Exceptions; +using JT809.Protocol.JT809SubMessageBody; +using JT809.Protocol.JT809Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x1400_0x1403Test + { + [Fact] + public void Test1() + { + JT809_0x1400_0x1403 jT809_0x1400_0x1403 = new JT809_0x1400_0x1403 + { + Result= JT809_0x1403_Result.将来处理, + InfoID = 3344, + }; + var hex = JT809Serializer.Serialize(jT809_0x1400_0x1403).ToHexString(); + // "00 00 0D 10 03" + } + + [Fact] + public void Test2() + { + var bytes = "00 00 0D 10 03".ToHexBytes(); + JT809_0x1400_0x1403 jT809_0x1400_0x1403 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x1403_Result.将来处理, jT809_0x1400_0x1403.Result); + Assert.Equal((uint)3344, jT809_0x1400_0x1403.InfoID); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1502Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1502Test.cs new file mode 100644 index 0000000..504e672 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1502Test.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.JT809Extensions; +using JT809.Protocol.JT809MessageBody; +using JT809.Protocol.JT809Exceptions; +using JT809.Protocol.JT809SubMessageBody; +using JT809.Protocol.JT809Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x1500_0x1502Test + { + [Fact] + public void Test1() + { + JT809_0x1500_0x1502 jT809_0x1500_0x1502 = new JT809_0x1500_0x1502 + { + PhotoRspFlag= JT809_0x1502_PhotoRspFlag.完成拍照, + VehiclePosition=new JT809Properties.JT809VehiclePositionProperties + { + Encrypt= JT809_VehiclePositionEncrypt.未加密, + Day=19, + Month=7, + Year=2012, + Hour=15, + Minute=15, + Second=15, + Lon= 133123456, + Lat= 24123456, + Vec1=53, + Vec2=45, + Vec3=1234, + Direction=45, + Altitude=45, + State=1, + Alarm=1 + }, + LensID=123, + SizeType=1, + Type=1, + }; + var hex = JT809Serializer.Serialize(jT809_0x1500_0x1502).ToHexString(); + //"01 00 13 07 07 DC 0F 0F 0F 07 EF 4D 80 01 70 18 40 00 35 00 2D 00 00 04 D2 00 2D 00 2D 00 00 00 01 00 00 00 01 7B 00 00 00 00 01 01" + } + + [Fact] + public void Test2() + { + var bytes = "01 00 13 07 07 DC 0F 0F 0F 07 EF 4D 80 01 70 18 40 00 35 00 2D 00 00 04 D2 00 2D 00 2D 00 00 00 01 00 00 00 01 7B 00 00 00 00 01 01".ToHexBytes(); + JT809_0x1500_0x1502 jT809_0x1500_0x1502 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x1502_PhotoRspFlag.完成拍照, jT809_0x1500_0x1502.PhotoRspFlag); + Assert.Equal(JT809_VehiclePositionEncrypt.未加密, jT809_0x1500_0x1502.VehiclePosition.Encrypt); + Assert.Equal(19, jT809_0x1500_0x1502.VehiclePosition.Day); + Assert.Equal(7, jT809_0x1500_0x1502.VehiclePosition.Month); + Assert.Equal(2012, jT809_0x1500_0x1502.VehiclePosition.Year); + Assert.Equal(15, jT809_0x1500_0x1502.VehiclePosition.Hour); + Assert.Equal(15, jT809_0x1500_0x1502.VehiclePosition.Minute); + Assert.Equal(15, jT809_0x1500_0x1502.VehiclePosition.Second); + Assert.Equal((uint)133123456, jT809_0x1500_0x1502.VehiclePosition.Lon); + Assert.Equal((uint)24123456, jT809_0x1500_0x1502.VehiclePosition.Lat); + Assert.Equal((ushort)53, jT809_0x1500_0x1502.VehiclePosition.Vec1); + Assert.Equal((ushort)45, jT809_0x1500_0x1502.VehiclePosition.Vec2); + Assert.Equal((uint)1234, jT809_0x1500_0x1502.VehiclePosition.Vec3); + Assert.Equal((ushort)45, jT809_0x1500_0x1502.VehiclePosition.Direction); + Assert.Equal((ushort)45, jT809_0x1500_0x1502.VehiclePosition.Altitude); + Assert.Equal((uint)1, jT809_0x1500_0x1502.VehiclePosition.State); + Assert.Equal((uint)1, jT809_0x1500_0x1502.VehiclePosition.Alarm); + Assert.Equal(123, jT809_0x1500_0x1502.LensID); + Assert.Equal(1, jT809_0x1500_0x1502.SizeType); + Assert.Equal(1, jT809_0x1500_0x1502.Type); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1504Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1504Test.cs new file mode 100644 index 0000000..6e2788e --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1504Test.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.JT809Extensions; +using JT809.Protocol.JT809MessageBody; +using JT809.Protocol.JT809Exceptions; +using JT809.Protocol.JT809SubMessageBody; +using JT809.Protocol.JT809Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x1500_0x1504Test + { + [Fact] + public void Test1() + { + JT809_0x1400_0x1403 jT809_0x1400_0x1403 = new JT809_0x1400_0x1403 + { + Result = JT809_0x1403_Result.将来处理, + InfoID = 3344, + }; + var hex = JT809Serializer.Serialize(jT809_0x1400_0x1403).ToHexString(); + // "00 00 0D 10 03" + } + + [Fact] + public void Test2() + { + var bytes = "00 00 0D 10 03".ToHexBytes(); + JT809_0x1400_0x1403 jT809_0x1400_0x1403 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x1403_Result.将来处理, jT809_0x1400_0x1403.Result); + Assert.Equal((uint)3344, jT809_0x1400_0x1403.InfoID); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9300_0x9301Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9300_0x9301Test.cs new file mode 100644 index 0000000..cf08db4 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9300_0x9301Test.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.JT809Extensions; +using JT809.Protocol.JT809MessageBody; +using JT809.Protocol.JT809Exceptions; +using JT809.Protocol.JT809SubMessageBody; +using JT809.Protocol.JT809Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x9300_0x9301Test + { + [Fact] + public void Test1() + { + JT809_0x9300_0x9301 jT809_0x9300_0x9301 = new JT809_0x9300_0x9301 + { + ObjectID="smallchi", + ObjectType= JT809_0x9301_ObjectType.下级平台所属单一业户, + InfoContent="reply", + InfoID = 3344, + }; + var hex = JT809Serializer.Serialize(jT809_0x9300_0x9301).ToHexString(); + // "02 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 0D 10 00 00 00 05 72 65 70 6C 79" + } + + [Fact] + public void Test2() + { + var bytes = "02 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 0D 10 00 00 00 05 72 65 70 6C 79".ToHexBytes(); + JT809_0x9300_0x9301 jT809_0x9300_0x9301 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x9301_ObjectType.下级平台所属单一业户, jT809_0x9300_0x9301.ObjectType); + Assert.Equal((uint)3344, jT809_0x9300_0x9301.InfoID); + Assert.Equal("reply", jT809_0x9300_0x9301.InfoContent); + Assert.Equal("smallchi", jT809_0x9300_0x9301.ObjectID); + } + + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9400_0x9401Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9400_0x9401Test.cs new file mode 100644 index 0000000..fc5065c --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9400_0x9401Test.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.JT809Extensions; +using JT809.Protocol.JT809MessageBody; +using JT809.Protocol.JT809Exceptions; +using JT809.Protocol.JT809SubMessageBody; +using JT809.Protocol.JT809Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x9400_0x9401Test + { + [Fact] + public void Test1() + { + JT809_0x9400_0x9401 jT809_0x9400_0x9401 = new JT809_0x9400_0x9401 + { + WarnSrc= JT809WarnSrc.车载终端, + WarnType= JT809WarnType.疲劳驾驶报警, + WarnTime=DateTime.Parse("2018-09-27 10:24:00"), + SupervisionID="123FFAA1", + SupervisionEndTime= DateTime.Parse("2018-09-27 11:24:00"), + SupervisionLevel=3, + Supervisor="smallchi", + SupervisorTel= "12345678901", + SupervisorEmail= "123456@qq.com" + }; + var hex = JT809Serializer.Serialize(jT809_0x9400_0x9401).ToHexString(); + //"01 00 02 00 00 00 00 5B AC 3F 40 12 3F FA A1 00 00 00 00 5B AC 4D 50 03 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 31 32 33 34 35 36 37 38 39 30 31 00 00 00 00 00 00 00 00 00 31 32 33 34 35 36 40 71 71 2E 63 6F 6D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" + } + + [Fact] + public void Test2() + { + var bytes = "01 00 02 00 00 00 00 5B AC 3F 40 12 3F FA A1 00 00 00 00 5B AC 4D 50 03 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 31 32 33 34 35 36 37 38 39 30 31 00 00 00 00 00 00 00 00 00 31 32 33 34 35 36 40 71 71 2E 63 6F 6D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00".ToHexBytes(); + JT809_0x9400_0x9401 jT809_0x9400_0x9401 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809WarnSrc.车载终端, jT809_0x9400_0x9401.WarnSrc); + Assert.Equal(JT809WarnType.疲劳驾驶报警, jT809_0x9400_0x9401.WarnType); + Assert.Equal(DateTime.Parse("2018-09-27 10:24:00"), jT809_0x9400_0x9401.WarnTime); + Assert.Equal("123FFAA1", jT809_0x9400_0x9401.SupervisionID); + Assert.Equal(DateTime.Parse("2018-09-27 11:24:00"), jT809_0x9400_0x9401.SupervisionEndTime); + Assert.Equal(3, jT809_0x9400_0x9401.SupervisionLevel); + Assert.Equal("smallchi", jT809_0x9400_0x9401.Supervisor); + Assert.Equal("12345678901", jT809_0x9400_0x9401.SupervisorTel); + Assert.Equal("123456@qq.com", jT809_0x9400_0x9401.SupervisorEmail); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9504Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9504Test.cs new file mode 100644 index 0000000..333cf99 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9504Test.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.JT809Extensions; +using JT809.Protocol.JT809MessageBody; +using JT809.Protocol.JT809Exceptions; +using JT809.Protocol.JT809SubMessageBody; +using JT809.Protocol.JT809Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x9500_0x9504Test + { + [Fact] + public void Test1() + { + JT809_0x9500_0x9504 jT809_0X9500_0X9504 = new JT809_0x9500_0x9504 + { + Command= JT809CommandType.采集记录仪事故疑点记录, + StartTime=DateTime.Parse("2018-09-27 20:00:20"), + EndTime=DateTime.Parse("2018-09-27 23:00:20"), + Max=5556 + }; + var hex = JT809Serializer.Serialize(jT809_0X9500_0X9504).ToHexString(); + //"10 18 09 27 20 00 20 18 09 27 23 00 20 15 B4" + //"10 18 09 27 20 00 20 18 09 27 23 00 20 15 B4" + + //5B 00 00 00 45 00 00 00 85 95 00 01 33 53 D5 01 00 00 00 00 00 27 0F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 95 04 00 00 00 0F 10 18 09 27 20 00 20 18 09 27 23 00 20 15 B4 3C D8 5D + } + + [Fact] + public void Test2() + { + var bytes = "10 18 09 27 20 00 20 18 09 27 23 00 20 15 B4".ToHexBytes(); + JT809_0x9500_0x9504 jT809_0X9500_0X9504 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809CommandType.采集记录仪事故疑点记录, jT809_0X9500_0X9504.Command); + Assert.Equal(DateTime.Parse("2018-09-27 20:00:20"), jT809_0X9500_0X9504.StartTime); + Assert.Equal(DateTime.Parse("2018-09-27 23:00:20"), jT809_0X9500_0X9504.EndTime); + Assert.Equal(5556, jT809_0X9500_0X9504.Max); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9505Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9505Test.cs new file mode 100644 index 0000000..81a9db7 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9505Test.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.JT809Extensions; +using JT809.Protocol.JT809MessageBody; +using JT809.Protocol.JT809Exceptions; +using JT809.Protocol.JT809SubMessageBody; +using JT809.Protocol.JT809Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x9500_0x9505Test + { + [Fact] + public void Test1() + { + JT809_0x9500_0x9505 jT809_0X9500_0X9505 = new JT809_0x9500_0x9505 + { + AuthenticationCode= "808", + AccessPointName= "jt808", + UserName = "adslsmallchi", + Password= "adsl123", + ServerIP= "127.0.0.1", + TcpPort=808, + UdpPort=809, + EndTime=DateTime.Parse("2018-09-27 20:00:00") + }; + var hex = JT809Serializer.Serialize(jT809_0X9500_0X9505).ToHexString(); + //"00 00 00 00 00 00 00 00 08 08 6A 74 38 30 38 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 61 64 73 6C 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 61 64 73 6C 31 32 33 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 31 32 37 2E 30 2E 30 2E 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 28 03 29 00 00 00 00 5B AC C6 40" + //"00 00 00 00 00 00 00 00 08 08 6A 74 38 30 38 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 61 64 73 6C 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 61 64 73 6C 31 32 33 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 31 32 37 2E 30 2E 30 2E 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 28 03 29 00 00 00 00 5A 01 AC C6 40" + } + + [Fact] + public void Test2() + { + var bytes = "00 00 00 00 00 00 00 00 08 08 6A 74 38 30 38 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 61 64 73 6C 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 61 64 73 6C 31 32 33 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 31 32 37 2E 30 2E 30 2E 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 28 03 29 00 00 00 00 5B AC C6 40".ToHexBytes(); + JT809_0x9500_0x9505 jT809_0X9500_0X9505 = JT809Serializer.Deserialize(bytes); + Assert.Equal("00000000000000000808", jT809_0X9500_0X9505.AuthenticationCode); + Assert.Equal("jt808", jT809_0X9500_0X9505.AccessPointName); + Assert.Equal("adslsmallchi", jT809_0X9500_0X9505.UserName); + Assert.Equal("adsl123", jT809_0X9500_0X9505.Password); + Assert.Equal("127.0.0.1", jT809_0X9500_0X9505.ServerIP); + Assert.Equal(808, jT809_0X9500_0X9505.TcpPort); + Assert.Equal(809, jT809_0X9500_0X9505.UdpPort); + Assert.Equal(DateTime.Parse("2018-09-27 20:00:00"), jT809_0X9500_0X9505.EndTime); + } + } +} diff --git a/src/JT809.Protocol/Constants.cs b/src/JT809.Protocol/Constants.cs deleted file mode 100644 index 6711629..0000000 --- a/src/JT809.Protocol/Constants.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace JT809.Protocol -{ - /// - /// 常量 - /// - public static class Constants - { - /// - /// 报警类型 - /// - public readonly static Dictionary AlramType = new Dictionary() - { - {0x0001,"超速报警"}, - {0x0002,"疲劳驾驶报警"}, - {0x0003,"紧急报警"}, - {0x0004,"进入指定区域报警"}, - {0x0005,"离开指定区域报警"}, - {0x0006,"路段赌赛报警"}, - {0x0007,"危险路段报警"}, - {0x0008,"越界报警"}, - {0x0009,"盗警"}, - {0x000A,"劫警"}, - {0x000B,"偏离路线报警"}, - {0x000C,"车辆移动报警"}, - {0x000D,"超时驾驶报警"}, - {0x000E,"其他报警"} - }; - - /// - /// 车牌颜色 - /// - public readonly static Dictionary CarColor = new Dictionary() - { - {1,"蓝色"}, - {2,"黄色"}, - {3,"黄色"}, - {4,"白色"}, - {5,"绿"}, - {6,"黄绿"}, - {8,"农黄"}, - {9,"其他"} - }; - } -} diff --git a/src/JT809.Protocol/JT809.Protocol.csproj b/src/JT809.Protocol/JT809.Protocol.csproj index 0b1a46d..0b29cdc 100644 --- a/src/JT809.Protocol/JT809.Protocol.csproj +++ b/src/JT809.Protocol/JT809.Protocol.csproj @@ -16,6 +16,10 @@ bin\Release\netstandard2.0\JT809.Protocol.xml + + true + + @@ -47,6 +51,7 @@ + diff --git a/src/JT809.Protocol/JT809Enums/JT809WarnSrc.cs b/src/JT809.Protocol/JT809Enums/JT809WarnSrc.cs index 799f6b8..66b8367 100644 --- a/src/JT809.Protocol/JT809Enums/JT809WarnSrc.cs +++ b/src/JT809.Protocol/JT809Enums/JT809WarnSrc.cs @@ -9,9 +9,9 @@ namespace JT809.Protocol.JT809Enums /// public enum JT809WarnSrc : byte { - 车载终端 = 0x00, - 企业监控平台 = 0x01, - 政府监管平台 = 0x02, + 车载终端 = 0x01, + 企业监控平台 = 0x02, + 政府监管平台 = 0x03, 其他 =0x09 } } diff --git a/src/JT809.Protocol/JT809Enums/JT809WarnType.cs b/src/JT809.Protocol/JT809Enums/JT809WarnType.cs new file mode 100644 index 0000000..2da0e1c --- /dev/null +++ b/src/JT809.Protocol/JT809Enums/JT809WarnType.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.JT809Enums +{ + /// + /// 报警类型 + /// + public enum JT809WarnType:ushort + { + 超速报警=0x0001, + 疲劳驾驶报警=0x0002, + 紧急报警= 0x0003, + 进入指定区域报警= 0x0004, + 离开指定区域报警= 0x0005, + 路段赌赛报警= 0x0006, + 危险路段报警= 0x0007, + 越界报警= 0x0008, + 盗警= 0x0009, + 劫警= 0x000A, + 偏离路线报警= 0x000B, + 车辆移动报警= 0x000C, + 超时驾驶报警= 0x000D, + 其他报警= 0x000E + } +} diff --git a/src/JT809.Protocol/JT809Extensions/JT809BCDExtensions.cs b/src/JT809.Protocol/JT809Extensions/JT809BCDExtensions.cs new file mode 100644 index 0000000..b616839 --- /dev/null +++ b/src/JT809.Protocol/JT809Extensions/JT809BCDExtensions.cs @@ -0,0 +1,32 @@ +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Globalization; +using System.Text; + +namespace JT809.Protocol.JT809Extensions +{ + public static partial class JT809BinaryExtensions + { + public static string ReadBCDLittle(ReadOnlySpan buf, ref int offset, int len) + { + StringBuilder bcdSb = new StringBuilder(len*2); + for(int i = 0; i < len; i++) + { + bcdSb.Append(buf[offset + i].ToString("X2")); + } + offset = offset + len; + return bcdSb.ToString(); + } + + public static int WriteBCDLittle(IMemoryOwner memoryOwner, int offset, string data, int digit, int len) + { + ReadOnlySpan bcd = data.PadLeft(len, '0').AsSpan(); + for (int i = 0; i < digit; i++) + { + memoryOwner.Memory.Span[offset + i] = Convert.ToByte(bcd.Slice(i * 2, 2).ToString(), 16); + } + return digit; + } + } +} diff --git a/src/JT809.Protocol/JT809Extensions/JT809BinaryExtensions.cs b/src/JT809.Protocol/JT809Extensions/JT809BinaryExtensions.cs index 0ba8294..f506eeb 100644 --- a/src/JT809.Protocol/JT809Extensions/JT809BinaryExtensions.cs +++ b/src/JT809.Protocol/JT809Extensions/JT809BinaryExtensions.cs @@ -7,64 +7,8 @@ using System.Buffers; namespace JT809.Protocol.JT809Extensions { - public static class JT809BinaryExtensions + public static partial class JT809BinaryExtensions { - /// - /// 日期限制于2000年 - /// - private const int DateLimitYear = 2000; - - private const ushort cnCRC_CCITT = 0x1021; //CRC校验多项式 - - private static ulong[] CRC = new ulong[256]; //建立CRC16表 - - private static readonly DateTime UTCBaseTime = new DateTime(1970, 1, 1); - - static JT809BinaryExtensions() - { - Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); - encoding = Encoding.GetEncoding("GBK"); - ushort i, j; - ushort nData; - ushort nAccum; - for (i = 0; i < 256; i++) - { - nData = (ushort)(i << 8); - nAccum = 0; - for (j = 0; j < 8; j++) - { - if (((nData ^ nAccum) & 0x8000) > 0) - nAccum = (ushort)((nAccum << 1) ^ cnCRC_CCITT); - else - nAccum <<= 1; - nData <<= 1; - } - CRC[i] = (ulong)nAccum; - } - } - - public static Encoding encoding; - - public static int ReadBCD32(this byte data, byte dig) - { - int result = Convert.ToInt32(data.ToString("X")); - return result * (int)Math.Pow(100, dig - 1); - } - - public static int ReadBCD32(ReadOnlySpan read, ref int offset, int len) - { - int result = Convert.ToInt32(read[offset].ToString("X")); - offset += len; - return result * (int)Math.Pow(100, len - 1); - } - - - public static long ReadBCD64(this byte data, byte dig) - { - long result = Convert.ToInt64(data.ToString("X")); - return result * (long)Math.Pow(100, dig - 1); - } - public static string ReadStringLittle(ReadOnlySpan read, ref int offset, int len) { string value = encoding.GetString(read.Slice(offset, len).ToArray()); @@ -79,58 +23,6 @@ namespace JT809.Protocol.JT809Extensions return value.Trim('\0'); } - public static long ReadBCD(ReadOnlySpan buf, ref int offset, int len) - { - long result = 0; - try - { - for (int i = offset; i < offset + len; i++) - { - result += buf[i].ReadBCD64((byte)(offset + len - i)); - } - } - catch - { - } - offset = offset + len; - return result; - } - - public static DateTime ReadDateTimeLittle(ReadOnlySpan buf, ref int offset) - { - DateTime dateTime = new DateTime( - (buf[offset]).ReadBCD32(1) + DateLimitYear, - (buf[offset + 1]).ReadBCD32(1), - (buf[offset + 2]).ReadBCD32(1), - (buf[offset + 3]).ReadBCD32(1), - (buf[offset + 4]).ReadBCD32(1), - (buf[offset + 5]).ReadBCD32(1)); - offset = offset + 6; - return dateTime; - } - - public static DateTime ReadDateLittle(ReadOnlySpan buf, ref int offset) - { - DateTime dateTime = new DateTime( - ((buf[offset] << 8) | (buf[offset + 1])), - (buf[offset + 2]).ReadBCD32(1), - (buf[offset + 3]).ReadBCD32(1)); - offset = offset + 4; - return dateTime; - } - - public static DateTime ReadUTCDateTimeLittle(ReadOnlySpan buf, ref int offset) - { - ulong result = 0; - for (int i = 0; i < 8; i++) - { - ulong currentData = (ulong)buf[offset+i] << (8 * (8 - i - 1)); - result += currentData; - } - offset += 8; - return UTCBaseTime.AddSeconds(result).AddHours(8); - } - public static int ReadInt32Little(ReadOnlySpan read, ref int offset) { int value = (read[offset] << 24) | (read[offset + 1] << 16) | (read[offset + 2] << 8) | read[offset + 3]; @@ -226,26 +118,6 @@ namespace JT809.Protocol.JT809Extensions return result.ToString(); } - public static int WriteDateTime6Little(IMemoryOwner memoryOwner, int offset, DateTime date) - { - memoryOwner.Memory.Span[offset] = ((byte)(date.Year - DateLimitYear)).ToBcdByte(); - memoryOwner.Memory.Span[offset + 1] = ((byte)(date.Month)).ToBcdByte(); - memoryOwner.Memory.Span[offset + 2] = ((byte)(date.Day)).ToBcdByte(); - memoryOwner.Memory.Span[offset + 3] = ((byte)(date.Hour)).ToBcdByte(); - memoryOwner.Memory.Span[offset + 4] = ((byte)(date.Minute)).ToBcdByte(); - memoryOwner.Memory.Span[offset + 5] = ((byte)(date.Second)).ToBcdByte(); - return 6; - } - - public static int WriteDateTime4Little(IMemoryOwner memoryOwner, int offset, DateTime date) - { - memoryOwner.Memory.Span[offset] = (byte)(date.Year >> 8); - memoryOwner.Memory.Span[offset + 1] = (byte)date.Year; - memoryOwner.Memory.Span[offset + 2] = ((byte)(date.Month)).ToBcdByte(); - memoryOwner.Memory.Span[offset + 3] = ((byte)(date.Day)).ToBcdByte(); - return 4; - } - public static int WriteInt32Little(IMemoryOwner memoryOwner, int offset, int data) { memoryOwner.Memory.Span[offset] = (byte)(data >> 24); @@ -340,16 +212,6 @@ namespace JT809.Protocol.JT809Extensions return codeBytes.Length; } - public static int WriteBCDLittle(IMemoryOwner memoryOwner, int offset, string data, int digit, int len) - { - ReadOnlySpan bcd = data.PadLeft(len, '0').AsSpan(); - for (int i = 0; i < digit; i++) - { - memoryOwner.Memory.Span[offset + i] = Convert.ToByte(bcd.Slice(i * 2, 2).ToString(), 16); - } - return digit; - } - /// /// 数字编码 大端模式、高位在前 /// @@ -388,18 +250,6 @@ namespace JT809.Protocol.JT809Extensions return len; } - public static int WriteUTCDateTimeLittle(IMemoryOwner memoryOwner, int offset, DateTime date) - { - ulong totalSecends = (ulong)(date.AddHours(-8) - UTCBaseTime).TotalSeconds; - //高位在前 - for (int i = 7; i >= 0; i--) - { - memoryOwner.Memory.Span[offset+i] = (byte)(totalSecends & 0xFF); //取低8位 - totalSecends = totalSecends >> 8; - } - return 8; - } - public static IEnumerable ToBytes(this string data, Encoding coding) { return coding.GetBytes(data); @@ -422,45 +272,20 @@ namespace JT809.Protocol.JT809Extensions return bytes; } - /// - /// 从数据头到校验码前的 CRC 1 G-CCITT 的校验值,遵循人端排序方式的规定。 - /// - /// - /// - /// - /// - /// - public static ushort ToCRC16_CCITT(this Span ucbuf, int offset, int iLen) + public static byte ToBcdByte(this byte buf) { - ushort checkCode = 0xFFFF; - for (int j = offset; j < iLen; ++j) - { - checkCode = (ushort)((checkCode << 8) ^ (ushort)CRC[(checkCode >> 8) ^ ucbuf[j]]); - } - return checkCode; + return (byte)Convert.ToInt32(buf.ToString(), 16); } /// - /// 从数据头到校验码前的 CRC 1 G-CCITT 的校验值,遵循人端排序方式的规定。 + /// 字节数组字符串 /// - /// - /// - /// - /// + /// + /// 默认 " " /// - public static ushort ToCRC16_CCITT(this ReadOnlySpan ucbuf, int offset, int iLen) - { - ushort checkCode = 0xFFFF; - for (int j = offset; j < iLen; ++j) - { - checkCode = (ushort)((checkCode << 8) ^ (ushort)CRC[(checkCode >> 8) ^ ucbuf[j]]); - } - return checkCode; - } - - public static byte ToBcdByte(this byte buf) + public static string ToHexString(this byte[] bytes, string separator = " ") { - return (byte)Convert.ToInt32(buf.ToString(), 16); + return string.Join(separator, bytes.Select(s => s.ToString("X2"))); } /// @@ -480,62 +305,5 @@ namespace JT809.Protocol.JT809Extensions destination[offset + i] = source[i]; } } - - /// - /// 字节数组转16进制字符串 - /// - /// - /// 默认 " " - /// - public static string ToHexString(this byte[] bytes, string separator = " ") - { - return string.Join(separator, bytes.Select(s => s.ToString("X2"))); - } - - /// - /// 16进制字符串转16进制数组 - /// - /// - /// - /// - public static byte[] ToHexBytes(this string hexString, string separator = " ") - { - return hexString.Split(new string[] { separator }, StringSplitOptions.RemoveEmptyEntries).Select(s => Convert.ToByte(s, 16)).ToArray(); - } - - /// - /// 16进制字符串转16进制数组 - /// - /// - /// - public static byte[] ToStr2HexBytes(this string hexString) - { - //byte[] buf = new byte[hexString.Length / 2]; - //for (int i = 0; i < hexString.Length; i++) - //{ - // if (i % 2 == 0) - // { - // buf[i / 2] = Convert.ToByte(hexString.Substring(i, 2), 16) ; - // } - - //} - byte[] buf = new byte[hexString.Length / 2]; - ReadOnlySpan readOnlySpan = hexString.AsSpan(); - for (int i = 0; i < hexString.Length; i++) - { - if (i % 2 == 0) - { - buf[i / 2] = Convert.ToByte(readOnlySpan.Slice(i, 2).ToString(), 16); - } - } - return buf; - //List bytes = new List(); - //while (hexString.Length>0) - //{ - // bytes.Add(Convert.ToByte(hexString.AsSpan(0, 2).ToString(), 16)); - // hexString = hexString.Remove(0,2); - //} - //return Regex.Replace(hexString, @"(\w{2})", "$1 ").Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(s => Convert.ToByte(s, 16)).ToArray(); - } } } diff --git a/src/JT809.Protocol/JT809Extensions/JT809CRCExtensions.cs b/src/JT809.Protocol/JT809Extensions/JT809CRCExtensions.cs new file mode 100644 index 0000000..c7f5105 --- /dev/null +++ b/src/JT809.Protocol/JT809Extensions/JT809CRCExtensions.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.JT809Extensions +{ + public static partial class JT809BinaryExtensions + { + /// + /// 从数据头到校验码前的 CRC 1 G-CCITT 的校验值,遵循人端排序方式的规定。 + /// + /// + /// + /// + /// + /// + public static ushort ToCRC16_CCITT(this Span ucbuf, int offset, int iLen) + { + ushort checkCode = 0xFFFF; + for (int j = offset; j < iLen; ++j) + { + checkCode = (ushort)((checkCode << 8) ^ (ushort)CRC[(checkCode >> 8) ^ ucbuf[j]]); + } + return checkCode; + } + + /// + /// 从数据头到校验码前的 CRC 1 G-CCITT 的校验值,遵循人端排序方式的规定。 + /// + /// + /// + /// + /// + /// + public static ushort ToCRC16_CCITT(this ReadOnlySpan ucbuf, int offset, int iLen) + { + ushort checkCode = 0xFFFF; + for (int j = offset; j < iLen; ++j) + { + checkCode = (ushort)((checkCode << 8) ^ (ushort)CRC[(checkCode >> 8) ^ ucbuf[j]]); + } + return checkCode; + } + } +} diff --git a/src/JT809.Protocol/JT809Extensions/JT809DateTimeExtensions.cs b/src/JT809.Protocol/JT809Extensions/JT809DateTimeExtensions.cs new file mode 100644 index 0000000..2dd0927 --- /dev/null +++ b/src/JT809.Protocol/JT809Extensions/JT809DateTimeExtensions.cs @@ -0,0 +1,129 @@ +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.JT809Extensions +{ + public static partial class JT809BinaryExtensions + { + /// + /// 日期限制于2000年 + /// + private const int DateLimitYear = 2000; + + private static readonly DateTime UTCBaseTime = new DateTime(1970, 1, 1); + + /// + /// + /// + /// + /// + /// D2: 10 X2:16 + /// + public static DateTime ReadDateTime6Little(ReadOnlySpan buf, ref int offset,string format= "X2") + { + DateTime d = UTCBaseTime; + try + { + int year = Convert.ToInt32(buf[offset].ToString(format)) + DateLimitYear; + int month = Convert.ToInt32(buf[offset + 1].ToString(format)); + int day = Convert.ToInt32(buf[offset + 2].ToString(format)); + int hour = Convert.ToInt32(buf[offset + 3].ToString(format)); + int minute = Convert.ToInt32(buf[offset + 4].ToString(format)); + int second = Convert.ToInt32(buf[offset + 5].ToString(format)); + d = new DateTime(year, month, day, hour, minute, second); + } + catch (Exception ex) + { + d = UTCBaseTime; + } + offset = offset + 6; + return d; + } + + /// + /// + /// + /// + /// + /// D2: 10 X2:16 + /// + public static DateTime ReadDateTime4Little(ReadOnlySpan buf, ref int offset, string format = "X2") + { + DateTime d = UTCBaseTime; + try + { + d = new DateTime( + Convert.ToInt32(buf[offset].ToString(format)) + DateLimitYear, + Convert.ToInt32(buf[offset + 1].ToString(format)), + Convert.ToInt32(buf[offset + 2].ToString(format))); + } + catch (Exception) + { + d = UTCBaseTime; + } + offset = offset + 4; + return d; + } + + public static DateTime ReadUTCDateTimeLittle(ReadOnlySpan buf, ref int offset) + { + ulong result = 0; + for (int i = 0; i < 8; i++) + { + ulong currentData = (ulong)buf[offset + i] << (8 * (8 - i - 1)); + result += currentData; + } + offset += 8; + return UTCBaseTime.AddSeconds(result).AddHours(8); + } + + public static int WriteUTCDateTimeLittle(IMemoryOwner memoryOwner, int offset, DateTime date) + { + ulong totalSecends = (ulong)(date.AddHours(-8) - UTCBaseTime).TotalSeconds; + //高位在前 + for (int i = 7; i >= 0; i--) + { + memoryOwner.Memory.Span[offset + i] = (byte)(totalSecends & 0xFF); //取低8位 + totalSecends = totalSecends >> 8; + } + return 8; + } + + /// + /// + /// + /// + /// + /// + /// BCD:10 HEX:16 + /// + public static int WriteDateTime6Little(IMemoryOwner memoryOwner, int offset, DateTime date,int fromBase=16) + { + memoryOwner.Memory.Span[offset] = Convert.ToByte(date.ToString("yy"), fromBase); + memoryOwner.Memory.Span[offset + 1] = Convert.ToByte(date.ToString("MM"), fromBase); + memoryOwner.Memory.Span[offset + 2] = Convert.ToByte(date.ToString("dd"), fromBase); + memoryOwner.Memory.Span[offset + 3] = Convert.ToByte(date.ToString("HH"), fromBase); + memoryOwner.Memory.Span[offset + 4] = Convert.ToByte(date.ToString("mm"), fromBase); + memoryOwner.Memory.Span[offset + 5] = Convert.ToByte(date.ToString("ss"), fromBase); + return 6; + } + + /// + /// + /// + /// + /// + /// + /// BCD:10 HEX:16 + /// + public static int WriteDateTime4Little(IMemoryOwner memoryOwner, int offset, DateTime date, int fromBase = 16) + { + memoryOwner.Memory.Span[offset] = Convert.ToByte(date.ToString("yy"), fromBase); + memoryOwner.Memory.Span[offset + 1] = Convert.ToByte(date.ToString("MM"), fromBase); + memoryOwner.Memory.Span[offset + 2] = Convert.ToByte(date.ToString("dd"), fromBase); + return 4; + } + } +} diff --git a/src/JT809.Protocol/JT809Extensions/JT809HexExtensions.cs b/src/JT809.Protocol/JT809Extensions/JT809HexExtensions.cs new file mode 100644 index 0000000..343c563 --- /dev/null +++ b/src/JT809.Protocol/JT809Extensions/JT809HexExtensions.cs @@ -0,0 +1,290 @@ +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace JT809.Protocol.JT809Extensions +{ + /// + /// + /// + public static partial class JT809BinaryExtensions + { + static readonly int[] toHexTable = new int[] { + 3145776, 3211312, 3276848, 3342384, 3407920, 3473456, 3538992, 3604528, 3670064, 3735600, + 4259888, 4325424, 4390960, 4456496, 4522032, 4587568, 3145777, 3211313, 3276849, 3342385, + 3407921, 3473457, 3538993, 3604529, 3670065, 3735601, 4259889, 4325425, 4390961, 4456497, + 4522033, 4587569, 3145778, 3211314, 3276850, 3342386, 3407922, 3473458, 3538994, 3604530, + 3670066, 3735602, 4259890, 4325426, 4390962, 4456498, 4522034, 4587570, 3145779, 3211315, + 3276851, 3342387, 3407923, 3473459, 3538995, 3604531, 3670067, 3735603, 4259891, 4325427, + 4390963, 4456499, 4522035, 4587571, 3145780, 3211316, 3276852, 3342388, 3407924, 3473460, + 3538996, 3604532, 3670068, 3735604, 4259892, 4325428, 4390964, 4456500, 4522036, 4587572, + 3145781, 3211317, 3276853, 3342389, 3407925, 3473461, 3538997, 3604533, 3670069, 3735605, + 4259893, 4325429, 4390965, 4456501, 4522037, 4587573, 3145782, 3211318, 3276854, 3342390, + 3407926, 3473462, 3538998, 3604534, 3670070, 3735606, 4259894, 4325430, 4390966, 4456502, + 4522038, 4587574, 3145783, 3211319, 3276855, 3342391, 3407927, 3473463, 3538999, 3604535, + 3670071, 3735607, 4259895, 4325431, 4390967, 4456503, 4522039, 4587575, 3145784, 3211320, + 3276856, 3342392, 3407928, 3473464, 3539000, 3604536, 3670072, 3735608, 4259896, 4325432, + 4390968, 4456504, 4522040, 4587576, 3145785, 3211321, 3276857, 3342393, 3407929, 3473465, + 3539001, 3604537, 3670073, 3735609, 4259897, 4325433, 4390969, 4456505, 4522041, 4587577, + 3145793, 3211329, 3276865, 3342401, 3407937, 3473473, 3539009, 3604545, 3670081, 3735617, + 4259905, 4325441, 4390977, 4456513, 4522049, 4587585, 3145794, 3211330, 3276866, 3342402, + 3407938, 3473474, 3539010, 3604546, 3670082, 3735618, 4259906, 4325442, 4390978, 4456514, + 4522050, 4587586, 3145795, 3211331, 3276867, 3342403, 3407939, 3473475, 3539011, 3604547, + 3670083, 3735619, 4259907, 4325443, 4390979, 4456515, 4522051, 4587587, 3145796, 3211332, + 3276868, 3342404, 3407940, 3473476, 3539012, 3604548, 3670084, 3735620, 4259908, 4325444, + 4390980, 4456516, 4522052, 4587588, 3145797, 3211333, 3276869, 3342405, 3407941, 3473477, + 3539013, 3604549, 3670085, 3735621, 4259909, 4325445, 4390981, 4456517, 4522053, 4587589, + 3145798, 3211334, 3276870, 3342406, 3407942, 3473478, 3539014, 3604550, 3670086, 3735622, + 4259910, 4325446, 4390982, 4456518, 4522054, 4587590 + }; + + /// + /// values for '\0' to 'f' where 255 indicates invalid input character + /// starting from '\0' and not from '0' costs 48 bytes + /// but results 0 subtructions and less if conditions + /// + static readonly byte[] fromHexTable = new byte[] { + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 0, 1, + 2, 3, 4, 5, 6, 7, 8, 9, 255, 255, + 255, 255, 255, 255, 255, 10, 11, 12, 13, 14, + 15, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 10, 11, 12, + 13, 14, 15 + }; + + /// + /// same as above but valid values are multiplied by 16 + /// + static readonly byte[] fromHexTable16 = new byte[] { + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 0, 16, + 32, 48, 64, 80, 96, 112, 128, 144, 255, 255, + 255, 255, 255, 255, 255, 160, 176, 192, 208, 224, + 240, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 160, 176, 192, + 208, 224, 240 + }; + + public static string ToHexString(byte[] source) + { + return ToHexString(source, false); + } + + public static int WriteHexStringLittle(IMemoryOwner memoryOwner, int offset, string data, int len) + { + if (data == null) data = ""; + data = data.Replace(" ", ""); + int startIndex = 0; + if (data.StartsWith("0x", StringComparison.OrdinalIgnoreCase)) + { + startIndex = 2; + } + int length = len; + if (length == -1) + { + length = (data.Length - startIndex) / 2; + } + int noOfZero = length * 2 + startIndex - data.Length; + if (noOfZero > 0) + { + data = data.Insert(startIndex, new string('0', noOfZero)); + } + int byteIndex = 0; + while (startIndex < data.Length && byteIndex < length) + { + memoryOwner.Memory.Span[offset+byteIndex] = Convert.ToByte(data.Substring(startIndex, 2), 16); + startIndex += 2; + byteIndex++; + } + return length; + } + + /// + /// 16进制字符串转16进制数组 + /// + /// + /// + /// + public static byte[] ToHexBytes(this string hexString, string separator = " ") + { + return hexString.Split(new string[] { separator }, StringSplitOptions.RemoveEmptyEntries).Select(s => Convert.ToByte(s, 16)).ToArray(); + } + + /// + /// 16进制字符串转16进制数组 + /// + /// + /// + public static byte[] ToStr2HexBytes(this string hexString) + { + //byte[] buf = new byte[hexString.Length / 2]; + //for (int i = 0; i < hexString.Length; i++) + //{ + // if (i % 2 == 0) + // { + // buf[i / 2] = Convert.ToByte(hexString.Substring(i, 2), 16) ; + // } + + //} + byte[] buf = new byte[hexString.Length / 2]; + ReadOnlySpan readOnlySpan = hexString.AsSpan(); + for (int i = 0; i < hexString.Length; i++) + { + if (i % 2 == 0) + { + buf[i / 2] = Convert.ToByte(readOnlySpan.Slice(i, 2).ToString(), 16); + } + } + return buf; + //List bytes = new List(); + //while (hexString.Length>0) + //{ + // bytes.Add(Convert.ToByte(hexString.AsSpan(0, 2).ToString(), 16)); + // hexString = hexString.Remove(0,2); + //} + //return Regex.Replace(hexString, @"(\w{2})", "$1 ").Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(s => Convert.ToByte(s, 16)).ToArray(); + } + + public unsafe static string ReadHexStringLittle(ReadOnlySpan read, ref int offset, int len) + { + ReadOnlySpan source = read.Slice(offset, len); + offset += len; + // freeze toHexTable position in memory + fixed (int* hexRef = toHexTable) + // freeze source position in memory + fixed (byte* sourceRef = source) + { + // take first parsing position of source - allow inline pointer positioning + byte* s = sourceRef; + // calculate result length + int resultLen = (source.Length << 1); + // initialize result string with any character expect '\0' + string result = new string(' ', resultLen); + // take the first character address of result + fixed (char* resultRef = result) + { + // pairs of characters explain the endianess of toHexTable + // move on by pairs of characters (2 x 2 bytes) - allow inline pointer positioning + int* pair = (int*)resultRef; + // more to go + while (*pair != 0) + // set the value of the current pair and move to next pair and source byte + *pair++ = hexRef[*s++]; + return result; + } + } + } + + /// + /// hexIndicator: use prefix ("0x") or not + /// + /// + /// + /// + public unsafe static string ToHexString(byte[] source, bool hexIndicator) + { + // freeze toHexTable position in memory + fixed (int* hexRef = toHexTable) + // freeze source position in memory + fixed (byte* sourceRef = source) + { + // take first parsing position of source - allow inline pointer positioning + byte* s = sourceRef; + // calculate result length + int resultLen = (source.Length << 1); + // use prefix ("Ox") + if (hexIndicator) + // adapt result length + resultLen += 2; + // initialize result string with any character expect '\0' + string result = new string(' ', resultLen); + // take the first character address of result + fixed (char* resultRef = result) + { + // pairs of characters explain the endianess of toHexTable + // move on by pairs of characters (2 x 2 bytes) - allow inline pointer positioning + int* pair = (int*)resultRef; + // use prefix ("Ox") ? + if (hexIndicator) + // set first pair value + *pair++ = 7864368; + // more to go + while (*pair != 0) + // set the value of the current pair and move to next pair and source byte + *pair++ = hexRef[*s++]; + return result; + } + } + } + + public unsafe static byte[] FromHexString(string source) + { + // return an empty array in case of null or empty source + if (string.IsNullOrEmpty(source)) + return new byte[0]; // you may change it to return null + if (source.Length % 2 == 1) // source length must be even + throw new ArgumentException(); + int + index = 0, // start position for parsing source + len = source.Length >> 1; // initial length of result + // take the first character address of source + fixed (char* sourceRef = source) + { + if (*(int*)sourceRef == 7864368) // source starts with "0x" + { + if (source.Length == 2) // source must not be just a "0x") + throw new ArgumentException(); + index += 2; // start position (bypass "0x") + len -= 1; // result length (exclude "0x") + } + byte add = 0; // keeps a fromHexTable value + byte[] result = new byte[len]; // initialization of result for known length + // freeze fromHexTable16 position in memory + fixed (byte* hiRef = fromHexTable16) + // freeze fromHexTable position in memory + fixed (byte* lowRef = fromHexTable) + // take the first byte address of result + fixed (byte* resultRef = result) + { + // take first parsing position of source - allow inremental memory position + char* s = (char*)&sourceRef[index]; + // take first byte position of result - allow incremental memory position + byte* r = resultRef; + // source has more characters to parse + while (*s != 0) + { + // check for non valid characters in pairs + // you may split it if you don't like its readbility + if ( + // check for character > 'f' + *s > 102 || + // assign source value to current result position and increment source position + // and check if is a valid character + (*r = hiRef[*s++]) == 255 || + // check for character > 'f' + *s > 102 || + // assign source value to "add" parameter and increment source position + // and check if is a valid character + (add = lowRef[*s++]) == 255 + ) + throw new ArgumentException(); + // set final value of current result byte and move pointer to next byte + *r++ += add; + } + return result; + } + } + } + } +} diff --git a/src/JT809.Protocol/JT809Extensions/JT809InitBinaryExtensions.cs b/src/JT809.Protocol/JT809Extensions/JT809InitBinaryExtensions.cs new file mode 100644 index 0000000..74a64fa --- /dev/null +++ b/src/JT809.Protocol/JT809Extensions/JT809InitBinaryExtensions.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.JT809Extensions +{ + public static partial class JT809BinaryExtensions + { + public static Encoding encoding; + + private const ushort cnCRC_CCITT = 0x1021; //CRC校验多项式 + + private static ulong[] CRC = new ulong[256]; //建立CRC16表 + + static JT809BinaryExtensions() + { + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + encoding = Encoding.GetEncoding("GBK"); + ushort i, j; + ushort nData; + ushort nAccum; + for (i = 0; i < 256; i++) + { + nData = (ushort)(i << 8); + nAccum = 0; + for (j = 0; j < 8; j++) + { + if (((nData ^ nAccum) & 0x8000) > 0) + nAccum = (ushort)((nAccum << 1) ^ cnCRC_CCITT); + else + nAccum <<= 1; + nData <<= 1; + } + CRC[i] = (ulong)nAccum; + } + } + } +} diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1400_0x1402Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1400_0x1402Formatter.cs index 4d6097e..30a1ec2 100644 --- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1400_0x1402Formatter.cs +++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1400_0x1402Formatter.cs @@ -14,7 +14,7 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters int offset = 0; JT809_0x1400_0x1402 jT809_0X1400_0X1402 = new JT809_0x1400_0x1402(); jT809_0X1400_0X1402.WarnSrc = (JT809Enums.JT809WarnSrc)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); - jT809_0X1400_0X1402.WarnType= JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); + jT809_0X1400_0X1402.WarnType=(JT809Enums.JT809WarnType) JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); jT809_0X1400_0X1402.WarnTime = JT809BinaryExtensions.ReadUTCDateTimeLittle(bytes, ref offset); jT809_0X1400_0X1402.InfoID= JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); jT809_0X1400_0X1402.InfoLength = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); @@ -26,7 +26,7 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters public int Serialize(IMemoryOwner memoryOwner, int offset, JT809_0x1400_0x1402 value) { offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.WarnSrc); - offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset,value.WarnType); + offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset,(ushort)value.WarnType); offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(memoryOwner, offset, value.WarnTime); offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.InfoID); // 先计算内容长度(汉字为两个字节) diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1502Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1502Formatter.cs index f46db26..817f4f2 100644 --- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1502Formatter.cs +++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1502Formatter.cs @@ -35,7 +35,10 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters jT809_0X1500_0X1502.PhotoLen = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); jT809_0X1500_0X1502.SizeType = JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); jT809_0X1500_0X1502.Type = JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); - jT809_0X1500_0X1502.Photo = JT809BinaryExtensions.ReadBytesLittle(bytes, ref offset); + if (jT809_0X1500_0X1502.PhotoLen > 0) + { + jT809_0X1500_0X1502.Photo = JT809BinaryExtensions.ReadBytesLittle(bytes, ref offset, (int)jT809_0X1500_0X1502.PhotoLen); + } readSize = offset; return jT809_0X1500_0X1502; } @@ -60,10 +63,14 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VehiclePosition.State); offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VehiclePosition.Alarm); offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.LensID); - offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.PhotoLen); + bool isPhoto = (value.Photo != null && value.Photo.Length > 0); + offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, isPhoto ? (uint)value.Photo.Length : 0); offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.SizeType); offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.Type); - offset += JT809BinaryExtensions.WriteBytesLittle(memoryOwner, offset, value.Photo); + if (isPhoto) + { + offset += JT809BinaryExtensions.WriteBytesLittle(memoryOwner, offset, value.Photo); + } return offset; } } diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1504Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1504Formatter.cs index 18f474f..991cd74 100644 --- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1504Formatter.cs +++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x1500_0x1504Formatter.cs @@ -1,4 +1,5 @@ -using JT809.Protocol.JT809Extensions; +using JT809.Protocol.JT809Enums; +using JT809.Protocol.JT809Extensions; using JT809.Protocol.JT809SubMessageBody; using System; using System.Buffers; @@ -13,7 +14,7 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters { int offset = 0; JT809_0x1500_0x1504 jT809_0X1500_0X1504 = new JT809_0x1500_0x1504(); - jT809_0X1500_0X1504.CommandType = JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); + jT809_0X1500_0X1504.CommandType = (JT809CommandType)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); jT809_0X1500_0X1504.TraveldataLength= JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); jT809_0X1500_0X1504.TraveldataInfo = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, (int)jT809_0X1500_0X1504.TraveldataLength); readSize = offset; @@ -22,7 +23,7 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters public int Serialize(IMemoryOwner memoryOwner, int offset, JT809_0x1500_0x1504 value) { - offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.CommandType); + offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.CommandType); // 先计算内容长度(汉字为两个字节) offset += 4; int byteLength = JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.TraveldataInfo); diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9400_0x9401Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9400_0x9401Formatter.cs index 7684a14..fc472ae 100644 --- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9400_0x9401Formatter.cs +++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9400_0x9401Formatter.cs @@ -14,10 +14,10 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters int offset = 0; JT809_0x9400_0x9401 jT809_0X9400_0X9401 = new JT809_0x9400_0x9401(); jT809_0X9400_0X9401.WarnSrc = (JT809Enums.JT809WarnSrc)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); - jT809_0X9400_0X9401.WarnType = JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); + jT809_0X9400_0X9401.WarnType =(JT809Enums.JT809WarnType) JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); jT809_0X9400_0X9401.WarnTime = JT809BinaryExtensions.ReadUTCDateTimeLittle(bytes, ref offset); - jT809_0X9400_0X9401.SupervisionID = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); - jT809_0X9400_0X9401.SupervisionEndtime = JT809BinaryExtensions.ReadUTCDateTimeLittle(bytes, ref offset); + jT809_0X9400_0X9401.SupervisionID = JT809BinaryExtensions.ReadHexStringLittle(bytes, ref offset,4); + jT809_0X9400_0X9401.SupervisionEndTime = JT809BinaryExtensions.ReadUTCDateTimeLittle(bytes, ref offset); jT809_0X9400_0X9401.SupervisionLevel = JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); jT809_0X9400_0X9401.Supervisor = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset,16); jT809_0X9400_0X9401.SupervisorTel = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset,20); @@ -29,10 +29,10 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters public int Serialize(IMemoryOwner memoryOwner, int offset, JT809_0x9400_0x9401 value) { offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.WarnSrc); - offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.WarnType); + offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, (ushort)value.WarnType); offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(memoryOwner, offset, value.WarnTime); - offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.SupervisionID); - offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(memoryOwner, offset, value.SupervisionEndtime); + offset += JT809BinaryExtensions.WriteHexStringLittle(memoryOwner, offset, value.SupervisionID,4); + offset += JT809BinaryExtensions.WriteUTCDateTimeLittle(memoryOwner, offset, value.SupervisionEndTime); offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, value.SupervisionLevel); offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.Supervisor,16); offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.SupervisorTel,20); diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9504Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9504Formatter.cs index 4d73307..b73c166 100644 --- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9504Formatter.cs +++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9504Formatter.cs @@ -33,8 +33,8 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters case JT809Enums.JT809CommandType.采集记录仪外部供电记录: case JT809Enums.JT809CommandType.采集记录仪参数修改记录: case JT809Enums.JT809CommandType.采集记录仪速度状态日志: - jT809_0X9500_0X9504.StartTime = JT809BinaryExtensions.ReadDateTimeLittle(bytes, ref offset); - jT809_0X9500_0X9504.EndTime = JT809BinaryExtensions.ReadDateTimeLittle(bytes, ref offset); + jT809_0X9500_0X9504.StartTime = JT809BinaryExtensions.ReadDateTime6Little(bytes, ref offset); + jT809_0X9500_0X9504.EndTime = JT809BinaryExtensions.ReadDateTime6Little(bytes, ref offset); jT809_0X9500_0X9504.Max = JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); break; } diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9505Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9505Formatter.cs index 3a0b33f..9604eb2 100644 --- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9505Formatter.cs +++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9505Formatter.cs @@ -13,21 +13,21 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters { int offset = 0; JT809_0x9500_0x9505 jT809_0X9500_0X9505 = new JT809_0x9500_0x9505(); - jT809_0X9500_0X9505.AuthenticationCode= JT809BinaryExtensions.ReadBCD32(bytes, ref offset,10).ToString(); + jT809_0X9500_0X9505.AuthenticationCode= JT809BinaryExtensions.ReadBCDLittle(bytes, ref offset,10); jT809_0X9500_0X9505.AccessPointName = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, 20); jT809_0X9500_0X9505.UserName = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset,49); jT809_0X9500_0X9505.Password = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset,22); jT809_0X9500_0X9505.ServerIP = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, 32); jT809_0X9500_0X9505.TcpPort = JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); jT809_0X9500_0X9505.UdpPort = JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); - jT809_0X9500_0X9505.EndTime = JT809BinaryExtensions.ReadDateTimeLittle(bytes, ref offset); + jT809_0X9500_0X9505.EndTime = JT809BinaryExtensions.ReadUTCDateTimeLittle(bytes, ref offset); readSize = offset; return jT809_0X9500_0X9505; } public int Serialize(IMemoryOwner memoryOwner, int offset, JT809_0x9500_0x9505 value) { - offset += JT809BinaryExtensions.WriteBCDLittle(memoryOwner, offset, value.AuthenticationCode,4,10); + offset += JT809BinaryExtensions.WriteBCDLittle(memoryOwner, offset, value.AuthenticationCode,10,20); offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.AccessPointName,20); offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.UserName, 49); offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.Password, 22); diff --git a/src/JT809.Protocol/JT809SubMessageBody/JT809_0x1400_0x1402.cs b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x1400_0x1402.cs index 91bdc90..bcc78ce 100644 --- a/src/JT809.Protocol/JT809SubMessageBody/JT809_0x1400_0x1402.cs +++ b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x1400_0x1402.cs @@ -23,7 +23,7 @@ namespace JT809.Protocol.JT809SubMessageBody /// /// 报警类型 /// - public ushort WarnType { get; set; } + public JT809WarnType WarnType { get; set; } /// /// 报警时间 /// diff --git a/src/JT809.Protocol/JT809SubMessageBody/JT809_0x1500_0x1502.cs b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x1500_0x1502.cs index 3be9b62..0d0031c 100644 --- a/src/JT809.Protocol/JT809SubMessageBody/JT809_0x1500_0x1502.cs +++ b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x1500_0x1502.cs @@ -16,6 +16,10 @@ namespace JT809.Protocol.JT809SubMessageBody [JT809Formatter(typeof(JT809_0x1500_0x1502Formatter))] public class JT809_0x1500_0x1502:JT809SubBodies { + public JT809_0x1500_0x1502() + { + VehiclePosition = new JT809VehiclePositionProperties(); + } /// /// 拍照应答标识 /// diff --git a/src/JT809.Protocol/JT809SubMessageBody/JT809_0x1500_0x1504.cs b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x1500_0x1504.cs index 2cabc13..852f4bb 100644 --- a/src/JT809.Protocol/JT809SubMessageBody/JT809_0x1500_0x1504.cs +++ b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x1500_0x1504.cs @@ -1,4 +1,5 @@ using JT809.Protocol.JT809Attributes; +using JT809.Protocol.JT809Enums; using JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters; using System; using System.Collections.Generic; @@ -17,7 +18,7 @@ namespace JT809.Protocol.JT809SubMessageBody /// /// 命令字 /// - public byte CommandType { get; set; } + public JT809CommandType CommandType { get; set; } /// /// 车辆行驶记录数据体长度 /// diff --git a/src/JT809.Protocol/JT809SubMessageBody/JT809_0x9400_0x9401.cs b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x9400_0x9401.cs index 8941349..ccff30f 100644 --- a/src/JT809.Protocol/JT809SubMessageBody/JT809_0x9400_0x9401.cs +++ b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x9400_0x9401.cs @@ -22,19 +22,19 @@ namespace JT809.Protocol.JT809SubMessageBody /// /// 报警类型 /// - public ushort WarnType { get; set; } + public JT809WarnType WarnType { get; set; } /// - /// 报警时间 + /// 报警时间UTCDateTime /// public DateTime WarnTime { get; set; } /// - /// 报警督办ID + /// 报警督办ID HexString /// - public uint SupervisionID { get; set; } + public string SupervisionID { get; set; } /// /// 督办截止时间 /// - public DateTime SupervisionEndtime { get; set; } + public DateTime SupervisionEndTime { get; set; } /// /// 督办级别 /// diff --git a/src/JT809.Protocol/JT809SubMessageBody/JT809_0x9400_0x9402.cs b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x9400_0x9402.cs index 320527a..a7f8760 100644 --- a/src/JT809.Protocol/JT809SubMessageBody/JT809_0x9400_0x9402.cs +++ b/src/JT809.Protocol/JT809SubMessageBody/JT809_0x9400_0x9402.cs @@ -25,7 +25,7 @@ namespace JT809.Protocol.JT809SubMessageBody /// public ushort WarnType { get; set; } /// - /// 报警时间 + /// 报警时间 UTCDateTime /// public DateTime WarnTime { get; set; } ///