From d537a1eb038fa91f302cc13a6a3b93c98ed38ab1 Mon Sep 17 00:00:00 2001 From: "smallchi(Koike)" <564952747@qq.com> Date: Tue, 21 Jan 2020 23:33:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8D=8F=E8=AE=AE=E5=88=86?= =?UTF-8?q?=E6=9E=90=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 +- .../MessageBody/JT808_0x0200Test.cs | 7 ++ .../MessageBody/JT808_0x0201Test.cs | 7 ++ .../MessageBody/JT808_0x0500Test.cs | 7 ++ .../MessageBody/JT808_0x0608Test.cs | 35 +++++++ .../MessageBody/JT808_0x0701Test.cs | 7 ++ .../MessageBody/JT808_0x0702Test.cs | 7 ++ .../MessageBody/JT808_0x0704Test.cs | 6 ++ .../MessageBody/JT808_0x0705Test.cs | 7 ++ .../MessageBody/JT808_0x0800Test.cs | 7 ++ .../MessageBody/JT808_0x0801Test.cs | 7 ++ .../MessageBody/JT808_0x0802Test.cs | 7 ++ .../MessageBody/JT808_0x0805Test.cs | 7 ++ .../MessageBody/JT808_0x0900Test.cs | 7 ++ .../MessageBody/JT808_0x0901Test.cs | 7 ++ .../JT808_0x8103_0x0075.cs | 38 +++++++- .../MessageBody/JT808_0x8103Test.cs | 14 ++- .../MessageBody/JT808_0x8105Test.cs | 4 +- .../Extensions/JT808AnalyzeExtensions.cs | 24 +++++ src/JT808.Protocol/JT808.Protocol.xml | 4 +- .../MessageBody/JT808_0x0200.cs | 96 ++++++++++++++++++- .../MessageBody/JT808_0x0200_0x01.cs | 29 ++++-- .../MessageBody/JT808_0x0200_0x02.cs | 28 ++++-- .../MessageBody/JT808_0x0200_0x03.cs | 29 ++++-- .../MessageBody/JT808_0x0200_0x04.cs | 26 +++-- .../MessageBody/JT808_0x0200_0x05.cs | 15 ++- .../MessageBody/JT808_0x0200_0x06.cs | 15 ++- .../MessageBody/JT808_0x0200_0x11.cs | 35 +++++-- .../MessageBody/JT808_0x0200_0x12.cs | 34 +++++-- .../MessageBody/JT808_0x0200_0x13.cs | 35 +++++-- .../MessageBody/JT808_0x0200_0x25.cs | 29 ++++-- .../MessageBody/JT808_0x0200_0x2A.cs | 28 ++++-- .../MessageBody/JT808_0x0200_0x2B.cs | 27 ++++-- .../MessageBody/JT808_0x0200_0x30.cs | 27 ++++-- .../MessageBody/JT808_0x0200_0x31.cs | 29 ++++-- .../MessageBody/JT808_0x0201.cs | 18 +++- .../MessageBody/JT808_0x0303.cs | 18 ++-- .../MessageBody/JT808_0x0500.cs | 26 +++-- .../MessageBody/JT808_0x0608.cs | 82 +++++++++++++++- .../MessageBody/JT808_0x0701.cs | 22 ++++- .../MessageBody/JT808_0x0702.cs | 73 ++++++++++---- .../MessageBody/JT808_0x0704.cs | 37 ++++++- .../MessageBody/JT808_0x0705.cs | 44 +++++++-- .../MessageBody/JT808_0x0800.cs | 38 ++++++-- .../MessageBody/JT808_0x0801.cs | 46 ++++++--- .../MessageBody/JT808_0x0802.cs | 50 ++++++++-- .../MessageBody/JT808_0x0805.cs | 57 ++++++++--- .../MessageBody/JT808_0x0900.cs | 21 +++- .../MessageBody/JT808_0x0901.cs | 27 +++++- .../MessageBody/JT808_0x0A00.cs | 27 +++++- .../MessageBody/JT808_0x8103.cs | 43 ++++++++- .../MessageBody/JT808_0x8105.cs | 6 +- 52 files changed, 1125 insertions(+), 208 deletions(-) create mode 100644 src/JT808.Protocol/Extensions/JT808AnalyzeExtensions.cs diff --git a/README.md b/README.md index f395b81..39d24ce 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,10 @@ 2. 掌握BCD编码、Hex编码; 3. 掌握各种位移、异或; 4. 掌握常用反射; -5. 掌握快速ctrl+c、ctrl+v; -6. 掌握Span\的基本用法 -7. 掌握以上装逼技能,就可以开始搬砖了。 +5. 掌握JObject的用法; +6. 掌握快速ctrl+c、ctrl+v; +7. 掌握Span\的基本用法 +8. 掌握以上装逼技能,就可以开始搬砖了。 ## JT808数据结构解析 diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x0200Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x0200Test.cs index 86c6a04..d23ca2b 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x0200Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x0200Test.cs @@ -138,6 +138,13 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal(55, ((JT808_0x0200_0x02)jT808UploadLocationRequest.JT808LocationAttachData[JT808Constants.JT808_0x0200_0x02]).Oil); } + [Fact] + public void Test2_1() + { + byte[] bodys = "00 00 00 01 00 00 00 02 00 BA 7F 0E 07 E4 F1 1C 00 28 00 3C 00 00 18 07 15 10 10 10 01 04 00 00 00 64 02 02 00 37".ToHexBytes(); + string json = JT808Serializer.Analyze(bodys); + } + [Fact] public void Test3() { diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x0201Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x0201Test.cs index c48da07..d1d5f4a 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x0201Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x0201Test.cs @@ -68,5 +68,12 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal(100, ((JT808_0x0200_0x01)jT808_0X0201.Position.JT808LocationAttachData[JT808Constants.JT808_0x0200_0x01]).Mileage); Assert.Equal(55, ((JT808_0x0200_0x02)jT808_0X0201.Position.JT808LocationAttachData[JT808Constants.JT808_0x0200_0x02]).Oil); } + + [Fact] + public void Test3() + { + byte[] bytes = "7E0201002811223344556622B83039000000010000000200BA7F0E07E4F11C0028003C000018071510101001040000006402020037517E".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes); + } } } diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x0500Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x0500Test.cs index 868fda4..f7c8e62 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x0500Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x0500Test.cs @@ -70,5 +70,12 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal(100, ((JT808_0x0200_0x01)JT808Bodies.JT808_0x0200.JT808LocationAttachData[JT808Constants.JT808_0x0200_0x01]).Mileage); Assert.Equal(55, ((JT808_0x0200_0x02)JT808Bodies.JT808_0x0200.JT808LocationAttachData[JT808Constants.JT808_0x0200_0x02]).Oil); } + + [Fact] + public void Test3() + { + byte[] bytes = "7E0500002811223344556622B803E8000000010000000200BA7F0E07E4F11C0028003C000018071510101001040000006402020037B57E".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes); + } } } diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x0608Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x0608Test.cs index b516202..a4c35e1 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x0608Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x0608Test.cs @@ -36,6 +36,13 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal(3u, value.Ids[2]); } + [Fact] + public void Test3() + { + byte[] bytes = "0500000003000000010000000200000003".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes); + } + [Fact] public void Test_JT808_0X8600s_1() { @@ -95,6 +102,13 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal("SmallChi", item0.AreaName); } + [Fact] + public void Test_JT808_0X8600s_3() + { + byte[] bytes = "01000000010101000005F200DE075BCD15075BCD15000000C8003CC8029A0008536D616C6C436869".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes, JT808Version.JTT2019); + } + [Fact] public void Test_JT808_0X8602s_1() { @@ -155,6 +169,13 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal("smallchi", item0.AreaName); } + [Fact] + public void Test_JT808_0X8602s_3() + { + byte[] bytes = "02000000010101000005F200DE075BCD13075BCD12075BCD15075BCD14003CC800000008736D616C6C636869".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes, JT808Version.JTT2019); + } + [Fact] public void Test_JT808_0x8604s_1() { @@ -215,6 +236,13 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal("smallchi", jT808_0X8604.AreaName); } + [Fact] + public void Test_JT808_0X8604s_3() + { + byte[] bytes = "0300000001000004D200012001070000122001070000130002075BCD15075BCD14075BCCBC075BCCBD0008736D616C6C636869".ToHexBytes(); + string value = JT808Serializer.Analyze(bytes, JT808Version.JTT2019); + } + [Fact] public void Test_JT808_0x8606s_1() { @@ -284,5 +312,12 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal("koike518", jT808_0X8606.RouteName); } + + [Fact] + public void Test_JT808_0X8606s_3() + { + byte[] bytes = "04000000010000270F00332001070000122001070000120001000003E800000507075BCD15075BCD1438030032007B004517005000086B6F696B65353138".ToHexBytes(); + string value = JT808Serializer.Analyze(bytes, JT808Version.JTT2019); + } } } diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x0701Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x0701Test.cs index a9e52c9..9f7b0be 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x0701Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x0701Test.cs @@ -43,5 +43,12 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal("汉smallchi", jT808_0X0701_content.UserName); Assert.Equal(10, jT808_0X0701_content.UserNameLength); } + + [Fact] + public void Test3() + { + byte[] bytes = "000000100000014D000ABABA736D616C6C636869".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes); + } } } diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x0702Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x0702Test.cs index 5c3cbe3..5bf9654 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x0702Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x0702Test.cs @@ -118,5 +118,12 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal(DateTime.Parse("2019-12-01"), jT808_0X0702.CertificateExpiresDate); Assert.Equal("12345678901234567000", jT808_0X0702.DriverIdentityCard); } + + [Fact] + public void Test_2019_3() + { + byte[] bytes = "0119120111111100056B6F696B65717765313233343536616161303030303030303006717765727478201912013132333435363738393031323334353637303030".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes, JT808Version.JTT2019); + } } } diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x0704Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x0704Test.cs index 7870eb5..b54e028 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x0704Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x0704Test.cs @@ -151,5 +151,11 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal(96, ((JT808_0x0200_0x01)JT808Bodies.Positions[1].JT808LocationAttachData[JT808Constants.JT808_0x0200_0x01]).Mileage); Assert.Equal(66, ((JT808_0x0200_0x02)JT808Bodies.Positions[1].JT808LocationAttachData[JT808Constants.JT808_0x0200_0x02]).Oil); } + [Fact] + public void Test3() + { + byte[] bytes = "7E 07 04 00 53 11 22 33 44 55 66 22 B8 00 02 00 00 26 00 00 00 01 00 00 00 02 00 BA 7F 0E 07 E4 F1 1C 00 28 00 3C 00 00 18 07 15 10 10 10 01 04 00 00 00 64 02 02 00 37 00 26 00 00 00 02 00 00 00 01 00 CB 73 55 07 E6 A3 23 00 29 00 36 00 78 18 07 15 10 10 30 01 04 00 00 00 60 02 02 00 42 D4 7E".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes); + } } } diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x0705Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x0705Test.cs index 5d76557..4353e8d 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x0705Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x0705Test.cs @@ -48,5 +48,12 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal(0x05060708u , jT808_0X0705.CanItems[1].CanId); Assert.Equal(new byte[] { 0x01, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01 }, jT808_0X0705.CanItems[1].CanData); } + + [Fact] + public void Test3() + { + byte[] bytes = "00022000050350001203040102030401020304050607080103040506070801".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes); + } } } diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x0800Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x0800Test.cs index 3b689b1..86d62dd 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x0800Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x0800Test.cs @@ -33,5 +33,12 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal(0x06, jT808_0X0800.ChannelId); Assert.Equal(0x01, jT808_0X0800.EventItemCoding); } + + [Fact] + public void Test3() + { + var bytes = "000015C101020106".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes); + } } } diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x0801Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x0801Test.cs index d4cf183..b1e2667 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x0801Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x0801Test.cs @@ -70,6 +70,13 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal((uint)2, jT808_0X0801.Position.StatusFlag); } + [Fact] + public void Test3() + { + byte[] bytes = "00000A070000017B000000010000000200BA7F0E07E4F11C0028003C000018111523261001020304".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes); + } + [Fact] public void Package1() { diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x0802Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x0802Test.cs index 672214e..0813048 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x0802Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x0802Test.cs @@ -99,5 +99,12 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal((ushort)0, jT808_0X0802.MultimediaSearchItems[1].Position.Direction); Assert.Equal((uint)2, jT808_0X0802.MultimediaSearchItems[1].Position.StatusFlag); } + + [Fact] + public void Test3() + { + byte[] bytes = "3051000200000102007B01000000010000000200BA7F0E07E4F11C0028003C000018111620202000000103027C00000000010000000200BA7F0E07E4F11C0028003C0000181116222222".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes); + } } } diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x0805Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x0805Test.cs index fa9999c..4b42630 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x0805Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x0805Test.cs @@ -37,5 +37,12 @@ namespace JT808.Protocol.Test.MessageBody 12580 }, jT808_0X0805.MultimediaIds); } + + [Fact] + public void Test3() + { + byte[] bytes = "30A80000020000301200003124".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes); + } } } diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x0900Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x0900Test.cs index 8a4f599..be79f1d 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x0900Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x0900Test.cs @@ -52,5 +52,12 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal("smallchi", jT808_0x0900_0x83.PassthroughContent); Assert.Equal(0x83, JT808Bodies.PassthroughType); } + + [Fact] + public void Test1_2() + { + 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); + } } } diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x0901Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x0901Test.cs index 0cfed39..bc2a6c4 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x0901Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x0901Test.cs @@ -37,5 +37,12 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal((uint)88, jT808_0X8600.UnCompressMessageLength); Assert.Equal(Encoding.UTF8.GetBytes(UserName), jT808_0X8600.UnCompressMessage); } + + [Fact] + public void Test3() + { + byte[] bytes = "0000001F1F8B080000000000000B2BCE4DCCC949CEC82CA6320D0027F897E258000000".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes); + } } } diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x8103CustomIdExtensions/JT808_0x8103_0x0075.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x8103CustomIdExtensions/JT808_0x8103_0x0075.cs index 6028518..348ffae 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x8103CustomIdExtensions/JT808_0x8103_0x0075.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x8103CustomIdExtensions/JT808_0x8103_0x0075.cs @@ -1,10 +1,13 @@ using JT808.Protocol.Attributes; using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; +using JT808.Protocol.Extensions; using JT808.Protocol.MessageBody; using JT808.Protocol.MessagePack; using System; using System.Collections.Generic; using System.Text; +using System.Text.Json; namespace JT808.Protocol.Test.MessageBody.JT808_0x8103CustomIdExtensions { @@ -12,7 +15,7 @@ namespace JT808.Protocol.Test.MessageBody.JT808_0x8103CustomIdExtensions /// 音视频参数设置 /// 0x8103_0x0075 /// - public class JT808_0x8103_0x0075 : JT808_0x8103_CustomBodyBase, IJT808MessagePackFormatter + public class JT808_0x8103_0x0075 : JT808_0x8103_CustomBodyBase, IJT808MessagePackFormatter,IJT808Analyze { public override uint ParamId { get; set; } = 0x0075; /// @@ -74,6 +77,39 @@ namespace JT808.Protocol.Test.MessageBody.JT808_0x8103CustomIdExtensions /// public byte AudioOutputEnabled { get; set; } + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x8103_0x0075 value = new JT808_0x8103_0x0075(); + value.ParamId = reader.ReadUInt32(); + writer.WriteNumber($"[{value.ParamId.ReadNumber()}]参数Id", value.ParamId); + value.ParamLength = reader.ReadByte(); + writer.WriteNumber($"[{value.ParamLength.ReadNumber()}]数据长度", value.ParamLength); + value.RTS_EncodeMode = reader.ReadByte(); + writer.WriteNumber($"[{value.RTS_EncodeMode.ReadNumber()}]实时流编码模式", value.RTS_EncodeMode); + value.RTS_Resolution = reader.ReadByte(); + writer.WriteNumber($"[{value.RTS_Resolution.ReadNumber()}]实时流分辨率", value.RTS_Resolution); + value.RTS_KF_Interval = reader.ReadUInt16(); + writer.WriteNumber($"[{value.RTS_KF_Interval.ReadNumber()}]实时流关键帧间隔", value.RTS_KF_Interval); + value.RTS_Target_FPS = reader.ReadByte(); + writer.WriteNumber($"[{value.RTS_Target_FPS.ReadNumber()}]实时流目标帧率", value.RTS_Target_FPS); + value.RTS_Target_CodeRate = reader.ReadUInt32(); + writer.WriteNumber($"[{value.RTS_Target_CodeRate.ReadNumber()}]实时流目标码率", value.RTS_Target_CodeRate); + value.StreamStore_EncodeMode = reader.ReadByte(); + writer.WriteNumber($"[{value.StreamStore_EncodeMode.ReadNumber()}]存储流编码模式", value.StreamStore_EncodeMode); + value.StreamStore_Resolution = reader.ReadByte(); + writer.WriteNumber($"[{value.StreamStore_Resolution.ReadNumber()}]存储流分辨率", value.StreamStore_Resolution); + value.StreamStore_KF_Interval = reader.ReadUInt16(); + writer.WriteNumber($"[{value.StreamStore_KF_Interval.ReadNumber()}]存储流关键帧间隔", value.StreamStore_KF_Interval); + value.StreamStore_Target_FPS = reader.ReadByte(); + writer.WriteNumber($"[{value.StreamStore_Target_FPS.ReadNumber()}]存储流目标帧率", value.StreamStore_Target_FPS); + value.StreamStore_Target_CodeRate = reader.ReadUInt32(); + writer.WriteNumber($"[{value.StreamStore_Target_CodeRate.ReadNumber()}]存储流目标码率", value.StreamStore_Target_CodeRate); + value.OSD = reader.ReadUInt16(); + writer.WriteNumber($"[{value.OSD.ReadNumber()}]OSD字幕叠加设置", value.OSD); + value.AudioOutputEnabled = reader.ReadByte(); + writer.WriteNumber($"[{value.AudioOutputEnabled.ReadNumber()}]是否启用音频输出", value.AudioOutputEnabled); + } + public JT808_0x8103_0x0075 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { JT808_0x8103_0x0075 jT808_0X8103_0X0075 = new JT808_0x8103_0x0075(); diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x8103Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x8103Test.cs index 37ed118..bfda7fb 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x8103Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x8103Test.cs @@ -75,7 +75,6 @@ namespace JT808.Protocol.Test.MessageBody } } - [Fact] public void Test2() { @@ -123,6 +122,13 @@ namespace JT808.Protocol.Test.MessageBody } } + [Fact] + public void Test2_2() + { + byte[] bytes = "0200000001040000000A000000130D7777772E62616964752E636F6D".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes); + } + [Fact] public void Test3() { @@ -163,6 +169,12 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal(customParams, Newtonsoft.Json.JsonConvert.SerializeObject(jT808_0X8103.CustomParamList)); } + [Fact] + public void Test3_2() + { + byte[] bytes = "010000007515030500040700000006080A00090C0000000B000201".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes); + } } } diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x8105Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x8105Test.cs index 72f2bc5..3e5a6f7 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x8105Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x8105Test.cs @@ -32,7 +32,7 @@ namespace JT808.Protocol.Test.MessageBody FirmwareVersion = "1.0", HardwareVersion = "2.0", ConnectTimeLimit = 60, - ManufacturerCode = 12345, + MakerId = "12345", MonitoringPlatformAuthenticationCode = "code", ServerUrl = "www.baidu.com", TCPPort = 8806, @@ -61,7 +61,7 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal(8806, (int)JT808_0x8105.CommandValue.TCPPort); Assert.Equal("www.baidu.com", JT808_0x8105.CommandValue.ServerUrl); Assert.Equal("code", JT808_0x8105.CommandValue.MonitoringPlatformAuthenticationCode); - Assert.Equal(12345, JT808_0x8105.CommandValue.ManufacturerCode); + Assert.Equal("12345", JT808_0x8105.CommandValue.MakerId); Assert.Equal("2.0", JT808_0x8105.CommandValue.HardwareVersion); Assert.Equal("1.0", JT808_0x8105.CommandValue.FirmwareVersion); Assert.Equal("TK", JT808_0x8105.CommandValue.DialUserName); diff --git a/src/JT808.Protocol/Extensions/JT808AnalyzeExtensions.cs b/src/JT808.Protocol/Extensions/JT808AnalyzeExtensions.cs new file mode 100644 index 0000000..f7109e6 --- /dev/null +++ b/src/JT808.Protocol/Extensions/JT808AnalyzeExtensions.cs @@ -0,0 +1,24 @@ +using JT808.Protocol.Interfaces; +using JT808.Protocol.MessagePack; +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.Json; + +namespace JT808.Protocol.Extensions +{ + public static class JT808AnalyzeExtensions + { + public static void Analyze(this object instance, ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + if(instance is IJT808Analyze analyze) + { + analyze.Analyze(ref reader, writer, config); + } + else + { + throw new NotImplementedException($"{instance.GetType().FullName} {nameof(IJT808Analyze)}"); + } + } + } +} diff --git a/src/JT808.Protocol/JT808.Protocol.xml b/src/JT808.Protocol/JT808.Protocol.xml index 98b5486..c1b8476 100644 --- a/src/JT808.Protocol/JT808.Protocol.xml +++ b/src/JT808.Protocol/JT808.Protocol.xml @@ -4014,7 +4014,7 @@ - 发证机构名称长度 + 发证机构名称 @@ -5811,7 +5811,7 @@ UDP端口 - + 制造商ID 终端制造商编码 diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200.cs index 11c844b..319d1ce 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0200.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0200.cs @@ -2,16 +2,18 @@ using JT808.Protocol.Exceptions; using JT808.Protocol.Extensions; using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; using System; using System.Collections.Generic; +using System.Text.Json; namespace JT808.Protocol.MessageBody { /// /// 位置信息汇报 /// - public class JT808_0x0200 : JT808Bodies, IJT808MessagePackFormatter + public class JT808_0x0200 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze { public override ushort MsgId { get; } = 0x0200; public override string Description => "位置信息汇报"; @@ -200,5 +202,97 @@ namespace JT808.Protocol.MessageBody } } } + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200 value = new JT808_0x0200(); + value.AlarmFlag = reader.ReadUInt32(); + writer.WriteNumber($"[{value.AlarmFlag.ReadNumber()}]报警标志", value.AlarmFlag); + value.StatusFlag = reader.ReadUInt32(); + writer.WriteNumber($"[{value.StatusFlag.ReadNumber()}]状态位标志", value.StatusFlag); + if (((value.StatusFlag >> 28) & 1) == 1) + { //南纬 268435456 0x10000000 + value.Lat = (int)reader.ReadUInt32(); + writer.WriteNumber($"[{value.Lat.ReadNumber()}]纬度", value.Lat); + } + else + { + value.Lat = reader.ReadInt32(); + writer.WriteNumber($"[{value.Lat.ReadNumber()}]纬度", value.Lat); + } + if (((value.StatusFlag >> 27) & 1) == 1) + { //西经 ‭134217728‬ 0x8000000 + value.Lng = (int)reader.ReadUInt32(); + writer.WriteNumber($"[{value.Lng.ReadNumber()}]经度", value.Lng); + } + else + { + value.Lng = reader.ReadInt32(); + writer.WriteNumber($"[{value.Lng.ReadNumber()}]经度", value.Lng); + } + value.Altitude = reader.ReadUInt16(); + writer.WriteNumber($"[{value.Altitude.ReadNumber()}]高程", value.Altitude); + value.Speed = reader.ReadUInt16(); + writer.WriteNumber($"[{value.Speed.ReadNumber()}]速度", value.Speed); + value.Direction = reader.ReadUInt16(); + writer.WriteNumber($"[{value.Direction.ReadNumber()}]方向", value.Direction); + value.GPSTime = reader.ReadDateTime6(); + writer.WriteString($"[{value.GPSTime.ToString("yyMMddHHmmss")}]定位时间", value.GPSTime.ToString("yyyy-MM-dd HH:mm:ss")); + // 位置附加信息 + writer.WriteStartArray("附加信息列表"); + while (reader.ReadCurrentRemainContentLength() > 0) + { + try + { + ReadOnlySpan attachSpan = reader.GetVirtualReadOnlySpan(2); + byte attachId = attachSpan[0]; + byte attachLen = attachSpan[1]; + if (config.JT808_0X0200_Factory.Map.TryGetValue(attachId, out object jT808LocationAttachInstance)) + { + writer.WriteStartObject(); + jT808LocationAttachInstance.Analyze(ref reader, writer, config); + writer.WriteEndObject(); + } + else if (config.JT808_0X0200_Custom_Factory.Map.TryGetValue(attachId, out object customAttachInstance)) + { + writer.WriteStartObject(); + customAttachInstance.Analyze(ref reader, writer, config); + writer.WriteEndObject(); + } + else + { + writer.WriteStartObject(); + reader.Skip(2); + writer.WriteNumber($"[{attachId.ReadNumber()}]未知附加信息Id", attachId); + writer.WriteNumber($"[{attachLen.ReadNumber()}]未知附加信息长度", attachLen); + writer.WriteString($"未知附加信息", reader.ReadArray(reader.ReaderCount - 2, attachLen + 2).ToArray().ToHexString()); + reader.Skip(attachLen); + writer.WriteEndObject(); + } + } + catch + { + writer.WriteStartObject(); + try + { + byte attachId = reader.ReadByte(); + byte attachLen = reader.ReadByte(); + writer.WriteNumber($"[{attachId.ReadNumber()}]未知附加信息Id", attachId); + writer.WriteNumber($"[{attachLen.ReadNumber()}]未知附加信息长度", attachLen); + writer.WriteString($"未知附加信息", reader.ReadArray(reader.ReaderCount - 2, attachLen + 2).ToArray().ToHexString()); + reader.Skip(attachLen); + } + catch (Exception ex) + { + throw; + } + finally + { + writer.WriteEndObject(); + } + } + } + writer.WriteEndArray(); + } } } diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x01.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x01.cs index 615efa4..8f8543e 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x01.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x01.cs @@ -1,10 +1,13 @@ -using JT808.Protocol.Formatters; +using JT808.Protocol.Extensions; +using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; using System.Runtime.Serialization; +using System.Text.Json; namespace JT808.Protocol.MessageBody { - public class JT808_0x0200_0x01 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter + public class JT808_0x0200_0x01 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808Analyze { public override byte AttachInfoId { get; set; } = JT808Constants.JT808_0x0200_0x01; public override byte AttachInfoLength { get; set; } = 4; @@ -17,13 +20,25 @@ namespace JT808.Protocol.MessageBody /// [IgnoreDataMember] public double ConvertMileage => Mileage / 10.0; + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0x01 value = new JT808_0x0200_0x01(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + value.Mileage = reader.ReadInt32(); + writer.WriteNumber($"[{value.Mileage.ReadNumber()}]里程", value.Mileage); + } + public JT808_0x0200_0x01 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0200_0x01 jT808LocationAttachImpl0X01 = new JT808_0x0200_0x01(); - jT808LocationAttachImpl0X01.AttachInfoId = reader.ReadByte(); - jT808LocationAttachImpl0X01.AttachInfoLength = reader.ReadByte(); - jT808LocationAttachImpl0X01.Mileage = reader.ReadInt32(); - return jT808LocationAttachImpl0X01; + JT808_0x0200_0x01 value = new JT808_0x0200_0x01(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.Mileage = reader.ReadInt32(); + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x01 value, IJT808Config config) diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x02.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x02.cs index 68c7f4f..c65ac20 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x02.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x02.cs @@ -1,10 +1,13 @@ -using JT808.Protocol.Formatters; +using JT808.Protocol.Extensions; +using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; using System.Runtime.Serialization; +using System.Text.Json; namespace JT808.Protocol.MessageBody { - public class JT808_0x0200_0x02 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter + public class JT808_0x0200_0x02 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808Analyze { /// /// 油量 @@ -18,13 +21,24 @@ namespace JT808.Protocol.MessageBody public override byte AttachInfoId { get; set; } = JT808Constants.JT808_0x0200_0x02; public override byte AttachInfoLength { get; set; } = 2; + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0x02 value = new JT808_0x0200_0x02(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + value.Oil = reader.ReadUInt16(); + writer.WriteNumber($"[{value.Oil.ReadNumber()}]油量", value.Oil); + } + public JT808_0x0200_0x02 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0200_0x02 jT808LocationAttachImpl0X02 = new JT808_0x0200_0x02(); - jT808LocationAttachImpl0X02.AttachInfoId = reader.ReadByte(); - jT808LocationAttachImpl0X02.AttachInfoLength = reader.ReadByte(); - jT808LocationAttachImpl0X02.Oil = reader.ReadUInt16(); - return jT808LocationAttachImpl0X02; + JT808_0x0200_0x02 value = new JT808_0x0200_0x02(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.Oil = reader.ReadUInt16(); + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x02 value, IJT808Config config) diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x03.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x03.cs index 52ba1af..b4bc4ef 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x03.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x03.cs @@ -1,11 +1,14 @@ -using JT808.Protocol.Formatters; +using JT808.Protocol.Extensions; +using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; using System.Runtime.Serialization; +using System.Text.Json; namespace JT808.Protocol.MessageBody { - public class JT808_0x0200_0x03 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter + public class JT808_0x0200_0x03 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808Analyze { /// /// 行驶记录功能获取的速度 @@ -18,13 +21,25 @@ namespace JT808.Protocol.MessageBody public double ConvertSpeed => Speed / 10.0; public override byte AttachInfoId { get; set; } = JT808Constants.JT808_0x0200_0x03; public override byte AttachInfoLength { get; set; } = 2; + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0x03 value = new JT808_0x0200_0x03(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + value.Speed = reader.ReadUInt16(); + writer.WriteNumber($"[{value.Speed.ReadNumber()}]速度", value.Speed); + } + public JT808_0x0200_0x03 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0200_0x03 jT808LocationAttachImpl0x03 = new JT808_0x0200_0x03(); - jT808LocationAttachImpl0x03.AttachInfoId = reader.ReadByte(); - jT808LocationAttachImpl0x03.AttachInfoLength = reader.ReadByte(); - jT808LocationAttachImpl0x03.Speed = reader.ReadUInt16(); - return jT808LocationAttachImpl0x03; + JT808_0x0200_0x03 value = new JT808_0x0200_0x03(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.Speed = reader.ReadUInt16(); + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x03 value, IJT808Config config) diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x04.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x04.cs index 5ed9a19..25915e8 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x04.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x04.cs @@ -1,10 +1,13 @@ using JT808.Protocol.Attributes; +using JT808.Protocol.Extensions; using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; +using System.Text.Json; namespace JT808.Protocol.MessageBody { - public class JT808_0x0200_0x04 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter + public class JT808_0x0200_0x04 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808Analyze { /// /// 需要人工确认报警事件的 ID,从 1 开始计数 @@ -13,13 +16,24 @@ namespace JT808.Protocol.MessageBody public override byte AttachInfoId { get; set; } = JT808Constants.JT808_0x0200_0x04; public override byte AttachInfoLength { get; set; } = 2; + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0x04 value = new JT808_0x0200_0x04(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + value.EventId = reader.ReadUInt16(); + writer.WriteNumber($"[{value.EventId.ReadNumber()}]报警事件ID", value.EventId); + } + public JT808_0x0200_0x04 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0200_0x04 jT808LocationAttachImpl0x04 = new JT808_0x0200_0x04(); - jT808LocationAttachImpl0x04.AttachInfoId = reader.ReadByte(); - jT808LocationAttachImpl0x04.AttachInfoLength = reader.ReadByte(); - jT808LocationAttachImpl0x04.EventId = reader.ReadUInt16(); - return jT808LocationAttachImpl0x04; + JT808_0x0200_0x04 value = new JT808_0x0200_0x04(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.EventId = reader.ReadUInt16(); + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x04 value, IJT808Config config) diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x05.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x05.cs index cb59e46..27d57e4 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x05.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x05.cs @@ -1,7 +1,9 @@ using JT808.Protocol.Attributes; +using JT808.Protocol.Extensions; using JT808.Protocol.Formatters; using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; +using System.Text.Json; namespace JT808.Protocol.MessageBody { @@ -9,7 +11,7 @@ namespace JT808.Protocol.MessageBody /// 胎压 /// 2019版本 /// - public class JT808_0x0200_0x05 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808_2019_Version + public class JT808_0x0200_0x05 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808Analyze, IJT808_2019_Version { /// /// 胎压 @@ -18,6 +20,17 @@ namespace JT808.Protocol.MessageBody public override byte AttachInfoId { get; set; } = JT808Constants.JT808_0x0200_0x05; public override byte AttachInfoLength { get; set; } = 30; + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0x05 value = new JT808_0x0200_0x05(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + value.TirePressure = reader.ReadArray(value.AttachInfoLength).ToArray(); + writer.WriteString($"胎压", value.TirePressure.ToHexString()); + } + public JT808_0x0200_0x05 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { JT808_0x0200_0x05 value = new JT808_0x0200_0x05(); diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x06.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x06.cs index b737ecd..1449121 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x06.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x06.cs @@ -1,7 +1,9 @@ using JT808.Protocol.Attributes; +using JT808.Protocol.Extensions; using JT808.Protocol.Formatters; using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; +using System.Text.Json; namespace JT808.Protocol.MessageBody { @@ -9,7 +11,7 @@ namespace JT808.Protocol.MessageBody /// 胎压 /// 2019版本 /// - public class JT808_0x0200_0x06 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808_2019_Version + public class JT808_0x0200_0x06 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808Analyze, IJT808_2019_Version { /// /// 车厢温度 @@ -18,6 +20,17 @@ namespace JT808.Protocol.MessageBody public override byte AttachInfoId { get; set; } = JT808Constants.JT808_0x0200_0x06; public override byte AttachInfoLength { get; set; } = 2; + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0x06 value = new JT808_0x0200_0x06(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + value.CarTemperature = reader.ReadInt16(); + writer.WriteNumber($"[{value.CarTemperature.ReadNumber()}]车厢温度", value.CarTemperature); + } + public JT808_0x0200_0x06 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { JT808_0x0200_0x06 value = new JT808_0x0200_0x06(); diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x11.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x11.cs index 79001ce..a043b85 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x11.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x11.cs @@ -1,10 +1,13 @@ using JT808.Protocol.Enums; +using JT808.Protocol.Extensions; using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; +using System.Text.Json; namespace JT808.Protocol.MessageBody { - public class JT808_0x0200_0x11 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter + public class JT808_0x0200_0x11 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808Analyze { /// /// 超速报警附加信息 @@ -38,17 +41,33 @@ namespace JT808.Protocol.MessageBody set { } } + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0x11 value = new JT808_0x0200_0x11(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + value.JT808PositionType = (JT808PositionType)reader.ReadByte(); + writer.WriteNumber($"[{((byte)value.JT808PositionType).ReadNumber()}]超速报警附加信息-{value.JT808PositionType.ToString()}", (byte)value.JT808PositionType); + if (value.JT808PositionType != JT808PositionType.无特定位置) + { + value.AreaId = reader.ReadUInt32(); + writer.WriteNumber($"[{value.AreaId.ReadNumber()}]区域或路段ID", value.AreaId); + } + } + public JT808_0x0200_0x11 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0200_0x11 jT808LocationAttachImpl0x11 = new JT808_0x0200_0x11(); - jT808LocationAttachImpl0x11.AttachInfoId = reader.ReadByte(); - jT808LocationAttachImpl0x11.AttachInfoLength = reader.ReadByte(); - jT808LocationAttachImpl0x11.JT808PositionType = (JT808PositionType)reader.ReadByte(); - if (jT808LocationAttachImpl0x11.JT808PositionType != JT808PositionType.无特定位置) + JT808_0x0200_0x11 value = new JT808_0x0200_0x11(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.JT808PositionType = (JT808PositionType)reader.ReadByte(); + if (value.JT808PositionType != JT808PositionType.无特定位置) { - jT808LocationAttachImpl0x11.AreaId = reader.ReadUInt32(); + value.AreaId = reader.ReadUInt32(); } - return jT808LocationAttachImpl0x11; + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x11 value, IJT808Config config) diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x12.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x12.cs index f05fc5d..7a7a883 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x12.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x12.cs @@ -1,10 +1,13 @@ using JT808.Protocol.Enums; +using JT808.Protocol.Extensions; using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; +using System.Text.Json; namespace JT808.Protocol.MessageBody { - public class JT808_0x0200_0x12 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter + public class JT808_0x0200_0x12 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808Analyze { /// /// 位置类型 @@ -29,15 +32,30 @@ namespace JT808.Protocol.MessageBody public override byte AttachInfoId { get; set; } = JT808Constants.JT808_0x0200_0x12; public override byte AttachInfoLength { get; set; } = 6; + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0x12 value = new JT808_0x0200_0x12(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + value.JT808PositionType = (JT808PositionType)reader.ReadByte(); + writer.WriteNumber($"[{((byte)value.JT808PositionType).ReadNumber()}]位置类型-{value.JT808PositionType.ToString()}", (byte)value.JT808PositionType); + value.AreaId = reader.ReadInt32(); + writer.WriteNumber($"[{value.AreaId.ReadNumber()}]区域或路段ID", value.AreaId); + value.Direction = (JT808DirectionType)reader.ReadByte(); + writer.WriteNumber($"[{((byte)value.Direction).ReadNumber()}]方向-{value.Direction.ToString()}", (byte)value.Direction); + } + public JT808_0x0200_0x12 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0200_0x12 jT808LocationAttachImpl0x12 = new JT808_0x0200_0x12(); - jT808LocationAttachImpl0x12.AttachInfoId = reader.ReadByte(); - jT808LocationAttachImpl0x12.AttachInfoLength = reader.ReadByte(); - jT808LocationAttachImpl0x12.JT808PositionType = (JT808PositionType)reader.ReadByte(); - jT808LocationAttachImpl0x12.AreaId = reader.ReadInt32(); - jT808LocationAttachImpl0x12.Direction = (JT808DirectionType)reader.ReadByte(); - return jT808LocationAttachImpl0x12; + JT808_0x0200_0x12 value = new JT808_0x0200_0x12(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.JT808PositionType = (JT808PositionType)reader.ReadByte(); + value.AreaId = reader.ReadInt32(); + value.Direction = (JT808DirectionType)reader.ReadByte(); + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x12 value, IJT808Config config) diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x13.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x13.cs index 7b6cf04..e2971ae 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x13.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x13.cs @@ -1,10 +1,13 @@ using JT808.Protocol.Enums; +using JT808.Protocol.Extensions; using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; +using System.Text.Json; namespace JT808.Protocol.MessageBody { - public class JT808_0x0200_0x13 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter + public class JT808_0x0200_0x13 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808Analyze { public override byte AttachInfoId { get; set; } = JT808Constants.JT808_0x0200_0x13; public override byte AttachInfoLength { get; set; } = 7; @@ -25,15 +28,31 @@ namespace JT808.Protocol.MessageBody /// public JT808DrivenRouteType DrivenRoute { get; set; } + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0x13 value = new JT808_0x0200_0x13(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + value.DrivenRouteId = reader.ReadInt32(); + writer.WriteNumber($"[{((byte)value.DrivenRouteId).ReadNumber()}]路段ID", value.DrivenRouteId); + value.Time = reader.ReadUInt16(); + writer.WriteNumber($"[{value.Time.ReadNumber()}]路段行驶时间", value.Time); + value.DrivenRoute = (JT808DrivenRouteType)reader.ReadByte(); + writer.WriteNumber($"[{((byte)value.DrivenRoute).ReadNumber()}]结果-{value.DrivenRoute.ToString()}", (byte)value.DrivenRoute); + } + + public JT808_0x0200_0x13 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0200_0x13 jT808LocationAttachImpl0x13 = new JT808_0x0200_0x13(); - jT808LocationAttachImpl0x13.AttachInfoId = reader.ReadByte(); - jT808LocationAttachImpl0x13.AttachInfoLength = reader.ReadByte(); - jT808LocationAttachImpl0x13.DrivenRouteId = reader.ReadInt32(); - jT808LocationAttachImpl0x13.Time = reader.ReadUInt16(); - jT808LocationAttachImpl0x13.DrivenRoute = (JT808DrivenRouteType)reader.ReadByte(); - return jT808LocationAttachImpl0x13; + JT808_0x0200_0x13 value = new JT808_0x0200_0x13(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.DrivenRouteId = reader.ReadInt32(); + value.Time = reader.ReadUInt16(); + value.DrivenRoute = (JT808DrivenRouteType)reader.ReadByte(); + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x13 value, IJT808Config config) diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x25.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x25.cs index aa66726..fe6b926 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x25.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x25.cs @@ -1,9 +1,12 @@ -using JT808.Protocol.Formatters; +using JT808.Protocol.Extensions; +using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; +using System.Text.Json; namespace JT808.Protocol.MessageBody { - public class JT808_0x0200_0x25 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter + public class JT808_0x0200_0x25 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808Analyze { /// /// 扩展车辆信号状态位 @@ -11,13 +14,25 @@ namespace JT808.Protocol.MessageBody public int CarSignalStatus { get; set; } public override byte AttachInfoId { get; set; } = JT808Constants.JT808_0x0200_0x25; public override byte AttachInfoLength { get; set; } = 4; + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0x25 value = new JT808_0x0200_0x25(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + value.CarSignalStatus = reader.ReadInt32(); + writer.WriteNumber($"[{value.CarSignalStatus.ReadNumber()}]扩展车辆信号状态位", value.CarSignalStatus); + } + public JT808_0x0200_0x25 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0200_0x25 jT808LocationAttachImpl0x13 = new JT808_0x0200_0x25(); - jT808LocationAttachImpl0x13.AttachInfoId = reader.ReadByte(); - jT808LocationAttachImpl0x13.AttachInfoLength = reader.ReadByte(); - jT808LocationAttachImpl0x13.CarSignalStatus = reader.ReadInt32(); - return jT808LocationAttachImpl0x13; + JT808_0x0200_0x25 value = new JT808_0x0200_0x25(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.CarSignalStatus = reader.ReadInt32(); + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x25 value, IJT808Config config) diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x2A.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x2A.cs index 115970e..c10d419 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x2A.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x2A.cs @@ -1,9 +1,12 @@ -using JT808.Protocol.Formatters; +using JT808.Protocol.Extensions; +using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; +using System.Text.Json; namespace JT808.Protocol.MessageBody { - public class JT808_0x0200_0x2A : JT808_0x0200_BodyBase, IJT808MessagePackFormatter + public class JT808_0x0200_0x2A : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808Analyze { /// /// IO状态位 @@ -12,13 +15,24 @@ namespace JT808.Protocol.MessageBody public override byte AttachInfoId { get; set; } = JT808Constants.JT808_0x0200_0x2A; public override byte AttachInfoLength { get; set; } = 2; + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0x2A value = new JT808_0x0200_0x2A(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + value.IOStatus = reader.ReadUInt16(); + writer.WriteNumber($"[{value.IOStatus.ReadNumber()}]IO状态位", value.IOStatus); + } + public JT808_0x0200_0x2A Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0200_0x2A jT808LocationAttachImpl0X2A = new JT808_0x0200_0x2A(); - jT808LocationAttachImpl0X2A.AttachInfoId = reader.ReadByte(); - jT808LocationAttachImpl0X2A.AttachInfoLength = reader.ReadByte(); - jT808LocationAttachImpl0X2A.IOStatus = reader.ReadUInt16(); - return jT808LocationAttachImpl0X2A; + JT808_0x0200_0x2A value = new JT808_0x0200_0x2A(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.IOStatus = reader.ReadUInt16(); + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x2A value, IJT808Config config) diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x2B.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x2B.cs index d0e43eb..925333f 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x2B.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x2B.cs @@ -1,10 +1,13 @@ using JT808.Protocol.Attributes; +using JT808.Protocol.Extensions; using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; +using System.Text.Json; namespace JT808.Protocol.MessageBody { - public class JT808_0x0200_0x2B : JT808_0x0200_BodyBase, IJT808MessagePackFormatter + public class JT808_0x0200_0x2B : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808Analyze { /// /// 模拟量 bit0-15,AD0;bit16-31,AD1 @@ -12,13 +15,25 @@ namespace JT808.Protocol.MessageBody public int Analog { get; set; } public override byte AttachInfoId { get; set; } = JT808Constants.JT808_0x0200_0x2B; public override byte AttachInfoLength { get; set; } = 4; + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0x2B value = new JT808_0x0200_0x2B(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + value.Analog = reader.ReadInt32(); + writer.WriteNumber($"[{value.Analog.ReadNumber()}]模拟量", value.Analog); + } + public JT808_0x0200_0x2B Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0200_0x2B jT808LocationAttachImpl0x2B = new JT808_0x0200_0x2B(); - jT808LocationAttachImpl0x2B.AttachInfoId = reader.ReadByte(); - jT808LocationAttachImpl0x2B.AttachInfoLength = reader.ReadByte(); - jT808LocationAttachImpl0x2B.Analog = reader.ReadInt32(); - return jT808LocationAttachImpl0x2B; + JT808_0x0200_0x2B value = new JT808_0x0200_0x2B(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.Analog = reader.ReadInt32(); + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x2B value, IJT808Config config) diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x30.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x30.cs index db8101a..6b16cfe 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x30.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x30.cs @@ -1,10 +1,13 @@ using JT808.Protocol.Attributes; +using JT808.Protocol.Extensions; using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; +using System.Text.Json; namespace JT808.Protocol.MessageBody { - public class JT808_0x0200_0x30 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter + public class JT808_0x0200_0x30 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808Analyze { /// /// 无线通信网络信号强度 @@ -12,13 +15,25 @@ namespace JT808.Protocol.MessageBody public byte WiFiSignalStrength { get; set; } public override byte AttachInfoId { get; set; } = JT808Constants.JT808_0x0200_0x30; public override byte AttachInfoLength { get; set; } = 1; + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0x30 value = new JT808_0x0200_0x30(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + value.WiFiSignalStrength = reader.ReadByte(); + writer.WriteNumber($"[{value.WiFiSignalStrength.ReadNumber()}]无线通信网络信号强度", value.WiFiSignalStrength); + } + public JT808_0x0200_0x30 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0200_0x30 jT808LocationAttachImpl0x30 = new JT808_0x0200_0x30(); - jT808LocationAttachImpl0x30.AttachInfoId = reader.ReadByte(); - jT808LocationAttachImpl0x30.AttachInfoLength = reader.ReadByte(); - jT808LocationAttachImpl0x30.WiFiSignalStrength = reader.ReadByte(); - return jT808LocationAttachImpl0x30; + JT808_0x0200_0x30 value = new JT808_0x0200_0x30(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.WiFiSignalStrength = reader.ReadByte(); + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x30 value, IJT808Config config) diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x31.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x31.cs index faa3f89..e047c7c 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x31.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x31.cs @@ -1,9 +1,12 @@ -using JT808.Protocol.Formatters; +using JT808.Protocol.Extensions; +using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; +using System.Text.Json; namespace JT808.Protocol.MessageBody { - public class JT808_0x0200_0x31 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter + public class JT808_0x0200_0x31 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808Analyze { /// /// GNSS 定位卫星数 @@ -11,13 +14,25 @@ namespace JT808.Protocol.MessageBody public byte GNSSCount { get; set; } public override byte AttachInfoId { get; set; } = JT808Constants.JT808_0x0200_0x31; public override byte AttachInfoLength { get; set; } = 1; + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0x31 value = new JT808_0x0200_0x31(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + value.GNSSCount = reader.ReadByte(); + writer.WriteNumber($"[{value.GNSSCount.ReadNumber()}]GNSS定位卫星数", value.GNSSCount); + } + public JT808_0x0200_0x31 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0200_0x31 jT808LocationAttachImpl0x31 = new JT808_0x0200_0x31(); - jT808LocationAttachImpl0x31.AttachInfoId = reader.ReadByte(); - jT808LocationAttachImpl0x31.AttachInfoLength = reader.ReadByte(); - jT808LocationAttachImpl0x31.GNSSCount = reader.ReadByte(); - return jT808LocationAttachImpl0x31; + JT808_0x0200_0x31 value = new JT808_0x0200_0x31(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.GNSSCount = reader.ReadByte(); + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x31 value, IJT808Config config) { diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0201.cs b/src/JT808.Protocol/MessageBody/JT808_0x0201.cs index 25d0142..59ddc9b 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0201.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0201.cs @@ -1,12 +1,15 @@ -using JT808.Protocol.Formatters; +using JT808.Protocol.Extensions; +using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; +using System.Text.Json; namespace JT808.Protocol.MessageBody { /// /// 位置信息查询应答 /// - public class JT808_0x0201 : JT808Bodies, IJT808MessagePackFormatter + public class JT808_0x0201 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze { public override ushort MsgId { get; } = 0x0201; public override string Description => "位置信息查询应答"; @@ -20,6 +23,17 @@ namespace JT808.Protocol.MessageBody /// 位置信息汇报见 8.12 /// public JT808_0x0200 Position { get; set; } + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0201 value = new JT808_0x0201(); + value.ReplyMsgNum = reader.ReadUInt16(); + writer.WriteNumber($"[{value.ReplyMsgNum.ReadNumber()}]", value.ReplyMsgNum); + writer.WriteStartObject("位置基本信息"); + config.GetAnalyze().Analyze(ref reader, writer, config); + writer.WriteEndObject(); + } + public JT808_0x0201 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { JT808_0x0201 jT808_0X0201 = new JT808_0x0201(); diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0303.cs b/src/JT808.Protocol/MessageBody/JT808_0x0303.cs index 638483d..fbfb246 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0303.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0303.cs @@ -27,19 +27,19 @@ namespace JT808.Protocol.MessageBody public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { - JT808_0x0303 jT808_0X0303 = new JT808_0x0303(); - jT808_0X0303.InformationType = reader.ReadByte(); - jT808_0X0303.Flag = reader.ReadByte(); - writer.WriteNumber($"[{jT808_0X0303.InformationType.ReadNumber()}]信息类型", jT808_0X0303.InformationType); - writer.WriteNumber($"[{jT808_0X0303.Flag.ReadNumber()}]{(jT808_0X0303.Flag==1? "点播" : "取消")}", jT808_0X0303.Flag); + JT808_0x0303 value = new JT808_0x0303(); + value.InformationType = reader.ReadByte(); + value.Flag = reader.ReadByte(); + writer.WriteNumber($"[{value.InformationType.ReadNumber()}]信息类型", value.InformationType); + writer.WriteNumber($"[{value.Flag.ReadNumber()}]{(value.Flag==1? "点播" : "取消")}", value.Flag); } public JT808_0x0303 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0303 jT808_0X0303 = new JT808_0x0303(); - jT808_0X0303.InformationType = reader.ReadByte(); - jT808_0X0303.Flag = reader.ReadByte(); - return jT808_0X0303; + JT808_0x0303 value = new JT808_0x0303(); + value.InformationType = reader.ReadByte(); + value.Flag = reader.ReadByte(); + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0303 value, IJT808Config config) diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0500.cs b/src/JT808.Protocol/MessageBody/JT808_0x0500.cs index 1bc272e..eb8ed63 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0500.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0500.cs @@ -1,12 +1,15 @@ -using JT808.Protocol.Formatters; +using JT808.Protocol.Extensions; +using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; +using System.Text.Json; namespace JT808.Protocol.MessageBody { /// /// 车辆控制应答 /// - public class JT808_0x0500 : JT808Bodies, IJT808MessagePackFormatter + public class JT808_0x0500 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze { public override ushort MsgId { get; } = 0x0500; public override string Description => "车辆控制应答"; @@ -19,12 +22,23 @@ namespace JT808.Protocol.MessageBody /// 位置信息汇报消息体 /// public JT808_0x0200 JT808_0x0200 { get; set; } + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0500 value = new JT808_0x0500(); + value.MsgNum = reader.ReadUInt16(); + writer.WriteNumber($"[{value.MsgNum.ReadNumber()}]应答流水号", value.MsgNum); + writer.WriteStartObject("位置基本信息"); + config.GetAnalyze().Analyze(ref reader, writer, config); + writer.WriteEndObject(); + } + public JT808_0x0500 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0500 jT808_0X0500 = new JT808_0x0500(); - jT808_0X0500.MsgNum = reader.ReadUInt16(); - jT808_0X0500.JT808_0x0200 = config.GetMessagePackFormatter().Deserialize(ref reader, config); - return jT808_0X0500; + JT808_0x0500 value = new JT808_0x0500(); + value.MsgNum = reader.ReadUInt16(); + value.JT808_0x0200 = config.GetMessagePackFormatter().Deserialize(ref reader, config); + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0500 value, IJT808Config config) diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0608.cs b/src/JT808.Protocol/MessageBody/JT808_0x0608.cs index 83f2866..cf00f6c 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0608.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0608.cs @@ -3,13 +3,14 @@ using JT808.Protocol.Formatters; using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; using System.Collections.Generic; +using System.Text.Json; namespace JT808.Protocol.MessageBody { /// /// 查询区域或线路数据应答 /// - public class JT808_0x0608 : JT808Bodies, IJT808MessagePackFormatter, IJT808_2019_Version + public class JT808_0x0608 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze, IJT808_2019_Version { public override ushort MsgId { get; } = 0x0608; public override string Description => "查询区域或线路数据应答"; @@ -45,6 +46,85 @@ namespace JT808.Protocol.MessageBody /// 查询类型为4 /// public List JT808_0x8606s { get; set; } + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0608 value = new JT808_0x0608(); + value.QueryType = reader.ReadByte(); + writer.WriteNumber($"[{value.QueryType.ReadNumber()}]查询类型", value.QueryType); + value.Count = reader.ReadUInt32(); + writer.WriteNumber($"[{value.Count.ReadNumber()}]查询的区域或线路的ID数量", value.Count); + if (value.Count > 0) + { + switch (value.QueryType) + { + case 1: + writer.WriteStartArray("设置圆形区域"); + for (int i = 0; i < value.Count; i++) + { + if (config.FormatterFactory.FormatterDict.TryGetValue(typeof(JT808_0x8600).GUID, out object instance)) + { + writer.WriteStartObject(); + instance.Analyze(ref reader, writer, config); + writer.WriteEndObject(); + } + } + writer.WriteEndArray(); + break; + case 2: + writer.WriteStartArray("设置矩形区域"); + for (int i = 0; i < value.Count; i++) + { + if (config.FormatterFactory.FormatterDict.TryGetValue(typeof(JT808_0x8602).GUID, out object instance)) + { + writer.WriteStartObject(); + instance.Analyze(ref reader, writer, config); + writer.WriteEndObject(); + } + } + writer.WriteEndArray(); + break; + case 3: + writer.WriteStartArray("设置多边形区域"); + for (int i = 0; i < value.Count; i++) + { + if (config.FormatterFactory.FormatterDict.TryGetValue(typeof(JT808_0x8604).GUID, out object instance)) + { + writer.WriteStartObject(); + instance.Analyze(ref reader, writer, config); + writer.WriteEndObject(); + } + } + writer.WriteEndArray(); + break; + case 4: + writer.WriteStartArray("设置路线"); + for (int i = 0; i < value.Count; i++) + { + if (config.FormatterFactory.FormatterDict.TryGetValue(typeof(JT808_0x8606).GUID, out object instance)) + { + writer.WriteStartObject(); + instance.Analyze(ref reader, writer, config); + writer.WriteEndObject(); + } + } + writer.WriteEndArray(); + break; + default: + writer.WriteStartArray("线路Id集合"); + for (int i = 0; i < value.Count; i++) + { + writer.WriteStartObject(); + var routeId = reader.ReadUInt32(); + writer.WriteNumber($"[{routeId.ReadNumber()}]Id{i+1}", routeId); + writer.WriteEndObject(); + } + writer.WriteEndArray(); + break; + } + } + } + public JT808_0x0608 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { JT808_0x0608 value = new JT808_0x0608(); diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0701.cs b/src/JT808.Protocol/MessageBody/JT808_0x0701.cs index addd7b1..6378621 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0701.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0701.cs @@ -1,7 +1,9 @@ using JT808.Protocol.Extensions; using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; using System; +using System.Text.Json; namespace JT808.Protocol.MessageBody { @@ -9,7 +11,7 @@ namespace JT808.Protocol.MessageBody /// 电子运单上报 /// 0x0701 /// - public class JT808_0x0701 : JT808Bodies, IJT808MessagePackFormatter + public class JT808_0x0701 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze { public override ushort MsgId { get; } = 0x0701; public override string Description => "电子运单上报"; @@ -25,12 +27,22 @@ namespace JT808.Protocol.MessageBody /// 注意:需要具体的实现 /// public JT808_0x0701_CustomBodyBase ElectronicContentObj { get; set; } + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0701 value = new JT808_0x0701(); + value.ElectronicWaybillLength = reader.ReadUInt32(); + writer.WriteNumber($"[{value.ElectronicWaybillLength.ReadNumber()}]电子运单长度", value.ElectronicWaybillLength); + value.ElectronicContent = reader.ReadArray((int)value.ElectronicWaybillLength).ToArray(); + writer.WriteString($"电子运单", value.ElectronicContent.ToHexString()); + } + public JT808_0x0701 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0701 jT808_0X0701 = new JT808_0x0701(); - jT808_0X0701.ElectronicWaybillLength = reader.ReadUInt32(); - jT808_0X0701.ElectronicContent = reader.ReadArray((int)jT808_0X0701.ElectronicWaybillLength).ToArray(); - return jT808_0X0701; + JT808_0x0701 value = new JT808_0x0701(); + value.ElectronicWaybillLength = reader.ReadUInt32(); + value.ElectronicContent = reader.ReadArray((int)value.ElectronicWaybillLength).ToArray(); + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0701 value, IJT808Config config) diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0702.cs b/src/JT808.Protocol/MessageBody/JT808_0x0702.cs index 3715d83..065fde2 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0702.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0702.cs @@ -2,14 +2,16 @@ using JT808.Protocol.Formatters; using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; +using JT808.Protocol.Extensions; using System; +using System.Text.Json; namespace JT808.Protocol.MessageBody { /// /// 驾驶员身份信息采集上报 /// - public class JT808_0x0702 : JT808Bodies, IJT808MessagePackFormatter, IJT808_2019_Version + public class JT808_0x0702 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze, IJT808_2019_Version { public override ushort MsgId { get; } = 0x0702; public override string Description => "驾驶员身份信息采集上报"; @@ -53,7 +55,7 @@ namespace JT808.Protocol.MessageBody /// public byte LicenseIssuingLength { get; set; } /// - /// 发证机构名称长度 + /// 发证机构名称 /// public string LicenseIssuing { get; set; } /// @@ -65,29 +67,68 @@ namespace JT808.Protocol.MessageBody /// 2019版本 /// public string DriverIdentityCard { get; set; } + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0702 value = new JT808_0x0702(); + value.IC_Card_Status = (JT808ICCardStatus)reader.ReadByte(); + writer.WriteNumber($"[{((byte)value.IC_Card_Status).ReadNumber()}]状态-{value.IC_Card_Status.ToString()}", (byte)value.IC_Card_Status); + value.IC_Card_PlugDateTime = reader.ReadDateTime6(); + writer.WriteString($"[{value.IC_Card_PlugDateTime.ToString("yyMMddHHmmss")}]插拔卡时间", value.IC_Card_PlugDateTime.ToString("yyyy-MM-dd HH:mm:ss")); + if (value.IC_Card_Status == JT808ICCardStatus.从业资格证IC卡插入_驾驶员上班) + { + value.IC_Card_ReadResult = (JT808ICCardReadResult)reader.ReadByte(); + writer.WriteNumber($"[{((byte)value.IC_Card_ReadResult).ReadNumber()}]IC卡读取结果-{value.IC_Card_ReadResult.ToString()}", (byte)value.IC_Card_ReadResult); + if (value.IC_Card_ReadResult == JT808ICCardReadResult.IC卡读卡成功) + { + value.DriverUserNameLength = reader.ReadByte(); + writer.WriteNumber($"[{value.DriverUserNameLength.ReadNumber()}]驾驶员姓名长度", value.DriverUserNameLength); + var driverUserNameBuffer= reader.ReadVirtualArray(value.DriverUserNameLength); + value.DriverUserName = reader.ReadString(value.DriverUserNameLength); + writer.WriteString($"[{driverUserNameBuffer.ToArray().ToHexString()}]驾驶员姓名", value.DriverUserName); + var qualificationCodeBuffer = reader.ReadVirtualArray(20); + value.QualificationCode = reader.ReadString(20); + writer.WriteString($"[{qualificationCodeBuffer.ToArray().ToHexString()}]从业资格证编码", value.QualificationCode); + value.LicenseIssuingLength = reader.ReadByte(); + writer.WriteNumber($"[{value.LicenseIssuingLength.ReadNumber()}]发证机构名称长度", value.LicenseIssuingLength); + var licenseIssuingLengtheBuffer = reader.ReadVirtualArray(value.LicenseIssuingLength); + value.LicenseIssuing = reader.ReadString(value.LicenseIssuingLength); + writer.WriteString($"[{licenseIssuingLengtheBuffer.ToArray().ToHexString()}]发证机构名称", value.LicenseIssuing); + value.CertificateExpiresDate = reader.ReadDateTime4(); + writer.WriteString($"[{value.CertificateExpiresDate.ToString("yyMMdd")}]插拔卡时间", value.CertificateExpiresDate.ToString("yyyy-MM-dd")); + if (reader.Version == JT808Version.JTT2019) + { + var driverIdentityCardBuffer = reader.ReadVirtualArray(20); + value.DriverIdentityCard = reader.ReadString(20); + writer.WriteString($"[{driverIdentityCardBuffer.ToArray().ToHexString()}]驾驶员身份证号", value.DriverIdentityCard); + } + } + } + } + public JT808_0x0702 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0702 jT808_0X0702 = new JT808_0x0702(); - jT808_0X0702.IC_Card_Status = (JT808ICCardStatus)reader.ReadByte(); - jT808_0X0702.IC_Card_PlugDateTime = reader.ReadDateTime6(); - if (jT808_0X0702.IC_Card_Status == JT808ICCardStatus.从业资格证IC卡插入_驾驶员上班) + JT808_0x0702 value = new JT808_0x0702(); + value.IC_Card_Status = (JT808ICCardStatus)reader.ReadByte(); + value.IC_Card_PlugDateTime = reader.ReadDateTime6(); + if (value.IC_Card_Status == JT808ICCardStatus.从业资格证IC卡插入_驾驶员上班) { - jT808_0X0702.IC_Card_ReadResult = (JT808ICCardReadResult)reader.ReadByte(); - if (jT808_0X0702.IC_Card_ReadResult == JT808ICCardReadResult.IC卡读卡成功) + value.IC_Card_ReadResult = (JT808ICCardReadResult)reader.ReadByte(); + if (value.IC_Card_ReadResult == JT808ICCardReadResult.IC卡读卡成功) { - jT808_0X0702.DriverUserNameLength = reader.ReadByte(); - jT808_0X0702.DriverUserName = reader.ReadString(jT808_0X0702.DriverUserNameLength); - jT808_0X0702.QualificationCode = reader.ReadString(20); - jT808_0X0702.LicenseIssuingLength = reader.ReadByte(); - jT808_0X0702.LicenseIssuing = reader.ReadString(jT808_0X0702.LicenseIssuingLength); - jT808_0X0702.CertificateExpiresDate = reader.ReadDateTime4(); + value.DriverUserNameLength = reader.ReadByte(); + value.DriverUserName = reader.ReadString(value.DriverUserNameLength); + value.QualificationCode = reader.ReadString(20); + value.LicenseIssuingLength = reader.ReadByte(); + value.LicenseIssuing = reader.ReadString(value.LicenseIssuingLength); + value.CertificateExpiresDate = reader.ReadDateTime4(); if(reader.Version== JT808Version.JTT2019) { - jT808_0X0702.DriverIdentityCard = reader.ReadString(20); + value.DriverIdentityCard = reader.ReadString(20); } } } - return jT808_0X0702; + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0702 value, IJT808Config config) diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0704.cs b/src/JT808.Protocol/MessageBody/JT808_0x0704.cs index b40f035..2ca3ae9 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0704.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0704.cs @@ -1,14 +1,17 @@ -using JT808.Protocol.Formatters; +using JT808.Protocol.Extensions; +using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; using System; using System.Collections.Generic; +using System.Text.Json; namespace JT808.Protocol.MessageBody { /// /// 定位数据批量上传 /// - public class JT808_0x0704 : JT808Bodies, IJT808MessagePackFormatter + public class JT808_0x0704 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze { public override ushort MsgId { get; } = 0x0704; public override string Description => "定位数据批量上传"; @@ -79,5 +82,35 @@ namespace JT808.Protocol.MessageBody } } } + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0704 jT808_0X0704 = new JT808_0x0704(); + jT808_0X0704.Count = reader.ReadUInt16(); + writer.WriteNumber($"[{jT808_0X0704.Count.ReadNumber()}]数据项个数", jT808_0X0704.Count); + jT808_0X0704.LocationType = (JT808_0x0704.BatchLocationType)reader.ReadByte(); + writer.WriteNumber($"[{((byte)jT808_0X0704.LocationType).ReadNumber()}]位置数据类型-{jT808_0X0704.LocationType.ToString()}", (byte)jT808_0X0704.LocationType); + writer.WriteStartArray("位置汇报数据集合"); + for (int i = 0; i < jT808_0X0704.Count; i++) + { + writer.WriteStartObject(); + int buflen = reader.ReadUInt16(); + writer.WriteNumber($"[{buflen.ReadNumber()}]位置汇报数据长度", buflen); + try + { + writer.WriteString($"位置汇报数据", reader.ReadVirtualArray(buflen).ToArray().ToHexString()); + JT808MessagePackReader tmpReader = new JT808MessagePackReader(reader.ReadArray(buflen)); + writer.WriteStartObject("位置信息汇报"); + config.GetAnalyze().Analyze(ref tmpReader, writer, config); + writer.WriteEndObject(); + } + catch (Exception) + { + + } + writer.WriteEndObject(); + } + writer.WriteEndArray(); + } } } diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0705.cs b/src/JT808.Protocol/MessageBody/JT808_0x0705.cs index f816e64..2021da9 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0705.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0705.cs @@ -1,10 +1,12 @@ using JT808.Protocol.Exceptions; +using JT808.Protocol.Extensions; using JT808.Protocol.Formatters; using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; using JT808.Protocol.Metadata; using System; using System.Collections.Generic; +using System.Text.Json; namespace JT808.Protocol.MessageBody { @@ -12,7 +14,7 @@ namespace JT808.Protocol.MessageBody /// CAN 总线数据上传 /// 0x0705 /// - public class JT808_0x0705 : JT808Bodies, IJT808MessagePackFormatter,IJT808_2019_Version + public class JT808_0x0705 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze, IJT808_2019_Version { public override ushort MsgId { get; } = 0x0705; public override string Description => "CAN总线数据上传"; @@ -31,13 +33,39 @@ namespace JT808.Protocol.MessageBody /// public List CanItems { get; set; } + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0705 value = new JT808_0x0705(); + value.CanItemCount = reader.ReadUInt16(); + writer.WriteNumber($"[{value.CanItemCount.ReadNumber()}]数据项个数", value.CanItemCount); + var dateTimeBuffer = reader.ReadVirtualArray(5).ToArray(); + value.FirstCanReceiveTime = reader.ReadDateTime5(); + writer.WriteString($"[{dateTimeBuffer.ToHexString()}]CAN总线数据接收时间", value.FirstCanReceiveTime.ToString("HH-mm-ss:fff")); + writer.WriteStartArray("CAN总线数据项"); + for (var i = 0; i < value.CanItemCount; i++) + { + writer.WriteStartObject(); + JT808CanProperty jT808CanProperty = new JT808CanProperty(); + jT808CanProperty.CanId = reader.ReadUInt32(); + writer.WriteNumber($"[{ jT808CanProperty.CanId.ReadNumber()}]CAN_ID", jT808CanProperty.CanId); + jT808CanProperty.CanData = reader.ReadArray(8).ToArray(); + writer.WriteString($"CAN_数据", jT808CanProperty.CanData.ToHexString()); + if (jT808CanProperty.CanData.Length != 8) + { + throw new JT808Exception(Enums.JT808ErrorCode.NotEnoughLength, $"{nameof(jT808CanProperty.CanData)}->8"); + } + writer.WriteEndObject(); + } + writer.WriteEndArray(); + } + public JT808_0x0705 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0705 jT808_0X0705 = new JT808_0x0705(); - jT808_0X0705.CanItemCount = reader.ReadUInt16(); - jT808_0X0705.FirstCanReceiveTime = reader.ReadDateTime5(); - jT808_0X0705.CanItems = new List(); - for (var i = 0; i < jT808_0X0705.CanItemCount; i++) + JT808_0x0705 value = new JT808_0x0705(); + value.CanItemCount = reader.ReadUInt16(); + value.FirstCanReceiveTime = reader.ReadDateTime5(); + value.CanItems = new List(); + for (var i = 0; i < value.CanItemCount; i++) { JT808CanProperty jT808CanProperty = new JT808CanProperty(); jT808CanProperty.CanId = reader.ReadUInt32(); @@ -46,9 +74,9 @@ namespace JT808.Protocol.MessageBody { throw new JT808Exception(Enums.JT808ErrorCode.NotEnoughLength, $"{nameof(jT808CanProperty.CanData)}->8"); } - jT808_0X0705.CanItems.Add(jT808CanProperty); + value.CanItems.Add(jT808CanProperty); } - return jT808_0X0705; + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0705 value, IJT808Config config) diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0800.cs b/src/JT808.Protocol/MessageBody/JT808_0x0800.cs index 2e1ca8b..0df05c3 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0800.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0800.cs @@ -1,5 +1,9 @@ -using JT808.Protocol.Formatters; +using JT808.Protocol.Enums; +using JT808.Protocol.Extensions; +using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; +using System.Text.Json; namespace JT808.Protocol.MessageBody { @@ -7,7 +11,7 @@ namespace JT808.Protocol.MessageBody /// 多媒体事件信息上传 /// 0x0800 /// - public class JT808_0x0800 : JT808Bodies, IJT808MessagePackFormatter + public class JT808_0x0800 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze { public override ushort MsgId { get; } = 0x0800; public override string Description => "多媒体事件信息上传"; @@ -44,15 +48,31 @@ namespace JT808.Protocol.MessageBody /// 通道 ID /// public byte ChannelId { get; set; } + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0800 value = new JT808_0x0800(); + value.MultimediaId = reader.ReadUInt32(); + writer.WriteNumber($"[{value.MultimediaId.ReadNumber()}]多媒体ID", value.MultimediaId); + value.MultimediaType = reader.ReadByte(); + writer.WriteNumber($"[{value.MultimediaType.ReadNumber()}]多媒体类型-{((JT808MultimediaType)value.MultimediaType).ToString()}", value.MultimediaType); + value.MultimediaCodingFormat = reader.ReadByte(); + writer.WriteNumber($"[{value.MultimediaCodingFormat.ReadNumber()}]多媒体格式编码-{((JT808MultimediaCodingFormat)value.MultimediaCodingFormat).ToString()}", value.MultimediaCodingFormat); + value.EventItemCoding = reader.ReadByte(); + writer.WriteNumber($"[{value.EventItemCoding.ReadNumber()}]事件项编码-{((JT808EventItemCoding)value.EventItemCoding).ToString()}", value.MultimediaCodingFormat); + value.ChannelId = reader.ReadByte(); + writer.WriteNumber($"[{value.ChannelId.ReadNumber()}]通道ID", value.ChannelId); + } + public JT808_0x0800 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0800 jT808_0X0800 = new JT808_0x0800(); - jT808_0X0800.MultimediaId = reader.ReadUInt32(); - jT808_0X0800.MultimediaType = reader.ReadByte(); - jT808_0X0800.MultimediaCodingFormat = reader.ReadByte(); - jT808_0X0800.EventItemCoding = reader.ReadByte(); - jT808_0X0800.ChannelId = reader.ReadByte(); - return jT808_0X0800; + JT808_0x0800 value = new JT808_0x0800(); + value.MultimediaId = reader.ReadUInt32(); + value.MultimediaType = reader.ReadByte(); + value.MultimediaCodingFormat = reader.ReadByte(); + value.EventItemCoding = reader.ReadByte(); + value.ChannelId = reader.ReadByte(); + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0800 value, IJT808Config config) diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0801.cs b/src/JT808.Protocol/MessageBody/JT808_0x0801.cs index 4decbba..bddc5fc 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0801.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0801.cs @@ -1,6 +1,9 @@ -using JT808.Protocol.Formatters; +using JT808.Protocol.Enums; +using JT808.Protocol.Extensions; +using JT808.Protocol.Formatters; using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; +using System.Text.Json; namespace JT808.Protocol.MessageBody { @@ -8,7 +11,7 @@ namespace JT808.Protocol.MessageBody /// 多媒体数据上传 /// 0x0801 /// - public class JT808_0x0801 : JT808Bodies, IJT808MessagePackFormatter, IJT808_2019_Version + public class JT808_0x0801 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze, IJT808_2019_Version { public override ushort MsgId { get; } = 0x0801; public override string Description => "多媒体数据上传"; @@ -46,18 +49,39 @@ namespace JT808.Protocol.MessageBody /// public byte[] MultimediaDataPackage { get; set; } + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0801 value = new JT808_0x0801(); + value.MultimediaId = reader.ReadUInt32(); + writer.WriteNumber($"[{value.MultimediaId.ReadNumber()}]多媒体ID", value.MultimediaId); + value.MultimediaType = reader.ReadByte(); + writer.WriteNumber($"[{value.MultimediaType.ReadNumber()}]多媒体类型-{((JT808MultimediaType)value.MultimediaType).ToString()}", value.MultimediaType); + value.MultimediaCodingFormat = reader.ReadByte(); + writer.WriteNumber($"[{value.MultimediaCodingFormat.ReadNumber()}]多媒体格式编码-{((JT808MultimediaCodingFormat)value.MultimediaCodingFormat).ToString()}", value.MultimediaCodingFormat); + value.EventItemCoding = reader.ReadByte(); + writer.WriteNumber($"[{value.EventItemCoding.ReadNumber()}]事件项编码-{((JT808EventItemCoding)value.EventItemCoding).ToString()}", value.MultimediaCodingFormat); + value.ChannelId = reader.ReadByte(); + writer.WriteNumber($"[{value.ChannelId.ReadNumber()}]通道ID", value.ChannelId); + JT808MessagePackReader positionReader = new JT808MessagePackReader(reader.ReadArray(28)); + writer.WriteStartObject("位置基本信息"); + config.GetAnalyze().Analyze(ref positionReader, writer, config); + writer.WriteEndObject(); + value.MultimediaDataPackage = reader.ReadContent().ToArray(); + writer.WriteString($"多媒体数据包", value.MultimediaDataPackage.ToHexString()); + } + public JT808_0x0801 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0801 jT808_0X0801 = new JT808_0x0801(); - jT808_0X0801.MultimediaId = reader.ReadUInt32(); - jT808_0X0801.MultimediaType = reader.ReadByte(); - jT808_0X0801.MultimediaCodingFormat = reader.ReadByte(); - jT808_0X0801.EventItemCoding = reader.ReadByte(); - jT808_0X0801.ChannelId = reader.ReadByte(); + JT808_0x0801 value = new JT808_0x0801(); + value.MultimediaId = reader.ReadUInt32(); + value.MultimediaType = reader.ReadByte(); + value.MultimediaCodingFormat = reader.ReadByte(); + value.EventItemCoding = reader.ReadByte(); + value.ChannelId = reader.ReadByte(); JT808MessagePackReader positionReader = new JT808MessagePackReader(reader.ReadArray(28)); - jT808_0X0801.Position = config.GetMessagePackFormatter().Deserialize(ref positionReader, config); - jT808_0X0801.MultimediaDataPackage = reader.ReadContent().ToArray(); - return jT808_0X0801; + value.Position = config.GetMessagePackFormatter().Deserialize(ref positionReader, config); + value.MultimediaDataPackage = reader.ReadContent().ToArray(); + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0801 value, IJT808Config config) diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0802.cs b/src/JT808.Protocol/MessageBody/JT808_0x0802.cs index f108791..017d148 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0802.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0802.cs @@ -1,8 +1,11 @@ -using JT808.Protocol.Formatters; +using JT808.Protocol.Enums; +using JT808.Protocol.Extensions; +using JT808.Protocol.Formatters; using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; using JT808.Protocol.Metadata; using System.Collections.Generic; +using System.Text.Json; namespace JT808.Protocol.MessageBody { @@ -10,7 +13,7 @@ namespace JT808.Protocol.MessageBody /// 存储多媒体数据检索应答 /// 0x0802 /// - public class JT808_0x0802 : JT808Bodies, IJT808MessagePackFormatter, IJT808_2019_Version + public class JT808_0x0802 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze, IJT808_2019_Version { public override ushort MsgId { get; } = 0x0802; public override string Description => "存储多媒体数据检索应答"; @@ -29,13 +32,42 @@ namespace JT808.Protocol.MessageBody /// public List MultimediaSearchItems { get; set; } + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0802 value = new JT808_0x0802(); + value.MsgNum = reader.ReadUInt16(); + writer.WriteNumber($"[{value.MsgNum.ReadNumber()}]应答流水号", value.MsgNum); + value.MultimediaItemCount = reader.ReadUInt16(); + writer.WriteNumber($"[{value.MultimediaItemCount.ReadNumber()}]多媒体数据总项数", value.MultimediaItemCount); + writer.WriteStartArray("多媒体数据集合"); + for (var i = 0; i < value.MultimediaItemCount; i++) + { + writer.WriteStartObject(); + JT808MultimediaSearchProperty jT808MultimediaSearchProperty = new JT808MultimediaSearchProperty(); + jT808MultimediaSearchProperty.MultimediaId = reader.ReadUInt32(); + writer.WriteNumber($"[{jT808MultimediaSearchProperty.MultimediaId.ReadNumber()}]多媒体ID", jT808MultimediaSearchProperty.MultimediaId); + jT808MultimediaSearchProperty.MultimediaType = reader.ReadByte(); + writer.WriteNumber($"[{jT808MultimediaSearchProperty.MultimediaType.ReadNumber()}]多媒体类型-{((JT808MultimediaType)jT808MultimediaSearchProperty.MultimediaType).ToString()}", jT808MultimediaSearchProperty.MultimediaType); + jT808MultimediaSearchProperty.ChannelId = reader.ReadByte(); + writer.WriteNumber($"[{jT808MultimediaSearchProperty.ChannelId.ReadNumber()}]通道ID", jT808MultimediaSearchProperty.ChannelId); + jT808MultimediaSearchProperty.EventItemCoding = reader.ReadByte(); + writer.WriteNumber($"[{jT808MultimediaSearchProperty.EventItemCoding.ReadNumber()}]事件项编码-{((JT808EventItemCoding)jT808MultimediaSearchProperty.EventItemCoding).ToString()}", jT808MultimediaSearchProperty.EventItemCoding); + JT808MessagePackReader positionReader = new JT808MessagePackReader(reader.ReadArray(28)); + writer.WriteStartObject($"位置基本信息"); + config.GetAnalyze().Analyze(ref positionReader, writer, config); + writer.WriteEndObject(); + writer.WriteEndObject(); + } + writer.WriteEndArray(); + } + public JT808_0x0802 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0802 JT808_0x0802 = new JT808_0x0802(); - JT808_0x0802.MsgNum = reader.ReadUInt16(); - JT808_0x0802.MultimediaItemCount = reader.ReadUInt16(); - JT808_0x0802.MultimediaSearchItems = new List(); - for (var i = 0; i < JT808_0x0802.MultimediaItemCount; i++) + JT808_0x0802 value = new JT808_0x0802(); + value.MsgNum = reader.ReadUInt16(); + value.MultimediaItemCount = reader.ReadUInt16(); + value.MultimediaSearchItems = new List(); + for (var i = 0; i < value.MultimediaItemCount; i++) { JT808MultimediaSearchProperty jT808MultimediaSearchProperty = new JT808MultimediaSearchProperty(); jT808MultimediaSearchProperty.MultimediaId = reader.ReadUInt32(); @@ -44,9 +76,9 @@ namespace JT808.Protocol.MessageBody jT808MultimediaSearchProperty.EventItemCoding = reader.ReadByte(); JT808MessagePackReader positionReader = new JT808MessagePackReader(reader.ReadArray(28)); jT808MultimediaSearchProperty.Position = config.GetMessagePackFormatter().Deserialize(ref positionReader, config); - JT808_0x0802.MultimediaSearchItems.Add(jT808MultimediaSearchProperty); + value.MultimediaSearchItems.Add(jT808MultimediaSearchProperty); } - return JT808_0x0802; + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0802 value, IJT808Config config) diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0805.cs b/src/JT808.Protocol/MessageBody/JT808_0x0805.cs index c2a4a07..96c8969 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0805.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0805.cs @@ -1,7 +1,9 @@ -using JT808.Protocol.Formatters; +using JT808.Protocol.Extensions; +using JT808.Protocol.Formatters; using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; using System.Collections.Generic; +using System.Text.Json; namespace JT808.Protocol.MessageBody { @@ -9,7 +11,7 @@ namespace JT808.Protocol.MessageBody /// 摄像头立即拍摄命令应答 /// 0x0805 /// - public class JT808_0x0805 : JT808Bodies, IJT808MessagePackFormatter, IJT808_2019_Version + public class JT808_0x0805 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze, IJT808_2019_Version { public override ushort MsgId { get; } = 0x0805; public override string Description => "摄像头立即拍摄命令应答"; @@ -33,22 +35,55 @@ namespace JT808.Protocol.MessageBody /// public List MultimediaIds { get; set; } + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0805 value = new JT808_0x0805(); + value.ReplyMsgNum = reader.ReadUInt16(); + writer.WriteNumber($"[{value.ReplyMsgNum.ReadNumber()}]应答流水号", value.ReplyMsgNum); + value.Result = reader.ReadByte(); + string result = "成功"; + switch (value.Result) + { + case 1: + result = "失败"; + break; + case 2: + result = "通道不支持"; + break; + } + writer.WriteNumber($"[{value.Result.ReadNumber()}]结果-{result}", value.Result); + if (value.Result == 0) + { + value.MultimediaIdCount = reader.ReadUInt16(); + writer.WriteNumber($"[{value.MultimediaIdCount.ReadNumber()}]多媒体ID个数", value.MultimediaIdCount); + writer.WriteStartArray("多媒体ID列表"); + for (var i = 0; i < value.MultimediaIdCount; i++) + { + writer.WriteStartObject(); + uint id = reader.ReadUInt32(); + writer.WriteNumber($"[{id.ReadNumber()}]ID{i+1}", id); + writer.WriteEndObject(); + } + writer.WriteEndArray(); + } + } + public JT808_0x0805 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0805 jT808_0X0805 = new JT808_0x0805(); - jT808_0X0805.ReplyMsgNum = reader.ReadUInt16(); - jT808_0X0805.Result = reader.ReadByte(); - if (jT808_0X0805.Result == 0) + JT808_0x0805 value = new JT808_0x0805(); + value.ReplyMsgNum = reader.ReadUInt16(); + value.Result = reader.ReadByte(); + if (value.Result == 0) { - jT808_0X0805.MultimediaIdCount = reader.ReadUInt16(); - jT808_0X0805.MultimediaIds = new List(); - for (var i = 0; i < jT808_0X0805.MultimediaIdCount; i++) + value.MultimediaIdCount = reader.ReadUInt16(); + value.MultimediaIds = new List(); + for (var i = 0; i < value.MultimediaIdCount; i++) { uint id = reader.ReadUInt32(); - jT808_0X0805.MultimediaIds.Add(id); + value.MultimediaIds.Add(id); } } - return jT808_0X0805; + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0805 value, IJT808Config config) diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0900.cs b/src/JT808.Protocol/MessageBody/JT808_0x0900.cs index 3b9d75c..496ca88 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0900.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0900.cs @@ -3,13 +3,14 @@ using JT808.Protocol.Extensions; using JT808.Protocol.Formatters; using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; +using System.Text.Json; namespace JT808.Protocol.MessageBody { /// /// 数据上行透传 /// - public class JT808_0x0900 : JT808Bodies, IJT808MessagePackFormatter, IJT808_2019_Version + public class JT808_0x0900 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze, IJT808_2019_Version { public override ushort MsgId { get; } = 0x0900; public override string Description => "数据上行透传"; @@ -28,12 +29,22 @@ namespace JT808.Protocol.MessageBody /// public JT808_0x0900_BodyBase JT808_0x0900_BodyBase { get; set; } + 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()); + } + public JT808_0x0900 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0900 jT808_0X0900 = new JT808_0x0900(); - jT808_0X0900.PassthroughType = reader.ReadByte(); - jT808_0X0900.PassthroughData = reader.ReadContent().ToArray(); ; - return jT808_0X0900; + JT808_0x0900 value = new JT808_0x0900(); + value.PassthroughType = reader.ReadByte(); + value.PassthroughData = reader.ReadContent().ToArray(); + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0900 value, IJT808Config config) diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0901.cs b/src/JT808.Protocol/MessageBody/JT808_0x0901.cs index 7dcd81f..ed54da1 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0901.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0901.cs @@ -1,6 +1,9 @@ using JT808.Protocol.Attributes; +using JT808.Protocol.Extensions; using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; +using System.Text.Json; namespace JT808.Protocol.MessageBody { @@ -8,7 +11,7 @@ namespace JT808.Protocol.MessageBody /// 数据压缩上报 /// 0x0901 /// - public class JT808_0x0901 : JT808Bodies, IJT808MessagePackFormatter + public class JT808_0x0901 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze { public override ushort MsgId { get; } = 0x0901; public override string Description => "数据压缩上报"; @@ -22,14 +25,28 @@ namespace JT808.Protocol.MessageBody /// 可实现 自定义压缩算法 /// public byte[] UnCompressMessage { get; set; } + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0901 value = new JT808_0x0901(); + var compressMessageLength = reader.ReadUInt32(); + writer.WriteNumber($"[{compressMessageLength.ReadNumber()}]压缩消息长度", compressMessageLength); + var data = reader.ReadArray((int)compressMessageLength); + writer.WriteString("压缩消息体", data.ToArray().ToHexString()); + value.UnCompressMessage = config.Compress.Decompress(data.ToArray()); + value.UnCompressMessageLength = (uint)value.UnCompressMessage.Length; + writer.WriteNumber($"[{value.UnCompressMessageLength.ReadNumber()}]未压缩消息长度", value.UnCompressMessageLength); + writer.WriteString("未压缩消息体", value.UnCompressMessage.ToHexString()); + } + public JT808_0x0901 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0901 jT808_0X0901 = new JT808_0x0901(); + JT808_0x0901 value = new JT808_0x0901(); var compressMessageLength = reader.ReadUInt32(); var data = reader.ReadArray((int)compressMessageLength); - jT808_0X0901.UnCompressMessage = config.Compress.Decompress(data.ToArray()); - jT808_0X0901.UnCompressMessageLength = (uint)jT808_0X0901.UnCompressMessage.Length; - return jT808_0X0901; + value.UnCompressMessage = config.Compress.Decompress(data.ToArray()); + value.UnCompressMessageLength = (uint)value.UnCompressMessage.Length; + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0901 value, IJT808Config config) diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0A00.cs b/src/JT808.Protocol/MessageBody/JT808_0x0A00.cs index 37d978f..e63d337 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0A00.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0A00.cs @@ -1,6 +1,9 @@ using JT808.Protocol.Exceptions; +using JT808.Protocol.Extensions; using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; +using System.Text.Json; namespace JT808.Protocol.MessageBody { @@ -8,7 +11,7 @@ namespace JT808.Protocol.MessageBody /// 终端 RSA 公钥 /// 0x0A00 /// - public class JT808_0x0A00 : JT808Bodies, IJT808MessagePackFormatter + public class JT808_0x0A00 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze { public override ushort MsgId { get; } = 0x0A00; public override string Description => "终端RSA公钥"; @@ -22,18 +25,32 @@ namespace JT808.Protocol.MessageBody /// RSA 公钥{e,n}中的 n /// public byte[] N { get; set; } + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0A00 value = new JT808_0x0A00(); + value.E = reader.ReadUInt32(); + writer.WriteNumber($"[{value.E.ReadNumber()}]终端RSA公钥e", value.E); + value.N = reader.ReadArray(128).ToArray(); + writer.WriteString($"终端RSA公钥n", value.N.ToHexString()); + if (value.N.Length != 128) + { + throw new JT808Exception(Enums.JT808ErrorCode.NotEnoughLength, $"{nameof(value.N)}->128"); + } + } + public JT808_0x0A00 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0A00 jT808_0X0A00 = new JT808_0x0A00 + JT808_0x0A00 value = new JT808_0x0A00 { E = reader.ReadUInt32(), N = reader.ReadArray(128).ToArray() }; - if (jT808_0X0A00.N.Length != 128) + if (value.N.Length != 128) { - throw new JT808Exception(Enums.JT808ErrorCode.NotEnoughLength, $"{nameof(jT808_0X0A00.N)}->128"); + throw new JT808Exception(Enums.JT808ErrorCode.NotEnoughLength, $"{nameof(value.N)}->128"); } - return jT808_0X0A00; + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0A00 value, IJT808Config config) diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8103.cs b/src/JT808.Protocol/MessageBody/JT808_0x8103.cs index 264041d..db7b853 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x8103.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x8103.cs @@ -1,17 +1,19 @@ using JT808.Protocol.Attributes; using JT808.Protocol.Extensions; using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json; namespace JT808.Protocol.MessageBody { /// /// 设置终端参数 /// - public class JT808_0x8103 : JT808Bodies, IJT808MessagePackFormatter + public class JT808_0x8103 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze { public override ushort MsgId { get; } = 0x8103; public override string Description => "设置终端参数"; @@ -39,7 +41,7 @@ namespace JT808.Protocol.MessageBody public JT808_0x8103 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x8103 jT808_0x8103 = new JT808_0x8103 + JT808_0x8103 value = new JT808_0x8103 { ParamList = new List(), CustomParamList = new List() @@ -53,12 +55,12 @@ namespace JT808.Protocol.MessageBody if (config.JT808_0X8103_Factory.Map.TryGetValue(paramId, out object instance)) { dynamic attachImpl = JT808MessagePackFormatterResolverExtensions.JT808DynamicDeserialize(instance, ref reader, config); - jT808_0x8103.ParamList.Add(attachImpl); + value.ParamList.Add(attachImpl); } else if (config.JT808_0X8103_Custom_Factory.Map.TryGetValue(paramId, out object customInstance)) { dynamic attachImpl = JT808MessagePackFormatterResolverExtensions.JT808DynamicDeserialize(customInstance, ref reader, config); - jT808_0x8103.CustomParamList.Add(attachImpl); + value.CustomParamList.Add(attachImpl); } } } @@ -66,7 +68,7 @@ namespace JT808.Protocol.MessageBody { } - return jT808_0x8103; + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8103 value, IJT808Config config) @@ -88,5 +90,36 @@ namespace JT808.Protocol.MessageBody } catch (Exception ex) { } } + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + var paramCount = reader.ReadByte();//参数总数 + writer.WriteNumber($"[{paramCount.ReadNumber()}]参数总数", paramCount); + try + { + writer.WriteStartArray("参数项"); + for (int i = 0; i < paramCount; i++) + { + var paramId = reader.ReadVirtualUInt32();//参数ID + if (config.JT808_0X8103_Factory.Map.TryGetValue(paramId, out object instance)) + { + writer.WriteStartObject(); + instance.Analyze(ref reader, writer, config); + writer.WriteEndObject(); + } + else if (config.JT808_0X8103_Custom_Factory.Map.TryGetValue(paramId, out object customInstance)) + { + writer.WriteStartObject(); + customInstance.Analyze(ref reader, writer, config); + writer.WriteEndObject(); + } + } + writer.WriteEndArray(); + } + catch (Exception ex) + { + writer.WriteString($"异常信息", ex.StackTrace); + } + } } } diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8105.cs b/src/JT808.Protocol/MessageBody/JT808_0x8105.cs index 4909c5d..f348987 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x8105.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x8105.cs @@ -226,7 +226,7 @@ namespace JT808.Protocol.MessageBody /// 制造商ID /// 终端制造商编码 /// - public long? ManufacturerCode { get; set; } + public string MakerId { get; set; } /// /// 监管平台鉴权码 /// 监管平台下发的鉴权码,仅用于终端连接到监管平台之后的鉴权,终端连接回原监控平台还用原鉴权码 @@ -254,7 +254,7 @@ namespace JT808.Protocol.MessageBody public ushort? ConnectTimeLimit { get; set; } public override string ToString() { - return $"{ConnectionControl};{DialPointName};{DialUserName};{DialPwd};{ServerUrl};{TCPPort};{UDPPort};{ManufacturerCode};{MonitoringPlatformAuthenticationCode};{HardwareVersion};{FirmwareVersion};{URL};{ConnectTimeLimit}"; + return $"{ConnectionControl};{DialPointName};{DialUserName};{DialPwd};{ServerUrl};{TCPPort};{UDPPort};{MakerId};{MonitoringPlatformAuthenticationCode};{HardwareVersion};{FirmwareVersion};{URL};{ConnectTimeLimit}"; } public void SetCommandParams(string commandValue) { @@ -289,7 +289,7 @@ namespace JT808.Protocol.MessageBody } if (!string.IsNullOrEmpty(values[7])) { - ManufacturerCode = long.Parse(values[7]); + MakerId = values[7]; } if (!string.IsNullOrEmpty(values[8])) {