@@ -1,27 +0,0 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<OutputType>Exe</OutputType> | |||
<TargetFramework>netcoreapp2.2</TargetFramework> | |||
<LangVersion>latest</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="..\JT808.Protocol\JT808.Protocol.csproj" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<None Update="appsettings.json"> | |||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||
</None> | |||
</ItemGroup> | |||
</Project> |
@@ -1,30 +0,0 @@ | |||
using JT808.Protocol.Formatters; | |||
using JT808.Protocol.Interfaces; | |||
using JT808.Protocol.MessagePack; | |||
using System; | |||
namespace JT808.Protocol.Extensions.DependencyInjection.Test.JT808LocationAttach | |||
{ | |||
public class JT808_0x0200_0x06Formatter : IJT808MessagePackFormatter<JT808LocationAttachImpl0x06> | |||
{ | |||
public JT808LocationAttachImpl0x06 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) | |||
{ | |||
JT808LocationAttachImpl0x06 jT808LocationAttachImpl0x06 = new JT808LocationAttachImpl0x06() { }; | |||
jT808LocationAttachImpl0x06.AttachInfoId = reader.ReadByte(); | |||
jT808LocationAttachImpl0x06.AttachInfoLength = reader.ReadByte(); | |||
jT808LocationAttachImpl0x06.Age = reader.ReadInt32(); | |||
jT808LocationAttachImpl0x06.Gender = reader.ReadByte(); | |||
jT808LocationAttachImpl0x06.UserName = reader.ReadRemainStringContent(); | |||
return jT808LocationAttachImpl0x06; | |||
} | |||
public void Serialize(ref JT808MessagePackWriter writer, JT808LocationAttachImpl0x06 value, IJT808Config config) | |||
{ | |||
writer.WriteByte(value.AttachInfoId); | |||
writer.WriteByte( value.AttachInfoLength); | |||
writer.WriteInt32(value.Age); | |||
writer.WriteByte(value.Gender); | |||
writer.WriteString(value.UserName); | |||
} | |||
} | |||
} |
@@ -1,28 +0,0 @@ | |||
using JT808.Protocol.Extensions.DependencyInjection.Test.JT808_0x0701BodiesImpl; | |||
using JT808.Protocol.Formatters; | |||
using JT808.Protocol.Interfaces; | |||
using JT808.Protocol.MessagePack; | |||
using System; | |||
namespace JT808.Protocol.Extensions.DependencyInjection.Test.JT808Formatters | |||
{ | |||
public class JT808_0x0701TestBodiesImplFormatter : IJT808MessagePackFormatter<JT808_0x0701TestBodiesImpl> | |||
{ | |||
public JT808_0x0701TestBodiesImpl Deserialize(ref JT808MessagePackReader reader, IJT808Config config) | |||
{ | |||
JT808_0x0701TestBodiesImpl jT808_0X0701TestBodiesImpl = new JT808_0x0701TestBodiesImpl(); | |||
jT808_0X0701TestBodiesImpl.Id = reader.ReadUInt32(); | |||
jT808_0X0701TestBodiesImpl.UserNameLength = reader.ReadUInt16(); | |||
return jT808_0X0701TestBodiesImpl; | |||
} | |||
public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0701TestBodiesImpl value, IJT808Config config) | |||
{ | |||
writer.WriteUInt32(value.Id); | |||
// 先计算内容长度(汉字为两个字节) | |||
writer.Skip(2, out int position); | |||
writer.WriteString(value.UserName); | |||
writer.WriteUInt16Return((ushort)(writer.GetCurrentPosition()- position-2), position); | |||
} | |||
} | |||
} |
@@ -1,21 +0,0 @@ | |||
using JT808.Protocol.Attributes; | |||
using JT808.Protocol.MessageBody; | |||
namespace JT808.Protocol.Extensions.DependencyInjection.Test.JT808LocationAttach | |||
{ | |||
/// <summary> | |||
/// 自定义附加信息 | |||
/// Age-word-2 | |||
/// UserName-BCD(10) | |||
/// Gerder-byte-1 | |||
/// </summary> | |||
[JT808Formatter(typeof(JT808_0x0200_0x06Formatter))] | |||
public class JT808LocationAttachImpl0x06 : JT808_0x0200_BodyBase | |||
{ | |||
public override byte AttachInfoId { get; set; } = 0x06; | |||
public override byte AttachInfoLength { get; set; } = 13; | |||
public int Age { get; set; } | |||
public byte Gender { get; set; } | |||
public string UserName { get; set; } | |||
} | |||
} |
@@ -1,16 +0,0 @@ | |||
using JT808.Protocol.Attributes; | |||
using JT808.Protocol.Extensions.DependencyInjection.Test.JT808Formatters; | |||
using JT808.Protocol.MessageBody; | |||
namespace JT808.Protocol.Extensions.DependencyInjection.Test.JT808_0x0701BodiesImpl | |||
{ | |||
[JT808Formatter(typeof(JT808_0x0701TestBodiesImplFormatter))] | |||
public class JT808_0x0701TestBodiesImpl : JT808_0x0701_CustomBodyBase | |||
{ | |||
public uint Id { get; set; } | |||
public ushort UserNameLength { get; set; } | |||
public string UserName { get; set; } | |||
} | |||
} |
@@ -1,73 +0,0 @@ | |||
using Microsoft.Extensions.Configuration; | |||
using Microsoft.Extensions.Hosting; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using System; | |||
using System.Threading.Tasks; | |||
using System.Linq; | |||
using JT808.Protocol.Extensions.DependencyInjection.Test.JT808LocationAttach; | |||
using JT808.Protocol.Extensions.DependencyInjection.Test.JT808_0x0701BodiesImpl; | |||
using System.Reflection; | |||
using JT808.Protocol.Interfaces; | |||
namespace JT808.Protocol.Extensions.DependencyInjection.Test | |||
{ | |||
class Program | |||
{ | |||
static void Main(string[] args) | |||
{ | |||
//单个 | |||
IServiceCollection serviceDescriptors1 = new ServiceCollection(); | |||
serviceDescriptors1.AddJT808Configure(new DefaultConfig()); | |||
var ServiceProvider1 = serviceDescriptors1.BuildServiceProvider(); | |||
var defaultConfig = ServiceProvider1.GetRequiredService<IJT808Config>(); | |||
//多个 | |||
IServiceCollection serviceDescriptors2 = new ServiceCollection(); | |||
serviceDescriptors2.AddJT808Configure(new Config1()); | |||
serviceDescriptors2.AddJT808Configure(new Config2()); | |||
serviceDescriptors2.AddSingleton(factory => | |||
{ | |||
Func<string, IJT808Config> accesor = key => | |||
{ | |||
if (key.Equals("Config1")) | |||
{ | |||
return factory.GetService<Config1>(); | |||
} | |||
else if (key.Equals("Config2")) | |||
{ | |||
return factory.GetService<Config2>(); | |||
} | |||
else | |||
{ | |||
throw new ArgumentException($"Not Support key : {key}"); | |||
} | |||
}; | |||
return accesor; | |||
}); | |||
var ServiceProvider2 = serviceDescriptors2.BuildServiceProvider(); | |||
var config1 = ServiceProvider2.GetRequiredService<Func<string, IJT808Config>>()("Config1"); | |||
var flag21 = config1.GetSerializer().SerializerId == "Config1"; | |||
var config2 = ServiceProvider2.GetRequiredService<Func<string, IJT808Config>>()("Config2"); | |||
var flag22 = config2.GetSerializer().SerializerId == "Config2"; | |||
} | |||
} | |||
public class DefaultConfig : GlobalConfigBase | |||
{ | |||
public override string ConfigId => "test"; | |||
} | |||
public class Config1 : GlobalConfigBase | |||
{ | |||
public override string ConfigId => "Config1"; | |||
} | |||
public class Config2 : GlobalConfigBase | |||
{ | |||
public override string ConfigId => "Config2"; | |||
} | |||
} | |||
@@ -1,5 +0,0 @@ | |||
{ | |||
"JT809Options": { | |||
"SkipCRCCode": false | |||
} | |||
} |
@@ -1,26 +0,0 @@ | |||
using JT808.Protocol.Interfaces; | |||
using Microsoft.Extensions.DependencyInjection; | |||
namespace JT808.Protocol.Extensions.DependencyInjection | |||
{ | |||
public static class DependencyInjectionExtensions | |||
{ | |||
public static IServiceCollection AddJT808Configure(this IServiceCollection services, IJT808Config jT808Config) | |||
{ | |||
services.AddSingleton(jT808Config.GetType(), jT808Config); | |||
services.AddSingleton(jT808Config); | |||
return services; | |||
} | |||
public static IServiceCollection AddJT808Configure(this IServiceCollection services) | |||
{ | |||
services.AddSingleton<IJT808Config>(new DefaultGlobalConfig()); | |||
return services; | |||
} | |||
class DefaultGlobalConfig : GlobalConfigBase | |||
{ | |||
public override string ConfigId => "default"; | |||
} | |||
} | |||
} |
@@ -1,31 +0,0 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>netcoreapp2.2</TargetFramework> | |||
<LangVersion>7.3</LangVersion> | |||
<Copyright>Copyright 2018.</Copyright> | |||
<Authors>SmallChi</Authors> | |||
<PackageId>JT808.Extensions.DependencyInjection</PackageId> | |||
<Product>JT808.Extensions.DependencyInjection</Product> | |||
<Description>JT808协议依赖注入扩展包</Description> | |||
<PackageReleaseNotes>JT808协议依赖注入扩展包</PackageReleaseNotes> | |||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance> | |||
<RepositoryUrl>https://github.com/SmallChi/JT808</RepositoryUrl> | |||
<PackageProjectUrl>https://github.com/SmallChi/JT808</PackageProjectUrl> | |||
<license>https://github.com/SmallChi/JT808/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.Options.ConfigurationExtensions" Version="2.2.0" /> | |||
<PackageReference Include="NETStandard.Library" Version="2.0.3" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\JT808.Protocol\JT808.Protocol.csproj" /> | |||
</ItemGroup> | |||
</Project> |
@@ -102,6 +102,7 @@ | |||
<PackageReference Include="NETStandard.Library" Version="2.0.3" /> | |||
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" /> | |||
<PackageReference Include="System.Drawing.Common" Version="4.5.1" /> | |||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" /> | |||
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" /> | |||
<PackageReference Include="xunit" Version="2.4.1" /> | |||
<PackageReference Include="xunit.runner.console" Version="2.4.1"> | |||
@@ -0,0 +1,84 @@ | |||
using JT808.Protocol.Interfaces; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using Xunit; | |||
namespace JT808.Protocol.Test.Simples | |||
{ | |||
public class Demo7 | |||
{ | |||
/// <summary> | |||
/// 单个 | |||
/// </summary> | |||
[Fact] | |||
public void Test1() | |||
{ | |||
IServiceCollection serviceDescriptors1 = new ServiceCollection(); | |||
serviceDescriptors1.AddJT808Configure(new DefaultConfig()); | |||
var serviceProvider1 = serviceDescriptors1.BuildServiceProvider(); | |||
var config = serviceProvider1.GetRequiredService<IJT808Config>(); | |||
var defaultConfig = (DefaultConfig)config; | |||
Assert.Equal("test", defaultConfig.ConfigId); | |||
Assert.Equal("smallchi", defaultConfig.Test()); | |||
} | |||
/// <summary> | |||
/// 多个 | |||
/// </summary> | |||
[Fact] | |||
public void Test2() | |||
{ | |||
IServiceCollection serviceDescriptors2 = new ServiceCollection(); | |||
serviceDescriptors2.AddJT808Configure(new Config1()); | |||
serviceDescriptors2.AddJT808Configure(new Config2()); | |||
serviceDescriptors2.AddSingleton(factory => | |||
{ | |||
Func<string, IJT808Config> accesor = key => | |||
{ | |||
if (key.Equals("Config1")) | |||
{ | |||
return factory.GetService<Config1>(); | |||
} | |||
else if (key.Equals("Config2")) | |||
{ | |||
return factory.GetService<Config2>(); | |||
} | |||
else | |||
{ | |||
throw new ArgumentException($"Not Support key : {key}"); | |||
} | |||
}; | |||
return accesor; | |||
}); | |||
var ServiceProvider2 = serviceDescriptors2.BuildServiceProvider(); | |||
var config1 = ServiceProvider2.GetRequiredService<Func<string, IJT808Config>>()("Config1"); | |||
Assert.Equal("Config1", config1.ConfigId); | |||
Assert.Equal("Config1", config1.GetSerializer().SerializerId); | |||
var config2 = ServiceProvider2.GetRequiredService<Func<string, IJT808Config>>()("Config2"); | |||
Assert.Equal("Config2", config2.ConfigId); | |||
Assert.Equal("Config2", config2.GetSerializer().SerializerId); | |||
} | |||
public class DefaultConfig : GlobalConfigBase | |||
{ | |||
public override string ConfigId => "test"; | |||
public string Test() | |||
{ | |||
return "smallchi"; | |||
} | |||
} | |||
public class Config1 : GlobalConfigBase | |||
{ | |||
public override string ConfigId => "Config1"; | |||
} | |||
public class Config2 : GlobalConfigBase | |||
{ | |||
public override string ConfigId => "Config2"; | |||
} | |||
} | |||
} |
@@ -15,8 +15,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution | |||
EndProject | |||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT808.Protocol.Benchmark", "JT808.Protocol.Benchmark\JT808.Protocol.Benchmark.csproj", "{04966672-8FC4-42F2-BF0F-9E367A8FC5AF}" | |||
EndProject | |||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT808.Protocol.Extensions.DependencyInjection.Test", "JT808.Protocol.Extensions.DependencyInjection.Test\JT808.Protocol.Extensions.DependencyInjection.Test.csproj", "{B5B337C9-5C40-4DFD-BC8D-B0EA7F2F2F15}" | |||
EndProject | |||
Global | |||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | |||
Debug|Any CPU = Debug|Any CPU | |||
@@ -35,10 +33,6 @@ Global | |||
{04966672-8FC4-42F2-BF0F-9E367A8FC5AF}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
{04966672-8FC4-42F2-BF0F-9E367A8FC5AF}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
{04966672-8FC4-42F2-BF0F-9E367A8FC5AF}.Release|Any CPU.Build.0 = Release|Any CPU | |||
{B5B337C9-5C40-4DFD-BC8D-B0EA7F2F2F15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||
{B5B337C9-5C40-4DFD-BC8D-B0EA7F2F2F15}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
{B5B337C9-5C40-4DFD-BC8D-B0EA7F2F2F15}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
{B5B337C9-5C40-4DFD-BC8D-B0EA7F2F2F15}.Release|Any CPU.Build.0 = Release|Any CPU | |||
EndGlobalSection | |||
GlobalSection(SolutionProperties) = preSolution | |||
HideSolutionNode = FALSE | |||
@@ -39,9 +39,9 @@ namespace JT808.Protocol.Formatters | |||
if (jT808Package.Header.MessageBodyProperty.IsPackage) | |||
{ | |||
//3.5.1.读取消息包总数 | |||
jT808Package.PackgeCount = reader.ReadUInt16(); | |||
jT808Package.Header.PackgeCount = reader.ReadUInt16(); | |||
//3.5.2.读取消息包序号 | |||
jT808Package.PackageIndex = reader.ReadUInt16(); | |||
jT808Package.Header.PackageIndex = reader.ReadUInt16(); | |||
} | |||
// 4.处理数据体 | |||
// 4.1.判断有无数据体 | |||
@@ -8,8 +8,7 @@ namespace JT808.Protocol | |||
{ | |||
public interface IJT808Builder | |||
{ | |||
IServiceCollection Services { get; } | |||
IJT808Config Config { get; } | |||
IServiceCollection Services { get; } | |||
} | |||
} |
@@ -9,9 +9,7 @@ namespace JT808.Protocol.Internal | |||
class DefaultBuilder : IJT808Builder | |||
{ | |||
public IServiceCollection Services { get; } | |||
public IJT808Config Config { get; } | |||
public DefaultBuilder(IServiceCollection services, IJT808Config config) | |||
{ | |||
Services = services; | |||
@@ -14,7 +14,7 @@ | |||
<licenseUrl>https://github.com/SmallChi/JT808/blob/master/LICENSE</licenseUrl> | |||
<license>https://github.com/SmallChi/JT808/blob/master/LICENSE</license> | |||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild> | |||
<Version>2.1.3</Version> | |||
<Version>2.1.6</Version> | |||
<PackageLicenseFile>LICENSE</PackageLicenseFile> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | |||
@@ -1,140 +0,0 @@ | |||
using JT808.Protocol.Formatters; | |||
using JT808.Protocol.Interfaces; | |||
using JT808.Protocol.Internal; | |||
using System; | |||
using System.Reflection; | |||
using System.Runtime.CompilerServices; | |||
using System.Text; | |||
[assembly: InternalsVisibleTo("JT808.Protocol.Benchmark")] | |||
[assembly: InternalsVisibleTo("JT808.Protocol.Test")] | |||
namespace JT808.Protocol | |||
{ | |||
public class JT808GlobalConfig | |||
{ | |||
public static readonly JT808GlobalConfig Instance = new JT808GlobalConfig(); | |||
public JT808GlobalConfig() | |||
{ | |||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); | |||
MsgSNDistributed = new DefaultMsgSNDistributedImpl(); | |||
Compress = new JT808GZipCompressImpl(); | |||
SplitPackageStrategy = new DefaultSplitPackageStrategyImpl(); | |||
SkipCRCCode = false; | |||
MsgIdFactory = new JT808MsgIdFactory(); | |||
Encoding = Encoding.GetEncoding("GBK"); | |||
FormatterFactory = new JT808FormatterFactory(); | |||
JT808_0X0200_Custom_Factory = new JT808_0x0200_Custom_Factory(); | |||
JT808_0X8103_Custom_Factory = new JT808_0x8103_Custom_Factory(); | |||
} | |||
public IJT808MsgSNDistributed MsgSNDistributed { get; private set; } | |||
public IJT808Compress Compress { get; private set; } | |||
public IJT808SplitPackageStrategy SplitPackageStrategy { get; private set; } | |||
public IJT808MsgIdFactory MsgIdFactory { get; private set; } | |||
public Encoding Encoding; | |||
/// <summary> | |||
/// 序列化器工厂 | |||
/// </summary> | |||
internal IJT808FormatterFactory FormatterFactory { get; } | |||
/// <summary> | |||
/// 自定义附加信息工厂 | |||
/// </summary> | |||
internal IJT808_0x0200_Custom_Factory JT808_0X0200_Custom_Factory { get; } | |||
/// <summary> | |||
///自定义设置终端参数工厂 | |||
/// </summary> | |||
internal IJT808_0x8103_Custom_Factory JT808_0X8103_Custom_Factory { get; } | |||
/// <summary> | |||
/// 跳过校验码 | |||
/// 测试的时候需要手动修改值,避免验证 | |||
/// 默认:false | |||
/// </summary> | |||
public bool SkipCRCCode { get; private set; } | |||
/// <summary> | |||
/// 设置消息序列号 | |||
/// </summary> | |||
/// <param name="msgSNDistributed"></param> | |||
/// <returns></returns> | |||
public JT808GlobalConfig SetMsgSNDistributed(IJT808MsgSNDistributed msgSNDistributed) | |||
{ | |||
Instance.MsgSNDistributed = msgSNDistributed; | |||
return this; | |||
} | |||
/// <summary> | |||
/// 设置压缩算法 | |||
/// 默认GZip | |||
/// </summary> | |||
/// <param name="compressImpl"></param> | |||
/// <returns></returns> | |||
public JT808GlobalConfig SetCompress(IJT808Compress compressImpl) | |||
{ | |||
Instance.Compress = compressImpl; | |||
return this; | |||
} | |||
/// <summary> | |||
/// 设置分包算法 | |||
/// 默认3*256 | |||
/// </summary> | |||
/// <param name="splitPackageStrategy"></param> | |||
/// <returns></returns> | |||
public JT808GlobalConfig SetSplitPackageStrategy(IJT808SplitPackageStrategy splitPackageStrategy) | |||
{ | |||
Instance.SplitPackageStrategy = splitPackageStrategy; | |||
return this; | |||
} | |||
/// <summary> | |||
/// 设置跳过校验码 | |||
/// 场景:测试的时候,可能需要手动改数据,所以测试的时候有用 | |||
/// </summary> | |||
/// <param name="skipCRCCode"></param> | |||
/// <returns></returns> | |||
public JT808GlobalConfig SetSkipCRCCode(bool skipCRCCode) | |||
{ | |||
Instance.SkipCRCCode = skipCRCCode; | |||
return this; | |||
} | |||
/// <summary> | |||
/// 设置消息工厂的实现 | |||
/// </summary> | |||
/// <param name="msgIdFactory"></param> | |||
/// <returns></returns> | |||
public JT808GlobalConfig SetMsgIdFactory(IJT808MsgIdFactory msgIdFactory) | |||
{ | |||
if (msgIdFactory != null) | |||
{ | |||
Instance.MsgIdFactory = msgIdFactory; | |||
} | |||
return this; | |||
} | |||
/// <summary> | |||
/// 全局注册外部程序集 | |||
/// </summary> | |||
/// <param name="externalAssemblies"></param> | |||
/// <returns></returns> | |||
public JT808GlobalConfig Register(params Assembly[] externalAssemblies) | |||
{ | |||
if (externalAssemblies != null) | |||
{ | |||
foreach(var easb in externalAssemblies) | |||
{ | |||
FormatterFactory.Register(easb); | |||
JT808_0X0200_Custom_Factory.Register(easb); | |||
JT808_0X8103_Custom_Factory.Register(easb); | |||
} | |||
} | |||
return this; | |||
} | |||
} | |||
} |
@@ -30,13 +30,5 @@ namespace JT808.Protocol | |||
/// 终止符 | |||
/// </summary> | |||
public byte End { get; set; } | |||
/// <summary> | |||
/// 消息总包数 | |||
/// </summary> | |||
public ushort PackgeCount { get; set; } | |||
/// <summary> | |||
/// 报序号 从1开始 | |||
/// </summary> | |||
public ushort PackageIndex { get; set; } | |||
} | |||
} |
@@ -1,237 +0,0 @@ | |||
using System; | |||
namespace JT808.Protocol.Metadata | |||
{ | |||
/// <summary> | |||
/// 报警标志位定义 | |||
/// </summary> | |||
public class JT808AlarmProperty | |||
{ | |||
private const int bitCount = 32; | |||
/// <summary> | |||
/// 初始化读取报警标志位 | |||
/// </summary> | |||
/// <param name="alarmStr"></param> | |||
public JT808AlarmProperty(string alarmStr) | |||
{ | |||
Bit0 = alarmStr[0]; | |||
Bit1 = alarmStr[1]; | |||
Bit2 = alarmStr[2]; | |||
Bit3 = alarmStr[3]; | |||
Bit4 = alarmStr[4]; | |||
Bit5 = alarmStr[5]; | |||
Bit6 = alarmStr[6]; | |||
Bit7 = alarmStr[7]; | |||
Bit8 = alarmStr[8]; | |||
Bit9 = alarmStr[9]; | |||
Bit10 = alarmStr[10]; | |||
Bit11 = alarmStr[11]; | |||
Bit12 = alarmStr[12]; | |||
Bit13 = alarmStr[13]; | |||
Bit14 = alarmStr[14]; | |||
Bit15 = alarmStr[15]; | |||
Bit16 = alarmStr[16]; | |||
Bit17 = alarmStr[17]; | |||
Bit18 = alarmStr[18]; | |||
Bit19 = alarmStr[19]; | |||
Bit20 = alarmStr[20]; | |||
Bit21 = alarmStr[21]; | |||
Bit22 = alarmStr[22]; | |||
Bit23 = alarmStr[23]; | |||
Bit24 = alarmStr[24]; | |||
Bit25 = alarmStr[25]; | |||
Bit26 = alarmStr[26]; | |||
Bit27 = alarmStr[27]; | |||
Bit28 = alarmStr[28]; | |||
Bit29 = alarmStr[29]; | |||
Bit30 = alarmStr[30]; | |||
Bit31 = alarmStr[31]; | |||
} | |||
/// <summary> | |||
/// 写入报警标志位 | |||
/// 从左开始写入,不满32位自动补'0' | |||
/// </summary> | |||
/// <param name="alarmChar"></param> | |||
public JT808AlarmProperty(params char[] alarmChar) | |||
{ | |||
alarmChar = alarmChar ?? new char[32]; | |||
ReadOnlySpan<char> span = alarmChar.ToString().PadRight(32, '0').AsSpan(); | |||
Bit0 = span[0]; | |||
Bit1 = span[1]; | |||
Bit2 = span[2]; | |||
Bit3 = span[3]; | |||
Bit4 = span[4]; | |||
Bit5 = span[5]; | |||
Bit6 = span[6]; | |||
Bit7 = span[7]; | |||
Bit8 = span[8]; | |||
Bit9 = span[9]; | |||
Bit10 = span[10]; | |||
Bit11 = span[11]; | |||
Bit12 = span[12]; | |||
Bit13 = span[13]; | |||
Bit14 = span[14]; | |||
Bit15 = span[15]; | |||
Bit16 = span[16]; | |||
Bit17 = span[17]; | |||
Bit18 = span[18]; | |||
Bit19 = span[19]; | |||
Bit20 = span[20]; | |||
Bit21 = span[21]; | |||
Bit22 = span[22]; | |||
Bit23 = span[23]; | |||
Bit24 = span[24]; | |||
Bit25 = span[25]; | |||
Bit26 = span[26]; | |||
Bit27 = span[27]; | |||
Bit28 = span[28]; | |||
Bit29 = span[29]; | |||
Bit30 = span[30]; | |||
Bit31 = span[31]; | |||
} | |||
/// <summary> | |||
/// 1:紧急报警,触动报警开关后触发 收到应答后清零 | |||
/// </summary> | |||
public char Bit0 { get; set; } | |||
/// <summary> | |||
/// 1:超速报警 标志维持至报警条件解除 | |||
/// </summary> | |||
public char Bit1 { get; set; } | |||
/// <summary> | |||
/// 1:疲劳驾驶 标志维持至报警条件解除 | |||
/// </summary> | |||
public char Bit2 { get; set; } | |||
/// <summary> | |||
/// 1:危险预警 收到应答后清零 | |||
/// </summary> | |||
public char Bit3 { get; set; } | |||
/// <summary> | |||
/// GNSS模块发生故障 标志维持至报警条件解除 | |||
/// </summary> | |||
public char Bit4 { get; set; } | |||
/// <summary> | |||
/// GNSS天线未接或被剪断 标志维持至报警条件解除 | |||
/// </summary> | |||
public char Bit5 { get; set; } | |||
/// <summary> | |||
/// GNSS天线短路 标志维持至报警条件解除 | |||
/// </summary> | |||
public char Bit6 { get; set; } | |||
/// <summary> | |||
/// 终端主电源欠压 标志维持至报警条件解除 | |||
/// </summary> | |||
public char Bit7 { get; set; } | |||
/// <summary> | |||
/// 终端主电源掉电 标志维持至报警条件解除 | |||
/// </summary> | |||
public char Bit8 { get; set; } | |||
/// <summary> | |||
/// 终端LCD或显示器故障 标志维持至报警条件解除 | |||
/// </summary> | |||
public char Bit9 { get; set; } | |||
/// <summary> | |||
/// TTS模块故障 标志维持至报警条件解除 | |||
/// </summary> | |||
public char Bit10 { get; set; } | |||
/// <summary> | |||
/// 摄像头故障 标志维持至报警条件解除 | |||
/// </summary> | |||
public char Bit11 { get; set; } | |||
/// <summary> | |||
/// 道路运输证IC卡模块故障 标志维持至报警条件解除 | |||
/// </summary> | |||
public char Bit12 { get; set; } | |||
/// <summary> | |||
/// 超速预警 标志维持至报警条件解除 | |||
/// </summary> | |||
public char Bit13 { get; set; } | |||
/// <summary> | |||
/// 疲劳驾驶预警 标志维持至报警条件解除 | |||
/// </summary> | |||
public char Bit14 { get; set; } | |||
/// <summary> | |||
/// 保留15 | |||
/// </summary> | |||
public char Bit15 { get; set; } | |||
/// <summary> | |||
/// 保留16 | |||
/// </summary> | |||
public char Bit16 { get; set; } | |||
/// <summary> | |||
/// 保留17 | |||
/// </summary> | |||
public char Bit17 { get; set; } | |||
/// <summary> | |||
/// 当天累计驾驶超时 标志维持至报警条件解除 | |||
/// </summary> | |||
public char Bit18 { get; set; } | |||
/// <summary> | |||
/// 超时停车 标志维持至报警条件解除 | |||
/// </summary> | |||
public char Bit19 { get; set; } | |||
/// <summary> | |||
/// 进出区域 收到应答后清零 | |||
/// </summary> | |||
public char Bit20 { get; set; } | |||
/// <summary> | |||
/// 进出路线 收到应答后清零 | |||
/// </summary> | |||
public char Bit21 { get; set; } | |||
/// <summary> | |||
/// 路段行驶时间不足或过长 收到应答后清零 | |||
/// </summary> | |||
public char Bit22 { get; set; } | |||
/// <summary> | |||
/// 路线偏离报警 标志维持至报警条件解除 | |||
/// </summary> | |||
public char Bit23 { get; set; } | |||
/// <summary> | |||
/// 车辆VSS故障 标志维持至报警条件解除 | |||
/// </summary> | |||
public char Bit24 { get; set; } | |||
/// <summary> | |||
/// 车辆油量异常 标志维持至报警条件解除 | |||
/// </summary> | |||
public char Bit25 { get; set; } | |||
/// <summary> | |||
/// 车辆被盗通过车辆防盗器 标志维持至报警条件解除 | |||
/// </summary> | |||
public char Bit26 { get; set; } | |||
/// <summary> | |||
/// 车辆非法点火 | |||
/// </summary> | |||
public char Bit27 { get; set; } | |||
/// <summary> | |||
/// 车辆非法位移 收到应答后清零 | |||
/// </summary> | |||
public char Bit28 { get; set; } | |||
/// <summary> | |||
/// 碰撞预警 标志维持至报警条件解除 | |||
/// </summary> | |||
public char Bit29 { get; set; } | |||
/// <summary> | |||
/// 侧翻预警 标志维持至报警条件解除 | |||
/// </summary> | |||
public char Bit30 { get; set; } | |||
/// <summary> | |||
/// 非法开门报警 (终端未设置区域时,不判断非法开门)收到应答后清零 | |||
/// </summary> | |||
public char Bit31 { get; set; } | |||
/// <summary> | |||
/// 报警标志位 | |||
/// </summary> | |||
/// <returns></returns> | |||
public override string ToString() | |||
{ | |||
Span<char> span = new char[bitCount]; | |||
for (int i = 0; i < span.Length; i++) | |||
{ | |||
span[i] = (char)this.GetType().GetProperty("Bit" + i.ToString()).GetValue(this); | |||
} | |||
return span.ToString(); | |||
} | |||
} | |||
} |
@@ -1,236 +0,0 @@ | |||
using System; | |||
namespace JT808.Protocol.Metadata | |||
{ | |||
/// <summary> | |||
/// 状态位 | |||
/// </summary> | |||
public struct JT808StatusProperty | |||
{ | |||
/// <summary> | |||
/// 初始化读取状态位 | |||
/// </summary> | |||
/// <param name="alarmStr"></param> | |||
public JT808StatusProperty(string alarmStr) | |||
{ | |||
Bit0 = alarmStr[0]; | |||
Bit1 = alarmStr[1]; | |||
Bit2 = alarmStr[2]; | |||
Bit3 = alarmStr[3]; | |||
Bit4 = alarmStr[4]; | |||
Bit5 = alarmStr[5]; | |||
Bit6 = alarmStr[6]; | |||
Bit7 = alarmStr[7]; | |||
Bit8 = alarmStr[8]; | |||
Bit9 = alarmStr[9]; | |||
Bit10 = alarmStr[10]; | |||
Bit11 = alarmStr[11]; | |||
Bit12 = alarmStr[12]; | |||
Bit13 = alarmStr[13]; | |||
Bit14 = alarmStr[14]; | |||
Bit15 = alarmStr[15]; | |||
Bit16 = alarmStr[16]; | |||
Bit17 = alarmStr[17]; | |||
Bit18 = alarmStr[18]; | |||
Bit19 = alarmStr[19]; | |||
Bit20 = alarmStr[20]; | |||
Bit21 = alarmStr[21]; | |||
Bit22 = alarmStr[22]; | |||
Bit23 = alarmStr[23]; | |||
Bit24 = alarmStr[24]; | |||
Bit25 = alarmStr[25]; | |||
Bit26 = alarmStr[26]; | |||
Bit27 = alarmStr[27]; | |||
Bit28 = alarmStr[28]; | |||
Bit29 = alarmStr[29]; | |||
Bit30 = alarmStr[30]; | |||
Bit31 = alarmStr[31]; | |||
} | |||
/// <summary> | |||
/// 写入状态位 | |||
/// 从左开始写入,不满32位自动补'0' | |||
/// </summary> | |||
/// <param name="alarmChar"></param> | |||
public JT808StatusProperty(params char[] alarmChar) | |||
{ | |||
alarmChar = alarmChar ?? new char[32]; | |||
ReadOnlySpan<char> span = alarmChar.ToString().PadRight(32, '0').AsSpan(); | |||
Bit0 = span[0]; | |||
Bit1 = span[1]; | |||
Bit2 = span[2]; | |||
Bit3 = span[3]; | |||
Bit4 = span[4]; | |||
Bit5 = span[5]; | |||
Bit6 = span[6]; | |||
Bit7 = span[7]; | |||
Bit8 = span[8]; | |||
Bit9 = span[9]; | |||
Bit10 = span[10]; | |||
Bit11 = span[11]; | |||
Bit12 = span[12]; | |||
Bit13 = span[13]; | |||
Bit14 = span[14]; | |||
Bit15 = span[15]; | |||
Bit16 = span[16]; | |||
Bit17 = span[17]; | |||
Bit18 = span[18]; | |||
Bit19 = span[19]; | |||
Bit20 = span[20]; | |||
Bit21 = span[21]; | |||
Bit22 = span[22]; | |||
Bit23 = span[23]; | |||
Bit24 = span[24]; | |||
Bit25 = span[25]; | |||
Bit26 = span[26]; | |||
Bit27 = span[27]; | |||
Bit28 = span[28]; | |||
Bit29 = span[29]; | |||
Bit30 = span[30]; | |||
Bit31 = span[31]; | |||
} | |||
/// <summary> | |||
/// 0:ACC 关;1: ACC 开 | |||
/// </summary> | |||
public char Bit0 { get; set; } | |||
/// <summary> | |||
/// 0:未定位;1:定位 | |||
/// </summary> | |||
public char Bit1 { get; set; } | |||
/// <summary> | |||
/// 0:北纬;1:南纬 | |||
/// </summary> | |||
public char Bit2 { get; set; } | |||
/// <summary> | |||
/// 0:东经;1:西经 | |||
/// </summary> | |||
public char Bit3 { get; set; } | |||
/// <summary> | |||
/// 0:运营状态;1:停运状态 | |||
/// </summary> | |||
public char Bit4 { get; set; } | |||
/// <summary> | |||
/// 0:经纬度未经保密插件加密;1:经纬度已经保密插件加密 | |||
/// </summary> | |||
public char Bit5 { get; set; } | |||
/// <summary> | |||
/// 保留 | |||
/// </summary> | |||
public char Bit6 { get; set; } | |||
/// <summary> | |||
/// 保留 | |||
/// </summary> | |||
public char Bit7 { get; set; } | |||
/// <summary> | |||
/// 00:空车;01:半载;10:保留;11:满载(可用于客车的空、重车及货车的空载、满载状态表示,人工输入或传感器获取) | |||
/// </summary> | |||
public char Bit8 { get; set; } | |||
/// <summary> | |||
/// 00:空车;01:半载;10:保留;11:满载(可用于客车的空、重车及货车的空载、满载状态表示,人工输入或传感器获取) | |||
/// </summary> | |||
public char Bit9 { get; set; } | |||
/// <summary> | |||
/// 0:车辆油路正常;1:车辆油路断开 | |||
/// </summary> | |||
public char Bit10 { get; set; } | |||
/// <summary> | |||
/// 0:车辆电路正常;1:车辆电路断开 | |||
/// </summary> | |||
public char Bit11 { get; set; } | |||
/// <summary> | |||
/// 0:车门解锁;1:车门加锁 | |||
/// </summary> | |||
public char Bit12 { get; set; } | |||
/// <summary> | |||
/// 0:门 1 关;1:门 1 开(前门) | |||
/// </summary> | |||
public char Bit13 { get; set; } | |||
/// <summary> | |||
/// 0:门 2 关;1:门 2 开(中门) | |||
/// </summary> | |||
public char Bit14 { get; set; } | |||
/// <summary> | |||
/// 0:门 3 关;1:门 3 开(后门) | |||
/// </summary> | |||
public char Bit15 { get; set; } | |||
/// <summary> | |||
/// 0:门 4 关;1:门 4 开(驾驶席门) | |||
/// </summary> | |||
public char Bit16 { get; set; } | |||
/// <summary> | |||
/// 0:门 5 关;1:门 5 开(自定义) | |||
/// </summary> | |||
public char Bit17 { get; set; } | |||
/// <summary> | |||
/// 0:未使用 GPS 卫星进行定位;1:使用 GPS 卫星进行定位 | |||
/// </summary> | |||
public char Bit18 { get; set; } | |||
/// <summary> | |||
/// 0:未使用北斗卫星进行定位;1:使用北斗卫星进行定位 | |||
/// </summary> | |||
public char Bit19 { get; set; } | |||
/// <summary> | |||
/// 0:未使用 GLONASS 卫星进行定位;1:使用 GLONASS 卫星进行定位 | |||
/// </summary> | |||
public char Bit20 { get; set; } | |||
/// <summary> | |||
/// 0:未使用 Galileo 卫星进行定位;1:使用 Galileo 卫星进行定位 | |||
/// </summary> | |||
public char Bit21 { get; set; } | |||
/// <summary> | |||
/// 保留 | |||
/// </summary> | |||
public char Bit22 { get; set; } | |||
/// <summary> | |||
/// 保留 | |||
/// </summary> | |||
public char Bit23 { get; set; } | |||
/// <summary> | |||
/// 保留 | |||
/// </summary> | |||
public char Bit24 { get; set; } | |||
/// <summary> | |||
/// 保留 | |||
/// </summary> | |||
public char Bit25 { get; set; } | |||
/// <summary> | |||
/// 保留 | |||
/// </summary> | |||
public char Bit26 { get; set; } | |||
/// <summary> | |||
/// 保留 | |||
/// </summary> | |||
public char Bit27 { get; set; } | |||
/// <summary> | |||
/// 保留 | |||
/// </summary> | |||
public char Bit28 { get; set; } | |||
/// <summary> | |||
/// 保留 | |||
/// </summary> | |||
public char Bit29 { get; set; } | |||
/// <summary> | |||
/// 保留 | |||
/// </summary> | |||
public char Bit30 { get; set; } | |||
/// <summary> | |||
/// 保留 | |||
/// </summary> | |||
public char Bit31 { get; set; } | |||
/// <summary> | |||
/// 状态位 | |||
/// </summary> | |||
/// <returns></returns> | |||
public override string ToString() | |||
{ | |||
Span<char> span = new char[32]; | |||
for (int i = 0; i < span.Length; i++) | |||
{ | |||
span[i] = (char)this.GetType().GetProperty("Bit" + i.ToString()).GetValue(this); | |||
} | |||
return span.ToString(); | |||
} | |||
} | |||
} |