浏览代码

1.增加位置实时上传枚举特性

2.增加Benchmark测试
3.修改文档
4.移除无用项目
tags/1.0.0
SmallChi 6 年前
父节点
当前提交
636315ca54
共有 78 个文件被更改,包括 0 次插入3778 次删除
  1. +0
    -125
      src/GBNewEnergy.Protocol.Test/DownStream/NEControlDownStreamTest.cs
  2. +0
    -28
      src/GBNewEnergy.Protocol.Test/GBNewEnergy.Protocol.Test.csproj
  3. +0
    -14
      src/GBNewEnergy.Protocol.Test/NEPackageBase.cs
  4. +0
    -18
      src/GBNewEnergy.Protocol.Test/NEPackageTest.cs
  5. +0
    -152
      src/GBNewEnergy.Protocol.Test/UpStream/CommonUpStreamTest.cs
  6. +0
    -67
      src/GBNewEnergy.Protocol.Test/UpStream/NELoginUpStreamTest.cs
  7. +0
    -100
      src/GBNewEnergy.Protocol.Test/UpStream/NELogoutUpStreamTest.cs
  8. +0
    -52
      src/GBNewEnergy.Protocol.Test/UpStream/NEPlatformLoginUpStreamTest.cs
  9. +0
    -67
      src/GBNewEnergy.Protocol.Test/UpStream/NEPlatformLogoutUpStreamTest.cs
  10. +0
    -92
      src/GBNewEnergy.Protocol/DownStream/NEControlDownStream.cs
  11. +0
    -23
      src/GBNewEnergy.Protocol/DownStream/NELoginDownStream.cs
  12. +0
    -38
      src/GBNewEnergy.Protocol/DownStream/NEQueryDownStream.cs
  13. +0
    -37
      src/GBNewEnergy.Protocol/DownStream/NESettingsDownStream.cs
  14. +0
    -18
      src/GBNewEnergy.Protocol/Enums/NEAlarmLevel.cs
  15. +0
    -29
      src/GBNewEnergy.Protocol/Enums/NEAskId.cs
  16. +0
    -55
      src/GBNewEnergy.Protocol/Enums/NEControlCmd.cs
  17. +0
    -19
      src/GBNewEnergy.Protocol/Enums/NEEncryptMethod.cs
  18. +0
    -22
      src/GBNewEnergy.Protocol/Enums/NEErrorCode.cs
  19. +0
    -25
      src/GBNewEnergy.Protocol/Enums/NEInfoType.cs
  20. +0
    -57
      src/GBNewEnergy.Protocol/Enums/NEMsgId.cs
  21. +0
    -23
      src/GBNewEnergy.Protocol/Exceptions/NEException.cs
  22. +0
    -135
      src/GBNewEnergy.Protocol/Extensions/EnumExtensions.cs
  23. +0
    -139
      src/GBNewEnergy.Protocol/Extensions/NEExtensions.cs
  24. +0
    -30
      src/GBNewEnergy.Protocol/GBNewEnergy.Protocol.csproj
  25. +0
    -12
      src/GBNewEnergy.Protocol/INEEncrypt.cs
  26. +0
    -14
      src/GBNewEnergy.Protocol/INEParameter.cs
  27. +0
    -10
      src/GBNewEnergy.Protocol/INEProperties.cs
  28. +0
    -56
      src/GBNewEnergy.Protocol/NEBodies.cs
  29. +0
    -43
      src/GBNewEnergy.Protocol/NEBodiesFactory.cs
  30. +0
    -41
      src/GBNewEnergy.Protocol/NEBufferedEntityBase.cs
  31. +0
    -11
      src/GBNewEnergy.Protocol/NEDownStreamBase.cs
  32. +0
    -28
      src/GBNewEnergy.Protocol/NEEncryptFactory.cs
  33. +0
    -58
      src/GBNewEnergy.Protocol/NEEncrypts/Default_NEAES128EncryptImpl.cs
  34. +0
    -193
      src/GBNewEnergy.Protocol/NEEncrypts/Default_NERSAEncryptImpl.cs
  35. +0
    -90
      src/GBNewEnergy.Protocol/NEEncrypts/Default_NERSAEncryptImpl_NET.cs
  36. +0
    -14
      src/GBNewEnergy.Protocol/NEEncrypts/NEAESBase.cs
  37. +0
    -45
      src/GBNewEnergy.Protocol/NEEncrypts/NERSABase.cs
  38. +0
    -27
      src/GBNewEnergy.Protocol/NEGlobalConfigs.cs
  39. +0
    -40
      src/GBNewEnergy.Protocol/NEHeader.cs
  40. +0
    -143
      src/GBNewEnergy.Protocol/NEPackage.cs
  41. +0
    -18
      src/GBNewEnergy.Protocol/NEProperties/NEControlAlarmParameter.cs
  42. +0
    -27
      src/GBNewEnergy.Protocol/NEProperties/NEControlProperty.cs
  43. +0
    -57
      src/GBNewEnergy.Protocol/NEProperties/NEControlUpgradeParameter.cs
  44. +0
    -14
      src/GBNewEnergy.Protocol/NEProperties/NEEmptyProperty.cs
  45. +0
    -19
      src/GBNewEnergy.Protocol/NEProperties/NELoginProperty.cs
  46. +0
    -11
      src/GBNewEnergy.Protocol/NEProperties/NELogoutProperty.cs
  47. +0
    -15
      src/GBNewEnergy.Protocol/NEProperties/NEPackageProperty.cs
  48. +0
    -27
      src/GBNewEnergy.Protocol/NEProperties/NEPlatformLoginProperty.cs
  49. +0
    -16
      src/GBNewEnergy.Protocol/NEProperties/NEPlatformLogoutProperty.cs
  50. +0
    -60
      src/GBNewEnergy.Protocol/NEProperties/NEUploadProperties/NEUploadAlarmProperty.cs
  51. +0
    -63
      src/GBNewEnergy.Protocol/NEProperties/NEUploadProperties/NEUploadDrivenElectricalProperty.cs
  52. +0
    -60
      src/GBNewEnergy.Protocol/NEProperties/NEUploadProperties/NEUploadEnergyStorageProperty.cs
  53. +0
    -43
      src/GBNewEnergy.Protocol/NEProperties/NEUploadProperties/NEUploadEnergyStorageTemperatureProperty.cs
  54. +0
    -39
      src/GBNewEnergy.Protocol/NEProperties/NEUploadProperties/NEUploadEnginePartProperty.cs
  55. +0
    -94
      src/GBNewEnergy.Protocol/NEProperties/NEUploadProperties/NEUploadExtremeProperty.cs
  56. +0
    -103
      src/GBNewEnergy.Protocol/NEProperties/NEUploadProperties/NEUploadFuelBatteryProperty.cs
  57. +0
    -26
      src/GBNewEnergy.Protocol/NEProperties/NEUploadProperties/NEUploadProperty.cs
  58. +0
    -12
      src/GBNewEnergy.Protocol/NEProperties/NEUploadProperties/NEUploadPropertyBase.cs
  59. +0
    -33
      src/GBNewEnergy.Protocol/NEProperties/NEUploadProperties/NEUploadVehiclePositionProperty.cs
  60. +0
    -72
      src/GBNewEnergy.Protocol/NEProperties/NEUploadProperties/NEUploadVehicleProperty.cs
  61. +0
    -14
      src/GBNewEnergy.Protocol/NEUpStreamBase.cs
  62. +0
    -37
      src/GBNewEnergy.Protocol/UpStream/CommonUpStream.cs
  63. +0
    -106
      src/GBNewEnergy.Protocol/UpStream/NELoginUpStream.cs
  64. +0
    -50
      src/GBNewEnergy.Protocol/UpStream/NELogoutUpStream.cs
  65. +0
    -88
      src/GBNewEnergy.Protocol/UpStream/NEPlatformLoginUpStream.cs
  66. +0
    -47
      src/GBNewEnergy.Protocol/UpStream/NEPlatformLogoutUpStream.cs
  67. +0
    -38
      src/GBNewEnergy.Protocol/UpStream/NERealUploadUpStream.cs
  68. +0
    -56
      src/GBNewEnergy.sln
  69. 二进制
      src/NEEncrypts.Tests/NEEncrypts for linux.png
  70. +0
    -53
      src/NEEncrypts.Tests/NEEncryptsNET4.Test/NEEncryptsNET4.Test.csproj
  71. +0
    -46
      src/NEEncrypts.Tests/NEEncryptsNET4.Test/Program.cs
  72. +0
    -36
      src/NEEncrypts.Tests/NEEncryptsNET4.Test/Properties/AssemblyInfo.cs
  73. +0
    -6
      src/NEEncrypts.Tests/NEEncryptsNET45.Test/App.config
  74. +0
    -57
      src/NEEncrypts.Tests/NEEncryptsNET45.Test/NEEncryptsNET45.Test.csproj
  75. +0
    -45
      src/NEEncrypts.Tests/NEEncryptsNET45.Test/Program.cs
  76. +0
    -36
      src/NEEncrypts.Tests/NEEncryptsNET45.Test/Properties/AssemblyInfo.cs
  77. +0
    -12
      src/NEEncrypts.Tests/NEEncryptsNETCore.Test/NEEncryptsNETCore.Test.csproj
  78. +0
    -52
      src/NEEncrypts.Tests/NEEncryptsNETCore.Test/Program.cs

+ 0
- 125
src/GBNewEnergy.Protocol.Test/DownStream/NEControlDownStreamTest.cs 查看文件

@@ -1,125 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using Xunit;
using GBNewEnergy.Protocol.Extensions;
using GBNewEnergy.Protocol.NEProperties;
using GBNewEnergy.Protocol.DownStream;
using GBNewEnergy.Protocol.Enums;
namespace GBNewEnergy.Protocol.Test.DownStream
{
public class NEControlDownStreamTest : NEPackageBase
{
#region NEControlCmd.unused
[Fact]
public void NEControlDownStreamConstructor4_1()
{
NEControlProperty nEControlProperty = new NEControlProperty
{
VIN = "LGHC4V1D3HE202652",
CmdID=NEControlCmd.unused,
UpgradeParameter=new NEControlUpgradeParameter {
DialPassword = "123",
DialPointName = "xyz",
DialUserName = "11"
}
};
NEControlDownStream nEControlDownStream = new NEControlDownStream(nEControlProperty, NEGlobalConfigs);
INEProperties nEPackageProperty = new NEPackageProperty
{
Bodies = nEControlDownStream,
MsgId = Enums.NEMsgId.control,
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 NEControlDownStreamConstructor4_2()
{
byte[] packageBytes = "23 23 82 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 07 12 06 0E 0A 0E 1B 00 57".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 NEControlCmd.remoteupdate
[Fact]
public void NEControlDownStreamConstructor4_3()
{
NEControlProperty nEControlProperty = new NEControlProperty
{
VIN = "LGHC4V1D3HE202652",
CmdID = NEControlCmd.remoteupdate,
UpgradeParameter=new NEControlUpgradeParameter {
DialPassword = "123",
DialPointName = "xyz",
DialUserName = "11"
}
};
NEControlDownStream nEControlDownStream = new NEControlDownStream(nEControlProperty, NEGlobalConfigs);
INEProperties nEPackageProperty = new NEPackageProperty
{
Bodies = nEControlDownStream,
MsgId = Enums.NEMsgId.control,
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 NEControlDownStreamConstructor4_4()
{
byte[] packageBytes = "23 23 82 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 18 12 06 0E 0A 22 0B 01 3B 78 79 7A 3B 31 31 3B 31 32 33 3B 3B 3B 3B 3B 3B 05".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 NEControlCmd.warning
[Fact]
public void NEControlDownStreamConstructor4_5()
{
NEControlProperty nEControlProperty = new NEControlProperty
{
VIN = "LGHC4V1D3HE202652",
CmdID = NEControlCmd.warning,
AlarmParameter= new NEControlAlarmParameter { nEAlarmLevel= NEAlarmLevel.一级报警 }
};
NEControlDownStream nEControlDownStream = new NEControlDownStream(nEControlProperty, NEGlobalConfigs);
INEProperties nEPackageProperty = new NEPackageProperty
{
Bodies = nEControlDownStream,
MsgId = Enums.NEMsgId.control,
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 NEControlDownStreamConstructor4_6()
{
byte[] packageBytes = "23 23 82 FE 4C 47 48 43 34 56 31 44 33 48 45 32 30 32 36 35 32 01 00 08 12 06 0E 0B 2C 0B 06 01 6C".ToHexBytes();
NEPackage nEPackage = new NEPackage(packageBytes, NEGlobalConfigs);
string headerHex = nEPackage.Header.ToHexString();
string bodiesHex = nEPackage.Bodies.Buffer.ToHexString();
string packageHex = nEPackage.Buffer.ToHexString();
}
#endregion
}
}

+ 0
- 28
src/GBNewEnergy.Protocol.Test/GBNewEnergy.Protocol.Test.csproj 查看文件

@@ -1,28 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<LangVersion>7.2</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<LangVersion>7.2</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GBNewEnergy.Protocol\GBNewEnergy.Protocol.csproj" />
</ItemGroup>

</Project>

+ 0
- 14
src/GBNewEnergy.Protocol.Test/NEPackageBase.cs 查看文件

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

namespace GBNewEnergy.Protocol.Test
{
public class NEPackageBase
{
public readonly NEGlobalConfigs NEGlobalConfigs = new NEGlobalConfigs()
{

};
}
}

+ 0
- 18
src/GBNewEnergy.Protocol.Test/NEPackageTest.cs 查看文件

@@ -1,18 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using Xunit;
using GBNewEnergy.Protocol.Extensions;
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: NEPackageBase
{

}
}

+ 0
- 152
src/GBNewEnergy.Protocol.Test/UpStream/CommonUpStreamTest.cs 查看文件

@@ -1,152 +0,0 @@
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
}
}

+ 0
- 67
src/GBNewEnergy.Protocol.Test/UpStream/NELoginUpStreamTest.cs 查看文件

@@ -1,67 +0,0 @@
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
}
}

+ 0
- 100
src/GBNewEnergy.Protocol.Test/UpStream/NELogoutUpStreamTest.cs 查看文件

@@ -1,100 +0,0 @@
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
}
}

+ 0
- 52
src/GBNewEnergy.Protocol.Test/UpStream/NEPlatformLoginUpStreamTest.cs 查看文件

@@ -1,52 +0,0 @@
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
}
}

+ 0
- 67
src/GBNewEnergy.Protocol.Test/UpStream/NEPlatformLogoutUpStreamTest.cs 查看文件

@@ -1,67 +0,0 @@
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
}
}

+ 0
- 92
src/GBNewEnergy.Protocol/DownStream/NEControlDownStream.cs 查看文件

