@@ -382,6 +382,7 @@ Due to access many different equipment vendor's agreement, but each protocol doc | |||
| Install-Package JT808.Protocol.Extensions.JT1078 |  | | |JT1078 extension JT808| | |||
| Install-Package JT808.Protocol.Extensions.SuBiao|  | | |Active Safety (Su Biao) extension JT808| | |||
| Install-Package JT808.Protocol.Extensions.YueBiao|  | | |Active Safety (Yue Biao) extension JT808| | |||
| Install-Package JT808.Protocol.DependencyInjection|  | | |JT808 DependencyInjection| | |||
## Using BenchmarkDotNet performance test reports (just for fun, not to be taken seriously) | |||
@@ -532,9 +533,13 @@ Platform=AnyCpu Server=False Toolchain=.NET 7.0 | |||
## usage | |||
```csharp | |||
Use DI: | |||
IServiceCollection serviceDescriptors1 = new ServiceCollection(); | |||
serviceDescriptors1.AddJT808Configure() | |||
.AddJT1078Configure(); | |||
Use Global: | |||
JT808Serializer.Instance.Register(JT808_JT1078_Constants.GetCurrentAssembly()); | |||
``` | |||
## Active Security (SuBiao) extended JT808 protocol message comparison table | |||
@@ -564,9 +569,13 @@ serviceDescriptors1.AddJT808Configure() | |||
## usage | |||
```csharp | |||
Use DI: | |||
IServiceCollection serviceDescriptors1 = new ServiceCollection(); | |||
serviceDescriptors1.AddJT808Configure() | |||
.AddSuBiaoConfigure(); | |||
Use Global: | |||
JT808Serializer.Instance.Register(JT808_SuBiao_Constants.GetCurrentAssembly()); | |||
``` | |||
## Active Security (Yue Biao) extended JT808 protocol message comparison table | |||
@@ -600,7 +609,11 @@ serviceDescriptors1.AddJT808Configure() | |||
## usage | |||
```csharp | |||
Use DI: | |||
IServiceCollection serviceDescriptors1 = new ServiceCollection(); | |||
serviceDescriptors1.AddJT808Configure() | |||
.AddYueBiaoConfigure(); | |||
Use Global: | |||
JT808Serializer.Instance.Register(JT808_YueBiao_Constants.GetCurrentAssembly()); | |||
``` |
@@ -382,6 +382,7 @@ JT808Serializer DT2JT808Serializer = new JT808Serializer(DT2JT808Config); | |||
| Install-Package JT808.Protocol.Extensions.JT1078 |  | | |JT1078扩展JT808| | |||
| Install-Package JT808.Protocol.Extensions.SuBiao|  | | |主动安全(苏标)扩展JT808| | |||
| Install-Package JT808.Protocol.Extensions.YueBiao|  | | |主动安全(粤标)扩展JT808| | |||
| Install-Package JT808.Protocol.DependencyInjection|  | | |JT808依赖注入扩展| | |||
## 使用BenchmarkDotNet性能测试报告(只是玩玩,不能当真) | |||
@@ -532,9 +533,12 @@ Platform=AnyCpu Server=False Toolchain=.NET 7.0 | |||
## 使用方法 | |||
```csharp | |||
DI: | |||
IServiceCollection serviceDescriptors1 = new ServiceCollection(); | |||
serviceDescriptors1.AddJT808Configure() | |||
.AddJT1078Configure(); | |||
全局注册: | |||
JT808Serializer.Instance.Register(JT808_JT1078_Constants.GetCurrentAssembly()); | |||
``` | |||
## 主动安全(苏标)扩展JT808协议消息对照表 | |||
@@ -564,9 +568,13 @@ serviceDescriptors1.AddJT808Configure() | |||
## 使用方法 | |||
```csharp | |||
DI: | |||
IServiceCollection serviceDescriptors1 = new ServiceCollection(); | |||
serviceDescriptors1.AddJT808Configure() | |||
.AddSuBiaoConfigure(); | |||
全局注册: | |||
JT808Serializer.Instance.Register(JT808_SuBiao_Constants.GetCurrentAssembly()); | |||
``` | |||
## 主动安全(粤标)扩展JT808协议消息对照表 | |||
@@ -600,7 +608,11 @@ serviceDescriptors1.AddJT808Configure() | |||
## 使用方法 | |||
```csharp | |||
DI: | |||
IServiceCollection serviceDescriptors1 = new ServiceCollection(); | |||
serviceDescriptors1.AddJT808Configure() | |||
.AddYueBiaoConfigure(); | |||
全局注册: | |||
JT808Serializer.Instance.Register(JT808_YueBiao_Constants.GetCurrentAssembly()); | |||
``` |
@@ -1,4 +1,5 @@ | |||
dotnet pack .\src\JT808.Protocol\JT808.Protocol.csproj -c Release --output nupkgs | |||
dotnet pack .\src\JT808.Protocol.Extensions\JT808.Protocol.DependencyInjection\JT808.Protocol.DependencyInjection.csproj -c Release --output nupkgs | |||
dotnet pack .\src\JT808.Protocol.Extensions\JT808.Protocol.Extensions.JT1078\JT808.Protocol.Extensions.JT1078.csproj -c Release --output nupkgs | |||
dotnet pack .\src\JT808.Protocol.Extensions\JT808.Protocol.Extensions.SuBiao\JT808.Protocol.Extensions.SuBiao.csproj -c Release --output nupkgs | |||
dotnet pack .\src\JT808.Protocol.Extensions\JT808.Protocol.Extensions.YueBiao\JT808.Protocol.Extensions.YueBiao.csproj -c Release --output nupkgs | |||
@@ -1,6 +1,6 @@ | |||
<Project> | |||
<PropertyGroup> | |||
<TargetFrameworks>net7.0;</TargetFrameworks> | |||
<TargetFrameworks>net7.0;</TargetFrameworks> | |||
<LangVersion>11.0</LangVersion> | |||
<Copyright>Copyright 2018.</Copyright> | |||
<Authors>SmallChi(Koike)</Authors> | |||
@@ -8,7 +8,7 @@ | |||
<PackageProjectUrl>https://github.com/SmallChi/JT808</PackageProjectUrl> | |||
<licenseUrl>https://github.com/SmallChi/JT808/blob/master/LICENSE</licenseUrl> | |||
<license>https://github.com/SmallChi/JT808/blob/master/LICENSE</license> | |||
<Version>2.6.0</Version> | |||
<Version>2.6.1</Version> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
<PackageLicenseFile>LICENSE</PackageLicenseFile> | |||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> | |||
@@ -21,6 +21,7 @@ | |||
<PackageReference Include="System.Memory" Version="4.5.5" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\JT808.Protocol.Extensions\JT808.Protocol.DependencyInjection\JT808.Protocol.DependencyInjection.csproj" /> | |||
<ProjectReference Include="..\JT808.Protocol\JT808.Protocol.csproj" /> | |||
</ItemGroup> | |||
</Project> |
@@ -0,0 +1,33 @@ | |||
using JT808.Protocol.Interfaces; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
namespace JT808.Protocol.DependencyInjection | |||
{ | |||
/// <summary> | |||
/// 默认JT808构造器 | |||
/// </summary> | |||
class DefaultDIBuilder : IJT808DIBuilder | |||
{ | |||
/// <summary> | |||
/// JT808配置 | |||
/// </summary> | |||
public IJT808Config Config { get; } | |||
/// <summary> | |||
/// DI ServiceCollection | |||
/// </summary> | |||
public IServiceCollection Services { get; } | |||
/// <summary> | |||
/// | |||
/// </summary> | |||
/// <param name="services"></param> | |||
/// <param name="config"></param> | |||
public DefaultDIBuilder(IServiceCollection services,IJT808Config config) | |||
{ | |||
Config = config; | |||
Services = services; | |||
} | |||
} | |||
} |
@@ -1,4 +1,5 @@ | |||
using JT808.Protocol.Interfaces; | |||
using JT808.Protocol.DependencyInjection; | |||
using JT808.Protocol.Interfaces; | |||
using JT808.Protocol.Internal; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using System; | |||
@@ -8,7 +9,8 @@ using System.Text; | |||
namespace JT808.Protocol | |||
{ | |||
/// <summary> | |||
/// DI扩展 | |||
/// JT808 DI扩展 | |||
/// JT808 DependencyInjectionExtensions | |||
/// </summary> | |||
public static class DependencyInjectionExtensions | |||
{ | |||
@@ -18,10 +20,10 @@ namespace JT808.Protocol | |||
/// <param name="services"></param> | |||
/// <param name="jT808Config"></param> | |||
/// <returns></returns> | |||
public static IJT808Builder AddJT808Configure(this IServiceCollection services, IJT808Config jT808Config) | |||
public static IJT808DIBuilder AddJT808Configure(this IServiceCollection services, IJT808Config jT808Config) | |||
{ | |||
services.AddSingleton(jT808Config.GetType(), jT808Config); | |||
return new DefaultBuilder(services, jT808Config); | |||
return new DefaultDIBuilder(services,jT808Config); | |||
} | |||
/// <summary> | |||
/// 注册808配置 | |||
@@ -29,7 +31,7 @@ namespace JT808.Protocol | |||
/// <param name="builder"></param> | |||
/// <param name="jT808Config"></param> | |||
/// <returns></returns> | |||
public static IJT808Builder AddJT808Configure(this IJT808Builder builder, IJT808Config jT808Config) | |||
public static IJT808DIBuilder AddJT808Configure(this IJT808DIBuilder builder, IJT808Config jT808Config) | |||
{ | |||
builder.Services.AddSingleton(jT808Config.GetType(), jT808Config); | |||
return builder; | |||
@@ -40,11 +42,11 @@ namespace JT808.Protocol | |||
/// <typeparam name="TJT808Config"></typeparam> | |||
/// <param name="services"></param> | |||
/// <returns></returns> | |||
public static IJT808Builder AddJT808Configure<TJT808Config>(this IServiceCollection services)where TJT808Config : IJT808Config,new() | |||
public static IJT808DIBuilder AddJT808Configure<TJT808Config>(this IServiceCollection services)where TJT808Config : IJT808Config,new() | |||
{ | |||
var config = new TJT808Config(); | |||
services.AddSingleton(typeof(TJT808Config), config); | |||
return new DefaultBuilder(services, config); | |||
return new DefaultDIBuilder(services, config); | |||
} | |||
/// <summary> | |||
/// 注册808配置 | |||
@@ -52,7 +54,7 @@ namespace JT808.Protocol | |||
/// <typeparam name="TJT808Config"></typeparam> | |||
/// <param name="builder"></param> | |||
/// <returns></returns> | |||
public static IJT808Builder AddJT808Configure<TJT808Config>(this IJT808Builder builder) where TJT808Config : IJT808Config, new() | |||
public static IJT808DIBuilder AddJT808Configure<TJT808Config>(this IJT808DIBuilder builder) where TJT808Config : IJT808Config, new() | |||
{ | |||
var config = new TJT808Config(); | |||
builder.Services.AddSingleton(typeof(TJT808Config), config); | |||
@@ -63,11 +65,11 @@ namespace JT808.Protocol | |||
/// </summary> | |||
/// <param name="services"></param> | |||
/// <returns></returns> | |||
public static IJT808Builder AddJT808Configure(this IServiceCollection services) | |||
public static IJT808DIBuilder AddJT808Configure(this IServiceCollection services) | |||
{ | |||
DefaultGlobalConfig config = new DefaultGlobalConfig(); | |||
services.AddSingleton<IJT808Config>(config); | |||
return new DefaultBuilder(services, config); | |||
return new DefaultDIBuilder(services,config); | |||
} | |||
} | |||
} |
@@ -0,0 +1,20 @@ | |||
using Microsoft.Extensions.DependencyInjection; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace JT808.Protocol.DependencyInjection | |||
{ | |||
/// <summary> | |||
/// JT808 DI Builder | |||
/// </summary> | |||
public interface IJT808DIBuilder: IJT808Builder | |||
{ | |||
/// <summary> | |||
/// 服务注册 | |||
/// </summary> | |||
IServiceCollection Services { get; } | |||
} | |||
} |
@@ -0,0 +1,29 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<Import Project="..\..\Info.props" /> | |||
<PropertyGroup> | |||
<PackageId>JT808.Protocol.DependencyInjection</PackageId> | |||
<Product>JT808.Protocol.DependencyInjection</Product> | |||
<Description> | |||
JT808.Protocol.DependencyInjection. | |||
</Description> | |||
<PackageReleaseNotes> | |||
JT808.Protocol.DependencyInjection. | |||
</PackageReleaseNotes> | |||
<DocumentationFile>JT808.Protocol.DependencyInjection.xml</DocumentationFile> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<None Include="..\..\..\LICENSE" Pack="true" PackagePath="" /> | |||
<None Include="..\..\..\README.md" Pack="true" PackagePath="" /> | |||
<None Include="..\..\..\README.en.md" Pack="true" PackagePath="" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\..\JT808.Protocol\JT808.Protocol.csproj" /> | |||
</ItemGroup> | |||
</Project> |
@@ -0,0 +1,85 @@ | |||
<?xml version="1.0"?> | |||
<doc> | |||
<assembly> | |||
<name>JT808.Protocol.DependencyInjection</name> | |||
</assembly> | |||
<members> | |||
<member name="T:JT808.Protocol.DependencyInjection.DefaultDIBuilder"> | |||
<summary> | |||
默认JT808构造器 | |||
</summary> | |||
</member> | |||
<member name="P:JT808.Protocol.DependencyInjection.DefaultDIBuilder.Config"> | |||
<summary> | |||
JT808配置 | |||
</summary> | |||
</member> | |||
<member name="P:JT808.Protocol.DependencyInjection.DefaultDIBuilder.Services"> | |||
<summary> | |||
DI ServiceCollection | |||
</summary> | |||
</member> | |||
<member name="M:JT808.Protocol.DependencyInjection.DefaultDIBuilder.#ctor(Microsoft.Extensions.DependencyInjection.IServiceCollection,JT808.Protocol.IJT808Config)"> | |||
<summary> | |||
</summary> | |||
<param name="services"></param> | |||
<param name="config"></param> | |||
</member> | |||
<member name="T:JT808.Protocol.DependencyInjection.IJT808DIBuilder"> | |||
<summary> | |||
JT808 DI Builder | |||
</summary> | |||
</member> | |||
<member name="P:JT808.Protocol.DependencyInjection.IJT808DIBuilder.Services"> | |||
<summary> | |||
服务注册 | |||
</summary> | |||
</member> | |||
<member name="T:JT808.Protocol.DependencyInjectionExtensions"> | |||
<summary> | |||
JT808 DI扩展 | |||
JT808 DependencyInjectionExtensions | |||
</summary> | |||
</member> | |||
<member name="M:JT808.Protocol.DependencyInjectionExtensions.AddJT808Configure(Microsoft.Extensions.DependencyInjection.IServiceCollection,JT808.Protocol.IJT808Config)"> | |||
<summary> | |||
注册808配置 | |||
</summary> | |||
<param name="services"></param> | |||
<param name="jT808Config"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:JT808.Protocol.DependencyInjectionExtensions.AddJT808Configure(JT808.Protocol.DependencyInjection.IJT808DIBuilder,JT808.Protocol.IJT808Config)"> | |||
<summary> | |||
注册808配置 | |||
</summary> | |||
<param name="builder"></param> | |||
<param name="jT808Config"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:JT808.Protocol.DependencyInjectionExtensions.AddJT808Configure``1(Microsoft.Extensions.DependencyInjection.IServiceCollection)"> | |||
<summary> | |||
注册808配置 | |||
</summary> | |||
<typeparam name="TJT808Config"></typeparam> | |||
<param name="services"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:JT808.Protocol.DependencyInjectionExtensions.AddJT808Configure``1(JT808.Protocol.DependencyInjection.IJT808DIBuilder)"> | |||
<summary> | |||
注册808配置 | |||
</summary> | |||
<typeparam name="TJT808Config"></typeparam> | |||
<param name="builder"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:JT808.Protocol.DependencyInjectionExtensions.AddJT808Configure(Microsoft.Extensions.DependencyInjection.IServiceCollection)"> | |||
<summary> | |||
注册808配置 | |||
</summary> | |||
<param name="services"></param> | |||
<returns></returns> | |||
</member> | |||
</members> | |||
</doc> |
@@ -16,6 +16,7 @@ | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\JT808.Protocol.DependencyInjection\JT808.Protocol.DependencyInjection.csproj" /> | |||
<ProjectReference Include="..\JT808.Protocol.Extensions.JT1078\JT808.Protocol.Extensions.JT1078.csproj" /> | |||
</ItemGroup> | |||
@@ -6,6 +6,7 @@ using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using Xunit; | |||
using System.Reflection; | |||
namespace JT808.Protocol.Extensions.JT1078.Test | |||
{ | |||
@@ -121,5 +122,16 @@ namespace JT808.Protocol.Extensions.JT1078.Test | |||
byte[] bodys = "7e020040420100000000013419905507021200040000001410010213679206c4a97d01001300000002220720103957010400000e3e020200000302025825040000001030014531010814040000000115040000000c797e".ToHexBytes(); | |||
string json = JT808Serializer.Analyze<JT808Package>(bodys); | |||
} | |||
/// <summary> | |||
/// | |||
/// </summary> | |||
[Fact] | |||
public void Test_0x15_5() | |||
{ | |||
JT808Serializer.Instance.Register(JT808_JT1078_Constants.GetCurrentAssembly()); | |||
byte[] bodys = "7e020040420100000000013419905507021200040000001410010213679206c4a97d01001300000002220720103957010400000e3e020200000302025825040000001030014531010814040000000115040000000c797e".ToHexBytes(); | |||
string json = JT808Serializer.Instance.Analyze<JT808Package>(bodys); | |||
} | |||
} | |||
} |
@@ -1,7 +1,6 @@ | |||
using JT808.Protocol.Extensions.JT1078.Enums; | |||
using JT808.Protocol.Extensions.JT1078.MessageBody; | |||
using JT808.Protocol.Interfaces; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Reflection; | |||
@@ -262,6 +262,12 @@ | |||
Wake up in hibernation mode | |||
</summary> | |||
</member> | |||
<member name="M:JT808.Protocol.Extensions.JT1078.JT808_JT1078_Constants.GetCurrentAssembly"> | |||
<summary> | |||
</summary> | |||
<returns></returns> | |||
</member> | |||
<member name="T:JT808.Protocol.Extensions.JT1078.MessageBody.JT808_0x0200_0x14"> | |||
<summary> | |||
视频相关报警 | |||
@@ -1,5 +1,6 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Reflection; | |||
using System.Text; | |||
namespace JT808.Protocol.Extensions.JT1078 | |||
@@ -69,5 +70,13 @@ namespace JT808.Protocol.Extensions.JT1078 | |||
/// Wake up in hibernation mode | |||
/// </summary> | |||
public const uint JT808_0X8103_0x007C = 0x007C; | |||
/// <summary> | |||
/// | |||
/// </summary> | |||
/// <returns></returns> | |||
public static Assembly GetCurrentAssembly() | |||
{ | |||
return Assembly.GetExecutingAssembly(); | |||
} | |||
} | |||
} |
@@ -17,6 +17,7 @@ | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\JT808.Protocol.DependencyInjection\JT808.Protocol.DependencyInjection.csproj" /> | |||
<ProjectReference Include="..\JT808.Protocol.Extensions.SuBiao\JT808.Protocol.Extensions.SuBiao.csproj" /> | |||
</ItemGroup> | |||
@@ -96,5 +96,12 @@ namespace JT808.Protocol.Extensions.SuBiao.Test | |||
{ | |||
var json = JT808Serializer.Analyze<JT808_0x0200>("000000010000000200BA7F0E07E4F11C0028003C00001807151010106420000000010C0605120A0B100F1100070000000D0000000E191211183100001334343434343434191210183100030200".ToHexBytes()); | |||
} | |||
[Fact] | |||
public void Deserialize2() | |||
{ | |||
JT808Serializer.Instance.Register(JT808_SuBiao_Constants.GetCurrentAssembly()); | |||
var json = JT808Serializer.Instance.Analyze<JT808_0x0200>("000000010000000200BA7F0E07E4F11C0028003C00001807151010106420000000010C0605120A0B100F1100070000000D0000000E191211183100001334343434343434191210183100030200".ToHexBytes()); | |||
} | |||
} | |||
} |
@@ -1,7 +1,6 @@ | |||
using JT808.Protocol.Extensions.SuBiao.Enums; | |||
using JT808.Protocol.Extensions.SuBiao.MessageBody; | |||
using JT808.Protocol.Interfaces; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Reflection; | |||
@@ -298,6 +298,12 @@ | |||
信息查询 | |||
</summary> | |||
</member> | |||
<member name="M:JT808.Protocol.Extensions.SuBiao.JT808_SuBiao_Constants.GetCurrentAssembly"> | |||
<summary> | |||
</summary> | |||
<returns></returns> | |||
</member> | |||
<member name="T:JT808.Protocol.Extensions.SuBiao.MessageBody.JT808_0x0200_0x64"> | |||
<summary> | |||
高级驾驶辅助系统报警信息 | |||
@@ -1,5 +1,6 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Reflection; | |||
using System.Text; | |||
namespace JT808.Protocol.Extensions.SuBiao | |||
@@ -49,5 +50,13 @@ namespace JT808.Protocol.Extensions.SuBiao | |||
/// 信息查询 | |||
/// </summary> | |||
public const byte JT808_0X0900_0xF8 = 0xF8; | |||
/// <summary> | |||
/// | |||
/// </summary> | |||
/// <returns></returns> | |||
public static Assembly GetCurrentAssembly() | |||
{ | |||
return Assembly.GetExecutingAssembly(); | |||
} | |||
} | |||
} |
@@ -21,6 +21,7 @@ | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\JT808.Protocol.DependencyInjection\JT808.Protocol.DependencyInjection.csproj" /> | |||
<ProjectReference Include="..\JT808.Protocol.Extensions.YueBiao\JT808.Protocol.Extensions.YueBiao.csproj" /> | |||
</ItemGroup> | |||
@@ -1,5 +1,4 @@ | |||
using JT808.Protocol.Interfaces; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Reflection; | |||
@@ -387,6 +387,12 @@ | |||
信息查询 | |||
</summary> | |||
</member> | |||
<member name="M:JT808.Protocol.Extensions.YueBiao.JT808_YueBiao_Constants.GetCurrentAssembly"> | |||
<summary> | |||
</summary> | |||
<returns></returns> | |||
</member> | |||
<member name="T:JT808.Protocol.Extensions.YueBiao.MessageBody.JT808_0x0200_0x64"> | |||
<summary> | |||
高级驾驶辅助系统报警信息 | |||
@@ -1,5 +1,6 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Reflection; | |||
using System.Text; | |||
namespace JT808.Protocol.Extensions.YueBiao | |||
@@ -62,5 +63,13 @@ namespace JT808.Protocol.Extensions.YueBiao | |||
/// 信息查询 | |||
/// </summary> | |||
public const byte JT808_0X0900_0xF8 = 0xF8; | |||
/// <summary> | |||
/// | |||
/// </summary> | |||
/// <returns></returns> | |||
public static Assembly GetCurrentAssembly() | |||
{ | |||
return Assembly.GetExecutingAssembly(); | |||
} | |||
} | |||
} |
@@ -126,6 +126,7 @@ | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\JT808.Protocol.Extensions\JT808.Protocol.DependencyInjection\JT808.Protocol.DependencyInjection.csproj" /> | |||
<ProjectReference Include="..\JT808.Protocol\JT808.Protocol.csproj" /> | |||
</ItemGroup> | |||
@@ -29,31 +29,6 @@ namespace JT808.Protocol.Test | |||
} | |||
} | |||
[Fact] | |||
public void ReadOnlySpanTest1() | |||
{ | |||
IJT808Config jT808Config = new DefaultGlobalConfig(); | |||
JT808Serializer jT808Serializer = new JT808Serializer(jT808Config); | |||
JT808Package jT808Package = new JT808Package | |||
{ | |||
Header = new JT808Header | |||
{ | |||
MsgId = Enums.JT808MsgId._0x0001.ToUInt16Value(), | |||
MsgNum = 1203, | |||
TerminalPhoneNo = "012345678900", | |||
MessageBodyProperty=new JT808HeaderMessageBodyProperty() | |||
}, | |||
Bodies = new JT808_0x0001 | |||
{ | |||
ReplyMsgId = Enums.JT808MsgId._0x0002.ToUInt16Value(), | |||
ReplyMsgNum = 1000, | |||
TerminalResult = Enums.JT808TerminalResult.Success | |||
} | |||
}; | |||
var hexSpan = jT808Serializer.SerializeReadOnlySpan(jT808Package); | |||
Assert.Equal(0x7e, hexSpan[0]); | |||
} | |||
[Fact] | |||
public unsafe void DefaultGlobalConfigTest1() | |||
{ | |||
@@ -33,6 +33,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT808.Protocol.Extensions.S | |||
EndProject | |||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT808.Protocol.Extensions.SuBiao.Test", "JT808.Protocol.Extensions\JT808.Protocol.Extensions.SuBiao.Test\JT808.Protocol.Extensions.SuBiao.Test.csproj", "{BEE2E12D-C123-4682-AB7E-210C2BF564B3}" | |||
EndProject | |||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JT808.Protocol.DependencyInjection", "JT808.Protocol.Extensions\JT808.Protocol.DependencyInjection\JT808.Protocol.DependencyInjection.csproj", "{7EB01F74-DFDB-4733-8F15-5785A9ED7DBD}" | |||
EndProject | |||
Global | |||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | |||
Debug|Any CPU = Debug|Any CPU | |||
@@ -75,6 +77,10 @@ Global | |||
{BEE2E12D-C123-4682-AB7E-210C2BF564B3}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
{BEE2E12D-C123-4682-AB7E-210C2BF564B3}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
{BEE2E12D-C123-4682-AB7E-210C2BF564B3}.Release|Any CPU.Build.0 = Release|Any CPU | |||
{7EB01F74-DFDB-4733-8F15-5785A9ED7DBD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||
{7EB01F74-DFDB-4733-8F15-5785A9ED7DBD}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
{7EB01F74-DFDB-4733-8F15-5785A9ED7DBD}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
{7EB01F74-DFDB-4733-8F15-5785A9ED7DBD}.Release|Any CPU.Build.0 = Release|Any CPU | |||
EndGlobalSection | |||
GlobalSection(SolutionProperties) = preSolution | |||
HideSolutionNode = FALSE | |||
@@ -86,6 +92,7 @@ Global | |||
{4984E375-4B55-4188-A94E-844B694BBA5C} = {3A0EEA9A-9667-4386-BB46-4A9CB319CE30} | |||
{001ECBA0-CF17-40B0-B983-B7AE824B8050} = {3A0EEA9A-9667-4386-BB46-4A9CB319CE30} | |||
{BEE2E12D-C123-4682-AB7E-210C2BF564B3} = {3A0EEA9A-9667-4386-BB46-4A9CB319CE30} | |||
{7EB01F74-DFDB-4733-8F15-5785A9ED7DBD} = {3A0EEA9A-9667-4386-BB46-4A9CB319CE30} | |||
EndGlobalSection | |||
GlobalSection(ExtensibilityGlobals) = postSolution | |||
SolutionGuid = {D58CCAA8-ED94-4048-A6DE-55A84814DF17} | |||
@@ -1,5 +1,4 @@ | |||
using JT808.Protocol.Interfaces; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
@@ -15,9 +14,5 @@ namespace JT808.Protocol | |||
/// JT808配置 | |||
/// </summary> | |||
IJT808Config Config { get; } | |||
/// <summary> | |||
/// 服务注册 | |||
/// </summary> | |||
IServiceCollection Services { get; } | |||
} | |||
} |
@@ -1,5 +1,4 @@ | |||
using JT808.Protocol.Interfaces; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
@@ -11,10 +10,6 @@ namespace JT808.Protocol.Internal | |||
/// </summary> | |||
class DefaultBuilder : IJT808Builder | |||
{ | |||
/// <summary> | |||
/// DI服务 | |||
/// </summary> | |||
public IServiceCollection Services { get; } | |||
/// <summary> | |||
/// JT808配置 | |||
/// </summary> | |||
@@ -22,11 +17,9 @@ namespace JT808.Protocol.Internal | |||
/// <summary> | |||
/// | |||
/// </summary> | |||
/// <param name="services"></param> | |||
/// <param name="config"></param> | |||
public DefaultBuilder(IServiceCollection services, IJT808Config config) | |||
public DefaultBuilder(IJT808Config config) | |||
{ | |||
Services = services; | |||
Config = config; | |||
} | |||
} | |||
@@ -1,10 +1,11 @@ | |||
using JT808.Protocol.Interfaces; | |||
using System.Runtime.CompilerServices; | |||
namespace JT808.Protocol.Internal | |||
{ | |||
/// <summary> | |||
/// 默认全局配置 | |||
/// </summary> | |||
/// </summary> | |||
class DefaultGlobalConfig : GlobalConfigBase | |||
{ | |||
/// <summary> | |||
@@ -27,6 +27,7 @@ | |||
</ItemGroup> | |||
<ItemGroup> | |||
<Compile Remove="DependencyInjectionExtensions.cs" /> | |||
<Compile Remove="Formatters\JT808HeaderFormatter.cs" /> | |||
<Compile Remove="Formatters\JT808HeaderPackageFormatter.cs" /> | |||
<Compile Remove="Formatters\JT808PackageFormatter.cs" /> | |||
@@ -40,12 +41,10 @@ | |||
<Compile Remove="Metadata\JT808UploadLocationRequestProperty.cs" /> | |||
</ItemGroup> | |||
<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' "> | |||
<ItemGroup> | |||
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" /> | |||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<None Update="Extensions\JT808PackageExtensionsTemplate.tt"> | |||
<Generator>TextTemplatingFileGenerator</Generator> | |||
@@ -15,50 +15,6 @@ | |||
编码之前的写入位置 | |||
</summary> | |||
</member> | |||
<member name="T:JT808.Protocol.DependencyInjectionExtensions"> | |||
<summary> | |||
DI扩展 | |||
</summary> | |||
</member> | |||
<member name="M:JT808.Protocol.DependencyInjectionExtensions.AddJT808Configure(Microsoft.Extensions.DependencyInjection.IServiceCollection,JT808.Protocol.IJT808Config)"> | |||
<summary> | |||
注册808配置 | |||
</summary> | |||
<param name="services"></param> | |||
<param name="jT808Config"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:JT808.Protocol.DependencyInjectionExtensions.AddJT808Configure(JT808.Protocol.IJT808Builder,JT808.Protocol.IJT808Config)"> | |||
<summary> | |||
注册808配置 | |||
</summary> | |||
<param name="builder"></param> | |||
<param name="jT808Config"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:JT808.Protocol.DependencyInjectionExtensions.AddJT808Configure``1(Microsoft.Extensions.DependencyInjection.IServiceCollection)"> | |||
<summary> | |||
注册808配置 | |||
</summary> | |||
<typeparam name="TJT808Config"></typeparam> | |||
<param name="services"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:JT808.Protocol.DependencyInjectionExtensions.AddJT808Configure``1(JT808.Protocol.IJT808Builder)"> | |||
<summary> | |||
注册808配置 | |||
</summary> | |||
<typeparam name="TJT808Config"></typeparam> | |||
<param name="builder"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:JT808.Protocol.DependencyInjectionExtensions.AddJT808Configure(Microsoft.Extensions.DependencyInjection.IServiceCollection)"> | |||
<summary> | |||
注册808配置 | |||
</summary> | |||
<param name="services"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="T:JT808.Protocol.Enums.JT808Alarm"> | |||
<summary> | |||
报警标志 | |||
@@ -4278,11 +4234,6 @@ | |||
JT808配置 | |||
</summary> | |||
</member> | |||
<member name="P:JT808.Protocol.IJT808Builder.Services"> | |||
<summary> | |||
服务注册 | |||
</summary> | |||
</member> | |||
<member name="T:JT808.Protocol.Interfaces.GlobalConfigBase"> | |||
<summary> | |||
全局配置基类 | |||
@@ -4928,27 +4879,21 @@ | |||
默认JT808构造器 | |||
</summary> | |||
</member> | |||
<member name="P:JT808.Protocol.Internal.DefaultBuilder.Services"> | |||
<summary> | |||
DI服务 | |||
</summary> | |||
</member> | |||
<member name="P:JT808.Protocol.Internal.DefaultBuilder.Config"> | |||
<summary> | |||
JT808配置 | |||
</summary> | |||
</member> | |||
<member name="M:JT808.Protocol.Internal.DefaultBuilder.#ctor(Microsoft.Extensions.DependencyInjection.IServiceCollection,JT808.Protocol.IJT808Config)"> | |||
<member name="M:JT808.Protocol.Internal.DefaultBuilder.#ctor(JT808.Protocol.IJT808Config)"> | |||
<summary> | |||
</summary> | |||
<param name="services"></param> | |||
<param name="config"></param> | |||
</member> | |||
<member name="T:JT808.Protocol.Internal.DefaultGlobalConfig"> | |||
<summary> | |||
默认全局配置 | |||
</summary> | |||
</summary> | |||
</member> | |||
<member name="P:JT808.Protocol.Internal.DefaultGlobalConfig.ConfigId"> | |||
<summary> | |||
@@ -6150,6 +6095,12 @@ | |||
JT808序列化器 | |||
</summary> | |||
</member> | |||
<member name="F:JT808.Protocol.JT808Serializer.Instance"> | |||
<summary> | |||
默认实例 | |||
default instance | |||
</summary> | |||
</member> | |||
<member name="M:JT808.Protocol.JT808Serializer.#ctor(JT808.Protocol.IJT808Config)"> | |||
<summary> | |||
@@ -6175,15 +6126,6 @@ | |||
<param name="minBufferSize"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:JT808.Protocol.JT808Serializer.SerializeReadOnlySpan(JT808.Protocol.JT808Package,JT808.Protocol.Enums.JT808Version,System.Int32)"> | |||
<summary> | |||
</summary> | |||
<param name="package"></param> | |||
<param name="version"></param> | |||
<param name="minBufferSize"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:JT808.Protocol.JT808Serializer.Deserialize(System.ReadOnlySpan{System.Byte},JT808.Protocol.Enums.JT808Version,System.Int32)"> | |||
<summary> | |||
@@ -6203,16 +6145,6 @@ | |||
<param name="minBufferSize"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:JT808.Protocol.JT808Serializer.SerializeReadOnlySpan``1(``0,JT808.Protocol.Enums.JT808Version,System.Int32)"> | |||
<summary> | |||
</summary> | |||
<typeparam name="T"></typeparam> | |||
<param name="obj"></param> | |||
<param name="version"></param> | |||
<param name="minBufferSize"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:JT808.Protocol.JT808Serializer.Deserialize``1(System.ReadOnlySpan{System.Byte},JT808.Protocol.Enums.JT808Version,System.Int32)"> | |||
<summary> | |||
@@ -6314,6 +6246,13 @@ | |||
<param name="minBufferSize"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="M:JT808.Protocol.JT808Serializer.Register(System.Reflection.Assembly[])"> | |||
<summary> | |||
外部注册 | |||
</summary> | |||
<param name="externalAssemblies"></param> | |||
<returns></returns> | |||
</member> | |||
<member name="T:JT808.Protocol.MessageBody.CarDVR.JT808_CarDVR_Down_0x00"> | |||
<summary> | |||
采集记录仪执行标准版本 | |||
@@ -1,14 +1,14 @@ | |||
using JT808.Protocol.Enums; | |||
using JT808.Protocol.Extensions; | |||
using JT808.Protocol.Formatters; | |||
using JT808.Protocol.Interfaces; | |||
using JT808.Protocol.Internal; | |||
using JT808.Protocol.MessagePack; | |||
using System; | |||
using System.IO; | |||
using System.Reflection; | |||
using System.Runtime.CompilerServices; | |||
using System.Text; | |||
using System.Text.Json; | |||
[assembly: InternalsVisibleTo("JT808.Protocol.DependencyInjection")] | |||
namespace JT808.Protocol | |||
{ | |||
/// <summary> | |||
@@ -22,6 +22,17 @@ namespace JT808.Protocol | |||
private readonly static Type JT808_Package_Type = typeof(JT808Package); | |||
/// <summary> | |||
/// 默认实例 | |||
/// default instance | |||
/// </summary> | |||
public readonly static JT808Serializer Instance; | |||
static JT808Serializer() | |||
{ | |||
Instance= new JT808Serializer(); | |||
} | |||
/// <summary> | |||
/// | |||
/// </summary> | |||
@@ -30,6 +41,7 @@ namespace JT808.Protocol | |||
{ | |||
this.jT808Config = jT808Config; | |||
} | |||
/// <summary> | |||
/// | |||
/// </summary> | |||
@@ -68,27 +80,6 @@ namespace JT808.Protocol | |||
/// <summary> | |||
/// | |||
/// </summary> | |||
/// <param name="package"></param> | |||
/// <param name="version"></param> | |||
/// <param name="minBufferSize"></param> | |||
/// <returns></returns> | |||
public ReadOnlySpan<byte> SerializeReadOnlySpan(JT808Package package, JT808Version version = JT808Version.JTT2013, int minBufferSize = 4096) | |||
{ | |||
byte[] buffer = JT808ArrayPool.Rent(minBufferSize); | |||
try | |||
{ | |||
JT808MessagePackWriter jT808MessagePackWriter = new JT808MessagePackWriter(buffer, version); | |||
package.Serialize(ref jT808MessagePackWriter, package, jT808Config); | |||
return jT808MessagePackWriter.FlushAndGetEncodingReadOnlySpan(); | |||
} | |||
finally | |||
{ | |||
JT808ArrayPool.Return(buffer); | |||
} | |||
} | |||
/// <summary> | |||
/// | |||
/// </summary> | |||
/// <param name="bytes"></param> | |||
/// <param name="version"></param> | |||
/// <param name="minBufferSize"></param> | |||
@@ -134,29 +125,6 @@ namespace JT808.Protocol | |||
/// | |||
/// </summary> | |||
/// <typeparam name="T"></typeparam> | |||
/// <param name="obj"></param> | |||
/// <param name="version"></param> | |||
/// <param name="minBufferSize"></param> | |||
/// <returns></returns> | |||
public ReadOnlySpan<byte> SerializeReadOnlySpan<T>(T obj, JT808Version version = JT808Version.JTT2013, int minBufferSize = 4096) | |||
{ | |||
byte[] buffer = JT808ArrayPool.Rent(minBufferSize); | |||
try | |||
{ | |||
var formatter = jT808Config.GetMessagePackFormatter<T>(); | |||
JT808MessagePackWriter jT808MessagePackWriter = new JT808MessagePackWriter(buffer, version); | |||
formatter.Serialize(ref jT808MessagePackWriter, obj, jT808Config); | |||
return jT808MessagePackWriter.FlushAndGetEncodingReadOnlySpan(); | |||
} | |||
finally | |||
{ | |||
JT808ArrayPool.Return(buffer); | |||
} | |||
} | |||
/// <summary> | |||
/// | |||
/// </summary> | |||
/// <typeparam name="T"></typeparam> | |||
/// <param name="bytes"></param> | |||
/// <param name="version"></param> | |||
/// <param name="minBufferSize"></param> | |||
@@ -217,7 +185,7 @@ namespace JT808.Protocol | |||
/// <param name="version"></param> | |||
/// <param name="minBufferSize"></param> | |||
/// <returns></returns> | |||
public dynamic Deserialize(ReadOnlySpan<byte> bytes, Type type, JT808Version version = JT808Version.JTT2013, int minBufferSize = 4096) | |||
public object Deserialize(ReadOnlySpan<byte> bytes, Type type, JT808Version version = JT808Version.JTT2013, int minBufferSize = 4096) | |||
{ | |||
byte[] buffer = JT808ArrayPool.Rent(minBufferSize); | |||
try | |||
@@ -424,5 +392,22 @@ namespace JT808.Protocol | |||
JT808ArrayPool.Return(buffer); | |||
} | |||
} | |||
/// <summary> | |||
/// 外部注册 | |||
/// </summary> | |||
/// <param name="externalAssemblies"></param> | |||
/// <returns></returns> | |||
public JT808Serializer Register(params Assembly[] externalAssemblies) | |||
{ | |||
if(externalAssemblies!=null && externalAssemblies.Length > 0) | |||
{ | |||
foreach(var asm in externalAssemblies) | |||
{ | |||
jT808Config.Register(asm); | |||
} | |||
} | |||
return this; | |||
} | |||
} | |||
} |