From e184229cfe31279ac849ba2d1f9db507a08876c7 Mon Sep 17 00:00:00 2001 From: "SmallChi(Koike)" <564952747@qq.com> Date: Fri, 7 Oct 2022 11:17:03 +0800 Subject: [PATCH] =?UTF-8?q?2.5.0-preview4=201.=E4=BD=BF=E7=94=A8=E5=BE=AE?= =?UTF-8?q?=E8=BD=AF=E8=87=AA=E5=B8=A6=E7=9A=84hex=E5=BA=93=202.readme?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=A4=E4=B8=AA=E4=BD=BF=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en.md | 12 +++ README.md | 14 +++- src/Info.props | 2 +- .../JT808.Protocol.Benchmark.csproj | 4 +- .../JT808.Protocol.Extensions.JT1078.csproj | 6 +- .../JT808.Protocol.Extensions.SuBiao.csproj | 6 +- .../JT808.Protocol.Extensions.YueBiao.csproj | 6 +- .../Extensions/JT808HexExtensions.cs | 78 +------------------ src/JT808.Protocol/JT808.Protocol.csproj | 10 +-- src/JT808.Protocol/JT808.Protocol.xml | 23 ------ .../MessagePack/JT808MessagePackReader.cs | 2 +- 11 files changed, 39 insertions(+), 124 deletions(-) diff --git a/README.en.md b/README.en.md index 5137af0..8420357 100644 --- a/README.en.md +++ b/README.en.md @@ -360,6 +360,18 @@ We can refer to the subcontracting data structure of the equipment in [Example 5 [See Demo16 for Simples](https://github.com/SmallChi/JT808/blob/master/src/JT808.Protocol.Test/Simples/Demo16.cs) +### 举个栗子17 + +***scene:*** +The additional data of the JT/T808 0x0200 standard protocol is explicitly reserved for some additional information ids. Therefore, according to the standard, some device manufacturers use the additional information ids of the standard. Therefore, to resolve the problem, you can refer to the external custom additional information registration method. + +[see Demo10 for Simples](https://github.com/SmallChi/JT808/blob/master/src/JT808.Protocol.Test/Simples/Demo10.cs). + +### 举个栗子18 + +***scene:*** +Due to access many different equipment vendor's agreement, but each protocol docking and less, think at the same time in a class library under the unified management, then in each manufacturer not conflict using the assembly way of registration is no problem, once has the conflict, then use the assembly way registered will quote Id conflict, The library does not support this way of isolation, so I use [SetMap] to manage this situation. + ## NuGet Install | Package Name| Version| Preview Version |Downloads|Remark| diff --git a/README.md b/README.md index d28ec40..bb2e7a9 100644 --- a/README.md +++ b/README.md @@ -358,9 +358,19 @@ JT808Serializer DT2JT808Serializer = new JT808Serializer(DT2JT808Config); 场景: 平台下发分包数据到设备 -可以参考【栗子5】中,设备上来的分包数据结构,然后举一反三的去实现。 +可以参考【举个栗子5】中,设备上来的分包数据结构,然后举一反三的去实现。 -[可以参考Simples的Demo16](https://github.com/SmallChi/JT808/blob/master/src/JT808.Protocol.Test/Simples/Demo16.cs) +### 举个栗子17 + +场景: +由于808的0x0200标准协议的附加数据是有明确的表示对部分附加信息Id进行保留的,所以按照标准,有些设备厂商把标准的附加信息Id占用,所以需要解析这部分的数据,可以参考外部自定义附加信息注册的方式来解决解析问题。 + +可以参考[举个栗子10](https://github.com/SmallChi/JT808/blob/master/src/JT808.Protocol.Test/Simples/Demo10.cs)中的程序。 + +### 举个栗子18 + +场景: +由于接入很多不同设备厂商的协议,但是每个协议对接又比较少,想同时放在一个类库下面进行统一管理,那么在各个厂家不冲突的情况下使用程序集方式的注册是没有问题的,一旦有冲突,那么使用程序集的方式进行注册会报Id冲突,本身库不支持这种方式进行隔离的,所以遇到这种情况自己使用SetMap的方式进行管理。 ## NuGet安装 diff --git a/src/Info.props b/src/Info.props index c0d2ad9..3c90dcf 100644 --- a/src/Info.props +++ b/src/Info.props @@ -8,7 +8,7 @@ https://github.com/SmallChi/JT808 https://github.com/SmallChi/JT808/blob/master/LICENSE https://github.com/SmallChi/JT808/blob/master/LICENSE - 2.5.0-preview3 + 2.5.0-preview4 LICENSE true latest diff --git a/src/JT808.Protocol.Benchmark/JT808.Protocol.Benchmark.csproj b/src/JT808.Protocol.Benchmark/JT808.Protocol.Benchmark.csproj index 088e548..82cefa2 100644 --- a/src/JT808.Protocol.Benchmark/JT808.Protocol.Benchmark.csproj +++ b/src/JT808.Protocol.Benchmark/JT808.Protocol.Benchmark.csproj @@ -14,8 +14,8 @@ - - + + diff --git a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.JT1078/JT808.Protocol.Extensions.JT1078.csproj b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.JT1078/JT808.Protocol.Extensions.JT1078.csproj index 62b2cac..e9d3ca2 100644 --- a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.JT1078/JT808.Protocol.Extensions.JT1078.csproj +++ b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.JT1078/JT808.Protocol.Extensions.JT1078.csproj @@ -4,12 +4,10 @@ JT808.Protocol.Extensions.JT1078 JT808.Protocol.Extensions.JT1078 - JT/T1078 video message protocol based on JT/JT808 protocol and GB808 protocol extension. - 基于JT808协议、GB808协议扩展的JT1078视频消息协议。 + JT/T1078 video message protocol based on JT/JT808 protocol and GB808 protocol extension.基于JT808协议、GB808协议扩展的JT1078视频消息协议。 - JT/T1078 video message protocol based on JT/JT808 protocol and GB808 protocol extension. - 基于JT/T808协议、GB808协议扩展的JT/T1078视频消息协议。 + JT/T1078 video message protocol based on JT/JT808 protocol and GB808 protocol extension.基于JT/T808协议、GB808协议扩展的JT/T1078视频消息协议。 JT808.Protocol.Extensions.JT1078.xml diff --git a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.SuBiao/JT808.Protocol.Extensions.SuBiao.csproj b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.SuBiao/JT808.Protocol.Extensions.SuBiao.csproj index 485d79e..e65f911 100644 --- a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.SuBiao/JT808.Protocol.Extensions.SuBiao.csproj +++ b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.SuBiao/JT808.Protocol.Extensions.SuBiao.csproj @@ -4,12 +4,10 @@ JT808.Protocol.Extensions.SuBiao JT808.Protocol.Extensions.SuBiao - Active secure message protocol (Su Biao) based on JT/T808 protocol and GB808 protocol extension. - 基于JT/T808协议、GB808协议扩展的主动安全消息协议(苏标)。 + Active secure message protocol (Su Biao) based on JT/T808 protocol and GB808 protocol extension.基于JT/T808协议、GB808协议扩展的主动安全消息协议(苏标)。 - Active secure message protocol (Su Biao) based on JT/T808 protocol and GB808 protocol extension. - 基于JT/T808协议、GB808协议扩展的主动安全消息协议(苏标)。 + Active secure message protocol (Su Biao) based on JT/T808 protocol and GB808 protocol extension.基于JT/T808协议、GB808协议扩展的主动安全消息协议(苏标)。 JT808.Protocol.Extensions.SuBiao.xml diff --git a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.YueBiao/JT808.Protocol.Extensions.YueBiao.csproj b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.YueBiao/JT808.Protocol.Extensions.YueBiao.csproj index 0106416..969f9dc 100644 --- a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.YueBiao/JT808.Protocol.Extensions.YueBiao.csproj +++ b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.YueBiao/JT808.Protocol.Extensions.YueBiao.csproj @@ -4,12 +4,10 @@ JT808.Protocol.Extensions.YueBiao JT808.Protocol.Extensions.YueBiao - Active Secure Message Protocol Based on JT/T808 protocol and GB808 Protocol Extension (Yue Biao). - 基于JT/T808协议、GB808协议扩展的主动安全消息协议(粤标)。 + Active Secure Message Protocol Based on JT/T808 protocol and GB808 Protocol Extension (Yue Biao).基于JT/T808协议、GB808协议扩展的主动安全消息协议(粤标)。 - Active Secure Message Protocol Based on JT/T808 protocol and GB808 Protocol Extension (Yue Biao). - 基于JT/T808协议、GB808协议扩展的主动安全消息协议(粤标)。 + Active Secure Message Protocol Based on JT/T808 protocol and GB808 Protocol Extension (Yue Biao).基于JT/T808协议、GB808协议扩展的主动安全消息协议(粤标)。 JT808.Protocol.Extensions.YueBiao.xml diff --git a/src/JT808.Protocol/Extensions/JT808HexExtensions.cs b/src/JT808.Protocol/Extensions/JT808HexExtensions.cs index f288e2c..f134368 100644 --- a/src/JT808.Protocol/Extensions/JT808HexExtensions.cs +++ b/src/JT808.Protocol/Extensions/JT808HexExtensions.cs @@ -15,7 +15,7 @@ namespace JT808.Protocol.Extensions /// public static string ToHexString(this byte[] source) { - return HexUtil.DoHexDump(source, 0, source.Length).ToUpper(); + return Convert.ToHexString(source, 0, source.Length); } /// @@ -26,16 +26,7 @@ namespace JT808.Protocol.Extensions public static byte[] ToHexBytes(this string hexString) { hexString = hexString.Replace(" ", ""); - byte[] buf = new byte[hexString.Length / 2]; - ReadOnlySpan readOnlySpan = hexString.AsSpan(); - for (int i = 0; i < hexString.Length; i++) - { - if (i % 2 == 0) - { - buf[i / 2] = Convert.ToByte(readOnlySpan.Slice(i, 2).ToString(), 16); - } - } - return buf; + return Convert.FromHexString(hexString); } /// @@ -47,8 +38,7 @@ namespace JT808.Protocol.Extensions /// public static string ReadHexStringLittle(ReadOnlySpan read, ref int offset, int len) { - //ReadOnlySpan source = read.Slice(offset, len); - string hex = HexUtil.DoHexDump(read, offset, len); + string hex = Convert.ToHexString(read.Slice(offset, len)); offset += len; return hex; } @@ -200,66 +190,4 @@ namespace JT808.Protocol.Extensions return System.Convert.ToString(value, 2).PadLeft(8, '0').AsSpan(); } } - /// - /// - /// - public static class HexUtil - { - static readonly char[] HexdumpTable = new char[256 * 4]; - static HexUtil() - { - char[] digits = "0123456789ABCDEF".ToCharArray(); - for (int i = 0; i < 256; i++) - { - HexdumpTable[i << 1] = digits[(int)((uint)i >> 4 & 0x0F)]; - HexdumpTable[(i << 1) + 1] = digits[i & 0x0F]; - } - } - /// - /// - /// - /// - /// - /// - /// - public static string DoHexDump(ReadOnlySpan buffer, int fromIndex, int length) - { - if (length == 0) - { - return ""; - } - int endIndex = fromIndex + length; - var buf = new char[length << 1]; - int srcIdx = fromIndex; - int dstIdx = 0; - for (; srcIdx < endIndex; srcIdx++, dstIdx += 2) - { - Array.Copy(HexdumpTable, buffer[srcIdx] << 1, buf, dstIdx, 2); - } - return new string(buf); - } - /// - /// - /// - /// - /// - /// - /// - public static string DoHexDump(byte[] array, int fromIndex, int length) - { - if (length == 0) - { - return ""; - } - int endIndex = fromIndex + length; - var buf = new char[length << 1]; - int srcIdx = fromIndex; - int dstIdx = 0; - for (; srcIdx < endIndex; srcIdx++, dstIdx += 2) - { - Array.Copy(HexdumpTable, (array[srcIdx] & 0xFF) << 1, buf, dstIdx, 2); - } - return new string(buf); - } - } } diff --git a/src/JT808.Protocol/JT808.Protocol.csproj b/src/JT808.Protocol/JT808.Protocol.csproj index e9b6eb9..9fd2b7f 100644 --- a/src/JT808.Protocol/JT808.Protocol.csproj +++ b/src/JT808.Protocol/JT808.Protocol.csproj @@ -4,12 +4,10 @@ JT808 JT808 - JT/T808 protocol,JT808 protocol, GB808 protocol(support 2011, 2013, 2019 version). - JT/T808协议、JT808协议、GB808协议(支持2011、2013、2019版本)。 + JT/T808 protocol,JT808 protocol, GB808 protocol(support 2011, 2013, 2019 version).JT/T808协议、JT808协议、GB808协议(支持2011、2013、2019版本)。 - JT/T808 protocol,JT808 protocol, GB808 protocol(support 2011, 2013, 2019 version). - JT/T808协议、JT808协议、GB808协议(支持2011、2013、2019版本)。 + JT/T808 protocol,JT808 protocol, GB808 protocol(support 2011, 2013, 2019 version).JT/T808协议、JT808协议、GB808协议(支持2011、2013、2019版本)。 JT808.Protocol.xml README.md @@ -61,8 +59,4 @@ JT808PackageExtensionsTemplate.tt - - - - diff --git a/src/JT808.Protocol/JT808.Protocol.xml b/src/JT808.Protocol/JT808.Protocol.xml index 6fef27b..957cbc1 100644 --- a/src/JT808.Protocol/JT808.Protocol.xml +++ b/src/JT808.Protocol/JT808.Protocol.xml @@ -2239,29 +2239,6 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/JT808.Protocol/MessagePack/JT808MessagePackReader.cs b/src/JT808.Protocol/MessagePack/JT808MessagePackReader.cs index 06a8301..4e626f6 100644 --- a/src/JT808.Protocol/MessagePack/JT808MessagePackReader.cs +++ b/src/JT808.Protocol/MessagePack/JT808MessagePackReader.cs @@ -364,7 +364,7 @@ namespace JT808.Protocol.MessagePack public string ReadHex(int len) { var readOnlySpan = GetReadOnlySpan(len); - string hex = HexUtil.DoHexDump(readOnlySpan, 0, len); + string hex = Convert.ToHexString(readOnlySpan.Slice(0, len)); return hex; } ///