From d15aa6d94b4967ce11e902cc1ee444d4c35712aa Mon Sep 17 00:00:00 2001 From: "smallchi(Koike)" <564952747@qq.com> Date: Tue, 25 Feb 2020 19:49:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=848604=E3=80=818606=E3=80=81880?= =?UTF-8?q?1=E5=8D=8F=E8=AE=AE=E5=88=86=E6=9E=90=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MessageBody/JT808_0x8606Test.cs | 7 ++++ .../Enums/JT808CameraResolutionType.cs | 21 ++++++++++ .../MessageBody/JT808_0x8604.cs | 6 +-- .../MessageBody/JT808_0x8606.cs | 35 +++++++++++++++-- .../MessageBody/JT808_0x8801.cs | 38 ++++++++----------- 5 files changed, 78 insertions(+), 29 deletions(-) create mode 100644 src/JT808.Protocol/Enums/JT808CameraResolutionType.cs diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x8606Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x8606Test.cs index 308d323..7f5123d 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x8606Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x8606Test.cs @@ -211,6 +211,13 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal(75, jT808_0X8606.InflectionPointItems[1].SectionWidth); } + [Fact] + public void Test5() + { + byte[] bytes = "0000270F00331811200000121811210000120002000003E800000507075BCD15075BCD1438030032007B004517000003E900002EE7075BCD0C075BCD0D4B03003A007C002A1A".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes); + } + [Fact] public void Test5_2019() { diff --git a/src/JT808.Protocol/Enums/JT808CameraResolutionType.cs b/src/JT808.Protocol/Enums/JT808CameraResolutionType.cs new file mode 100644 index 0000000..3bdf2b9 --- /dev/null +++ b/src/JT808.Protocol/Enums/JT808CameraResolutionType.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT808.Protocol.Enums +{ + /// + /// 摄像头分辨率 + /// + public enum JT808CameraResolutionType:byte + { + x320_240 = 0x01, + x640_480 = 0x02, + x800_600 = 0x03, + x1020_768 = 0x04, + x176_144_Qcif = 0x05, + x352_288_Cif = 0x06, + x704_288_HALF_D1 = 0x07, + x704_576_D1 = 0x07, + } +} diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8604.cs b/src/JT808.Protocol/MessageBody/JT808_0x8604.cs index 3786c2f..478c1dc 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x8604.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x8604.cs @@ -200,9 +200,7 @@ namespace JT808.Protocol.MessageBody writer.WriteString($"[bit0]{areaPropertyBits[0]}", areaPropertyBits[0] == '1' ? "根据时间" : "无"); } writer.WriteEndObject(); - - ReadOnlySpan areaProperty16Bit = Convert.ToString(value.AreaProperty, 2).PadLeft(16, '0').AsSpan(); - bool bit0Flag = areaProperty16Bit.Slice(areaProperty16Bit.Length - 1).ToString().Equals("0"); + bool bit0Flag = areaPropertyBits.Slice(areaPropertyBits.Length - 1).ToString().Equals("0"); if (!bit0Flag) { value.StartTime = reader.ReadDateTime6(); @@ -210,7 +208,7 @@ namespace JT808.Protocol.MessageBody 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"); + bool bit1Flag = areaPropertyBits.Slice(areaPropertyBits.Length - 2, 1).ToString().Equals("0"); if (!bit1Flag) { value.HighestSpeed = reader.ReadUInt16(); diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8606.cs b/src/JT808.Protocol/MessageBody/JT808_0x8606.cs index b217ce9..7ae10c2 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x8606.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x8606.cs @@ -169,6 +169,28 @@ namespace JT808.Protocol.MessageBody value.RouteProperty = reader.ReadUInt16(); writer.WriteNumber($"[{ value.RouteProperty.ReadNumber()}]路线属性", value.RouteProperty); ReadOnlySpan routeProperty16Bit = Convert.ToString(value.RouteProperty, 2).PadLeft(16, '0').AsSpan(); + writer.WriteStartObject($"路线属性对象[{routeProperty16Bit.ToString()}]"); + if (reader.Version == JT808Version.JTT2019) + { + writer.WriteString($"[bit6~bit15]保留", routeProperty16Bit.Slice(6,10).ToString()); + writer.WriteString($"[bit5]出路线是否报警给平台-{routeProperty16Bit[5]}", routeProperty16Bit[5] == '0' ? "否" : "是"); + writer.WriteString($"[bit4]出路线是否报警给平驾驶员-{routeProperty16Bit[4]}", routeProperty16Bit[4] == '0' ? "否" : "是"); + writer.WriteString($"[bit3]进路线是否报警给平台-{routeProperty16Bit[3]}", routeProperty16Bit[3] == '0' ? "否" : "是"); + writer.WriteString($"[bit2]进路线是否报警给驾驶员-{routeProperty16Bit[2]}", routeProperty16Bit[2] == '0' ? "否" : "是"); + writer.WriteString($"[bit1]保留", routeProperty16Bit[1] == '0' ? "否" : "是"); + writer.WriteString($"[bit0]是否启用起始时间与结束时间的判断规则-{routeProperty16Bit[0]}", routeProperty16Bit[0] == '0' ? "否" : "是"); + } + else + { + writer.WriteString($"[bit6~bit15]保留", routeProperty16Bit.Slice(6, 10).ToString()); + writer.WriteString($"[bit5]{routeProperty16Bit[5]}", routeProperty16Bit[5] == '1' ? "出路线报警给平台" : "无"); + writer.WriteString($"[bit4]{routeProperty16Bit[4]}", routeProperty16Bit[4] == '1' ? "出路线报警给驾驶员" : "无"); + writer.WriteString($"[bit3]{routeProperty16Bit[3]}", routeProperty16Bit[3] == '1' ? "进路线报警给平台" : "无"); + writer.WriteString($"[bit2]{routeProperty16Bit[2]}", routeProperty16Bit[2] == '1' ? "进路线报警给驾驶员" : "无"); + writer.WriteString($"[bit1]保留", $"{routeProperty16Bit[1]}"); + writer.WriteString($"[bit0]{routeProperty16Bit[0]}", routeProperty16Bit[0] == '1' ? "根据时间" : "无"); + } + writer.WriteEndObject(); bool bit0Flag = routeProperty16Bit.Slice(routeProperty16Bit.Length - 1).ToString().Equals("0"); if (!bit0Flag) { @@ -196,8 +218,15 @@ namespace JT808.Protocol.MessageBody 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"); + ReadOnlySpan sectionProperty8Bit = Convert.ToString(jT808InflectionPointProperty.SectionProperty, 2).PadLeft(8, '0').AsSpan(); + writer.WriteStartObject($"路段属性对象[{sectionProperty8Bit.ToString()}]"); + writer.WriteString($"[bit4~bit7]保留", sectionProperty8Bit.Slice(4, 4).ToString()); + writer.WriteString($"[bit3]进路线是否报警给平台-{sectionProperty8Bit[3]}", sectionProperty8Bit[3] == '0' ? "无" : "限速"); + writer.WriteString($"[bit2]进路线是否报警给驾驶员-{sectionProperty8Bit[2]}", sectionProperty8Bit[2] == '0' ? "北纬" : "南纬"); + writer.WriteString($"[bit1]{sectionProperty8Bit[1]}", sectionProperty8Bit[1] == '0' ? "东经" : "西经"); + writer.WriteString($"[bit0]{sectionProperty8Bit[0]}", sectionProperty8Bit[0] == '0' ? "无" : "行驶时间"); + writer.WriteEndObject(); + bool sectionBit0Flag = sectionProperty8Bit.Slice(sectionProperty8Bit.Length - 1).ToString().Equals("0"); if (!sectionBit0Flag) { jT808InflectionPointProperty.SectionLongDrivingThreshold = reader.ReadUInt16(); @@ -205,7 +234,7 @@ namespace JT808.Protocol.MessageBody jT808InflectionPointProperty.SectionDrivingUnderThreshold = reader.ReadUInt16(); writer.WriteNumber($"[{ jT808InflectionPointProperty.SectionDrivingUnderThreshold.Value.ReadNumber()}]路段行驶不足阈值", jT808InflectionPointProperty.SectionDrivingUnderThreshold.Value); } - bool sectionBit1Flag = sectionProperty16Bit.Slice(sectionProperty16Bit.Length - 2, 1).ToString().Equals("0"); + bool sectionBit1Flag = sectionProperty8Bit.Slice(sectionProperty8Bit.Length - 2, 1).ToString().Equals("0"); if (!sectionBit1Flag) { jT808InflectionPointProperty.SectionHighestSpeed = reader.ReadUInt16(); diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8801.cs b/src/JT808.Protocol/MessageBody/JT808_0x8801.cs index cb824c5..a1b582a 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x8801.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x8801.cs @@ -1,4 +1,5 @@ -using JT808.Protocol.Extensions; +using JT808.Protocol.Enums; +using JT808.Protocol.Extensions; using JT808.Protocol.Formatters; using JT808.Protocol.Interfaces; using JT808.Protocol.MessagePack; @@ -35,14 +36,7 @@ namespace JT808.Protocol.MessageBody public byte SaveFlag { get; set; } /// /// 分辨率 - /// 0x01:320*240; - /// 0x02:640*480; - /// 0x03:800*600; - /// 0x04:1024*768; - /// 0x05:176*144;[Qcif]; - /// 0x06:352*288;[Cif]; - /// 0x07:704*288;[HALF D1]; - /// 0x08:704*576;[D1]; + /// /// public byte Resolution { get; set; } /// @@ -104,22 +98,22 @@ namespace JT808.Protocol.MessageBody public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { JT808_0x8801 value = new JT808_0x8801(); - value.ChannelId = reader.ReadByte(); - value.ShootingCommand = reader.ReadUInt16(); - value.VideoTime = reader.ReadUInt16(); - value.SaveFlag = reader.ReadByte(); - value.Resolution = reader.ReadByte(); - value.VideoQuality = reader.ReadByte(); - value.Lighting = reader.ReadByte(); - value.Contrast = reader.ReadByte(); - value.Saturability = reader.ReadByte(); - value.Chroma = reader.ReadByte(); - + value.ChannelId = reader.ReadByte(); + value.ShootingCommand = reader.ReadUInt16(); + value.VideoTime = reader.ReadUInt16(); + value.SaveFlag = reader.ReadByte(); + value.Resolution = reader.ReadByte(); + value.VideoQuality = reader.ReadByte(); + value.Lighting = reader.ReadByte(); + value.Contrast = reader.ReadByte(); + value.Saturability = reader.ReadByte(); + value.Chroma = reader.ReadByte(); + JT808CameraResolutionType jT808CameraResolutionType = (JT808CameraResolutionType)value.Resolution; writer.WriteNumber($"[{ value.ChannelId.ReadNumber()}]通道ID", value.ChannelId); writer.WriteNumber($"[{ value.ShootingCommand.ReadNumber()}]拍摄命令", value.ShootingCommand); writer.WriteNumber($"[{ value.VideoTime.ReadNumber()}]拍照间隔_录像时间", value.VideoTime); - writer.WriteNumber($"[{ value.SaveFlag.ReadNumber()}]保存标志", value.SaveFlag); - writer.WriteNumber($"[{ value.Resolution.ReadNumber()}]分辨率", value.Resolution); + writer.WriteString($"[{ value.SaveFlag.ReadNumber()}]保存标志-{value.SaveFlag}", value.SaveFlag==1? "保存" : "实时上传"); + writer.WriteNumber($"[{ value.Resolution.ReadNumber()}]分辨率-{jT808CameraResolutionType.ToString()}", value.Resolution); writer.WriteNumber($"[{ value.VideoQuality.ReadNumber()}]图像_视频质量", value.VideoQuality); writer.WriteNumber($"[{ value.Lighting.ReadNumber()}]亮度", value.Lighting); writer.WriteNumber($"[{ value.Contrast.ReadNumber()}]对比度", value.Contrast);