Skip to content

Commit

Permalink
v2.2.5
Browse files Browse the repository at this point in the history
兼容2011版本和2011补充版本的上传车辆注册信息
  • Loading branch information
SmallChi committed May 29, 2024
1 parent 52db083 commit fdb8c88
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "8.0.100"
"version": "8.0.300"
}
}
2 changes: 1 addition & 1 deletion src/Info.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageProjectUrl>https://github.com/SmallChi/JT809</PackageProjectUrl>
<license>https://github.com/SmallChi/JT809/blob/master/LICENSE</license>
<licenseUrl>https://github.com/SmallChi/JT809/blob/master/LICENSE</licenseUrl>
<Version>2.2.4</Version>
<Version>2.2.5</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<AnalysisLevel>latest</AnalysisLevel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.10" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/JT809.Protocol.Test/JT809.Protocol.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="JT808" Version="2.6.4" />
<PackageReference Include="JT808" Version="2.6.5" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<JT809_0x1200_0x1201>(data);
}

[Fact]
public void Test_2019_1()
{
Expand Down
15 changes: 15 additions & 0 deletions src/JT809.Protocol/JT809.Protocol.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions src/JT809.Protocol/MessagePack/JT809MessagePackReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,16 @@ public uint ReadVirtualUInt32()
{
return BinaryPrimitives.ReadUInt32BigEndian(GetVirtualReadOnlySpan(4));
}
/// <summary>
/// 使用场景:在不改变现有的结构的情况下进行补救,主要用于获取父类的解析长度在子类获取不到 骚操作
/// </summary>
/// <param name="backwordOffset">回退偏移量</param>
/// <returns></returns>
public uint ReadVirtualUInt32(int backwordOffset)
{
return BinaryPrimitives.ReadUInt32BigEndian(GetVirtualReadOnlySpan(backwordOffset,4));
}

public int ReadVirtualInt32()
{
return BinaryPrimitives.ReadInt32BigEndian(GetVirtualReadOnlySpan(4));
Expand Down Expand Up @@ -419,6 +429,15 @@ public ReadOnlySpan<byte> GetVirtualReadOnlySpan(int count)
{
return Reader.Slice(ReaderCount, count);
}
public ReadOnlySpan<byte> GetVirtualReadOnlySpan(int backwordOffset,int count)
{
if(ReaderCount - backwordOffset < 0)
{
//处理直接子类导致溢出
return Reader.Slice(ReaderCount, count);
}
return Reader.Slice(ReaderCount - backwordOffset, count);
}
public ReadOnlySpan<byte> ReadContent(int count=0)
{
if (_decoded)
Expand Down
44 changes: 39 additions & 5 deletions src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1201.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,16 @@ public class JT809_0x1200_0x1201:JT809SubBodies, IJT809MessagePackFormatter<JT80
public string ProducerId { get; set; }
/// <summary>
/// 车载终端型号,不是 8 位时以“\0”终结
/// 自己外部扩展是2011还是2011的补充
/// 2011版本是8位
/// 2011补充版本是20位
/// </summary>
public string TerminalModelType { get; set; }
/// <summary>
/// 默认为2011补充版本
/// </summary>
public int TerminalModelLength { get; set; } = 20;

/// <summary>
/// 车载终端通讯模块IMEI码
/// 2019版本
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down

0 comments on commit fdb8c88

Please sign in to comment.