From 2da7eb4512c319b40fb9f908f667278bfa81cbc6 Mon Sep 17 00:00:00 2001 From: "SmallChi(Koike)" <564952747@qq.com> Date: Sun, 26 Apr 2020 14:14:43 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A02019=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E7=9A=84=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=202.=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=A4=B4=E9=83=A8Time=E6=97=B6=E9=97=B4=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E7=9A=84=E8=B5=8B=E5=80=BC=203.=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E7=9A=84=E6=97=B6=E5=80=99=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E4=B8=BA2011=E7=89=88=E6=9C=AC=204.=E5=A2=9E=E5=8A=A0Demo4=205?= =?UTF-8?q?.=E4=BF=AE=E6=94=B9=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 24 ++++ .../JT809MessageBody/JT809_0x1001Test.cs | 30 +++++ .../JT809MessageBody/JT809_0x1002Test.cs | 1 + .../JT809MessageBody/JT809_0x1200Test.cs | 42 +++++++ .../JT809MessageBody/JT809_0x1300Test.cs | 39 +++++++ .../JT809MessageBody/JT809_0x1600Test.cs | 33 ++++++ .../JT809MessageBody/JT809_0x9001Test.cs | 3 + .../JT809_0x1001EncryptPackageTest.cs | 13 ++- .../JT809_0x1600_0x1601Test.cs | 27 +++++ .../JT809_0x9200_0x9207Test.cs | 24 ++++ .../JT809_0x9200_0x9208Test.cs | 26 ++++- .../JT809_0x9200_0x9209Test.cs | 23 ++++ .../JT809_0x9400_0x9402Test.cs | 40 +++++++ .../JT809_0x9400_0x9403Test.cs | 36 ++++++ .../JT809_0x9500_0x9501Test.cs | 3 + .../JT809_0x9500_0x9504Test.cs | 25 +++++ src/JT809.Protocol.Test/Simples/Demo2.cs | 15 ++- src/JT809.Protocol.Test/Simples/Demo3.cs | 1 + src/JT809.Protocol.Test/Simples/Demo4.cs | 106 ++++++++++++++++++ src/JT809.Protocol/Enums/JT809Version.cs | 2 +- .../Interfaces/JT809GlobalConfigBase.cs | 14 +-- src/JT809.Protocol/JT809Bodies.cs | 2 +- .../JT809DependencyInjectionExtensions.cs | 6 +- src/JT809.Protocol/JT809Header.cs | 2 +- .../MessageBody/JT809_0x1400.cs | 4 +- .../MessageBody/JT809_0x9400.cs | 4 +- .../SubMessageBody/JT809_0x1200_0x1201.cs | 4 +- .../SubMessageBody/JT809_0x1200_0x1202.cs | 4 +- .../SubMessageBody/JT809_0x1300_0x1301.cs | 4 +- .../SubMessageBody/JT809_0x1400_0x1402.cs | 8 +- .../SubMessageBody/JT809_0x1400_0x1403.cs | 4 +- .../SubMessageBody/JT809_0x9200_0x9202.cs | 4 +- .../SubMessageBody/JT809_0x9400_0x9402.cs | 10 +- .../SubMessageBody/JT809_0x9400_0x9403.cs | 4 +- .../SubMessageBody/JT809_0x9500_0x9504.cs | 9 +- 35 files changed, 545 insertions(+), 51 deletions(-) create mode 100644 src/JT809.Protocol.Test/Simples/Demo4.cs diff --git a/README.md b/README.md index 22e1289..29c0cbb 100644 --- a/README.md +++ b/README.md @@ -237,6 +237,30 @@ static void Main(string[] args) } ``` +### 举个栗子4 + +如何在项目中同时使用809的2011和2019版本 + +``` data4 +IServiceCollection serviceDescriptors = new ServiceCollection(); +serviceDescriptors.AddJT809Configure(new JT809_2011_Config()); +serviceDescriptors.AddJT809Configure(new JT809_2019_Config()); +JT809Serializer JT809_2011_Serializer= ServiceProvider.GetRequiredService().GetSerializer(); +JT809Serializer JT809_2019_Serializer = ServiceProvider.GetRequiredService().GetSerializer(); +public class JT809_2011_Config: JT809GlobalConfigBase +{ + public override string ConfigId => "JT809_2011"; +} +public class JT809_2019_Config : JT809GlobalConfigBase +{ + public override string ConfigId => "JT809_2019"; + public JT809_2019_Config() + { + Version = JT809Version.JTT2019; + } +} +``` + ## NuGet安装 | Package Name | Version | Downloads diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1001Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1001Test.cs index 6b2f499..aaaffe6 100644 --- a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1001Test.cs +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1001Test.cs @@ -6,12 +6,17 @@ using JT809.Protocol; using JT809.Protocol.Extensions; using JT809.Protocol.MessageBody; using JT809.Protocol.Exceptions; +using JT809.Protocol.Internal; +using JT809.Protocol.Enums; namespace JT809.Protocol.Test.JT809MessageBody { public class JT809_0x1001Test { private JT809Serializer JT809Serializer = new JT809Serializer(); + + private JT809Serializer JT809_2019_Serializer = new JT809Serializer(new DefaultGlobalConfig() { Version = JT809Version.JTT2019 }); + [Fact] public void Test1() { @@ -54,5 +59,30 @@ namespace JT809.Protocol.Test.JT809MessageBody Assert.Equal("127.0.0.1", jT809_0X1001.DownLinkIP); Assert.Equal((ushort)809,jT809_0X1001.DownLinkPort); } + + [Fact] + public void Test_2019_1() + { + JT809_0x1001 jT809_0X1001 = new JT809_0x1001(); + jT809_0X1001.UserId = 20180920; + jT809_0X1001.Password = "20180920"; + jT809_0X1001.MsgGNSSCENTERID = 44555555; + jT809_0X1001.DownLinkIP = "127.0.0.1"; + jT809_0X1001.DownLinkPort = 809; + var hex = JT809_2019_Serializer.Serialize(jT809_0X1001).ToHexString(); + Assert.Equal("0133EFB8323031383039323002A7DD233132372E302E302E3100000000000000000000000000000000000000000000000329", hex); + } + + [Fact] + public void Test_2019_2() + { + var bytes = "0133EFB8323031383039323002A7DD233132372E302E302E3100000000000000000000000000000000000000000000000329".ToHexBytes(); + JT809_0x1001 jT809_0X1001 = JT809_2019_Serializer.Deserialize(bytes); + Assert.Equal(20180920u, jT809_0X1001.UserId); + Assert.Equal("20180920", jT809_0X1001.Password); + Assert.Equal("127.0.0.1", jT809_0X1001.DownLinkIP); + Assert.Equal(809u, jT809_0X1001.DownLinkPort); + Assert.Equal(44555555u, jT809_0X1001.MsgGNSSCENTERID); + } } } diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1002Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1002Test.cs index 989bc5c..f3ff1fd 100644 --- a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1002Test.cs +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1002Test.cs @@ -13,6 +13,7 @@ namespace JT809.Protocol.Test.JT809MessageBody public class JT809_0x1002Test { private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] public void Test1() { diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1200Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1200Test.cs index a990d48..aeeb00b 100644 --- a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1200Test.cs +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1200Test.cs @@ -8,12 +8,14 @@ using System.Collections.Generic; using System.Text; using Xunit; using JT809.Protocol.Enums; +using JT809.Protocol.Internal; namespace JT809.Protocol.Test.JT809MessageBody { public class JT809_0x1200Test { private JT809Serializer JT809Serializer = new JT809Serializer(); + private JT809Serializer JT809_2019_Serializer = new JT809Serializer(new DefaultGlobalConfig() { Version = JT809Version.JTT2019 }); [Fact] public void Test1() { @@ -62,5 +64,45 @@ namespace JT809.Protocol.Test.JT809MessageBody Assert.Equal("11111111", jT809_0X1200_0X1201.TerminalModelType); Assert.Equal("222222222222", jT809_0X1200_0X1201.TerminalSimCode); } + + [Fact] + public void Test_2019_1() + { + JT809_0x1200 jT809_0X1200 = new JT809_0x1200(); + jT809_0X1200.VehicleNo = "粤A12345"; + jT809_0X1200.VehicleColor = JT809VehicleColorType.蓝色; + jT809_0X1200.SubBusinessType = JT809SubBusinessType.上传车辆注册信息.ToUInt16Value(); + jT809_0X1200.DataLength = 110; + JT809_0x1200_0x1201 jT809_0X1200_0X1201 = new JT809_0x1200_0x1201 + { + PlateformId = "1111111111", + ProducerId = "1111111111", + TerminalId = "11111AA", + TerminalModelType = "11111111", + TerminalSimCode = "222222222222", + IMIEId = "123456789" + }; + jT809_0X1200.SubBodies = jT809_0X1200_0X1201; + var hex = JT809_2019_Serializer.Serialize(jT809_0X1200).ToHexString(); + Assert.Equal("D4C1413132333435000000000000000000000000000112010000006E00000000000000423A35C700000000000000423A35C731313131313131310000000000000000000000000000000000000000000031323334353637383900000000000031313131314141000000000000000000000000000000000000000000000000323232323232323232323232", hex); + } + + [Fact] + public void Test_2019_2() + { + var bytes = "D4C1413132333435000000000000000000000000000112010000006E00000000000000423A35C700000000000000423A35C731313131313131310000000000000000000000000000000000000000000031323334353637383900000000000031313131314141000000000000000000000000000000000000000000000000323232323232323232323232".ToHexBytes(); + JT809_0x1200 jT809_0X9001 = JT809_2019_Serializer.Deserialize(bytes); + Assert.Equal("粤A12345", jT809_0X9001.VehicleNo); + Assert.Equal(JT809VehicleColorType.蓝色, jT809_0X9001.VehicleColor); + Assert.Equal(JT809SubBusinessType.上传车辆注册信息, (JT809SubBusinessType)jT809_0X9001.SubBusinessType); + Assert.Equal(110u, jT809_0X9001.DataLength); + JT809_0x1200_0x1201 jT809_0X1200_0X1201 = jT809_0X9001.SubBodies as JT809_0x1200_0x1201; + Assert.Equal("1111111111", jT809_0X1200_0X1201.PlateformId); + Assert.Equal("1111111111", jT809_0X1200_0X1201.ProducerId); + Assert.Equal("11111AA", jT809_0X1200_0X1201.TerminalId); + Assert.Equal("11111111", jT809_0X1200_0X1201.TerminalModelType); + Assert.Equal("222222222222", jT809_0X1200_0X1201.TerminalSimCode); + Assert.Equal("123456789", jT809_0X1200_0X1201.IMIEId); + } } } diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1300Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1300Test.cs index 985e8b9..0d4f508 100644 --- a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1300Test.cs +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1300Test.cs @@ -8,12 +8,14 @@ using System.Text; using Xunit; using JT809.Protocol.SubMessageBody; using JT809.Protocol.Enums; +using JT809.Protocol.Internal; namespace JT809.Protocol.Test.JT809MessageBody { public class JT809_0x1300Test { private JT809Serializer JT809Serializer = new JT809Serializer(); + private JT809Serializer JT809_2019_Serializer = new JT809Serializer(new DefaultGlobalConfig() { Version = JT809Version.JTT2019 }); [Fact] public void Test1() { @@ -43,5 +45,42 @@ namespace JT809.Protocol.Test.JT809MessageBody Assert.Equal((uint)1234, jT809SubBodies.InfoID); Assert.Equal(JT809_0x1301_ObjectType.当前连接的下级平台, jT809SubBodies.ObjectType); } + + [Fact] + public void Test_2019_1() + { + JT809_0x1300 jT809Bodies = new JT809_0x1300(); + jT809Bodies.SubBusinessType = JT809SubBusinessType.平台查岗应答消息.ToUInt16Value(); + jT809Bodies.SubBodies = new JT809_0x1300_0x1301 + { + ObjectID = "111", + InfoContent = "22ha22", + InfoID = 1234, + ObjectType = JT809_0x1301_ObjectType.当前连接的下级平台, + SourceMsgSn = 99, + ResponderTel = "12345678901", + SourceDataType = 111, + Responder = "smallchi" + }; + var hex = JT809_2019_Serializer.Serialize(jT809Bodies).ToHexString(); + Assert.Equal("13010000004901736D616C6C636869000000000000000031323334353637383930310000000000000000003131310000000000000000000000000000000000006F0000006300000006323268613232", hex); + } + + [Fact] + public void Test_2019_2() + { + var bytes = "13010000004901736D616C6C636869000000000000000031323334353637383930310000000000000000003131310000000000000000000000000000000000006F0000006300000006323268613232".ToHexBytes(); + JT809_0x1300 jT809Bodies = JT809_2019_Serializer.Deserialize(bytes); + Assert.Equal(JT809SubBusinessType.平台查岗应答消息, (JT809SubBusinessType)jT809Bodies.SubBusinessType); + JT809_0x1300_0x1301 jT809_0x1300_0x1301 = (JT809_0x1300_0x1301)jT809Bodies.SubBodies; + Assert.Equal("111", jT809_0x1300_0x1301.ObjectID); + Assert.Equal("22ha22", jT809_0x1300_0x1301.InfoContent); + Assert.Equal(0u, jT809_0x1300_0x1301.InfoID); + Assert.Equal(JT809_0x1301_ObjectType.当前连接的下级平台, jT809_0x1300_0x1301.ObjectType); + Assert.Equal(99u, jT809_0x1300_0x1301.SourceMsgSn); + Assert.Equal("12345678901", jT809_0x1300_0x1301.ResponderTel); + Assert.Equal(111, jT809_0x1300_0x1301.SourceDataType); + Assert.Equal("smallchi", jT809_0x1300_0x1301.Responder); + } } } diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1600Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1600Test.cs index d6e61db..36ba812 100644 --- a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1600Test.cs +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1600Test.cs @@ -8,12 +8,15 @@ using System.Text; using Xunit; using JT809.Protocol.SubMessageBody; using JT809.Protocol.Enums; +using JT809.Protocol.Internal; namespace JT809.Protocol.Test.JT809MessageBody { public class JT809_0x1600Test { private JT809Serializer JT809Serializer = new JT809Serializer(); + private JT809Serializer JT809_2019_Serializer = new JT809Serializer(new DefaultGlobalConfig() { Version = JT809Version.JTT2019 }); + [Fact] public void Test1() { @@ -40,5 +43,35 @@ namespace JT809.Protocol.Test.JT809MessageBody Assert.Equal(JT809SubBusinessType.补报车辆静态信息应答, (JT809SubBusinessType)jT809Bodies.SubBusinessType); Assert.Equal("什么鬼", ((JT809_0x1600_0x1601)jT809Bodies.SubBodies).CarInfo); } + + [Fact] + public void Test_2019_1() + { + JT809_0x1600 jT809Bodies = new JT809_0x1600(); + jT809Bodies.VehicleNo = "粤A12345"; + jT809Bodies.VehicleColor = JT809VehicleColorType.蓝色; + jT809Bodies.SubBusinessType = JT809SubBusinessType.补报车辆静态信息应答.ToUInt16Value(); + jT809Bodies.SubBodies = new JT809_0x1600_0x1601 + { + SourceDataType = 1, + SourceMsgSn = 2, + CarInfo = "什么鬼" + }; + var hex = JT809_2019_Serializer.Serialize(jT809Bodies).ToHexString(); + Assert.Equal("D4C1413132333435000000000000000000000000000116010000000C000100000002CAB2C3B4B9ED", hex); + } + + [Fact] + public void Test_2019_2() + { + var bytes = "D4C1413132333435000000000000000000000000000116010000000C000100000002CAB2C3B4B9ED".ToHexBytes(); + JT809_0x1600 jT809Bodies = JT809_2019_Serializer.Deserialize(bytes); + Assert.Equal("粤A12345", jT809Bodies.VehicleNo); + Assert.Equal(JT809VehicleColorType.蓝色, jT809Bodies.VehicleColor); + Assert.Equal(JT809SubBusinessType.补报车辆静态信息应答, (JT809SubBusinessType)jT809Bodies.SubBusinessType); + Assert.Equal("什么鬼", ((JT809_0x1600_0x1601)jT809Bodies.SubBodies).CarInfo); + Assert.Equal(2u, ((JT809_0x1600_0x1601)jT809Bodies.SubBodies).SourceMsgSn); + Assert.Equal(1, ((JT809_0x1600_0x1601)jT809Bodies.SubBodies).SourceDataType); + } } } diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9001Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9001Test.cs index ba5d819..3347cef 100644 --- a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9001Test.cs +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9001Test.cs @@ -6,12 +6,15 @@ using System; using System.Collections.Generic; using System.Text; using Xunit; +using JT809.Protocol.Internal; +using JT809.Protocol.Enums; namespace JT809.Protocol.Test.JT809MessageBody { public class JT809_0x9001Test { private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] public void Test1() { diff --git a/src/JT809.Protocol.Test/JT809Packages/JT809_0x1001EncryptPackageTest.cs b/src/JT809.Protocol.Test/JT809Packages/JT809_0x1001EncryptPackageTest.cs index 26c1ebd..5c546be 100644 --- a/src/JT809.Protocol.Test/JT809Packages/JT809_0x1001EncryptPackageTest.cs +++ b/src/JT809.Protocol.Test/JT809Packages/JT809_0x1001EncryptPackageTest.cs @@ -17,12 +17,15 @@ namespace JT809.Protocol.Test.JT809Packages { class JT809GlobalConfig: JT809GlobalConfigBase { - public override JT809EncryptOptions EncryptOptions { get; set; }= new JT809EncryptOptions() + public JT809GlobalConfig() { - IA1 = 20000000, - IC1 = 20000000, - M1 = 30000000 - }; + EncryptOptions = new JT809EncryptOptions() + { + IA1 = 20000000, + IC1 = 20000000, + M1 = 30000000 + }; + } public override string ConfigId => "JT809GlobalConfig"; } private JT809Serializer JT809Serializer; diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1600_0x1601Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1600_0x1601Test.cs index 70470c8..fba5601 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1600_0x1601Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1600_0x1601Test.cs @@ -8,12 +8,15 @@ using JT809.Protocol.MessageBody; using JT809.Protocol.Exceptions; using JT809.Protocol.SubMessageBody; using JT809.Protocol.Enums; +using JT809.Protocol.Internal; namespace JT809.Protocol.Test.JT809SubMessageBody { public class JT809_0x1600_0x1601Test { private JT809Serializer JT809Serializer = new JT809Serializer(); + private JT809Serializer JT809_2019_Serializer = new JT809Serializer(new DefaultGlobalConfig() { Version = JT809Version.JTT2019 }); + [Fact] public void Test1() { @@ -32,5 +35,29 @@ namespace JT809.Protocol.Test.JT809SubMessageBody JT809_0x1600_0x1601 jT809_0x1600_0x1601 = JT809Serializer.Deserialize(bytes); Assert.Equal("smallchi", jT809_0x1600_0x1601.CarInfo); } + + + [Fact] + public void Test_2019_1() + { + JT809_0x1600_0x1601 jT809_0x1600_0x1601 = new JT809_0x1600_0x1601 + { + SourceDataType=1, + SourceMsgSn=2, + CarInfo = "smallchi", + }; + var hex = JT809_2019_Serializer.Serialize(jT809_0x1600_0x1601).ToHexString(); + Assert.Equal("000100000002736D616C6C636869", hex); + } + + [Fact] + public void Test_2019_2() + { + var bytes = "000100000002736D616C6C636869".ToHexBytes(); + JT809_0x1600_0x1601 jT809_0x1600_0x1601 = JT809_2019_Serializer.Deserialize(bytes); + Assert.Equal("smallchi", jT809_0x1600_0x1601.CarInfo); + Assert.Equal(2u, jT809_0x1600_0x1601.SourceMsgSn); + Assert.Equal(1, jT809_0x1600_0x1601.SourceDataType); + } } } diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9207Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9207Test.cs index ddf4de4..ab94917 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9207Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9207Test.cs @@ -8,12 +8,14 @@ using JT809.Protocol.MessageBody; using JT809.Protocol.Exceptions; using JT809.Protocol.SubMessageBody; using JT809.Protocol.Enums; +using JT809.Protocol.Internal; namespace JT809.Protocol.Test.JT809SubMessageBody { public class JT809_0x9200_0x9207Test { private JT809Serializer JT809Serializer = new JT809Serializer(); + private JT809Serializer JT809_2019_Serializer = new JT809Serializer(new DefaultGlobalConfig() { Version = JT809Version.JTT2019 }); [Fact] public void Test1() { @@ -33,5 +35,27 @@ namespace JT809.Protocol.Test.JT809SubMessageBody Assert.Equal(JT809_0x9207_Result.申请成功, jT809_0X9200_0X9207.Result); } + [Fact] + public void Test_2019_1() + { + JT809_0x9200_0x9207 jT809_0X9200_0X9207 = new JT809_0x9200_0x9207 + { + SourceDataType= 1, + SourceMsgSn=2, + Result = JT809_0x9207_Result.申请成功 + }; + var hex = JT809_2019_Serializer.Serialize(jT809_0X9200_0X9207).ToHexString(); + Assert.Equal("00010000000200", hex); + } + + [Fact] + public void Test_2019_2() + { + var bytes = "00010000000200".ToHexBytes(); + JT809_0x9200_0x9207 jT809_0X9200_0X9207 = JT809_2019_Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x9207_Result.申请成功, jT809_0X9200_0X9207.Result); + Assert.Equal(1, jT809_0X9200_0X9207.SourceDataType); + Assert.Equal(2u, jT809_0X9200_0X9207.SourceMsgSn); + } } } diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9208Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9208Test.cs index 275ef76..9f220f0 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9208Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9208Test.cs @@ -8,18 +8,20 @@ using JT809.Protocol.MessageBody; using JT809.Protocol.Exceptions; using JT809.Protocol.SubMessageBody; using JT809.Protocol.Enums; +using JT809.Protocol.Internal; namespace JT809.Protocol.Test.JT809SubMessageBody { public class JT809_0x9200_0x9208Test { private JT809Serializer JT809Serializer = new JT809Serializer(); + private JT809Serializer JT809_2019_Serializer = new JT809Serializer(new DefaultGlobalConfig() { Version = JT809Version.JTT2019 }); [Fact] public void Test1() { JT809_0x9200_0x9208 jT809_0X9200_0X9208 = new JT809_0x9200_0x9208 { - Result= JT809_0x9208_Result.其它 + Result= JT809_0x9208_Result.其它, }; var hex = JT809Serializer.Serialize(jT809_0X9200_0X9208).ToHexString(); Assert.Equal("02", hex); @@ -33,5 +35,27 @@ namespace JT809.Protocol.Test.JT809SubMessageBody Assert.Equal(JT809_0x9208_Result.其它, jT809_0X9200_0X9208.Result); } + [Fact] + public void Test_2019_1() + { + JT809_0x9200_0x9208 jT809_0X9200_0X9208 = new JT809_0x9200_0x9208 + { + Result = JT809_0x9208_Result.其它, + SourceDataType=1, + SourceMsgSn=2 + }; + var hex = JT809_2019_Serializer.Serialize(jT809_0X9200_0X9208).ToHexString(); + Assert.Equal("00010000000202", hex); + } + + [Fact] + public void Test_2019_2() + { + var bytes = "00010000000202".ToHexBytes(); + JT809_0x9200_0x9208 jT809_0X9200_0X9208 = JT809_2019_Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x9208_Result.其它, jT809_0X9200_0X9208.Result); + Assert.Equal(1, jT809_0X9200_0X9208.SourceDataType); + Assert.Equal(2u, jT809_0X9200_0X9208.SourceMsgSn); + } } } diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9209Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9209Test.cs index 2b80a2d..568c4dd 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9209Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9209Test.cs @@ -8,12 +8,14 @@ using JT809.Protocol.MessageBody; using JT809.Protocol.Exceptions; using JT809.Protocol.SubMessageBody; using JT809.Protocol.Enums; +using JT809.Protocol.Internal; namespace JT809.Protocol.Test.JT809SubMessageBody { public class JT809_0x9200_0x9209Test { private JT809Serializer JT809Serializer = new JT809Serializer(); + private JT809Serializer JT809_2019_Serializer = new JT809Serializer(new DefaultGlobalConfig() { Version = JT809Version.JTT2019 }); [Fact] public void Test1() { @@ -32,6 +34,27 @@ namespace JT809.Protocol.Test.JT809SubMessageBody JT809_0x9200_0x9209 jT809_0X9200_0X9209 = JT809Serializer.Deserialize(bytes); Assert.Equal(JT809_0x9209_Result.成功_上级平台即刻补发, jT809_0X9200_0X9209.Result); } + [Fact] + public void Test_2019_1() + { + JT809_0x9200_0x9209 jT809_0X9200_0X9209 = new JT809_0x9200_0x9209 + { + Result = JT809_0x9209_Result.成功_上级平台即刻补发, + SourceDataType=22, + SourceMsgSn=33 + }; + var hex = JT809_2019_Serializer.Serialize(jT809_0X9200_0X9209).ToHexString(); + Assert.Equal("00160000002100", hex); + } + [Fact] + public void Test_2019_2() + { + var bytes = "00160000002100".ToHexBytes(); + JT809_0x9200_0x9209 jT809_0X9200_0X9209 = JT809_2019_Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x9209_Result.成功_上级平台即刻补发, jT809_0X9200_0X9209.Result); + Assert.Equal(22, jT809_0X9200_0X9209.SourceDataType); + Assert.Equal(33u, jT809_0X9200_0X9209.SourceMsgSn); + } } } diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9400_0x9402Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9400_0x9402Test.cs index 33b0144..a5e5137 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9400_0x9402Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9400_0x9402Test.cs @@ -8,12 +8,14 @@ using JT809.Protocol.MessageBody; using JT809.Protocol.Exceptions; using JT809.Protocol.SubMessageBody; using JT809.Protocol.Enums; +using JT809.Protocol.Internal; namespace JT809.Protocol.Test.JT809SubMessageBody { public class JT809_0x9400_0x9402Test { private JT809Serializer JT809Serializer = new JT809Serializer(); + private JT809Serializer JT809_2019_Serializer = new JT809Serializer(new DefaultGlobalConfig() { Version = JT809Version.JTT2019 }); [Fact] public void Test1() { @@ -39,5 +41,43 @@ namespace JT809.Protocol.Test.JT809SubMessageBody Assert.Equal("劫警", jT809_0x9400_0x9402.WarnContent); Assert.Equal((uint)4, jT809_0x9400_0x9402.WarnLength); } + + [Fact] + public void Test_2019_1() + { + JT809_0x9400_0x9402 jT809_0x9400_0x9402 = new JT809_0x9400_0x9402 + { + SourcePlatformId=new byte[11], + WarnType = JT809WarnType.劫警, + WarnTime = DateTime.Parse("2020-04-26 18:23:00"), + StartTime = DateTime.Parse("2020-04-26 18:23:00"), + EndTime = DateTime.Parse("2020-04-26 19:23:00"), + VehicleNo= "粤A12345", + VehicleColor= JT809VehicleColorType.蓝色, + DestinationPlatformId= new byte[11], + DRVLineId=22, + WarnContent = "劫警", + }; + var hex = JT809_2019_Serializer.Serialize(jT809_0x9400_0x9402).ToHexString(); + Assert.Equal("0000000000000000000000000A000000005EA56104000000005EA56104000000005EA56F14D4C1413132333435000000000000000000000000000100000000000000000000000000001600000004BDD9BEAF", hex); + } + + [Fact] + public void Test_2019_2() + { + var bytes = "0000000000000000000000000A000000005EA56104000000005EA56104000000005EA56F14D4C1413132333435000000000000000000000000000100000000000000000000000000001600000004BDD9BEAF".ToHexBytes(); + JT809_0x9400_0x9402 jT809_0x9400_0x9402 = JT809_2019_Serializer.Deserialize(bytes); + Assert.Equal(JT809WarnType.劫警, jT809_0x9400_0x9402.WarnType); + Assert.Equal(DateTime.Parse("2020-04-26 18:23:00"), jT809_0x9400_0x9402.WarnTime); + Assert.Equal(DateTime.Parse("2020-04-26 18:23:00"), jT809_0x9400_0x9402.StartTime); + Assert.Equal(DateTime.Parse("2020-04-26 19:23:00"), jT809_0x9400_0x9402.EndTime); + Assert.Equal(DateTime.Parse("2020-04-26 19:23:00"), jT809_0x9400_0x9402.EndTime); + Assert.Equal("粤A12345", jT809_0x9400_0x9402.VehicleNo); + Assert.Equal(JT809VehicleColorType.蓝色, jT809_0x9400_0x9402.VehicleColor); + Assert.Equal(new byte[11], jT809_0x9400_0x9402.DestinationPlatformId); + Assert.Equal(new byte[11], jT809_0x9400_0x9402.SourcePlatformId); + Assert.Equal(22u, jT809_0x9400_0x9402.DRVLineId); + Assert.Equal(4u, jT809_0x9400_0x9402.WarnLength); + } } } diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9400_0x9403Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9400_0x9403Test.cs index 3ac0179..48bcde0 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9400_0x9403Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9400_0x9403Test.cs @@ -8,12 +8,14 @@ using JT809.Protocol.MessageBody; using JT809.Protocol.Exceptions; using JT809.Protocol.SubMessageBody; using JT809.Protocol.Enums; +using JT809.Protocol.Internal; namespace JT809.Protocol.Test.JT809SubMessageBody { public class JT809_0x9400_0x9403Test { private JT809Serializer JT809Serializer = new JT809Serializer(); + private JT809Serializer JT809_2019_Serializer = new JT809Serializer(new DefaultGlobalConfig() { Version = JT809Version.JTT2019 }); [Fact] public void Test1() { @@ -39,5 +41,39 @@ namespace JT809.Protocol.Test.JT809SubMessageBody Assert.Equal("疲劳驾驶报警", jT809_0x9400_0x9403.WarnContent); Assert.Equal((uint)12, jT809_0x9400_0x9403.WarnLength); } + + [Fact] + public void Test_2019_1() + { + JT809_0x9400_0x9403 jT809_0x9400_0x9403 = new JT809_0x9400_0x9403 + { + SourcePlatformId=new byte[11], + WarnType = JT809WarnType.疲劳驾驶报警, + WarnTime = DateTime.Parse("2020-04-26 18:24:00"), + StartTime = DateTime.Parse("2020-04-26 18:24:00"), + EndTime = DateTime.Parse("2020-04-26 19:24:00"), + VehicleNo = "粤A5647", + VehicleColor = JT809VehicleColorType.黄色, + DestinationPlatformId = new byte[11], + WarnContent = "疲劳驾驶报警", + }; + var hex = JT809_2019_Serializer.Serialize(jT809_0x9400_0x9403).ToHexString(); + Assert.Equal("00000000000000000000000002000000005EA56140000000005EA56140000000005EA56F50D4C141353634370000000000000000000000000000020000000000000000000000000000000000000CC6A3C0CDBCDDCABBB1A8BEAF", hex); + } + + [Fact] + public void Test_2019_2() + { + var bytes = "00000000000000000000000002000000005EA56140000000005EA56140000000005EA56F50D4C141353634370000000000000000000000000000020000000000000000000000000000000000000CC6A3C0CDBCDDCABBB1A8BEAF".ToHexBytes(); + JT809_0x9400_0x9403 jT809_0x9400_0x9403 = JT809_2019_Serializer.Deserialize(bytes); + Assert.Equal(JT809WarnType.疲劳驾驶报警, jT809_0x9400_0x9403.WarnType); + Assert.Equal(DateTime.Parse("2020-04-26 18:24:00"), jT809_0x9400_0x9403.WarnTime); + Assert.Equal(DateTime.Parse("2020-04-26 18:24:00"), jT809_0x9400_0x9403.StartTime); + Assert.Equal(DateTime.Parse("2020-04-26 19:24:00"), jT809_0x9400_0x9403.EndTime); + Assert.Equal("疲劳驾驶报警", jT809_0x9400_0x9403.WarnContent); + Assert.Equal((uint)12, jT809_0x9400_0x9403.WarnLength); + Assert.Equal(new byte[11], jT809_0x9400_0x9403.DestinationPlatformId); + Assert.Equal(new byte[11], jT809_0x9400_0x9403.SourcePlatformId); + } } } diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9501Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9501Test.cs index f1a7eb1..30cfa10 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9501Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9501Test.cs @@ -7,12 +7,15 @@ using JT809.Protocol.Extensions; using JT809.Protocol.MessageBody; using JT809.Protocol.Exceptions; using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Internal; +using JT809.Protocol.Enums; namespace JT809.Protocol.Test.JT809SubMessageBody { public class JT809_0x9500_0x9501Test { private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] public void Test1() { diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9504Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9504Test.cs index a0d6765..a9adb85 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9504Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9504Test.cs @@ -8,12 +8,14 @@ using JT809.Protocol.MessageBody; using JT809.Protocol.Exceptions; using JT809.Protocol.SubMessageBody; using JT809.Protocol.Enums; +using JT809.Protocol.Internal; namespace JT809.Protocol.Test.JT809SubMessageBody { public class JT809_0x9500_0x9504Test { private JT809Serializer JT809Serializer = new JT809Serializer(); + private JT809Serializer JT809_2019_Serializer = new JT809Serializer(new DefaultGlobalConfig() { Version = JT809Version.JTT2019 }); [Fact] public void Test1() { @@ -41,5 +43,28 @@ namespace JT809.Protocol.Test.JT809SubMessageBody Assert.Equal(DateTime.Parse("2018-09-27 23:00:20"), jT809_0X9500_0X9504.EndTime); //Assert.Equal(5556, jT809_0X9500_0X9504.Max); } + + [Fact] + public void Test_2019_1() + { + JT809_0x9500_0x9504 jT809_0X9500_0X9504 = new JT809_0x9500_0x9504 + { + Command = JT809CommandType.采集记录仪事故疑点记录, + StartTime = DateTime.Parse("2020-04-26 20:00:20"), + EndTime = DateTime.Parse("2020-04-26 23:00:20") + }; + var hex = JT809Serializer.Serialize(jT809_0X9500_0X9504).ToHexString(); + Assert.Equal("102004262000202004262300200000", hex); + } + + [Fact] + public void Test_2019_2() + { + var bytes = "102004262000202004262300200000".ToHexBytes(); + JT809_0x9500_0x9504 jT809_0X9500_0X9504 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809CommandType.采集记录仪事故疑点记录, jT809_0X9500_0X9504.Command); + Assert.Equal(DateTime.Parse("2020-04-26 20:00:20"), jT809_0X9500_0X9504.StartTime); + Assert.Equal(DateTime.Parse("2020-04-26 23:00:20"), jT809_0X9500_0X9504.EndTime); + } } } diff --git a/src/JT809.Protocol.Test/Simples/Demo2.cs b/src/JT809.Protocol.Test/Simples/Demo2.cs index 6eda842..436b8c2 100644 --- a/src/JT809.Protocol.Test/Simples/Demo2.cs +++ b/src/JT809.Protocol.Test/Simples/Demo2.cs @@ -10,13 +10,16 @@ namespace JT809.Protocol.Test.Simples { class JT809GlobalConfig : JT809GlobalConfigBase { - public override JT809EncryptOptions EncryptOptions { get; set; } = new JT809EncryptOptions() + public JT809GlobalConfig() { - IA1 = 20000000, - IC1 = 20000000, - M1 = 30000000 - }; - public override string ConfigId => "JT809GlobalConfig"; + EncryptOptions = new JT809EncryptOptions() + { + IA1 = 20000000, + IC1 = 20000000, + M1 = 30000000 + }; + } + public override string ConfigId { get; }= "JT809GlobalConfig"; } JT809Serializer JT809Serializer = new JT809Serializer(new JT809GlobalConfig()); diff --git a/src/JT809.Protocol.Test/Simples/Demo3.cs b/src/JT809.Protocol.Test/Simples/Demo3.cs index 29322a5..312e52d 100644 --- a/src/JT809.Protocol.Test/Simples/Demo3.cs +++ b/src/JT809.Protocol.Test/Simples/Demo3.cs @@ -55,6 +55,7 @@ namespace JT809.Protocol.Test.Simples var hex = JT809Serializer.Serialize(jT809Package).ToHexString(); //5B000000C1000006821700013415F4010000000000270FD4C1413132333435000000000000000000000000000217010000008B01020304050607080910110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000B22E5D + //5B000000C1000006821700013415F4010000000000270FD4C1413132333435000000000000000000000000000217010000008B01020304050607080910110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000B22E5D Assert.Equal("5B000000C1000006821700013415F4010000000000270FD4C1413132333435000000000000000000000000000217010000008B01020304050607080910110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000B22E5D", hex); } diff --git a/src/JT809.Protocol.Test/Simples/Demo4.cs b/src/JT809.Protocol.Test/Simples/Demo4.cs new file mode 100644 index 0000000..095f310 --- /dev/null +++ b/src/JT809.Protocol.Test/Simples/Demo4.cs @@ -0,0 +1,106 @@ +using Microsoft.Extensions.DependencyInjection; +using System; +using JT809.Protocol.Test.JT1078; +using JT809.Protocol.Extensions; +using Xunit; +using JT809.Protocol.Enums; +using JT809.Protocol.Interfaces; + +namespace JT809.Protocol.Test.Simples +{ + public class Demo4 + { + IServiceProvider ServiceProvider; + JT809Serializer JT809_2019_Serializer; + IJT809Config JT809_2011_Config; + IJT809Config JT809_2019_Config; + + public Demo4() + { + IServiceCollection serviceDescriptors = new ServiceCollection(); + serviceDescriptors.AddJT809Configure(new JT809_2011_Config()) + .AddJT1078Configure(); + serviceDescriptors.AddJT809Configure(new JT809_2019_Config()) + .AddJT1078Configure(); + ServiceProvider = serviceDescriptors.BuildServiceProvider(); + JT809_2011_Config = ServiceProvider.GetRequiredService(); + JT809_2019_Config = ServiceProvider.GetRequiredService(); + JT809_2019_Serializer = JT809_2019_Config.GetSerializer(); + } + + [Fact] + public void Test1() + { + JT809Package jT809Package = new JT809Package(); + jT809Package.Header = new JT809Header + { + MsgSN = 1666, + EncryptKey = 9999, + EncryptFlag = JT809Header_Encrypt.None, + Version = new JT809Header_Version(1, 0, 0), + BusinessType = JT809_JT1078_BusinessType.主链路时效口令业务类.ToUInt16Value(), + MsgGNSSCENTERID = 20190708, + Time=DateTime.Parse("2020-04-26 12:02:00") + }; + JT808_JT1078_0x1700 bodies = new JT808_JT1078_0x1700 + { + VehicleNo = "粤A12345", + VehicleColor = JT809VehicleColorType.黄色, + SubBusinessType = JT809_JT1078_SubBusinessType.时效口令上报消息.ToUInt16Value(), + }; + JT808_JT1078_0x1700_0x1701 jT808_JT1078_0x1700_0x1701 = new JT808_JT1078_0x1700_0x1701 + { + PlateFormId = new byte[11] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11 }, + AuthorizeCode1 = new byte[64], + AuthorizeCode2 = new byte[64] + }; + bodies.SubBodies = jT808_JT1078_0x1700_0x1701; + jT809Package.Bodies = bodies; + var hex = JT809_2019_Serializer.Serialize(jT809Package).ToHexString(); + Assert.Equal("5B000000C9000006821700013415F4010000000000270F000000005E02A507B8D4C1413132333435000000000000000000000000000217010000008B01020304050607080910110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E7D35D", hex); + } + + [Fact] + public void Test2() + { + var data = "5B000000C9000006821700013415F4010000000000270F000000005E02A507B8D4C1413132333435000000000000000000000000000217010000008B01020304050607080910110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E7D35D".ToHexBytes(); + JT809Package jT809Package = JT809_2019_Serializer.Deserialize(data); + Assert.Equal((uint)1666, jT809Package.Header.MsgSN); + Assert.Equal((uint)9999, jT809Package.Header.EncryptKey); + Assert.Equal(JT809Header_Encrypt.None, jT809Package.Header.EncryptFlag); + Assert.Equal(new JT809Header_Version(1, 0, 0).ToString(), jT809Package.Header.Version.ToString()); + Assert.Equal(DateTime.Parse("2020-04-26 12:02:00"), jT809Package.Header.Time); + Assert.Equal(0x1700, jT809Package.Header.BusinessType); + Assert.Equal((uint)20190708, jT809Package.Header.MsgGNSSCENTERID); + JT809ExchangeMessageBodies bodies = jT809Package.Bodies as JT809ExchangeMessageBodies; + JT808_JT1078_0x1700_0x1701 subBodies = bodies.SubBodies as JT808_JT1078_0x1700_0x1701; + Assert.Equal(new byte[11] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11 }, subBodies.PlateFormId); + Assert.Equal(new byte[64], subBodies.AuthorizeCode1); + Assert.Equal(new byte[64], subBodies.AuthorizeCode2); + } + + [Fact] + public void Test3() + { + Assert.Equal("JT809_2011", JT809_2011_Config.ConfigId); + Assert.Equal(JT809Version.JTT2011, JT809_2011_Config.Version); + Assert.Equal("JT809_2019", JT809_2019_Config.ConfigId); + Assert.Equal(JT809Version.JTT2019, JT809_2019_Config.Version); + } + } + + public class JT809_2011_Config: JT809GlobalConfigBase + { + public override string ConfigId => "JT809_2011"; + } + + public class JT809_2019_Config : JT809GlobalConfigBase + { + public override string ConfigId => "JT809_2019"; + + public JT809_2019_Config() + { + Version = JT809Version.JTT2019; + } + } +} diff --git a/src/JT809.Protocol/Enums/JT809Version.cs b/src/JT809.Protocol/Enums/JT809Version.cs index 577bdc8..296bab7 100644 --- a/src/JT809.Protocol/Enums/JT809Version.cs +++ b/src/JT809.Protocol/Enums/JT809Version.cs @@ -6,7 +6,7 @@ namespace JT809.Protocol.Enums { public enum JT809Version:byte { - JTT2013=1, + JTT2011=1, JTT2019=2, } } diff --git a/src/JT809.Protocol/Interfaces/JT809GlobalConfigBase.cs b/src/JT809.Protocol/Interfaces/JT809GlobalConfigBase.cs index 9fd98f0..6af841e 100644 --- a/src/JT809.Protocol/Interfaces/JT809GlobalConfigBase.cs +++ b/src/JT809.Protocol/Interfaces/JT809GlobalConfigBase.cs @@ -12,7 +12,7 @@ namespace JT809.Protocol.Interfaces { public abstract class JT809GlobalConfigBase : IJT809Config { - protected JT809GlobalConfigBase(JT809Version version= JT809Version.JTT2013) + protected JT809GlobalConfigBase(JT809Version version= JT809Version.JTT2011) { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); Encoding = Encoding.GetEncoding("GBK"); @@ -22,12 +22,12 @@ namespace JT809.Protocol.Interfaces Version = version; } public abstract string ConfigId { get; } - public virtual IJT809MsgSNDistributed MsgSNDistributed { get; set; }= new DefaultMsgSNDistributedImpl(); - public virtual Encoding Encoding { get; set; } - public virtual bool SkipCRCCode { get; set; } = false; - public virtual IJT809Encrypt Encrypt { get; set; } = new JT809EncryptImpl(); - public virtual JT809EncryptOptions EncryptOptions { get; set; } - public virtual JT809HeaderOptions HeaderOptions { get; set; } + public IJT809MsgSNDistributed MsgSNDistributed { get; set; }= new DefaultMsgSNDistributedImpl(); + public Encoding Encoding { get; set; } + public bool SkipCRCCode { get; set; } = false; + public IJT809Encrypt Encrypt { get; set; } = new JT809EncryptImpl(); + public JT809EncryptOptions EncryptOptions { get; set; } + public JT809HeaderOptions HeaderOptions { get; set; } public IJT809BusinessTypeFactory BusinessTypeFactory { get ; set ; } public IJT809SubBusinessTypeFactory SubBusinessTypeFactory { get; set ; } public IJT809FormatterFactory FormatterFactory { get; set; } diff --git a/src/JT809.Protocol/JT809Bodies.cs b/src/JT809.Protocol/JT809Bodies.cs index 1f0dc63..c321621 100644 --- a/src/JT809.Protocol/JT809Bodies.cs +++ b/src/JT809.Protocol/JT809Bodies.cs @@ -11,7 +11,7 @@ namespace JT809.Protocol /// 当数据体为空的时候,使用null作为空包感觉不适合,所以就算使用空包也需要new一下来表达意思。 /// public virtual bool SkipSerialization { get; set; } = false; - public virtual JT809Version Version => JT809Version.JTT2013; + public virtual JT809Version Version => JT809Version.JTT2011; public abstract ushort MsgId { get; } public abstract JT809_LinkType LinkType { get; } public abstract string Description { get; } diff --git a/src/JT809.Protocol/JT809DependencyInjectionExtensions.cs b/src/JT809.Protocol/JT809DependencyInjectionExtensions.cs index e44020f..91b0ae1 100644 --- a/src/JT809.Protocol/JT809DependencyInjectionExtensions.cs +++ b/src/JT809.Protocol/JT809DependencyInjectionExtensions.cs @@ -1,4 +1,5 @@ -using JT809.Protocol.Interfaces; +using JT809.Protocol.Enums; +using JT809.Protocol.Interfaces; using JT809.Protocol.Internal; using Microsoft.Extensions.DependencyInjection; using System; @@ -16,9 +17,10 @@ namespace JT809.Protocol return new DefaultBuilder(services, jT809Config); } - public static IJT809Builder AddJT809Configure(this IServiceCollection services) + public static IJT809Builder AddJT809Configure(this IServiceCollection services, JT809Version version= JT809Version.JTT2011) { DefaultGlobalConfig config = new DefaultGlobalConfig(); + config.Version = version; services.AddSingleton(config); return new DefaultBuilder(services, config); } diff --git a/src/JT809.Protocol/JT809Header.cs b/src/JT809.Protocol/JT809Header.cs index d2e9e65..d391121 100644 --- a/src/JT809.Protocol/JT809Header.cs +++ b/src/JT809.Protocol/JT809Header.cs @@ -70,7 +70,7 @@ namespace JT809.Protocol jT809Header.EncryptKey = reader.ReadUInt32(); if(config.Version== JT809Version.JTT2019) { - Time = reader.ReadUTCDateTime(); + jT809Header.Time = reader.ReadUTCDateTime(); } return jT809Header; } diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1400.cs b/src/JT809.Protocol/MessageBody/JT809_0x1400.cs index b6aec0a..4af443f 100644 --- a/src/JT809.Protocol/MessageBody/JT809_0x1400.cs +++ b/src/JT809.Protocol/MessageBody/JT809_0x1400.cs @@ -24,7 +24,7 @@ namespace JT809.Protocol.MessageBody public JT809_0x1400 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { JT809_0x1400 value = new JT809_0x1400(); - if (config.Version == JT809Version.JTT2013) + if (config.Version == JT809Version.JTT2011) { value.VehicleNo = reader.ReadString(21); value.VehicleColor = (JT809VehicleColorType)reader.ReadByte(); @@ -55,7 +55,7 @@ namespace JT809.Protocol.MessageBody public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1400 value, IJT809Config config) { - if (config.Version == JT809Version.JTT2013) + if (config.Version == JT809Version.JTT2011) { writer.WriteStringPadRight(value.VehicleNo, 21); writer.WriteByte((byte)value.VehicleColor); diff --git a/src/JT809.Protocol/MessageBody/JT809_0x9400.cs b/src/JT809.Protocol/MessageBody/JT809_0x9400.cs index c0e9b08..8b07df2 100644 --- a/src/JT809.Protocol/MessageBody/JT809_0x9400.cs +++ b/src/JT809.Protocol/MessageBody/JT809_0x9400.cs @@ -23,7 +23,7 @@ namespace JT809.Protocol.MessageBody public JT809_0x9400 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { JT809_0x9400 value = new JT809_0x9400(); - if (config.Version == JT809Version.JTT2013) + if (config.Version == JT809Version.JTT2011) { value.VehicleNo = reader.ReadString(21); value.VehicleColor = (JT809VehicleColorType)reader.ReadByte(); @@ -54,7 +54,7 @@ namespace JT809.Protocol.MessageBody public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9400 value, IJT809Config config) { - if (config.Version == JT809Version.JTT2013) + if (config.Version == JT809Version.JTT2011) { writer.WriteStringPadRight(value.VehicleNo, 21); writer.WriteByte((byte)value.VehicleColor); diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1201.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1201.cs index 8a75e8f..a67e0ba 100644 --- a/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1201.cs +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1201.cs @@ -47,7 +47,7 @@ namespace JT809.Protocol.SubMessageBody public JT809_0x1200_0x1201 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { JT809_0x1200_0x1201 value = new JT809_0x1200_0x1201(); - if(config.Version== JT809Version.JTT2013) + if(config.Version== JT809Version.JTT2011) { value.PlateformId = reader.ReadBigNumber(11); value.ProducerId = reader.ReadBigNumber(11); @@ -71,7 +71,7 @@ namespace JT809.Protocol.SubMessageBody public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1200_0x1201 value, IJT809Config config) { - if(config.Version== JT809Version.JTT2013) + if(config.Version== JT809Version.JTT2011) { writer.WriteBigNumber(value.PlateformId, 11); writer.WriteBigNumber(value.ProducerId, 11); diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1202.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1202.cs index 0016c9f..2f76fdc 100644 --- a/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1202.cs +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1202.cs @@ -30,7 +30,7 @@ namespace JT809.Protocol.SubMessageBody public JT809_0x1200_0x1202 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { JT809_0x1200_0x1202 value = new JT809_0x1200_0x1202(); - if (config.Version == JT809Version.JTT2013) + if (config.Version == JT809Version.JTT2011) { value.VehiclePosition.Encrypt = (JT809_VehiclePositionEncrypt)reader.ReadByte(); value.VehiclePosition.Day = reader.ReadByte(); @@ -58,7 +58,7 @@ namespace JT809.Protocol.SubMessageBody public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1200_0x1202 value, IJT809Config config) { - if (config.Version == JT809Version.JTT2013) + if (config.Version == JT809Version.JTT2011) { writer.WriteByte((byte)value.VehiclePosition.Encrypt); writer.WriteByte(value.VehiclePosition.Day); diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1300_0x1301.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1300_0x1301.cs index 339e299..a83a466 100644 --- a/src/JT809.Protocol/SubMessageBody/JT809_0x1300_0x1301.cs +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1300_0x1301.cs @@ -58,7 +58,7 @@ namespace JT809.Protocol.SubMessageBody { var value = new JT809_0x1300_0x1301(); value.ObjectType = (JT809_0x1301_ObjectType)reader.ReadByte(); - if (config.Version == JT809Version.JTT2013) + if (config.Version == JT809Version.JTT2011) { value.ObjectID = reader.ReadString(12); value.InfoID = reader.ReadUInt32(); @@ -78,7 +78,7 @@ namespace JT809.Protocol.SubMessageBody public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1300_0x1301 value, IJT809Config config) { writer.WriteByte((byte)value.ObjectType); - if (config.Version == JT809Version.JTT2013) + if (config.Version == JT809Version.JTT2011) { writer.WriteStringPadRight(value.ObjectID, 12); writer.WriteUInt32(value.InfoID); diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1400_0x1402.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1400_0x1402.cs index 6471feb..85438b3 100644 --- a/src/JT809.Protocol/SubMessageBody/JT809_0x1400_0x1402.cs +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1400_0x1402.cs @@ -73,7 +73,7 @@ namespace JT809.Protocol.SubMessageBody public JT809_0x1400_0x1402 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { var value = new JT809_0x1400_0x1402(); - if (config.Version == JT809Version.JTT2013) + if (config.Version == JT809Version.JTT2011) { value.WarnSrc = (JT809WarnSrc)reader.ReadByte(); } @@ -83,7 +83,7 @@ namespace JT809.Protocol.SubMessageBody } value.WarnType = (JT809WarnType)reader.ReadUInt16(); value.WarnTime = reader.ReadUTCDateTime(); - if (config.Version == JT809Version.JTT2013) + if (config.Version == JT809Version.JTT2011) { value.InfoID = reader.ReadUInt32(); } @@ -104,7 +104,7 @@ namespace JT809.Protocol.SubMessageBody public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1400_0x1402 value, IJT809Config config) { - if (config.Version == JT809Version.JTT2013) + if (config.Version == JT809Version.JTT2011) { writer.WriteByte((byte)value.WarnSrc); } @@ -114,7 +114,7 @@ namespace JT809.Protocol.SubMessageBody } writer.WriteUInt16((ushort)value.WarnType); writer.WriteUTCDateTime(value.WarnTime); - if (config.Version == JT809Version.JTT2013) + if (config.Version == JT809Version.JTT2011) { writer.WriteUInt32(value.InfoID); } diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1400_0x1403.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1400_0x1403.cs index c328c72..5c83466 100644 --- a/src/JT809.Protocol/SubMessageBody/JT809_0x1400_0x1403.cs +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1400_0x1403.cs @@ -76,7 +76,7 @@ namespace JT809.Protocol.SubMessageBody public JT809_0x1400_0x1403 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { var value = new JT809_0x1400_0x1403(); - if (config.Version == JT809Version.JTT2013) + if (config.Version == JT809Version.JTT2011) { value.InfoID = reader.ReadUInt32(); value.Result = (JT809_0x1403_Result)reader.ReadByte(); @@ -101,7 +101,7 @@ namespace JT809.Protocol.SubMessageBody public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1400_0x1403 value, IJT809Config config) { - if (config.Version == JT809Version.JTT2013) + if (config.Version == JT809Version.JTT2011) { writer.WriteUInt32(value.InfoID); writer.WriteByte((byte)value.Result); diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9202.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9202.cs index 440b969..17f9132 100644 --- a/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9202.cs +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9202.cs @@ -27,7 +27,7 @@ namespace JT809.Protocol.SubMessageBody public JT809_0x9200_0x9202 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { JT809_0x9200_0x9202 jT809_0X1200_0x9202 = new JT809_0x9200_0x9202(); - if (config.Version == JT809Version.JTT2013) + if (config.Version == JT809Version.JTT2011) { jT809_0X1200_0x9202.VehiclePosition = new JT809VehiclePositionProperties(); jT809_0X1200_0x9202.VehiclePosition.Encrypt = (JT809_VehiclePositionEncrypt)reader.ReadByte(); @@ -65,7 +65,7 @@ namespace JT809.Protocol.SubMessageBody public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9200_0x9202 value, IJT809Config config) { - if (config.Version == JT809Version.JTT2013) + if (config.Version == JT809Version.JTT2011) { writer.WriteByte((byte)value.VehiclePosition.Encrypt); writer.WriteByte(value.VehiclePosition.Day); diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9400_0x9402.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9400_0x9402.cs index d65514c..4fb3cfe 100644 --- a/src/JT809.Protocol/SubMessageBody/JT809_0x9400_0x9402.cs +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9400_0x9402.cs @@ -71,11 +71,12 @@ namespace JT809.Protocol.SubMessageBody public JT809_0x9400_0x9402 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { var value = new JT809_0x9400_0x9402(); - if (config.Version == JT809Version.JTT2013) + if (config.Version == JT809Version.JTT2011) { value.WarnSrc = (JT809WarnSrc)reader.ReadByte(); } - else { + else + { value.SourcePlatformId = reader.ReadArray(11).ToArray(); } value.WarnType = (JT809WarnType)reader.ReadUInt16(); @@ -96,11 +97,12 @@ namespace JT809.Protocol.SubMessageBody public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9400_0x9402 value, IJT809Config config) { - if (config.Version == JT809Version.JTT2013) + if (config.Version == JT809Version.JTT2011) { writer.WriteByte((byte)value.WarnSrc); } - else { + else + { writer.WriteArray(value.SourcePlatformId); } writer.WriteUInt16((ushort)value.WarnType); diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9400_0x9403.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9400_0x9403.cs index a936711..af75255 100644 --- a/src/JT809.Protocol/SubMessageBody/JT809_0x9400_0x9403.cs +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9400_0x9403.cs @@ -69,7 +69,7 @@ namespace JT809.Protocol.SubMessageBody public JT809_0x9400_0x9403 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { var value = new JT809_0x9400_0x9403(); - if (config.Version == JT809Version.JTT2013) + if (config.Version == JT809Version.JTT2011) { value.WarnSrc = (JT809WarnSrc)reader.ReadByte(); } @@ -96,7 +96,7 @@ namespace JT809.Protocol.SubMessageBody public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9400_0x9403 value, IJT809Config config) { - if (config.Version == JT809Version.JTT2013) + if (config.Version == JT809Version.JTT2011) { writer.WriteByte((byte)value.WarnSrc); } diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9500_0x9504.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9500_0x9504.cs index baefd01..cd8bd18 100644 --- a/src/JT809.Protocol/SubMessageBody/JT809_0x9500_0x9504.cs +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9500_0x9504.cs @@ -37,12 +37,14 @@ namespace JT809.Protocol.SubMessageBody public JT809_0x9500_0x9504 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { var value = new JT809_0x9500_0x9504(); - if(config.Version == JT809Version.JTT2019){ + if(config.Version == JT809Version.JTT2019) + { value.StartTime = reader.ReadUTCDateTime(); value.EndTime = reader.ReadUTCDateTime(); value.Command = (JT809CommandType)reader.ReadByte(); } - else { + else + { value.Command = (JT809CommandType)reader.ReadByte(); switch (value.Command) { @@ -80,7 +82,8 @@ namespace JT809.Protocol.SubMessageBody writer.WriteUTCDateTime(value.EndTime); writer.WriteByte((byte)value.Command); } - else { + else + { writer.WriteByte((byte)value.Command); switch (value.Command) {