Skip to content

Commit

Permalink
优化0107bug
Browse files Browse the repository at this point in the history
  • Loading branch information
waterliu99 committed Dec 12, 2024
1 parent 381ecce commit 0da7ef1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
7 changes: 7 additions & 0 deletions src/JT808.Protocol.Test/MessageBody/JT808_0x0107Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
35 changes: 24 additions & 11 deletions src/JT808.Protocol/MessageBody/JT808_0x0107.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -162,11 +178,11 @@ public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, I
writer.WriteString("bit8", terminalTypeBits[8] == '0' ? "不适用挂车" : "适用挂车");
}
writer.WriteEndObject();
ReadOnlySpan<byte> 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<byte> makerIdSpan = reader.ReadVirtualArray(11);
jT808_0X0107.MakerId = reader.ReadString(11);
writer.WriteString($"[{makerIdSpan.ToArray().ToHexString()}]制造商ID", jT808_0X0107.MakerId);
ReadOnlySpan<byte> terminalModelSpan = reader.ReadVirtualArray(30);
jT808_0X0107.TerminalModel = reader.ReadString(30);
writer.WriteString($"[{terminalModelSpan.ToArray().ToHexString()}]终端型号", jT808_0X0107.TerminalModel);
Expand All @@ -175,10 +191,7 @@ public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, I
writer.WriteString($"[{terminalIdSpan.ToArray().ToHexString()}]终端ID", jT808_0X0107.TerminalId);
}
else
{
ReadOnlySpan<byte> makerIdSpan = reader.ReadVirtualArray(5);
jT808_0X0107.MakerId = reader.ReadString(5);
writer.WriteString($"[{makerIdSpan.ToArray().ToHexString()}]制造商ID", jT808_0X0107.MakerId);
{
ReadOnlySpan<byte> terminalModelSpan = reader.ReadVirtualArray(20);
jT808_0X0107.TerminalModel = reader.ReadString(20);
writer.WriteString($"[{terminalModelSpan.ToArray().ToHexString()}]终端型号", jT808_0X0107.TerminalModel);
Expand Down

0 comments on commit 0da7ef1

Please sign in to comment.