From 4a58c0e2ee50295610b1eff7caa0eb0723420fe6 Mon Sep 17 00:00:00 2001 From: "smallchi(Koike)" <564952747@qq.com> Date: Mon, 3 Feb 2020 17:58:51 +0800 Subject: [PATCH] =?UTF-8?q?v2.2.7=201.=E5=A2=9E=E5=8A=A00900=E5=92=8C8900?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E6=B6=88=E6=81=AF=E5=B7=A5=E5=8E=82?= =?UTF-8?q?=202.=E5=AE=8C=E5=96=840900=E5=92=8C8900=E5=8D=8F=E8=AE=AE?= =?UTF-8?q?=E5=88=86=E6=9E=90=E5=B7=A5=E5=85=B7=203.=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- .../JT808_0X8900_Test_BodiesImpl.cs | 24 +++++++-- .../MessageBody/JT808_0x0900Test.cs | 9 ++-- .../JT808_0x0900_0x83.cs | 18 +++++-- .../MessageBody/JT808_0x8900Test.cs | 3 +- .../Extensions/JT808AnalyzeExtensions.cs | 2 +- .../Interfaces/GlobalConfigBase.cs | 6 +++ src/JT808.Protocol/Interfaces/IJT808Config.cs | 8 +++ .../IJT808_0x0900_Custom_Factory.cs | 13 +++++ .../IJT808_0x8900_Custom_Factory.cs | 13 +++++ .../Internal/JT808_0x0900_Custom_Factory.cs | 54 +++++++++++++++++++ .../Internal/JT808_0x8900_Custom_Factory.cs | 54 +++++++++++++++++++ src/JT808.Protocol/JT808.Protocol.csproj | 2 +- src/JT808.Protocol/JT808.Protocol.xml | 21 ++++++++ .../MessageBody/JT808_0x0900.cs | 30 +++++++++-- .../MessageBody/JT808_0x0900_BodyBase.cs | 5 +- .../MessageBody/JT808_0x8900.cs | 40 ++++++++++---- .../MessageBody/JT808_0x8900_BodyBase.cs | 6 ++- 18 files changed, 278 insertions(+), 32 deletions(-) create mode 100644 src/JT808.Protocol/Interfaces/IJT808_0x0900_Custom_Factory.cs create mode 100644 src/JT808.Protocol/Interfaces/IJT808_0x8900_Custom_Factory.cs create mode 100644 src/JT808.Protocol/Internal/JT808_0x0900_Custom_Factory.cs create mode 100644 src/JT808.Protocol/Internal/JT808_0x8900_Custom_Factory.cs diff --git a/README.md b/README.md index 9436e9a..fede084 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # JT808协议 -[![MIT Licence](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/SmallChi/JT808/blob/master/LICENSE)[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FSmallChi%2FJT808.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2FSmallChi%2FJT808?ref=badge_shield)[![Build Status](https://travis-ci.org/SmallChi/JT808.svg?branch=master)](https://travis-ci.org/SmallChi/JT808)[![Github Build status](https://github.com/SmallChi/JT808/workflows/.NET%20Core/badge.svg)]() +[![MIT Licence](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/SmallChi/JT808/blob/master/LICENSE)[![Github Build status](https://github.com/SmallChi/JT808/workflows/.NET%20Core/badge.svg)]() ## 前提条件 diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0X8900_BodiesImpl/JT808_0X8900_Test_BodiesImpl.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0X8900_BodiesImpl/JT808_0X8900_Test_BodiesImpl.cs index 6fac8f1..3c6c6f9 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0X8900_BodiesImpl/JT808_0X8900_Test_BodiesImpl.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0X8900_BodiesImpl/JT808_0X8900_Test_BodiesImpl.cs @@ -1,20 +1,34 @@ using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessageBody; using JT808.Protocol.MessagePack; +using JT808.Protocol.Extensions; +using System.Text.Json; namespace JT808.Protocol.Test.MessageBody.JT808_0X8900_BodiesImpl { - public class JT808_0X8900_Test_BodiesImpl: JT808_0x8900_BodyBase, IJT808MessagePackFormatter + public class JT808_0X8900_Test_BodiesImpl: JT808_0x8900_BodyBase, IJT808MessagePackFormatter, IJT808Analyze { public uint Id { get; set; } public byte Sex { get; set; } + public override byte PassthroughType { get; set; } = 0x0B; + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0X8900_Test_BodiesImpl value = new JT808_0X8900_Test_BodiesImpl(); + value.Id = reader.ReadUInt32(); + writer.WriteNumber($"[{value.Id.ReadNumber()}]编号Id", value.Id); + value.Sex = reader.ReadByte(); + writer.WriteNumber($"[{value.Sex.ReadNumber()}]性别", value.Sex); + } + public JT808_0X8900_Test_BodiesImpl Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0X8900_Test_BodiesImpl jT808_0X8900_Test_BodiesImpl = new JT808_0X8900_Test_BodiesImpl(); - jT808_0X8900_Test_BodiesImpl.Id = reader.ReadUInt32(); - jT808_0X8900_Test_BodiesImpl.Sex = reader.ReadByte(); - return jT808_0X8900_Test_BodiesImpl; + JT808_0X8900_Test_BodiesImpl value = new JT808_0X8900_Test_BodiesImpl(); + value.Id = reader.ReadUInt32(); + value.Sex = reader.ReadByte(); + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0X8900_Test_BodiesImpl value, IJT808Config config) diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x0900Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x0900Test.cs index be79f1d..b3f7a9c 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x0900Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x0900Test.cs @@ -16,6 +16,7 @@ namespace JT808.Protocol.Test.MessageBody { IJT808Config jT808Config = new DefaultGlobalConfig(); jT808Config.FormatterFactory.SetMap(); + jT808Config.JT808_0x0900_Custom_Factory.SetMap(); JT808Serializer = new JT808Serializer(jT808Config); } [Fact] @@ -43,21 +44,21 @@ namespace JT808.Protocol.Test.MessageBody public void Test1_1() { byte[] bytes = "7E 09 00 00 09 00 01 23 45 67 89 00 0A 83 73 6D 61 6C 6C 63 68 69 1D 7E".ToHexBytes(); - JT808Package jT808_0X0900 = JT808Serializer.Deserialize(bytes); + JT808Package jT808_0X0900 = JT808Serializer.Deserialize(bytes); Assert.Equal(Enums.JT808MsgId.数据上行透传.ToUInt16Value(), jT808_0X0900.Header.MsgId); Assert.Equal(10, jT808_0X0900.Header.MsgNum); Assert.Equal("123456789", jT808_0X0900.Header.TerminalPhoneNo); JT808_0x0900 JT808Bodies = (JT808_0x0900)jT808_0X0900.Bodies; - JT808_0x0900_0x83 jT808_0x0900_0x83 = JT808Serializer.Deserialize(JT808Bodies.PassthroughData); + JT808_0x0900_0x83 jT808_0x0900_0x83 = (JT808_0x0900_0x83)JT808Bodies.JT808_0x0900_BodyBase; Assert.Equal("smallchi", jT808_0x0900_0x83.PassthroughContent); Assert.Equal(0x83, JT808Bodies.PassthroughType); } [Fact] - public void Test1_2() + public void Test1_3() { byte[] bytes = "7E 09 00 00 09 00 01 23 45 67 89 00 0A 83 73 6D 61 6C 6C 63 68 69 1D 7E".ToHexBytes(); - string json = JT808Serializer.Analyze(bytes); + string json = JT808Serializer.Analyze(bytes); } } } diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x0900_BodiesImpl/JT808_0x0900_0x83.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x0900_BodiesImpl/JT808_0x0900_0x83.cs index f84e61d..c00fa9a 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x0900_BodiesImpl/JT808_0x0900_0x83.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x0900_BodiesImpl/JT808_0x0900_0x83.cs @@ -1,21 +1,31 @@ using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessageBody; using JT808.Protocol.MessagePack; +using System.Text.Json; namespace JT808.Protocol.Test.JT808_0x0900_BodiesImpl { - public class JT808_0x0900_0x83 : JT808_0x0900_BodyBase,IJT808MessagePackFormatter + public class JT808_0x0900_0x83 : JT808_0x0900_BodyBase,IJT808MessagePackFormatter, IJT808Analyze { /// /// 透传内容 /// public string PassthroughContent { get; set; } + public override byte PassthroughType { get; set; } = 0x83; + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0900_0x83 value = new JT808_0x0900_0x83(); + value.PassthroughContent = reader.ReadRemainStringContent(); + writer.WriteString("透传内容", value.PassthroughContent); + } public JT808_0x0900_0x83 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0900_0x83 jT808PassthroughType0x83 = new JT808_0x0900_0x83(); - jT808PassthroughType0x83.PassthroughContent = reader.ReadRemainStringContent(); - return jT808PassthroughType0x83; + JT808_0x0900_0x83 value = new JT808_0x0900_0x83(); + value.PassthroughContent = reader.ReadRemainStringContent(); + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0900_0x83 value, IJT808Config config) diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x8900Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x8900Test.cs index 7763816..c2df660 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x8900Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x8900Test.cs @@ -16,6 +16,7 @@ namespace JT808.Protocol.Test.MessageBody { IJT808Config jT808Config = new DefaultGlobalConfig(); jT808Config.FormatterFactory.SetMap(); + jT808Config.JT808_0x8900_Custom_Factory.SetMap(); JT808Serializer = new JT808Serializer(jT808Config); } [Fact] @@ -39,7 +40,7 @@ namespace JT808.Protocol.Test.MessageBody { byte[] bytes = "0B0000303901".ToHexBytes(); JT808_0x8900 jT808_0X8900 = JT808Serializer.Deserialize(bytes); - JT808_0X8900_Test_BodiesImpl jT808_0X8900_Test_BodiesImpl = JT808Serializer.Deserialize(jT808_0X8900.PassthroughData); + JT808_0X8900_Test_BodiesImpl jT808_0X8900_Test_BodiesImpl = (JT808_0X8900_Test_BodiesImpl)jT808_0X8900.JT808_0X8900_BodyBase; Assert.Equal(0x0B, jT808_0X8900.PassthroughType); Assert.Equal((uint)12345, jT808_0X8900_Test_BodiesImpl.Id); Assert.Equal(0x01, jT808_0X8900_Test_BodiesImpl.Sex); diff --git a/src/JT808.Protocol/Extensions/JT808AnalyzeExtensions.cs b/src/JT808.Protocol/Extensions/JT808AnalyzeExtensions.cs index f7109e6..dc339b6 100644 --- a/src/JT808.Protocol/Extensions/JT808AnalyzeExtensions.cs +++ b/src/JT808.Protocol/Extensions/JT808AnalyzeExtensions.cs @@ -17,7 +17,7 @@ namespace JT808.Protocol.Extensions } else { - throw new NotImplementedException($"{instance.GetType().FullName} {nameof(IJT808Analyze)}"); + throw new NotImplementedException($"Not Implemented {instance.GetType().FullName} {nameof(IJT808Analyze)}"); } } } diff --git a/src/JT808.Protocol/Interfaces/GlobalConfigBase.cs b/src/JT808.Protocol/Interfaces/GlobalConfigBase.cs index 47d9152..defff86 100644 --- a/src/JT808.Protocol/Interfaces/GlobalConfigBase.cs +++ b/src/JT808.Protocol/Interfaces/GlobalConfigBase.cs @@ -23,6 +23,8 @@ namespace JT808.Protocol.Interfaces JT808_0X0200_Factory = new JT808_0x0200_Factory(); JT808_0X8103_Custom_Factory = new JT808_0x8103_Custom_Factory(); JT808_0X8103_Factory = new JT808_0x8103_Factory(); + JT808_0x0900_Custom_Factory = new JT808_0x0900_Custom_Factory(); + JT808_0x8900_Custom_Factory = new JT808_0x8900_Custom_Factory(); TerminalPhoneNoLength = 12; Trim = true; } @@ -40,6 +42,8 @@ namespace JT808.Protocol.Interfaces public virtual IJT808_0x8103_Factory JT808_0X8103_Factory { get; set; } public virtual int TerminalPhoneNoLength { get; set; } public virtual bool Trim { get; set; } + public virtual IJT808_0x0900_Custom_Factory JT808_0x0900_Custom_Factory { get; set; } + public virtual IJT808_0x8900_Custom_Factory JT808_0x8900_Custom_Factory { get; set; } public virtual IJT808Config Register(params Assembly[] externalAssemblies) { if (externalAssemblies != null) @@ -52,6 +56,8 @@ namespace JT808.Protocol.Interfaces JT808_0X0200_Custom_Factory.Register(easb); JT808_0X8103_Factory.Register(easb); JT808_0X8103_Custom_Factory.Register(easb); + JT808_0x0900_Custom_Factory.Register(easb); + JT808_0x8900_Custom_Factory.Register(easb); } } return this; diff --git a/src/JT808.Protocol/Interfaces/IJT808Config.cs b/src/JT808.Protocol/Interfaces/IJT808Config.cs index a1d9d7b..6a83124 100644 --- a/src/JT808.Protocol/Interfaces/IJT808Config.cs +++ b/src/JT808.Protocol/Interfaces/IJT808Config.cs @@ -49,6 +49,14 @@ namespace JT808.Protocol /// IJT808_0x8103_Factory JT808_0X8103_Factory { get; set; } /// + ///数据上行透传工厂 + /// + IJT808_0x0900_Custom_Factory JT808_0x0900_Custom_Factory { get; set; } + /// + ///数据下行透传工厂 + /// + IJT808_0x8900_Custom_Factory JT808_0x8900_Custom_Factory { get; set; } + /// /// 统一编码 /// Encoding Encoding { get; set; } diff --git a/src/JT808.Protocol/Interfaces/IJT808_0x0900_Custom_Factory.cs b/src/JT808.Protocol/Interfaces/IJT808_0x0900_Custom_Factory.cs new file mode 100644 index 0000000..e7bc91c --- /dev/null +++ b/src/JT808.Protocol/Interfaces/IJT808_0x0900_Custom_Factory.cs @@ -0,0 +1,13 @@ +using JT808.Protocol.MessageBody; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT808.Protocol.Interfaces +{ + public interface IJT808_0x0900_Custom_Factory : IJT808ExternalRegister + { + IDictionary Map { get; } + IJT808_0x0900_Custom_Factory SetMap() where TJT808_0x0900_BodyBase : JT808_0x0900_BodyBase; + } +} diff --git a/src/JT808.Protocol/Interfaces/IJT808_0x8900_Custom_Factory.cs b/src/JT808.Protocol/Interfaces/IJT808_0x8900_Custom_Factory.cs new file mode 100644 index 0000000..7a36f88 --- /dev/null +++ b/src/JT808.Protocol/Interfaces/IJT808_0x8900_Custom_Factory.cs @@ -0,0 +1,13 @@ +using JT808.Protocol.MessageBody; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT808.Protocol.Interfaces +{ + public interface IJT808_0x8900_Custom_Factory : IJT808ExternalRegister + { + IDictionary Map { get; } + IJT808_0x8900_Custom_Factory SetMap() where TJT808_0x8900_BodyBase : JT808_0x8900_BodyBase; + } +} diff --git a/src/JT808.Protocol/Internal/JT808_0x0900_Custom_Factory.cs b/src/JT808.Protocol/Internal/JT808_0x0900_Custom_Factory.cs new file mode 100644 index 0000000..fa583cb --- /dev/null +++ b/src/JT808.Protocol/Internal/JT808_0x0900_Custom_Factory.cs @@ -0,0 +1,54 @@ +using JT808.Protocol.Interfaces; +using JT808.Protocol.MessageBody; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; + +namespace JT808.Protocol.Internal +{ + class JT808_0x0900_Custom_Factory : IJT808_0x0900_Custom_Factory + { + public IDictionary Map { get; } + + public JT808_0x0900_Custom_Factory() + { + Map = new Dictionary(); + } + + public void Register(Assembly externalAssembly) + { + var types = externalAssembly.GetTypes().Where(w => w.BaseType == typeof(JT808_0x0200_CustomBodyBase)).ToList(); + foreach(var type in types) + { + var instance = Activator.CreateInstance(type); + var attachid = (byte)type.GetProperty(nameof(JT808_0x0200_CustomBodyBase.AttachInfoId)).GetValue(instance); + if (Map.ContainsKey(attachid)) + { + throw new ArgumentException($"{type.FullName} {attachid} An element with the same key already exists."); + } + else + { + Map.Add(attachid, instance); + } + } + } + + public IJT808_0x0900_Custom_Factory SetMap() where TJT808_0x0900_Custom_Factory : JT808_0x0900_BodyBase + { + Type type = typeof(TJT808_0x0900_Custom_Factory); + var instance = Activator.CreateInstance(type); + var passthroughType = (byte)type.GetProperty(nameof(JT808_0x0900_BodyBase.PassthroughType)).GetValue(instance); + if (Map.ContainsKey(passthroughType)) + { + throw new ArgumentException($"{type.FullName} {passthroughType} An element with the same key already exists."); + } + else + { + Map.Add(passthroughType, instance); + } + return this; + } + } +} diff --git a/src/JT808.Protocol/Internal/JT808_0x8900_Custom_Factory.cs b/src/JT808.Protocol/Internal/JT808_0x8900_Custom_Factory.cs new file mode 100644 index 0000000..8140ad2 --- /dev/null +++ b/src/JT808.Protocol/Internal/JT808_0x8900_Custom_Factory.cs @@ -0,0 +1,54 @@ +using JT808.Protocol.Interfaces; +using JT808.Protocol.MessageBody; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; + +namespace JT808.Protocol.Internal +{ + class JT808_0x8900_Custom_Factory : IJT808_0x8900_Custom_Factory + { + public IDictionary Map { get; } + + public JT808_0x8900_Custom_Factory() + { + Map = new Dictionary(); + } + + public void Register(Assembly externalAssembly) + { + var types = externalAssembly.GetTypes().Where(w => w.BaseType == typeof(JT808_0x0200_CustomBodyBase)).ToList(); + foreach(var type in types) + { + var instance = Activator.CreateInstance(type); + var attachid = (byte)type.GetProperty(nameof(JT808_0x0200_CustomBodyBase.AttachInfoId)).GetValue(instance); + if (Map.ContainsKey(attachid)) + { + throw new ArgumentException($"{type.FullName} {attachid} An element with the same key already exists."); + } + else + { + Map.Add(attachid, instance); + } + } + } + + public IJT808_0x8900_Custom_Factory SetMap() where TJT808_0x8900_Custom_Factory : JT808_0x8900_BodyBase + { + Type type = typeof(TJT808_0x8900_Custom_Factory); + var instance = Activator.CreateInstance(type); + var passthroughType = (byte)type.GetProperty(nameof(JT808_0x8900_BodyBase.PassthroughType)).GetValue(instance); + if (Map.ContainsKey(passthroughType)) + { + throw new ArgumentException($"{type.FullName} {passthroughType} An element with the same key already exists."); + } + else + { + Map.Add(passthroughType, instance); + } + return this; + } + } +} diff --git a/src/JT808.Protocol/JT808.Protocol.csproj b/src/JT808.Protocol/JT808.Protocol.csproj index 5ea26a5..2f09328 100644 --- a/src/JT808.Protocol/JT808.Protocol.csproj +++ b/src/JT808.Protocol/JT808.Protocol.csproj @@ -14,7 +14,7 @@ https://github.com/SmallChi/JT808/blob/master/LICENSE https://github.com/SmallChi/JT808/blob/master/LICENSE false - 2.2.6 + 2.2.7 LICENSE diff --git a/src/JT808.Protocol/JT808.Protocol.xml b/src/JT808.Protocol/JT808.Protocol.xml index c1b8476..08ef5ba 100644 --- a/src/JT808.Protocol/JT808.Protocol.xml +++ b/src/JT808.Protocol/JT808.Protocol.xml @@ -2654,6 +2654,16 @@ 设置终端参数工厂 + + + 数据上行透传工厂 + + + + + 数据下行透传工厂 + + 统一编码 @@ -4243,6 +4253,11 @@ 数据上行透传 + + + 透传消息类型 + + 数据压缩上报 @@ -6678,6 +6693,12 @@ 数据下行透传 + + + 透传消息类型 + 透传消息类型定义见 表 93 + + 平台RSA公钥 diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0900.cs b/src/JT808.Protocol/MessageBody/JT808_0x0900.cs index 496ca88..93322af 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0900.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0900.cs @@ -31,19 +31,41 @@ namespace JT808.Protocol.MessageBody public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { - //todo:待扩展完善 JT808_0x0900 value = new JT808_0x0900(); value.PassthroughType = reader.ReadByte(); writer.WriteNumber($"[{value.PassthroughType.ReadNumber()}]透传消息类型", value.PassthroughType); - value.PassthroughData = reader.ReadContent().ToArray(); - writer.WriteString("透传消息内容", value.PassthroughData.ToHexString()); + if (config.JT808_0x0900_Custom_Factory.Map.TryGetValue(value.PassthroughType, out var instance)) + { + writer.WriteStartObject("数据上行对象"); + try + { + instance.Analyze(ref reader, writer, config); + } + catch (System.Exception ex) + { + writer.WriteString("错误信息", $"{ex.Message}-{ex.StackTrace}"); + } + writer.WriteEndObject(); + } + else + { + value.PassthroughData = reader.ReadContent().ToArray(); + writer.WriteString("透传消息内容", value.PassthroughData.ToHexString()); + } } public JT808_0x0900 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { JT808_0x0900 value = new JT808_0x0900(); value.PassthroughType = reader.ReadByte(); - value.PassthroughData = reader.ReadContent().ToArray(); + if(config.JT808_0x0900_Custom_Factory.Map.TryGetValue(value.PassthroughType,out var instance)) + { + value.JT808_0x0900_BodyBase = JT808MessagePackFormatterResolverExtensions.JT808DynamicDeserialize(instance, ref reader, config); + } + else + { + value.PassthroughData = reader.ReadContent().ToArray(); + } return value; } diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0900_BodyBase.cs b/src/JT808.Protocol/MessageBody/JT808_0x0900_BodyBase.cs index 4c99af1..1e3604c 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0900_BodyBase.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0900_BodyBase.cs @@ -5,6 +5,9 @@ /// public abstract class JT808_0x0900_BodyBase { - + /// + /// 透传消息类型 + /// + public abstract byte PassthroughType { get; set; } } } diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8900.cs b/src/JT808.Protocol/MessageBody/JT808_0x8900.cs index 39ddc4f..0dc56e0 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x8900.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x8900.cs @@ -31,10 +31,17 @@ namespace JT808.Protocol.MessageBody public JT808_0x8900 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x8900 jT808_0X8900 = new JT808_0x8900(); - jT808_0X8900.PassthroughType = reader.ReadByte(); - jT808_0X8900.PassthroughData = reader.ReadContent().ToArray(); - return jT808_0X8900; + JT808_0x8900 value = new JT808_0x8900(); + value.PassthroughType = reader.ReadByte(); + if (config.JT808_0x8900_Custom_Factory.Map.TryGetValue(value.PassthroughType, out var instance)) + { + value.JT808_0X8900_BodyBase = JT808MessagePackFormatterResolverExtensions.JT808DynamicDeserialize(instance, ref reader, config); + } + else + { + value.PassthroughData = reader.ReadContent().ToArray(); + } + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8900 value, IJT808Config config) @@ -45,11 +52,26 @@ namespace JT808.Protocol.MessageBody public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { - JT808_0x8900 jT808_0X8900 = new JT808_0x8900(); - jT808_0X8900.PassthroughType = reader.ReadByte(); - jT808_0X8900.PassthroughData = reader.ReadContent().ToArray(); - writer.WriteNumber($"[{jT808_0X8900.PassthroughType.ReadNumber()}]透传消息类型", jT808_0X8900.PassthroughType); - writer.WriteString($"透传消息内容", jT808_0X8900.PassthroughData.ToHexString()); + JT808_0x8900 value = new JT808_0x8900(); + value.PassthroughType = reader.ReadByte(); + if (config.JT808_0x8900_Custom_Factory.Map.TryGetValue(value.PassthroughType, out var instance)) + { + writer.WriteStartObject("数据下行对象"); + try + { + instance.Analyze(ref reader, writer, config); + } + catch (System.Exception ex) + { + writer.WriteString("错误信息", $"{ex.Message}-{ex.StackTrace}"); + } + writer.WriteEndObject(); + } + else + { + value.PassthroughData = reader.ReadContent().ToArray(); + writer.WriteString("透传消息内容", value.PassthroughData.ToHexString()); + } } } } diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8900_BodyBase.cs b/src/JT808.Protocol/MessageBody/JT808_0x8900_BodyBase.cs index 9f62c87..dfcf263 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x8900_BodyBase.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x8900_BodyBase.cs @@ -5,6 +5,10 @@ /// public abstract class JT808_0x8900_BodyBase { - + /// + /// 透传消息类型 + /// 透传消息类型定义见 表 93 + /// + public abstract byte PassthroughType { get; set; } } }