diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index af59485..bf580f0 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -12,7 +12,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@master with: - dotnet-version: 8.0.100 + dotnet-version: 8.0.300 - name: dotnet info run: dotnet --info - name: dotnet restore diff --git a/global.json b/global.json index f3365c4..7fa817c 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { "sdk": { - "version": "8.0.100" + "version": "8.0.300" } } \ No newline at end of file diff --git a/src/Info.props b/src/Info.props index 81e99d1..6048b74 100644 --- a/src/Info.props +++ b/src/Info.props @@ -8,7 +8,7 @@ https://github.com/SmallChi/JT809 https://github.com/SmallChi/JT809/blob/master/LICENSE https://github.com/SmallChi/JT809/blob/master/LICENSE - 2.2.4 + 2.2.5 LICENSE true latest diff --git a/src/JT809.Protocol.Benchmark/JT809.Protocol.Benchmark.csproj b/src/JT809.Protocol.Benchmark/JT809.Protocol.Benchmark.csproj index f7a9389..674d5eb 100644 --- a/src/JT809.Protocol.Benchmark/JT809.Protocol.Benchmark.csproj +++ b/src/JT809.Protocol.Benchmark/JT809.Protocol.Benchmark.csproj @@ -6,7 +6,7 @@ - + diff --git a/src/JT809.Protocol.Test/JT809.Protocol.Test.csproj b/src/JT809.Protocol.Test/JT809.Protocol.Test.csproj index 113901b..7ac1a86 100644 --- a/src/JT809.Protocol.Test/JT809.Protocol.Test.csproj +++ b/src/JT809.Protocol.Test/JT809.Protocol.Test.csproj @@ -11,11 +11,11 @@ - + - - - + + + all runtime; build; native; contentfiles; analyzers diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1201Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1201Test.cs index 59d556a..28e0207 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1201Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1201Test.cs @@ -46,6 +46,20 @@ public void Test2() Assert.Equal("222222222222", jT809_0X1200_0X1201.TerminalSimCode); } + [Fact] + public void Test3() + { + var data = "5b00000067000000611200000003f30100000000036871bea948454e333137000000000000000000000000000412010000003100000000000000313031310000000000003730313131000000000000000000000000000000313230323939353533353735327d5d".ToHexBytes(); + var json = JT809Serializer.Analyze(data); + } + + [Fact] + public void Test4() + { + var data = "31313131313131313131003131313131313131313100313131313131313100000000000000000000000031313131314141323232323232323232323232".ToHexBytes(); + var json = JT809Serializer.Analyze(data); + } + [Fact] public void Test_2019_1() { diff --git a/src/JT809.Protocol/JT809.Protocol.xml b/src/JT809.Protocol/JT809.Protocol.xml index 1267f7f..275f2cd 100644 --- a/src/JT809.Protocol/JT809.Protocol.xml +++ b/src/JT809.Protocol/JT809.Protocol.xml @@ -1844,6 +1844,13 @@ + + + 使用场景:在不改变现有的结构的情况下进行补救,主要用于获取父类的解析长度在子类获取不到 骚操作 + + 回退偏移量 + + 数字编码 大端模式、高位在前 @@ -2167,6 +2174,14 @@ 车载终端型号,不是 8 位时以“\0”终结 + 自己外部扩展是2011还是2011的补充 + 2011版本是8位 + 2011补充版本是20位 + + + + + 默认为2011补充版本 diff --git a/src/JT809.Protocol/MessagePack/JT809MessagePackReader.cs b/src/JT809.Protocol/MessagePack/JT809MessagePackReader.cs index d749264..3864b1f 100644 --- a/src/JT809.Protocol/MessagePack/JT809MessagePackReader.cs +++ b/src/JT809.Protocol/MessagePack/JT809MessagePackReader.cs @@ -262,6 +262,16 @@ public uint ReadVirtualUInt32() { return BinaryPrimitives.ReadUInt32BigEndian(GetVirtualReadOnlySpan(4)); } + /// + /// 使用场景:在不改变现有的结构的情况下进行补救,主要用于获取父类的解析长度在子类获取不到 骚操作 + /// + /// 回退偏移量 + /// + public uint ReadVirtualUInt32(int backwordOffset) + { + return BinaryPrimitives.ReadUInt32BigEndian(GetVirtualReadOnlySpan(backwordOffset,4)); + } + public int ReadVirtualInt32() { return BinaryPrimitives.ReadInt32BigEndian(GetVirtualReadOnlySpan(4)); @@ -419,6 +429,15 @@ public ReadOnlySpan GetVirtualReadOnlySpan(int count) { return Reader.Slice(ReaderCount, count); } + public ReadOnlySpan GetVirtualReadOnlySpan(int backwordOffset,int count) + { + if(ReaderCount - backwordOffset < 0) + { + //处理直接子类导致溢出 + return Reader.Slice(ReaderCount, count); + } + return Reader.Slice(ReaderCount - backwordOffset, count); + } public ReadOnlySpan ReadContent(int count=0) { if (_decoded) diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1201.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1201.cs index 04a480f..bf5fdfe 100644 --- a/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1201.cs +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1201.cs @@ -29,8 +29,16 @@ public class JT809_0x1200_0x1201:JT809SubBodies, IJT809MessagePackFormatter /// 车载终端型号,不是 8 位时以“\0”终结 + /// 自己外部扩展是2011还是2011的补充 + /// 2011版本是8位 + /// 2011补充版本是20位 /// public string TerminalModelType { get; set; } + /// + /// 默认为2011补充版本 + /// + public int TerminalModelLength { get; set; } = 20; + /// /// 车载终端通讯模块IMEI码 /// 2019版本 @@ -50,15 +58,33 @@ public void Analyze(ref JT809MessagePackReader reader, Utf8JsonWriter writer, IJ JT809_0x1200_0x1201 value = new JT809_0x1200_0x1201(); if (config.Version == JT809Version.JTT2011) { + var dataLength = reader.ReadVirtualUInt32(4); + if (dataLength == 49) + { + writer.WriteString($"[使用2011版本]", "2011-8版本"); + } + else + { + writer.WriteString($"[使用2011补充版本]", "2011-20版本"); + } var virtualHex = reader.ReadVirtualArray(11); value.PlateformId = reader.ReadString(11); writer.WriteString($"[{virtualHex.ToArray().ToHexString()}]平台唯一编码", value.PlateformId); virtualHex = reader.ReadVirtualArray(11); value.ProducerId = reader.ReadString(11); writer.WriteString($"[{virtualHex.ToArray().ToHexString()}]车载终端厂商唯一编码", value.ProducerId); - virtualHex = reader.ReadVirtualArray(20); - value.TerminalModelType = reader.ReadString(20); - writer.WriteString($"[{virtualHex.ToArray().ToHexString()}]车载终端型号", value.TerminalModelType); + if (dataLength == 49) + { + virtualHex = reader.ReadVirtualArray(8); + value.TerminalModelType = reader.ReadString(8); + writer.WriteString($"[{virtualHex.ToArray().ToHexString()}]车载终端型号", value.TerminalModelType); + } + else + { + virtualHex = reader.ReadVirtualArray(20); + value.TerminalModelType = reader.ReadString(20); + writer.WriteString($"[{virtualHex.ToArray().ToHexString()}]车载终端型号", value.TerminalModelType); + } virtualHex = reader.ReadVirtualArray(7); value.TerminalId = reader.ReadString(7); value.TerminalId = value.TerminalId.ToUpper(); @@ -96,9 +122,17 @@ public JT809_0x1200_0x1201 Deserialize(ref JT809MessagePackReader reader, IJT809 JT809_0x1200_0x1201 value = new JT809_0x1200_0x1201(); if(config.Version== JT809Version.JTT2011) { + var dataLength = reader.ReadVirtualUInt32(4); value.PlateformId = reader.ReadString(11); value.ProducerId = reader.ReadString(11); - value.TerminalModelType = reader.ReadString(20); + if (dataLength == 49) + { + value.TerminalModelType = reader.ReadString(8); + } + else + { + value.TerminalModelType = reader.ReadString(20); + } value.TerminalId = reader.ReadString(7); value.TerminalId = value.TerminalId.ToUpper(); value.TerminalSimCode = reader.ReadString(12); @@ -122,7 +156,7 @@ public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1200_0x1201 val { writer.WriteStringPadRight(value.PlateformId, 11); writer.WriteStringPadRight(value.ProducerId, 11); - writer.WriteStringPadRight(value.TerminalModelType, 20); + writer.WriteStringPadRight(value.TerminalModelType, TerminalModelLength); writer.WriteStringPadRight(value.TerminalId.ToUpper(), 7); writer.WriteStringPadLeft(value.TerminalSimCode, 12); }