From 0da7ef17e7669c468a3189e2b88d927454f10741 Mon Sep 17 00:00:00 2001 From: waterliu99 Date: Thu, 12 Dec 2024 22:48:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=960107bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MessageBody/JT808_0x0107Test.cs | 7 ++++ .../MessageBody/JT808_0x0107.cs | 35 +++++++++++++------ 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x0107Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x0107Test.cs index 0da416b1..42346989 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x0107Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x0107Test.cs @@ -65,5 +65,12 @@ public void Test3() byte[] bytes = "7E0107004111223344556622B8000531303630313130343535353435393535313033303030303030346436613133301234567890123456789007616263646566670A706F69757974726577710709DA7E".ToHexBytes(); string json = JT808Serializer.Analyze(bytes); } + [Fact] + public void Test4() + { + //2019版本JT808_0x0107解析制造商有误 #43 + byte[] bytes = "7E010740660100000000010941000493000700FF3838383838434B31303043000000000000000000000000000000000000000000000000313030303439330000000000000000000000000000000000000000000000898603249475600329000748572D56322E350E434B313030432D4A542D5630323402209B7E".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes); + } } } diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0107.cs b/src/JT808.Protocol/MessageBody/JT808_0x0107.cs index 14157815..c07b3709 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0107.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0107.cs @@ -107,8 +107,16 @@ public override JT808_0x0107 Deserialize(ref JT808MessagePackReader reader, IJT8 JT808_0x0107 jT808_0X0107 = new JT808_0x0107(); jT808_0X0107.TerminalType = reader.ReadUInt16(); jT808_0X0107.MakerId = reader.ReadString(5); - jT808_0X0107.TerminalModel = reader.ReadString(20); - jT808_0X0107.TerminalId = reader.ReadString(7); + if (reader.Version == JT808Version.JTT2019) + { + jT808_0X0107.TerminalModel = reader.ReadString(30); + jT808_0X0107.TerminalId = reader.ReadString(30); + } + else + { + jT808_0X0107.TerminalModel = reader.ReadString(20); + jT808_0X0107.TerminalId = reader.ReadString(7); + } jT808_0X0107.Terminal_SIM_ICCID = reader.ReadBCD(20, config.Trim); jT808_0X0107.Terminal_Hardware_Version_Length = reader.ReadByte(); jT808_0X0107.Terminal_Hardware_Version_Num = reader.ReadString(jT808_0X0107.Terminal_Hardware_Version_Length); @@ -128,8 +136,16 @@ public override void Serialize(ref JT808MessagePackWriter writer, JT808_0x0107 v { writer.WriteUInt16(value.TerminalType); writer.WriteString(value.MakerId.PadRight(5, '\0').ValiString(nameof(value.MakerId), 5)); - writer.WriteString(value.TerminalModel.PadRight(20, '\0').ValiString(nameof(value.TerminalModel), 20)); - writer.WriteString(value.TerminalId.PadRight(7, '\0').ValiString(nameof(value.TerminalId), 7)); + if (writer.Version == JT808Version.JTT2019) + { + writer.WriteString(value.TerminalModel.PadRight(30, '\0').ValiString(nameof(value.TerminalModel), 30)); + writer.WriteString(value.TerminalId.PadRight(30, '\0').ValiString(nameof(value.TerminalId), 30)); + } + else + { + writer.WriteString(value.TerminalModel.PadRight(20, '\0').ValiString(nameof(value.TerminalModel), 20)); + writer.WriteString(value.TerminalId.PadRight(7, '\0').ValiString(nameof(value.TerminalId), 7)); + } writer.WriteBCD(value.Terminal_SIM_ICCID.ValiString(nameof(value.Terminal_SIM_ICCID), 20), 20); writer.WriteByte((byte)value.Terminal_Hardware_Version_Num.Length); writer.WriteString(value.Terminal_Hardware_Version_Num); @@ -162,11 +178,11 @@ public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, I writer.WriteString("bit8", terminalTypeBits[8] == '0' ? "不适用挂车" : "适用挂车"); } writer.WriteEndObject(); + ReadOnlySpan makerIdSpan = reader.ReadVirtualArray(5); + jT808_0X0107.MakerId = reader.ReadString(5); + writer.WriteString($"[{makerIdSpan.ToArray().ToHexString()}]制造商ID", jT808_0X0107.MakerId); if (reader.Version == JT808Version.JTT2019) { - ReadOnlySpan makerIdSpan = reader.ReadVirtualArray(11); - jT808_0X0107.MakerId = reader.ReadString(11); - writer.WriteString($"[{makerIdSpan.ToArray().ToHexString()}]制造商ID", jT808_0X0107.MakerId); ReadOnlySpan terminalModelSpan = reader.ReadVirtualArray(30); jT808_0X0107.TerminalModel = reader.ReadString(30); writer.WriteString($"[{terminalModelSpan.ToArray().ToHexString()}]终端型号", jT808_0X0107.TerminalModel); @@ -175,10 +191,7 @@ public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, I writer.WriteString($"[{terminalIdSpan.ToArray().ToHexString()}]终端ID", jT808_0X0107.TerminalId); } else - { - ReadOnlySpan makerIdSpan = reader.ReadVirtualArray(5); - jT808_0X0107.MakerId = reader.ReadString(5); - writer.WriteString($"[{makerIdSpan.ToArray().ToHexString()}]制造商ID", jT808_0X0107.MakerId); + { ReadOnlySpan terminalModelSpan = reader.ReadVirtualArray(20); jT808_0X0107.TerminalModel = reader.ReadString(20); writer.WriteString($"[{terminalModelSpan.ToArray().ToHexString()}]终端型号", jT808_0X0107.TerminalModel);