@@ -1,92 +0,0 @@
using GBNewEnergy.Protocol.Enums;
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 NEControlCmd CmdID { get; set; }
/// <summary>
/// 命令参数 没有内容则内容为空
/// </summary>
public string CmdParameter { get; set; }
protected override void InitializeProperties(INEProperties nEProperties)
{
NEControlProperty nEControlProperty = (NEControlProperty)nEProperties;
CmdID = nEControlProperty.CmdID;
if (CmdID == NEControlCmd.remoteupdate)
{
CmdParameter = nEControlProperty.UpgradeParameter.ToString();
}
else if(CmdID == NEControlCmd.warning)
{
CmdParameter = nEControlProperty.AlarmParameter.nEAlarmLevel.ToString();
}
}
protected override void InitializePropertiesFromBuffer()
{
CurrentDateTime = Buffer.ReadDateTimeLittle(0, 6);
CmdID = (NEControlCmd)Buffer[6];
switch (CmdID)
{
case NEControlCmd.remoteupdate:
CmdParameter = Buffer.ReadStringLittle(7, Buffer.Length - 8);//最后一位为校验码,不在参数列
break;
case NEControlCmd.warning:
CmdParameter = ((NEAlarmLevel)Buffer[7]).ToString();
break;
case NEControlCmd.unused:
case NEControlCmd.shutdown:
case NEControlCmd.reset:
case NEControlCmd.restorefactorysettings:
case NEControlCmd.interruptrequest:
case NEControlCmd.OpenMonitoring:
default:
break;
}
}
protected override void ToBuffer()
{
if (CmdID == NEControlCmd.remoteupdate)
{
var contentLength = NEConfigs.NEEncoding.GetBytes(CmdParameter).Length;
Buffer = new byte[6 + 1 + contentLength];
Buffer.WriteLittle(CurrentDateTime, 0, 6);
Buffer.WriteLittle(CmdID.ToByteValue(), 6);
Buffer.WriteLittle(CmdParameter, 7);
}
else if (CmdID == NEControlCmd.warning) {
Buffer = new byte[6 + 1 + 1];
Buffer.WriteLittle(CurrentDateTime, 0, 6);
Buffer.WriteLittle(CmdID.ToByteValue(), 6);
Buffer.WriteLittle(CmdParameter.ToEnum<NEAlarmLevel>().ToByteValue(), 7);
}
else
{
Buffer = new byte[6 + 1];
Buffer.WriteLittle(CurrentDateTime, 0, 6);
Buffer.WriteLittle(CmdID.ToByteValue(), 6);
}
}
}
}

+ 0
- 23
src/GBNewEnergy.Protocol/DownStream/NELoginDownStream.cs 查看文件

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

namespace GBNewEnergy.Protocol.Response
{
public class NELoginDownStream : NEBodies
{
protected NELoginDownStream(byte[] buffer) : base(buffer)
{
}

protected NELoginDownStream(string vin) : base(vin)
{

}

public override void ToBuffer()
{
throw new NotImplementedException();
}
}
}

+ 0
- 38
src/GBNewEnergy.Protocol/DownStream/NEQueryDownStream.cs 查看文件

@@ -1,38 +0,0 @@
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);
}
}
}

+ 0
- 37
src/GBNewEnergy.Protocol/DownStream/NESettingsDownStream.cs 查看文件

@@ -1,37 +0,0 @@
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);
}
}
}

+ 0
- 18
src/GBNewEnergy.Protocol/Enums/NEAlarmLevel.cs 查看文件

@@ -1,18 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace GBNewEnergy.Protocol.Enums
{
/// <summary>
/// 报警等级
/// </summary>
public enum NEAlarmLevel:byte
{
无报警 = 0x00,
一级报警 = 0x01,
二级报警 = 0x02,
三级报警 = 0x03,
无效数据 = 0xFF
}
}

+ 0
- 29
src/GBNewEnergy.Protocol/Enums/NEAskId.cs 查看文件

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

namespace GBNewEnergy.Protocol.Enums
{
/// <summary>
/// 应答标志
/// </summary>
public enum NEAskId:byte
{
/// <summary>
/// 接收到的信息正确
/// </summary>
success=0x01,
/// <summary>
/// 设置未成功
/// </summary>
error=0x02,
/// <summary>
/// VIN重复错误
/// </summary>
vin_repeat_error=0x03,
/// <summary>
/// 数据包为命令包,而非应答包
/// </summary>
cmd=0xFE
}
}

+ 0
- 55
src/GBNewEnergy.Protocol/Enums/NEControlCmd.cs 查看文件

@@ -1,55 +0,0 @@
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>
/// 远程升级 见表B.16
/// </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,








}
}

+ 0
- 19
src/GBNewEnergy.Protocol/Enums/NEEncryptMethod.cs 查看文件

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

namespace GBNewEnergy.Protocol.Enums
{
/// <summary>
/// 数据单元加密方式
/// 0x01:数据不加密;0x02:数据经过 RSA 算法加密;0x03:数据经过 AES128 位算法加密;“0xFE”表示异常,“0xFF”表示无效
/// </summary>
public enum NEEncryptMethod:byte
{
None= 0x01,
RSA= 0x02,
AES128=0x03,
Exception = 0xFE,
Invalid= 0xFF
}
}

+ 0
- 22
src/GBNewEnergy.Protocol/Enums/NEErrorCode.cs 查看文件

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

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

+ 0
- 25
src/GBNewEnergy.Protocol/Enums/NEInfoType.cs 查看文件

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

namespace GBNewEnergy.Protocol.Enums
{
/// <summary>
/// 信息类型标志
/// </summary>
public enum NEInfoType:byte
{
整车数据=0x01,
驱动电机数据=0x02,
燃料电池数据=0x03,
发动机数据=0x04,
车辆位置数据=0x05,
极值数据=0x06,
报警数据=0x07,
可充电储能装置电压数据=0x08,
可充电储能装置温度数据 = 0x09,
平台交换协议自定义数据 =0x0A,
预留=0x30,
用户自定义=0x80
}
}

+ 0
- 57
src/GBNewEnergy.Protocol/Enums/NEMsgId.cs 查看文件

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

namespace GBNewEnergy.Protocol.Enums
{
/// <summary>
/// 命令单元
/// </summary>
public enum NEMsgId:byte
{
/// <summary>
/// 车辆登入
/// </summary>
login = 0x01,
/// <summary>
/// 实时信息上传
/// </summary>
uploadim = 0x02,
/// <summary>
/// 补传信息上传
/// </summary>
uploadsup = 0x03,
/// <summary>
/// 车辆登出
/// </summary>
loginout = 0x04,
/// <summary>
/// 平台登入
/// </summary>
platformlogin = 0x05,
/// <summary>
/// 平台登出
/// </summary>
platformlogout = 0x06,
/// <summary>
/// 心跳
/// </summary>
heartbeat = 0x07,
/// <summary>
/// 终端校时
/// </summary>
checktime = 0x08,
/// <summary>
/// 查询命令
/// </summary>
query = 0x80,
/// <summary>
/// 设置命令
/// </summary>
settings = 0x81,
/// <summary>
/// 控制命令
/// </summary>
control = 0x82
}
}

+ 0
- 23
src/GBNewEnergy.Protocol/Exceptions/NEException.cs 查看文件

@@ -1,23 +0,0 @@
using GBNewEnergy.Protocol.Enums;
using System;
using System.Collections.Generic;
using System.Text;

namespace GBNewEnergy.Protocol.Exceptions
{
public class NEException:Exception
{
public NEException(NEErrorCode errorCode) : base(errorCode.ToString())
{
this.ErrorCode = errorCode;
}

public NEException(NEErrorCode errorCode, string message) : base(message)
{
this.ErrorCode = errorCode;
}


public NEErrorCode ErrorCode { get; }
}
}

+ 0
- 135
src/GBNewEnergy.Protocol/Extensions/EnumExtensions.cs 查看文件

@@ -1,135 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
namespace GBNewEnergy.Protocol.Extensions
{
/// <summary>
/// 枚举扩展
/// </summary>
internal static class EnumExtensions
{
/// <summary>
/// 转为整型
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="t"></param>
/// <returns></returns>
public static int ToValue<T>(this T t) where T : struct
{
return Convert.ToInt32(t);
}
/// <summary>
/// 转为Byte
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="t"></param>
/// <returns></returns>
public static byte ToByteValue<T>(this T t) where T : struct
{
return Convert.ToByte(t);
}
/// <summary>
/// 字符转枚举
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value"></param>
/// <returns></returns>
public static T ToEnum<T>(this string value) where T : struct
{
return (T)Enum.Parse(typeof(T), value);
}
/// <summary>
/// 获取枚举字符串
/// </summary>
/// <param name="valueEnum"></param>
public static string GetName(this Enum valueEnum)
{
return valueEnum.ToString();
}
/// <summary>
/// 获取DescriptionAttribute特性枚举值的描述
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string GetDescription(this Enum value)
{
var attribute = value.GetAttribute<DescriptionAttribute>();
return attribute == null ? value.ToString() : attribute.Description;
}
/// <summary>
/// 验证是否是枚举类型
/// </summary>
/// <typeparam name="TEnum"></typeparam>
/// <param name="enumValue"></param>
/// <returns></returns>
public static bool IsEnumValid<TEnum>(this int enumValue)
{
return Enum.IsDefined(typeof(TEnum), enumValue);
}
/// <summary>
/// 获取DescriptionAttribute特性枚举及描述
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public static Dictionary<string, string> GetDescriptionAttributeDictionary(this Enum value)
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
var fields = value.GetType().GetFields(BindingFlags.Static | BindingFlags.Public);
foreach (var fi in fields)
{
DescriptionAttribute attr = Attribute.GetCustomAttribute(fi, typeof(DescriptionAttribute), false) as DescriptionAttribute;
dictionary.Add(fi.Name, attr != null ? attr.Description : "");
}
return dictionary;
}
/// <summary>
/// 获取DisplayNameAttribute特性枚举值的描述
/// </summary>
/// <param name="obj">枚举值</param>
/// <returns></returns>
public static string GetDisplayName(this Enum value)
{
var attribute = value.GetAttribute<DisplayNameAttribute>();
return attribute == null ? value.ToString() : attribute.DisplayName;
}
/// <summary>
/// 获取DisplayNameAttribute特性枚举及描述
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public static Dictionary<string, string> GetDisplayNameAttributeDictionary(this Enum value)
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
var fields = value.GetType().GetFields(BindingFlags.Static | BindingFlags.Public);
foreach (var fi in fields)
{
DisplayNameAttribute attr = Attribute.GetCustomAttribute(fi, typeof(DisplayNameAttribute), false) as DisplayNameAttribute;
dictionary.Add(fi.Name, attr != null ? attr.DisplayName : "");
}
return dictionary;
}
/// <summary>
/// 获取枚举对应特性
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value"></param>
/// <returns></returns>
public static T GetAttribute<T>(this Enum value) where T : Attribute
{
var type = value.GetType();
var memberInfo = type.GetMember(value.ToString());
var attributes = memberInfo[0].GetCustomAttributes(typeof(T), false);
return (T)attributes[0];
}
}
}

+ 0
- 139
src/GBNewEnergy.Protocol/Extensions/NEExtensions.cs 查看文件

@@ -1,139 +0,0 @@
using System;
using System.IO;
using System.Linq;
using System.Text;

namespace GBNewEnergy.Protocol.Extensions
{
public static class NEExtensions
{
/// <summary>
/// 日期限制于2000年
/// </summary>
private const int DateLimitYear = 2000;

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++]);
}

public static ushort ReadUShortH2LLittle(this byte[] read, int offset, int len)
{
int result = 0;
for (int i = offset; i < offset + len; i++)
{
result += read[i] * (int)Math.Pow(256, len + offset - i - 1);
}
return (ushort)result;
}

public static string ReadStringLittle(this byte[] read, int offset, int len,Encoding coding)
{
return coding.GetString(read, offset, len).Trim('\0');
}

public static string ReadStringLittle(this byte[] read, int offset, int len)
{
return Encoding.ASCII.GetString(read, offset, len).Trim('\0');
}

public static void WriteLittle(this byte[] write,string str, int offset, Encoding coding)
{
byte[] strByte = coding.GetBytes(str);
Array.Copy(strByte, 0, write, offset, strByte.Length);
}

public static void WriteLittle(this byte[] write, string str, int offset)
{
byte[] strByte = Encoding.ASCII.GetBytes(str);
Array.Copy(strByte, 0, write, offset, strByte.Length);
}

public static void WriteLittle(this byte[] write,int data ,int offset,int len)
{
int n = 1;
for (int i = 0; i < len; i++)
{
write[offset] = (byte)(data >> 8 * (len - n));
n++;
offset++;
}
}

public static void WriteLittle(this byte[] write, ushort data, int offset, int len)
{
int n = 1;
for (int i = 0; i < len; i++)
{
write[offset] = (byte)(data >> 8 * (len - n));
n++;
offset++;
}
}

public static void WriteLittle(this byte[] write, byte[] bytes, int offset, int len)
{
Array.Copy(bytes, 0, write, offset, len);
}

public static void WriteLittle(this byte[] write, byte bit, int offset)
{
write[offset] = bit;
}

public static void WriteLittle(this byte[] write, DateTime date, int offset,int len)
{
write[offset++] = (byte)(date.Year - DateLimitYear);
write[offset++] = (byte)date.Month;
write[offset++] = (byte)date.Day;
write[offset++] = (byte)date.Hour;
write[offset++] = (byte)date.Minute;
write[offset++] = (byte)date.Second;
}

/// <summary>
/// 异或
/// </summary>
/// <param name="buf"></param>
/// <param name="offset"></param>
/// <param name="len"></param>
/// <returns></returns>
public static byte ToXor(this byte[] buf, int offset, int len)
{
byte result = buf[offset];
for (int i = offset + 1; i < offset + len; i++)
{
result = (byte)(result ^ buf[i]);
}
return result;
}

/// <summary>
/// 字节数组转16进制字符串
/// </summary>
/// <param name="bytes"></param>
/// <param name="separator">默认 " "</param>
/// <returns></returns>
public static string ToHexString(this byte[] bytes,string separator=" ")
{
return string.Join(separator, bytes.Select(s => s.ToString("X2")));
}

/// <summary>
/// 16进制字符串转16进制数组
/// </summary>
/// <param name="hexString"></param>
/// <param name="separator"></param>
/// <returns></returns>
public static byte[] ToHexBytes(this string hexString, string separator = " ")
{
return hexString.Split(new string[] { separator }, StringSplitOptions.RemoveEmptyEntries).Select(s => Convert.ToByte(s, 16)).ToArray();
}
}
}

+ 0
- 30
src/GBNewEnergy.Protocol/GBNewEnergy.Protocol.csproj 查看文件

@@ -1,30 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net40;net45</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<Compile Remove="DownStream\NELoginDownStream.cs" />
<Compile Remove="IBuffer.cs" />
<Compile Remove="IBuffered.cs" />
<Compile Remove="NEDownStreamBase.cs" />
<Compile Remove="NEEncryptFactory.cs" />
<Compile Remove="NEEncrypts\NEAES128EncryptImpl_NetCore2.cs" />
<Compile Remove="NEHeader.cs" />
<Compile Remove="NEUpStreamBase.cs" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net40' ">
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
</ItemGroup>


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

