diff --git a/src/GBNewEnergy.Protocol.Test/NEPackageBase.cs b/src/GBNewEnergy.Protocol.Test/NEPackageBase.cs new file mode 100644 index 0000000..65b3e46 --- /dev/null +++ b/src/GBNewEnergy.Protocol.Test/NEPackageBase.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace GBNewEnergy.Protocol.Test +{ + public class NEPackageBase + { + public readonly NEGlobalConfigs NEGlobalConfigs = new NEGlobalConfigs() + { + + }; + } +} diff --git a/src/GBNewEnergy.Protocol.Test/NEPackageTest.cs b/src/GBNewEnergy.Protocol.Test/NEPackageTest.cs index f017f5c..04fb4ad 100644 --- a/src/GBNewEnergy.Protocol.Test/NEPackageTest.cs +++ b/src/GBNewEnergy.Protocol.Test/NEPackageTest.cs @@ -7,243 +7,12 @@ using GBNewEnergy.Protocol.UpStream; using GBNewEnergy.Protocol.Enums; using GBNewEnergy.Protocol.Exceptions; using GBNewEnergy.Protocol.NEProperties; +using GBNewEnergy.Protocol.DownStream; namespace GBNewEnergy.Protocol.Test { - public class NEPackageTest + public class NEPackageTest: NEPackageBase { - private readonly NEGlobalConfigs NEGlobalConfigs = new NEGlobalConfigs() - { - }; - - #region 车辆登入 - [Fact] - public void NELoginUpStreamConstructor4_1() - { - // "23 23 01 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 1F" - // "12 06 08 11 09 14 00 01 36 34 37 34 33 30 36 36 34 30 35 00 00 00 00 00 00 00 00 00 01 01 31" - // "23 23 01 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 1F 12 06 08 11 09 14 00 01 36 34 37 34 33 30 36 36 34 30 35 00 00 00 00 00 00 00 00 00 01 01 31 DA" - INEProperties nELoginProperty = new NELoginProperty - { - VIN= "LGHC4V1D3HE202652", - BatteryCount=1, - BatteryLength=1, - BatteryNos=new List() { "1" }, - SIM= "64743066405" - }; - NELoginUpStream nELoginUpStream = new NELoginUpStream(nELoginProperty, NEGlobalConfigs); - INEProperties nEPackageProperty = new NEPackageProperty - { - Bodies= nELoginUpStream, - MsgId = Enums.NEMsgId.login, - AskId= Enums.NEAskId.cmd, - VIN= "LGHC4V1D3HE202652" - }; - NEPackage nEPackage = new NEPackage(nEPackageProperty, NEGlobalConfigs); - string headerHex = nEPackage.Header.ToHexString(); - string bodiesHex = nEPackage.Bodies.Buffer.ToHexString(); - string packageHex = nEPackage.Buffer.ToHexString(); - } - [Fact] - public void NELoginUpStreamConstructor4_2() - { - // "23 23 01 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 1F" - // "12 06 07 11 04 1B 00 01 36 34 37 34 33 30 36 36 34 30 35 00 00 00 00 00 00 00 00 00 01 01 31" - // "23 23 01 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 1F 12 06 07 11 04 1B 00 01 36 34 37 34 33 30 36 36 34 30 35 00 00 00 00 00 00 00 00 00 01 01 31 D7" - byte[] header = "23 23 01 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 1F".ToHexBytes(); - byte[] body = "12 06 07 11 04 1B 00 01 36 34 37 34 33 30 36 36 34 30 35 00 00 00 00 00 00 00 00 00 01 01 31 D7".ToHexBytes(); - NEPackage nEPackage = new NEPackage(header, body,NEGlobalConfigs); - string headerHex = nEPackage.Header.ToHexString(); - string bodiesHex = nEPackage.Bodies.Buffer.ToHexString(); - string packageHex = nEPackage.Buffer.ToHexString(); - } - [Fact] - public void NELoginUpStreamConstructor4_3() - { - - // "23 23 01 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 1F 12 06 07 11 04 1B 00 01 36 34 37 34 33 30 36 36 34 30 35 00 00 00 00 00 00 00 00 00 01 01 31 D7" - byte[] packageBytes = "23 23 01 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 1F 12 06 07 11 04 1B 00 01 36 34 37 34 33 30 36 36 34 30 35 00 00 00 00 00 00 00 00 00 01 01 31 D7".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 车辆登出(依赖车辆登入的流水号所有必须先进行登入产生流水号) - - [Fact] - public void NELogoutUpStream1_1() - { - try - { - INEProperties nELogoutProperty = new NELogoutProperty() - { - VIN = "LGHC4V1D3HE202652" - }; - NELogoutUpStream nELogoutUpStream1 = new NELogoutUpStream(nELogoutProperty, NEGlobalConfigs); - INEProperties nEPackageProperty1 = new NEPackageProperty - { - Bodies = nELogoutUpStream1, - MsgId = Enums.NEMsgId.login, - AskId = Enums.NEAskId.cmd, - VIN = "LGHC4V1D3HE202652" - }; - NEPackage nEPackage = new NEPackage(nEPackageProperty1, NEGlobalConfigs); - string headerHex = nEPackage.Header.ToHexString(); - string bodiesHex = nEPackage.Bodies.Buffer.ToHexString(); - string packageHex = nEPackage.Buffer.ToHexString(); - } - catch (NEException ex) - { - Assert.Equal(NEErrorCode.LoginSerialNoError, ex.ErrorCode); - } - } - - [Fact] - public void NELogoutUpStream2_1() - { - INEProperties nELoginProperty = new NELoginProperty - { - VIN = "LGHC4V1D3HE202652", - BatteryCount = 1, - BatteryLength = 1, - BatteryNos = new List() { "1" }, - SIM = "64743066405" - }; - NELoginUpStream nELoginUpStream = new NELoginUpStream(nELoginProperty, NEGlobalConfigs); - INEProperties nEPackageProperty = new NEPackageProperty - { - Bodies = nELoginUpStream, - MsgId = Enums.NEMsgId.login, - AskId = Enums.NEAskId.cmd, - VIN = "LGHC4V1D3HE202652" - }; - NEPackage nEPackageLogin = new NEPackage(nEPackageProperty, NEGlobalConfigs); - INEProperties nELogoutProperty = new NELogoutProperty() - { - VIN = "LGHC4V1D3HE202652" - }; - NELogoutUpStream nELogoutUpStream1 = new NELogoutUpStream(nELogoutProperty, NEGlobalConfigs); - INEProperties nEPackageProperty1 = new NEPackageProperty - { - Bodies = nELogoutUpStream1, - MsgId = Enums.NEMsgId.loginout, - AskId = Enums.NEAskId.cmd, - VIN = "LGHC4V1D3HE202652" - }; - NEPackage nEPackage = new NEPackage(nEPackageProperty1, NEGlobalConfigs); - // "23 23 05 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 08" - // "12 06 08 12 06 3A 00 01" - // "23 23 05 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 08 12 06 08 12 06 3A 00 01 E9" - string headerHex = nEPackage.Header.ToHexString(); - string bodiesHex = nEPackage.Bodies.Buffer.ToHexString(); - string packageHex = nEPackage.Buffer.ToHexString(); - } - - [Fact] - public void NELogoutUpStream2_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 08 12 06 08 12 06 3A 00 01 E9".ToHexBytes(); - NEPackage nEPackage = new NEPackage(packageBytes, NEGlobalConfigs); - string headerHex = nEPackage.Header.ToHexString(); - string bodiesHex = nEPackage.Bodies.Buffer.ToHexString(); - string packageHex = nEPackage.Buffer.ToHexString(); - Assert.Equal("23 23 05 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 08", headerHex); - Assert.Equal("12 06 08 12 06 3A 00 01 E9", bodiesHex); - } - - #endregion - - #region 平台登入 - - [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, - Password = "123456", - UserName = "smallchi", - }; - NEPlatformLoginUpStream nEPlatformLoginUpStream = new NEPlatformLoginUpStream(nEPlatformLoginProperty, NEGlobalConfigs); - INEProperties nEPackageProperty = new NEPackageProperty - { - Bodies = nEPlatformLoginUpStream, - MsgId = Enums.NEMsgId.platformlogin, - AskId = Enums.NEAskId.cmd, - VIN = "LGHC4V1D3HE202652" - }; - NEPackage nEPackage = new NEPackage(nEPackageProperty, NEGlobalConfigs); - string headerHex = nEPackage.Header.ToHexString(); - string bodiesHex = nEPackage.Bodies.Buffer.ToHexString(); - 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 平台登出(依赖平台登出的流水号所有必须先进行登入产生流水号) - - [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, - Password = "123456", - UserName = "smallchi", - }; - NEPlatformLoginUpStream nEPlatformLoginUpStream = new NEPlatformLoginUpStream(nEPlatformLoginProperty, NEGlobalConfigs); - INEProperties nEPackageProperty = new NEPackageProperty - { - Bodies = nEPlatformLoginUpStream, - MsgId = Enums.NEMsgId.platformlogin, - AskId = Enums.NEAskId.cmd, - VIN = "LGHC4V1D3HE202652" - }; - NEPackage nEPackage = new NEPackage(nEPackageProperty, NEGlobalConfigs); - - NEPlatformLogoutProperty nEPlatformLogoutProperty = new NEPlatformLogoutProperty - { - UserName = "smallchi", - }; - NEPlatformLoginUpStream nEPlatformLogoutUpStream = new NEPlatformLoginUpStream(nEPlatformLoginProperty, NEGlobalConfigs); - INEProperties logoutNEPackageProperty = new NEPackageProperty - { - Bodies = nEPlatformLogoutUpStream, - MsgId = Enums.NEMsgId.platformlogout, - AskId = Enums.NEAskId.cmd, - VIN = "LGHC4V1D3HE202652" - }; - NEPackage loginNEPackage = new NEPackage(logoutNEPackageProperty, NEGlobalConfigs); - string headerHex = loginNEPackage.Header.ToHexString(); - string bodiesHex = loginNEPackage.Bodies.Buffer.ToHexString(); - 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.Test/UpStream/CommonUpStreamTest.cs b/src/GBNewEnergy.Protocol.Test/UpStream/CommonUpStreamTest.cs new file mode 100644 index 0000000..c619b43 --- /dev/null +++ b/src/GBNewEnergy.Protocol.Test/UpStream/CommonUpStreamTest.cs @@ -0,0 +1,152 @@ +using GBNewEnergy.Protocol.NEProperties; +using GBNewEnergy.Protocol.UpStream; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using GBNewEnergy.Protocol.Extensions; + +namespace GBNewEnergy.Protocol.Test.UpStream +{ + public class CommonUpStreamTest: NEPackageBase + { + #region 控制应答 + [Fact] + public void NEControlTest1_1() + { + // "23 23 82 01 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 06 12 06 0C 0B 21 08 96" + CommonUpStream nEControlDownStream = new CommonUpStream(new NEEmptyProperty(), NEGlobalConfigs); + INEProperties nEPackageProperty = new NEPackageProperty + { + Bodies = nEControlDownStream, + MsgId = Enums.NEMsgId.control, + AskId = Enums.NEAskId.success, + VIN = "LGHC4V1D3HE202652" + }; + NEPackage nEPackage = new NEPackage(nEPackageProperty, NEGlobalConfigs); + string headerHex = nEPackage.Header.ToHexString(); + string bodiesHex = nEPackage.Bodies.Buffer.ToHexString(); + string packageHex = nEPackage.Buffer.ToHexString(); + } + + [Fact] + public void NEControlTest1_2() + { + // "23 23 82 01 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 06 12 06 0C 0B 21 08 96" + byte[] packageBytes = "23 23 82 01 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 06 12 06 0C 0B 21 08 96".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 设置应答 + [Fact] + public void NESettingsTest1_1() + { + // "23 23 81 01 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 06 12 06 0C 0B 23 15 8A" + CommonUpStream nESettingsDownStream = new CommonUpStream(new NEEmptyProperty(), NEGlobalConfigs); + INEProperties nEPackageProperty = new NEPackageProperty + { + Bodies = nESettingsDownStream, + MsgId = Enums.NEMsgId.settings, + AskId = Enums.NEAskId.success, + VIN = "LGHC4V1D3HE202652" + }; + NEPackage nEPackage = new NEPackage(nEPackageProperty, NEGlobalConfigs); + string headerHex = nEPackage.Header.ToHexString(); + string bodiesHex = nEPackage.Bodies.Buffer.ToHexString(); + string packageHex = nEPackage.Buffer.ToHexString(); + } + + [Fact] + public void NESettingsTest1_2() + { + byte[] packageBytes = "23 23 81 01 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 06 12 06 0C 0B 23 15 8A".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 心跳 + + [Fact] + public void NEHeartbeatTest1_1() + { + // "23 23 81 01 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 06 12 06 0C 0B 23 15 8A" + CommonUpStream nESettingsDownStream = new CommonUpStream(new NEEmptyProperty(), NEGlobalConfigs); + INEProperties nEPackageProperty = new NEPackageProperty + { + Bodies = nESettingsDownStream, + MsgId = Enums.NEMsgId.heartbeat, + AskId = Enums.NEAskId.cmd, + VIN = "LGHC4V1D3HE202652" + }; + NEPackage nEPackage = new NEPackage(nEPackageProperty, NEGlobalConfigs); + string headerHex = nEPackage.Header.ToHexString(); + string bodiesHex = nEPackage.Bodies.Buffer.ToHexString(); + string packageHex = nEPackage.Buffer.ToHexString(); + } + + [Fact] + public void NEHeartbeatTest1_2() + { + // "23 23 81 01 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 06 12 06 0C 0B 23 15 8A" + CommonUpStream nESettingsDownStream = new CommonUpStream(new NEEmptyProperty(), NEGlobalConfigs); + INEProperties nEPackageProperty = new NEPackageProperty + { + Bodies = nESettingsDownStream, + MsgId = Enums.NEMsgId.heartbeat, + AskId = Enums.NEAskId.success, + VIN = "LGHC4V1D3HE202652" + }; + NEPackage nEPackage = new NEPackage(nEPackageProperty, NEGlobalConfigs); + string headerHex = nEPackage.Header.ToHexString(); + string bodiesHex = nEPackage.Bodies.Buffer.ToHexString(); + string packageHex = nEPackage.Buffer.ToHexString(); + } + + #endregion + + #region 终端校时 + [Fact] + public void NECheckTimeTest1_1() + { + // "23 23 81 01 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 06 12 06 0C 0B 23 15 8A" + CommonUpStream nESettingsDownStream = new CommonUpStream(new NEEmptyProperty(), NEGlobalConfigs); + INEProperties nEPackageProperty = new NEPackageProperty + { + Bodies = nESettingsDownStream, + MsgId = Enums.NEMsgId.checktime, + AskId = Enums.NEAskId.cmd, + VIN = "LGHC4V1D3HE202652" + }; + NEPackage nEPackage = new NEPackage(nEPackageProperty, NEGlobalConfigs); + string headerHex = nEPackage.Header.ToHexString(); + string bodiesHex = nEPackage.Bodies.Buffer.ToHexString(); + string packageHex = nEPackage.Buffer.ToHexString(); + } + + [Fact] + public void NECheckTimeTest1_2() + { + // "23 23 81 01 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 06 12 06 0C 0B 23 15 8A" + CommonUpStream nESettingsDownStream = new CommonUpStream(new NEEmptyProperty(), NEGlobalConfigs); + INEProperties nEPackageProperty = new NEPackageProperty + { + Bodies = nESettingsDownStream, + MsgId = Enums.NEMsgId.checktime, + AskId = Enums.NEAskId.success, + VIN = "LGHC4V1D3HE202652" + }; + NEPackage nEPackage = new NEPackage(nEPackageProperty, NEGlobalConfigs); + string headerHex = nEPackage.Header.ToHexString(); + string bodiesHex = nEPackage.Bodies.Buffer.ToHexString(); + string packageHex = nEPackage.Buffer.ToHexString(); + } + #endregion + } +} diff --git a/src/GBNewEnergy.Protocol.Test/UpStream/NELoginUpStreamTest.cs b/src/GBNewEnergy.Protocol.Test/UpStream/NELoginUpStreamTest.cs new file mode 100644 index 0000000..68f962a --- /dev/null +++ b/src/GBNewEnergy.Protocol.Test/UpStream/NELoginUpStreamTest.cs @@ -0,0 +1,67 @@ +using GBNewEnergy.Protocol.NEProperties; +using GBNewEnergy.Protocol.UpStream; +using GBNewEnergy.Protocol.Extensions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; + +namespace GBNewEnergy.Protocol.Test.UpStream +{ + public class NELoginUpStreamTest:NEPackageTest + { + #region 车辆登入 + [Fact] + public void NELoginUpStreamConstructor4_1() + { + // "23 23 01 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 1F" + // "12 06 08 11 09 14 00 01 36 34 37 34 33 30 36 36 34 30 35 00 00 00 00 00 00 00 00 00 01 01 31" + // "23 23 01 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 1F 12 06 08 11 09 14 00 01 36 34 37 34 33 30 36 36 34 30 35 00 00 00 00 00 00 00 00 00 01 01 31 DA" + INEProperties nELoginProperty = new NELoginProperty + { + VIN = "LGHC4V1D3HE202652", + BatteryCount = 1, + BatteryLength = 1, + BatteryNos = new List() { "1" }, + SIM = "64743066405" + }; + NELoginUpStream nELoginUpStream = new NELoginUpStream(nELoginProperty, NEGlobalConfigs); + INEProperties nEPackageProperty = new NEPackageProperty + { + Bodies = nELoginUpStream, + MsgId = Enums.NEMsgId.login, + AskId = Enums.NEAskId.cmd, + VIN = "LGHC4V1D3HE202652" + }; + NEPackage nEPackage = new NEPackage(nEPackageProperty, NEGlobalConfigs); + string headerHex = nEPackage.Header.ToHexString(); + string bodiesHex = nEPackage.Bodies.Buffer.ToHexString(); + string packageHex = nEPackage.Buffer.ToHexString(); + } + [Fact] + public void NELoginUpStreamConstructor4_2() + { + // "23 23 01 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 1F" + // "12 06 07 11 04 1B 00 01 36 34 37 34 33 30 36 36 34 30 35 00 00 00 00 00 00 00 00 00 01 01 31" + // "23 23 01 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 1F 12 06 07 11 04 1B 00 01 36 34 37 34 33 30 36 36 34 30 35 00 00 00 00 00 00 00 00 00 01 01 31 D7" + byte[] header = "23 23 01 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 1F".ToHexBytes(); + byte[] body = "12 06 07 11 04 1B 00 01 36 34 37 34 33 30 36 36 34 30 35 00 00 00 00 00 00 00 00 00 01 01 31 D7".ToHexBytes(); + NEPackage nEPackage = new NEPackage(header, body, NEGlobalConfigs); + string headerHex = nEPackage.Header.ToHexString(); + string bodiesHex = nEPackage.Bodies.Buffer.ToHexString(); + string packageHex = nEPackage.Buffer.ToHexString(); + } + [Fact] + public void NELoginUpStreamConstructor4_3() + { + + // "23 23 01 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 1F 12 06 07 11 04 1B 00 01 36 34 37 34 33 30 36 36 34 30 35 00 00 00 00 00 00 00 00 00 01 01 31 D7" + byte[] packageBytes = "23 23 01 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 1F 12 06 07 11 04 1B 00 01 36 34 37 34 33 30 36 36 34 30 35 00 00 00 00 00 00 00 00 00 01 01 31 D7".ToHexBytes(); + NEPackage nEPackage = new NEPackage(packageBytes, NEGlobalConfigs); + string headerHex = nEPackage.Header.ToHexString(); + string bodiesHex = nEPackage.Bodies.Buffer.ToHexString(); + string packageHex = nEPackage.Buffer.ToHexString(); + } + #endregion + } +} diff --git a/src/GBNewEnergy.Protocol.Test/UpStream/NELogoutUpStreamTest.cs b/src/GBNewEnergy.Protocol.Test/UpStream/NELogoutUpStreamTest.cs new file mode 100644 index 0000000..c3494fc --- /dev/null +++ b/src/GBNewEnergy.Protocol.Test/UpStream/NELogoutUpStreamTest.cs @@ -0,0 +1,100 @@ +using GBNewEnergy.Protocol.NEProperties; +using GBNewEnergy.Protocol.UpStream; +using GBNewEnergy.Protocol.Extensions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using GBNewEnergy.Protocol.Exceptions; +using GBNewEnergy.Protocol.Enums; + +namespace GBNewEnergy.Protocol.Test.UpStream +{ + public class NELogoutUpStreamTest:NEPackageBase + { + #region 车辆登出(依赖车辆登入的流水号所有必须先进行登入产生流水号) + + [Fact] + public void NELogoutUpStream1_1() + { + try + { + INEProperties nELogoutProperty = new NELogoutProperty() + { + VIN = "LGHC4V1D3HE202652" + }; + NELogoutUpStream nELogoutUpStream1 = new NELogoutUpStream(nELogoutProperty, NEGlobalConfigs); + INEProperties nEPackageProperty1 = new NEPackageProperty + { + Bodies = nELogoutUpStream1, + MsgId = Enums.NEMsgId.login, + AskId = Enums.NEAskId.cmd, + VIN = "LGHC4V1D3HE202652" + }; + NEPackage nEPackage = new NEPackage(nEPackageProperty1, NEGlobalConfigs); + string headerHex = nEPackage.Header.ToHexString(); + string bodiesHex = nEPackage.Bodies.Buffer.ToHexString(); + string packageHex = nEPackage.Buffer.ToHexString(); + } + catch (NEException ex) + { + Assert.Equal(NEErrorCode.LoginSerialNoError, ex.ErrorCode); + } + } + + [Fact] + public void NELogoutUpStream2_1() + { + INEProperties nELoginProperty = new NELoginProperty + { + VIN = "LGHC4V1D3HE202652", + BatteryCount = 1, + BatteryLength = 1, + BatteryNos = new List() { "1" }, + SIM = "64743066405" + }; + NELoginUpStream nELoginUpStream = new NELoginUpStream(nELoginProperty, NEGlobalConfigs); + INEProperties nEPackageProperty = new NEPackageProperty + { + Bodies = nELoginUpStream, + MsgId = Enums.NEMsgId.login, + AskId = Enums.NEAskId.cmd, + VIN = "LGHC4V1D3HE202652" + }; + NEPackage nEPackageLogin = new NEPackage(nEPackageProperty, NEGlobalConfigs); + INEProperties nELogoutProperty = new NELogoutProperty() + { + VIN = "LGHC4V1D3HE202652" + }; + NELogoutUpStream nELogoutUpStream1 = new NELogoutUpStream(nELogoutProperty, NEGlobalConfigs); + INEProperties nEPackageProperty1 = new NEPackageProperty + { + Bodies = nELogoutUpStream1, + MsgId = Enums.NEMsgId.loginout, + AskId = Enums.NEAskId.cmd, + VIN = "LGHC4V1D3HE202652" + }; + NEPackage nEPackage = new NEPackage(nEPackageProperty1, NEGlobalConfigs); + // "23 23 05 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 08" + // "12 06 08 12 06 3A 00 01" + // "23 23 05 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 08 12 06 08 12 06 3A 00 01 E9" + string headerHex = nEPackage.Header.ToHexString(); + string bodiesHex = nEPackage.Bodies.Buffer.ToHexString(); + string packageHex = nEPackage.Buffer.ToHexString(); + } + + [Fact] + public void NELogoutUpStream2_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 08 12 06 08 12 06 3A 00 01 E9".ToHexBytes(); + NEPackage nEPackage = new NEPackage(packageBytes, NEGlobalConfigs); + string headerHex = nEPackage.Header.ToHexString(); + string bodiesHex = nEPackage.Bodies.Buffer.ToHexString(); + string packageHex = nEPackage.Buffer.ToHexString(); + Assert.Equal("23 23 05 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 08", headerHex); + Assert.Equal("12 06 08 12 06 3A 00 01 E9", bodiesHex); + } + + #endregion + } +} diff --git a/src/GBNewEnergy.Protocol.Test/UpStream/NEPlatformLoginUpStreamTest.cs b/src/GBNewEnergy.Protocol.Test/UpStream/NEPlatformLoginUpStreamTest.cs new file mode 100644 index 0000000..0372d20 --- /dev/null +++ b/src/GBNewEnergy.Protocol.Test/UpStream/NEPlatformLoginUpStreamTest.cs @@ -0,0 +1,52 @@ +using GBNewEnergy.Protocol.NEProperties; +using GBNewEnergy.Protocol.UpStream; +using GBNewEnergy.Protocol.Extensions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using GBNewEnergy.Protocol.Enums; + +namespace GBNewEnergy.Protocol.Test.UpStream +{ + public class NEPlatformLoginUpStreamTest:NEPackageBase + { + #region 平台登入 + + [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, + Password = "123456", + UserName = "smallchi", + }; + NEPlatformLoginUpStream nEPlatformLoginUpStream = new NEPlatformLoginUpStream(nEPlatformLoginProperty, NEGlobalConfigs); + INEProperties nEPackageProperty = new NEPackageProperty + { + Bodies = nEPlatformLoginUpStream, + MsgId = Enums.NEMsgId.platformlogin, + AskId = Enums.NEAskId.cmd, + VIN = "LGHC4V1D3HE202652" + }; + NEPackage nEPackage = new NEPackage(nEPackageProperty, NEGlobalConfigs); + string headerHex = nEPackage.Header.ToHexString(); + string bodiesHex = nEPackage.Bodies.Buffer.ToHexString(); + 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 + } +} diff --git a/src/GBNewEnergy.Protocol.Test/UpStream/NEPlatformLogoutUpStreamTest.cs b/src/GBNewEnergy.Protocol.Test/UpStream/NEPlatformLogoutUpStreamTest.cs new file mode 100644 index 0000000..a80958d --- /dev/null +++ b/src/GBNewEnergy.Protocol.Test/UpStream/NEPlatformLogoutUpStreamTest.cs @@ -0,0 +1,67 @@ +using GBNewEnergy.Protocol.NEProperties; +using GBNewEnergy.Protocol.UpStream; +using GBNewEnergy.Protocol.Extensions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using GBNewEnergy.Protocol.Enums; + +namespace GBNewEnergy.Protocol.Test.UpStream +{ + public class NEPlatformLogoutUpStreamTest : NEPackageBase + { + + #region 平台登出(依赖平台登出的流水号所有必须先进行登入产生流水号) + + [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, + Password = "123456", + UserName = "smallchi", + }; + NEPlatformLoginUpStream nEPlatformLoginUpStream = new NEPlatformLoginUpStream(nEPlatformLoginProperty, NEGlobalConfigs); + INEProperties nEPackageProperty = new NEPackageProperty + { + Bodies = nEPlatformLoginUpStream, + MsgId = Enums.NEMsgId.platformlogin, + AskId = Enums.NEAskId.cmd, + VIN = "LGHC4V1D3HE202652" + }; + NEPackage nEPackage = new NEPackage(nEPackageProperty, NEGlobalConfigs); + + NEPlatformLogoutProperty nEPlatformLogoutProperty = new NEPlatformLogoutProperty + { + UserName = "smallchi", + }; + NEPlatformLoginUpStream nEPlatformLogoutUpStream = new NEPlatformLoginUpStream(nEPlatformLoginProperty, NEGlobalConfigs); + INEProperties logoutNEPackageProperty = new NEPackageProperty + { + Bodies = nEPlatformLogoutUpStream, + MsgId = Enums.NEMsgId.platformlogout, + AskId = Enums.NEAskId.cmd, + VIN = "LGHC4V1D3HE202652" + }; + NEPackage loginNEPackage = new NEPackage(logoutNEPackageProperty, NEGlobalConfigs); + string headerHex = loginNEPackage.Header.ToHexString(); + string bodiesHex = loginNEPackage.Bodies.Buffer.ToHexString(); + 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/DownStream/NEControlDownStream.cs b/src/GBNewEnergy.Protocol/DownStream/NEControlDownStream.cs new file mode 100644 index 0000000..c876c26 --- /dev/null +++ b/src/GBNewEnergy.Protocol/DownStream/NEControlDownStream.cs @@ -0,0 +1,49 @@ +using GBNewEnergy.Protocol.Extensions; +using GBNewEnergy.Protocol.NEProperties; +using System; +using System.Collections.Generic; +using System.Text; + +namespace GBNewEnergy.Protocol.DownStream +{ + /// + /// 车载终端控制命令 + /// + public class NEControlDownStream : NEBodies + { + public NEControlDownStream(byte[] buffer, NEGlobalConfigs nEConfigs) : base(buffer, nEConfigs) + { + } + + public NEControlDownStream(INEProperties nEProperties, NEGlobalConfigs nEConfigs) : base(nEProperties, nEConfigs) + { + } + + /// + /// 命令ID 只能发送一个 + /// + public byte CmdId { get; set; } + + /// + /// 命令参数 + /// [{id,value},{id,value}], 没有内容则内容为空 + /// + public List> Vauels { get; set; } + + protected override void InitializeProperties(INEProperties nEProperties) + { + + } + + protected override void InitializePropertiesFromBuffer() + { + CurrentDateTime = Buffer.ReadDateTimeLittle(0, 6); + } + + protected override void ToBuffer() + { + Buffer = new byte[6]; + Buffer.WriteLittle(CurrentDateTime, 0, 6); + } + } +} diff --git a/src/GBNewEnergy.Protocol/DownStream/NEQueryDownStream.cs b/src/GBNewEnergy.Protocol/DownStream/NEQueryDownStream.cs new file mode 100644 index 0000000..d4820f1 --- /dev/null +++ b/src/GBNewEnergy.Protocol/DownStream/NEQueryDownStream.cs @@ -0,0 +1,38 @@ +using GBNewEnergy.Protocol.Extensions; +using GBNewEnergy.Protocol.NEProperties; +using System; +using System.Collections.Generic; +using System.Text; + +namespace GBNewEnergy.Protocol.DownStream +{ + /// + /// 查询命令 + /// + public class NEQueryDownStream : NEBodies + { + public NEQueryDownStream(byte[] buffer, NEGlobalConfigs nEConfigs) : base(buffer, nEConfigs) + { + } + + public NEQueryDownStream(INEProperties nEProperties, NEGlobalConfigs nEConfigs) : base(nEProperties, nEConfigs) + { + } + + protected override void InitializeProperties(INEProperties nEProperties) + { + + } + + protected override void InitializePropertiesFromBuffer() + { + CurrentDateTime = Buffer.ReadDateTimeLittle(0, 6); + } + + protected override void ToBuffer() + { + Buffer = new byte[6]; + Buffer.WriteLittle(CurrentDateTime, 0, 6); + } + } +} diff --git a/src/GBNewEnergy.Protocol/DownStream/NESettingsDownStream.cs b/src/GBNewEnergy.Protocol/DownStream/NESettingsDownStream.cs new file mode 100644 index 0000000..50eaa42 --- /dev/null +++ b/src/GBNewEnergy.Protocol/DownStream/NESettingsDownStream.cs @@ -0,0 +1,37 @@ +using GBNewEnergy.Protocol.Extensions; +using System; +using System.Collections.Generic; +using System.Text; + +namespace GBNewEnergy.Protocol.DownStream +{ + /// + /// 设置命令 + /// + public class NESettingsDownStream : NEBodies + { + public NESettingsDownStream(byte[] buffer, NEGlobalConfigs nEConfigs) : base(buffer, nEConfigs) + { + } + + public NESettingsDownStream(INEProperties nEProperties, NEGlobalConfigs nEConfigs) : base(nEProperties, nEConfigs) + { + } + + protected override void InitializeProperties(INEProperties nEProperties) + { + + } + + protected override void InitializePropertiesFromBuffer() + { + CurrentDateTime = Buffer.ReadDateTimeLittle(0, 6); + } + + protected override void ToBuffer() + { + Buffer = new byte[6]; + Buffer.WriteLittle(CurrentDateTime, 0, 6); + } + } +} diff --git a/src/GBNewEnergy.Protocol/Enums/NEControlCmd.cs b/src/GBNewEnergy.Protocol/Enums/NEControlCmd.cs new file mode 100644 index 0000000..08437b1 --- /dev/null +++ b/src/GBNewEnergy.Protocol/Enums/NEControlCmd.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace GBNewEnergy.Protocol.Enums +{ + /// + /// 车载终端控制命令枚举 + /// 0x80-0x7F 预留 + /// 0x80-0xFE 用户自定义 + /// + public enum NEControlCmd:byte + { + /// + /// 未用 + /// + unused= 0x00, + /// + /// 远程升级 + /// + remoteupdate=0x01, + /// + /// 车载终端关机 + /// + shutdown = 0x02, + /// + /// 车载终端复位 + /// + reset = 0x03, + /// + /// 车载终端恢复出厂设置,其中包括本地存储时间周期、心跳发送时间周期、终端应答超时时间等等 + /// + restorefactorysettings = 0x04, + /// + /// 断开数据通信链路 + /// + interruptrequest = 0x05, + /// + /// 车载终端报警/预警,报警命令参数数据格式和定义见表B.17 + /// + warning = 0x06, + /// + /// 开启抽样检测链路 + /// + OpenMonitoring = 0x07, + + + + + + + + + } +} diff --git a/src/GBNewEnergy.Protocol/Enums/NEMsgId.cs b/src/GBNewEnergy.Protocol/Enums/NEMsgId.cs index b4aaa1b..25bd2e6 100644 --- a/src/GBNewEnergy.Protocol/Enums/NEMsgId.cs +++ b/src/GBNewEnergy.Protocol/Enums/NEMsgId.cs @@ -42,15 +42,15 @@ namespace GBNewEnergy.Protocol.Enums /// checktime = 0x08, /// - /// 查询应答 + /// 查询命令 /// query = 0x80, /// - /// 设置应答 + /// 设置命令 /// settings = 0x81, /// - /// 控制应答 + /// 控制命令 /// control = 0x82 } diff --git a/src/GBNewEnergy.Protocol/GBNewEnergy.Protocol.csproj b/src/GBNewEnergy.Protocol/GBNewEnergy.Protocol.csproj index 09a6046..a9c3d6d 100644 --- a/src/GBNewEnergy.Protocol/GBNewEnergy.Protocol.csproj +++ b/src/GBNewEnergy.Protocol/GBNewEnergy.Protocol.csproj @@ -24,7 +24,6 @@ - diff --git a/src/GBNewEnergy.Protocol/NEBodiesFactory.cs b/src/GBNewEnergy.Protocol/NEBodiesFactory.cs index c27f657..032f90a 100644 --- a/src/GBNewEnergy.Protocol/NEBodiesFactory.cs +++ b/src/GBNewEnergy.Protocol/NEBodiesFactory.cs @@ -1,4 +1,5 @@ -using GBNewEnergy.Protocol.Enums; +using GBNewEnergy.Protocol.DownStream; +using GBNewEnergy.Protocol.Enums; using GBNewEnergy.Protocol.UpStream; using System; using System.Collections.Generic; @@ -26,6 +27,12 @@ namespace GBNewEnergy.Protocol return new NEPlatformLoginUpStream(buf, nEConfigs); case NEMsgId.platformlogout: return new NEPlatformLogoutUpStream(buf, nEConfigs); + case NEMsgId.control: + case NEMsgId.settings: + case NEMsgId.heartbeat: + case NEMsgId.checktime: + return new CommonUpStream(buf, nEConfigs); + default: return null; } diff --git a/src/GBNewEnergy.Protocol/NEProperties/NEEmptyProperty.cs b/src/GBNewEnergy.Protocol/NEProperties/NEEmptyProperty.cs new file mode 100644 index 0000000..f3d6ef8 --- /dev/null +++ b/src/GBNewEnergy.Protocol/NEProperties/NEEmptyProperty.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace GBNewEnergy.Protocol.NEProperties +{ + /// + /// 空包属性 + /// + public class NEEmptyProperty : INEProperties + { + public string VIN { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + } +} diff --git a/src/GBNewEnergy.Protocol/UpStream/CommonUpStream.cs b/src/GBNewEnergy.Protocol/UpStream/CommonUpStream.cs new file mode 100644 index 0000000..18ee1f7 --- /dev/null +++ b/src/GBNewEnergy.Protocol/UpStream/CommonUpStream.cs @@ -0,0 +1,37 @@ +using GBNewEnergy.Protocol.Extensions; +using System; +using System.Collections.Generic; +using System.Text; + +namespace GBNewEnergy.Protocol.UpStream +{ + /// + /// 通用应答 + /// + public class CommonUpStream : NEBodies + { + public CommonUpStream(byte[] buffer, NEGlobalConfigs nEConfigs) : base(buffer, nEConfigs) + { + } + + public CommonUpStream(INEProperties nEProperties, NEGlobalConfigs nEConfigs) : base(nEProperties, nEConfigs) + { + } + + protected override void InitializeProperties(INEProperties nEProperties) + { + + } + + protected override void InitializePropertiesFromBuffer() + { + CurrentDateTime = Buffer.ReadDateTimeLittle(0, 6); + } + + protected override void ToBuffer() + { + Buffer = new byte[6]; + Buffer.WriteLittle(CurrentDateTime, 0, 6); + } + } +}