@@ -59,7 +59,7 @@ | |||||
#### 1.组包: | #### 1.组包: | ||||
> 业务数据类型 BusinessType:从链路报警信息交互消息 | > 业务数据类型 BusinessType:从链路报警信息交互消息 | ||||
> | > | ||||
> 子业务类型标识 SubBusinessType:报警督办请求消息 | > 子业务类型标识 SubBusinessType:报警督办请求消息 | ||||
``` code | ``` code | ||||
@@ -185,7 +185,9 @@ Assert.Equal("12345678901", jT809_0x9400_0x9401.SupervisorTel); | |||||
Assert.Equal("123456@qq.com", jT809_0x9400_0x9401.SupervisorEmail); | Assert.Equal("123456@qq.com", jT809_0x9400_0x9401.SupervisorEmail); | ||||
``` | ``` | ||||
### 举个栗子2 | ### 举个栗子2 | ||||
``` data2 | ``` data2 | ||||
// 设置全局配置 | // 设置全局配置 | ||||
JT809GlobalConfig.Instance.SetHeaderOptions(new JT809Configs.JT809HeaderOptions | JT809GlobalConfig.Instance.SetHeaderOptions(new JT809Configs.JT809HeaderOptions | ||||
@@ -215,7 +217,9 @@ JT809Package jT809Package = JT809BusinessType.从链路报警信息交互消息. | |||||
}); | }); | ||||
var hex = JT809Serializer.Serialize(jT809Package); | var hex = JT809Serializer.Serialize(jT809Package); | ||||
``` | ``` | ||||
### 举个栗子3 | ### 举个栗子3 | ||||
``` data3 | ``` data3 | ||||
static void Main(string[] args) | static void Main(string[] args) | ||||
{ | { | ||||
@@ -227,8 +231,7 @@ static void Main(string[] args) | |||||
{ | { | ||||
IA1 = 20000000, | IA1 = 20000000, | ||||
IC1 = 20000000, | IC1 = 20000000, | ||||
M1 = 30000000, | M1 = 30000000 | ||||
Key = 256178 | |||||
}) | }) | ||||
) | ) | ||||
// 设置头部信息 | // 设置头部信息 | ||||
@@ -246,11 +249,53 @@ static void Main(string[] args) | |||||
} | } | ||||
``` | ``` | ||||
### 举个栗子4 | |||||
``` data DI | |||||
// 使用依赖注入的方式实现配置 | |||||
// Install-Package JT809.Extensions.DependencyInjection | |||||
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) => | |||||
{ | |||||
// 方式1: | |||||
//services.AddJT809Configure(hostContext.Configuration.GetSection("JT809Options")); | |||||
// 方式2: | |||||
services.AddJT809Configure(new JT809Options | |||||
{ | |||||
HeaderOptions=new JT809Configs.JT809HeaderOptions { | |||||
MsgGNSSCENTERID=20181012, | |||||
EncryptFlag= JT809Header_Encrypt.Common, | |||||
EncryptKey= 9999, | |||||
Version = new JT809Header_Version{ | |||||
Major=2, | |||||
Minor=1, | |||||
Build= 2 | |||||
} | |||||
}, | |||||
EncryptOptions = new JT809Configs.JT809EncryptOptions { | |||||
IA1 = 20000000, | |||||
IC1 = 20000000, | |||||
M1 = 30000000 | |||||
} | |||||
}); | |||||
}); | |||||
await serverHostBuilder.RunConsoleAsync(); | |||||
} | |||||
``` | |||||
## NuGet安装 | ## NuGet安装 | ||||
| Package Name | Version | Downloads | | Package Name | Version | Downloads | ||||
|--------------| ------- | ---- | |--------------| ------- | ---- | ||||
| Install-Package JT809 |  |  | | Install-Package JT809 |  |  | ||||
| Install-Package JT809.Extensions.DependencyInjection |  |  | |||||
## 使用BenchmarkDotNet性能测试报告(只是玩玩,不能当真) | ## 使用BenchmarkDotNet性能测试报告(只是玩玩,不能当真) | ||||
@@ -19,7 +19,27 @@ namespace JT809.Protocol.Extensions.DependencyInjection.Test | |||||
}) | }) | ||||
.ConfigureServices((hostContext, services) => | .ConfigureServices((hostContext, services) => | ||||
{ | { | ||||
services.AddJT809Configure(hostContext.Configuration.GetSection("JT809Options")); | // 方式1: | ||||
//services.AddJT809Configure(hostContext.Configuration.GetSection("JT809Options")); | |||||
// 方式2: | |||||
services.AddJT809Configure(new JT809Options | |||||
{ | |||||
HeaderOptions=new JT809Configs.JT809HeaderOptions { | |||||
MsgGNSSCENTERID=20181012, | |||||
EncryptFlag= JT809Header_Encrypt.Common, | |||||
EncryptKey= 9999, | |||||
Version = new JT809Header_Version{ | |||||
Major=2, | |||||
Minor=1, | |||||
Build= 2 | |||||
} | |||||
}, | |||||
EncryptOptions = new JT809Configs.JT809EncryptOptions { | |||||
M1= 10000000, | |||||
IA1=20000000, | |||||
IC1=30000000 | |||||
} | |||||
}); | |||||
}); | }); | ||||
await serverHostBuilder.RunConsoleAsync(); | await serverHostBuilder.RunConsoleAsync(); | ||||
} | } | ||||
@@ -1,29 +1,19 @@ | |||||
{ | { | ||||
"Logging": { | |||||
"IncludeScopes": false, | |||||
"Debug": { | |||||
"LogLevel": { | |||||
"Default": "Trace" | |||||
} | |||||
}, | |||||
"Console": { | |||||
"LogLevel": { | |||||
"Default": "Trace" | |||||
} | |||||
} | |||||
}, | |||||
"JT809Options": { | "JT809Options": { | ||||
"HeaderOptions": { | "HeaderOptions": { | ||||
"MsgGNSSCENTERID": 20181012, | "MsgGNSSCENTERID": 20181012, | ||||
"EncryptFlag": "None", | "EncryptFlag": "Common", | ||||
"EncryptKey": 9999, | "EncryptKey": 9999, | ||||
"Version": "1.0.0" | "Version": { | ||||
"Major": 2, | |||||
"Minor": 1, | |||||
"Build": 2 | |||||
} | |||||
}, | }, | ||||
"EncryptOptions": { | "EncryptOptions": { | ||||
"M1": 0, | "M1": 10000000, | ||||
"IA1": 0, | "IA1": 20000000, | ||||
"IC1": 0, | "IC1": 30000000 | ||||
"Key": 0 | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -18,24 +18,31 @@ namespace JT809.Protocol.Extensions.DependencyInjection | |||||
services.Configure<JT809Options>(configuration); | services.Configure<JT809Options>(configuration); | ||||
ServiceProvider serviceProvider = services.BuildServiceProvider(); | ServiceProvider serviceProvider = services.BuildServiceProvider(); | ||||
JT809Options options = serviceProvider.GetRequiredService<IOptions<JT809Options>>().Value; | JT809Options options = serviceProvider.GetRequiredService<IOptions<JT809Options>>().Value; | ||||
var versions = options.Version.Split(new string []{ "." }, StringSplitOptions.RemoveEmptyEntries); | JT809GlobalConfig.Instance.SetHeaderOptions(options.HeaderOptions); | ||||
if (versions.Length == 3) | JT809GlobalConfig.Instance.SetSkipCRCCode(options.SkipCRCCode); | ||||
if (options.HeaderOptions.EncryptFlag == JT809Header_Encrypt.Common) | |||||
{ | { | ||||
options.HeaderOptions.Version = new JT809Header_Version(byte.Parse(versions[0]), byte.Parse(versions[1]), byte.Parse(versions[2])); | JT809GlobalConfig.Instance.SetEncryptOptions(options.EncryptOptions); | ||||
} | } | ||||
else if(versions.Length == 2) | try | ||||
{ | { | ||||
options.HeaderOptions.Version = new JT809Header_Version(byte.Parse(versions[0]), byte.Parse(versions[1]),0); | var msgSNDistributedImpl = services.BuildServiceProvider().GetRequiredService<IMsgSNDistributed>(); | ||||
JT809GlobalConfig.Instance.SetMsgSNDistributed(msgSNDistributedImpl); | |||||
} | } | ||||
else if (versions.Length == 1) | catch | ||||
{ | { | ||||
options.HeaderOptions.Version = new JT809Header_Version(byte.Parse(versions[0]), 0, 0); | |||||
} | } | ||||
JT809GlobalConfig.Instance.SetHeaderOptions(options.HeaderOptions); | return services; | ||||
JT809GlobalConfig.Instance.SetSkipCRCCode(options.SkipCRCCode); | } | ||||
if (options.HeaderOptions.EncryptFlag == JT809Header_Encrypt.Common) | public static IServiceCollection AddJT809Configure(this IServiceCollection services, JT809Options jT809Options) | ||||
{ | |||||
JT809GlobalConfig.Instance.SetHeaderOptions(jT809Options.HeaderOptions); | |||||
JT809GlobalConfig.Instance.SetSkipCRCCode(jT809Options.SkipCRCCode); | |||||
if (jT809Options.HeaderOptions.EncryptFlag == JT809Header_Encrypt.Common) | |||||
{ | { | ||||
JT809GlobalConfig.Instance.SetEncrypt(new JT809EncryptImpl(options.EncryptOptions)); | JT809GlobalConfig.Instance.SetEncryptOptions(jT809Options.EncryptOptions); | ||||
} | } | ||||
try | try | ||||
{ | { | ||||
@@ -44,7 +51,7 @@ namespace JT809.Protocol.Extensions.DependencyInjection | |||||
} | } | ||||
catch | catch | ||||
{ | { | ||||
} | } | ||||
return services; | return services; | ||||
} | } | ||||
@@ -1,15 +1,31 @@ | |||||
<Project Sdk="Microsoft.NET.Sdk"> | <Project Sdk="Microsoft.NET.Sdk"> | ||||
<PropertyGroup> | <PropertyGroup> | ||||
<TargetFramework>netstandard2.0</TargetFramework> | <TargetFramework>netstandard2.0</TargetFramework> | ||||
<LangVersion>latest</LangVersion> | |||||
<Copyright>Copyright 2018.</Copyright> | |||||
<Authors>SmallChi</Authors> | |||||
<PackageId>JT809.Extensions.DependencyInjection</PackageId> | |||||
<Product>JT809.Extensions.DependencyInjection</Product> | |||||
<Description>JT809协议依赖注入扩展包</Description> | |||||
<PackageReleaseNotes>JT809协议依赖注入扩展包</PackageReleaseNotes> | |||||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance> | |||||
<RepositoryUrl>https://github.com/SmallChi/JT809</RepositoryUrl> | |||||
<PackageProjectUrl>https://github.com/SmallChi/JT809</PackageProjectUrl> | |||||
<PackageLicenseUrl>https://github.com/SmallChi/JT809/blob/master/LICENSE</PackageLicenseUrl> | |||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | |||||
<Version>1.0.0</Version> | |||||
</PropertyGroup> | </PropertyGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<PackageReference Include="JT809" Version="1.0.4" /> | |||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.1.1" /> | <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.1.1" /> | ||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" 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.DependencyInjection.Abstractions" Version="2.1.1" /> | ||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.1.1" /> | <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.1.1" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | |||||
<ProjectReference Include="..\JT809.Protocol\JT809.Protocol.csproj" /> | |||||
</ItemGroup> | |||||
</Project> | </Project> |
@@ -10,11 +10,6 @@ namespace JT809.Protocol.Extensions.DependencyInjection.Options | |||||
public JT809EncryptOptions EncryptOptions { get; set; } | public JT809EncryptOptions EncryptOptions { get; set; } | ||||
public JT809HeaderOptions HeaderOptions { get; set; } | public JT809HeaderOptions HeaderOptions { get; set; } | ||||
/// <summary> | /// <summary> | ||||
/// 版本号: | |||||
/// 默认 1.0.0 | |||||
/// </summary> | |||||
public string Version { get; set; } | |||||
/// <summary> | |||||
/// 设置跳过校验码 | /// 设置跳过校验码 | ||||
/// 场景:测试的时候,可能需要收到改数据,所以测试的时候有用 | /// 场景:测试的时候,可能需要收到改数据,所以测试的时候有用 | ||||
/// </summary> | /// </summary> | ||||
@@ -7,7 +7,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT809.Protocol", "JT809.Pro | |||||
EndProject | EndProject | ||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT809.Protocol.Test", "JT809.Protocol.Test\JT809.Protocol.Test.csproj", "{59D2D876-8D81-4CCE-839A-B153912C0C27}" | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT809.Protocol.Test", "JT809.Protocol.Test\JT809.Protocol.Test.csproj", "{59D2D876-8D81-4CCE-839A-B153912C0C27}" | ||||
EndProject | EndProject | ||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JT809.Protocol.Benchmark", "JT809.Protocol.Benchmark\JT809.Protocol.Benchmark.csproj", "{47CE50B3-A0D6-4F5F-907B-01BD7B8AB87F}" | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT809.Protocol.Benchmark", "JT809.Protocol.Benchmark\JT809.Protocol.Benchmark.csproj", "{47CE50B3-A0D6-4F5F-907B-01BD7B8AB87F}" | ||||
EndProject | |||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT809.Protocol.Extensions.DependencyInjection", "JT809.Protocol.Extensions.DependencyInjection\JT809.Protocol.Extensions.DependencyInjection.csproj", "{9C6AD175-2B56-46F6-8817-FA920720BEB2}" | |||||
EndProject | |||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT809.Protocol.Extensions.DependencyInjection.Test", "JT809.Protocol.Extensions.DependencyInjection.Test\JT809.Protocol.Extensions.DependencyInjection.Test.csproj", "{3A5D2CC3-4658-4C73-8C73-6E3B97740A66}" | |||||
EndProject | EndProject | ||||
Global | Global | ||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||
@@ -27,6 +31,14 @@ Global | |||||
{47CE50B3-A0D6-4F5F-907B-01BD7B8AB87F}.Debug|Any CPU.Build.0 = Debug|Any CPU | {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.ActiveCfg = Release|Any CPU | ||||
{47CE50B3-A0D6-4F5F-907B-01BD7B8AB87F}.Release|Any CPU.Build.0 = Release|Any CPU | {47CE50B3-A0D6-4F5F-907B-01BD7B8AB87F}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
{9C6AD175-2B56-46F6-8817-FA920720BEB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||||
{9C6AD175-2B56-46F6-8817-FA920720BEB2}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||||
{9C6AD175-2B56-46F6-8817-FA920720BEB2}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||||
{9C6AD175-2B56-46F6-8817-FA920720BEB2}.Release|Any CPU.Build.0 = Release|Any CPU | |||||
{3A5D2CC3-4658-4C73-8C73-6E3B97740A66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||||
{3A5D2CC3-4658-4C73-8C73-6E3B97740A66}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||||
{3A5D2CC3-4658-4C73-8C73-6E3B97740A66}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||||
{3A5D2CC3-4658-4C73-8C73-6E3B97740A66}.Release|Any CPU.Build.0 = Release|Any CPU | |||||
EndGlobalSection | EndGlobalSection | ||||
GlobalSection(SolutionProperties) = preSolution | GlobalSection(SolutionProperties) = preSolution | ||||
HideSolutionNode = FALSE | HideSolutionNode = FALSE | ||||
@@ -14,7 +14,7 @@ | |||||
<PackageProjectUrl>https://github.com/SmallChi/JT809</PackageProjectUrl> | <PackageProjectUrl>https://github.com/SmallChi/JT809</PackageProjectUrl> | ||||
<PackageLicenseUrl>https://github.com/SmallChi/JT809/blob/master/LICENSE</PackageLicenseUrl> | <PackageLicenseUrl>https://github.com/SmallChi/JT809/blob/master/LICENSE</PackageLicenseUrl> | ||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | <GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||||
<Version>1.0.5</Version> | <Version>1.0.6</Version> | ||||
</PropertyGroup> | </PropertyGroup> | ||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||||
@@ -19,19 +19,19 @@ namespace JT809.Protocol | |||||
public byte Major | public byte Major | ||||
{ | { | ||||
get { return Buffer[MajorIndex]; } | get { return Buffer[MajorIndex]; } | ||||
private set { Buffer[MajorIndex] = value; } | set { Buffer[MajorIndex] = value; } | ||||
} | } | ||||
public byte Minor | public byte Minor | ||||
{ | { | ||||
get { return Buffer[MinorIndex]; } | get { return Buffer[MinorIndex]; } | ||||
private set { Buffer[MinorIndex] = value; } | set { Buffer[MinorIndex] = value; } | ||||
} | } | ||||
public byte Build | public byte Build | ||||
{ | { | ||||
get { return Buffer[BuildIndex]; } | get { return Buffer[BuildIndex]; } | ||||
private set { Buffer[BuildIndex] = value; } | set { Buffer[BuildIndex] = value; } | ||||
} | } | ||||
/// <summary> | /// <summary> | ||||