</Project>

+ 0
- 12
src/GBNewEnergy.Protocol/INEEncrypt.cs 查看文件

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

namespace GBNewEnergy.Protocol
{
public interface INEEncrypt
{
byte[] Encrypt(byte[] buffer);
byte[] Decrypt(byte[] buffer);
}
}

+ 0
- 14
src/GBNewEnergy.Protocol/INEParameter.cs 查看文件

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

namespace GBNewEnergy.Protocol
{
public interface INEParameter
{
/// <summary>
/// 车架号
/// </summary>
string VIN { get; set; }
}
}

+ 0
- 10
src/GBNewEnergy.Protocol/INEProperties.cs 查看文件

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

namespace GBNewEnergy.Protocol
{
public interface INEProperties:INEParameter
{
}
}

+ 0
- 56
src/GBNewEnergy.Protocol/NEBodies.cs 查看文件

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

namespace GBNewEnergy.Protocol
{
public abstract class NEBodies : NEBufferedEntityBase
{
/// <summary>
/// VIN - 登入流水号,过期时间(每天置1)
/// 车载终端登入一次,登入流水号自动加1,从1开始循环累加,最大值为65531,循环周期为天
/// </summary>
protected static readonly ConcurrentDictionary<string, LoginInfo> LoginNumDict;

/// <summary>
/// 平台登入 登录流水号,过期时间(每天置1)
/// 下级平台登入一次,登入流水号自动加1,从1开始循环累加,最大值为65531,循环周期为天
/// </summary>
protected static readonly ConcurrentDictionary<string, PlatformLoginInfo> PlatformLoginNumDict;

static NEBodies()
{
LoginNumDict = new ConcurrentDictionary<string, LoginInfo>();
PlatformLoginNumDict = new ConcurrentDictionary<string, PlatformLoginInfo>();
}

/// <summary>
/// 登入流水号
/// 作用:看数据是否是连续请求
/// </summary>
public ushort LoginNum { get; set; }

/// <summary>
/// 数据采集时间
/// 采用北京时间
/// </summary>
public DateTime CurrentDateTime { get; set; } = DateTime.Now;

protected NEBodies(byte[] buffer, NEGlobalConfigs nEConfigs) : base(buffer, nEConfigs) { }

protected NEBodies(INEProperties nEProperties, NEGlobalConfigs nEConfigs) : base(nEProperties, nEConfigs) { }

protected class LoginInfo
{
public ushort LoginNum { get; set; }
public DateTime ExpirationTime { get; set; }
}

protected class PlatformLoginInfo
{
public ushort LoginNum { get; set; }
public DateTime ExpirationTime { get; set; }
}
}
}

+ 0
- 43
src/GBNewEnergy.Protocol/NEBodiesFactory.cs 查看文件

@@ -1,43 +0,0 @@
using GBNewEnergy.Protocol.DownStream;
using GBNewEnergy.Protocol.Enums;
using GBNewEnergy.Protocol.UpStream;
using System;
using System.Collections.Generic;
using System.Text;
namespace GBNewEnergy.Protocol
{
public class NEBodiesFactory
{
/// <summary>
/// 通过命令id获取数据体
/// </summary>
/// <param name="msgId"></param>
/// <param name="buf"></param>
/// <returns></returns>
public static NEBodies GetNEBodiesByMsgId(NEMsgId msgId,byte[] buf, NEGlobalConfigs nEConfigs)
{
switch (msgId)
{
case NEMsgId.login:
return new NELoginUpStream(buf, nEConfigs);
case NEMsgId.uploadim:
return new NERealUploadUpStream(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);
case NEMsgId.control:
return new NEControlDownStream(buf, nEConfigs);
case NEMsgId.settings:
case NEMsgId.heartbeat:
case NEMsgId.checktime:
return new CommonUpStream(buf, nEConfigs);
default:
return null;
}
}
}
}

+ 0
- 41
src/GBNewEnergy.Protocol/NEBufferedEntityBase.cs 查看文件

@@ -1,41 +0,0 @@
using System;
using System.IO;

namespace GBNewEnergy.Protocol
{
public abstract class NEBufferedEntityBase
{
public byte[] Buffer { get; protected set; }

public NEGlobalConfigs NEConfigs { get;}

protected NEBufferedEntityBase(byte[] buffer, NEGlobalConfigs nEConfigs)
{
NEConfigs = nEConfigs;
Buffer = buffer;
InitializePropertiesFromBuffer();
}

protected NEBufferedEntityBase(byte[] headerBuffer, byte[] bodyBuffer, NEGlobalConfigs nEConfigs)
{
NEConfigs = nEConfigs;
Buffer = new byte[headerBuffer.Length + bodyBuffer.Length];
Array.Copy(headerBuffer, 0, Buffer, 0, headerBuffer.Length);
Array.Copy(bodyBuffer, 0, Buffer, headerBuffer.Length, bodyBuffer.Length);
InitializePropertiesFromBuffer();
}

protected NEBufferedEntityBase(INEProperties nEProperties,NEGlobalConfigs nEConfigs)
{
NEConfigs = nEConfigs;
InitializeProperties(nEProperties);
ToBuffer();
}

protected abstract void InitializeProperties(INEProperties nEProperties);

protected abstract void ToBuffer();

protected abstract void InitializePropertiesFromBuffer();
}
}

+ 0
- 11
src/GBNewEnergy.Protocol/NEDownStreamBase.cs 查看文件

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

namespace GBNewEnergy.Protocol
{
public abstract class NEDownStreamBase
{

}
}

+ 0
- 28
src/GBNewEnergy.Protocol/NEEncryptFactory.cs 查看文件

@@ -1,28 +0,0 @@
using GBNewEnergy.Protocol.Enums;
using GBNewEnergy.Protocol.NEEncrypts;
using System;
using System.Collections.Generic;
using System.Text;

namespace GBNewEnergy.Protocol
{
internal class NEEncryptFactory
{
internal static INEEncrypt GetNEEncrypt(NEEncryptMethod nEEncryptMethod, NEGlobalConfigs nEConfigs)
{
switch (nEEncryptMethod)
{
case NEEncryptMethod.None:
case NEEncryptMethod.Invalid:
case NEEncryptMethod.Exception:
return null;
case NEEncryptMethod.AES128:
return new NEAES128EncryptImpl(nEConfigs);
case NEEncryptMethod.RSA:
return new NERSAEncryptImpl(nEConfigs);
default:
return null;
}
}
}
}

+ 0
- 58
src/GBNewEnergy.Protocol/NEEncrypts/Default_NEAES128EncryptImpl.cs 查看文件

@@ -1,58 +0,0 @@
using System.IO;
using System.Security.Cryptography;

namespace GBNewEnergy.Protocol.NEEncrypts
{
public class Default_NEAES128EncryptImpl : NEAESBase
{
public override string PrivateKey { get; }

public override byte[] SaltBytes { get; }

public Default_NEAES128EncryptImpl(string privateKey)
{
PrivateKey = privateKey;
SaltBytes = new byte[9] { 13, 34, 27, 67, 189, 255, 104, 219, 122 };
}

public Default_NEAES128EncryptImpl(string privateKey, byte[] saltBytes)
{
PrivateKey = privateKey;
SaltBytes = saltBytes;
}

public override byte[] Encrypt(byte[] buffer)
{
using (Aes encryptor = Aes.Create())
{
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(PrivateKey, SaltBytes);
encryptor.Key = pdb.GetBytes(32);
encryptor.IV = pdb.GetBytes(16);
using (MemoryStream ms = new MemoryStream())
using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(),CryptoStreamMode.Write))
{
cs.Write(buffer, 0, buffer.Length);
cs.Close();
return ms.ToArray();
}
}
}

public override byte[] Decrypt(byte[] buffer)
{
using (Aes encryptor = Aes.Create())
{
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(PrivateKey, SaltBytes);
encryptor.Key = pdb.GetBytes(32);
encryptor.IV = pdb.GetBytes(16);
using (MemoryStream ms = new MemoryStream())
using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(),CryptoStreamMode.Write))
{
cs.Write(buffer, 0, buffer.Length);
cs.Close();
return ms.ToArray();
}
}
}
}
}

+ 0
- 193
src/GBNewEnergy.Protocol/NEEncrypts/Default_NERSAEncryptImpl.cs 查看文件

@@ -1,193 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Xml;

namespace GBNewEnergy.Protocol.NEEncrypts
{
#if NETSTANDARD2_0
public class Default_NERSAEncryptImpl : NERSABase
{
private readonly RSA _privateKeyRsaProvider;
private readonly RSA _publicKeyRsaProvider;
private readonly Encoding _encoding;

public override string HashAlgorithmStr=>throw new NotImplementedException();

public override string PublicKey { get; }

public override string PrivateKey { get; }

public override HashAlgorithmName HashAlgorithmName { get; }

public Default_NERSAEncryptImpl(Encoding encoding, HashAlgorithmName hashAlgorithmName, string publicKey, string privateKey)
{
_privateKeyRsaProvider = CreateRsaProviderFromPrivateKey(privateKey);
_publicKeyRsaProvider = CreateRsaProviderFromPublicKey(publicKey);
HashAlgorithmName = hashAlgorithmName;
_encoding = encoding;
PublicKey = publicKey;
PrivateKey = privateKey;
}

public override byte[] Decrypt(byte[] buffer)
{
return _privateKeyRsaProvider.Decrypt(buffer, RSAEncryptionPadding.Pkcs1);
}

public override byte[] Encrypt(byte[] buffer)
{
return _publicKeyRsaProvider.Encrypt(buffer, RSAEncryptionPadding.Pkcs1);
}

/// <summary>
/// 使用私钥签名
/// </summary>
/// <param name="data">原始数据</param>
/// <returns></returns>
public override string Sign(string data)
{
byte[] dataBytes = _encoding.GetBytes(data);
var signatureBytes = _privateKeyRsaProvider.SignData(dataBytes, HashAlgorithmName, RSASignaturePadding.Pkcs1);
return Convert.ToBase64String(signatureBytes);
}

/// <summary>
/// 使用公钥验证签名
/// </summary>
/// <param name="data">原始数据</param>
/// <param name="sign">签名</param>
/// <returns></returns>
public override bool Verify(string data, string sign)
{
byte[] dataBytes = _encoding.GetBytes(data);
byte[] signBytes = Convert.FromBase64String(sign);
var verify = _publicKeyRsaProvider.VerifyData(dataBytes, signBytes, HashAlgorithmName, RSASignaturePadding.Pkcs1);
return verify;
}

private RSA CreateRsaProviderFromPublicKey(string publicKeyString)
{
var rsa = RSA.Create();
FromXmlStringExtensions(rsa,publicKeyString);
return rsa;
}

private RSA CreateRsaProviderFromPrivateKey(string privateKey)
{
var rsa = RSA.Create();
FromXmlStringExtensions(rsa, privateKey);
return rsa;
}

private int GetIntegerSize(BinaryReader binr)
{
byte bt = 0;
int count = 0;
bt = binr.ReadByte();
if (bt != 0x02)
return 0;
bt = binr.ReadByte();

if (bt == 0x81)
count = binr.ReadByte();
else
if (bt == 0x82)
{
var highbyte = binr.ReadByte();
var lowbyte = binr.ReadByte();
byte[] modint = { lowbyte, highbyte, 0x00, 0x00 };
count = BitConverter.ToInt32(modint, 0);
}
else
{
count = bt;
}

while (binr.ReadByte() == 0x00)
{
count -= 1;
}
binr.BaseStream.Seek(-1, SeekOrigin.Current);
return count;
}

private bool CompareBytearrays(byte[] a, byte[] b)
{
if (a.Length != b.Length)
return false;
int i = 0;
foreach (byte c in a)
{
if (c != b[i])
return false;
i++;
}
return true;
}

private static void FromXmlStringExtensions(RSA rsa, string xmlString)
{
var parameters = new RSAParameters();
var xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlString);
if (xmlDoc.DocumentElement.Name.Equals("RSAKeyValue"))
{
foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes)
{
switch (node.Name)
{
case "Modulus":
parameters.Modulus = (string.IsNullOrEmpty(node.InnerText)
? null
: Convert.FromBase64String(node.InnerText));
break;
case "Exponent":
parameters.Exponent = (string.IsNullOrEmpty(node.InnerText)
? null
: Convert.FromBase64String(node.InnerText));
break;
case "P":
parameters.P = (string.IsNullOrEmpty(node.InnerText)
? null
: Convert.FromBase64String(node.InnerText));
break;
case "Q":
parameters.Q = (string.IsNullOrEmpty(node.InnerText)
? null
: Convert.FromBase64String(node.InnerText));
break;
case "DP":
parameters.DP = (string.IsNullOrEmpty(node.InnerText)
? null
: Convert.FromBase64String(node.InnerText));
break;
case "DQ":
parameters.DQ = (string.IsNullOrEmpty(node.InnerText)
? null
: Convert.FromBase64String(node.InnerText));
break;
case "InverseQ":
parameters.InverseQ = (string.IsNullOrEmpty(node.InnerText)
? null
: Convert.FromBase64String(node.InnerText));
break;
case "D":
parameters.D = (string.IsNullOrEmpty(node.InnerText)
? null
: Convert.FromBase64String(node.InnerText));
break;
}
}
}
else
{
throw new Exception("Invalid XML RSA key.");
}
rsa.ImportParameters(parameters);
}
}
#endif
}

+ 0
- 90
src/GBNewEnergy.Protocol/NEEncrypts/Default_NERSAEncryptImpl_NET.cs 查看文件

@@ -1,90 +0,0 @@
using System;
using System.Security.Cryptography;
using System.Text;

