Browse Source

1.增加车辆登出及测试

2.增加车辆登出错误码
tags/1.0.0
SmallChi 7 years ago
parent
commit
4dafd58710
6 changed files with 89 additions and 16 deletions
  1. +54
    -10
      src/GBNewEnergy.Protocol.Test/NEPackageTest.cs
  2. +11
    -1
      src/GBNewEnergy.Protocol/Enums/ErrorCode.cs
  3. +2
    -0
      src/GBNewEnergy.Protocol/NEBodiesFactory.cs
  4. +3
    -0
      src/GBNewEnergy.Protocol/UpStream/NELoginUpStream.cs
  5. +18
    -4
      src/GBNewEnergy.Protocol/UpStream/NELogoutUpStream.cs
  6. +1
    -1
      src/GBNewEnergy.sln

+ 54
- 10
src/GBNewEnergy.Protocol.Test/NEPackageTest.cs View File

@@ -5,27 +5,21 @@ using Xunit;
using GBNewEnergy.Protocol.Extensions;
using GBNewEnergy.Protocol.UpStream;
using GBNewEnergy.Protocol.Enums;
using GBNewEnergy.Protocol.Exceptions;

namespace GBNewEnergy.Protocol.Test
{
public class NEPackageTest
{
[Fact]
public void NEPackageConstructor()
{
byte[] header = "23 23 02 FE 54 45 53 54 32 30 31 38 30 34 31 36 30 30 30 30 31 01 02 25".ToHexBytes();
byte[] body = "12 05 0F 0F 29 15 01 02 01 01 00 00 00 00 33 54 19 B1 23 06 58 01 00 06 9F 00 00 02 01 01 03 47 00 00 4E 20 47 10 D6 27 24 05 01 06 CA 3C 03 01 57 8E C3 06 01 38 0D 5C 01 01 0D 48 01 01 43 01 0B 42 07 00 00 00 00 00 00 00 00 00 08 01 01 19 B1 23 06 00 C0 00 01 C0 0D 48 0D 48 0D 48 0D 48 0D 52 0D 48 0D 48 0D 52 0D 52 0D 48 0D 48 0D 52 0D 48 0D 52 0D 52 0D 48 0D 52 0D 52 0D 52 0D 48 0D 52 0D 52 0D 48 0D 52 0D 48 0D 52 0D 48 0D 52 0D 52 0D 52 0D 52 0D 52 0D 48 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 48 0D 48 0D 48 0D 48 0D 48 0D 52 0D 48 0D 52 0D 48 0D 52 0D 48 0D 48 0D 48 0D 5C 0D 52 0D 52 0D 52 0D 5C 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 48 0D 48 0D 48 0D 52 0D 48 0D 52 0D 52 0D 52 0D 48 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 48 0D 48 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 48 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 48 0D 52 0D 48 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 48 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 48 0D 48 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 48 0D 52 0D 52 0D 52 0D 52 0D 48 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 52 0D 48 0D 48 0D 48 0D 48 0D 52 0D 52 0D 48 0D 48 0D 48 0D 52 0D 48 0D 48 0D 48 0D 52 0D 48 0D 52 0D 52 09 01 01 00 48 43 43 43 43 43 43 43 43 43 43 42 43 42 42 42 42 42 43 42 42 42 42 42 42 42 43 42 42 42 43 42 42 42 42 42 42 42 42 42 42 42 42 42 42 43 42 42 43 42 42 42 42 42 42 42 42 43 42 42 43 43 43 42 43 43 43 43 43 43 43 43 43 48".ToHexBytes();
NEPackage nEPackage = new NEPackage(header, body);
}

#region 车辆登入
[Fact]
public void NELoginUpStreamConstructor1_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 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"
NELoginUpStream nELoginUpStream = new NELoginUpStream("LGHC4V1D3HE202652", "64743066405", 1,1,new string[] { "1"});
NEPackage nEPackage = new NEPackage("LGHC4V1D3HE202652", Enums.MsgId.login,Enums.AskId.cmd, nELoginUpStream, EncryptMethod.None);
NELoginUpStream nELoginUpStream = new NELoginUpStream("LGHC4V1D3HE202652", "64743066405", 1, 1, new string[] { "1" });
NEPackage nEPackage = new NEPackage("LGHC4V1D3HE202652", Enums.MsgId.login, Enums.AskId.cmd, nELoginUpStream, EncryptMethod.None);
string headerHex = nEPackage.Header.ToHexString();
string bodiesHex = nEPackage.Bodies.Buffer.ToHexString();
string packageHex = nEPackage.Buffer.ToHexString();
@@ -87,5 +81,55 @@ namespace GBNewEnergy.Protocol.Test
string bodiesHex = nEPackage.Bodies.Buffer.ToHexString();
string packageHex = nEPackage.Buffer.ToHexString();
}
#endregion

#region 车辆登出(依赖车辆登录的流水号所有必须先进行登录产生流水号)

[Fact]
public void NELogoutUpStream1_1()
{
try
{
NELoginUpStream nELoginUpStream = new NELoginUpStream("LGHC4V1D3HE202652", "64743066405", 1, 1, new string[] { "1" });
NELogoutUpStream eLogoutUpStream = new NELogoutUpStream("LGHC4V1D3HE202652");
NEPackage nEPackage = new NEPackage("LGHC4V1D3HE202652", Enums.MsgId.loginout, Enums.AskId.cmd, eLogoutUpStream, EncryptMethod.None);
}
catch (NEException ex)
{
Assert.Equal(ErrorCode.LoginSerialNoError, ex.ErrorCode);
}
}

[Fact]
public void NELogoutUpStream2_1()
{
// 先进行车辆登入
NELoginUpStream nELoginUpStream = new NELoginUpStream("LGHC4V1D3HE202652", "64743066405", 1, 1, new string[] { "1" });
// "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 0B 2B 0A 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 0B 2B 0A 00 01 ED"
// 车辆登出
NELogoutUpStream eLogoutUpStream = new NELogoutUpStream("LGHC4V1D3HE202652");
NEPackage nEPackage = new NEPackage("LGHC4V1D3HE202652", Enums.MsgId.loginout, Enums.AskId.cmd, eLogoutUpStream, EncryptMethod.None);
string headerHex = nEPackage.Header.ToHexString();
string bodiesHex = nEPackage.Bodies.Buffer.ToHexString();
string packageHex = nEPackage.Buffer.ToHexString();
}

[Fact]
public void NELogoutUpStream2_2()
{
byte[] header = "23 23 05 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 08".ToHexBytes();
byte[] body = "12 06 08 0B 2B 0A 00 01 ED".ToHexBytes();
NEPackage nEPackage = new NEPackage(header, body);
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 0B 2B 0A 00 01 ED", bodiesHex);
}

#endregion

}
}

