1.增加外部程序集注入支持扩展协议注入 2.合并DI库 3.修改依赖基本类型不依赖枚举方便扩展协议扩展 4.修改文档内容 5.增加外部程序集注册的使用demotags/v2.1.0
@@ -67,7 +67,7 @@ jT809Package.Header = new JT809Header | |||
EncryptKey = 9999, | |||
EncryptFlag= JT809Header_Encrypt.None, | |||
Version = new JT809Header_Version(1, 0, 0), | |||
BusinessType = JT809BusinessType.从链路报警信息交互消息, | |||
BusinessType = JT809BusinessType.从链路报警信息交互消息.ToUInt16Value(), | |||
MsgGNSSCENTERID = 20180920, | |||
}; | |||
@@ -75,13 +75,13 @@ JT809_0x9400 bodies = new JT809_0x9400 | |||
{ | |||
VehicleNo="粤A12345", | |||
VehicleColor= JT809VehicleColorType.黄色, | |||
SubBusinessType= JT809SubBusinessType.报警督办请求消息, | |||
SubBusinessType= JT809SubBusinessType.报警督办请求消息.ToUInt16Value(), | |||
}; | |||
JT809_0x9400_0x9401 jT809_0x9400_0x9401 = new JT809_0x9400_0x9401 | |||
{ | |||
WarnSrc = JT809WarnSrc.车载终端, | |||
WarnType = JT809WarnType.疲劳驾驶报警, | |||
WarnType = JT809WarnType.疲劳驾驶报警.ToUInt16Value(), | |||
WarnTime = DateTime.Parse("2018-09-27 10:24:00"), | |||
SupervisionID = "123FFAA1", | |||
SupervisionEndTime = DateTime.Parse("2018-09-27 11:24:00"), | |||
@@ -158,20 +158,20 @@ Assert.Equal((uint)1666, jT809Package.Header.MsgSN); | |||
Assert.Equal((uint)9999, jT809Package.Header.EncryptKey); | |||
Assert.Equal(JT809Header_Encrypt.None, jT809Package.Header.EncryptFlag); | |||
Assert.Equal((uint)20180920, jT809Package.Header.MsgGNSSCENTERID); | |||
Assert.Equal(JT809BusinessType.从链路报警信息交互消息, jT809Package.Header.BusinessType); | |||
Assert.Equal(JT809BusinessType.从链路报警信息交互消息, (JT809BusinessType)jT809Package.Header.BusinessType); | |||
Assert.Equal(new JT809Header_Version(1, 0, 0).ToString(), jT809Package.Header.Version.ToString()); | |||
//4.数据包体 | |||
JT809_0x9400 jT809_0X400 = (JT809_0x9400)jT809Package.Bodies; | |||
Assert.Equal("粤A12345", jT809_0X400.VehicleNo); | |||
Assert.Equal(JT809VehicleColorType.黄色, jT809_0X400.VehicleColor); | |||
Assert.Equal(JT809SubBusinessType.报警督办请求消息, jT809_0X400.SubBusinessType); | |||
Assert.Equal(JT809SubBusinessType.报警督办请求消息, (JT809SubBusinessType)jT809_0X400.SubBusinessType); | |||
Assert.Equal((uint)92, jT809_0X400.DataLength); | |||
//5.子数据包体 | |||
JT809_0x9400_0x9401 jT809_0x9400_0x9401 = (JT809_0x9400_0x9401)jT809_0X400.JT809SubBodies; | |||
Assert.Equal(JT809WarnSrc.车载终端, jT809_0x9400_0x9401.WarnSrc); | |||
Assert.Equal(JT809WarnType.疲劳驾驶报警, jT809_0x9400_0x9401.WarnType); | |||
Assert.Equal(JT809WarnType.疲劳驾驶报警, (JT809WarnType)jT809_0x9400_0x9401.WarnType); | |||
Assert.Equal(DateTime.Parse("2018-09-27 10:24:00"), jT809_0x9400_0x9401.WarnTime); | |||
Assert.Equal("123FFAA1", jT809_0x9400_0x9401.SupervisionID); | |||
Assert.Equal(DateTime.Parse("2018-09-27 11:24:00"), jT809_0x9400_0x9401.SupervisionEndTime); | |||
@@ -198,12 +198,12 @@ JT809Package jT809Package = JT809BusinessType.从链路报警信息交互消息. | |||
{ | |||
VehicleNo = "粤A12345", | |||
VehicleColor = JT809VehicleColorType.黄色, | |||
SubBusinessType = JT809SubBusinessType.报警督办请求, | |||
SubBusinessType = JT809SubBusinessType.报警督办请求.ToUInt16Value(), | |||
SubBodies = JT809SubBusinessType.报警督办请求.Create_报警督办请求( | |||
new JT809_0x9400_0x9401 | |||
{ | |||
WarnSrc = JT809WarnSrc.车载终端, | |||
WarnType = JT809WarnType.疲劳驾驶报警, | |||
WarnType = JT809WarnType.疲劳驾驶报警.ToUInt16Value(), | |||
WarnTime = DateTime.Parse("2018-09-27 10:24:00"), | |||
SupervisionID = "123FFAA1", | |||
SupervisionEndTime = DateTime.Parse("2018-09-27 11:24:00"), | |||
@@ -237,20 +237,11 @@ static void Main(string[] args) | |||
} | |||
``` | |||
### 举个栗子4 | |||
使用依赖注入的方式实现配置 | |||
Install-Package JT809.Extensions.DependencyInjection | |||
[参考例子](https://github.com/SmallChi/JT809/blob/master/src/JT809.Protocol.Extensions.DependencyInjection.Test/Program.cs) | |||
## NuGet安装 | |||
| Package Name | Version | Downloads | |||
|--------------| ------- | ---- | |||
| Install-Package JT809 |  |  | |||
| Install-Package JT809.Extensions.DependencyInjection |  |  | |||
## 使用BenchmarkDotNet性能测试报告(只是玩玩,不能当真) | |||
@@ -265,20 +256,21 @@ Intel Core i7-8700K CPU 3.70GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical | |||
Platform=AnyCpu Runtime=Clr Server=False | |||
``` | |||
| Method | Toolchain | N | Mean | Error | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | | |||
|---------------------------------------- |-------------- |------- |-------------:|-------------:|-------------:|-----------:|------:|------:|-------------:| | |||
| **JT809_0x9400_0x9401_Package_Deserialize** | **Default** | **100** | **690.1 us** | **13.596 us** | **21.565 us** | **18.5547** | **-** | **-** | **118.75 KB** | | |||
| JT809_0x9400_0x9401_Package_Serialize | Default | 100 | 332.8 us | 6.863 us | 7.047 us | 11.7188 | - | - | 74.22 KB | | |||
| JT809_0x9400_0x9401_Package_Deserialize | .NET Core 2.2 | 100 | 385.4 us | 5.410 us | 5.061 us | 19.0430 | - | - | 118.75 KB | | |||
| JT809_0x9400_0x9401_Package_Serialize | .NET Core 2.2 | 100 | 201.0 us | 2.146 us | 1.903 us | 11.9629 | - | - | 74.22 KB | | |||
| **JT809_0x9400_0x9401_Package_Deserialize** | **Default** | **10000** | **68,568.1 us** | **1,263.632 us** | **1,182.002 us** | **1857.1429** | **-** | **-** | **11875.59 KB** | | |||
| JT809_0x9400_0x9401_Package_Serialize | Default | 10000 | 32,706.0 us | 440.949 us | 412.464 us | 1187.5000 | - | - | 7422.12 KB | | |||
| JT809_0x9400_0x9401_Package_Deserialize | .NET Core 2.2 | 10000 | 38,843.3 us | 968.815 us | 858.829 us | 1928.5714 | - | - | 11875 KB | | |||
| JT809_0x9400_0x9401_Package_Serialize | .NET Core 2.2 | 10000 | 19,914.1 us | 383.802 us | 394.136 us | 1187.5000 | - | - | 7421.88 KB | | |||
| **JT809_0x9400_0x9401_Package_Deserialize** | **Default** | **100000** | **678,892.7 us** | **9,244.595 us** | **8,647.400 us** | **19000.0000** | **-** | **-** | **118753.65 KB** | | |||
| JT809_0x9400_0x9401_Package_Serialize | Default | 100000 | 336,631.2 us | 2,672.170 us | 2,499.550 us | 12000.0000 | - | - | 74225.1 KB | | |||
| JT809_0x9400_0x9401_Package_Deserialize | .NET Core 2.2 | 100000 | 387,380.1 us | 6,355.761 us | 5,945.183 us | 19000.0000 | - | - | 118750 KB | | |||
| JT809_0x9400_0x9401_Package_Serialize | .NET Core 2.2 | 100000 | 198,709.1 us | 3,502.843 us | 3,276.562 us | 12000.0000 | - | - | 74218.75 KB | | |||
| Method | Toolchain | N | Mean | Error | StdDev | Median | Gen 0 | Gen 1 | Gen 2 | Allocated | | |||
|---------------------------------------- |-------------- |------- |---------------:|--------------:|--------------:|---------------:|-----------:|------:|------:|-------------:| | |||
| **JT809_0x9400_0x9401_Package_Deserialize** | **Default** | **100** | **1,145.8 us** | **22.830 us** | **43.986 us** | **1,144.3 us** | **17.5781** | **-** | **-** | **118.75 KB** | | |||
| JT809_0x9400_0x9401_Package_Serialize | Default | 100 | 757.9 us | 3.429 us | 2.863 us | 757.1 us | 12.6953 | - | - | 83.6 KB | | |||
| JT809_0x9400_0x9401_Package_Deserialize | .NET Core 2.2 | 100 | 707.3 us | 2.582 us | 2.288 us | 707.7 us | 18.5547 | - | - | 118.75 KB | | |||
| JT809_0x9400_0x9401_Package_Serialize | .NET Core 2.2 | 100 | 564.7 us | 1.691 us | 1.581 us | 564.8 us | 12.6953 | - | - | 83.59 KB | | |||
| **JT809_0x9400_0x9401_Package_Deserialize** | **Default** | **10000** | **105,333.9 us** | **614.531 us** | **544.766 us** | **105,205.9 us** | **1800.0000** | **-** | **-** | **11875.35 KB** | | |||
| JT809_0x9400_0x9401_Package_Serialize | Default | 10000 | 80,959.5 us | 1,036.250 us | 865.316 us | 80,677.3 us | 1285.7143 | - | - | 8360.25 KB | | |||
| JT809_0x9400_0x9401_Package_Deserialize | .NET Core 2.2 | 10000 | 73,005.2 us | 1,432.367 us | 2,393.163 us | 73,562.0 us | 1857.1429 | - | - | 11875 KB | | |||
| JT809_0x9400_0x9401_Package_Serialize | .NET Core 2.2 | 10000 | 54,773.7 us | 234.702 us | 208.057 us | 54,814.1 us | 1333.3333 | - | - | 8359.38 KB | | |||
| **JT809_0x9400_0x9401_Package_Deserialize** | **Default** | **100000** | **1,053,064.0 us** | **4,933.821 us** | **4,615.100 us** | **1,052,073.9 us** | **19000.0000** | **-** | **-** | **118753.65 KB** | | |||
| JT809_0x9400_0x9401_Package_Serialize | Default | 100000 | 792,674.1 us | 16,105.634 us | 39,507.395 us | 772,030.9 us | 13000.0000 | - | - | 83594.54 KB | | |||
| JT809_0x9400_0x9401_Package_Deserialize | .NET Core 2.2 | 100000 | 722,564.1 us | 14,036.532 us | 15,601.568 us | 719,740.4 us | 19000.0000 | - | - | 118750 KB | | |||
| JT809_0x9400_0x9401_Package_Serialize | .NET Core 2.2 | 100000 | 588,767.7 us | 12,003.898 us | 31,832.636 us | 579,346.9 us | 13000.0000 | - | - | 83593.75 KB | | |||
## JT809协议消息对照表 | |||
@@ -52,7 +52,7 @@ namespace JT809.Protocol.Benchmark | |||
EncryptKey = 9999, | |||
EncryptFlag = JT809Header_Encrypt.None, | |||
Version = new JT809Header_Version(1, 0, 0), | |||
BusinessType = JT809BusinessType.从链路报警信息交互消息, | |||
BusinessType = (ushort)JT809BusinessType.从链路报警信息交互消息, | |||
MsgGNSSCENTERID = 20180920, | |||
}; | |||
@@ -60,13 +60,13 @@ namespace JT809.Protocol.Benchmark | |||
{ | |||
VehicleNo = "粤A12345", | |||
VehicleColor = JT809VehicleColorType.黄色, | |||
SubBusinessType = JT809SubBusinessType.报警督办请求, | |||
SubBusinessType = JT809SubBusinessType.报警督办请求.ToUInt16Value(), | |||
}; | |||
JT809_0x9400_0x9401 jT809_0x9400_0x9401 = new JT809_0x9400_0x9401 | |||
{ | |||
WarnSrc = JT809WarnSrc.车载终端, | |||
WarnType = JT809WarnType.疲劳驾驶报警, | |||
WarnType = JT809WarnType.疲劳驾驶报警.ToUInt16Value(), | |||
WarnTime = DateTime.Parse("2018-09-27 10:24:00"), | |||
SupervisionID = "123FFAA1", | |||
SupervisionEndTime = DateTime.Parse("2018-09-27 11:24:00"), | |||
@@ -1,27 +0,0 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<OutputType>Exe</OutputType> | |||
<TargetFramework>netcoreapp2.2</TargetFramework> | |||
<LangVersion>7.3</LangVersion> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" /> | |||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" /> | |||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.2.0" /> | |||
<PackageReference Include="Microsoft.Extensions.Options" Version="2.2.0" /> | |||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.2.0" /> | |||
</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,19 +0,0 @@ | |||
{ | |||
"JT809Options": { | |||
"HeaderOptions": { | |||
"MsgGNSSCENTERID": 20181012, | |||
"EncryptFlag": "Common", | |||
"EncryptKey": 9999, | |||
"Version": { | |||
"Major": 2, | |||
"Minor": 1, | |||
"Build": 2 | |||
} | |||
}, | |||
"EncryptOptions": { | |||
"M1": 10000000, | |||
"IA1": 20000000, | |||
"IC1": 30000000 | |||
} | |||
} | |||
} |
@@ -1,26 +0,0 @@ | |||
using Microsoft.Extensions.DependencyInjection; | |||
using JT809.Protocol.Interfaces; | |||
namespace JT809.Protocol.Extensions.DependencyInjection | |||
{ | |||
public static class DependencyInjectionExtensions | |||
{ | |||
public static IServiceCollection AddJT809Configure(this IServiceCollection services, IJT809Config jT809Config) | |||
{ | |||
services.AddSingleton(jT809Config.GetType(), jT809Config); | |||
services.AddSingleton(jT809Config); | |||
return services; | |||
} | |||
public static IServiceCollection AddJT809Configure(this IServiceCollection services) | |||
{ | |||
services.AddSingleton<IJT809Config>(new DefaultGlobalConfig()); | |||
return services; | |||
} | |||
class DefaultGlobalConfig : GlobalConfigBase | |||
{ | |||
public override string ConfigId => "default"; | |||
} | |||
} | |||
} |
@@ -1,32 +0,0 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<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> | |||
<license>https://github.com/SmallChi/JT809/blob/master/LICENSE</license> | |||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | |||
<Version>2.0.0</Version> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.2.0" /> | |||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" /> | |||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.2.0" /> | |||
<PackageReference Include="Microsoft.Extensions.Options" Version="2.2.0" /> | |||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.2.0" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\JT809.Protocol\JT809.Protocol.csproj" /> | |||
</ItemGroup> | |||
</Project> |
@@ -0,0 +1,19 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Reflection; | |||
using System.Text; | |||
namespace JT809.Protocol.Test.JT1078 | |||
{ | |||
public static class JT1078DependencyInjectionExtensions | |||
{ | |||
public static IJT809Builder AddJT1078Configure(this IJT809Builder builder) | |||
{ | |||
builder.Config.Register(Assembly.GetExecutingAssembly()); | |||
builder.Config.BusinessTypeFactory.SetMap<JT808_JT1078_0x1700>(0x1700); | |||
#warning 不知道是不是jt1078协议的809结构有问题,先按交换的格式(少了数据交换的头部) | |||
builder.Config.SubBusinessTypeFactory.SetMap<JT808_JT1078_0x1700_0x1701>(0x1701); | |||
return builder; | |||
} | |||
} | |||
} |
@@ -0,0 +1,14 @@ | |||
using JT809.Protocol.Attributes; | |||
using JT809.Protocol.Formatters; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
namespace JT809.Protocol.Test.JT1078 | |||
{ | |||
[JT809Formatter(typeof(JT809BodiesFormatter<JT808_JT1078_0x1700>))] | |||
public class JT808_JT1078_0x1700: JT809ExchangeMessageBodies | |||
{ | |||
} | |||
} |
@@ -0,0 +1,24 @@ | |||
using JT809.Protocol.Attributes; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
namespace JT809.Protocol.Test.JT1078 | |||
{ | |||
[JT809Formatter(typeof(JT808_JT1078_0x1700_0x1701_Formatter))] | |||
public class JT808_JT1078_0x1700_0x1701 : JT809SubBodies | |||
{ | |||
/// <summary> | |||
/// 企业视频监控平台唯一编码,平台所属企业行政区域代码+平台公共编号 | |||
/// </summary> | |||
public byte[] PlateFormId { get; set; } | |||
/// <summary> | |||
/// 归属地区政府平台使用的时效口令 | |||
/// </summary> | |||
public byte[] AuthorizeCode1 { get; set; } | |||
/// <summary> | |||
/// 跨域地区政府平台使用的时效口令 | |||
/// </summary> | |||
public byte[] AuthorizeCode2 { get; set; } | |||
} | |||
} |
@@ -0,0 +1,24 @@ | |||
using JT809.Protocol.Formatters; | |||
using JT809.Protocol.MessagePack; | |||
namespace JT809.Protocol.Test.JT1078 | |||
{ | |||
public class JT808_JT1078_0x1700_0x1701_Formatter : IJT809MessagePackFormatter<JT808_JT1078_0x1700_0x1701> | |||
{ | |||
public JT808_JT1078_0x1700_0x1701 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) | |||
{ | |||
JT808_JT1078_0x1700_0x1701 jT808_JT1078_0X1701 = new JT808_JT1078_0x1700_0x1701(); | |||
jT808_JT1078_0X1701.PlateFormId = reader.ReadArray(11).ToArray(); | |||
jT808_JT1078_0X1701.AuthorizeCode1 = reader.ReadArray(64).ToArray(); | |||
jT808_JT1078_0X1701.AuthorizeCode2 = reader.ReadArray(64).ToArray(); | |||
return jT808_JT1078_0X1701; | |||
} | |||
public void Serialize(ref JT809MessagePackWriter writer, JT808_JT1078_0x1700_0x1701 value, IJT809Config config) | |||
{ | |||
writer.WriteArray(value.PlateFormId); | |||
writer.WriteArray(value.AuthorizeCode1); | |||
writer.WriteArray(value.AuthorizeCode2); | |||
} | |||
} | |||
} |
@@ -0,0 +1,50 @@ | |||
using JT809.Protocol.Enums; | |||
using JT809.Protocol.Exceptions; | |||
using JT809.Protocol.Extensions; | |||
using JT809.Protocol.Formatters; | |||
using JT809.Protocol.MessagePack; | |||
using System; | |||
namespace JT809.Protocol.Test.JT1078 | |||
{ | |||
public class JT808_JT1078_0x1700_Formatter : IJT809MessagePackFormatter<JT808_JT1078_0x1700> | |||
{ | |||
public JT808_JT1078_0x1700 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) | |||
{ | |||
JT808_JT1078_0x1700 jT808_JT1078_0X1700 = new JT808_JT1078_0x1700(); | |||
jT808_JT1078_0X1700.SubBusinessType = reader.ReadUInt16(); | |||
try | |||
{ | |||
Type jT809SubBodiesImplType = config.SubBusinessTypeFactory.GetSubBodiesImplTypeBySubBusinessType(jT808_JT1078_0X1700.SubBusinessType); | |||
if (jT809SubBodiesImplType != null) | |||
jT808_JT1078_0X1700.SubBodies = JT809MessagePackFormatterResolverExtensions.JT809DynamicDeserialize( | |||
config.GetMessagePackFormatterByType(jT809SubBodiesImplType), | |||
ref reader, config); | |||
} | |||
catch | |||
{ | |||
throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{jT808_JT1078_0X1700.SubBusinessType.ToString()}"); | |||
} | |||
return jT808_JT1078_0X1700; | |||
} | |||
public void Serialize(ref JT809MessagePackWriter writer, JT808_JT1078_0x1700 value, IJT809Config config) | |||
{ | |||
try | |||
{ | |||
writer.WriteUInt16(value.SubBusinessType); | |||
if (value.SubBodies != null) | |||
{ | |||
JT809MessagePackFormatterResolverExtensions.JT809DynamicSerialize( | |||
config.GetMessagePackFormatterByType(value.SubBodies.GetType()), | |||
ref writer, value.SubBodies, | |||
config); | |||
} | |||
} | |||
catch | |||
{ | |||
throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{value.SubBusinessType.ToString()}"); | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,20 @@ | |||
using JT809.Protocol.Attributes; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.ComponentModel; | |||
using System.Text; | |||
namespace JT809.Protocol.Test.JT1078 | |||
{ | |||
public enum JT809_JT1078_BusinessType:ushort | |||
{ | |||
///<summary> | |||
///主链路时效口令业务类 | |||
///UP_AUTHORIZE_MSG | |||
///</summary> | |||
[Description("主链路时效口令业务类")] | |||
[JT809BodiesType(typeof(JT808_JT1078_0x1700))] | |||
[JT809BusinessTypeDescription("UP_AUTHORIZE_MSG", "主链路时效口令业务类")] | |||
主链路时效口令业务类 = 0x1700, | |||
} | |||
} |
@@ -0,0 +1,20 @@ | |||
using JT809.Protocol.Attributes; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.ComponentModel; | |||
using System.Text; | |||
namespace JT809.Protocol.Test.JT1078 | |||
{ | |||
public enum JT809_JT1078_SubBusinessType : ushort | |||
{ | |||
///<summary> | |||
///时效口令上报消息 | |||
///UP_AUTHRIZE_MSG_STARTUP | |||
///</summary> | |||
[Description("时效口令上报消息")] | |||
[JT809BodiesType(typeof(JT808_JT1078_0x1700_0x1701))] | |||
[JT809BusinessTypeDescription("UP_AUTHRIZE_MSG_STARTUP", "主链路时效口令业务类")] | |||
时效口令上报消息 = 0x1701, | |||
} | |||
} |
@@ -11,6 +11,7 @@ | |||
</ItemGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" /> | |||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> | |||
<PackageReference Include="xunit" Version="2.4.1" /> | |||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1"> | |||
@@ -1,22 +1,28 @@ | |||
using JT809.Protocol.Interfaces; | |||
using Microsoft.Extensions.Configuration; | |||
using JT809.Protocol.Extensions; | |||
using JT809.Protocol.Interfaces; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using Microsoft.Extensions.Hosting; | |||
using System; | |||
using System.Threading.Tasks; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using Xunit; | |||
namespace JT809.Protocol.Extensions.DependencyInjection.Test | |||
namespace JT809.Protocol.Test | |||
{ | |||
class Program | |||
public class JT809DependencyInjectionExtensionsTest | |||
{ | |||
static void Main(string[] args) | |||
[Fact] | |||
public void Test1() | |||
{ | |||
//单个 | |||
IServiceCollection serviceDescriptors1 = new ServiceCollection(); | |||
serviceDescriptors1.AddJT809Configure(new DefaultConfig()); | |||
var ServiceProvider1 = serviceDescriptors1.BuildServiceProvider(); | |||
var defaultConfig = ServiceProvider1.GetRequiredService<IJT809Config>(); | |||
Assert.True(defaultConfig.GetSerializer().SerializerId == "test"); | |||
} | |||
[Fact] | |||
public void Test2() | |||
{ | |||
//多个 | |||
IServiceCollection serviceDescriptors2 = new ServiceCollection(); | |||
serviceDescriptors2.AddJT809Configure(new Config1()); | |||
@@ -40,14 +46,13 @@ namespace JT809.Protocol.Extensions.DependencyInjection.Test | |||
}; | |||
return accesor; | |||
}); | |||
var ServiceProvider2 = serviceDescriptors2.BuildServiceProvider(); | |||
var config1 = ServiceProvider2.GetRequiredService<Func<string, IJT809Config>>()("Config1"); | |||
var flag21 = config1.GetSerializer().SerializerId == "Config1"; | |||
Assert.True(config1.GetSerializer().SerializerId == "Config1"); | |||
var config2 = ServiceProvider2.GetRequiredService<Func<string, IJT809Config>>()("Config2"); | |||
var flag22 = config2.GetSerializer().SerializerId == "Config2"; | |||
Assert.True(config2.GetSerializer().SerializerId == "Config2"); | |||
} | |||
} | |||
@@ -68,12 +68,12 @@ namespace JT809.Protocol.Test.JT809Extensions | |||
{ | |||
VehicleNo = "粤A12345", | |||
VehicleColor = JT809VehicleColorType.黄色, | |||
SubBusinessType = JT809SubBusinessType.报警督办请求, | |||
SubBusinessType = JT809SubBusinessType.报警督办请求.ToUInt16Value(), | |||
SubBodies = JT809SubBusinessType.报警督办请求.Create_报警督办请求( | |||
new JT809_0x9400_0x9401 | |||
{ | |||
WarnSrc = JT809WarnSrc.车载终端, | |||
WarnType = JT809WarnType.疲劳驾驶报警, | |||
WarnType = JT809WarnType.疲劳驾驶报警.ToUInt16Value(), | |||
WarnTime = DateTime.Parse("2018-09-27 10:24:00"), | |||
SupervisionID = "123FFAA1", | |||
SupervisionEndTime = DateTime.Parse("2018-09-27 11:24:00"), | |||
@@ -19,7 +19,7 @@ namespace JT809.Protocol.Test | |||
JT809Header jT809Header = new JT809Header(); | |||
jT809Header.MsgLength = 24; | |||
jT809Header.MsgSN = 1024; | |||
jT809Header.BusinessType = JT809BusinessType.从链路静态信息交换消息; | |||
jT809Header.BusinessType = JT809BusinessType.从链路静态信息交换消息.ToUInt16Value(); | |||
jT809Header.MsgGNSSCENTERID = 1200; | |||
jT809Header.Version = new JT809Header_Version(); | |||
jT809Header.EncryptFlag = JT809Header_Encrypt.None; | |||
@@ -36,7 +36,7 @@ namespace JT809.Protocol.Test | |||
JT809Header jT809Header= JT809Serializer.Deserialize<JT809Header>(bytes); | |||
Assert.Equal((uint)24, jT809Header.MsgLength); | |||
Assert.Equal((uint)1024, jT809Header.MsgSN); | |||
Assert.Equal(JT809BusinessType.从链路静态信息交换消息, jT809Header.BusinessType); | |||
Assert.Equal(JT809BusinessType.从链路静态信息交换消息, (JT809BusinessType)jT809Header.BusinessType); | |||
Assert.Equal((uint)1200, jT809Header.MsgGNSSCENTERID); | |||
Assert.Equal(new JT809Header_Version().ToString(), jT809Header.Version.ToString()); | |||
Assert.Equal(JT809Header_Encrypt.None, jT809Header.EncryptFlag); | |||
@@ -49,7 +49,7 @@ namespace JT809.Protocol.Test | |||
JT809Header jT809Header = new JT809Header(); | |||
jT809Header.MsgLength = 24; | |||
jT809Header.MsgSN = 1024; | |||
jT809Header.BusinessType = JT809BusinessType.从链路静态信息交换消息; | |||
jT809Header.BusinessType = JT809BusinessType.从链路静态信息交换消息.ToUInt16Value(); | |||
jT809Header.MsgGNSSCENTERID = 1200; | |||
jT809Header.Version = new JT809Header_Version (0xFF,0xAA,0xBB); | |||
jT809Header.EncryptFlag = JT809Header_Encrypt.None; | |||
@@ -20,7 +20,7 @@ namespace JT809.Protocol.Test.JT809MessageBody | |||
JT809_0x1200 jT809_0X1200 = new JT809_0x1200(); | |||
jT809_0X1200.VehicleNo= "粤A12345"; | |||
jT809_0X1200.VehicleColor = JT809VehicleColorType.蓝色; | |||
jT809_0X1200.SubBusinessType = JT809SubBusinessType.上传车辆注册信息; | |||
jT809_0X1200.SubBusinessType = JT809SubBusinessType.上传车辆注册信息.ToUInt16Value(); | |||
jT809_0X1200.DataLength = 61; | |||
JT809_0x1200_0x1201 jT809_0X1200_0X1201 = new JT809_0x1200_0x1201 | |||
{ | |||
@@ -53,7 +53,7 @@ namespace JT809.Protocol.Test.JT809MessageBody | |||
JT809_0x1200 jT809_0X9001 = JT809Serializer.Deserialize<JT809_0x1200>(bytes); | |||
Assert.Equal("粤A12345", jT809_0X9001.VehicleNo); | |||
Assert.Equal(JT809VehicleColorType.蓝色, jT809_0X9001.VehicleColor); | |||
Assert.Equal(JT809SubBusinessType.上传车辆注册信息, jT809_0X9001.SubBusinessType); | |||
Assert.Equal(JT809SubBusinessType.上传车辆注册信息, (JT809SubBusinessType)jT809_0X9001.SubBusinessType); | |||
Assert.Equal((ushort)61, jT809_0X9001.DataLength); | |||
JT809_0x1200_0x1201 jT809_0X1200_0X1201 = jT809_0X9001.SubBodies as JT809_0x1200_0x1201; | |||
Assert.Equal("1111111111", jT809_0X1200_0X1201.PlateformId); | |||
@@ -18,7 +18,7 @@ namespace JT809.Protocol.Test.JT809MessageBody | |||
public void Test1() | |||
{ | |||
JT809_0x1300 jT809Bodies = new JT809_0x1300(); | |||
jT809Bodies.SubBusinessType = JT809SubBusinessType.平台查岗应答; | |||
jT809Bodies.SubBusinessType = JT809SubBusinessType.平台查岗应答.ToUInt16Value(); | |||
jT809Bodies.SubBodies = new JT809_0x1300_0x1301 | |||
{ | |||
ObjectID="111", | |||
@@ -36,7 +36,7 @@ namespace JT809.Protocol.Test.JT809MessageBody | |||
{ | |||
var bytes = "13 01 00 00 00 1B 01 31 31 31 00 00 00 00 00 00 00 00 00 00 00 04 D2 00 00 00 06 32 32 68 61 32 32".ToHexBytes(); | |||
JT809_0x1300 jT809Bodies = JT809Serializer.Deserialize<JT809_0x1300>(bytes); | |||
Assert.Equal(JT809SubBusinessType.平台查岗应答, jT809Bodies.SubBusinessType); | |||
Assert.Equal(JT809SubBusinessType.平台查岗应答, (JT809SubBusinessType)jT809Bodies.SubBusinessType); | |||
JT809_0x1300_0x1301 jT809SubBodies = (JT809_0x1300_0x1301)jT809Bodies.SubBodies; | |||
Assert.Equal("111", jT809SubBodies.ObjectID); | |||
Assert.Equal("22ha22", jT809SubBodies.InfoContent); | |||
@@ -20,7 +20,7 @@ namespace JT809.Protocol.Test.JT809MessageBody | |||
JT809_0x1600 jT809Bodies = new JT809_0x1600(); | |||
jT809Bodies.VehicleNo = "粤A12345"; | |||
jT809Bodies.VehicleColor = JT809VehicleColorType.蓝色; | |||
jT809Bodies.SubBusinessType = JT809SubBusinessType.补报车辆静态信息应答; | |||
jT809Bodies.SubBusinessType = JT809SubBusinessType.补报车辆静态信息应答.ToUInt16Value(); | |||
jT809Bodies.SubBodies = new JT809_0x1600_0x1601 | |||
{ | |||
CarInfo = "什么鬼" | |||
@@ -37,7 +37,7 @@ namespace JT809.Protocol.Test.JT809MessageBody | |||
JT809_0x1600 jT809Bodies = JT809Serializer.Deserialize<JT809_0x1600>(bytes); | |||
Assert.Equal("粤A12345", jT809Bodies.VehicleNo); | |||
Assert.Equal(JT809VehicleColorType.蓝色, jT809Bodies.VehicleColor); | |||
Assert.Equal(JT809SubBusinessType.补报车辆静态信息应答, jT809Bodies.SubBusinessType); | |||
Assert.Equal(JT809SubBusinessType.补报车辆静态信息应答, (JT809SubBusinessType)jT809Bodies.SubBusinessType); | |||
Assert.Equal("什么鬼", ((JT809_0x1600_0x1601)jT809Bodies.SubBodies).CarInfo); | |||
} | |||
} | |||
@@ -21,7 +21,7 @@ namespace JT809.Protocol.Test.JT809Packages | |||
Assert.Equal((uint)133, jT809HeaderPackage.Header.MsgSN); | |||
Assert.Equal((uint)9999, jT809HeaderPackage.Header.EncryptKey); | |||
Assert.Equal((uint)20180920, jT809HeaderPackage.Header.MsgGNSSCENTERID); | |||
Assert.Equal(JT809BusinessType.主链路登录请求消息, jT809HeaderPackage.Header.BusinessType); | |||
Assert.Equal(JT809BusinessType.主链路登录请求消息, (JT809BusinessType)jT809HeaderPackage.Header.BusinessType); | |||
Assert.Equal(new JT809Header_Version().ToString(), jT809HeaderPackage.Header.Version.ToString()); | |||
JT809_0x1001 jT809_0X1001 = JT809Serializer.Deserialize<JT809_0x1001>(jT809HeaderPackage.Bodies); | |||
Assert.Equal((uint)20180920, jT809_0X1001.UserId); | |||
@@ -40,7 +40,7 @@ namespace JT809.Protocol.Test.JT809Packages | |||
EncryptFlag = JT809Header_Encrypt.Common, | |||
MsgSN = 133, | |||
EncryptKey = 256178, | |||
BusinessType = JT809BusinessType.主链路登录请求消息, | |||
BusinessType = JT809BusinessType.主链路登录请求消息.ToUInt16Value(), | |||
MsgGNSSCENTERID = 20180920, | |||
}; | |||
JT809_0x1001 jT809_0X1001 = new JT809_0x1001(); | |||
@@ -66,7 +66,7 @@ namespace JT809.Protocol.Test.JT809Packages | |||
Assert.Equal((uint)72, jT809Package.Header.MsgLength); | |||
Assert.Equal((uint)133, jT809Package.Header.MsgSN); | |||
Assert.Equal((uint)20180920, jT809Package.Header.MsgGNSSCENTERID); | |||
Assert.Equal(JT809BusinessType.主链路登录请求消息, jT809Package.Header.BusinessType); | |||
Assert.Equal(JT809BusinessType.主链路登录请求消息, (JT809BusinessType)jT809Package.Header.BusinessType); | |||
Assert.Equal("1.0.0", jT809Package.Header.Version.ToString()); | |||
JT809_0x1001 jT809_0X1001 = (JT809_0x1001)jT809Package.Bodies; | |||
Assert.Equal((uint)20180920, jT809_0X1001.UserId); | |||
@@ -20,7 +20,7 @@ namespace JT809.Protocol.Test.JT809Packages | |||
{ | |||
MsgSN= 133, | |||
EncryptKey=9999, | |||
BusinessType= JT809BusinessType.主链路登录请求消息, | |||
BusinessType= JT809BusinessType.主链路登录请求消息.ToUInt16Value(), | |||
MsgGNSSCENTERID= 20180920, | |||
}; | |||
JT809_0x1001 jT809_0X1001 = new JT809_0x1001(); | |||
@@ -58,7 +58,7 @@ namespace JT809.Protocol.Test.JT809Packages | |||
Assert.Equal((uint)133, jT809Package.Header.MsgSN); | |||
Assert.Equal((uint)9999, jT809Package.Header.EncryptKey); | |||
Assert.Equal((uint)20180920, jT809Package.Header.MsgGNSSCENTERID); | |||
Assert.Equal(JT809BusinessType.主链路登录请求消息, jT809Package.Header.BusinessType); | |||
Assert.Equal(JT809BusinessType.主链路登录请求消息, (JT809BusinessType)jT809Package.Header.BusinessType); | |||
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); | |||
@@ -20,7 +20,7 @@ namespace JT809.Protocol.Test.JT809SubMessageBody | |||
JT809_0x9400_0x9401 jT809_0x9400_0x9401 = new JT809_0x9400_0x9401 | |||
{ | |||
WarnSrc= JT809WarnSrc.车载终端, | |||
WarnType= JT809WarnType.疲劳驾驶报警, | |||
WarnType= JT809WarnType.疲劳驾驶报警.ToUInt16Value(), | |||
WarnTime=DateTime.Parse("2018-09-27 10:24:00"), | |||
SupervisionID="123FFAA1", | |||
SupervisionEndTime= DateTime.Parse("2018-09-27 11:24:00"), | |||
@@ -42,7 +42,7 @@ namespace JT809.Protocol.Test.JT809SubMessageBody | |||
var bytes = "01 00 02 00 00 00 00 5B AC 3F 40 12 3F FA A1 00 00 00 00 5B AC 4D 50 03 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 31 32 33 34 35 36 37 38 39 30 31 00 00 00 00 00 00 00 00 00 31 32 33 34 35 36 40 71 71 2E 63 6F 6D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00".ToHexBytes(); | |||
JT809_0x9400_0x9401 jT809_0x9400_0x9401 = JT809Serializer.Deserialize<JT809_0x9400_0x9401>(bytes); | |||
Assert.Equal(JT809WarnSrc.车载终端, jT809_0x9400_0x9401.WarnSrc); | |||
Assert.Equal(JT809WarnType.疲劳驾驶报警, jT809_0x9400_0x9401.WarnType); | |||
Assert.Equal(JT809WarnType.疲劳驾驶报警, (JT809WarnType)jT809_0x9400_0x9401.WarnType); | |||
Assert.Equal(DateTime.Parse("2018-09-27 10:24:00"), jT809_0x9400_0x9401.WarnTime); | |||
Assert.Equal("123FFAA1", jT809_0x9400_0x9401.SupervisionID); | |||
Assert.Equal(DateTime.Parse("2018-09-27 11:24:00"), jT809_0x9400_0x9401.SupervisionEndTime); | |||
@@ -9,9 +9,9 @@ using JT809.Protocol.SubMessageBody; | |||
using JT809.Protocol.Enums; | |||
using JT809.Protocol.Configs; | |||
namespace JT809.Protocol.Test.JT809Packages | |||
namespace JT809.Protocol.Test.Simples | |||
{ | |||
public class JT809_0x9400_0x9401PackageTest | |||
public class Demo1 | |||
{ | |||
private JT809Serializer JT809Serializer = new JT809Serializer(); | |||
@@ -24,23 +24,23 @@ namespace JT809.Protocol.Test.JT809Packages | |||
{ | |||
MsgSN = 1666, | |||
EncryptKey = 9999, | |||
EncryptFlag= JT809Header_Encrypt.None, | |||
EncryptFlag = JT809Header_Encrypt.None, | |||
Version = new JT809Header_Version(1, 0, 0), | |||
BusinessType = JT809BusinessType.从链路报警信息交互消息, | |||
BusinessType = JT809BusinessType.从链路报警信息交互消息.ToUInt16Value(), | |||
MsgGNSSCENTERID = 20180920, | |||
}; | |||
JT809_0x9400 bodies = new JT809_0x9400 | |||
{ | |||
VehicleNo="粤A12345", | |||
VehicleColor= JT809VehicleColorType.黄色, | |||
SubBusinessType= JT809SubBusinessType.报警督办请求, | |||
VehicleNo = "粤A12345", | |||
VehicleColor = JT809VehicleColorType.黄色, | |||
SubBusinessType = JT809SubBusinessType.报警督办请求.ToUInt16Value(), | |||
}; | |||
JT809_0x9400_0x9401 jT809_0x9400_0x9401 = new JT809_0x9400_0x9401 | |||
{ | |||
WarnSrc = JT809WarnSrc.车载终端, | |||
WarnType = JT809WarnType.疲劳驾驶报警, | |||
WarnType = JT809WarnType.疲劳驾驶报警.ToUInt16Value(), | |||
WarnTime = DateTime.Parse("2018-09-27 10:24:00"), | |||
SupervisionID = "123FFAA1", | |||
SupervisionEndTime = DateTime.Parse("2018-09-27 11:24:00"), | |||
@@ -53,8 +53,6 @@ namespace JT809.Protocol.Test.JT809Packages | |||
jT809Package.Bodies = bodies; | |||
var hex = JT809Serializer.Serialize(jT809Package).ToHexString(); | |||
//"5B 00 00 00 92 00 00 06 82 94 00 01 33 EF B8 01 00 00 00 00 00 27 0F D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 02 94 01 00 00 00 5C 01 00 02 00 00 00 00 5A 01 AC 3F 40 12 3F FA A1 00 00 00 00 5A 01 AC 4D 50 03 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 31 32 33 34 35 36 37 38 39 30 31 00 00 00 00 00 00 00 00 00 31 32 33 34 35 36 40 71 71 2E 63 6F 6D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 BA D8 5D" | |||
//5B000000900000068294000133EFB8010000000000270FD4C1413132333435000000000000000000000000000294010000005C010002000000005A01AC3F40123FFAA1000000005A01AC4D5003736D616C6C636869000000000000000031323334353637383930310000000000000000003132333435364071712E636F6D00000000000000000000000000000000000000C69C5D | |||
//5B000000920000068294000133EFB8010000000000270FD4C1413132333435000000000000000000000000000294010000005C010002000000005A01AC3F40123FFAA1000000005A01AC4D5003736D616C6C636869000000000000000031323334353637383930310000000000000000003132333435364071712E636F6D00000000000000000000000000000000000000BAD85D | |||
Assert.Equal("5B000000920000068294000133EFB8010000000000270FD4C1413132333435000000000000000000000000000294010000005C010002000000005A01AC3F40123FFAA1000000005A01AC4D5003736D616C6C636869000000000000000031323334353637383930310000000000000000003132333435364071712E636F6D00000000000000000000000000000000000000BAD85D", hex); | |||
} | |||
@@ -69,18 +67,18 @@ namespace JT809.Protocol.Test.JT809Packages | |||
Assert.Equal((uint)9999, jT809Package.Header.EncryptKey); | |||
Assert.Equal(JT809Header_Encrypt.None, jT809Package.Header.EncryptFlag); | |||
Assert.Equal((uint)20180920, jT809Package.Header.MsgGNSSCENTERID); | |||
Assert.Equal(JT809BusinessType.从链路报警信息交互消息, jT809Package.Header.BusinessType); | |||
Assert.Equal(JT809BusinessType.从链路报警信息交互消息, (JT809BusinessType)jT809Package.Header.BusinessType); | |||
Assert.Equal(new JT809Header_Version().ToString(), jT809Package.Header.Version.ToString()); | |||
JT809_0x9400 jT809_0X400 = (JT809_0x9400)jT809Package.Bodies; | |||
Assert.Equal("粤A12345", jT809_0X400.VehicleNo); | |||
Assert.Equal(JT809VehicleColorType.黄色, jT809_0X400.VehicleColor); | |||
Assert.Equal(JT809SubBusinessType.报警督办请求, jT809_0X400.SubBusinessType); | |||
Assert.Equal(JT809SubBusinessType.报警督办请求, (JT809SubBusinessType)jT809_0X400.SubBusinessType); | |||
Assert.Equal((uint)92, jT809_0X400.DataLength); | |||
JT809_0x9400_0x9401 jT809_0x9400_0x9401 = (JT809_0x9400_0x9401)jT809_0X400.SubBodies; | |||
Assert.Equal(JT809WarnSrc.车载终端, jT809_0x9400_0x9401.WarnSrc); | |||
Assert.Equal(JT809WarnType.疲劳驾驶报警, jT809_0x9400_0x9401.WarnType); | |||
Assert.Equal(JT809WarnType.疲劳驾驶报警, (JT809WarnType)jT809_0x9400_0x9401.WarnType); | |||
Assert.Equal(DateTime.Parse("2018-09-27 10:24:00"), jT809_0x9400_0x9401.WarnTime); | |||
Assert.Equal("123FFAA1", jT809_0x9400_0x9401.SupervisionID); | |||
Assert.Equal(DateTime.Parse("2018-09-27 11:24:00"), jT809_0x9400_0x9401.SupervisionEndTime); | |||
@@ -98,20 +96,20 @@ namespace JT809.Protocol.Test.JT809Packages | |||
{ | |||
VehicleNo = "粤A12345", | |||
VehicleColor = JT809VehicleColorType.黄色, | |||
SubBusinessType = JT809SubBusinessType.报警督办请求, | |||
SubBusinessType = JT809SubBusinessType.报警督办请求.ToUInt16Value(), | |||
SubBodies = new JT809_0x9400_0x9401 | |||
{ | |||
WarnSrc = JT809WarnSrc.车载终端, | |||
WarnType = JT809WarnType.疲劳驾驶报警, | |||
WarnTime = DateTime.Parse("2018-09-27 10:24:00"), | |||
SupervisionID = "123FFAA1", | |||
SupervisionEndTime = DateTime.Parse("2018-09-27 11:24:00"), | |||
SupervisionLevel = 3, | |||
Supervisor = "smallchi", | |||
SupervisorTel = "12345678901", | |||
SupervisorEmail = "123456@qq.com" | |||
WarnSrc = JT809WarnSrc.车载终端, | |||
WarnType = JT809WarnType.疲劳驾驶报警.ToUInt16Value(), | |||
WarnTime = DateTime.Parse("2018-09-27 10:24:00"), | |||
SupervisionID = "123FFAA1", | |||
SupervisionEndTime = DateTime.Parse("2018-09-27 11:24:00"), | |||
SupervisionLevel = 3, | |||
Supervisor = "smallchi", | |||
SupervisorTel = "12345678901", | |||
SupervisorEmail = "123456@qq.com" | |||
} | |||
}); | |||
}); | |||
jT809Package.Header.MsgSN = 1666; | |||
jT809Package.Header.EncryptKey = 9999; | |||
jT809Package.Header.MsgGNSSCENTERID = 20180920; |
@@ -0,0 +1,24 @@ | |||
using JT809.Protocol.Configs; | |||
using JT809.Protocol.Interfaces; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
namespace JT809.Protocol.Test.Simples | |||
{ | |||
public class Demo2 | |||
{ | |||
class JT809GlobalConfig : GlobalConfigBase | |||
{ | |||
public override JT809EncryptOptions EncryptOptions { get; set; } = new JT809EncryptOptions() | |||
{ | |||
IA1 = 20000000, | |||
IC1 = 20000000, | |||
M1 = 30000000 | |||
}; | |||
public override string ConfigId => "JT809GlobalConfig"; | |||
} | |||
JT809Serializer JT809Serializer = new JT809Serializer(new JT809GlobalConfig()); | |||
} | |||
} |
@@ -0,0 +1,82 @@ | |||
using Microsoft.Extensions.DependencyInjection; | |||
using System; | |||
using JT809.Protocol.Test.JT1078; | |||
using JT809.Protocol.Extensions; | |||
using Xunit; | |||
using JT809.Protocol.Enums; | |||
namespace JT809.Protocol.Test.Simples | |||
{ | |||
public class Demo3 | |||
{ | |||
IServiceProvider ServiceProvider; | |||
JT809Serializer JT809Serializer; | |||
public Demo3() | |||
{ | |||
IServiceCollection serviceDescriptors = new ServiceCollection(); | |||
serviceDescriptors.AddJT809Configure() | |||
.AddJT1078Configure(); | |||
ServiceProvider = serviceDescriptors.BuildServiceProvider(); | |||
var config = ServiceProvider.GetRequiredService<IJT809Config>(); | |||
JT809Serializer = config.GetSerializer(); | |||
} | |||
[Fact] | |||
public void Test1() | |||
{ | |||
JT809Package jT809Package = new JT809Package(); | |||
jT809Package.Header = new JT809Header | |||
{ | |||
MsgSN = 1666, | |||
EncryptKey = 9999, | |||
EncryptFlag = JT809Header_Encrypt.None, | |||
Version = new JT809Header_Version(1, 0, 0), | |||
BusinessType = JT809_JT1078_BusinessType.主链路时效口令业务类.ToUInt16Value(), | |||
MsgGNSSCENTERID = 20190708, | |||
}; | |||
JT808_JT1078_0x1700 bodies = new JT808_JT1078_0x1700 | |||
{ | |||
VehicleNo = "粤A12345", | |||
VehicleColor = JT809VehicleColorType.黄色, | |||
SubBusinessType = JT809_JT1078_SubBusinessType.时效口令上报消息.ToUInt16Value(), | |||
}; | |||
JT808_JT1078_0x1700_0x1701 jT808_JT1078_0x1700_0x1701 = new JT808_JT1078_0x1700_0x1701 | |||
{ | |||
PlateFormId = new byte[11] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11 }, | |||
AuthorizeCode1 = new byte[64], | |||
AuthorizeCode2 = new byte[64] | |||
}; | |||
bodies.SubBodies = jT808_JT1078_0x1700_0x1701; | |||
jT809Package.Bodies = bodies; | |||
var hex = JT809Serializer.Serialize(jT809Package).ToHexString(); | |||
//5B000000C1000006821700013415F4010000000000270FD4C1413132333435000000000000000000000000000217010000008B01020304050607080910110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000B22E5D | |||
Assert.Equal("5B000000C1000006821700013415F4010000000000270FD4C1413132333435000000000000000000000000000217010000008B01020304050607080910110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000B22E5D", hex); | |||
} | |||
[Fact] | |||
public void Test2() | |||
{ | |||
var data = "5B000000C1000006821700013415F4010000000000270FD4C1413132333435000000000000000000000000000217010000008B01020304050607080910110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000B22E5D".ToHexBytes(); | |||
JT809Package jT809Package = JT809Serializer.Deserialize(data); | |||
Assert.Equal((uint)1666, jT809Package.Header.MsgSN); | |||
Assert.Equal((uint)9999, jT809Package.Header.EncryptKey); | |||
Assert.Equal(JT809Header_Encrypt.None, jT809Package.Header.EncryptFlag); | |||
Assert.Equal(new JT809Header_Version(1, 0, 0).ToString(), jT809Package.Header.Version.ToString()); | |||
Assert.Equal(0x1700, jT809Package.Header.BusinessType); | |||
Assert.Equal((uint)20190708, jT809Package.Header.MsgGNSSCENTERID); | |||
JT809ExchangeMessageBodies bodies = jT809Package.Bodies as JT809ExchangeMessageBodies; | |||
JT808_JT1078_0x1700_0x1701 subBodies = bodies.SubBodies as JT808_JT1078_0x1700_0x1701; | |||
Assert.Equal(new byte[11] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11 }, subBodies.PlateFormId); | |||
Assert.Equal(new byte[64], subBodies.AuthorizeCode1); | |||
Assert.Equal(new byte[64], subBodies.AuthorizeCode2); | |||
} | |||
} | |||
} |
@@ -9,10 +9,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT809.Protocol.Test", "JT80 | |||
EndProject | |||
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 | |||
Global | |||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | |||
Debug|Any CPU = Debug|Any CPU | |||
@@ -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 | |||
{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 | |||
GlobalSection(SolutionProperties) = preSolution | |||
HideSolutionNode = FALSE | |||
@@ -8,13 +8,20 @@ namespace JT809.Protocol.Attributes | |||
[AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)] | |||
public sealed class JT809SubBusinessTypeDescriptionAttribute : Attribute | |||
{ | |||
public JT809BusinessType BusinessType { get; set; } | |||
public ushort BusinessType { get; set; } | |||
public string Code { get; set; } | |||
public string Name { get; set; } | |||
public JT809SubBusinessTypeDescriptionAttribute(string code,string name, JT809BusinessType businessType) | |||
{ | |||
Code = code; | |||
Name = name; | |||
BusinessType = (ushort)businessType; | |||
} | |||
public JT809SubBusinessTypeDescriptionAttribute(string code, string name, ushort businessType) | |||
{ | |||
Code = code; | |||
Name = name; | |||
@@ -14,6 +14,8 @@ namespace JT809.Protocol.Enums | |||
HeaderParseError=1006, | |||
BodiesParseError=1007, | |||
SubBodiesParseError = 1008, | |||
GetAttributeError=1009 | |||
GetAttributeError=1009, | |||
GetFormatterAttributeError=1010, | |||
NotGlobalRegisterFormatterAssembly=1011, | |||
} | |||
} |
@@ -1,14 +1,30 @@ | |||
using JT809.Protocol.Interfaces; | |||
using JT809.Protocol.Enums; | |||
using JT809.Protocol.Exceptions; | |||
using JT809.Protocol.Formatters; | |||
using JT809.Protocol.Interfaces; | |||
using System; | |||
using System.Collections.Concurrent; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
namespace JT809.Protocol.Extensions | |||
namespace JT809.Protocol | |||
{ | |||
public static class JT809ConfigExtensions | |||
{ | |||
private readonly static ConcurrentDictionary<string, JT809Serializer> jT809SerializerDict = new ConcurrentDictionary<string, JT809Serializer>(StringComparer.OrdinalIgnoreCase); | |||
public static object GetMessagePackFormatterByType(this IJT809Config jT809Config, Type type) | |||
{ | |||
if (!jT809Config.FormatterFactory.FormatterDict.TryGetValue(type.GUID, out var formatter)) | |||
{ | |||
throw new JT809Exception(JT809ErrorCode.NotGlobalRegisterFormatterAssembly, type.FullName); | |||
} | |||
return formatter; | |||
} | |||
public static IJT809MessagePackFormatter<T> GetMessagePackFormatter<T>(this IJT809Config jT809Config) | |||
{ | |||
return (IJT809MessagePackFormatter<T>)GetMessagePackFormatterByType(jT809Config, typeof(T)); | |||
} | |||
public static JT809Serializer GetSerializer(this IJT809Config jT808Config) | |||
{ | |||
if(!jT809SerializerDict.TryGetValue(jT808Config.ConfigId,out var serializer)) | |||
@@ -18,7 +18,7 @@ namespace JT809.Protocol.Extensions | |||
/// </summary> | |||
public static class JT809MessagePackFormatterResolverExtensions | |||
{ | |||
delegate int JT809SerializeMethod(object dynamicFormatter, ref JT809MessagePackWriter writer,object value, IJT809Config config); | |||
delegate void JT809SerializeMethod(object dynamicFormatter, ref JT809MessagePackWriter writer,object value, IJT809Config config); | |||
delegate dynamic JT809DeserializeMethod(object dynamicFormatter, ref JT809MessagePackReader reader, IJT809Config config); | |||
@@ -26,7 +26,7 @@ namespace JT809.Protocol.Extensions | |||
static readonly ConcurrentDictionary<Type, (object Value, JT809DeserializeMethod DeserializeMethod)> jT809Deserializes = new ConcurrentDictionary<Type, (object Value, JT809DeserializeMethod DeserializeMethod)>(); | |||
public static int JT809DynamicSerialize(object objFormatter, ref JT809MessagePackWriter writer, object value, IJT809Config config) | |||
public static void JT809DynamicSerialize(object objFormatter, ref JT809MessagePackWriter writer, object value, IJT809Config config) | |||
{ | |||
Type type = value.GetType(); | |||
var ti = type.GetTypeInfo(); | |||
@@ -52,7 +52,7 @@ namespace JT809.Protocol.Extensions | |||
} | |||
jT809Serializers.TryAdd(t, formatterAndDelegate); | |||
} | |||
return formatterAndDelegate.SerializeMethod(formatterAndDelegate.Value, ref writer, value, config); | |||
formatterAndDelegate.SerializeMethod(formatterAndDelegate.Value, ref writer, value, config); | |||
} | |||
public static dynamic JT809DynamicDeserialize(object objFormatter, ref JT809MessagePackReader reader, IJT809Config config) | |||
@@ -14,12 +14,34 @@ namespace JT809.Protocol.Extensions | |||
jT809Package.Bodies = jT809Bodies; | |||
jT809Package.Header = new JT809Header() | |||
{ | |||
BusinessType = jT809BusinessType | |||
BusinessType = (ushort)jT809BusinessType | |||
}; | |||
return jT809Package; | |||
} | |||
public static JT809Package Create<TJT809Bodies>(this ushort jT809BusinessType, TJT809Bodies jT809Bodies) | |||
where TJT809Bodies : JT809Bodies | |||
{ | |||
JT809Package jT809Package = new JT809Package(); | |||
jT809Package.Bodies = jT809Bodies; | |||
jT809Package.Header = new JT809Header() | |||
{ | |||
BusinessType = jT809BusinessType | |||
}; | |||
return jT809Package; | |||
} | |||
public static JT809Package Create(this JT809BusinessType jT809BusinessType) | |||
{ | |||
JT809Package jT809Package = new JT809Package(); | |||
jT809Package.Header = new JT809Header() | |||
{ | |||
BusinessType = (ushort)jT809BusinessType, | |||
}; | |||
return jT809Package; | |||
} | |||
public static JT809Package Create(this ushort jT809BusinessType) | |||
{ | |||
JT809Package jT809Package = new JT809Package(); | |||
jT809Package.Header = new JT809Header() | |||
@@ -31,6 +53,23 @@ namespace JT809.Protocol.Extensions | |||
public static JT809Package Create<TJT809Bodies>(this JT809BusinessType jT809BusinessType, JT809Header jT809Header, TJT809Bodies jT809Bodies) | |||
where TJT809Bodies : JT809Bodies | |||
{ | |||
JT809Package jT809Package = new JT809Package(); | |||
jT809Package.Bodies = jT809Bodies; | |||
jT809Package.Header = new JT809Header() | |||
{ | |||
BusinessType = (ushort)jT809BusinessType, | |||
MsgSN = jT809Header.MsgSN, | |||
EncryptFlag = jT809Header.EncryptFlag, | |||
EncryptKey = jT809Header.EncryptKey, | |||
MsgGNSSCENTERID = jT809Header.MsgGNSSCENTERID, | |||
Version = jT809Header.Version | |||
}; | |||
return jT809Package; | |||
} | |||
public static JT809Package Create<TJT809Bodies>(this ushort jT809BusinessType, JT809Header jT809Header, TJT809Bodies jT809Bodies) | |||
where TJT809Bodies : JT809Bodies | |||
{ | |||
JT809Package jT809Package = new JT809Package(); | |||
jT809Package.Bodies = jT809Bodies; | |||
@@ -47,6 +86,21 @@ namespace JT809.Protocol.Extensions | |||
} | |||
public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809Header jT809Header) | |||
{ | |||
JT809Package jT809Package = new JT809Package(); | |||
jT809Package.Header = new JT809Header() | |||
{ | |||
BusinessType = (ushort)jT809BusinessType, | |||
MsgSN = jT809Header.MsgSN, | |||
EncryptFlag = jT809Header.EncryptFlag, | |||
EncryptKey = jT809Header.EncryptKey, | |||
MsgGNSSCENTERID = jT809Header.MsgGNSSCENTERID, | |||
Version = jT809Header.Version | |||
}; | |||
return jT809Package; | |||
} | |||
public static JT809Package Create(this ushort jT809BusinessType, JT809Header jT809Header) | |||
{ | |||
JT809Package jT809Package = new JT809Package(); | |||
jT809Package.Header = new JT809Header() | |||
@@ -0,0 +1,18 @@ | |||
using JT809.Protocol; | |||
using JT809.Protocol.Interfaces; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Reflection; | |||
using System.Text; | |||
namespace JT808.Protocol.Formatters | |||
{ | |||
public interface IJT809FormatterFactory : IJT809ExternalRegister | |||
{ | |||
Dictionary<Guid,object> FormatterDict { get;} | |||
IJT809FormatterFactory SetMap<TJT809Bodies>() | |||
where TJT809Bodies : JT809Bodies; | |||
IJT809FormatterFactory SetSubMap<TJT809SubBodies>() | |||
where TJT809SubBodies : JT809SubBodies; | |||
} | |||
} |
@@ -30,11 +30,15 @@ namespace JT809.Protocol.Formatters | |||
TJT809Bodies jT809Bodies = new TJT809Bodies(); | |||
jT809Bodies.VehicleNo = reader.ReadString(21); | |||
jT809Bodies.VehicleColor = (JT809VehicleColorType)reader.ReadByte(); | |||
jT809Bodies.SubBusinessType = (JT809SubBusinessType)reader.ReadUInt16(); | |||
jT809Bodies.SubBusinessType = reader.ReadUInt16(); | |||
jT809Bodies.DataLength = reader.ReadUInt32(); | |||
try | |||
{ | |||
jT809Bodies.SubBodies = jT809Bodies.SubBusinessType.Deserialize(ref reader, config); | |||
Type jT809SubBodiesImplType = config.SubBusinessTypeFactory.GetSubBodiesImplTypeBySubBusinessType(jT809Bodies.SubBusinessType); | |||
if (jT809SubBodiesImplType != null) | |||
jT809Bodies.SubBodies = JT809MessagePackFormatterResolverExtensions.JT809DynamicDeserialize( | |||
config.GetMessagePackFormatterByType(jT809SubBodiesImplType), | |||
ref reader, config); | |||
} | |||
catch | |||
{ | |||
@@ -47,12 +51,18 @@ namespace JT809.Protocol.Formatters | |||
{ | |||
writer.WriteStringPadRight(value.VehicleNo, 21); | |||
writer.WriteByte((byte)value.VehicleColor); | |||
writer.WriteUInt16((ushort)value.SubBusinessType); | |||
writer.WriteUInt16(value.SubBusinessType); | |||
try | |||
{ | |||
// 先写入内容,然后在根据内容反写内容长度 | |||
writer.Skip(4, out int subContentLengthPosition); | |||
value.SubBusinessType.Serialize(ref writer,value.SubBodies, config); | |||
if (value.SubBodies != null) | |||
{ | |||
JT809MessagePackFormatterResolverExtensions.JT809DynamicSerialize( | |||
config.GetMessagePackFormatterByType(value.SubBodies.GetType()), | |||
ref writer, value.SubBodies, | |||
config); | |||
} | |||
writer.WriteInt32Return(writer.GetCurrentPosition()- subContentLengthPosition - 4, subContentLengthPosition); | |||
} | |||
catch | |||
@@ -18,7 +18,7 @@ namespace JT809.Protocol.Formatters | |||
JT809Header jT809Header = new JT809Header(); | |||
jT809Header.MsgLength = reader.ReadUInt32(); | |||
jT809Header.MsgSN = reader.ReadUInt32(); | |||
jT809Header.BusinessType = (JT809BusinessType)reader.ReadUInt16(); | |||
jT809Header.BusinessType = reader.ReadUInt16(); | |||
jT809Header.MsgGNSSCENTERID = reader.ReadUInt32(); | |||
jT809Header.Version = new JT809Header_Version(reader.ReadArray(JT809Header_Version.FixedByteLength)); | |||
jT809Header.EncryptFlag = (JT809Header_Encrypt)reader.ReadByte(); | |||
@@ -30,7 +30,7 @@ namespace JT809.Protocol.Formatters | |||
{ | |||
writer.WriteUInt32(value.MsgLength); | |||
writer.WriteUInt32( value.MsgSN); | |||
writer.WriteUInt16((ushort)value.BusinessType); | |||
writer.WriteUInt16(value.BusinessType); | |||
writer.WriteUInt32(value.MsgGNSSCENTERID); | |||
writer.WriteArray(value.Version.Buffer); | |||
writer.WriteByte((byte)value.EncryptFlag); | |||
@@ -44,19 +44,27 @@ namespace JT809.Protocol.Formatters | |||
{ | |||
try | |||
{ | |||
// 5.2 是否加密 | |||
switch (jT809Package.Header.EncryptFlag) | |||
Type jT809BodiesImplType = config.BusinessTypeFactory.GetBodiesImplTypeByBusinessType(jT809Package.Header.BusinessType, jT809Package.Header.MsgGNSSCENTERID); | |||
if (jT809BodiesImplType != null) | |||
{ | |||
case JT809Header_Encrypt.None: | |||
// 5.3 处理消息体 | |||
jT809Package.Bodies = jT809Package.Header.BusinessType.Deserialize(ref reader, config); | |||
break; | |||
case JT809Header_Encrypt.Common: | |||
// 5.4. 处理加密消息体 | |||
byte[] bodiesData = config.Encrypt.Decrypt(reader.ReadContent(), config.EncryptOptions, jT809Package.Header.EncryptKey); | |||
JT809MessagePackReader bodiesReader = new JT809MessagePackReader(bodiesData); | |||
jT809Package.Bodies = jT809Package.Header.BusinessType.Deserialize(ref bodiesReader, config); | |||
break; | |||
// 5.2 是否加密 | |||
switch (jT809Package.Header.EncryptFlag) | |||
{ | |||
case JT809Header_Encrypt.None: | |||
// 5.3 处理消息体 | |||
jT809Package.Bodies = JT809MessagePackFormatterResolverExtensions.JT809DynamicDeserialize( | |||
config.GetMessagePackFormatterByType(jT809BodiesImplType), | |||
ref reader, config); | |||
break; | |||
case JT809Header_Encrypt.Common: | |||
// 5.4. 处理加密消息体 | |||
byte[] bodiesData = config.Encrypt.Decrypt(reader.ReadContent(), config.EncryptOptions, jT809Package.Header.EncryptKey); | |||
JT809MessagePackReader bodiesReader = new JT809MessagePackReader(bodiesData); | |||
jT809Package.Bodies = JT809MessagePackFormatterResolverExtensions.JT809DynamicDeserialize( | |||
config.GetMessagePackFormatterByType(jT809BodiesImplType), | |||
ref bodiesReader, config); | |||
break; | |||
} | |||
} | |||
} | |||
catch (Exception ex) | |||
@@ -81,7 +89,7 @@ namespace JT809.Protocol.Formatters | |||
value.Header.MsgSN = value.Header.MsgSN > 0 ? value.Header.MsgSN : config.MsgSNDistributed.Increment(); | |||
writer.WriteUInt32(value.Header.MsgSN); | |||
// 2.3.业务数据类型 | |||
writer.WriteUInt16((ushort)value.Header.BusinessType); | |||
writer.WriteUInt16(value.Header.BusinessType); | |||
// 2.4.下级平台接入码 | |||
writer.WriteUInt32(value.Header.MsgGNSSCENTERID); | |||
// 2.5.版本号 | |||
@@ -94,7 +102,13 @@ namespace JT809.Protocol.Formatters | |||
// 3.1.记录当前开始位置 | |||
int startIndex = writer.GetCurrentPosition(); | |||
// 3.2.写入数据对应数据体 | |||
value.Header.BusinessType.Serialize(ref writer, value.Bodies, config); | |||
if (value.Bodies != null) | |||
{ | |||
JT809MessagePackFormatterResolverExtensions.JT809DynamicSerialize( | |||
config.GetMessagePackFormatterByType(value.Bodies.GetType()), | |||
ref writer, value.Bodies, | |||
config); | |||
} | |||
// 3.3.记录当前结束位置 | |||
int endIndex = writer.GetCurrentPosition(); | |||
int contentLength = endIndex - startIndex; | |||
@@ -20,12 +20,16 @@ namespace JT809.Protocol.Formatters.MessageBodyFormatters | |||
public JT809_0x1300 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) | |||
{ | |||
JT809_0x1300 jT809_0X1300 = new JT809_0x1300(); | |||
jT809_0X1300.SubBusinessType = (JT809SubBusinessType)reader.ReadUInt16(); | |||
jT809_0X1300.SubBusinessType = reader.ReadUInt16(); | |||
jT809_0X1300.DataLength = reader.ReadUInt32(); | |||
try | |||
{ | |||
//JT809.Protocol.Enums.JT809BusinessType 映射对应消息特性 | |||
jT809_0X1300.SubBodies = jT809_0X1300.SubBusinessType.Deserialize(ref reader, config); | |||
Type jT809SubBodiesImplType = config.SubBusinessTypeFactory.GetSubBodiesImplTypeBySubBusinessType(jT809_0X1300.SubBusinessType); | |||
if (jT809SubBodiesImplType != null) | |||
jT809_0X1300.SubBodies = JT809MessagePackFormatterResolverExtensions.JT809DynamicDeserialize( | |||
config.GetMessagePackFormatterByType(jT809SubBodiesImplType), | |||
ref reader, config); | |||
} | |||
catch | |||
{ | |||
@@ -36,13 +40,19 @@ namespace JT809.Protocol.Formatters.MessageBodyFormatters | |||
public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1300 value, IJT809Config config) | |||
{ | |||
writer.WriteUInt16((ushort)value.SubBusinessType); | |||
writer.WriteUInt16(value.SubBusinessType); | |||
//JT809.Protocol.Enums.JT809BusinessType 映射对应消息特性 | |||
try | |||
{ | |||
// 先写入内容,然后在根据内容反写内容长度 | |||
writer.Skip(4, out int subContentLengthPosition); | |||
value.SubBusinessType.Serialize(ref writer, value.SubBodies, config); | |||
if (value.SubBodies != null) | |||
{ | |||
JT809MessagePackFormatterResolverExtensions.JT809DynamicSerialize( | |||
config.GetMessagePackFormatterByType(value.SubBodies.GetType()), | |||
ref writer, value.SubBodies, | |||
config); | |||
} | |||
writer.WriteInt32Return(writer.GetCurrentPosition() - subContentLengthPosition - 4, subContentLengthPosition); | |||
} | |||
catch(Exception ex) | |||
@@ -20,12 +20,16 @@ namespace JT809.Protocol.Formatters.MessageBodyFormatters | |||
public JT809_0x9300 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) | |||
{ | |||
JT809_0x9300 jT809_0X9300 = new JT809_0x9300(); | |||
jT809_0X9300.SubBusinessType = (JT809SubBusinessType)reader.ReadUInt16(); | |||
jT809_0X9300.SubBusinessType =reader.ReadUInt16(); | |||
jT809_0X9300.DataLength = reader.ReadUInt32(); | |||
//JT809.Protocol.Enums.JT809BusinessType 映射对应消息特性 | |||
try | |||
{ | |||
jT809_0X9300.SubBodies = jT809_0X9300.SubBusinessType.Deserialize(ref reader, config); | |||
Type jT809SubBodiesImplType = config.SubBusinessTypeFactory.GetSubBodiesImplTypeBySubBusinessType(jT809_0X9300.SubBusinessType); | |||
if (jT809SubBodiesImplType != null) | |||
jT809_0X9300.SubBodies = JT809MessagePackFormatterResolverExtensions.JT809DynamicDeserialize( | |||
config.GetMessagePackFormatterByType(jT809SubBodiesImplType), | |||
ref reader, config); | |||
} | |||
catch | |||
{ | |||
@@ -36,13 +40,19 @@ namespace JT809.Protocol.Formatters.MessageBodyFormatters | |||
public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9300 value, IJT809Config config) | |||
{ | |||
writer.WriteUInt16((ushort)value.SubBusinessType); | |||
writer.WriteUInt16(value.SubBusinessType); | |||
//JT809.Protocol.Enums.JT809BusinessType 映射对应消息特性 | |||
try | |||
{ | |||
// 先写入内容,然后在根据内容反写内容长度 | |||
writer.Skip(4, out int subContentLengthPosition); | |||
value.SubBusinessType.Serialize(ref writer, value.SubBodies, config); | |||
if (value.SubBodies != null) | |||
{ | |||
JT809MessagePackFormatterResolverExtensions.JT809DynamicSerialize( | |||
config.GetMessagePackFormatterByType(value.SubBodies.GetType()), | |||
ref writer, value.SubBodies, | |||
config); | |||
} | |||
writer.WriteInt32Return(writer.GetCurrentPosition() - subContentLengthPosition - 4, subContentLengthPosition); | |||
} | |||
catch | |||
@@ -18,7 +18,7 @@ namespace JT809.Protocol.Formatters.SubMessageBodyFormatters | |||
{ | |||
JT809_0x9400_0x9401 jT809_0X9400_0X9401 = new JT809_0x9400_0x9401(); | |||
jT809_0X9400_0X9401.WarnSrc = (JT809WarnSrc)reader.ReadByte(); | |||
jT809_0X9400_0X9401.WarnType = (JT809WarnType)reader.ReadUInt16(); | |||
jT809_0X9400_0X9401.WarnType =reader.ReadUInt16(); | |||
jT809_0X9400_0X9401.WarnTime = reader.ReadUTCDateTime(); | |||
jT809_0X9400_0X9401.SupervisionID = reader.ReadHex(4); | |||
jT809_0X9400_0X9401.SupervisionEndTime = reader.ReadUTCDateTime(); | |||
@@ -0,0 +1,15 @@ | |||
using JT809.Protocol.Interfaces; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
namespace JT809.Protocol | |||
{ | |||
public interface IJT809Builder | |||
{ | |||
IServiceCollection Services { get;} | |||
IJT809Config Config { get; } | |||
} | |||
} |
@@ -0,0 +1,17 @@ | |||
using System; | |||
namespace JT809.Protocol.Interfaces | |||
{ | |||
public interface IJT809BusinessTypeFactory | |||
{ | |||
Type GetBodiesImplTypeByBusinessType(ushort businessType, uint msgGNSSCENTERID); | |||
IJT809BusinessTypeFactory SetMap<TJT809Bodies>(ushort businessType) | |||
where TJT809Bodies : JT809Bodies; | |||
IJT809BusinessTypeFactory SetMap(ushort businessType,Type bodiesImplType); | |||
IJT809BusinessTypeFactory ReplaceMap<TJT809Bodies>(ushort businessType) | |||
where TJT809Bodies : JT809Bodies; | |||
IJT809BusinessTypeFactory CustomSetMap<TJT809Bodies>(ushort businessType, uint msgGNSSCENTERID) | |||
where TJT809Bodies : JT809Bodies; | |||
IJT809BusinessTypeFactory CustomSetMap(ushort businessType,uint msgGNSSCENTERID,Type bodiesImplType); | |||
} | |||
} |
@@ -1,10 +1,12 @@ | |||
using JT809.Protocol.Configs; | |||
using JT808.Protocol.Formatters; | |||
using JT809.Protocol.Configs; | |||
using JT809.Protocol.Interfaces; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Reflection; | |||
using System.Text; | |||
namespace JT809.Protocol.Interfaces | |||
namespace JT809.Protocol | |||
{ | |||
public interface IJT809Config | |||
{ | |||
@@ -35,6 +37,9 @@ namespace JT809.Protocol.Interfaces | |||
/// 加密选项 | |||
/// </summary> | |||
JT809EncryptOptions EncryptOptions { get; set; } | |||
IJT809BusinessTypeFactory BusinessTypeFactory { get; set; } | |||
IJT809SubBusinessTypeFactory SubBusinessTypeFactory { get; set; } | |||
IJT809FormatterFactory FormatterFactory { get; set; } | |||
/// <summary> | |||
/// 全局注册外部程序集 | |||
/// </summary> | |||
@@ -0,0 +1,12 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Reflection; | |||
using System.Text; | |||
namespace JT809.Protocol.Interfaces | |||
{ | |||
public interface IJT809ExternalRegister | |||
{ | |||
void Register(Assembly externalAssembly); | |||
} | |||
} |
@@ -0,0 +1,17 @@ | |||
using System; | |||
namespace JT809.Protocol.Interfaces | |||
{ | |||
public interface IJT809SubBusinessTypeFactory | |||
{ | |||
Type GetSubBodiesImplTypeBySubBusinessType(ushort subBusinessType); | |||
IJT809SubBusinessTypeFactory SetMap<TJT809SubBodies>(ushort subBusinessType) | |||
where TJT809SubBodies : JT809SubBodies; | |||
IJT809SubBusinessTypeFactory SetMap(ushort subBusinessType,Type subBodiesImplType); | |||
IJT809SubBusinessTypeFactory ReplaceMap<TJT809SubBodies>(ushort subBusinessType) | |||
where TJT809SubBodies : JT809SubBodies; | |||
IJT809SubBusinessTypeFactory CustomSetMap<TJT809SubBodies>(ushort subBusinessType) | |||
where TJT809SubBodies : JT809SubBodies; | |||
IJT809SubBusinessTypeFactory CustomSetMap(ushort subBusinessType,Type subBodiesImplType); | |||
} | |||
} |
@@ -1,4 +1,6 @@ | |||
using JT809.Protocol.Configs; | |||
using JT808.Protocol.Formatters; | |||
using JT808.Protocol.Internal; | |||
using JT809.Protocol.Configs; | |||
using JT809.Protocol.Encrypt; | |||
using JT809.Protocol.Internal; | |||
using System; | |||
@@ -13,6 +15,9 @@ namespace JT809.Protocol.Interfaces | |||
{ | |||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); | |||
Encoding = Encoding.GetEncoding("GBK"); | |||
BusinessTypeFactory = new JT809BusinessTypeFactory(); | |||
SubBusinessTypeFactory = new JT809SubBusinessTypeFactory(); | |||
FormatterFactory = new JT809FormatterFactory(); | |||
} | |||
public abstract string ConfigId { get; } | |||
public virtual IJT809MsgSNDistributed MsgSNDistributed { get; set; }= new DefaultMsgSNDistributedImpl(); | |||
@@ -21,8 +26,18 @@ namespace JT809.Protocol.Interfaces | |||
public virtual IJT809Encrypt Encrypt { get; set; } = new JT809EncryptImpl(); | |||
public virtual JT809EncryptOptions EncryptOptions { get; set; } | |||
public virtual JT809HeaderOptions HeaderOptions { get; set; } | |||
public IJT809BusinessTypeFactory BusinessTypeFactory { get ; set ; } | |||
public IJT809SubBusinessTypeFactory SubBusinessTypeFactory { get; set ; } | |||
public IJT809FormatterFactory FormatterFactory { get; set; } | |||
public virtual IJT809Config Register(params Assembly[] externalAssemblies) | |||
{ | |||
if (externalAssemblies != null) | |||
{ | |||
foreach (var easb in externalAssemblies) | |||
{ | |||
FormatterFactory.Register(easb); | |||
} | |||
} | |||
return this; | |||
} | |||
} | |||
@@ -1,136 +0,0 @@ | |||
using JT809.Protocol.Enums; | |||
using JT809.Protocol.Formatters; | |||
using JT809.Protocol.Formatters.MessageBodyFormatters; | |||
using JT809.Protocol.Interfaces; | |||
using JT809.Protocol.MessageBody; | |||
using JT809.Protocol.MessagePack; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
namespace JT809.Protocol.Internal | |||
{ | |||
static class BusinessTypeSerializerFactory | |||
{ | |||
public static JT809Bodies Deserialize(this JT809BusinessType jT809BusinessType, ref JT809MessagePackReader reader,IJT809Config config) | |||
{ | |||
switch (jT809BusinessType) | |||
{ | |||
case JT809BusinessType.主链路登录请求消息: | |||
return JT809_0x1001_Formatter.Instance.Deserialize(ref reader, config); | |||
case JT809BusinessType.主链路登录应答消息: | |||
return JT809_0x1002_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809BusinessType.主链路注销请求消息: | |||
return JT809_0x1003_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809BusinessType.主链路断开通知消息: | |||
return JT809_0x1007_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809BusinessType.下级平台主动关闭链路通知消息: | |||
return JT809_0x1008_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809BusinessType.主链路动态信息交换消息: | |||
return JT809BodiesFormatter<JT809_0x1200>.Instance_0x1200.Deserialize(ref reader,config); | |||
case JT809BusinessType.主链路平台间信息交互消息: | |||
return JT809_0x1300_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809BusinessType.主链路报警信息交互消息: | |||
return JT809BodiesFormatter<JT809_0x1400>.Instance_0x1400.Deserialize(ref reader,config); | |||
case JT809BusinessType.主链路车辆监管消息: | |||
return JT809BodiesFormatter<JT809_0x1500>.Instance_0x1500.Deserialize(ref reader,config); | |||
case JT809BusinessType.主链路静态信息交换消息: | |||
return JT809BodiesFormatter<JT809_0x1600>.Instance_0x1600.Deserialize(ref reader,config); | |||
case JT809BusinessType.从链路连接请求消息: | |||
return JT809_0x9001_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809BusinessType.从链路连接应答消息: | |||
return JT809_0x9002_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809BusinessType.从链路注销请求消息: | |||
return JT809_0x9003_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809BusinessType.从链路断开通知消息: | |||
return JT809_0x9007_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809BusinessType.上级平台主动关闭链路通知消息: | |||
return JT809_0x9008_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809BusinessType.接收定位信息数量通知消息: | |||
return JT809_0x9101_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809BusinessType.从链路动态信息交换消息: | |||
return JT809BodiesFormatter<JT809_0x9200>.Instance_0x9200.Deserialize(ref reader,config); | |||
case JT809BusinessType.从链路平台间信息交互消息: | |||
return JT809_0x9300_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809BusinessType.从链路报警信息交互消息: | |||
return JT809BodiesFormatter<JT809_0x9400>.Instance_0x9400.Deserialize(ref reader,config); | |||
case JT809BusinessType.从链路车辆监管消息: | |||
return JT809BodiesFormatter<JT809_0x9500>.Instance_0x9500.Deserialize(ref reader,config); | |||
case JT809BusinessType.从链路静态信息交换消息: | |||
return JT809BodiesFormatter<JT809_0x9600>.Instance_0x9600.Deserialize(ref reader,config); | |||
default: | |||
return default; | |||
} | |||
} | |||
public static void Serialize(this JT809BusinessType jT809BusinessType, ref JT809MessagePackWriter writer, object value,IJT809Config config) | |||
{ | |||
switch (jT809BusinessType) | |||
{ | |||
case JT809BusinessType.主链路登录请求消息: | |||
JT809_0x1001_Formatter.Instance.Serialize(ref writer, (JT809_0x1001)value, config); | |||
break; | |||
case JT809BusinessType.主链路登录应答消息: | |||
JT809_0x1002_Formatter.Instance.Serialize(ref writer, (JT809_0x1002)value, config); | |||
break; | |||
case JT809BusinessType.主链路注销请求消息: | |||
JT809_0x1003_Formatter.Instance.Serialize(ref writer, (JT809_0x1003)value, config); | |||
break; | |||
case JT809BusinessType.主链路断开通知消息: | |||
JT809_0x1007_Formatter.Instance.Serialize(ref writer, (JT809_0x1007)value, config); | |||
break; | |||
case JT809BusinessType.下级平台主动关闭链路通知消息: | |||
JT809_0x1008_Formatter.Instance.Serialize(ref writer, (JT809_0x1008)value, config); | |||
break; | |||
case JT809BusinessType.主链路动态信息交换消息: | |||
JT809BodiesFormatter<JT809_0x1200>.Instance_0x1200.Serialize(ref writer, (JT809_0x1200)value, config); | |||
break; | |||
case JT809BusinessType.主链路平台间信息交互消息: | |||
JT809_0x1300_Formatter.Instance.Serialize(ref writer, (JT809_0x1300)value, config); | |||
break; | |||
case JT809BusinessType.主链路报警信息交互消息: | |||
JT809BodiesFormatter<JT809_0x1400>.Instance_0x1400.Serialize(ref writer, (JT809_0x1400)value, config); | |||
break; | |||
case JT809BusinessType.主链路车辆监管消息: | |||
JT809BodiesFormatter<JT809_0x1500>.Instance_0x1500.Serialize(ref writer,(JT809_0x1500) value, config); | |||
break; | |||
case JT809BusinessType.主链路静态信息交换消息: | |||
JT809BodiesFormatter<JT809_0x1600>.Instance_0x1600.Serialize(ref writer,(JT809_0x1600) value, config); | |||
break; | |||
case JT809BusinessType.从链路连接请求消息: | |||
JT809_0x9001_Formatter.Instance.Serialize(ref writer, (JT809_0x9001)value, config); | |||
break; | |||
case JT809BusinessType.从链路连接应答消息: | |||
JT809_0x9002_Formatter.Instance.Serialize(ref writer, (JT809_0x9002)value, config); | |||
break; | |||
case JT809BusinessType.从链路注销请求消息: | |||
JT809_0x9003_Formatter.Instance.Serialize(ref writer, (JT809_0x9003)value, config); | |||
break; | |||
case JT809BusinessType.从链路断开通知消息: | |||
JT809_0x9007_Formatter.Instance.Serialize(ref writer, (JT809_0x9007)value, config); | |||
break; | |||
case JT809BusinessType.上级平台主动关闭链路通知消息: | |||
JT809_0x9008_Formatter.Instance.Serialize(ref writer, (JT809_0x9008)value, config); | |||
break; | |||
case JT809BusinessType.接收定位信息数量通知消息: | |||
JT809_0x9101_Formatter.Instance.Serialize(ref writer, (JT809_0x9101)value, config); | |||
break; | |||
case JT809BusinessType.从链路动态信息交换消息: | |||
JT809BodiesFormatter<JT809_0x9200>.Instance_0x9200.Serialize(ref writer, (JT809_0x9200)value, config); | |||
break; | |||
case JT809BusinessType.从链路平台间信息交互消息: | |||
JT809_0x9300_Formatter.Instance.Serialize(ref writer, (JT809_0x9300)value, config); | |||
break; | |||
case JT809BusinessType.从链路报警信息交互消息: | |||
JT809BodiesFormatter<JT809_0x9400>.Instance_0x9400.Serialize(ref writer, (JT809_0x9400)value, config); | |||
break; | |||
case JT809BusinessType.从链路车辆监管消息: | |||
JT809BodiesFormatter<JT809_0x9500>.Instance_0x9500.Serialize(ref writer, (JT809_0x9500)value, config); | |||
break; | |||
case JT809BusinessType.从链路静态信息交换消息: | |||
JT809BodiesFormatter<JT809_0x9600>.Instance_0x9600.Serialize(ref writer, (JT809_0x9600)value, config); | |||
break; | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,21 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using JT809.Protocol.Interfaces; | |||
using Microsoft.Extensions.DependencyInjection; | |||
namespace JT809.Protocol.Internal | |||
{ | |||
class DefaultBuilder : IJT809Builder | |||
{ | |||
public IServiceCollection Services { get; } | |||
public IJT809Config Config { get; } | |||
public DefaultBuilder(IServiceCollection services, IJT809Config config) | |||
{ | |||
Services = services; | |||
Config = config; | |||
} | |||
} | |||
} |
@@ -0,0 +1,127 @@ | |||
using JT809.Protocol; | |||
using JT809.Protocol.Attributes; | |||
using JT809.Protocol.Enums; | |||
using JT809.Protocol.Extensions; | |||
using JT809.Protocol.Interfaces; | |||
using System; | |||
using System.Collections.Generic; | |||
namespace JT808.Protocol.Internal | |||
{ | |||
internal class JT809BusinessTypeFactory : IJT809BusinessTypeFactory | |||
{ | |||
private readonly Dictionary<ushort, Type> map; | |||
private readonly Dictionary<uint, Dictionary<ushort, Type>> customMap; | |||
internal JT809BusinessTypeFactory() | |||
{ | |||
map = new Dictionary<ushort, Type>(); | |||
customMap = new Dictionary<uint, Dictionary<ushort, Type>>(); | |||
InitMap(); | |||
} | |||
private void InitMap() | |||
{ | |||
foreach (var item in Enum.GetNames(typeof(JT809BusinessType))) | |||
{ | |||
JT809BusinessType businessType = item.ToEnum<JT809BusinessType>(); | |||
if (!map.ContainsKey((ushort)businessType)) | |||
{ | |||
JT809BodiesTypeAttribute jT809BodiesTypeAttribute = businessType.GetAttribute<JT809BodiesTypeAttribute>(); | |||
if (jT809BodiesTypeAttribute != null) | |||
{ | |||
map.Add((ushort)businessType, jT809BodiesTypeAttribute.JT809BodiesType); | |||
} | |||
} | |||
} | |||
} | |||
public Type GetBodiesImplTypeByBusinessType(ushort businessType, uint msgGNSSCENTERID) | |||
{ | |||
//判断有无自定义消息Id类型 | |||
if (customMap.TryGetValue(msgGNSSCENTERID, out var dict)) | |||
{ | |||
if (dict != null) | |||
{ | |||
return dict.TryGetValue(businessType, out Type bodiesImptType)? bodiesImptType:null; | |||
} | |||
} | |||
return map.TryGetValue(businessType, out Type type) ? type : null; | |||
} | |||
public IJT809BusinessTypeFactory SetMap<TJT809Bodies>(ushort businessType) | |||
where TJT809Bodies : JT809Bodies | |||
{ | |||
if (!map.ContainsKey(businessType)) | |||
{ | |||
map.Add(businessType, typeof(TJT809Bodies)); | |||
} | |||
return this; | |||
} | |||
public IJT809BusinessTypeFactory SetMap(ushort businessType, Type bodiesImplType) | |||
{ | |||
if (!map.ContainsKey(businessType)) | |||
{ | |||
map.Add(businessType, bodiesImplType); | |||
} | |||
return this; | |||
} | |||
public IJT809BusinessTypeFactory ReplaceMap<TJT809Bodies>(ushort businessType) where TJT809Bodies : JT809Bodies | |||
{ | |||
if (!map.ContainsKey(businessType)) | |||
{ | |||
map.Add(businessType, typeof(TJT809Bodies)); | |||
} | |||
else | |||
{ | |||
map[businessType] = typeof(TJT809Bodies); | |||
} | |||
return this; | |||
} | |||
public IJT809BusinessTypeFactory CustomSetMap<TJT809Bodies>(ushort businessType, uint msgGNSSCENTERID) where TJT809Bodies : JT809Bodies | |||
{ | |||
if (!customMap.TryGetValue(msgGNSSCENTERID, out var dict)) | |||
{ | |||
if (dict == null) | |||
{ | |||
Dictionary<ushort, Type> tmp = new Dictionary<ushort, Type>(); | |||
tmp.Add(businessType, typeof(TJT809Bodies)); | |||
customMap.Add(businessType, tmp); | |||
} | |||
else | |||
{ | |||
if (!dict.ContainsKey(businessType)) | |||
{ | |||
dict.Add(businessType, typeof(TJT809Bodies)); | |||
} | |||
} | |||
} | |||
return this; | |||
} | |||
public IJT809BusinessTypeFactory CustomSetMap(ushort businessType, uint msgGNSSCENTERID, Type bodiesImplType) | |||
{ | |||
if (!customMap.TryGetValue(msgGNSSCENTERID, out var dict)) | |||
{ | |||
if (dict == null) | |||
{ | |||
Dictionary<ushort, Type> tmp = new Dictionary<ushort, Type>(); | |||
tmp.Add(businessType, bodiesImplType); | |||
customMap.Add(businessType, tmp); | |||
} | |||
else | |||
{ | |||
if (!dict.ContainsKey(businessType)) | |||
{ | |||
dict.Add(businessType, bodiesImplType); | |||
} | |||
} | |||
} | |||
return this; | |||
} | |||
} | |||
} |
@@ -0,0 +1,75 @@ | |||
using JT808.Protocol.Formatters; | |||
using JT809.Protocol.Attributes; | |||
using JT809.Protocol.Enums; | |||
using JT809.Protocol.Exceptions; | |||
using JT809.Protocol.Formatters; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Diagnostics; | |||
using System.Linq; | |||
using System.Reflection; | |||
using System.Text; | |||
namespace JT809.Protocol.Internal | |||
{ | |||
class JT809FormatterFactory : IJT809FormatterFactory | |||
{ | |||
public Dictionary<Guid, object> FormatterDict { get; } | |||
public JT809FormatterFactory() | |||
{ | |||
FormatterDict = new Dictionary<Guid, object>(); | |||
Init(Assembly.GetExecutingAssembly()); | |||
} | |||
private void Init(Assembly assembly) | |||
{ | |||
foreach (var type in assembly.GetTypes()) | |||
{ | |||
var attr = type.GetCustomAttribute<JT809FormatterAttribute>(); | |||
if (attr != null) | |||
{ | |||
if (!FormatterDict.ContainsKey(type.GUID)) | |||
{ | |||
FormatterDict.Add(type.GUID, Activator.CreateInstance(attr.FormatterType)); | |||
} | |||
} | |||
} | |||
} | |||
public IJT809FormatterFactory SetMap<TJT809Bodies>() where TJT809Bodies : JT809Bodies | |||
{ | |||
Type bodiesType = typeof(TJT809Bodies); | |||
var attr = bodiesType.GetTypeInfo().GetCustomAttribute<JT809FormatterAttribute>(); | |||
if (attr == null) | |||
{ | |||
throw new JT809Exception(JT809ErrorCode.GetFormatterAttributeError, bodiesType.FullName); | |||
} | |||
if (!FormatterDict.ContainsKey(bodiesType.GUID)) | |||
{ | |||
FormatterDict.Add(bodiesType.GUID, Activator.CreateInstance(attr.FormatterType)); | |||
} | |||
return this; | |||
} | |||
public void Register(Assembly externalAssembly) | |||
{ | |||
Init(externalAssembly); | |||
} | |||
public IJT809FormatterFactory SetSubMap<TJT809SubBodies>() where TJT809SubBodies : JT809SubBodies | |||
{ | |||
Type bodiesType = typeof(TJT809SubBodies); | |||
var attr = bodiesType.GetTypeInfo().GetCustomAttribute<JT809FormatterAttribute>(); | |||
if (attr == null) | |||
{ | |||
throw new JT809Exception(JT809ErrorCode.GetFormatterAttributeError, bodiesType.FullName); | |||
} | |||
if (!FormatterDict.ContainsKey(bodiesType.GUID)) | |||
{ | |||
FormatterDict.Add(bodiesType.GUID, Activator.CreateInstance(attr.FormatterType)); | |||
} | |||
return this; | |||
} | |||
} | |||
} |
@@ -0,0 +1,95 @@ | |||
using JT809.Protocol; | |||
using JT809.Protocol.Attributes; | |||
using JT809.Protocol.Enums; | |||
using JT809.Protocol.Extensions; | |||
using JT809.Protocol.Interfaces; | |||
using System; | |||
using System.Collections.Generic; | |||
namespace JT808.Protocol.Internal | |||
{ | |||
internal class JT809SubBusinessTypeFactory : IJT809SubBusinessTypeFactory | |||
{ | |||
private readonly Dictionary<ushort, Type> map; | |||
internal JT809SubBusinessTypeFactory() | |||
{ | |||
map = new Dictionary<ushort, Type>(); | |||
InitMap(); | |||
} | |||
private void InitMap() | |||
{ | |||
foreach (var item in Enum.GetNames(typeof(JT809SubBusinessType))) | |||
{ | |||
JT809SubBusinessType subBusinessType = item.ToEnum<JT809SubBusinessType>(); | |||
if (!map.ContainsKey((ushort)subBusinessType)) | |||
{ | |||
JT809BodiesTypeAttribute jT809BodiesTypeAttribute = subBusinessType.GetAttribute<JT809BodiesTypeAttribute>(); | |||
if (jT809BodiesTypeAttribute != null) | |||
{ | |||
map.Add((ushort)subBusinessType, jT809BodiesTypeAttribute.JT809BodiesType); | |||
} | |||
} | |||
} | |||
} | |||
public Type GetSubBodiesImplTypeBySubBusinessType(ushort subBusinessType) | |||
{ | |||
return map.TryGetValue(subBusinessType, out Type type) ? type : null; | |||
} | |||
public IJT809SubBusinessTypeFactory SetMap<TJT809SubBodies>(ushort subBusinessType) | |||
where TJT809SubBodies : JT809SubBodies | |||
{ | |||
if (!map.ContainsKey(subBusinessType)) | |||
{ | |||
map.Add(subBusinessType, typeof(TJT809SubBodies)); | |||
} | |||
return this; | |||
} | |||
public IJT809SubBusinessTypeFactory SetMap(ushort subBusinessType, Type subBodiesImplType) | |||
{ | |||
if (!map.ContainsKey(subBusinessType)) | |||
{ | |||
map.Add(subBusinessType, subBodiesImplType); | |||
} | |||
return this; | |||
} | |||
public IJT809SubBusinessTypeFactory ReplaceMap<TJT809SubBodies>(ushort subBusinessType) where TJT809SubBodies : JT809SubBodies | |||
{ | |||
if (!map.ContainsKey(subBusinessType)) | |||
{ | |||
map.Add(subBusinessType, typeof(TJT809SubBodies)); | |||
} | |||
else | |||
{ | |||
map[subBusinessType] = typeof(TJT809SubBodies); | |||
} | |||
return this; | |||
} | |||
public IJT809SubBusinessTypeFactory CustomSetMap<TJT809SubBodies>(ushort subBusinessType) where TJT809SubBodies : JT809SubBodies | |||
{ | |||
if (!map.ContainsKey(subBusinessType)) | |||
{ | |||
map.Add(subBusinessType, typeof(TJT809SubBodies)); | |||
} | |||
else | |||
{ | |||
map[subBusinessType] = typeof(TJT809SubBodies); | |||
} | |||
return this; | |||
} | |||
public IJT809SubBusinessTypeFactory CustomSetMap(ushort subBusinessType, Type subBodiesImplType) | |||
{ | |||
if (!map.ContainsKey(subBusinessType)) | |||
{ | |||
map.Add(subBusinessType, subBodiesImplType); | |||
} | |||
return this; | |||
} | |||
} | |||
} |
@@ -1,218 +0,0 @@ | |||
using JT809.Protocol.Enums; | |||
using JT809.Protocol.Formatters.SubMessageBodyFormatters; | |||
using JT809.Protocol.Interfaces; | |||
using JT809.Protocol.MessagePack; | |||
using JT809.Protocol.SubMessageBody; | |||
using System; | |||
namespace JT809.Protocol.Internal | |||
{ | |||
static class SubBodiesTypeSerializerFactory | |||
{ | |||
public static JT809SubBodies Deserialize(this JT809SubBusinessType jT809SubBusinessType, ref JT809MessagePackReader reader, IJT809Config config) | |||
{ | |||
switch (jT809SubBusinessType) | |||
{ | |||
case JT809SubBusinessType.上传车辆注册信息: | |||
return JT809_0x1200_0x1201_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809SubBusinessType.实时上传车辆定位信息: | |||
return JT809_0x1200_0x1202_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809SubBusinessType.车辆定位信息自动补报: | |||
return JT809_0x1200_0x1203_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809SubBusinessType.申请交换指定车辆定位信息请求: | |||
return JT809_0x1200_0x1207_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809SubBusinessType.补发车辆定位信息请求: | |||
return JT809_0x1200_0x1209_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809SubBusinessType.上报车辆驾驶员身份识别信息应答: | |||
return JT809_0x1200_0x120A_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809SubBusinessType.上报车辆电子运单应答: | |||
return JT809_0x1200_0x120B_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809SubBusinessType.主动上报驾驶员身份信息: | |||
return JT809_0x1200_0x120C_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809SubBusinessType.主动上报车辆电子运单信息: | |||
return JT809_0x1200_0x120D_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809SubBusinessType.平台查岗应答: | |||
return JT809_0x1300_0x1301_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809SubBusinessType.下发平台间报文应答: | |||
return JT809_0x1300_0x1302_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809SubBusinessType.报警督办应答: | |||
return JT809_0x1400_0x1401_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809SubBusinessType.上报报警信息: | |||
return JT809_0x1400_0x1402_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809SubBusinessType.主动上报报警处理结果信息: | |||
return JT809_0x1400_0x1403_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809SubBusinessType.车辆单向监听应答: | |||
return JT809_0x1500_0x1501_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809SubBusinessType.车辆拍照应答: | |||
return JT809_0x1500_0x1502_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809SubBusinessType.下发车辆报文应答: | |||
return JT809_0x1500_0x1503_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809SubBusinessType.上报车辆行驶记录应答: | |||
return JT809_0x1500_0x1504_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809SubBusinessType.车辆应急接入监管平台应答消息: | |||
return JT809_0x1500_0x1505_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809SubBusinessType.补报车辆静态信息应答: | |||
return JT809_0x1600_0x1601_Formatter.Instance.Deserialize(ref reader,config); | |||
case JT809SubBusinessType.交换车辆定位信息: | |||
return JT809_0x9200_0x9202_Formatter.Instance.Deserialize(ref reader, config); | |||
case JT809SubBusinessType.车辆定位信息交换补发: | |||
return JT809_0x9200_0x9203_Formatter.Instance.Deserialize(ref reader, config); | |||
case JT809SubBusinessType.交换车辆静态信息: | |||
return JT809_0x9200_0x9204_Formatter.Instance.Deserialize(ref reader, config); | |||
case JT809SubBusinessType.启动车辆定位信息交换请求: | |||
return JT809_0x9200_0x9205_Formatter.Instance.Deserialize(ref reader, config); | |||
case JT809SubBusinessType.结束车辆定位信息交换请求: | |||
return JT809_0x9200_0x9206_Formatter.Instance.Deserialize(ref reader, config); | |||
case JT809SubBusinessType.申请交换指定车辆定位信息应答: | |||
return JT809_0x9200_0x9207_Formatter.Instance.Deserialize(ref reader, config); | |||
case JT809SubBusinessType.取消交换指定车辆定位信息应答: | |||
return JT809_0x9200_0x9208_Formatter.Instance.Deserialize(ref reader, config); | |||
case JT809SubBusinessType.补发车辆定位信息应答: | |||
return JT809_0x9200_0x9209_Formatter.Instance.Deserialize(ref reader, config); | |||
case JT809SubBusinessType.平台查岗请求: | |||
return JT809_0x9300_0x9301_Formatter.Instance.Deserialize(ref reader, config); | |||
case JT809SubBusinessType.下发平台间报文请求: | |||
return JT809_0x9300_0x9302_Formatter.Instance.Deserialize(ref reader, config); | |||
case JT809SubBusinessType.报警督办请求: | |||
return JT809_0x9400_0x9401_Formatter.Instance.Deserialize(ref reader, config); | |||
case JT809SubBusinessType.报警预警: | |||
return JT809_0x9400_0x9402_Formatter.Instance.Deserialize(ref reader, config); | |||
case JT809SubBusinessType.实时交换报警信息: | |||
return JT809_0x9400_0x9403_Formatter.Instance.Deserialize(ref reader, config); | |||
case JT809SubBusinessType.车辆单向监听请求: | |||
return JT809_0x9500_0x9501_Formatter.Instance.Deserialize(ref reader, config); | |||
case JT809SubBusinessType.车辆拍照请求: | |||
return JT809_0x9500_0x9502_Formatter.Instance.Deserialize(ref reader, config); | |||
case JT809SubBusinessType.下发车辆报文请求: | |||
return JT809_0x9500_0x9503_Formatter.Instance.Deserialize(ref reader, config); | |||
case JT809SubBusinessType.上报车辆行驶记录请求: | |||
return JT809_0x9500_0x9504_Formatter.Instance.Deserialize(ref reader, config); | |||
case JT809SubBusinessType.车辆应急接入监管平台请求消息: | |||
return JT809_0x9500_0x9505_Formatter.Instance.Deserialize(ref reader, config); | |||
default: | |||
return default; | |||
} | |||
} | |||
public static void Serialize(this JT809SubBusinessType jT809SubBusinessType, ref JT809MessagePackWriter writer, object value, IJT809Config config) | |||
{ | |||
switch (jT809SubBusinessType) | |||
{ | |||
case JT809SubBusinessType.上传车辆注册信息: | |||
JT809_0x1200_0x1201_Formatter.Instance.Serialize(ref writer, (JT809_0x1200_0x1201)value, config); | |||
break; | |||
case JT809SubBusinessType.实时上传车辆定位信息: | |||
JT809_0x1200_0x1202_Formatter.Instance.Serialize(ref writer,(JT809_0x1200_0x1202)value, config); | |||
break; | |||
case JT809SubBusinessType.车辆定位信息自动补报: | |||
JT809_0x1200_0x1203_Formatter.Instance.Serialize(ref writer,(JT809_0x1200_0x1203)value, config); | |||
break; | |||
case JT809SubBusinessType.申请交换指定车辆定位信息请求: | |||
JT809_0x1200_0x1207_Formatter.Instance.Serialize(ref writer,(JT809_0x1200_0x1207)value, config); | |||
break; | |||
case JT809SubBusinessType.补发车辆定位信息请求: | |||
JT809_0x1200_0x1209_Formatter.Instance.Serialize(ref writer,(JT809_0x1200_0x1209)value, config); | |||
break; | |||
case JT809SubBusinessType.上报车辆驾驶员身份识别信息应答: | |||
JT809_0x1200_0x120A_Formatter.Instance.Serialize(ref writer,(JT809_0x1200_0x120A)value, config); | |||
break; | |||
case JT809SubBusinessType.上报车辆电子运单应答: | |||
JT809_0x1200_0x120B_Formatter.Instance.Serialize(ref writer,(JT809_0x1200_0x120B)value, config); | |||
break; | |||
case JT809SubBusinessType.主动上报驾驶员身份信息: | |||
JT809_0x1200_0x120C_Formatter.Instance.Serialize(ref writer, (JT809_0x1200_0x120C)value, config); | |||
break; | |||
case JT809SubBusinessType.主动上报车辆电子运单信息: | |||
JT809_0x1200_0x120D_Formatter.Instance.Serialize(ref writer,(JT809_0x1200_0x120D)value, config); | |||
break; | |||
case JT809SubBusinessType.平台查岗应答: | |||
JT809_0x1300_0x1301_Formatter.Instance.Serialize(ref writer, (JT809_0x1300_0x1301)value, config); | |||
break; | |||
case JT809SubBusinessType.下发平台间报文应答: | |||
JT809_0x1300_0x1302_Formatter.Instance.Serialize(ref writer, (JT809_0x1300_0x1302)value, config); | |||
break; | |||
case JT809SubBusinessType.报警督办应答: | |||
JT809_0x1400_0x1401_Formatter.Instance.Serialize(ref writer, (JT809_0x1400_0x1401)value, config); | |||
break; | |||
case JT809SubBusinessType.上报报警信息: | |||
JT809_0x1400_0x1402_Formatter.Instance.Serialize(ref writer, (JT809_0x1400_0x1402)value, config); | |||
break; | |||
case JT809SubBusinessType.主动上报报警处理结果信息: | |||
JT809_0x1400_0x1403_Formatter.Instance.Serialize(ref writer, (JT809_0x1400_0x1403)value, config); | |||
break; | |||
case JT809SubBusinessType.车辆单向监听应答: | |||
JT809_0x1500_0x1501_Formatter.Instance.Serialize(ref writer, (JT809_0x1500_0x1501)value, config); | |||
break; | |||
case JT809SubBusinessType.车辆拍照应答: | |||
JT809_0x1500_0x1502_Formatter.Instance.Serialize(ref writer, (JT809_0x1500_0x1502)value, config); | |||
break; | |||
case JT809SubBusinessType.下发车辆报文应答: | |||
JT809_0x1500_0x1503_Formatter.Instance.Serialize(ref writer, (JT809_0x1500_0x1503)value, config); | |||
break; | |||
case JT809SubBusinessType.上报车辆行驶记录应答: | |||
JT809_0x1500_0x1504_Formatter.Instance.Serialize(ref writer,(JT809_0x1500_0x1504) value, config); | |||
break; | |||
case JT809SubBusinessType.车辆应急接入监管平台应答消息: | |||
JT809_0x1500_0x1505_Formatter.Instance.Serialize(ref writer, (JT809_0x1500_0x1505)value, config); | |||
break; | |||
case JT809SubBusinessType.补报车辆静态信息应答: | |||
JT809_0x1600_0x1601_Formatter.Instance.Serialize(ref writer, (JT809_0x1600_0x1601)value, config); | |||
break; | |||
case JT809SubBusinessType.交换车辆定位信息: | |||
JT809_0x9200_0x9202_Formatter.Instance.Serialize(ref writer, (JT809_0x9200_0x9202)value, config); | |||
break; | |||
case JT809SubBusinessType.车辆定位信息交换补发: | |||
JT809_0x9200_0x9203_Formatter.Instance.Serialize(ref writer, (JT809_0x9200_0x9203)value, config); | |||
break; | |||
case JT809SubBusinessType.交换车辆静态信息: | |||
JT809_0x9200_0x9204_Formatter.Instance.Serialize(ref writer, (JT809_0x9200_0x9204)value, config); | |||
break; | |||
case JT809SubBusinessType.启动车辆定位信息交换请求: | |||
JT809_0x9200_0x9205_Formatter.Instance.Serialize(ref writer, (JT809_0x9200_0x9205)value, config); | |||
break; | |||
case JT809SubBusinessType.结束车辆定位信息交换请求: | |||
JT809_0x9200_0x9206_Formatter.Instance.Serialize(ref writer, (JT809_0x9200_0x9206)value, config); | |||
break; | |||
case JT809SubBusinessType.申请交换指定车辆定位信息应答: | |||
JT809_0x9200_0x9207_Formatter.Instance.Serialize(ref writer, (JT809_0x9200_0x9207)value, config); | |||
break; | |||
case JT809SubBusinessType.取消交换指定车辆定位信息应答: | |||
JT809_0x9200_0x9208_Formatter.Instance.Serialize(ref writer, (JT809_0x9200_0x9208)value, config); | |||
break; | |||
case JT809SubBusinessType.补发车辆定位信息应答: | |||
JT809_0x9200_0x9209_Formatter.Instance.Serialize(ref writer, (JT809_0x9200_0x9209)value, config); | |||
break; | |||
case JT809SubBusinessType.平台查岗请求: | |||
JT809_0x9300_0x9301_Formatter.Instance.Serialize(ref writer, (JT809_0x9300_0x9301)value, config); | |||
break; | |||
case JT809SubBusinessType.下发平台间报文请求: | |||
JT809_0x9300_0x9302_Formatter.Instance.Serialize(ref writer, (JT809_0x9300_0x9302)value, config); | |||
break; | |||
case JT809SubBusinessType.报警督办请求: | |||
JT809_0x9400_0x9401_Formatter.Instance.Serialize(ref writer, (JT809_0x9400_0x9401)value, config); | |||
break; | |||
case JT809SubBusinessType.报警预警: | |||
JT809_0x9400_0x9402_Formatter.Instance.Serialize(ref writer, (JT809_0x9400_0x9402)value, config); | |||
break; | |||
case JT809SubBusinessType.实时交换报警信息: | |||
JT809_0x9400_0x9403_Formatter.Instance.Serialize(ref writer, (JT809_0x9400_0x9403)value, config); | |||
break; | |||
case JT809SubBusinessType.车辆单向监听请求: | |||
JT809_0x9500_0x9501_Formatter.Instance.Serialize(ref writer, (JT809_0x9500_0x9501)value, config); | |||
break; | |||
case JT809SubBusinessType.车辆拍照请求: | |||
JT809_0x9500_0x9502_Formatter.Instance.Serialize(ref writer, (JT809_0x9500_0x9502)value, config); | |||
break; | |||
case JT809SubBusinessType.下发车辆报文请求: | |||
JT809_0x9500_0x9503_Formatter.Instance.Serialize(ref writer, (JT809_0x9500_0x9503)value, config); | |||
break; | |||
case JT809SubBusinessType.上报车辆行驶记录请求: | |||
JT809_0x9500_0x9504_Formatter.Instance.Serialize(ref writer, (JT809_0x9500_0x9504)value, config); | |||
break; | |||
case JT809SubBusinessType.车辆应急接入监管平台请求消息: | |||
JT809_0x9500_0x9505_Formatter.Instance.Serialize(ref writer, (JT809_0x9500_0x9505)value, config); | |||
break; | |||
} | |||
} | |||
} | |||
} |
@@ -9,12 +9,13 @@ | |||
<Product>JT809</Product> | |||
<Description>JT809协议、GB809协议、道路运输车辆卫星定位系统平台数据交换协议</Description> | |||
<PackageReleaseNotes>JT809协议、GB809协议、道路运输车辆卫星定位系统平台数据交换协议</PackageReleaseNotes> | |||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance> | |||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> | |||
<RepositoryUrl>https://github.com/SmallChi/JT809</RepositoryUrl> | |||
<PackageProjectUrl>https://github.com/SmallChi/JT809</PackageProjectUrl> | |||
<license>https://github.com/SmallChi/JT809/blob/master/LICENSE</license> | |||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | |||
<Version>2.0.0</Version> | |||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild> | |||
<Version>2.1.0</Version> | |||
<PackageLicenseFile>LICENSE</PackageLicenseFile> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | |||
@@ -42,6 +43,10 @@ | |||
<None Remove="Enums\**" /> | |||
<None Remove="Escape\**" /> | |||
<None Remove="ProtocolPacket\**" /> | |||
<None Include="..\..\LICENSE"> | |||
<Pack>True</Pack> | |||
<PackagePath></PackagePath> | |||
</None> | |||
</ItemGroup> | |||
<ItemGroup> | |||
@@ -99,6 +104,7 @@ | |||
<ItemGroup> | |||
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" /> | |||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.2.0" /> | |||
<PackageReference Include="System.Buffers" Version="4.5.0" /> | |||
<PackageReference Include="System.Dynamic.Runtime" Version="4.3.0" /> | |||
<PackageReference Include="System.Memory" Version="4.5.3" /> | |||
@@ -0,0 +1,26 @@ | |||
using JT809.Protocol.Interfaces; | |||
using JT809.Protocol.Internal; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
namespace JT809.Protocol | |||
{ | |||
public static class JT809DependencyInjectionExtensions | |||
{ | |||
public static IJT809Builder AddJT809Configure(this IServiceCollection services, IJT809Config jT809Config) | |||
{ | |||
services.AddSingleton(jT809Config.GetType(), jT809Config); | |||
services.AddSingleton(jT809Config); | |||
return new DefaultBuilder(services, jT809Config); | |||
} | |||
public static IJT809Builder AddJT809Configure(this IServiceCollection services) | |||
{ | |||
DefaultGlobalConfig config = new DefaultGlobalConfig(); | |||
services.AddSingleton<IJT809Config>(config); | |||
return new DefaultBuilder(services, config); | |||
} | |||
} | |||
} |
@@ -23,7 +23,7 @@ namespace JT809.Protocol | |||
/// <summary> | |||
/// 子业务类型标识 | |||
/// </summary> | |||
public JT809SubBusinessType SubBusinessType { get; set; } = JT809SubBusinessType.None; | |||
public ushort SubBusinessType { get; set; } | |||
/// <summary> | |||
/// 后续数据长度 | |||
/// </summary> | |||
@@ -29,7 +29,7 @@ namespace JT809.Protocol | |||
/// <summary> | |||
/// 业务数据类型 | |||
/// </summary> | |||
public JT809BusinessType BusinessType { get; set; } | |||
public ushort BusinessType { get; set; } | |||
/// <summary> | |||
/// 下级平台接入码,上级平台给下级平台分配唯一标识码。 | |||
/// </summary> | |||
@@ -22,7 +22,7 @@ namespace JT809.Protocol.SubMessageBody | |||
/// <summary> | |||
/// 报警类型 | |||
/// </summary> | |||
public JT809WarnType WarnType { get; set; } | |||
public ushort WarnType { get; set; } | |||
/// <summary> | |||
/// 报警时间UTCDateTime | |||
/// </summary> | |||