namespace GBNewEnergy.Protocol.NEEncrypts
{
public class Default_NERSAEncryptImpl_NET : NERSABase
{
private readonly Encoding _encoding;

public Default_NERSAEncryptImpl_NET(Encoding encoding,string hashAlgorithmStr, string publicKey, string privateKey)
{
_encoding = encoding;
HashAlgorithmStr = hashAlgorithmStr;
PublicKey = publicKey;
PrivateKey = privateKey;
}

#if NETSTANDARD2_0
public override HashAlgorithmName HashAlgorithmName => throw new NotImplementedException();
#endif
public override string HashAlgorithmStr { get;}

public override string PublicKey { get; }

public override string PrivateKey { get;}

public override byte[] Decrypt(byte[] buffer)
{
using (RSACryptoServiceProvider provider=new RSACryptoServiceProvider())
{
provider.FromXmlString(PrivateKey);
return provider.Decrypt(buffer, false);
}
}

public override byte[] Encrypt(byte[] buffer)
{
using (RSACryptoServiceProvider provider = new RSACryptoServiceProvider())
{
provider.FromXmlString(PublicKey);
return provider.Encrypt(buffer, false);
}
}

/// <summary>
/// 使用私钥签名
/// </summary>
/// <param name="data">原始数据</param>
/// <returns></returns>
public override string Sign(string data)
{
byte[] dataBytes = _encoding.GetBytes(data);
byte[] rgbHash = HashAlgorithm.Create(HashAlgorithmStr).ComputeHash(dataBytes);
using (RSACryptoServiceProvider key = new RSACryptoServiceProvider())
{
key.FromXmlString(PrivateKey);
RSAPKCS1SignatureFormatter formatter = new RSAPKCS1SignatureFormatter(key);
formatter.SetHashAlgorithm(HashAlgorithmStr);
byte[] inArray = formatter.CreateSignature(rgbHash);
return Convert.ToBase64String(inArray);
}
}

/// <summary>
/// 使用公钥验证签名
/// </summary>
/// <param name="data">原始数据</param>
/// <param name="sign">签名</param>
/// <returns></returns>
public override bool Verify(string data, string sign)
{
byte[] dataBytes = _encoding.GetBytes(data);
byte[] signBytes = Convert.FromBase64String(sign);
byte[] rgbHash = HashAlgorithm.Create(HashAlgorithmStr).ComputeHash(dataBytes);
using (RSACryptoServiceProvider key = new RSACryptoServiceProvider())
{
key.FromXmlString(PublicKey);
RSAPKCS1SignatureDeformatter deformatter = new RSAPKCS1SignatureDeformatter(key);
deformatter.SetHashAlgorithm(HashAlgorithmStr);
byte[] rgbSignature = Convert.FromBase64String(sign);
if (deformatter.VerifySignature(rgbHash, rgbSignature))
{
return true;
}
return false;
}
}
}
}

+ 0
- 14
src/GBNewEnergy.Protocol/NEEncrypts/NEAESBase.cs 查看文件

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

namespace GBNewEnergy.Protocol.NEEncrypts
{
public abstract class NEAESBase : INEEncrypt
{
public abstract string PrivateKey { get; }
public abstract byte[] SaltBytes { get; }
public abstract byte[] Decrypt(byte[] buffer);
public abstract byte[] Encrypt(byte[] buffer);
}
}

+ 0
- 45
src/GBNewEnergy.Protocol/NEEncrypts/NERSABase.cs 查看文件

@@ -1,45 +0,0 @@
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;

namespace GBNewEnergy.Protocol.NEEncrypts
{
public abstract class NERSABase : INEEncrypt
{
public abstract byte[] Decrypt(byte[] buffer);
public abstract byte[] Encrypt(byte[] buffer);

#if NETSTANDARD2_0
/// <summary>
/// dotnet core 使用
/// </summary>
public abstract HashAlgorithmName HashAlgorithmName { get; }
#endif
/// <summary>
/// .net framework 使用
/// 哈希算法
/// MD5 new MD5CryptoServiceProvider()
/// SHA1 new SHA1CryptoServiceProvider()
/// SHA256 new SHA256CryptoServiceProvider()
/// SHA384 new SHA384CryptoServiceProvider()
/// SHA512 new SHA512CryptoServiceProvider()
/// </summary>
public abstract string HashAlgorithmStr { get; }
public abstract string PublicKey { get; }
public abstract string PrivateKey { get; }
/// <summary>
/// 使用私钥签名
/// </summary>
/// <param name="data">原始数据</param>
/// <returns></returns>
public abstract bool Verify(string data, string sign);
/// <summary>
/// 使用公钥验证签名
/// </summary>
/// <param name="data">原始数据</param>
/// <param name="sign">签名</param>
/// <returns></returns>
public abstract string Sign(string data);
}
}

+ 0
- 27
src/GBNewEnergy.Protocol/NEGlobalConfigs.cs 查看文件

@@ -1,27 +0,0 @@
using GBNewEnergy.Protocol.Enums;
using System.Text;

namespace GBNewEnergy.Protocol
{
public class NEGlobalConfigs
{
/// <summary>
/// 加密编码
/// </summary>
public Encoding NEEncryptEncoding { get; set; } = Encoding.UTF8;
/// <summary>
/// 字符串编码
/// </summary>
public Encoding NEEncoding { get; set; } = Encoding.UTF8;
/// <summary>
/// 数据单元加密方式
/// 0x01:数据不加密;0x02:数据经过 RSA 算法加密;0x03:数据经过 AES128 位算法加密;“0xFE”表示异常,“0xFF”表示无效
/// </summary>
public NEEncryptMethod EncryptMethod { get; set; } = NEEncryptMethod.None;
/// <summary>
/// 数据单元加密
/// 当数据单元存在加密时,应先加密后校验,先校验后解密
/// </summary>
public INEEncrypt Encrypt { get; set; }
}
}

+ 0
- 40
src/GBNewEnergy.Protocol/NEHeader.cs 查看文件

@@ -1,40 +0,0 @@
using GBNewEnergy.Protocol.Enums;
using GBNewEnergy.Protocol.Exceptions;
using GBNewEnergy.Protocol.Extensions;
using System;
using System.Text;

namespace GBNewEnergy.Protocol
{
/// <summary>
/// 头部
/// </summary>
public class NEHeader: BufferedEntityBase
{
public NEHeader(byte[] buffer):base(buffer)
{
}
/// <summary>
/// 起始符
/// </summary>
public const byte BeginFlag = 0x23;
/// <summary>
/// 命令标识
/// </summary>
public MsgId MsgId { get; private set; }
/// <summary>
/// 应答标志
/// </summary>
public AskId AskId { get; private set; }
/// <summary>
/// 车辆识别码
/// </summary>
public string VIN { get; private set; }
/// <summary>
/// 数据加密方式
/// 0x01:数据不加密;0x02:数据经过 RSA 算法加密;0x03:数据经过 AES128 位算法加密;“0xFE”表示异常,“0xFF”表示无效
/// </summary>
public EncryptMethod EncryptMethod { get; private set; }
}
}

+ 0
- 143
src/GBNewEnergy.Protocol/NEPackage.cs 查看文件

@@ -1,143 +0,0 @@
using GBNewEnergy.Protocol.Enums;
using GBNewEnergy.Protocol.Exceptions;
using GBNewEnergy.Protocol.Extensions;
using GBNewEnergy.Protocol.NEProperties;
using System;
using System.IO;

namespace GBNewEnergy.Protocol
{
/// <summary>
/// 新能源包
/// </summary>
public class NEPackage : NEBufferedEntityBase
{
public NEPackage(byte[] header, byte[] body, NEGlobalConfigs nEConfigs) : base(header, body, nEConfigs)
{
}

public NEPackage(byte[] buf, NEGlobalConfigs nEConfigs) : base(buf, nEConfigs)
{
}

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

/// <summary>
/// 固定为24个字节长度
/// </summary>
public const int HeaderFixedByteLength = 24;
/// <summary>
/// 起始符
/// </summary>
public const byte BeginFlag = 0x23;
/// <summary>
/// 校验位1字节
/// </summary>
private const int CheckBit = 1;
/// <summary>
/// 命令标识
/// </summary>
public NEMsgId MsgId { get; private set; }
/// <summary>
/// 应答标志
/// </summary>
public NEAskId AskId { get; private set; }
/// <summary>
/// 车辆识别码
/// </summary>
public string VIN { get; private set; }
/// <summary>
/// 数据加密方式
/// 0x01:数据不加密;0x02:数据经过 RSA 算法加密;0x03:数据经过 AES128 位算法加密;“0xFE”表示异常,“0xFF”表示无效
/// </summary>
public NEEncryptMethod EncryptMethod { get; private set; }
/// <summary>
/// 数据单元长度是数据单元的总字节数,有效值范围:0-65531
/// </summary>
public int DataUnitLength { get; private set; }
/// <summary>
/// 采用BCC(异或检验)法,校验范围从命令单元的第一个字节开始,同后一个字节异或,直到校验码前一个字节为止,
/// 校验码占用一个字节,当数据单元存在加密时,应先加密后检验,先校验后解密
/// </summary>
public byte BCCCode { get; private set; }
/// <summary>
/// 头数据
/// </summary>
public byte[] Header { get; private set; }
/// <summary>
/// 数据体
/// </summary>
public NEBodies Bodies { get; protected set; }

protected override void ToBuffer()
{
// 固定单元长度
DataUnitLength = Bodies.Buffer.Length;
Buffer = new byte[HeaderFixedByteLength + DataUnitLength + CheckBit];
Buffer[0] = BeginFlag;
Buffer[1] = BeginFlag;
Buffer[2] = (byte)MsgId;
Buffer[3] = (byte)AskId;
Buffer.WriteLittle(VIN, 4);
Buffer[21] = (byte)EncryptMethod;
Buffer.WriteLittle(DataUnitLength, 22, 2);
if (NEConfigs.Encrypt != null)
{
Buffer.WriteLittle(NEConfigs.Encrypt.Encrypt(Bodies.Buffer), 24, DataUnitLength);
}
else
{
Buffer.WriteLittle(Bodies.Buffer, 24, DataUnitLength);
}
BCCCode = Buffer.ToXor(2, (HeaderFixedByteLength + DataUnitLength - 1));
Buffer[HeaderFixedByteLength + DataUnitLength] = BCCCode;
Header = new byte[HeaderFixedByteLength];
Array.Copy(Buffer, 0, Header, 0, HeaderFixedByteLength);
}

protected override void InitializeProperties(INEProperties nEProperties)
{
NEPackageProperty nEPackageProperty = (NEPackageProperty)nEProperties;
VIN = nEPackageProperty.VIN;
MsgId = nEPackageProperty.MsgId;
AskId = nEPackageProperty.AskId;
Bodies = nEPackageProperty.Bodies;
EncryptMethod = NEConfigs.EncryptMethod;
}

protected override void InitializePropertiesFromBuffer()
{
if (Buffer[0] != BeginFlag && Buffer[1] == BeginFlag) throw new NEException(NEErrorCode.BeginFlagError, $"{Buffer[0]},{Buffer[1]}");
MsgId = (NEMsgId)Buffer[2];
AskId = (NEAskId)Buffer[3];
VIN = Buffer.ReadStringLittle(4, 17);
EncryptMethod = (NEEncryptMethod)Buffer[21];
DataUnitLength = Buffer.ReadUShortH2LLittle(22, 2);
// 2.4. 验证校验码
// 进行BCC校验码
// 校验位 = 报文长度 - 最后一位(校验位) - 偏移量(2)
int checkBit = Buffer.Length - CheckBit - 2;
byte bCCCode = Buffer.ToXor(2, checkBit);
byte bCCCode2 = Buffer[Buffer.Length - CheckBit];
if (bCCCode != bCCCode2)
{
throw new NEException(NEErrorCode.BCCCodeError, $"request:{bCCCode2}!=calculate:{bCCCode}");
}
BCCCode = bCCCode2;
byte[] bodiesBytes = new byte[DataUnitLength + CheckBit];
Array.Copy(Buffer, HeaderFixedByteLength, bodiesBytes, 0, bodiesBytes.Length);
if (NEConfigs.Encrypt != null)
{
Bodies = NEBodiesFactory.GetNEBodiesByMsgId(MsgId, NEConfigs.Encrypt.Decrypt(bodiesBytes),NEConfigs);
}
else
{
Bodies = NEBodiesFactory.GetNEBodiesByMsgId(MsgId, bodiesBytes, NEConfigs);
}
Header = new byte[HeaderFixedByteLength];
Array.Copy(Buffer, 0, Header, 0, HeaderFixedByteLength);
}
}
}

+ 0
- 18
src/GBNewEnergy.Protocol/NEProperties/NEControlAlarmParameter.cs 查看文件

@@ -1,18 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using GBNewEnergy.Protocol.Enums;
namespace GBNewEnergy.Protocol.NEProperties
{
/// <summary>
/// 控制命令 报警、预警
/// </summary>
public class NEControlAlarmParameter
{
/// <summary>
/// 报警等级
/// </summary>
public NEAlarmLevel nEAlarmLevel { get; set; }
}
}

+ 0
- 27
src/GBNewEnergy.Protocol/NEProperties/NEControlProperty.cs 查看文件

@@ -1,27 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using GBNewEnergy.Protocol.Enums;
namespace GBNewEnergy.Protocol.NEProperties
{
/// <summary>
/// 控制命令属性
/// </summary>
public class NEControlProperty : INEProperties
{
public string VIN { get; set ; }
/// <summary>
/// 命令ID 只能发送一个
/// </summary>
public NEControlCmd CmdID { get; set; }
/// <summary>
/// 升级参数
/// </summary>
public NEControlUpgradeParameter UpgradeParameter { get; set; }
/// <summary>
/// 报警,预警参数
/// </summary>
public NEControlAlarmParameter AlarmParameter { get; set; }
}
}

+ 0
- 57
src/GBNewEnergy.Protocol/NEProperties/NEControlUpgradeParameter.cs 查看文件

@@ -1,57 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace GBNewEnergy.Protocol.NEProperties
{
/// <summary>
/// 控制命令,升级
/// </summary>
public class NEControlUpgradeParameter
{
/// <summary>
/// URL地址
/// </summary>
public string Url { get; set; }
/// <summary>
/// 拨号点名称
/// </summary>
public string DialPointName { get; set; }
/// <summary>
/// 拨号用户名
/// </summary>
public string DialUserName { get; set; }
/// <summary>
/// 拨号密码
/// </summary>
public string DialPassword { get; set; }
/// <summary>
/// 服务器地址
/// </summary>
public string ServerUrl { get; set; }
/// <summary>
/// 服务器端口
/// </summary>
public string ServerPort { get; set; }
/// <summary>
/// 生产厂商代码
/// </summary>
public string ProviderCode { get; set; }
/// <summary>
/// 硬件版本
/// </summary>
public string HardwareVersion { get; set; }
/// <summary>
/// 固件版本
/// </summary>
public string FirmwareVersion { get; set; }
/// <summary>
/// 升级服务器时限
/// </summary>
public string UpLimitTime { get; set; }
public override string ToString()
{
return $"{Url};{DialPointName};{DialUserName};{DialPassword};{ServerUrl};{ServerPort};{ProviderCode};{HardwareVersion};{FirmwareVersion};{UpLimitTime}";
}
}
}

+ 0
- 14
src/GBNewEnergy.Protocol/NEProperties/NEEmptyProperty.cs 查看文件

@@ -1,14 +0,0 @@
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(); }
}
}

+ 0
- 19
src/GBNewEnergy.Protocol/NEProperties/NELoginProperty.cs 查看文件

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

namespace GBNewEnergy.Protocol.NEProperties
{
public class NELoginProperty : INEProperties
{
public string VIN { get; set; }

public string SIM { get; set; }

public byte BatteryCount { get; set; }

public byte BatteryLength { get; set; }

public IEnumerable<string> BatteryNos { get; set;}
}
}

+ 0
- 11
src/GBNewEnergy.Protocol/NEProperties/NELogoutProperty.cs 查看文件

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

