Sfoglia il codice sorgente

1.拆解各个功能测试

2.增加控制命令、查询命令、设置命令
tags/1.0.0
SmallChi 7 anni fa
parent
commit
878aff575c
16 ha cambiato i file con 695 aggiunte e 238 eliminazioni
  1. +14
    -0
      src/GBNewEnergy.Protocol.Test/NEPackageBase.cs
  2. +2
    -233
      src/GBNewEnergy.Protocol.Test/NEPackageTest.cs
  3. +152
    -0
      src/GBNewEnergy.Protocol.Test/UpStream/CommonUpStreamTest.cs
  4. +67
    -0
      src/GBNewEnergy.Protocol.Test/UpStream/NELoginUpStreamTest.cs
  5. +100
    -0
      src/GBNewEnergy.Protocol.Test/UpStream/NELogoutUpStreamTest.cs
  6. +52
    -0
      src/GBNewEnergy.Protocol.Test/UpStream/NEPlatformLoginUpStreamTest.cs
  7. +67
    -0
      src/GBNewEnergy.Protocol.Test/UpStream/NEPlatformLogoutUpStreamTest.cs
  8. +49
    -0
      src/GBNewEnergy.Protocol/DownStream/NEControlDownStream.cs
  9. +38
    -0
      src/GBNewEnergy.Protocol/DownStream/NEQueryDownStream.cs
  10. +37
    -0
      src/GBNewEnergy.Protocol/DownStream/NESettingsDownStream.cs
  11. +55
    -0
      src/GBNewEnergy.Protocol/Enums/NEControlCmd.cs
  12. +3
    -3
      src/GBNewEnergy.Protocol/Enums/NEMsgId.cs
  13. +0
    -1
      src/GBNewEnergy.Protocol/GBNewEnergy.Protocol.csproj
  14. +8
    -1
      src/GBNewEnergy.Protocol/NEBodiesFactory.cs
  15. +14
    -0
      src/GBNewEnergy.Protocol/NEProperties/NEEmptyProperty.cs
  16. +37
    -0
      src/GBNewEnergy.Protocol/UpStream/CommonUpStream.cs

+ 14
- 0
src/GBNewEnergy.Protocol.Test/NEPackageBase.cs Vedi File

@@ -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()
{

};
}
}

+ 2
- 233
src/GBNewEnergy.Protocol.Test/NEPackageTest.cs Vedi File

@@ -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<string>() { "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<string>() { "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
}
}

+ 152
- 0
src/GBNewEnergy.Protocol.Test/UpStream/CommonUpStreamTest.cs Vedi File

@@ -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
}
}

+ 67
- 0
src/GBNewEnergy.Protocol.Test/UpStream/NELoginUpStreamTest.cs Vedi File

@@ -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<string>() { "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
}
}

+ 100
- 0
src/GBNewEnergy.Protocol.Test/UpStream/NELogoutUpStreamTest.cs Vedi File

@@ -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<string>() { "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
}
}

+ 52
- 0
src/GBNewEnergy.Protocol.Test/UpStream/NEPlatformLoginUpStreamTest.cs Vedi File

@@ -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
}
}

+ 67
- 0
src/GBNewEnergy.Protocol.Test/UpStream/NEPlatformLogoutUpStreamTest.cs Vedi File

@@ -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
}
}

+ 49
- 0
src/GBNewEnergy.Protocol/DownStream/NEControlDownStream.cs Vedi File

@@ -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
{
/// <summary>
/// 车载终端控制命令
/// </summary>
public class NEControlDownStream : NEBodies
{
public NEControlDownStream(byte[] buffer, NEGlobalConfigs nEConfigs) : base(buffer, nEConfigs)
{
}

public NEControlDownStream(INEProperties nEProperties, NEGlobalConfigs nEConfigs) : base(nEProperties, nEConfigs)
{
}

/// <summary>
/// 命令ID 只能发送一个
/// </summary>
public byte CmdId { get; set; }

/// <summary>
/// 命令参数
/// [{id,value},{id,value}], 没有内容则内容为空
/// </summary>
public List<KeyValuePair<byte, string>> 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);
}
}
}

+ 38
- 0
src/GBNewEnergy.Protocol/DownStream/NEQueryDownStream.cs Vedi File

@@ -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
{
/// <summary>
/// 查询命令
/// </summary>
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);
}
}
}

+ 37
- 0
src/GBNewEnergy.Protocol/DownStream/NESettingsDownStream.cs Vedi File

@@ -0,0 +1,37 @@
using GBNewEnergy.Protocol.Extensions;
using System;
using System.Collections.Generic;
using System.Text;

namespace GBNewEnergy.Protocol.DownStream
{
/// <summary>
/// 设置命令
/// </summary>
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);
}
}
}

+ 55
- 0
src/GBNewEnergy.Protocol/Enums/NEControlCmd.cs Vedi File

@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace GBNewEnergy.Protocol.Enums
{
/// <summary>
/// 车载终端控制命令枚举
/// 0x80-0x7F 预留
/// 0x80-0xFE 用户自定义
/// </summary>
public enum NEControlCmd:byte
{
/// <summary>
/// 未用
/// </summary>
unused= 0x00,
/// <summary>
/// 远程升级
/// </summary>
remoteupdate=0x01,
/// <summary>
/// 车载终端关机
/// </summary>
shutdown = 0x02,
/// <summary>
/// 车载终端复位
/// </summary>
reset = 0x03,
/// <summary>
/// 车载终端恢复出厂设置,其中包括本地存储时间周期、心跳发送时间周期、终端应答超时时间等等
/// </summary>
restorefactorysettings = 0x04,
/// <summary>
/// 断开数据通信链路
/// </summary>
interruptrequest = 0x05,
/// <summary>
/// 车载终端报警/预警,报警命令参数数据格式和定义见表B.17
/// </summary>
warning = 0x06,
/// <summary>
/// 开启抽样检测链路
/// </summary>
OpenMonitoring = 0x07,








}
}

+ 3
- 3
src/GBNewEnergy.Protocol/Enums/NEMsgId.cs Vedi File

@@ -42,15 +42,15 @@ namespace GBNewEnergy.Protocol.Enums
/// </summary>
checktime = 0x08,
/// <summary>
/// 查询应答
/// 查询命令
/// </summary>
query = 0x80,
/// <summary>
/// 设置应答
/// 设置命令
/// </summary>
settings = 0x81,
/// <summary>
/// 控制应答
/// 控制命令
/// </summary>
control = 0x82
}


+ 0
- 1
src/GBNewEnergy.Protocol/GBNewEnergy.Protocol.csproj Vedi File

@@ -24,7 +24,6 @@

<ItemGroup>
<Folder Include="DownStream\" />
<Folder Include="Properties\" />
</ItemGroup>



+ 8
- 1
src/GBNewEnergy.Protocol/NEBodiesFactory.cs Vedi File

@@ -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;
}


+ 14
- 0
src/GBNewEnergy.Protocol/NEProperties/NEEmptyProperty.cs Vedi File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace GBNewEnergy.Protocol.NEProperties
{
/// <summary>
/// 空包属性
/// </summary>
public class NEEmptyProperty : INEProperties
{
public string VIN { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
}
}

+ 37
- 0
src/GBNewEnergy.Protocol/UpStream/CommonUpStream.cs Vedi File

@@ -0,0 +1,37 @@
using GBNewEnergy.Protocol.Extensions;
using System;
using System.Collections.Generic;
using System.Text;

namespace GBNewEnergy.Protocol.UpStream
{
/// <summary>
/// 通用应答
/// </summary>
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);
}
}
}

Caricamento…
Annulla
Salva