From e81d4b46363769112c9aaae6ae977f6c8441abb2 Mon Sep 17 00:00:00 2001 From: SmallChi <564952747@qq.com> Date: Sat, 3 Nov 2018 23:08:11 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E5=A4=8DBCD=E6=89=A9=E5=B1=95bug=20?= =?UTF-8?q?2.=E4=BF=AE=E6=94=B9=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/JT809.Protocol.Test/JT809HeaderTest.cs | 2 ++ .../JT809MessageBody/JT809_0x1001Test.cs | 1 + .../JT809MessageBody/JT809_0x1002Test.cs | 1 + .../JT809MessageBody/JT809_0x1003Test.cs | 1 + .../JT809MessageBody/JT809_0x1007Test.cs | 1 + .../JT809MessageBody/JT809_0x1008Test.cs | 1 + .../JT809MessageBody/JT809_0x1200Test.cs | 1 + .../JT809MessageBody/JT809_0x1300Test.cs | 1 + .../JT809MessageBody/JT809_0x1600Test.cs | 1 + .../JT809MessageBody/JT809_0x9001Test.cs | 1 + .../JT809MessageBody/JT809_0x9002Test.cs | 1 + .../JT809MessageBody/JT809_0x9003Test.cs | 1 + .../JT809MessageBody/JT809_0x9007Test.cs | 1 + .../JT809MessageBody/JT809_0x9008Test.cs | 1 + .../JT809MessageBody/JT809_0x9101Test.cs | 1 + .../JT809_0x1001EncryptPackageTest.cs | 1 + .../JT809Packages/JT809_0x1001PackageTest.cs | 2 ++ .../JT809_0x9400_0x9401PackageTest.cs | 2 ++ .../JT809_0x1200_0x1201Test.cs | 1 + .../JT809_0x1200_0x1202Test.cs | 1 + .../JT809_0x1200_0x1203Test.cs | 1 + .../JT809_0x1200_0x1207Test.cs | 1 + .../JT809_0x1200_0x1209Test.cs | 1 + .../JT809_0x1200_0x120ATest.cs | 1 + .../JT809_0x1200_0x120BTest.cs | 1 + .../JT809_0x1300_0x1301Test.cs | 1 + .../JT809_0x1400_0x1402Test.cs | 1 + .../JT809_0x1400_0x1403Test.cs | 1 + .../JT809_0x1500_0x1502Test.cs | 1 + .../JT809_0x1500_0x1504Test.cs | 1 + .../JT809_0x9300_0x9301Test.cs | 1 + .../JT809_0x9400_0x9401Test.cs | 1 + .../JT809_0x9500_0x9504Test.cs | 2 +- .../JT809_0x9500_0x9505Test.cs | 3 ++- .../JT809Extensions/JT809BCDExtensions.cs | 22 +++++++++++-------- .../JT809_0x9500_0x9505Formatter.cs | 2 +- 36 files changed, 52 insertions(+), 12 deletions(-) diff --git a/src/JT809.Protocol.Test/JT809HeaderTest.cs b/src/JT809.Protocol.Test/JT809HeaderTest.cs index e5b943c..a26a4cd 100644 --- a/src/JT809.Protocol.Test/JT809HeaderTest.cs +++ b/src/JT809.Protocol.Test/JT809HeaderTest.cs @@ -23,6 +23,7 @@ namespace JT809.Protocol.Test jT809Header.EncryptFlag = JT809Header_Encrypt.None; jT809Header.EncryptKey = 0; var hex = JT809Serializer.Serialize(jT809Header).ToHexString(); + Assert.Equal("00000018000004009600000004B00100000000000000", hex); //"00 00 00 18 00 00 04 00 96 00 00 00 04 B0 01 00 00 00 00 00 00 00" } @@ -66,6 +67,7 @@ namespace JT809.Protocol.Test jT809Header.EncryptFlag = JT809Header_Encrypt.None; jT809Header.EncryptKey = 0; var hex = JT809Serializer.Serialize(jT809Header).ToHexString(); + Assert.Equal("00000018000004009600000004B0FFAABB0000000000", hex); } } } diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1001Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1001Test.cs index 2f1faf3..82217ec 100644 --- a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1001Test.cs +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1001Test.cs @@ -20,6 +20,7 @@ namespace JT809.Protocol.Test.JT809MessageBody jT809_0X1001.DownLinkIP = "127.0.0.1"; jT809_0X1001.DownLinkPort = 809; var hex = JT809Serializer.Serialize(jT809_0X1001).ToHexString(); + Assert.Equal("0133EFB832303138303932303132372E302E302E3100000000000000000000000000000000000000000000000329", hex); //5B //00 00 00 48 //00 00 00 85 diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1002Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1002Test.cs index f98825a..5f3b775 100644 --- a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1002Test.cs +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1002Test.cs @@ -19,6 +19,7 @@ namespace JT809.Protocol.Test.JT809MessageBody jT809_0X1002.VerifyCode = 54456; var hex = JT809Serializer.Serialize(jT809_0X1002).ToHexString(); //"00 00 00 D4 B8" + Assert.Equal("000000D4B8", hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1003Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1003Test.cs index c5921e9..8053eb4 100644 --- a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1003Test.cs +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1003Test.cs @@ -19,6 +19,7 @@ namespace JT809.Protocol.Test.JT809MessageBody jT809_0X1003.Password = "20180920"; var hex = JT809Serializer.Serialize(jT809_0X1003).ToHexString(); //"01 33 EF B8 32 30 31 38 30 39 32 30" + Assert.Equal("0133EFB83230313830393230", hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1007Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1007Test.cs index d77d93f..a16f14e 100644 --- a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1007Test.cs +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1007Test.cs @@ -17,6 +17,7 @@ namespace JT809.Protocol.Test.JT809MessageBody JT809_0x1007 jT809_0X1007 = new JT809_0x1007(); jT809_0X1007.ErrorCode = JT809Enums.JT809_0x1007_ErrorCode.主链路断开; var hex = JT809Serializer.Serialize(jT809_0X1007).ToHexString(); + Assert.Equal("00", hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1008Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1008Test.cs index ce6b7a6..6cf21da 100644 --- a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1008Test.cs +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1008Test.cs @@ -17,6 +17,7 @@ namespace JT809.Protocol.Test.JT809MessageBody JT809_0x1008 jT809_0X1008 = new JT809_0x1008(); jT809_0X1008.ReasonCode = JT809Enums.JT809_0x1008_ReasonCode.网关重启; var hex = JT809Serializer.Serialize(jT809_0X1008).ToHexString(); + Assert.Equal("00", hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1200Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1200Test.cs index 9b4ae67..aea5e7f 100644 --- a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1200Test.cs +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1200Test.cs @@ -30,6 +30,7 @@ namespace JT809.Protocol.Test.JT809MessageBody }; jT809_0X1200.SubBodies = jT809_0X1200_0X1201; var hex = JT809Serializer.Serialize(jT809_0X1200).ToHexString(); + Assert.Equal("D4C1413132333435000000000000000000000000000112010000003D00000000000000423A35C700000000000000423A35C7313131313131313100000000000000000000000031313131314141323232323232323232323232", hex); //"D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 01 12 01 00 00 00 3D 00 00 00 00 00 00 00 42 3A 35 C7 00 00 00 00 00 00 00 42 3A 35 C7 31 31 31 31 31 31 31 31 00 00 00 00 00 00 00 00 00 00 00 00 31 31 31 31 31 41 41 32 32 32 32 32 32 32 32 32 32 32 32" //"D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 01 12 01 00 00 00 3D 00 00 00 00 00 00 00 42 3A 35 C7 00 00 00 00 00 00 00 42 3A 35 C7 31 31 31 31 31 31 31 31 00 00 00 00 00 00 00 00 00 00 00 00 31 31 31 31 31 61 61 32 32 32 32 32 32 32 32 32 32 32 32" } diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1300Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1300Test.cs index aa06da0..b2a9558 100644 --- a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1300Test.cs +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1300Test.cs @@ -26,6 +26,7 @@ namespace JT809.Protocol.Test.JT809MessageBody }; var hex = JT809Serializer.Serialize(jT809Bodies).ToHexString(); //"13 01 00 00 00 1B 01 31 31 31 00 00 00 00 00 00 00 00 00 00 00 04 D2 00 00 00 06 32 32 68 61 32 32" + Assert.Equal("13010000001B01313131000000000000000000000004D200000006323268613232", hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1600Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1600Test.cs index 26a58ed..bb88c87 100644 --- a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1600Test.cs +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1600Test.cs @@ -25,6 +25,7 @@ namespace JT809.Protocol.Test.JT809MessageBody }; var hex = JT809Serializer.Serialize(jT809Bodies).ToHexString(); //"D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 01 16 01 00 00 00 06 CA B2 C3 B4 B9 ED" + Assert.Equal("D4C14131323334350000000000000000000000000001160100000006CAB2C3B4B9ED",hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9001Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9001Test.cs index 638cd2e..e1e2c5e 100644 --- a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9001Test.cs +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9001Test.cs @@ -17,6 +17,7 @@ namespace JT809.Protocol.Test.JT809MessageBody JT809_0x9001 jT809_0X9001 = new JT809_0x9001(); jT809_0X9001.VerifyCode = 45454; var hex = JT809Serializer.Serialize(jT809_0X9001).ToHexString(); + Assert.Equal("0000B18E", hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9002Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9002Test.cs index ca5753d..b503f40 100644 --- a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9002Test.cs +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9002Test.cs @@ -17,6 +17,7 @@ namespace JT809.Protocol.Test.JT809MessageBody JT809_0x9002 jT809_0X9002 = new JT809_0x9002(); jT809_0X9002.Result = JT809Enums.JT809_0x9002_Result.成功; var hex = JT809Serializer.Serialize(jT809_0X9002).ToHexString(); + Assert.Equal("00", hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9003Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9003Test.cs index e296e6f..f64ffa5 100644 --- a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9003Test.cs +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9003Test.cs @@ -17,6 +17,7 @@ namespace JT809.Protocol.Test.JT809MessageBody JT809_0x9003 jT809_0X9003 = new JT809_0x9003(); jT809_0X9003.VerifyCode = 45454; var hex = JT809Serializer.Serialize(jT809_0X9003).ToHexString(); + Assert.Equal("0000B18E",hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9007Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9007Test.cs index cede3b8..a218b7e 100644 --- a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9007Test.cs +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9007Test.cs @@ -17,6 +17,7 @@ namespace JT809.Protocol.Test.JT809MessageBody JT809_0x9007 jT809_0X9007 = new JT809_0x9007(); jT809_0X9007.ReasonCode = JT809Enums.JT809_0x9007_ReasonCode.无法连接下级平台指定的服务IP与端口; var hex = JT809Serializer.Serialize(jT809_0X9007).ToHexString(); + Assert.Equal("00", hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9008Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9008Test.cs index 40474b3..51d64fe 100644 --- a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9008Test.cs +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9008Test.cs @@ -17,6 +17,7 @@ namespace JT809.Protocol.Test.JT809MessageBody JT809_0x9008 jT809_0X9008 = new JT809_0x9008(); jT809_0X9008.ReasonCode = JT809Enums.JT809_0x9008_ReasonCode.其它原因; var hex = JT809Serializer.Serialize(jT809_0X9008).ToHexString(); + Assert.Equal("01", hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9101Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9101Test.cs index b6fe963..d238d59 100644 --- a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9101Test.cs +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9101Test.cs @@ -19,6 +19,7 @@ namespace JT809.Protocol.Test.JT809MessageBody jT809_0X9101.StartTime = 1537513862; jT809_0X9101.EndTime = 1537531862; var hex = JT809Serializer.Serialize(jT809_0X9101).ToHexString(); + Assert.Equal("00002710000000005BA49986000000005BA4DFD6",hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809Packages/JT809_0x1001EncryptPackageTest.cs b/src/JT809.Protocol.Test/JT809Packages/JT809_0x1001EncryptPackageTest.cs index fcb6447..8d66cea 100644 --- a/src/JT809.Protocol.Test/JT809Packages/JT809_0x1001EncryptPackageTest.cs +++ b/src/JT809.Protocol.Test/JT809Packages/JT809_0x1001EncryptPackageTest.cs @@ -41,6 +41,7 @@ namespace JT809.Protocol.Test.JT809Packages jT809Package.Bodies = jT809_0X1001; var hex = JT809Serializer.Serialize(jT809Package).ToHexString(); //"5B 00 00 00 48 00 00 00 85 10 01 01 33 EF B8 01 00 00 01 00 00 16 BB D3 7D 9C C4 90 0C 77 DC 78 F8 67 65 27 D8 AE 12 24 3C FB 64 CC 2F BA 61 9A EF AD 33 AC CB 32 56 F6 7B FF 19 DF 33 09 78 41 09 86 65 70 3F 2E B5 5D" + Assert.Equal("5B000000480000008510010133EFB8010000010003E8B2D37D9CC4900C77DC78F8676527D8AE12243CFB64CC2FBA619AEFAD33ACCB3256F67BFF19DF33097841098665703FE36E5D", hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809Packages/JT809_0x1001PackageTest.cs b/src/JT809.Protocol.Test/JT809Packages/JT809_0x1001PackageTest.cs index aa4a1e5..a5a88de 100644 --- a/src/JT809.Protocol.Test/JT809Packages/JT809_0x1001PackageTest.cs +++ b/src/JT809.Protocol.Test/JT809Packages/JT809_0x1001PackageTest.cs @@ -28,6 +28,7 @@ namespace JT809.Protocol.Test.JT809Packages jT809_0X1001.DownLinkPort = 809; jT809Package.Bodies = jT809_0X1001; var hex = JT809Serializer.Serialize(jT809Package).ToHexString(); + Assert.Equal("5B000000480000008510010133EFB8010000000000270F0133EFB832303138303932303132372E302E302E31000000000000000000000000000000000000000000000003296A915D", hex); //"5B //00 00 00 48 //00 00 00 85 @@ -65,6 +66,7 @@ namespace JT809.Protocol.Test.JT809Packages [Fact] public void Test3() { + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); //字符'0':char c = '0'; 它的ASCII码实际上是48。 //字符'\0' : ASCII码为0,表示一个字符串结束的标志。 //"5B 00 00 00 48 00 00 00 85 10 01 01 33 EF B8 01 00 00 00 00 00 27 0F 30 01 33 EF B8 32 30 31 38 30 39 32 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 32 37 2E 30 2E 30 2E 31 03 29 7D 38 5D" diff --git a/src/JT809.Protocol.Test/JT809Packages/JT809_0x9400_0x9401PackageTest.cs b/src/JT809.Protocol.Test/JT809Packages/JT809_0x9400_0x9401PackageTest.cs index 2affc45..5712c99 100644 --- a/src/JT809.Protocol.Test/JT809Packages/JT809_0x9400_0x9401PackageTest.cs +++ b/src/JT809.Protocol.Test/JT809Packages/JT809_0x9400_0x9401PackageTest.cs @@ -50,6 +50,7 @@ namespace JT809.Protocol.Test.JT809Packages jT809Package.Bodies = bodies; var hex = JT809Serializer.Serialize(jT809Package).ToHexString(); //"5B 00 00 00 92 00 00 06 82 94 00 01 33 EF B8 01 00 00 00 00 00 27 0F D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 02 94 01 00 00 00 5C 01 00 02 00 00 00 00 5A 01 AC 3F 40 12 3F FA A1 00 00 00 00 5A 01 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 BA D8 5D" + Assert.Equal("5B000000920000068294000133EFB8010000000000270FD4C1413132333435000000000000000000000000000294010000005C010002000000005A01AC3F40123FFAA1000000005A01AC4D5003736D616C6C636869000000000000000031323334353637383930310000000000000000003132333435364071712E636F6D00000000000000000000000000000000000000BAD85D", hex); } [Fact] @@ -113,6 +114,7 @@ namespace JT809.Protocol.Test.JT809Packages jT809Package.Header.MsgSN = 1666; var hex = JT809Serializer.Serialize(jT809Package).ToHexString(); //"5B000000920000068294000133EFB8010000000000270FD4C1413132333435000000000000000000000000000294010000005C010002000000005A01AC3F40123FFAA1000000005A01AC4D5003736D616C6C636869000000000000000031323334353637383930310000000000000000003132333435364071712E636F6D00000000000000000000000000000000000000BAD85D" + Assert.Equal("5B000000920000068294000133EFB8010000000000270FD4C1413132333435000000000000000000000000000294010000005C010002000000005A01AC3F40123FFAA1000000005A01AC4D5003736D616C6C636869000000000000000031323334353637383930310000000000000000003132333435364071712E636F6D00000000000000000000000000000000000000BAD85D", hex); } } } diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1201Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1201Test.cs index 0890d7b..54c6cb1 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1201Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1201Test.cs @@ -25,6 +25,7 @@ namespace JT809.Protocol.Test.JT809SubMessageBody }; var hex = JT809Serializer.Serialize(jT809_0X1200_0X1201).ToHexString(); //"00 00 00 00 00 00 00 42 3A 35 C7 00 00 00 00 00 00 00 42 3A 35 C7 31 31 31 31 31 31 31 31 00 00 00 00 00 00 00 00 00 00 00 00 31 31 31 31 31 41 41 32 32 32 32 32 32 32 32 32 32 32 32" + Assert.Equal("00000000000000423A35C700000000000000423A35C7313131313131313100000000000000000000000031313131314141323232323232323232323232",hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1202Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1202Test.cs index e1e4c7e..ccbc265 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1202Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1202Test.cs @@ -33,6 +33,7 @@ namespace JT809.Protocol.Test.JT809SubMessageBody jT809_0X1200_0X1202.VehiclePosition.Alarm = 257; var hex = JT809Serializer.Serialize(jT809_0X1200_0X1202).ToHexString(); //"00 13 07 07 DC 0F 0F 0F 07 EF 4D 80 01 70 18 40 00 32 00 33 00 00 00 96 00 2D 00 2D 00 00 00 03 00 00 01 01" + Assert.Equal("00130707DC0F0F0F07EF4D80017018400032003300000096002D002D0000000300000101", hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1203Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1203Test.cs index 6835727..071d220 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1203Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1203Test.cs @@ -76,6 +76,7 @@ namespace JT809.Protocol.Test.JT809SubMessageBody var hex = JT809Serializer.Serialize(jT809_0X1200_0X1203).ToHexString(); //"03 00 13 07 07 DC 0F 0F 0F 07 EF 4D 80 01 70 18 40 00 32 00 33 00 00 00 96 00 2D 00 2D 00 00 00 03 00 00 01 01 00 13 07 07 DC 10 10 10 07 EF 4D 80 01 70 18 40 00 32 00 33 00 00 00 96 00 2D 00 2D 00 00 00 03 00 00 01 01 00 13 07 07 DC 11 11 11 07 EF 4D 80 01 70 18 40 00 32 00 33 00 00 00 96 00 2D 00 2D 00 00 00 03 00 00 01 01" + Assert.Equal("0300130707DC0F0F0F07EF4D80017018400032003300000096002D002D000000030000010100130707DC10101007EF4D80017018400032003300000096002D002D000000030000010100130707DC11111107EF4D80017018400032003300000096002D002D0000000300000101", hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1207Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1207Test.cs index 7d13e3d..306e796 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1207Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1207Test.cs @@ -22,6 +22,7 @@ namespace JT809.Protocol.Test.JT809SubMessageBody }; var hex = JT809Serializer.Serialize(jT809_0X1200_0X1201).ToHexString(); //"00 00 00 00 5B A8 80 B6 00 00 00 00 5B A9 01 6B" + Assert.Equal("000000005BA880B6000000005BA9016B",hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1209Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1209Test.cs index 7090711..cd59933 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1209Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1209Test.cs @@ -22,6 +22,7 @@ namespace JT809.Protocol.Test.JT809SubMessageBody }; var hex = JT809Serializer.Serialize(jT809_0X1200_0X1209).ToHexString(); //"00 00 00 00 5B A8 80 B6 00 00 00 00 5B A9 01 6B" + Assert.Equal("000000005BA880B6000000005BA9016B",hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x120ATest.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x120ATest.cs index b41d9ba..c9e18bb 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x120ATest.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x120ATest.cs @@ -24,6 +24,7 @@ namespace JT809.Protocol.Test.JT809SubMessageBody }; var hex = JT809Serializer.Serialize(jT809_0X1200_0X120A).ToHexString(); //"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 31 32 33 34 35 36 37 38 39 00 00 61 62 63 64 65 66 31 32 33 34 35 36 37 38 39 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 77 77 77 31 32 33 34 35 36 37 38 39 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 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 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 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 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 00 00 00" + Assert.Equal("736D616C6C63686900000000000000003132333435363738393132333435363738390000616263646566313233343536373839000000000000000000000000000000000000000000000000007777773132333435363738390000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", hex);Assert.Equal("736D616C6C63686900000000000000003132333435363738393132333435363738390000616263646566313233343536373839000000000000000000000000000000000000000000000000007777773132333435363738390000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x120BTest.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x120BTest.cs index 8fda46e..8ec6ac3 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x120BTest.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x120BTest.cs @@ -21,6 +21,7 @@ namespace JT809.Protocol.Test.JT809SubMessageBody }; var hex = JT809Serializer.Serialize(jT809_0X1200_0X120B).ToHexString(); //"00 00 00 0C 61 73 64 31 32 33 34 35 36 61 73 64" + Assert.Equal("0000000C617364313233343536617364", hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1300_0x1301Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1300_0x1301Test.cs index c7f284b..33c496d 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1300_0x1301Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1300_0x1301Test.cs @@ -24,6 +24,7 @@ namespace JT809.Protocol.Test.JT809SubMessageBody }; var hex = JT809Serializer.Serialize(jT809_0x1300_0x1301).ToHexString(); //"01 31 31 31 00 00 00 00 00 00 00 00 00 00 00 04 D2 00 00 00 06 32 32 68 61 32 32" + Assert.Equal("01313131000000000000000000000004D200000006323268613232", hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1400_0x1402Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1400_0x1402Test.cs index 47f2760..711b797 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1400_0x1402Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1400_0x1402Test.cs @@ -26,6 +26,7 @@ namespace JT809.Protocol.Test.JT809SubMessageBody }; var hex = JT809Serializer.Serialize(jT809_0x1400_0x1402).ToHexString(); // "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" + Assert.Equal("01000B000000005BAA5B8000000D100000000A67666466343534353533", hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1400_0x1403Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1400_0x1403Test.cs index 8b17dc9..ef14e8c 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1400_0x1403Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1400_0x1403Test.cs @@ -23,6 +23,7 @@ namespace JT809.Protocol.Test.JT809SubMessageBody }; var hex = JT809Serializer.Serialize(jT809_0x1400_0x1403).ToHexString(); // "00 00 0D 10 03" + Assert.Equal("00000D1003", hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1502Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1502Test.cs index 504e672..bc45dc1 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1502Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1502Test.cs @@ -44,6 +44,7 @@ namespace JT809.Protocol.Test.JT809SubMessageBody }; 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" + Assert.Equal("0100130707DC0F0F0F07EF4D80017018400035002D000004D2002D002D00000001000000017B000000000101", hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1504Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1504Test.cs index 6e2788e..0549723 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1504Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1504Test.cs @@ -23,6 +23,7 @@ namespace JT809.Protocol.Test.JT809SubMessageBody }; var hex = JT809Serializer.Serialize(jT809_0x1400_0x1403).ToHexString(); // "00 00 0D 10 03" + Assert.Equal("00000D1003",hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9300_0x9301Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9300_0x9301Test.cs index cf08db4..dca38ef 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9300_0x9301Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9300_0x9301Test.cs @@ -25,6 +25,7 @@ namespace JT809.Protocol.Test.JT809SubMessageBody }; 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" + Assert.Equal("02736D616C6C6368690000000000000D10000000057265706C79", hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9400_0x9401Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9400_0x9401Test.cs index fc5065c..4780ed7 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9400_0x9401Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9400_0x9401Test.cs @@ -30,6 +30,7 @@ namespace JT809.Protocol.Test.JT809SubMessageBody }; 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" + Assert.Equal("010002000000005BAC3F40123FFAA1000000005BAC4D5003736D616C6C636869000000000000000031323334353637383930310000000000000000003132333435364071712E636F6D00000000000000000000000000000000000000", hex); } [Fact] diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9504Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9504Test.cs index 333cf99..b14c759 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9504Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9504Test.cs @@ -26,7 +26,7 @@ namespace JT809.Protocol.Test.JT809SubMessageBody 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" - + Assert.Equal("1018092720002018092723002015B4",hex); //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 } diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9505Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9505Test.cs index 81a9db7..d8bddb4 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9505Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9505Test.cs @@ -28,6 +28,7 @@ namespace JT809.Protocol.Test.JT809SubMessageBody EndTime=DateTime.Parse("2018-09-27 20:00:00") }; var hex = JT809Serializer.Serialize(jT809_0X9500_0X9505).ToHexString(); + Assert.Equal("000000000000000008086A743830380000000000000000000000000000006164736C736D616C6C636869000000000000000000000000000000000000000000000000000000000000000000000000006164736C3132330000000000000000000000000000003132372E302E302E31000000000000000000000000000000000000000000000003280329000000005BACC640", hex); //"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" } @@ -37,7 +38,7 @@ namespace JT809.Protocol.Test.JT809SubMessageBody { 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("808", 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); diff --git a/src/JT809.Protocol/JT809Extensions/JT809BCDExtensions.cs b/src/JT809.Protocol/JT809Extensions/JT809BCDExtensions.cs index d3f1af7..d52879f 100644 --- a/src/JT809.Protocol/JT809Extensions/JT809BCDExtensions.cs +++ b/src/JT809.Protocol/JT809Extensions/JT809BCDExtensions.cs @@ -10,32 +10,36 @@ namespace JT809.Protocol.JT809Extensions { public static string ReadBCDLittle(ReadOnlySpan buf, ref int offset, int len) { - StringBuilder bcdSb = new StringBuilder(len*2); - for(int i = 0; i < len; i++) + int count = len / 2; + StringBuilder bcdSb = new StringBuilder(count); + for (int i = 0; i < count; i++) { bcdSb.Append(buf[offset + i].ToString("X2")); } - offset = offset + len; - return bcdSb.ToString(); + offset = offset + count; + return bcdSb.ToString().TrimStart('0'); } - public static int WriteBCDLittle(byte[] bytes, int offset, string data,int len) + public static int WriteBCDLittle(byte[] bytes, int offset, string data, int len) { string bcdText = data == null ? "" : data; int startIndex = 0; - int noOfZero = len * 2 - bcdText.Length; + int noOfZero = len - bcdText.Length; if (noOfZero > 0) { bcdText = bcdText.Insert(startIndex, new string('0', noOfZero)); } int byteIndex = 0; - while (startIndex < bcdText.Length && byteIndex < len) + int count = len / 2; + byte[] tempBytes = new byte[count]; + while (startIndex < bcdText.Length && byteIndex < count) { - bytes[startIndex + offset] = Convert.ToByte(bcdText.Substring(startIndex, 2), 16); + tempBytes[byteIndex] = Convert.ToByte(bcdText.Substring(startIndex, 2), 16); startIndex += 2; byteIndex++; } - return len; + Array.Copy(tempBytes, 0, bytes, offset, tempBytes.Length); + return count; } } } diff --git a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9505Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9505Formatter.cs index c541410..2e11495 100644 --- a/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9505Formatter.cs +++ b/src/JT809.Protocol/JT809Formatters/JT809SubMessageBodyFormatters/JT809_0x9500_0x9505Formatter.cs @@ -13,7 +13,7 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters { int offset = 0; JT809_0x9500_0x9505 jT809_0X9500_0X9505 = new JT809_0x9500_0x9505(); - jT809_0X9500_0X9505.AuthenticationCode= JT809BinaryExtensions.ReadBCDLittle(bytes, ref offset,10); + jT809_0X9500_0X9505.AuthenticationCode= JT809BinaryExtensions.ReadBCDLittle(bytes, ref offset,20); 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);