namespace GBNewEnergy.Protocol.NEProperties
{
public class NELogoutProperty : INEProperties
{
public string VIN { get; set; }
}
}

+ 0
- 15
src/GBNewEnergy.Protocol/NEProperties/NEPackageProperty.cs 查看文件

@@ -1,15 +0,0 @@
using GBNewEnergy.Protocol.Enums;
using System;
using System.Collections.Generic;
using System.Text;

namespace GBNewEnergy.Protocol.NEProperties
{
public class NEPackageProperty : INEProperties
{
public string VIN { get; set; }
public NEMsgId MsgId { get; set; }
public NEAskId AskId { get; set; }
public NEBodies Bodies { get; set; }
}
}

+ 0
- 27
src/GBNewEnergy.Protocol/NEProperties/NEPlatformLoginProperty.cs 查看文件

@@ -1,27 +0,0 @@
using GBNewEnergy.Protocol.Enums;
using System;
using System.Collections.Generic;
using System.Text;

namespace GBNewEnergy.Protocol.NEProperties
{
public class NEPlatformLoginProperty : INEProperties
{
[Obsolete("平台登入无用字段")]
public string VIN { get ; set; }
/// <summary>
/// 平台用户名
/// </summary>
public string UserName { get; set; }

/// <summary>
/// 加密规则
/// </summary>
public NEEncryptMethod EncryptMethod { get; set; }

/// <summary>
/// 平台密码
/// </summary>
public string Password { get; set; }
}
}

+ 0
- 16
src/GBNewEnergy.Protocol/NEProperties/NEPlatformLogoutProperty.cs 查看文件

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

namespace GBNewEnergy.Protocol.NEProperties
{
public class NEPlatformLogoutProperty : INEProperties
{
[Obsolete("平台登入无用字段")]
public string VIN { get; set; }
/// <summary>
/// 平台用户名
/// </summary>
public string UserName { get; set; }
}
}

+ 0
- 60
src/GBNewEnergy.Protocol/NEProperties/NEUploadProperties/NEUploadAlarmProperty.cs 查看文件

@@ -1,60 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using GBNewEnergy.Protocol.Enums;

namespace GBNewEnergy.Protocol.NEProperties.NEUploadProperties
{
/// <summary>
/// 报警数据
/// </summary>
public class NEUploadAlarmProperty : NEUploadPropertyBase
{
public override NEInfoType NEInfoType => NEInfoType.报警数据;

/// <summary>
/// 报警等级
/// </summary>
public byte AlarmLevel { get; set; }
/// <summary>
/// 通用报警标志
/// </summary>
public int AlarmBatteryFlag { get; set; }
/// <summary>
/// 报警没变化 0,有报警 1
/// </summary>
public byte AlarmBatteryChanged { get; set; }
/// <summary>
/// 可充电储能装置故障总数
/// </summary>
public byte AlarmBatteryOtherCount { get; set; }
/// <summary>
/// 可充电储能装置故障代码列表
/// </summary>
public List<int> AlarmBatteryOtherList { get; set; } = new List<int>();
/// <summary>
/// 驱动电机故障总数
/// </summary>
public byte AlarmElCount { get; set; }
/// <summary>
/// 驱动电机故障代码列表
/// </summary>
public List<int> AlarmElList { get; set; } = new List<int>();
/// <summary>
/// 发动机故障总数
/// </summary>
public byte AlarmEngineCount { get; set; }
/// <summary>
/// 发动机故障列表
/// </summary>
public List<int>AlarmEngineList { get; set; } = new List<int>();
/// <summary>
/// 其他故障总数
/// </summary>
public byte AlarmOtherCount { get; set; }
/// <summary>
/// 其他故障代码列表
/// </summary>
public List<int> AlarmOtherList { get; set; } = new List<int>();
}
}

+ 0
- 63
src/GBNewEnergy.Protocol/NEProperties/NEUploadProperties/NEUploadDrivenElectricalProperty.cs 查看文件

@@ -1,63 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using GBNewEnergy.Protocol.Enums;

namespace GBNewEnergy.Protocol.NEProperties.NEUploadProperties
{
/// <summary>
/// 驱动电机数据
/// </summary>
public class NEUploadDrivenElectricalProperty : NEUploadPropertyBase
{
public override NEInfoType NEInfoType => NEInfoType.驱动电机数据;

/// <summary>
/// 电机个数
/// </summary>
public byte ElectricalCount;
/// <summary>
/// 电机信息集合
/// </summary>
public IEnumerable<ElectricalInfo> ElectricalList { get; set; }

/// <summary>
/// 电机信息
/// </summary>
public class ElectricalInfo
{
/// <summary>
/// 电机序号
/// </summary>
public byte ElNo { get; set; }
/// <summary>
/// 电机状态
/// </summary>
public byte ElStatus { get; set; }
/// <summary>
/// 电机控制器温度
/// </summary>
public int ElControlTemp { get; set; }
/// <summary>
/// 电机转速
/// </summary>
public int ElSpeed { get; set; }
/// <summary>
/// 电机转矩
/// </summary>
public double ElTorque { get; set; }
/// <summary>
/// 电机温度
/// </summary>
public int ElTemp { get; set; }
/// <summary>
/// 电机电压
/// </summary>
public double ElVoltage { get; set; }
/// <summary>
/// 电机母线电流
/// </summary>
public double ElCurrent { get; set; }
}
}
}

+ 0
- 60
src/GBNewEnergy.Protocol/NEProperties/NEUploadProperties/NEUploadEnergyStorageProperty.cs 查看文件

@@ -1,60 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using GBNewEnergy.Protocol.Enums;

namespace GBNewEnergy.Protocol.NEProperties.NEUploadProperties
{
/// <summary>
/// 可充电储能装置电压数据
/// </summary>
public class NEUploadEnergyStorageProperty : NEUploadPropertyBase
{
public override NEInfoType NEInfoType => NEInfoType.可充电储能装置电压数据;

/// <summary>
/// 可充电储能子系统个数
/// </summary>
public byte BatteryAssemblyCount { get; set; }

/// <summary>
/// 可充电储能子系统电压信息列表
/// </summary>
public List<BatteryAssembly> BatteryAssemblyList { get; set; } = new List<BatteryAssembly>();

/// <summary>
/// 每个电池总成数据
/// </summary>
public class BatteryAssembly
{
/// <summary>
/// 可充电储能子系统号
/// </summary>
public byte BatteryAssemblyNo { get; set; }
/// <summary>
/// 可充电储能装置电压
/// </summary>
public double BatteryAssemblyVoltage { get; set; }
/// <summary>
/// 可充电储能装置电流
/// </summary>
public double BatteryAssemblyCurrent { get; set; }
/// <summary>
/// 单体电池总数
/// </summary>
public int SingleBatteryCount { get; set; }
/// <summary>
/// 本帧起始电池序号
/// </summary>
public int ThisSingleBatteryBeginNo { get; set; }
/// <summary>
/// /本帧单体电池总数
/// </summary>
public int ThisSingleBatteryBeginCount { get; set; }
/// <summary>
/// 单体电池电压
/// </summary>
public List<double> SingleBatteryVoltageList { get; set; } = new List<double>();
}
}
}

+ 0
- 43
src/GBNewEnergy.Protocol/NEProperties/NEUploadProperties/NEUploadEnergyStorageTemperatureProperty.cs 查看文件

@@ -1,43 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using GBNewEnergy.Protocol.Enums;

namespace GBNewEnergy.Protocol.NEProperties.NEUploadProperties
{
/// <summary>
/// 可充电储能装置温度数据
/// </summary>
public class NEUploadEnergyStorageTemperatureProperty : NEUploadPropertyBase
{
public override NEInfoType NEInfoType => NEInfoType.可充电储能装置温度数据;

/// <summary>
/// 动力蓄电池总成个数
/// </summary>
public byte BatteryAssemblyCount { get; set; }
/// <summary>
/// 每个可充电储能子系统温度信息长度
/// </summary>
public List<BatteryTemperature> BatteryAssemblyList { get; set; } = new List<BatteryTemperature>();

/// <summary>
/// 每个动力蓄电池上温度数据
/// </summary>
public class BatteryTemperature
{
/// <summary>
/// 可充电储能子系统号
/// </summary>
public byte BatteryAssemblyNo { get; set; }
/// <summary>
/// 可充电储能温度探针个数
/// </summary>
public int TemperatureProbeCount { get; set; }
/// <summary>
/// 可充电储能子系统各温度探针检测到的温度值
/// </summary>
public List<int> TemperatureList { get; set; } = new List<int>();
}
}
}

+ 0
- 39
src/GBNewEnergy.Protocol/NEProperties/NEUploadProperties/NEUploadEnginePartProperty.cs 查看文件

@@ -1,39 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using GBNewEnergy.Protocol.Enums;

namespace GBNewEnergy.Protocol.NEProperties.NEUploadProperties
{
/// <summary>
/// 发动机部分数据
/// </summary>
public class NEUploadEnginePartProperty : NEUploadPropertyBase
{
public override NEInfoType NEInfoType => NEInfoType.发动机数据;
/// <summary>
/// 发动机状态
/// 0x01:启动状态
/// 0x02:关闭状态
/// 0xFE:异常
/// 0xFF:无效
/// </summary>
public byte EngineStatus { get; set; }
/// <summary>
/// 曲轴转速
/// 有效范围:0-60000(表示0 r/min-60000 r/min)
/// 最小计量单元:1 r/min
/// 异常:0xFF,0XFE
/// 无效:0xFF,0xFF
/// </summary>
public int Revs { get; set; }
/// <summary>
/// 燃料消耗率
/// 有效值范围:0-60000(表示0L/100km - 600L/100km)
/// 最小计量单元:0.01L/km
/// 异常:0xFF,0XFE
/// 无效:0xFF,0xFF
/// </summary>
public double FuelRate { get; set; }
}
}

+ 0
- 94
src/GBNewEnergy.Protocol/NEProperties/NEUploadProperties/NEUploadExtremeProperty.cs 查看文件

@@ -1,94 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using GBNewEnergy.Protocol.Enums;

namespace GBNewEnergy.Protocol.NEProperties.NEUploadProperties
{
/// <summary>
/// 极值数据
/// </summary>
public class NEUploadExtremeProperty : NEUploadPropertyBase
{
public override NEInfoType NEInfoType => NEInfoType.极值数据;

/// <summary>
/// 最高电压电池总成号
/// 有效值范围:1-250
/// 异常:0XFE
/// 无效:0xFF
/// </summary>
public byte MaxVoltageBatteryAssemblyNo { get; set; }
/// <summary>
/// 最高电压电池单体代号
/// 有效值范围:1-250
/// 异常:0XFE
/// 无效:0xFF
/// </summary>
public byte MaxVoltageSingleBatteryNo { get; set; }
/// <summary>
/// 电池单体电压最高值
/// 有效值范围:0-15000(表示0V - 15V)
/// 最小计量单元:0.001V
/// 异常:0xFF,0XFE
/// 无效:0xFF,0xFF
/// </summary>
public double MaxVoltageSingleBatteryValue { get; set; }
/// <summary>
/// 最低电压电池子系统号
/// 有效值范围:1-250
/// 异常:0XFE
/// 无效:0xFF
/// </summary>
public byte MinVoltageBatteryAssemblyNo { get; set; }
/// <summary>
/// 最低电压电池单体代号
/// 有效值范围:1-250
/// 异常:0XFE
/// 无效:0xFF
/// </summary>
public byte MinVoltageSingleBatteryNo { get; set; }
/// <summary>
/// 最低单体电压最低值
/// 有效值范围:0-15000(表示0V - 15V)
/// 最小计量单元:0.001V
/// 异常:0xFF,0XFE
/// 无效:0xFF,0xFF
/// </summary>
public double MinVoltageSingleBatteryValue { get; set; }
/// <summary>
/// 蓄电池中最高温度子系统号
/// 有效值范围:1-250
/// 异常:0XFE
/// 无效:0xFF
/// </summary>
public byte MaxTempProbeBatteryNo { get; set; }
/// <summary>
/// 蓄电池中最高温度探针序号
/// 有效值范围:1-250
/// 异常:0XFE
/// 无效:0xFF
/// </summary>
public byte MaxTempBatteryAssemblyNo { get; set; }
/// <summary>
/// 最高温度值
/// 有效值范围:0-250(数值偏移量40℃,表示-40℃ - +210℃)
/// 最小计量单元:1℃
/// 异常:0XFE
/// 无效:0xFF
/// </summary>
public int MaxTempProbeBatteryValue { get; set; }
/// <summary>
/// 最低温度子系统号
/// </summary>
public byte MinTempProbeBatteryNo { get; set; }
/// <summary>
/// 蓄电池中最低温度探针序号
/// </summary>
public byte MinTempBatteryAssemblyNo { get; set; }
/// <summary>
/// 最低温度值
/// </summary>
public int MinTempProbeBatteryValue { get; set; }
}
}

+ 0
- 103
src/GBNewEnergy.Protocol/NEProperties/NEUploadProperties/NEUploadFuelBatteryProperty.cs 查看文件

@@ -1,103 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using GBNewEnergy.Protocol.Enums;

namespace GBNewEnergy.Protocol.NEProperties.NEUploadProperties
{
/// <summary>
/// 燃料电池数据
/// </summary>
public class NEUploadFuelBatteryProperty : NEUploadPropertyBase
{
public override NEInfoType NEInfoType => NEInfoType.燃料电池数据;
/// <summary>
/// 燃料电池电压
/// 有效值范围:0 - 20000(表示 0V-2000V)
/// 最小计量单元:0.1V
/// 异常:0xFF,0XFE
/// 无效:0xFF,0xFF
/// </summary>
public double FuelBatteryVoltage { get; set; }
/// <summary>
/// 燃料电池电流
/// 有效值范围:0 - 20000(表示 0A- +2000A)
/// 最小计量单元:0.1 A
/// 异常:0xFF,0XFE
/// 无效:0xFF,0xFF
/// </summary>
public double FuelBatteryCurrent { get; set; }
/// <summary>
/// 燃料消耗率
/// 有效值范围:0-60000(表示 0kg/100km - 600kg/100km)
/// 最小计量单元:0.01kg/100km
/// 异常:0xFF,0XFE
/// 无效:0xFF,0xFF
/// </summary>
public double FuelConsumptionRate { get; set; }
/// <summary>
/// 燃料电池温度探针总数
/// N个燃料电池温度探针
/// 有效值范围:0-65531
/// 异常:0xFF,0XFE
/// 无效:0xFF,0xFF
/// </summary>
public int TemperatureProbeCount { get; set; }
/// <summary>
/// 探针温度值
/// 有效值范围:0-240(数值偏移量40 ℃,表示-40 ℃ - +200 ℃)
/// 最小计量单元:1 ℃
/// </summary>
public List<int> TemperatureList { get; set; } = new List<int>();
/// <summary>
/// 氢系统中最高温度
/// 有效值范围:0-2400(偏移量40 ℃,表示-40 ℃ - 200 ℃)
/// 最小计量单元:0.1 ℃
/// 异常:0xFF,0XFE
/// 无效:0xFF,0xFF
/// </summary>
public double HydrogenSystemMaxTemp { get; set; }
/// <summary>
/// 氢系统中最高温度探针代号
/// 有效值范围:1-252
/// 异常:0XFE
/// 无效:0xFF
/// </summary>
public byte HydrogenSystemMaxTempNo { get; set; }
/// <summary>
/// 氢气最高浓度
/// 有效值范围:0-60000(表示0 mg/kg - 50000 mg/kg)
/// 最小计量单元:1 mg/kg
/// 异常:0xFF,0XFE
/// 无效:0xFF,0xFF
/// </summary>
public double HydrogenSystemMaxConcentrations { get; set; }
/// <summary>
/// 氢气最高浓度传感器代号
/// 有效值范围:1-252
/// 异常:0XFE
/// 无效:0xFF
/// </summary>
public byte HydrogenSystemMaxConcentrationsNo { get; set; }
/// <summary>
/// 氢气最高压力
/// 有效值范围:0-1000(表示0MPa - 100MPa),最小计量单位:0.1MPa
/// </summary>
public double HydrogenSystemMaxPressure { get; set; }
/// <summary>
/// 氢气最高压力传感器代号
/// 有效值访问:1-252
/// 异常:0xFE
/// 无效:0xFF
/// </summary>
public byte HydrogenSystemMaxPressureNo { get; set; }
/// <summary>
/// 高压DC/DC状态
/// 0x01:工作
/// 0x02:断开
/// 0xFE:表示异常
/// 0xFF:表示无效
/// </summary>
public byte DCStatus { get; set; }
}
}