+ 11
- 1
src/GBNewEnergy.Protocol/Enums/ErrorCode.cs View File

@@ -6,7 +6,17 @@ namespace GBNewEnergy.Protocol.Enums
{
public enum ErrorCode
{
/// <summary>
/// 开始标识错误
/// </summary>
BeginFlagError = 1001,
BCCCodeError = 1001
/// <summary>
/// BCC校验错误
/// </summary>
BCCCodeError = 1002,
/// <summary>
/// 登入流水号错误
/// </summary>
LoginSerialNoError=1003
}
}

+ 2
- 0
src/GBNewEnergy.Protocol/NEBodiesFactory.cs View File

@@ -20,6 +20,8 @@ namespace GBNewEnergy.Protocol
{
case MsgId.login:
return new NELoginUpStream(buf);
case MsgId.loginout:
return new NELogoutUpStream(buf);
default:
return null;
}


+ 3
- 0
src/GBNewEnergy.Protocol/UpStream/NELoginUpStream.cs View File

@@ -5,6 +5,9 @@ using System.Text;

namespace GBNewEnergy.Protocol.UpStream
{
/// <summary>
/// 车辆登入
/// </summary>
public class NELoginUpStream : NEBodies
{
public NELoginUpStream(byte[] buffer) : base(buffer)


+ 18
- 4
src/GBNewEnergy.Protocol/UpStream/NELogoutUpStream.cs View File

@@ -1,27 +1,41 @@
using System;
using GBNewEnergy.Protocol.Exceptions;
using GBNewEnergy.Protocol.Extensions;
using System;
using System.Collections.Generic;
using System.Text;

namespace GBNewEnergy.Protocol.UpStream
{
/// <summary>
/// 车辆登入
/// </summary>
public class NELogoutUpStream : NEBodies
{
protected NELogoutUpStream(byte[] buffer) : base(buffer)
public NELogoutUpStream(byte[] buffer) : base(buffer)
{
CurrentDateTime = buffer.ReadDateTimeLittle(0, 6);
LoginNum = buffer.ReadUShortH2LLittle(6, 2);
}

protected NELogoutUpStream(string vin) : base(vin)
public NELogoutUpStream(string vin) : base(vin)
{
(ushort LoginNum, DateTime ExpirationTime) temp;
if (LoginNumDict.TryGetValue(vin, out temp))
{
LoginNum = temp.LoginNum;
}
else
{
throw new NEException(Enums.ErrorCode.LoginSerialNoError, "Must Dependency NELoginUpStream Class.");
}
ToBuffer();
}

public override void ToBuffer()
{
throw new NotImplementedException();
Buffer = new byte[8];
Buffer.WriteLittle(CurrentDateTime, 0, 6);
Buffer.WriteLittle(LoginNum, 6, 2);
}
}
}

+ 1
- 1
src/GBNewEnergy.sln View File

@@ -5,7 +5,7 @@ VisualStudioVersion = 15.0.27703.2018
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GBNewEnergy.Protocol", "GBNewEnergy.Protocol\GBNewEnergy.Protocol.csproj", "{1934F3A6-1396-46C2-BFD6-1E2DC1A26E3A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GBNewEnergy.Protocol.Test", "GBNewEnergy.Protocol.Test\GBNewEnergy.Protocol.Test.csproj", "{AAA669F5-E689-40CA-97EF-B5BA672B11DD}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GBNewEnergy.Protocol.Test", "GBNewEnergy.Protocol.Test\GBNewEnergy.Protocol.Test.csproj", "{AAA669F5-E689-40CA-97EF-B5BA672B11DD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution


Loading…
Cancel
Save