@@ -50,7 +50,7 @@ namespace JT809.Protocol.Benchmark | |||
MsgSN = 1666, | |||
EncryptKey = 9999, | |||
EncryptFlag = JT809Header_Encrypt.None, | |||
Version = "010000", | |||
Version = new JT809Header_Version(1, 0, 0), | |||
BusinessType = JT809Enums.JT809BusinessType.从链路报警信息交互消息, | |||
MsgGNSSCENTERID = 20180920, | |||
}; | |||
@@ -1,27 +0,0 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<OutputType>Exe</OutputType> | |||
<TargetFramework>netcoreapp2.1</TargetFramework> | |||
<LangVersion>7.3</LangVersion> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" /> | |||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" /> | |||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.1.1" /> | |||
<PackageReference Include="Microsoft.Extensions.Options" Version="2.1.1" /> | |||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.1.1" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\JT809.Protocol.Extensions.DependencyInjection\JT809.Protocol.Extensions.DependencyInjection.csproj" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<None Update="appsettings.json"> | |||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||
</None> | |||
</ItemGroup> | |||
</Project> |
@@ -1,27 +0,0 @@ | |||
using JT809.Protocol.Extensions.DependencyInjection.Options; | |||
using Microsoft.Extensions.Configuration; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using Microsoft.Extensions.Hosting; | |||
using System; | |||
using System.Threading.Tasks; | |||
namespace JT809.Protocol.Extensions.DependencyInjection.Test | |||
{ | |||
class Program | |||
{ | |||
static async Task Main(string[] args) | |||
{ | |||
var serverHostBuilder = new HostBuilder() | |||
.ConfigureAppConfiguration((hostingContext, config) => | |||
{ | |||
config.SetBasePath(AppDomain.CurrentDomain.BaseDirectory); | |||
config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); | |||
}) | |||
.ConfigureServices((hostContext, services) => | |||
{ | |||
services.AddJT809Configure(hostContext.Configuration.GetSection("JT809Options")); | |||
}); | |||
await serverHostBuilder.RunConsoleAsync(); | |||
} | |||
} | |||
} |
@@ -1,29 +0,0 @@ | |||
{ | |||
"Logging": { | |||
"IncludeScopes": false, | |||
"Debug": { | |||
"LogLevel": { | |||
"Default": "Trace" | |||
} | |||
}, | |||
"Console": { | |||
"LogLevel": { | |||
"Default": "Trace" | |||
} | |||
} | |||
}, | |||
"JT809Options": { | |||
"HeaderOptions": { | |||
"MsgGNSSCENTERID": 20181012, | |||
"EncryptFlag": "None", | |||
"EncryptKey": 9999, | |||
"Version": "1.0.0" | |||
}, | |||
"EncryptOptions": { | |||
"M1": 0, | |||
"IA1": 0, | |||
"IC1": 0, | |||
"Key": 0 | |||
} | |||
} | |||
} |
@@ -1,52 +0,0 @@ | |||
using Microsoft.Extensions.DependencyInjection; | |||
using Microsoft.Extensions.DependencyInjection.Extensions; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using JT809.Protocol.JT809Configs; | |||
using Microsoft.Extensions.Configuration; | |||
using JT809.Protocol.JT809Encrypt; | |||
using JT809.Protocol.Extensions.DependencyInjection.Options; | |||
using Microsoft.Extensions.Options; | |||
namespace JT809.Protocol.Extensions.DependencyInjection | |||
{ | |||
public static class DependencyInjectionExtensions | |||
{ | |||
public static IServiceCollection AddJT809Configure(this IServiceCollection services, IConfiguration configuration) | |||
{ | |||
services.Configure<JT809Options>(configuration); | |||
ServiceProvider serviceProvider = services.BuildServiceProvider(); | |||
JT809Options options = serviceProvider.GetRequiredService<IOptions<JT809Options>>().Value; | |||
var versions = options.Version.Split(new string []{ "." }, StringSplitOptions.RemoveEmptyEntries); | |||
if (versions.Length == 3) | |||
{ | |||
options.HeaderOptions.Version = new JT809Header_Version(byte.Parse(versions[0]), byte.Parse(versions[1]), byte.Parse(versions[2])); | |||
} | |||
else if(versions.Length == 2) | |||
{ | |||
options.HeaderOptions.Version = new JT809Header_Version(byte.Parse(versions[0]), byte.Parse(versions[1]),0); | |||
} | |||
else if (versions.Length == 1) | |||
{ | |||
options.HeaderOptions.Version = new JT809Header_Version(byte.Parse(versions[0]), 0, 0); | |||
} | |||
JT809GlobalConfig.Instance.SetHeaderOptions(options.HeaderOptions); | |||
JT809GlobalConfig.Instance.SetSkipCRCCode(options.SkipCRCCode); | |||
if (options.HeaderOptions.EncryptFlag == JT809Header_Encrypt.Common) | |||
{ | |||
JT809GlobalConfig.Instance.SetEncrypt(new JT809EncryptImpl(options.EncryptOptions)); | |||
} | |||
try | |||
{ | |||
var msgSNDistributedImpl = services.BuildServiceProvider().GetRequiredService<IMsgSNDistributed>(); | |||
JT809GlobalConfig.Instance.SetMsgSNDistributed(msgSNDistributedImpl); | |||
} | |||
catch | |||
{ | |||
} | |||
return services; | |||
} | |||
} | |||
} |
@@ -1,15 +0,0 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>netstandard2.0</TargetFramework> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="JT809" Version="1.0.4" /> | |||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.1.1" /> | |||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" /> | |||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.1.1" /> | |||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.1.1" /> | |||
</ItemGroup> | |||
</Project> |
@@ -1,23 +0,0 @@ | |||
using JT809.Protocol.JT809Configs; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
namespace JT809.Protocol.Extensions.DependencyInjection.Options | |||
{ | |||
public class JT809Options | |||
{ | |||
public JT809EncryptOptions EncryptOptions { get; set; } | |||
public JT809HeaderOptions HeaderOptions { get; set; } | |||
/// <summary> | |||
/// 版本号: | |||
/// 默认 1.0.0 | |||
/// </summary> | |||
public string Version { get; set; } | |||
/// <summary> | |||
/// 设置跳过校验码 | |||
/// 场景:测试的时候,可能需要收到改数据,所以测试的时候有用 | |||
/// </summary> | |||
public bool SkipCRCCode { get; set; } | |||
} | |||
} |
@@ -14,7 +14,8 @@ namespace JT809.Protocol.Test.JT809Encrypt | |||
{ | |||
IA1 = 20000000, | |||
IC1 = 20000000, | |||
M1 = 30000000 | |||
M1 = 30000000, | |||
Key = 256178, | |||
}; | |||
[Fact] | |||
@@ -25,7 +26,7 @@ namespace JT809.Protocol.Test.JT809Encrypt | |||
01,02,03,04,05,06,07 | |||
}; | |||
IJT809Encrypt jT809Encrypt = new JT809EncryptImpl(options); | |||
var data = jT809Encrypt.Encrypt(bytes, 256178).ToHexString(); | |||
var data = jT809Encrypt.Encrypt(bytes).ToHexString(); | |||
//"D3 4C 70 78 A7 3A 41" | |||
} | |||
@@ -34,7 +35,7 @@ namespace JT809.Protocol.Test.JT809Encrypt | |||
{ | |||
byte[] bytes = "D3 4C 70 78 A7 3A 41".ToHexBytes(); | |||
IJT809Encrypt jT809Encrypt = new JT809EncryptImpl(options); | |||
var data = jT809Encrypt.Decrypt(bytes, 256178); | |||
var data = jT809Encrypt.Decrypt(bytes); | |||
Assert.Equal(new byte[] | |||
{ | |||
01,02,03,04,05,06,07 | |||
@@ -19,7 +19,7 @@ namespace JT809.Protocol.Test | |||
jT809Header.MsgSN = 1024; | |||
jT809Header.BusinessType = JT809Enums.JT809BusinessType.从链路静态信息交换消息; | |||
jT809Header.MsgGNSSCENTERID = 1200; | |||
jT809Header.Version = "010000"; | |||
jT809Header.Version = new JT809Header_Version(); | |||
jT809Header.EncryptFlag = JT809Header_Encrypt.None; | |||
jT809Header.EncryptKey = 0; | |||
var hex = JT809Serializer.Serialize(jT809Header).ToHexString(); | |||
@@ -35,25 +35,11 @@ namespace JT809.Protocol.Test | |||
Assert.Equal((uint)1024, jT809Header.MsgSN); | |||
Assert.Equal(JT809Enums.JT809BusinessType.从链路静态信息交换消息, jT809Header.BusinessType); | |||
Assert.Equal((uint)1200, jT809Header.MsgGNSSCENTERID); | |||
Assert.Equal("010000", jT809Header.Version); | |||
Assert.Equal(new JT809Header_Version().ToString(), jT809Header.Version.ToString()); | |||
Assert.Equal(JT809Header_Encrypt.None, jT809Header.EncryptFlag); | |||
Assert.Equal((uint)0, jT809Header.EncryptKey); | |||
} | |||
[Fact] | |||
public void Test4() | |||
{ | |||
JT809Header jT809Header = new JT809Header(); | |||
jT809Header.MsgLength = 24; | |||
jT809Header.MsgSN = 1024; | |||
jT809Header.BusinessType = JT809Enums.JT809BusinessType.从链路静态信息交换消息; | |||
jT809Header.MsgGNSSCENTERID = 1200; | |||
jT809Header.Version = "0F0A0B"; | |||
jT809Header.EncryptFlag = JT809Header_Encrypt.None; | |||
jT809Header.EncryptKey = 0; | |||
var hex = JT809Serializer.Serialize(jT809Header).ToHexString(); | |||
} | |||
[Fact] | |||
public void Test3() | |||
{ | |||
@@ -17,7 +17,8 @@ namespace JT809.Protocol.Test.JT809Packages | |||
{ | |||
IA1 = 20000000, | |||
IC1 = 20000000, | |||
M1 = 30000000 | |||
M1 = 30000000, | |||
Key = 256178, | |||
})); | |||
} | |||
@@ -29,7 +30,7 @@ namespace JT809.Protocol.Test.JT809Packages | |||
{ | |||
EncryptFlag= JT809Header_Encrypt.Common, | |||
MsgSN= 133, | |||
EncryptKey= 256178, | |||
EncryptKey=5819, | |||
BusinessType= JT809Enums.JT809BusinessType.主链路登录请求消息, | |||
MsgGNSSCENTERID= 20180920, | |||
}; | |||
@@ -46,15 +47,16 @@ namespace JT809.Protocol.Test.JT809Packages | |||
[Fact] | |||
public void Test2() | |||
{ | |||
var bytes = "5B000000480000008510010133EFB8010000010003E8B2D37D9CC4900C77DC78F8676527D8AE12243CFB64CC2FBA619AEFAD33ACCB3256F67BFF19DF33097841098665703FE36E5D".ToStr2HexBytes(); | |||
var bytes = "5B 00 00 00 48 00 00 00 85 10 01 01 33 EF B8 01 00 00 01 00 00 16 BB D3 7D 9C C4 90 0C 77 DC 78 F8 67 65 27 D8 AE 12 24 3C FB 64 CC 2F BA 61 9A EF AD 33 AC CB 32 56 F6 7B FF 19 DF 33 09 78 41 09 86 65 70 3F 2E B5 5D".ToHexBytes(); | |||
JT809Package jT809Package = JT809Serializer.Deserialize(bytes); | |||
Assert.Equal(JT809Header_Encrypt.Common, jT809Package.Header.EncryptFlag); | |||
Assert.Equal((uint)256178, jT809Package.Header.EncryptKey); | |||
Assert.Equal((uint)5819, jT809Package.Header.EncryptKey); | |||
Assert.Equal((uint)72, jT809Package.Header.MsgLength); | |||
Assert.Equal((uint)133, jT809Package.Header.MsgSN); | |||
Assert.Equal((uint)5819, jT809Package.Header.EncryptKey); | |||
Assert.Equal((uint)20180920, jT809Package.Header.MsgGNSSCENTERID); | |||
Assert.Equal(JT809Enums.JT809BusinessType.主链路登录请求消息, jT809Package.Header.BusinessType); | |||
Assert.Equal("010000", jT809Package.Header.Version); | |||
Assert.Equal(new JT809Header_Version().ToString(), jT809Package.Header.Version.ToString()); | |||
JT809_0x1001 jT809_0X1001 = (JT809_0x1001)jT809Package.Bodies; | |||
Assert.Equal((uint)20180920, jT809_0X1001.UserId); | |||
Assert.Equal("20180920", jT809_0X1001.Password); | |||
@@ -54,7 +54,7 @@ namespace JT809.Protocol.Test.JT809Packages | |||
Assert.Equal((uint)9999, jT809Package.Header.EncryptKey); | |||
Assert.Equal((uint)20180920, jT809Package.Header.MsgGNSSCENTERID); | |||
Assert.Equal(JT809Enums.JT809BusinessType.主链路登录请求消息, jT809Package.Header.BusinessType); | |||
Assert.Equal("010000", jT809Package.Header.Version); | |||
Assert.Equal(new JT809Header_Version().ToString(), jT809Package.Header.Version.ToString()); | |||
JT809_0x1001 jT809_0X1001 = (JT809_0x1001)jT809Package.Bodies; | |||
Assert.Equal((uint)20180920, jT809_0X1001.UserId); | |||
Assert.Equal("20180920", jT809_0X1001.Password); | |||
@@ -22,7 +22,7 @@ namespace JT809.Protocol.Test.JT809Packages | |||
MsgSN = 1666, | |||
EncryptKey = 9999, | |||
EncryptFlag= JT809Header_Encrypt.None, | |||
Version = "010000", | |||
Version = new JT809Header_Version(1, 0, 0), | |||
BusinessType = JT809Enums.JT809BusinessType.从链路报警信息交互消息, | |||
MsgGNSSCENTERID = 20180920, | |||
}; | |||
@@ -64,7 +64,7 @@ namespace JT809.Protocol.Test.JT809Packages | |||
Assert.Equal(JT809Header_Encrypt.None, jT809Package.Header.EncryptFlag); | |||
Assert.Equal((uint)20180920, jT809Package.Header.MsgGNSSCENTERID); | |||
Assert.Equal(JT809Enums.JT809BusinessType.从链路报警信息交互消息, jT809Package.Header.BusinessType); | |||
Assert.Equal("010000", jT809Package.Header.Version); | |||
Assert.Equal(new JT809Header_Version().ToString(), jT809Package.Header.Version.ToString()); | |||
JT809_0x9400 jT809_0X400 = (JT809_0x9400)jT809Package.Bodies; | |||
Assert.Equal("粤A12345", jT809_0X400.VehicleNo); | |||
@@ -7,11 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT809.Protocol", "JT809.Pro | |||
EndProject | |||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT809.Protocol.Test", "JT809.Protocol.Test\JT809.Protocol.Test.csproj", "{59D2D876-8D81-4CCE-839A-B153912C0C27}" | |||
EndProject | |||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT809.Protocol.Benchmark", "JT809.Protocol.Benchmark\JT809.Protocol.Benchmark.csproj", "{47CE50B3-A0D6-4F5F-907B-01BD7B8AB87F}" | |||
EndProject | |||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JT809.Protocol.Extensions.DependencyInjection", "JT809.Protocol.Extensions.DependencyInjection\JT809.Protocol.Extensions.DependencyInjection.csproj", "{974E9013-A19E-4643-8AB4-504D916AF4BD}" | |||
EndProject | |||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JT809.Protocol.Extensions.DependencyInjection.Test", "JT809.Protocol.Extensions.DependencyInjection.Test\JT809.Protocol.Extensions.DependencyInjection.Test.csproj", "{F3E0933D-13A9-48AA-958A-7903221D5DFA}" | |||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JT809.Protocol.Benchmark", "JT809.Protocol.Benchmark\JT809.Protocol.Benchmark.csproj", "{47CE50B3-A0D6-4F5F-907B-01BD7B8AB87F}" | |||
EndProject | |||
Global | |||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | |||
@@ -31,14 +27,6 @@ Global | |||
{47CE50B3-A0D6-4F5F-907B-01BD7B8AB87F}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
{47CE50B3-A0D6-4F5F-907B-01BD7B8AB87F}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
{47CE50B3-A0D6-4F5F-907B-01BD7B8AB87F}.Release|Any CPU.Build.0 = Release|Any CPU | |||
{974E9013-A19E-4643-8AB4-504D916AF4BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||
{974E9013-A19E-4643-8AB4-504D916AF4BD}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
{974E9013-A19E-4643-8AB4-504D916AF4BD}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
{974E9013-A19E-4643-8AB4-504D916AF4BD}.Release|Any CPU.Build.0 = Release|Any CPU | |||
{F3E0933D-13A9-48AA-958A-7903221D5DFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||
{F3E0933D-13A9-48AA-958A-7903221D5DFA}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
{F3E0933D-13A9-48AA-958A-7903221D5DFA}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
{F3E0933D-13A9-48AA-958A-7903221D5DFA}.Release|Any CPU.Build.0 = Release|Any CPU | |||
EndGlobalSection | |||
GlobalSection(SolutionProperties) = preSolution | |||
HideSolutionNode = FALSE | |||
@@ -2,7 +2,7 @@ | |||
{ | |||
public interface IJT809Encrypt | |||
{ | |||
byte[] Encrypt(byte[] buffer, uint privateKey); | |||
byte[] Decrypt(byte[] buffer, uint privateKey); | |||
byte[] Encrypt(byte[] buffer); | |||
byte[] Decrypt(byte[] buffer); | |||
} | |||
} |
@@ -5,5 +5,6 @@ | |||
public uint M1 { get; set; } | |||
public uint IA1 { get; set; } | |||
public uint IC1 { get; set; } | |||
public uint Key { get; set; } | |||
} | |||
} |
@@ -15,7 +15,7 @@ namespace JT809.Protocol.JT809Configs | |||
/// 编号;长度为 3 个字节来表示,0x01 0x02 0x0F 标识 | |||
/// 的版本号是 v1.2.15,以此类推。 | |||
/// </summary> | |||
public string Version { get; set; } = "010000"; | |||
public JT809Header_Version Version { get; set; } = new JT809Header_Version(); | |||
/// <summary> | |||
/// 报文加密标识位 b: 0 表示报文不加密,1 表示报文加密。 | |||
/// </summary> | |||
@@ -14,17 +14,17 @@ namespace JT809.Protocol.JT809Encrypt | |||
this.jT809EncryptOptions = jT809EncryptOptions; | |||
} | |||
public byte[] Decrypt(byte[] buffer, uint privateKey) | |||
public byte[] Decrypt(byte[] buffer) | |||
{ | |||
return Encrypt(buffer, privateKey); | |||
return Encrypt(buffer); | |||
} | |||
public byte[] Encrypt(byte[] buffer, uint privateKey) | |||
public byte[] Encrypt(byte[] buffer) | |||
{ | |||
byte[] data = new byte[buffer.Length]; | |||
if (0 == privateKey) | |||
if (0 == jT809EncryptOptions.Key) | |||
{ | |||
privateKey = 1; | |||
jT809EncryptOptions.Key = 1; | |||
} | |||
uint mkey = jT809EncryptOptions.M1; | |||
if (0 == mkey) | |||
@@ -33,8 +33,8 @@ namespace JT809.Protocol.JT809Encrypt | |||
} | |||
for (int idx = 0; idx < buffer.Length; idx++) | |||
{ | |||
privateKey = jT809EncryptOptions.IA1 * (privateKey % mkey) + jT809EncryptOptions.IC1; | |||
buffer[idx] ^= (byte)((privateKey >> 20) & 0xFF); | |||
jT809EncryptOptions.Key = jT809EncryptOptions.IA1 * (jT809EncryptOptions.Key % mkey) + jT809EncryptOptions.IC1; | |||
buffer[idx] ^= (byte)((jT809EncryptOptions.Key >> 20) & 0xFF); | |||
data[idx] = buffer[idx]; | |||
} | |||
return data; | |||
@@ -19,24 +19,14 @@ namespace JT809.Protocol.JT809Extensions | |||
return bcdSb.ToString(); | |||
} | |||
public static int WriteBCDLittle(IMemoryOwner<byte> memoryOwner, int offset, string data, int len) | |||
public static int WriteBCDLittle(IMemoryOwner<byte> memoryOwner, int offset, string data, int digit, int len) | |||
{ | |||
string bcdText = data == null ? "" : data; | |||
byte[] bytes = new byte[len]; | |||
int startIndex = 0; | |||
int noOfZero = len * 2 - data.Length; | |||
if (noOfZero > 0) | |||
ReadOnlySpan<char> bcd = data.PadLeft(len, '0').AsSpan(); | |||
for (int i = 0; i < digit; i++) | |||
{ | |||
bcdText = bcdText.Insert(startIndex, new string('0', noOfZero)); | |||
memoryOwner.Memory.Span[offset + i] = Convert.ToByte(bcd.Slice(i * 2, 2).ToString(), 16); | |||
} | |||
int byteIndex = 0; | |||
while (startIndex < bcdText.Length && byteIndex < len) | |||
{ | |||
memoryOwner.Memory.Span[offset + byteIndex] = Convert.ToByte(bcdText.Substring(startIndex, 2), 16); | |||
startIndex += 2; | |||
byteIndex++; | |||
} | |||
return len; | |||
return digit; | |||
} | |||
} | |||
} |
@@ -17,7 +17,7 @@ namespace JT809.Protocol.JT809Formatters | |||
jT809Header.MsgSN= JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); | |||
jT809Header.BusinessType = (JT809BusinessType)JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); | |||
jT809Header.MsgGNSSCENTERID = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); | |||
jT809Header.Version = JT809BinaryExtensions.ReadBCDLittle(bytes, ref offset, 3); | |||
jT809Header.Version = new JT809Header_Version(JT809BinaryExtensions.ReadBytesLittle(bytes, ref offset, JT809Header_Version.FixedByteLength)); | |||
jT809Header.EncryptFlag= (JT809Header_Encrypt)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); | |||
jT809Header.EncryptKey= JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); | |||
readSize = offset; | |||
@@ -30,7 +30,7 @@ namespace JT809.Protocol.JT809Formatters | |||
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.MsgSN); | |||
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, (ushort)value.BusinessType); | |||
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.MsgGNSSCENTERID); | |||
offset += JT809BinaryExtensions.WriteBCDLittle(memoryOwner, offset, value.Version,3); | |||
offset += JT809BinaryExtensions.WriteBytesLittle(memoryOwner, offset, value.Version.Buffer); | |||
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.EncryptFlag); | |||
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.EncryptKey); | |||
return offset; | |||
@@ -65,7 +65,7 @@ namespace JT809.Protocol.JT809Formatters | |||
jT809Package.Bodies = JT809FormatterResolverExtensions.JT809DynamicDeserialize(JT809FormatterExtensions.GetFormatter(jT809BodiesTypeAttribute.JT809BodiesType), buffer.Slice(offset, checkIndex - offset), out readSize); | |||
break; | |||
case JT809Header_Encrypt.Common: | |||
byte[] bodiesData = JT809GlobalConfig.Instance.Encrypt.Decrypt(buffer.Slice(offset, checkIndex - offset).ToArray(), jT809Package.Header.EncryptKey); | |||
byte[] bodiesData = JT809GlobalConfig.Instance.Encrypt.Decrypt(buffer.Slice(offset, checkIndex - offset).ToArray()); | |||
jT809Package.Bodies = JT809FormatterResolverExtensions.JT809DynamicDeserialize(JT809FormatterExtensions.GetFormatter(jT809BodiesTypeAttribute.JT809BodiesType), bodiesData, out readSize); | |||
break; | |||
} | |||
@@ -104,7 +104,7 @@ namespace JT809.Protocol.JT809Formatters | |||
case JT809Header_Encrypt.None: | |||
break; | |||
case JT809Header_Encrypt.Common: | |||
messageBodyData = JT809GlobalConfig.Instance.Encrypt.Encrypt(messageBodyData, value.Header.EncryptKey); | |||
messageBodyData = JT809GlobalConfig.Instance.Encrypt.Encrypt(messageBodyData); | |||
break; | |||
} | |||
} | |||
@@ -27,7 +27,7 @@ namespace JT809.Protocol.JT809Formatters.JT809SubMessageBodyFormatters | |||
public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9500_0x9505 value) | |||
{ | |||
offset += JT809BinaryExtensions.WriteBCDLittle(memoryOwner, offset, value.AuthenticationCode,20); | |||
offset += JT809BinaryExtensions.WriteBCDLittle(memoryOwner, offset, value.AuthenticationCode,10,20); | |||
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.AccessPointName,20); | |||
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.UserName, 49); | |||
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.Password, 22); | |||
@@ -1,5 +1,4 @@ | |||
using JT809.Protocol.JT809Configs; | |||
using JT809.Protocol.JT809Encrypt; | |||
using JT809.Protocol.JT809Internal; | |||
using System; | |||
using System.Collections.Generic; | |||
@@ -37,18 +36,6 @@ namespace JT809.Protocol | |||
/// </summary> | |||
public bool SkipCRCCode { get; private set; } | |||
/// <summary> | |||
/// 设置加密算法选项值 | |||
/// 不同的上下级平台之间,加密的算法是一致的,但是针对 M1, IA1, IC1 的不同。 | |||
/// 数据先经过加密而后解密。 | |||
/// </summary> | |||
/// <param name="jT809Encrypt"></param> | |||
/// <returns></returns> | |||
public JT809GlobalConfig SetEncryptOptions(JT809EncryptOptions jT809EncryptOptions) | |||
{ | |||
instance.Value.Encrypt = new JT809EncryptImpl(jT809EncryptOptions); | |||
return instance.Value; | |||
} | |||
/// <summary> | |||
/// 设置加密算法实现 | |||
/// </summary> | |||
/// <param name="jT809Encrypt"></param> | |||
@@ -38,9 +38,8 @@ namespace JT809.Protocol | |||
/// 协议版本号标识,上下级平台之间采用的标准协议版 | |||
/// 编号;长度为 3 个字节来表示,0x01 0x02 0x0F 标识 | |||
/// 的版本号是 v1.2.15,以此类推。 | |||
/// BCD编码 | |||
/// </summary> | |||
public string Version { get; set; } = "010000"; | |||
public JT809Header_Version Version { get; set; } = new JT809Header_Version(); | |||
/// <summary> | |||
/// 报文加密标识位 b: 0 表示报文不加密,1 表示报文加密。 | |||
/// </summary> | |||
@@ -4,13 +4,9 @@ using System.Text; | |||
namespace JT809.Protocol | |||
{ | |||
/// <summary> | |||
/// 协议版本号标识 | |||
/// BCD编码 | |||
/// </summary> | |||
public class JT809Header_Version | |||
{ | |||
public byte[] Buffer { get;} = new byte[3]; | |||
public byte[] Buffer { get; } = new byte[3]; | |||
private const int MajorIndex = 0; | |||
private const int MinorIndex = 1; | |||
private const int BuildIndex = 2; | |||
@@ -19,19 +15,19 @@ namespace JT809.Protocol | |||
public byte Major | |||
{ | |||
get { return Buffer[MajorIndex]; } | |||
set { Buffer[MajorIndex] = value; } | |||
private set { Buffer[MajorIndex] = value; } | |||
} | |||
public byte Minor | |||
{ | |||
get { return Buffer[MinorIndex]; } | |||
set { Buffer[MinorIndex] = value; } | |||
private set { Buffer[MinorIndex] = value; } | |||
} | |||
public byte Build | |||
{ | |||
get { return Buffer[BuildIndex]; } | |||
set { Buffer[BuildIndex] = value; } | |||
private set { Buffer[BuildIndex] = value; } | |||
} | |||
/// <summary> | |||