+ 0
- 26
src/GBNewEnergy.Protocol/NEProperties/NEUploadProperties/NEUploadProperty.cs 查看文件

@@ -1,26 +0,0 @@
using GBNewEnergy.Protocol.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GBNewEnergy.Protocol.NEProperties.NEUploadProperties
{
/// <summary>
/// 上报信息
/// </summary>
public class NEUploadProperty : INEProperties
{
public string VIN { get ; set; }

public NEUploadProperty(params NEUploadPropertyBase[] NEUploadPropertyBase)
{
if (NEUploadPropertyBase != null)
{
NEUploadPropertys = NEUploadPropertyBase.ToList();
}
}

public List<NEUploadPropertyBase> NEUploadPropertys { get; set; }
}
}

+ 0
- 12
src/GBNewEnergy.Protocol/NEProperties/NEUploadProperties/NEUploadPropertyBase.cs 查看文件

@@ -1,12 +0,0 @@
using GBNewEnergy.Protocol.Enums;
using System;
using System.Collections.Generic;
using System.Text;

namespace GBNewEnergy.Protocol.NEProperties.NEUploadProperties
{
public abstract class NEUploadPropertyBase
{
public abstract NEInfoType NEInfoType { get; }
}
}

+ 0
- 33
src/GBNewEnergy.Protocol/NEProperties/NEUploadProperties/NEUploadVehiclePositionProperty.cs 查看文件

@@ -1,33 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using GBNewEnergy.Protocol.Enums;

namespace GBNewEnergy.Protocol.NEProperties.NEUploadProperties
{
/// <summary>
/// 车辆位置数据
/// </summary>
public class NEUploadVehiclePositionProperty : NEUploadPropertyBase
{
public override NEInfoType NEInfoType => NEInfoType.车辆位置数据;
/// <summary>
/// 定位状态
/// 0位:0:有效定位;1:无效定位(当数据通信正常,而不能获取定位信息时,发送最后一次有效定位信息,并将定位状态置为无效。)
/// 1位:0:北纬;1:南纬
/// 2位:0:东经;1:西经
/// 3-7位:保留
/// </summary>
public byte PositioStatus { get; set; }
/// <summary>
/// 经度
/// 以度位单位的经度值乘以10^6,精确到百万分之一度
/// </summary>
public double Lng { get; set; }
/// <summary>
/// 纬度
/// 以度位单位的纬度值乘以10^6,精确到百万分之一度
/// </summary>
public double Lat { get; set; }
}
}

+ 0
- 72
src/GBNewEnergy.Protocol/NEProperties/NEUploadProperties/NEUploadVehicleProperty.cs 查看文件

@@ -1,72 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using GBNewEnergy.Protocol.Enums;

namespace GBNewEnergy.Protocol.NEProperties.NEUploadProperties
{
/// <summary>
/// 整车数据
/// </summary>
public class NEUploadVehicleProperty : NEUploadPropertyBase
{
public override NEInfoType NEInfoType => NEInfoType.整车数据;

/// <summary>
/// 车辆状态
/// </summary>
public byte CarStatus { get; set; }
/// <summary>
/// 充放电状态
/// </summary>
public byte ChargeStatus { get; set; }
/// <summary>
/// 运行模式
/// </summary>
public byte OperationMode { get; set; }
/// <summary>
/// 车速
/// </summary>
public double Speed { get; set; }
/// <summary>
/// 当前里程
/// </summary>
public double Dis { get; set; }
/// <summary>
/// 总里程
/// </summary>
public double TotalDis { get; set; }
/// <summary>
/// 总电压
/// </summary>
public double TotalVoltage { get; set; }
/// <summary>
/// 总电流
/// </summary>
public double TotalTemp { get; set; }
/// <summary>
/// SOC
/// </summary>
public byte soc { get; set; }
/// <summary>
/// DC-DC 状态
/// </summary>
public byte DCStatus { get; set; }
/// <summary>
/// 档位
/// </summary>
public byte Stall { get; set; }
/// <summary>
/// 加速踏板行程值
/// </summary>
public byte Accelerator { get; set; }
/// <summary>
/// 制动踏板状态
/// </summary>
public byte Brakes { get; set; }
/// <summary>
/// 绝缘电阻
/// </summary>
public int Resistance { get; set; }
}
}

+ 0
- 14
src/GBNewEnergy.Protocol/NEUpStreamBase.cs 查看文件

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

namespace GBNewEnergy.Protocol
{
public abstract class NEUpStreamBase
{
public DateTime Utc{ get; set; }
public byte[] Buffer { get;protected set; }
public abstract void ToBuffer();
}
}

+ 0
- 37
src/GBNewEnergy.Protocol/UpStream/CommonUpStream.cs 查看文件

@@ -1,37 +0,0 @@
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);
}
}
}

+ 0
- 106
src/GBNewEnergy.Protocol/UpStream/NELoginUpStream.cs 查看文件

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

namespace GBNewEnergy.Protocol.UpStream
{
/// <summary>
/// 车辆登入
/// </summary>
public class NELoginUpStream : NEBodies
{
public NELoginUpStream(INEProperties nEProperties, NEGlobalConfigs nEConfigs) : base(nEProperties, nEConfigs)
{
}

public NELoginUpStream(byte[] buffer, NEGlobalConfigs nEConfigs) : base(buffer, nEConfigs)
{
}

/// <summary>
/// SIM 卡号
/// </summary>
public string SIM { get; set; }
/// <summary>
/// 电池总成数
/// 可充电储能子系统数
/// </summary>
public byte BatteryCount { get; set; }
/// <summary>
/// 电池编码长度
/// 可充电储能系统编码长度
/// </summary>
public byte BatteryLength { get; set; }
/// <summary>
/// 电池编码
/// 可充电储能系统编码
/// </summary>
public IEnumerable<string> BatteryNos { get; set; }

protected override void ToBuffer()
{
// 根据协议说明书
Buffer = new byte[6 + 2 + 20 + 1 + 1 + (BatteryCount * BatteryLength)];
Buffer.WriteLittle(CurrentDateTime, 0, 6);
Buffer.WriteLittle(LoginNum, 6, 2);
Buffer.WriteLittle(SIM, 8);
Buffer[28] = BatteryCount;
Buffer[29] = BatteryLength;
if ((BatteryCount * BatteryLength) != 0)
{
string str = string.Join("", BatteryNos);
Buffer.WriteLittle(str, 30);
}
}

protected override void InitializeProperties(INEProperties nEProperties)
{
NELoginProperty nELoginProperty = (NELoginProperty)nEProperties;
if (LoginNumDict.ContainsKey(nELoginProperty.VIN))
{
LoginInfo temp;
if (LoginNumDict.TryGetValue(nELoginProperty.VIN, out temp))
{
// 不等于当天
if (temp.ExpirationTime != DateTime.Now.Date)
{
LoginNum = 1;
LoginNumDict.TryUpdate(nELoginProperty.VIN, new LoginInfo { LoginNum = LoginNum, ExpirationTime=DateTime.Now.Date }, temp);
}
else
{// 自增1 更新字典
LoginNum = temp.LoginNum++;
LoginNumDict.TryUpdate(nELoginProperty.VIN, new LoginInfo { LoginNum = LoginNum, ExpirationTime = DateTime.Now.Date }, temp);
}
}
}
else
{
LoginNum = 1;
LoginNumDict.TryAdd(nELoginProperty.VIN, new LoginInfo { LoginNum = LoginNum, ExpirationTime = DateTime.Now.Date });
}
SIM = nELoginProperty.SIM;
BatteryCount = nELoginProperty.BatteryCount;
BatteryLength = nELoginProperty.BatteryLength;
BatteryNos = nELoginProperty.BatteryNos;
}

protected override void InitializePropertiesFromBuffer()
{
CurrentDateTime = Buffer.ReadDateTimeLittle(0, 6);
LoginNum = Buffer.ReadUShortH2LLittle(6, 2);
SIM = Buffer.ReadStringLittle(8, 20);
BatteryCount = Buffer[28];
BatteryLength = Buffer[29];
List<string> batteryNos = new List<string>();
for (int i = 0; i < BatteryCount; i++)
{
batteryNos.Add(Buffer.ReadStringLittle(i * BatteryLength + 30, BatteryLength));
}
BatteryNos = batteryNos;
}
}
}

+ 0
- 50
src/GBNewEnergy.Protocol/UpStream/NELogoutUpStream.cs 查看文件

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

