From d7e65ee6eaed3fe6f19886a2611acffa288b3c75 Mon Sep 17 00:00:00 2001 From: "smallchi(Koike)" <564952747@qq.com> Date: Sun, 19 Jan 2020 22:49:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A08600-8608=E5=8D=8F=E8=AE=AE?= =?UTF-8?q?=E5=88=86=E6=9E=90=E5=99=A8=E5=8F=8A=E5=AF=B9=E5=BA=94=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JT808.Protocol.Test.csproj | 1 + .../MessageBody/JT808_0x8600Test.cs | 7 ++ .../MessageBody/JT808_0x8601Test.cs | 7 ++ .../MessageBody/JT808_0x8602Test.cs | 6 ++ .../MessageBody/JT808_0x8603Test.cs | 7 ++ .../MessageBody/JT808_0x8604Test.cs | 7 ++ .../MessageBody/JT808_0x8605Test.cs | 7 ++ .../MessageBody/JT808_0x8606Test.cs | 11 ++- .../MessageBody/JT808_0x8607Test.cs | 45 +++++++++++ .../MessageBody/JT808_0x8608Test.cs | 7 ++ src/JT808.Protocol/JT808.Protocol.xml | 1 + .../MessageBody/JT808_0x8600.cs | 61 ++++++++++++++- .../MessageBody/JT808_0x8601.cs | 23 +++++- .../MessageBody/JT808_0x8602.cs | 63 +++++++++++++++- .../MessageBody/JT808_0x8603.cs | 23 +++++- .../MessageBody/JT808_0x8604.cs | 57 +++++++++++++- .../MessageBody/JT808_0x8605.cs | 23 +++++- .../MessageBody/JT808_0x8606.cs | 74 ++++++++++++++++++- .../MessageBody/JT808_0x8607.cs | 23 +++++- .../MessageBody/JT808_0x8608.cs | 27 ++++++- .../Metadata/JT808InflectionPointProperty.cs | 1 + 21 files changed, 465 insertions(+), 16 deletions(-) create mode 100644 src/JT808.Protocol.Test/MessageBody/JT808_0x8607Test.cs diff --git a/src/JT808.Protocol.Test/JT808.Protocol.Test.csproj b/src/JT808.Protocol.Test/JT808.Protocol.Test.csproj index f62de82..26022c1 100644 --- a/src/JT808.Protocol.Test/JT808.Protocol.Test.csproj +++ b/src/JT808.Protocol.Test/JT808.Protocol.Test.csproj @@ -88,6 +88,7 @@ + diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x8600Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x8600Test.cs index 36fa2e5..3b61dd2 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x8600Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x8600Test.cs @@ -153,5 +153,12 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal(666, item0.NightMaximumSpeed); Assert.Equal("SmallChi", item0.AreaName); } + + [Fact] + public void Test_2019_3() + { + byte[] bytes = "0101000005F200DE075BCD15075BCD15000000C8003CC8029A0008536D616C6C436869".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes, JT808Version.JTT2019); + } } } diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x8601Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x8601Test.cs index ad63fb4..7dedf57 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x8601Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x8601Test.cs @@ -29,5 +29,12 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal((uint)1, jT808_0X8601.AreaIds[0]); Assert.Equal((uint)2, jT808_0X8601.AreaIds[1]); } + + [Fact] + public void Test3() + { + var bytes = "020000000100000002".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes); + } } } diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x8602Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x8602Test.cs index aa8eb63..624749e 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x8602Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x8602Test.cs @@ -86,5 +86,11 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal((ushort)60, item1.HighestSpeed); Assert.Equal((byte)200, item1.OverspeedDuration); } + [Fact] + public void Test3() + { + byte[] bytes = "0102000005F200DE075BCD13075BCD12075BCD15075BCD14003CC8000005F3000A075BCCBE075BCCBF075BCCBC075BCCBD003CC8".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes); + } } } diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x8603Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x8603Test.cs index de922e9..9d601fa 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x8603Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x8603Test.cs @@ -31,5 +31,12 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal((uint)772, jT808_0X8603.AreaIds[2]); Assert.Equal(3, jT808_0X8603.AreaCount); } + + [Fact] + public void Test3() + { + byte[] bytes = "0300000B16000006B500000304".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes); + } } } diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x8604Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x8604Test.cs index c6bcb26..eb5fb12 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x8604Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x8604Test.cs @@ -56,5 +56,12 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal((uint)123456700, jT808_0X8604.PeakItems[1].Lat); Assert.Equal((uint)123456701, jT808_0X8604.PeakItems[1].Lng); } + + [Fact] + public void Test3() + { + byte[] bytes = "000004D200011811200000121811210000120002075BCD15075BCD14075BCCBC075BCCBD".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes); + } } } diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x8605Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x8605Test.cs index 0372bc3..3ca83bf 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x8605Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x8605Test.cs @@ -31,5 +31,12 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal((uint)772, jT808_0X8605.AreaIds[2]); Assert.Equal(3, jT808_0X8605.AreaCount); } + + [Fact] + public void Test3() + { + byte[] bytes = "0300000B16000006B500000304".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes); + } } } diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x8606Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x8606Test.cs index 786a6b6..308d323 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x8606Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x8606Test.cs @@ -234,7 +234,7 @@ namespace JT808.Protocol.Test.MessageBody SectionOverspeedDuration = 23, SectionProperty = 3, SectionWidth = 56, - NightMaximumSpeed=80 + NightMaximumSpeed = 80 }); jT808_0X8606.InflectionPointItems.Add(new JT808InflectionPointProperty() { @@ -251,7 +251,7 @@ namespace JT808.Protocol.Test.MessageBody NightMaximumSpeed = 66 }); jT808_0X8606.RouteName = "koike518"; - var hex = JT808Serializer.Serialize(jT808_0X8606,JT808Version.JTT2019).ToHexString(); + var hex = JT808Serializer.Serialize(jT808_0X8606, JT808Version.JTT2019).ToHexString(); Assert.Equal("0000270F00332001040000122001040000120002000003E800000507075BCD15075BCD1438030032007B0045170050000003E900002EE7075BCD0C075BCD0D4B03003A007C002A1A004200086B6F696B65353138", hex); } @@ -295,5 +295,12 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal("koike518", jT808_0X8606.RouteName); } + + [Fact] + public void Test6_2019_1() + { + byte[] bytes = "0000270F00332001040000122001040000120002000003E800000507075BCD15075BCD1438030032007B0045170050000003E900002EE7075BCD0C075BCD0D4B03003A007C002A1A004200086B6F696B65353138".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes, JT808Version.JTT2019); + } } } diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x8607Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x8607Test.cs new file mode 100644 index 0000000..7c447aa --- /dev/null +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x8607Test.cs @@ -0,0 +1,45 @@ +using JT808.Protocol.MessageBody; +using JT808.Protocol.Extensions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; + +namespace JT808.Protocol.Test.MessageBody +{ + public class JT808_0x8607Test + { + JT808Serializer JT808Serializer = new JT808Serializer(); + + [Fact] + public void Test1() + { + JT808_0x8607 value = new JT808_0x8607(); + value.AreaIds = new List() + { + 1,2,3,4 + }; + var hex = JT808Serializer.Serialize(value).ToHexString(); + Assert.Equal("0400000001000000020000000300000004", hex); + } + + [Fact] + public void Test2() + { + byte[] bytes = "0400000001000000020000000300000004".ToHexBytes(); + JT808_0x8607 value = JT808Serializer.Deserialize(bytes); + Assert.Equal(4, value.AreaCount); + Assert.Equal(1u, value.AreaIds[0]); + Assert.Equal(2u, value.AreaIds[1]); + Assert.Equal(3u, value.AreaIds[2]); + Assert.Equal(4u, value.AreaIds[3]); + } + + [Fact] + public void Test3() + { + byte[] bytes = "0400000001000000020000000300000004".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes); + } + } +} diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x8608Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x8608Test.cs index a61e57f..c5b3946 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x8608Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x8608Test.cs @@ -54,5 +54,12 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal(1, value.QueryType); Assert.Equal(0u, value.Count); } + + [Fact] + public void Test5() + { + byte[] bytes = "0000000003000000010000000200000003".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes); + } } } diff --git a/src/JT808.Protocol/JT808.Protocol.xml b/src/JT808.Protocol/JT808.Protocol.xml index f146066..026cb76 100644 --- a/src/JT808.Protocol/JT808.Protocol.xml +++ b/src/JT808.Protocol/JT808.Protocol.xml @@ -6976,6 +6976,7 @@ + 夜间最高速度 单位为千米每小时(km/h),若路段属性 1 位为 0 则没有该字段 diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8600.cs b/src/JT808.Protocol/MessageBody/JT808_0x8600.cs index 390dfed..b4bbc56 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x8600.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x8600.cs @@ -1,10 +1,12 @@ 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; using System.Collections.Generic; +using System.Text.Json; namespace JT808.Protocol.MessageBody { @@ -13,7 +15,7 @@ namespace JT808.Protocol.MessageBody /// 0x8600 /// 注:本条消息协议支持周期时间范围,如要限制每天的8:30-18:00,起始/结束时间设为:00-00-00-08-30-00/00-00-00-18-00-00,其他以此类推 /// - public class JT808_0x8600 : JT808Bodies, IJT808MessagePackFormatter, IJT808_2019_Version + public class JT808_0x8600 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze, IJT808_2019_Version { public override ushort MsgId { get; } = 0x8600; public override string Description => "设置圆形区域"; @@ -123,5 +125,62 @@ namespace JT808.Protocol.MessageBody } } } + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x8600 value = new JT808_0x8600(); + value.SettingAreaProperty = reader.ReadByte(); + writer.WriteNumber($"[{ value.SettingAreaProperty.ReadNumber()}]设置属性", value.SettingAreaProperty); + value.AreaCount = reader.ReadByte(); + writer.WriteNumber($"[{ value.AreaCount.ReadNumber()}]区域数", value.AreaCount); + writer.WriteStartArray("区域项"); + for (var i = 0; i < value.AreaCount; i++) + { + writer.WriteStartObject(); + JT808CircleAreaProperty jT808CircleAreaProperty = new JT808CircleAreaProperty(); + jT808CircleAreaProperty.AreaId = reader.ReadUInt32(); + writer.WriteNumber($"[{ jT808CircleAreaProperty.AreaId.ReadNumber()}]区域ID", jT808CircleAreaProperty.AreaId); + jT808CircleAreaProperty.AreaProperty = reader.ReadUInt16(); + writer.WriteNumber($"[{ jT808CircleAreaProperty.AreaProperty.ReadNumber()}]区域属性", jT808CircleAreaProperty.AreaProperty); + jT808CircleAreaProperty.CenterPointLat = reader.ReadUInt32(); + writer.WriteNumber($"[{ jT808CircleAreaProperty.CenterPointLat.ReadNumber()}]中心点纬度", jT808CircleAreaProperty.CenterPointLat); + jT808CircleAreaProperty.CenterPointLng = reader.ReadUInt32(); + writer.WriteNumber($"[{ jT808CircleAreaProperty.CenterPointLng.ReadNumber()}]中心点经度", jT808CircleAreaProperty.CenterPointLng); + jT808CircleAreaProperty.Radius = reader.ReadUInt32(); + writer.WriteNumber($"[{ jT808CircleAreaProperty.Radius.ReadNumber()}]半径", jT808CircleAreaProperty.Radius); + ReadOnlySpan areaProperty16Bit = Convert.ToString(jT808CircleAreaProperty.AreaProperty, 2).PadLeft(16, '0').AsSpan(); + bool bit0Flag = areaProperty16Bit.Slice(areaProperty16Bit.Length - 1).ToString().Equals("0"); + if (!bit0Flag) + { + jT808CircleAreaProperty.StartTime = reader.ReadDateTime6(); + writer.WriteString($"[{ jT808CircleAreaProperty.StartTime.Value.ToString("yyMMddHHmmss")}]起始时间", jT808CircleAreaProperty.StartTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); + jT808CircleAreaProperty.EndTime = reader.ReadDateTime6(); + writer.WriteString($"[{ jT808CircleAreaProperty.EndTime.Value.ToString("yyMMddHHmmss")}]结束时间", jT808CircleAreaProperty.EndTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); + } + bool bit1Flag = areaProperty16Bit.Slice(areaProperty16Bit.Length - 2, 1).ToString().Equals("0"); + if (!bit1Flag) + { + jT808CircleAreaProperty.HighestSpeed = reader.ReadUInt16(); + writer.WriteNumber($"[{ jT808CircleAreaProperty.HighestSpeed.Value.ReadNumber()}]最高速度", jT808CircleAreaProperty.HighestSpeed.Value); + jT808CircleAreaProperty.OverspeedDuration = reader.ReadByte(); + writer.WriteNumber($"[{ jT808CircleAreaProperty.OverspeedDuration.Value.ReadNumber()}]超速持续时间", jT808CircleAreaProperty.OverspeedDuration.Value); + if (reader.Version == JT808Version.JTT2019) + { + jT808CircleAreaProperty.NightMaximumSpeed = reader.ReadUInt16(); + writer.WriteNumber($"[{ jT808CircleAreaProperty.NightMaximumSpeed.ReadNumber()}]夜间最高速度", jT808CircleAreaProperty.NightMaximumSpeed); + } + } + if (reader.Version == JT808Version.JTT2019) + { + jT808CircleAreaProperty.NameLength = reader.ReadUInt16(); + writer.WriteNumber($"[{ jT808CircleAreaProperty.NameLength.ReadNumber()}]名称长度", jT808CircleAreaProperty.NameLength); + var areaNameBuffer = reader.ReadVirtualArray(jT808CircleAreaProperty.NameLength); + jT808CircleAreaProperty.AreaName = reader.ReadString(jT808CircleAreaProperty.NameLength); + writer.WriteString($"[{ areaNameBuffer.ToArray().ToHexString()}]区域名称", jT808CircleAreaProperty.AreaName); + } + writer.WriteEndObject(); + } + writer.WriteEndArray(); + } } } diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8601.cs b/src/JT808.Protocol/MessageBody/JT808_0x8601.cs index f08bdad..8bd06ea 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x8601.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x8601.cs @@ -1,6 +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 { @@ -8,7 +11,7 @@ namespace JT808.Protocol.MessageBody /// 删除圆形区域 /// 0x8601 /// - public class JT808_0x8601 : JT808Bodies, IJT808MessagePackFormatter + public class JT808_0x8601 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze { public override ushort MsgId { get; } = 0x8601; public override string Description => "删除圆形区域"; @@ -45,5 +48,21 @@ namespace JT808.Protocol.MessageBody } } } + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x8601 value = new JT808_0x8601(); + value.AreaCount = reader.ReadByte(); + writer.WriteNumber($"[{ value.AreaCount.ReadNumber()}]区域数", value.AreaCount); + writer.WriteStartArray("区域ID集合"); + for (var i = 0; i < value.AreaCount; i++) + { + writer.WriteStartObject(); + var areaId = reader.ReadUInt32(); + writer.WriteNumber($"[{areaId.ReadNumber()}]Id{i + 1}", areaId); + writer.WriteEndObject(); + } + writer.WriteEndArray(); + } } } diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8602.cs b/src/JT808.Protocol/MessageBody/JT808_0x8602.cs index 36d2c32..c5da97a 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x8602.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x8602.cs @@ -1,10 +1,12 @@ 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; using System.Collections.Generic; +using System.Text.Json; namespace JT808.Protocol.MessageBody { @@ -12,7 +14,7 @@ namespace JT808.Protocol.MessageBody /// 设置矩形区域 /// 0x8602 /// - public class JT808_0x8602 : JT808Bodies, IJT808MessagePackFormatter, IJT808_2019_Version + public class JT808_0x8602 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze, IJT808_2019_Version { public override ushort MsgId { get; } = 0x8602; public override string Description => "设置矩形区域"; @@ -124,5 +126,64 @@ namespace JT808.Protocol.MessageBody } } } + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x8602 value = new JT808_0x8602(); + value.SettingAreaProperty = reader.ReadByte(); + writer.WriteNumber($"[{ value.SettingAreaProperty.ReadNumber()}]设置属性", value.SettingAreaProperty); + value.AreaCount = reader.ReadByte(); + writer.WriteNumber($"[{ value.AreaCount.ReadNumber()}]区域总数", value.AreaCount); + writer.WriteStartArray("区域项"); + for (var i = 0; i < value.AreaCount; i++) + { + writer.WriteStartObject(); + JT808RectangleAreaProperty areaProperty = new JT808RectangleAreaProperty(); + areaProperty.AreaId = reader.ReadUInt32(); + writer.WriteNumber($"[{areaProperty.AreaId.ReadNumber()}]区域ID", areaProperty.AreaId); + areaProperty.AreaProperty = reader.ReadUInt16(); + writer.WriteNumber($"[{areaProperty.AreaProperty.ReadNumber()}]区域属性", areaProperty.AreaProperty); + areaProperty.UpLeftPointLat = reader.ReadUInt32(); + writer.WriteNumber($"[{areaProperty.UpLeftPointLat.ReadNumber()}]左上点纬度", areaProperty.UpLeftPointLat); + areaProperty.UpLeftPointLng = reader.ReadUInt32(); + writer.WriteNumber($"[{areaProperty.UpLeftPointLng.ReadNumber()}]左上点经度", areaProperty.UpLeftPointLng); + areaProperty.LowRightPointLat = reader.ReadUInt32(); + writer.WriteNumber($"[{areaProperty.LowRightPointLat.ReadNumber()}]右下点纬度", areaProperty.LowRightPointLat); + areaProperty.LowRightPointLng = reader.ReadUInt32(); + writer.WriteNumber($"[{areaProperty.LowRightPointLng.ReadNumber()}]右下点经度", areaProperty.LowRightPointLng); + ReadOnlySpan areaProperty16Bit = Convert.ToString(areaProperty.AreaProperty, 2).PadLeft(16, '0').AsSpan(); + bool bit0Flag = areaProperty16Bit.Slice(areaProperty16Bit.Length - 1).ToString().Equals("0"); + if (!bit0Flag) + { + areaProperty.StartTime = reader.ReadDateTime6(); + writer.WriteString($"[{ areaProperty.StartTime.Value.ToString("yyMMddHHmmss")}]起始时间", areaProperty.StartTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); + areaProperty.EndTime = reader.ReadDateTime6(); + writer.WriteString($"[{ areaProperty.EndTime.Value.ToString("yyMMddHHmmss")}]起始时间", areaProperty.EndTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); + } + bool bit1Flag = areaProperty16Bit.Slice(areaProperty16Bit.Length - 2, 1).ToString().Equals("0"); + if (!bit1Flag) + { + areaProperty.HighestSpeed = reader.ReadUInt16(); + writer.WriteNumber($"[{areaProperty.HighestSpeed.Value.ReadNumber()}]最高速度", areaProperty.HighestSpeed.Value); + areaProperty.OverspeedDuration = reader.ReadByte(); + writer.WriteNumber($"[{areaProperty.OverspeedDuration.Value.ReadNumber()}]超速持续时间", areaProperty.OverspeedDuration.Value); + if (reader.Version == JT808Version.JTT2019) + { + areaProperty.NightMaximumSpeed = reader.ReadUInt16(); + writer.WriteNumber($"[{areaProperty.NightMaximumSpeed.ReadNumber()}]夜间最高速度", areaProperty.NightMaximumSpeed); + } + } + if (reader.Version == JT808Version.JTT2019) + { + areaProperty.NameLength = reader.ReadUInt16(); + writer.WriteNumber($"[{areaProperty.NameLength.ReadNumber()}]夜间最高速度", areaProperty.NameLength); + var areaNameBuffer = reader.ReadVirtualArray(areaProperty.NameLength); + areaProperty.AreaName = reader.ReadString(areaProperty.NameLength); + writer.WriteString($"[{ areaNameBuffer.ToArray().ToHexString()}]区域名称", areaProperty.AreaName); + } + writer.WriteEndObject(); + } + writer.WriteEndArray(); + } } } diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8603.cs b/src/JT808.Protocol/MessageBody/JT808_0x8603.cs index c38cfc3..93e8c9f 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x8603.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x8603.cs @@ -1,6 +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 { @@ -8,7 +11,7 @@ namespace JT808.Protocol.MessageBody /// 删除矩形区域 /// 0x8603 /// - public class JT808_0x8603 : JT808Bodies, IJT808MessagePackFormatter + public class JT808_0x8603 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze { public override ushort MsgId { get; } = 0x8603; public override string Description => "删除矩形区域"; @@ -45,5 +48,21 @@ namespace JT808.Protocol.MessageBody } } } + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x8603 value = new JT808_0x8603(); + value.AreaCount = reader.ReadByte(); + writer.WriteNumber($"[{ value.AreaCount.ReadNumber()}]区域数", value.AreaCount); + writer.WriteStartArray("区域ID集合"); + for (var i = 0; i < value.AreaCount; i++) + { + writer.WriteStartObject(); + var areaId = reader.ReadUInt32(); + writer.WriteNumber($"[{areaId.ReadNumber()}]Id{i + 1}", areaId); + writer.WriteEndObject(); + } + writer.WriteEndArray(); + } } } diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8604.cs b/src/JT808.Protocol/MessageBody/JT808_0x8604.cs index 3c9be9a..f47aabd 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x8604.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x8604.cs @@ -1,10 +1,12 @@ 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; using System.Collections.Generic; +using System.Text.Json; namespace JT808.Protocol.MessageBody { @@ -12,7 +14,7 @@ namespace JT808.Protocol.MessageBody /// 设置多边形区域 /// 0x8604 /// - public class JT808_0x8604 : JT808Bodies, IJT808MessagePackFormatter, IJT808_2019_Version + public class JT808_0x8604 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze, IJT808_2019_Version { public override ushort MsgId { get; } = 0x8604; public override string Description => "设置多边形区域"; @@ -157,5 +159,58 @@ namespace JT808.Protocol.MessageBody writer.WriteUInt16Return((ushort)(writer.GetCurrentPosition() - AreaNameLengthPosition - 2), AreaNameLengthPosition); } } + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x8604 value = new JT808_0x8604(); + value.AreaId = reader.ReadUInt32(); + writer.WriteNumber($"[{ value.AreaId.ReadNumber()}]区域ID", value.AreaId); + value.AreaProperty = reader.ReadUInt16(); + writer.WriteNumber($"[{ value.AreaProperty.ReadNumber()}]区域属性", value.AreaProperty); + ReadOnlySpan areaProperty16Bit = Convert.ToString(value.AreaProperty, 2).PadLeft(16, '0').AsSpan(); + bool bit0Flag = areaProperty16Bit.Slice(areaProperty16Bit.Length - 1).ToString().Equals("0"); + if (!bit0Flag) + { + value.StartTime = reader.ReadDateTime6(); + writer.WriteString($"[{ value.StartTime.Value.ToString("yyMMddHHmmss")}]起始时间", value.StartTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); + value.EndTime = reader.ReadDateTime6(); + writer.WriteString($"[{ value.EndTime.Value.ToString("yyMMddHHmmss")}]结束时间", value.EndTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); + } + bool bit1Flag = areaProperty16Bit.Slice(areaProperty16Bit.Length - 2, 1).ToString().Equals("0"); + if (!bit1Flag) + { + value.HighestSpeed = reader.ReadUInt16(); + writer.WriteNumber($"[{ value.HighestSpeed.Value.ReadNumber()}]最高速度", value.HighestSpeed.Value); + value.OverspeedDuration = reader.ReadByte(); + writer.WriteNumber($"[{ value.OverspeedDuration.Value.ReadNumber()}]超速持续时间", value.OverspeedDuration.Value); + } + value.PeakCount = reader.ReadUInt16(); + writer.WriteNumber($"[{ value.PeakCount.ReadNumber()}]区域总顶点数", value.PeakCount); + writer.WriteStartArray("区域顶"); + for (var i = 0; i < value.PeakCount; i++) + { + writer.WriteStartObject(); + var item = new JT808PeakProperty(); + item.Lat = reader.ReadUInt32(); + writer.WriteNumber($"[{item.Lat.ReadNumber()}]顶点纬度", item.Lat); + item.Lng = reader.ReadUInt32(); + writer.WriteNumber($"[{item.Lng.ReadNumber()}]顶点经度", item.Lng); + writer.WriteEndObject(); + } + writer.WriteEndArray(); + if (reader.Version == JT808Version.JTT2019) + { + if (!bit1Flag) + { + value.NightMaximumSpeed = reader.ReadUInt16(); + writer.WriteNumber($"[{value.NightMaximumSpeed .ReadNumber()}]夜间最高速度", value.NightMaximumSpeed); + } + value.NameLength = reader.ReadUInt16(); + writer.WriteNumber($"[{value.NameLength.ReadNumber()}]名称长度", value.NameLength); + var nameBuffer = reader.ReadVirtualArray(value.NameLength); + value.AreaName = reader.ReadString(value.NameLength); + writer.WriteString($"[{ nameBuffer.ToArray().ToHexString()}]区域名称", value.AreaName); + } + } } } diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8605.cs b/src/JT808.Protocol/MessageBody/JT808_0x8605.cs index fa375ac..b9c2acc 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x8605.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x8605.cs @@ -1,6 +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 { @@ -8,7 +11,7 @@ namespace JT808.Protocol.MessageBody /// 删除多边形区域 /// 0x8605 /// - public class JT808_0x8605 : JT808Bodies, IJT808MessagePackFormatter + public class JT808_0x8605 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze { public override ushort MsgId { get; } = 0x8605; public override string Description => "删除多边形区域"; @@ -44,5 +47,21 @@ namespace JT808.Protocol.MessageBody } } } + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x8605 value = new JT808_0x8605(); + value.AreaCount = reader.ReadByte(); + writer.WriteNumber($"[{ value.AreaCount.ReadNumber()}]区域数", value.AreaCount); + writer.WriteStartArray("区域ID集合"); + for (var i = 0; i < value.AreaCount; i++) + { + writer.WriteStartObject(); + var areaId = reader.ReadUInt32(); + writer.WriteNumber($"[{areaId.ReadNumber()}]Id{i + 1}", areaId); + writer.WriteEndObject(); + } + writer.WriteEndArray(); + } } } diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8606.cs b/src/JT808.Protocol/MessageBody/JT808_0x8606.cs index eb3fe9e..b217ce9 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x8606.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x8606.cs @@ -1,10 +1,12 @@ 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; using System.Collections.Generic; +using System.Text.Json; namespace JT808.Protocol.MessageBody { @@ -12,7 +14,7 @@ namespace JT808.Protocol.MessageBody /// 设置路线 /// 0x8606 /// - public class JT808_0x8606 : JT808Bodies, IJT808MessagePackFormatter, IJT808_2019_Version + public class JT808_0x8606 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze, IJT808_2019_Version { public override ushort MsgId { get; } = 0x8606; public override string Description => "设置路线"; @@ -158,5 +160,75 @@ namespace JT808.Protocol.MessageBody writer.WriteUInt16Return((ushort)(writer.GetCurrentPosition() - RouteNameLengthPosition - 2), RouteNameLengthPosition); } } + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x8606 value = new JT808_0x8606(); + value.RouteId = reader.ReadUInt32(); + writer.WriteNumber($"[{ value.RouteId.ReadNumber()}]路线ID", value.RouteId); + value.RouteProperty = reader.ReadUInt16(); + writer.WriteNumber($"[{ value.RouteProperty.ReadNumber()}]路线属性", value.RouteProperty); + ReadOnlySpan routeProperty16Bit = Convert.ToString(value.RouteProperty, 2).PadLeft(16, '0').AsSpan(); + bool bit0Flag = routeProperty16Bit.Slice(routeProperty16Bit.Length - 1).ToString().Equals("0"); + if (!bit0Flag) + { + value.StartTime = reader.ReadDateTime6(); + writer.WriteString($"[{ value.StartTime.Value.ToString("yyMMddHHmmss")}]起始时间", value.StartTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); + value.EndTime = reader.ReadDateTime6(); + writer.WriteString($"[{ value.EndTime.Value.ToString("yyMMddHHmmss")}]结束时间", value.EndTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); + } + value.InflectionPointCount = reader.ReadUInt16(); + writer.WriteNumber($"[{ value.InflectionPointCount.ReadNumber()}]路线总拐点数", value.InflectionPointCount); + writer.WriteStartArray("拐点项"); + for (var i = 0; i < value.InflectionPointCount; i++) + { + writer.WriteStartObject(); + JT808InflectionPointProperty jT808InflectionPointProperty = new JT808InflectionPointProperty(); + jT808InflectionPointProperty.InflectionPointId = reader.ReadUInt32(); + writer.WriteNumber($"[{ jT808InflectionPointProperty.InflectionPointId.ReadNumber()}]拐点ID", jT808InflectionPointProperty.InflectionPointId); + jT808InflectionPointProperty.SectionId = reader.ReadUInt32(); + writer.WriteNumber($"[{ jT808InflectionPointProperty.SectionId.ReadNumber()}]路段ID", jT808InflectionPointProperty.SectionId); + jT808InflectionPointProperty.InflectionPointLat = reader.ReadUInt32(); + writer.WriteNumber($"[{ jT808InflectionPointProperty.InflectionPointLat.ReadNumber()}]拐点纬度", jT808InflectionPointProperty.InflectionPointLat); + jT808InflectionPointProperty.InflectionPointLng = reader.ReadUInt32(); + writer.WriteNumber($"[{ jT808InflectionPointProperty.InflectionPointLng.ReadNumber()}]拐点经度", jT808InflectionPointProperty.InflectionPointLng); + jT808InflectionPointProperty.SectionWidth = reader.ReadByte(); + writer.WriteNumber($"[{ jT808InflectionPointProperty.SectionWidth.ReadNumber()}]路段宽度", jT808InflectionPointProperty.SectionWidth); + jT808InflectionPointProperty.SectionProperty = reader.ReadByte(); + writer.WriteNumber($"[{ jT808InflectionPointProperty.SectionProperty.ReadNumber()}]路段属性", jT808InflectionPointProperty.SectionProperty); + ReadOnlySpan sectionProperty16Bit = Convert.ToString(jT808InflectionPointProperty.SectionProperty, 2).PadLeft(16, '0').AsSpan(); + bool sectionBit0Flag = sectionProperty16Bit.Slice(sectionProperty16Bit.Length - 1).ToString().Equals("0"); + if (!sectionBit0Flag) + { + jT808InflectionPointProperty.SectionLongDrivingThreshold = reader.ReadUInt16(); + writer.WriteNumber($"[{ jT808InflectionPointProperty.SectionLongDrivingThreshold.Value.ReadNumber()}]路段行驶过长阈值", jT808InflectionPointProperty.SectionLongDrivingThreshold.Value) ; + jT808InflectionPointProperty.SectionDrivingUnderThreshold = reader.ReadUInt16(); + writer.WriteNumber($"[{ jT808InflectionPointProperty.SectionDrivingUnderThreshold.Value.ReadNumber()}]路段行驶不足阈值", jT808InflectionPointProperty.SectionDrivingUnderThreshold.Value); + } + bool sectionBit1Flag = sectionProperty16Bit.Slice(sectionProperty16Bit.Length - 2, 1).ToString().Equals("0"); + if (!sectionBit1Flag) + { + jT808InflectionPointProperty.SectionHighestSpeed = reader.ReadUInt16(); + writer.WriteNumber($"[{ jT808InflectionPointProperty.SectionHighestSpeed.Value.ReadNumber()}]路段最高速度", jT808InflectionPointProperty.SectionHighestSpeed.Value); + jT808InflectionPointProperty.SectionOverspeedDuration = reader.ReadByte(); + writer.WriteNumber($"[{ jT808InflectionPointProperty.SectionOverspeedDuration.Value.ReadNumber()}]超速持续时间", jT808InflectionPointProperty.SectionOverspeedDuration.Value); + if (reader.Version == JT808Version.JTT2019) + { + jT808InflectionPointProperty.NightMaximumSpeed = reader.ReadUInt16(); + writer.WriteNumber($"[{ jT808InflectionPointProperty.NightMaximumSpeed.Value.ReadNumber()}]夜间最高速度", jT808InflectionPointProperty.NightMaximumSpeed.Value); + } + } + writer.WriteEndObject(); + } + writer.WriteEndArray(); + if (reader.Version == JT808Version.JTT2019) + { + value.RouteNameLength = reader.ReadUInt16(); + writer.WriteNumber($"[{ value.RouteNameLength.ReadNumber()}]名称长度", value.RouteNameLength); + var routeNameBuffer = reader.ReadVirtualArray(value.RouteNameLength); + value.RouteName = reader.ReadString(value.RouteNameLength); + writer.WriteString($"[{ routeNameBuffer.ToArray().ToHexString()}]路线名称", value.RouteName); + } + } } } diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8607.cs b/src/JT808.Protocol/MessageBody/JT808_0x8607.cs index e6afe14..e23e45f 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x8607.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x8607.cs @@ -1,6 +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 { @@ -8,7 +11,7 @@ namespace JT808.Protocol.MessageBody /// 删除路线 /// 0x8607 /// - public class JT808_0x8607 : JT808Bodies, IJT808MessagePackFormatter + public class JT808_0x8607 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze { public override ushort MsgId { get; } = 0x8607; public override string Description => "删除路线"; @@ -45,5 +48,21 @@ namespace JT808.Protocol.MessageBody } } } + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x8607 value = new JT808_0x8607(); + value.AreaCount = reader.ReadByte(); + writer.WriteNumber($"[{ value.AreaCount.ReadNumber()}]区域数", value.AreaCount); + writer.WriteStartArray("区域ID集合"); + for (var i = 0; i < value.AreaCount; i++) + { + writer.WriteStartObject(); + var areaId = reader.ReadUInt32(); + writer.WriteNumber($"[{areaId.ReadNumber()}]Id{i + 1}", areaId); + writer.WriteEndObject(); + } + writer.WriteEndArray(); + } } } diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8608.cs b/src/JT808.Protocol/MessageBody/JT808_0x8608.cs index 039294a..59ea22a 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x8608.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x8608.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 { @@ -10,7 +12,7 @@ namespace JT808.Protocol.MessageBody /// 0x8608 /// 2019版本 /// - public class JT808_0x8608 : JT808Bodies, IJT808MessagePackFormatter, IJT808_2019_Version + public class JT808_0x8608 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze, IJT808_2019_Version { public override ushort MsgId { get; } = 0x8608; public override string Description => "查询区域或线路数据"; @@ -61,5 +63,26 @@ namespace JT808.Protocol.MessageBody writer.WriteUInt32(0); } } + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x8608 value = new JT808_0x8608(); + value.QueryType = reader.ReadByte(); + value.Count = reader.ReadUInt32(); + writer.WriteNumber($"[{ value.QueryType.ReadNumber()}]查询类型", value.QueryType); + writer.WriteNumber($"[{ value.Count.ReadNumber()}]查询的区域或线路的ID数量", value.Count); + if (value.Count > 0) + { + writer.WriteStartArray("Id列表"); + for (int i = 0; i < value.Count; i++) + { + writer.WriteStartObject(); + uint id = reader.ReadUInt32(); + writer.WriteNumber($"[{id.ReadNumber()}]Id{i+1}", id); + writer.WriteEndObject(); + } + writer.WriteEndArray(); + } + } } } diff --git a/src/JT808.Protocol/Metadata/JT808InflectionPointProperty.cs b/src/JT808.Protocol/Metadata/JT808InflectionPointProperty.cs index 2d8d1d2..52e226d 100644 --- a/src/JT808.Protocol/Metadata/JT808InflectionPointProperty.cs +++ b/src/JT808.Protocol/Metadata/JT808InflectionPointProperty.cs @@ -53,6 +53,7 @@ /// public byte? SectionOverspeedDuration { get; set; } /// + /// 夜间最高速度 /// 单位为千米每小时(km/h),若路段属性 1 位为 0 则没有该字段 /// public ushort? NightMaximumSpeed { get; set; }