From 66dab9dfe4e2c7c89025e97f627cb8b5eaba2f9b Mon Sep 17 00:00:00 2001 From: SmallChi <564952747@qq.com> Date: Tue, 12 Jun 2018 10:02:18 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E5=A4=8D=E5=B9=B3=E5=8F=B0=E7=99=BB?= =?UTF-8?q?=E5=85=A5bug=202.=E5=AE=8C=E5=96=84=E5=B9=B3=E5=8F=B0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEPackageTest.cs | 22 ++++++++++++++++++- .../Extensions/NEExtensions.cs | 12 +++++----- src/GBNewEnergy.Protocol/NEBodiesFactory.cs | 4 ++++ .../UpStream/NEPlatformLoginUpStream.cs | 8 +++---- 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/GBNewEnergy.Protocol.Test/NEPackageTest.cs b/src/GBNewEnergy.Protocol.Test/NEPackageTest.cs index 6e7997b..f017f5c 100644 --- a/src/GBNewEnergy.Protocol.Test/NEPackageTest.cs +++ b/src/GBNewEnergy.Protocol.Test/NEPackageTest.cs @@ -161,6 +161,7 @@ namespace GBNewEnergy.Protocol.Test [Fact] public void NEPlatformLogin1_1() { + // "23 23 05 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 29 12 06 0C 09 2F 12 00 01 00 00 00 00 73 6D 61 6C 6C 63 68 69 31 32 33 34 35 36 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 CD" NEPlatformLoginProperty nEPlatformLoginProperty = new NEPlatformLoginProperty { EncryptMethod = NEEncryptMethod.None, @@ -168,7 +169,6 @@ namespace GBNewEnergy.Protocol.Test UserName = "smallchi", }; NEPlatformLoginUpStream nEPlatformLoginUpStream = new NEPlatformLoginUpStream(nEPlatformLoginProperty, NEGlobalConfigs); - INEProperties nEPackageProperty = new NEPackageProperty { Bodies = nEPlatformLoginUpStream, @@ -182,6 +182,16 @@ namespace GBNewEnergy.Protocol.Test string packageHex = nEPackage.Buffer.ToHexString(); } + [Fact] + public void NEPlatformLogin1_2() + { + byte[] packageBytes = "23 23 05 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 29 12 06 0C 09 2F 12 00 01 00 00 00 00 73 6D 61 6C 6C 63 68 69 31 32 33 34 35 36 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 CD".ToHexBytes(); + NEPackage nEPackage = new NEPackage(packageBytes, NEGlobalConfigs); + string headerHex = nEPackage.Header.ToHexString(); + string bodiesHex = nEPackage.Bodies.Buffer.ToHexString(); + string packageHex = nEPackage.Buffer.ToHexString(); + } + #endregion #region 平台登出(依赖平台登出的流水号所有必须先进行登入产生流水号) @@ -189,6 +199,7 @@ namespace GBNewEnergy.Protocol.Test [Fact] public void NEPlatformLogin2_1() { + //"23 23 06 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 29 12 06 0C 09 3A 17 00 01 00 00 00 00 73 6D 61 6C 6C 63 68 69 31 32 33 34 35 36 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 DE" NEPlatformLoginProperty nEPlatformLoginProperty = new NEPlatformLoginProperty { EncryptMethod = NEEncryptMethod.None, @@ -223,6 +234,15 @@ namespace GBNewEnergy.Protocol.Test string packageHex = loginNEPackage.Buffer.ToHexString(); } + [Fact] + public void NEPlatformLogin2_2() + { + byte[] packageBytes = "23 23 06 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 29 12 06 0C 09 3A 17 00 01 00 00 00 00 73 6D 61 6C 6C 63 68 69 31 32 33 34 35 36 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 DE".ToHexBytes(); + NEPackage loginNEPackage = new NEPackage(packageBytes, NEGlobalConfigs); + string headerHex = loginNEPackage.Header.ToHexString(); + string bodiesHex = loginNEPackage.Bodies.Buffer.ToHexString(); + string packageHex = loginNEPackage.Buffer.ToHexString(); + } #endregion } diff --git a/src/GBNewEnergy.Protocol/Extensions/NEExtensions.cs b/src/GBNewEnergy.Protocol/Extensions/NEExtensions.cs index 2dc7bd3..0f4260f 100644 --- a/src/GBNewEnergy.Protocol/Extensions/NEExtensions.cs +++ b/src/GBNewEnergy.Protocol/Extensions/NEExtensions.cs @@ -15,12 +15,12 @@ namespace GBNewEnergy.Protocol.Extensions public static DateTime ReadDateTimeLittle(this byte[] read,int offset, int len) { return new DateTime( - read[offset] + DateLimitYear, - read[++offset], - read[++offset], - read[++offset], - read[++offset], - read[++offset]); + read[offset++] + DateLimitYear, + read[offset++], + read[offset++], + read[offset++], + read[offset++], + read[offset++]); } public static ushort ReadUShortH2LLittle(this byte[] read, int offset, int len) diff --git a/src/GBNewEnergy.Protocol/NEBodiesFactory.cs b/src/GBNewEnergy.Protocol/NEBodiesFactory.cs index b180e29..c27f657 100644 --- a/src/GBNewEnergy.Protocol/NEBodiesFactory.cs +++ b/src/GBNewEnergy.Protocol/NEBodiesFactory.cs @@ -22,6 +22,10 @@ namespace GBNewEnergy.Protocol return new NELoginUpStream(buf, nEConfigs); case NEMsgId.loginout: return new NELogoutUpStream(buf, nEConfigs); + case NEMsgId.platformlogin: + return new NEPlatformLoginUpStream(buf, nEConfigs); + case NEMsgId.platformlogout: + return new NEPlatformLogoutUpStream(buf, nEConfigs); default: return null; } diff --git a/src/GBNewEnergy.Protocol/UpStream/NEPlatformLoginUpStream.cs b/src/GBNewEnergy.Protocol/UpStream/NEPlatformLoginUpStream.cs index 355ae3d..7935414 100644 --- a/src/GBNewEnergy.Protocol/UpStream/NEPlatformLoginUpStream.cs +++ b/src/GBNewEnergy.Protocol/UpStream/NEPlatformLoginUpStream.cs @@ -70,9 +70,9 @@ namespace GBNewEnergy.Protocol.UpStream { CurrentDateTime = Buffer.ReadDateTimeLittle(0, 6); LoginNum = Buffer.ReadUShortH2LLittle(6, 2); - UserName = Buffer.ReadStringLittle(6, 12); - Password = Buffer.ReadStringLittle(12, 20); - EncryptMethod= (NEEncryptMethod)Buffer[21]; + UserName = Buffer.ReadStringLittle(8, 12); + Password = Buffer.ReadStringLittle(20, 20); + EncryptMethod= (NEEncryptMethod)Buffer[40]; } protected override void ToBuffer() @@ -82,7 +82,7 @@ namespace GBNewEnergy.Protocol.UpStream Buffer.WriteLittle(LoginNum, 6, 2); Buffer.WriteLittle(UserName, 12); Buffer.WriteLittle(Password, 20); - Buffer.WriteLittle((byte)EncryptMethod, 21); + Buffer.WriteLittle((byte)EncryptMethod, 40); } } }