namespace GBNewEnergy.Protocol.UpStream
{
/// <summary>
/// 车辆登出
/// </summary>
public class NELogoutUpStream : NEBodies
{
public NELogoutUpStream(INEProperties nEProperties, NEGlobalConfigs nEConfigs) : base(nEProperties, nEConfigs)
{
}

public NELogoutUpStream(byte[] buffer, NEGlobalConfigs nEConfigs) : base(buffer, nEConfigs)
{
}

protected override void InitializeProperties(INEProperties nEProperties)
{
NELogoutProperty nELogoutProperty = (NELogoutProperty)nEProperties;
LoginInfo temp;
if (LoginNumDict.TryGetValue(nELogoutProperty.VIN, out temp))
{
LoginNum = temp.LoginNum;
}
else
{
throw new NEException(Enums.NEErrorCode.LoginSerialNoError, "Must Dependency NELoginUpStream Class.");
}
}

protected override void InitializePropertiesFromBuffer()
{
CurrentDateTime = Buffer.ReadDateTimeLittle(0, 6);
LoginNum = Buffer.ReadUShortH2LLittle(6, 2);
}

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

+ 0
- 88
src/GBNewEnergy.Protocol/UpStream/NEPlatformLoginUpStream.cs 查看文件

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

namespace GBNewEnergy.Protocol.UpStream
{
/// <summary>
/// 平台登入
/// </summary>
public class NEPlatformLoginUpStream : NEBodies
{
public NEPlatformLoginUpStream(byte[] buffer, NEGlobalConfigs nEConfigs) : base(buffer, nEConfigs)
{
}

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

/// <summary>
/// 平台用户名
/// </summary>
public string UserName { get; set; }

/// <summary>
/// 加密规则
/// </summary>
public NEEncryptMethod EncryptMethod { get; set; }

/// <summary>
/// 平台密码
/// </summary>
public string Password { get; set; }

protected override void InitializeProperties(INEProperties nEProperties)
{
NEPlatformLoginProperty nEPlatformLoginProperty = (NEPlatformLoginProperty)nEProperties;
if (PlatformLoginNumDict.ContainsKey(nEPlatformLoginProperty.UserName))
{
PlatformLoginInfo temp;
if (PlatformLoginNumDict.TryGetValue(nEPlatformLoginProperty.UserName, out temp))
{
// 不等于当天
if (temp.ExpirationTime != DateTime.Now.Date)
{
LoginNum = 1;
PlatformLoginNumDict.TryUpdate(nEPlatformLoginProperty.UserName, new PlatformLoginInfo { LoginNum = LoginNum, ExpirationTime = DateTime.Now.Date }, temp);
}
else
{// 自增1 更新字典
LoginNum = temp.LoginNum++;
PlatformLoginNumDict.TryUpdate(nEPlatformLoginProperty.UserName, new PlatformLoginInfo { LoginNum = LoginNum, ExpirationTime = DateTime.Now.Date }, temp);
}
}
}
else
{
LoginNum = 1;
PlatformLoginNumDict.TryAdd(nEPlatformLoginProperty.UserName, new PlatformLoginInfo { LoginNum = LoginNum, ExpirationTime = DateTime.Now.Date });
}
UserName = nEPlatformLoginProperty.UserName;
EncryptMethod = nEPlatformLoginProperty.EncryptMethod;
Password = nEPlatformLoginProperty.Password;
}

protected override void InitializePropertiesFromBuffer()
{
CurrentDateTime = Buffer.ReadDateTimeLittle(0, 6);
LoginNum = Buffer.ReadUShortH2LLittle(6, 2);
UserName = Buffer.ReadStringLittle(8, 12);
Password = Buffer.ReadStringLittle(20, 20);
EncryptMethod= (NEEncryptMethod)Buffer[40];
}

protected override void ToBuffer()
{
Buffer = new byte[6+2+12+20+1];
Buffer.WriteLittle(CurrentDateTime, 0, 6);
Buffer.WriteLittle(LoginNum, 6, 2);
Buffer.WriteLittle(UserName, 12);
Buffer.WriteLittle(Password, 20);
Buffer.WriteLittle((byte)EncryptMethod, 40);
}
}
}

+ 0
- 47
src/GBNewEnergy.Protocol/UpStream/NEPlatformLogoutUpStream.cs 查看文件

@@ -1,47 +0,0 @@
using GBNewEnergy.Protocol.Exceptions;
using GBNewEnergy.Protocol.Extensions;
using GBNewEnergy.Protocol.NEProperties;

namespace GBNewEnergy.Protocol.UpStream
{
/// <summary>
/// 平台登出
/// </summary>
public class NEPlatformLogoutUpStream : NEBodies
{
public NEPlatformLogoutUpStream(INEProperties nEProperties, NEGlobalConfigs nEConfigs) : base(nEProperties, nEConfigs)
{
}

public NEPlatformLogoutUpStream(byte[] buffer, NEGlobalConfigs nEConfigs) : base(buffer, nEConfigs)
{
}

protected override void InitializeProperties(INEProperties nEProperties)
{
NEPlatformLogoutProperty nEPlatformLogoutProperty = (NEPlatformLogoutProperty)nEProperties;
PlatformLoginInfo temp;
if (PlatformLoginNumDict.TryGetValue(nEPlatformLogoutProperty.UserName, out temp))
{
LoginNum = temp.LoginNum;
}
else
{
throw new NEException(Enums.NEErrorCode.LoginSerialNoError, "Must Dependency NEPlatformLoginUpStream Class.");
}
}

protected override void InitializePropertiesFromBuffer()
{
CurrentDateTime = Buffer.ReadDateTimeLittle(0, 6);
LoginNum = Buffer.ReadUShortH2LLittle(6, 2);
}

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

+ 0
- 38
src/GBNewEnergy.Protocol/UpStream/NERealUploadUpStream.cs 查看文件

@@ -1,38 +0,0 @@
using GBNewEnergy.Protocol.NEProperties.NEUploadProperties;
using System;
using System.Collections.Generic;
using System.Text;

namespace GBNewEnergy.Protocol.UpStream
{
/// <summary>
/// 实时信息上报
/// </summary>
public class NERealUploadUpStream : NEBodies
{
public NERealUploadUpStream(byte[] buffer, NEGlobalConfigs nEConfigs) : base(buffer, nEConfigs)
{
}

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

public NEUploadProperty NEUploadProperty { get;private set; }

protected override void InitializeProperties(INEProperties nEProperties)
{
NEUploadProperty = (NEUploadProperty)nEProperties;
}

protected override void InitializePropertiesFromBuffer()
{
throw new NotImplementedException();
}

protected override void ToBuffer()
{
throw new NotImplementedException();
}
}
}

+ 0
- 56
src/GBNewEnergy.sln 查看文件

@@ -1,56 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
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("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GBNewEnergy.Protocol.Test", "GBNewEnergy.Protocol.Test\GBNewEnergy.Protocol.Test.csproj", "{AAA669F5-E689-40CA-97EF-B5BA672B11DD}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NEEncrypts.Tests", "NEEncrypts.Tests", "{1D162FFB-5944-470C-B6F0-8F7387C706DF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NEEncryptsNET4.Test", "NEEncrypts.Tests\NEEncryptsNET4.Test\NEEncryptsNET4.Test.csproj", "{7C7C1511-EB17-4DBF-B04F-EFE8FF4ECE92}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NEEncryptsNET45.Test", "NEEncrypts.Tests\NEEncryptsNET45.Test\NEEncryptsNET45.Test.csproj", "{1ED77002-D542-4013-B71A-C52CE92D5747}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NEEncryptsNETCore.Test", "NEEncrypts.Tests\NEEncryptsNETCore.Test\NEEncryptsNETCore.Test.csproj", "{361FD688-A06B-4D68-9B76-93C6559278E8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1934F3A6-1396-46C2-BFD6-1E2DC1A26E3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1934F3A6-1396-46C2-BFD6-1E2DC1A26E3A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1934F3A6-1396-46C2-BFD6-1E2DC1A26E3A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1934F3A6-1396-46C2-BFD6-1E2DC1A26E3A}.Release|Any CPU.Build.0 = Release|Any CPU
{AAA669F5-E689-40CA-97EF-B5BA672B11DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AAA669F5-E689-40CA-97EF-B5BA672B11DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AAA669F5-E689-40CA-97EF-B5BA672B11DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AAA669F5-E689-40CA-97EF-B5BA672B11DD}.Release|Any CPU.Build.0 = Release|Any CPU
{7C7C1511-EB17-4DBF-B04F-EFE8FF4ECE92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7C7C1511-EB17-4DBF-B04F-EFE8FF4ECE92}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7C7C1511-EB17-4DBF-B04F-EFE8FF4ECE92}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7C7C1511-EB17-4DBF-B04F-EFE8FF4ECE92}.Release|Any CPU.Build.0 = Release|Any CPU
{1ED77002-D542-4013-B71A-C52CE92D5747}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1ED77002-D542-4013-B71A-C52CE92D5747}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1ED77002-D542-4013-B71A-C52CE92D5747}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1ED77002-D542-4013-B71A-C52CE92D5747}.Release|Any CPU.Build.0 = Release|Any CPU
{361FD688-A06B-4D68-9B76-93C6559278E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{361FD688-A06B-4D68-9B76-93C6559278E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{361FD688-A06B-4D68-9B76-93C6559278E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{361FD688-A06B-4D68-9B76-93C6559278E8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{7C7C1511-EB17-4DBF-B04F-EFE8FF4ECE92} = {1D162FFB-5944-470C-B6F0-8F7387C706DF}
{1ED77002-D542-4013-B71A-C52CE92D5747} = {1D162FFB-5944-470C-B6F0-8F7387C706DF}
{361FD688-A06B-4D68-9B76-93C6559278E8} = {1D162FFB-5944-470C-B6F0-8F7387C706DF}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E7AF20B3-4327-4DF7-B503-9FE08AA92A75}
EndGlobalSection
EndGlobal

二进制
src/NEEncrypts.Tests/NEEncrypts for linux.png 查看文件

之前 之后
宽度: 1302  |  高度: 504  |  大小: 84 KiB

+ 0
- 53
src/NEEncrypts.Tests/NEEncryptsNET4.Test/NEEncryptsNET4.Test.csproj 查看文件

@@ -1,53 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7C7C1511-EB17-4DBF-B04F-EFE8FF4ECE92}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>NEEncryptsNET4.Test</RootNamespace>
<AssemblyName>NEEncryptsNET4.Test</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\GBNewEnergy.Protocol\GBNewEnergy.Protocol.csproj">
<Project>{1934f3a6-1396-46c2-bfd6-1e2dc1a26e3a}</Project>
<Name>GBNewEnergy.Protocol</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

+ 0
- 46
src/NEEncrypts.Tests/NEEncryptsNET4.Test/Program.cs 查看文件

@@ -1,46 +0,0 @@
using GBNewEnergy.Protocol.NEEncrypts;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using GBNewEnergy.Protocol.Extensions;

namespace NEEncryptsNET4.Test
{
class Program
{
static void Main(string[] args)
{
Default_NEAES128EncryptImpl nE_AES128EncryptImpl = new Default_NEAES128EncryptImpl("smallchi");
string str = "aaasssddd123";
var bytes = Encoding.UTF8.GetBytes(str);
var encrypt = nE_AES128EncryptImpl.Encrypt(bytes);
Console.WriteLine("原数据:" + str);
Console.WriteLine("加密后:" + encrypt.ToHexString());
Console.WriteLine("解密后:" + Encoding.UTF8.GetString(nE_AES128EncryptImpl.Decrypt(encrypt)));

Default_NERSAEncryptImpl_NET rsa = new Default_NERSAEncryptImpl_NET(Encoding.UTF8,
"SHA256",
"<RSAKeyValue><Modulus>s+rl5mtcckCF9mEECD86L9UE2pbCR4CuiqDepwpiZCEflymQLNC3qNUPDlua9/kltyu6L489uimHRbEp4C7Gl7dDmaXVZLUVGkgUCZoRc8MrOw4+BiVAeQtCDdilPpA7DMN0bMfJAj3U4GuTU89/OWZMb9SYFfqEHM2e60PZHIU=</Modulus><Exponent>AQAB</Exponent><P>8qSTX42w2NaMCXL0PTZuacUFdJj93KopOJPD2q/JfmXSjXHV/IQK9YlCVKXHucqy8xcQgjkaKHqy3Rse14SZ7Q==</P><Q>vdJfDZ6ZIAQDx0sQbmbadHb6EOr8/oXo8B1CUSG0LqFZgDY7vBj17ujd6UhJWzhsg/5/3L+m4wDjMkUpOExZ+Q==</Q><DP>Av3Uc1Ej5QiAIX2xVS/enJ85Of7I4neWmoP33jJcoZpPxj6pDLv0BqLylmiU1c2R9z1JjtF1aRpaKi+zaaTQ4Q==</DP><DQ>Pv5yhv2MCYDrlBbIJCtD8gSN5lFllj3wWMcM/Am4VwU6w368Aicybo+fHUzc80XdVUx/OE3t30WrIEKtdD56WQ==</DQ><InverseQ>OcUQg0/kEGi9l2CgXCLKmQ1/1VVb+r89LXTO6rqi2wg5txkJIIXXePx7ce0Bh0eEnZzeSudwBLA3kqXmeAyYaw==</InverseQ><D>mnPL+zwtd7OmjTUJ5h6JUCi56wFDNWjl7gJeQd4rSzQYT4eRyrc/A4QsUbIYXkqXsyCpzExWvGsMQqrtfRQKzR53MBL3MQln5BjAUql2NqCkM2KT/D8Px5M21/TpMAycK4tGLOHgcCQRH1PQLHG1OfpfDASIzLwLgMjvMuHnIyE=</D></RSAKeyValue>",
"<RSAKeyValue><Modulus>s+rl5mtcckCF9mEECD86L9UE2pbCR4CuiqDepwpiZCEflymQLNC3qNUPDlua9/kltyu6L489uimHRbEp4C7Gl7dDmaXVZLUVGkgUCZoRc8MrOw4+BiVAeQtCDdilPpA7DMN0bMfJAj3U4GuTU89/OWZMb9SYFfqEHM2e60PZHIU=</Modulus><Exponent>AQAB</Exponent><P>8qSTX42w2NaMCXL0PTZuacUFdJj93KopOJPD2q/JfmXSjXHV/IQK9YlCVKXHucqy8xcQgjkaKHqy3Rse14SZ7Q==</P><Q>vdJfDZ6ZIAQDx0sQbmbadHb6EOr8/oXo8B1CUSG0LqFZgDY7vBj17ujd6UhJWzhsg/5/3L+m4wDjMkUpOExZ+Q==</Q><DP>Av3Uc1Ej5QiAIX2xVS/enJ85Of7I4neWmoP33jJcoZpPxj6pDLv0BqLylmiU1c2R9z1JjtF1aRpaKi+zaaTQ4Q==</DP><DQ>Pv5yhv2MCYDrlBbIJCtD8gSN5lFllj3wWMcM/Am4VwU6w368Aicybo+fHUzc80XdVUx/OE3t30WrIEKtdD56WQ==</DQ><InverseQ>OcUQg0/kEGi9l2CgXCLKmQ1/1VVb+r89LXTO6rqi2wg5txkJIIXXePx7ce0Bh0eEnZzeSudwBLA3kqXmeAyYaw==</InverseQ><D>mnPL+zwtd7OmjTUJ5h6JUCi56wFDNWjl7gJeQd4rSzQYT4eRyrc/A4QsUbIYXkqXsyCpzExWvGsMQqrtfRQKzR53MBL3MQln5BjAUql2NqCkM2KT/D8Px5M21/TpMAycK4tGLOHgcCQRH1PQLHG1OfpfDASIzLwLgMjvMuHnIyE=</D></RSAKeyValue>"
);

Console.WriteLine("原始字符串:" + str);
//加密
byte[] enBytes = rsa.Encrypt(Encoding.UTF8.GetBytes(str));
Console.WriteLine("加密字符串:" + enBytes.ToHexString());
//解密
byte[] deBytes = rsa.Decrypt(enBytes);
Console.WriteLine("解密字符串:" + Encoding.UTF8.GetString(deBytes));
//私钥签名
string signStr = rsa.Sign(str);
Console.WriteLine("字符串签名:" + signStr);
//公钥验证签名
bool signVerify = rsa.Verify(str, signStr);
Console.WriteLine("验证签名:" + signVerify);
Console.ReadKey();
}
}
}

+ 0
- 36
src/NEEncrypts.Tests/NEEncryptsNET4.Test/Properties/AssemblyInfo.cs 查看文件

@@ -1,36 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("NEEncryptsNET4.Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NEEncryptsNET4.Test")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]

// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("7c7c1511-eb17-4dbf-b04f-efe8ff4ece92")]

// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

+ 0
- 6
src/NEEncrypts.Tests/NEEncryptsNET45.Test/App.config 查看文件

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>

+ 0
- 57
src/NEEncrypts.Tests/NEEncryptsNET45.Test/NEEncryptsNET45.Test.csproj 查看文件

@@ -1,57 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{1ED77002-D542-4013-B71A-C52CE92D5747}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>NEEncryptsNET45.Test</RootNamespace>
<AssemblyName>NEEncryptsNET45.Test</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\GBNewEnergy.Protocol\GBNewEnergy.Protocol.csproj">
<Project>{1934f3a6-1396-46c2-bfd6-1e2dc1a26e3a}</Project>
<Name>GBNewEnergy.Protocol</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

+ 0
- 45
src/NEEncrypts.Tests/NEEncryptsNET45.Test/Program.cs 查看文件

@@ -1,45 +0,0 @@
using GBNewEnergy.Protocol.Extensions;
using GBNewEnergy.Protocol.NEEncrypts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NEEncryptsNET45.Test
{
class Program
{
static void Main(string[] args)
{
Default_NEAES128EncryptImpl nE_AES128EncryptImpl = new Default_NEAES128EncryptImpl("smallchi");
string str = "aaasssddd123";
var bytes = Encoding.UTF8.GetBytes(str);
var encrypt = nE_AES128EncryptImpl.Encrypt(bytes);
Console.WriteLine("原数据:" + str);
Console.WriteLine("加密后:" + encrypt.ToHexString());
Console.WriteLine("解密后:" + Encoding.UTF8.GetString(nE_AES128EncryptImpl.Decrypt(encrypt)));

Default_NERSAEncryptImpl_NET rsa = new Default_NERSAEncryptImpl_NET(Encoding.UTF8,
"SHA256",
"<RSAKeyValue><Modulus>s+rl5mtcckCF9mEECD86L9UE2pbCR4CuiqDepwpiZCEflymQLNC3qNUPDlua9/kltyu6L489uimHRbEp4C7Gl7dDmaXVZLUVGkgUCZoRc8MrOw4+BiVAeQtCDdilPpA7DMN0bMfJAj3U4GuTU89/OWZMb9SYFfqEHM2e60PZHIU=</Modulus><Exponent>AQAB</Exponent><P>8qSTX42w2NaMCXL0PTZuacUFdJj93KopOJPD2q/JfmXSjXHV/IQK9YlCVKXHucqy8xcQgjkaKHqy3Rse14SZ7Q==</P><Q>vdJfDZ6ZIAQDx0sQbmbadHb6EOr8/oXo8B1CUSG0LqFZgDY7vBj17ujd6UhJWzhsg/5/3L+m4wDjMkUpOExZ+Q==</Q><DP>Av3Uc1Ej5QiAIX2xVS/enJ85Of7I4neWmoP33jJcoZpPxj6pDLv0BqLylmiU1c2R9z1JjtF1aRpaKi+zaaTQ4Q==</DP><DQ>Pv5yhv2MCYDrlBbIJCtD8gSN5lFllj3wWMcM/Am4VwU6w368Aicybo+fHUzc80XdVUx/OE3t30WrIEKtdD56WQ==</DQ><InverseQ>OcUQg0/kEGi9l2CgXCLKmQ1/1VVb+r89LXTO6rqi2wg5txkJIIXXePx7ce0Bh0eEnZzeSudwBLA3kqXmeAyYaw==</InverseQ><D>mnPL+zwtd7OmjTUJ5h6JUCi56wFDNWjl7gJeQd4rSzQYT4eRyrc/A4QsUbIYXkqXsyCpzExWvGsMQqrtfRQKzR53MBL3MQln5BjAUql2NqCkM2KT/D8Px5M21/TpMAycK4tGLOHgcCQRH1PQLHG1OfpfDASIzLwLgMjvMuHnIyE=</D></RSAKeyValue>",
"<RSAKeyValue><Modulus>s+rl5mtcckCF9mEECD86L9UE2pbCR4CuiqDepwpiZCEflymQLNC3qNUPDlua9/kltyu6L489uimHRbEp4C7Gl7dDmaXVZLUVGkgUCZoRc8MrOw4+BiVAeQtCDdilPpA7DMN0bMfJAj3U4GuTU89/OWZMb9SYFfqEHM2e60PZHIU=</Modulus><Exponent>AQAB</Exponent><P>8qSTX42w2NaMCXL0PTZuacUFdJj93KopOJPD2q/JfmXSjXHV/IQK9YlCVKXHucqy8xcQgjkaKHqy3Rse14SZ7Q==</P><Q>vdJfDZ6ZIAQDx0sQbmbadHb6EOr8/oXo8B1CUSG0LqFZgDY7vBj17ujd6UhJWzhsg/5/3L+m4wDjMkUpOExZ+Q==</Q><DP>Av3Uc1Ej5QiAIX2xVS/enJ85Of7I4neWmoP33jJcoZpPxj6pDLv0BqLylmiU1c2R9z1JjtF1aRpaKi+zaaTQ4Q==</DP><DQ>Pv5yhv2MCYDrlBbIJCtD8gSN5lFllj3wWMcM/Am4VwU6w368Aicybo+fHUzc80XdVUx/OE3t30WrIEKtdD56WQ==</DQ><InverseQ>OcUQg0/kEGi9l2CgXCLKmQ1/1VVb+r89LXTO6rqi2wg5txkJIIXXePx7ce0Bh0eEnZzeSudwBLA3kqXmeAyYaw==</InverseQ><D>mnPL+zwtd7OmjTUJ5h6JUCi56wFDNWjl7gJeQd4rSzQYT4eRyrc/A4QsUbIYXkqXsyCpzExWvGsMQqrtfRQKzR53MBL3MQln5BjAUql2NqCkM2KT/D8Px5M21/TpMAycK4tGLOHgcCQRH1PQLHG1OfpfDASIzLwLgMjvMuHnIyE=</D></RSAKeyValue>"
);

Console.WriteLine("原始字符串:" + str);
//加密
byte[] enBytes = rsa.Encrypt(Encoding.UTF8.GetBytes(str));
Console.WriteLine("加密字符串:" + enBytes.ToHexString());
//解密
byte[] deBytes = rsa.Decrypt(enBytes);
Console.WriteLine("解密字符串:" + Encoding.UTF8.GetString(deBytes));
//私钥签名
string signStr = rsa.Sign(str);
Console.WriteLine("字符串签名:" + signStr);
//公钥验证签名
bool signVerify = rsa.Verify(str, signStr);
Console.WriteLine("验证签名:" + signVerify);
Console.ReadKey();
}
}
}

+ 0
- 36
src/NEEncrypts.Tests/NEEncryptsNET45.Test/Properties/AssemblyInfo.cs 查看文件

@@ -1,36 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("NEEncryptsNET45.Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NEEncryptsNET45.Test")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]

// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("1ed77002-d542-4013-b71a-c52ce92d5747")]

// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

+ 0
- 12
src/NEEncrypts.Tests/NEEncryptsNETCore.Test/NEEncryptsNETCore.Test.csproj 查看文件

@@ -1,12 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\GBNewEnergy.Protocol\GBNewEnergy.Protocol.csproj" />
</ItemGroup>

</Project>

+ 0
- 52
src/NEEncrypts.Tests/NEEncryptsNETCore.Test/Program.cs 查看文件

@@ -1,52 +0,0 @@
using GBNewEnergy.Protocol.NEEncrypts;
using GBNewEnergy.Protocol.Extensions;
using System;
using System.Text;
using System.Security.Cryptography;

namespace NEEncryptsNETCore.Test
{
class Program
{
static void Main(string[] args)
{
//Default_NEAES128EncryptImpl nE_AES128EncryptImpl = new Default_NEAES128EncryptImpl("smallchi");
string str = "aaaaaa111111";
//var bytes = Encoding.UTF8.GetBytes(str);
//var encrypt = nE_AES128EncryptImpl.Encrypt(bytes);
//Console.WriteLine("原数据:" + str);
//Console.WriteLine("加密后:" + encrypt.ToHexString());
//Console.WriteLine("解密后:" + Encoding.ASCII.GetString(nE_AES128EncryptImpl.Decrypt(encrypt)));

//NERSAEncryptImpl rsa = new NERSAEncryptImpl(
// new GBNewEnergy.Protocol.NEGlobalConfigs()
// {
// NEEncryptRSAPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoQh0wEqx/R2H1v00IU12Oc30fosRC/frhH89L6G+fzeaqI19MYQhEPMU13wpeqRONCUta+2iC1sgCNQ9qGGf19yGdZUfueaB1Nu9rdueQKXgVurGHJ+5N71UFm+OP1XcnFUCK4wT5d7ZIifXxuqLehP9Ts6sNjhVfa+yU+VjF5HoIe69OJEPo7OxRZcRTe17khc93Ic+PfyqswQJJlY/bgpcLJQnM+QuHmxNtF7/FpAx9YEQsShsGpVo7JaKgLo+s6AFoJ4QldQKir2vbN9vcKRbG3piElPilWDpjXQkOJZhUloh/jd7QrKFimZFldJ1r6Q59QYUyGKZARUe0KZpMQIDAQAB",
// NEEncryptRSAPrivateKey = "MIIEpAIBAAKCAQEAoQh0wEqx/R2H1v00IU12Oc30fosRC/frhH89L6G+fzeaqI19MYQhEPMU13wpeqRONCUta+2iC1sgCNQ9qGGf19yGdZUfueaB1Nu9rdueQKXgVurGHJ+5N71UFm+OP1XcnFUCK4wT5d7ZIifXxuqLehP9Ts6sNjhVfa+yU+VjF5HoIe69OJEPo7OxRZcRTe17khc93Ic+PfyqswQJJlY/bgpcLJQnM+QuHmxNtF7/FpAx9YEQsShsGpVo7JaKgLo+s6AFoJ4QldQKir2vbN9vcKRbG3piElPilWDpjXQkOJZhUloh/jd7QrKFimZFldJ1r6Q59QYUyGKZARUe0KZpMQIDAQABAoIBAQCRZLUlOUvjIVqYvhznRK1OG6p45s8JY1r+UnPIId2Bt46oSLeUkZvZVeCnfq9k0Bzb8AVGwVPhtPEDh73z3dEYcT/lwjLXAkyPB6gG5ZfI/vvC/k7JYV01+neFmktw2/FIJWjEMMF2dvLNZ/Pm4bX1Dz9SfD/45Hwr8wqrvRzvFZsj5qqOxv9RPAudOYwCwZskKp/GF+L+3Ycod1Wu98imzMZUH+L5dQuDGg3kvf3ljIAegTPoqYBg0imNPYY/EGoFKnbxlK5S5/5uAFb16dGJqAz3XQCz9Is/IWrOTu0etteqV2Ncs8uqPdjed+b0j8CMsr4U1xjwPQ8WwdaJtTkRAoGBANAndgiGZkCVcc9975/AYdgFp35W6D+hGQAZlL6DmnucUFdXbWa/x2rTSEXlkvgk9X/PxOptUYsLJkzysTgfDywZwuIXLm9B3oNmv3bVgPXsgDsvDfaHYCgz0nHK6NSrX2AeX3yO/dFuoZsuk+J+UyRigMqYj0wjmxUlqj183hinAoGBAMYMOBgF77OXRII7GAuEut/nBeh2sBrgyzR7FmJMs5kvRh6Ck8wp3ysgMvX4lxh1ep8iCw1R2cguqNATr1klOdsCTOE9RrhuvOp3JrYzuIAK6MpH/uBICy4w1rW2+gQySsHcH40r+tNaTFQ7dQ1tef//iy/IW8v8i0t+csztE1JnAoGABdtWYt8FOYP688+jUmdjWWSvVcq0NjYeMfaGTOX/DsNTL2HyXhW/Uq4nNnBDNmAz2CjMbZwt0y+5ICkj+2REVQVUinAEinTcAe5+LKXNPx4sbX3hcrJUbk0m+rSu4G0B/f5cyXBsi9wFCAzDdHgBduCepxSr04Sc9Hde1uQQi7kCgYB0U20HP0Vh+TG2RLuE2HtjVDD2L/CUeQEiXEHzjxXWnhvTg+MIAnggvpLwQwmMxkQ2ACr5sd/3YuCpB0bxV5o594nsqq9FWVYBaecFEjAGlWHSnqMoXWijwu/6X/VOTbP3VjH6G6ECT4GR4DKKpokIQrMgZ9DzaezvdOA9WesFdQKBgQCWfeOQTitRJ0NZACFUn3Fs3Rvgc9eN9YSWj4RtqkmGPMPvguWo+SKhlk3IbYjrRBc5WVOdoX8JXb2/+nAGhPCuUZckWVmZe5pMSr4EkNQdYeY8kOXGSjoTOUH34ZdKeS+e399BkBWIiXUejX/Srln0H4KoHnTWgxwNpTsBCgXu8Q==",
// NERSAType = GBNewEnergy.Protocol.NEGlobalConfigs.RSAType.RSA2
// });

Default_NERSAEncryptImpl rsa = new Default_NERSAEncryptImpl(
Encoding.UTF8,
HashAlgorithmName.SHA256,
"<RSAKeyValue><Modulus>s+rl5mtcckCF9mEECD86L9UE2pbCR4CuiqDepwpiZCEflymQLNC3qNUPDlua9/kltyu6L489uimHRbEp4C7Gl7dDmaXVZLUVGkgUCZoRc8MrOw4+BiVAeQtCDdilPpA7DMN0bMfJAj3U4GuTU89/OWZMb9SYFfqEHM2e60PZHIU=</Modulus><Exponent>AQAB</Exponent><P>8qSTX42w2NaMCXL0PTZuacUFdJj93KopOJPD2q/JfmXSjXHV/IQK9YlCVKXHucqy8xcQgjkaKHqy3Rse14SZ7Q==</P><Q>vdJfDZ6ZIAQDx0sQbmbadHb6EOr8/oXo8B1CUSG0LqFZgDY7vBj17ujd6UhJWzhsg/5/3L+m4wDjMkUpOExZ+Q==</Q><DP>Av3Uc1Ej5QiAIX2xVS/enJ85Of7I4neWmoP33jJcoZpPxj6pDLv0BqLylmiU1c2R9z1JjtF1aRpaKi+zaaTQ4Q==</DP><DQ>Pv5yhv2MCYDrlBbIJCtD8gSN5lFllj3wWMcM/Am4VwU6w368Aicybo+fHUzc80XdVUx/OE3t30WrIEKtdD56WQ==</DQ><InverseQ>OcUQg0/kEGi9l2CgXCLKmQ1/1VVb+r89LXTO6rqi2wg5txkJIIXXePx7ce0Bh0eEnZzeSudwBLA3kqXmeAyYaw==</InverseQ><D>mnPL+zwtd7OmjTUJ5h6JUCi56wFDNWjl7gJeQd4rSzQYT4eRyrc/A4QsUbIYXkqXsyCpzExWvGsMQqrtfRQKzR53MBL3MQln5BjAUql2NqCkM2KT/D8Px5M21/TpMAycK4tGLOHgcCQRH1PQLHG1OfpfDASIzLwLgMjvMuHnIyE=</D></RSAKeyValue>",
"<RSAKeyValue><Modulus>s+rl5mtcckCF9mEECD86L9UE2pbCR4CuiqDepwpiZCEflymQLNC3qNUPDlua9/kltyu6L489uimHRbEp4C7Gl7dDmaXVZLUVGkgUCZoRc8MrOw4+BiVAeQtCDdilPpA7DMN0bMfJAj3U4GuTU89/OWZMb9SYFfqEHM2e60PZHIU=</Modulus><Exponent>AQAB</Exponent><P>8qSTX42w2NaMCXL0PTZuacUFdJj93KopOJPD2q/JfmXSjXHV/IQK9YlCVKXHucqy8xcQgjkaKHqy3Rse14SZ7Q==</P><Q>vdJfDZ6ZIAQDx0sQbmbadHb6EOr8/oXo8B1CUSG0LqFZgDY7vBj17ujd6UhJWzhsg/5/3L+m4wDjMkUpOExZ+Q==</Q><DP>Av3Uc1Ej5QiAIX2xVS/enJ85Of7I4neWmoP33jJcoZpPxj6pDLv0BqLylmiU1c2R9z1JjtF1aRpaKi+zaaTQ4Q==</DP><DQ>Pv5yhv2MCYDrlBbIJCtD8gSN5lFllj3wWMcM/Am4VwU6w368Aicybo+fHUzc80XdVUx/OE3t30WrIEKtdD56WQ==</DQ><InverseQ>OcUQg0/kEGi9l2CgXCLKmQ1/1VVb+r89LXTO6rqi2wg5txkJIIXXePx7ce0Bh0eEnZzeSudwBLA3kqXmeAyYaw==</InverseQ><D>mnPL+zwtd7OmjTUJ5h6JUCi56wFDNWjl7gJeQd4rSzQYT4eRyrc/A4QsUbIYXkqXsyCpzExWvGsMQqrtfRQKzR53MBL3MQln5BjAUql2NqCkM2KT/D8Px5M21/TpMAycK4tGLOHgcCQRH1PQLHG1OfpfDASIzLwLgMjvMuHnIyE=</D></RSAKeyValue>"
);

Console.WriteLine("原始字符串:" + str);
//加密
byte[] enBytes = rsa.Encrypt(Encoding.UTF8.GetBytes(str));
Console.WriteLine("加密字符串:" + enBytes.ToHexString());
//解密
byte[] deBytes = rsa.Decrypt(enBytes);
Console.WriteLine("解密字符串:" + Encoding.UTF8.GetString(deBytes));
//私钥签名
string signStr = rsa.Sign(str);
Console.WriteLine("字符串签名:" + signStr);
//公钥验证签名
bool signVerify = rsa.Verify(str, signStr);
Console.WriteLine("验证签名:" + signVerify);
Console.ReadKey();
}
}
}

正在加载...
取消
保存