Browse Source

改造809分析器

master
SmallChi(Koike) 5 years ago
parent
commit
30126711a1
6 changed files with 128 additions and 22 deletions
  1. +13
    -0
      src/JTTools/Configs/JT809_2011_Config.cs
  2. +19
    -0
      src/JTTools/Configs/JT809_2019_Config.cs
  3. +1
    -1
      src/JTTools/JTTools.csproj
  4. +78
    -18
      src/JTTools/Pages/JT809Parse.razor
  5. +16
    -2
      src/JTTools/Program.cs
  6. +1
    -1
      src/JTTools/Shared/NavMenu.razor

+ 13
- 0
src/JTTools/Configs/JT809_2011_Config.cs View File

@@ -0,0 +1,13 @@
using JT809.Protocol.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace JTTools.Configs
{
public class JT809_2011_Config : JT809GlobalConfigBase
{
public override string ConfigId { get; }= "JT809_2011";
}
}

+ 19
- 0
src/JTTools/Configs/JT809_2019_Config.cs View File

@@ -0,0 +1,19 @@
using JT809.Protocol.Enums;
using JT809.Protocol.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace JTTools.Configs
{
public class JT809_2019_Config : JT809GlobalConfigBase
{
public override string ConfigId { get; }= "JT809_2019";

public JT809_2019_Config()
{
Version = JT809Version.JTT2019;
}
}
}

+ 1
- 1
src/JTTools/JTTools.csproj View File

@@ -12,7 +12,7 @@
<PackageReference Include="JT808" Version="2.2.10" />
<PackageReference Include="JT808.Protocol.Extensions.JT1078" Version="2.2.9" />
<PackageReference Include="JT808.Protocol.Extensions.JTActiveSafety" Version="1.0.4" />
<PackageReference Include="JT809" Version="2.1.3" />
<PackageReference Include="JT809" Version="2.1.4-preview1" />
<PackageReference Include="JT809.Protocol.Extensions.JT1078" Version="2.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />


+ 78
- 18
src/JTTools/Pages/JT809Parse.razor View File

@@ -6,8 +6,15 @@
@using JT809.Protocol.Configs;
@using JT809.Protocol.Interfaces;
@using JT809.Protocol.Exceptions;
@inject IJT809Config Config

@using JTTools.Configs;
@using JT809.Protocol.Enums;
@inject JT809_2011_Config Config2011
@inject JT809_2019_Config Config2019

<select class="form-control" @onchange="@OnSelectVersion">
<option value="v2011">2011版本</option>
<option value="v2019">2019版本</option>
</select>
<select class="form-control" @onchange="@OnSelectEncryptType">
<option value="none">未加密</option>
<option value="encrypt">加密</option>
@@ -33,14 +40,21 @@
</div>

@code {
private JT809Serializer Serializer;
private JT809Serializer Serializer2011;
private JT809Serializer Serializer2019;

private string HexData2011 = "5B 00 00 00 92 00 00 06 82 94 00 01 33 EF B8 01 00 00 00 00 00 27 0F D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 02 94 01 00 00 00 5C 01 00 02 00 00 00 00 5A 01 AC 3F 40 12 3F FA A1 00 00 00 00 5A 01 AC 4D 50 03 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 31 32 33 34 35 36 37 38 39 30 31 00 00 00 00 00 00 00 00 00 31 32 33 34 35 36 40 71 71 2E 63 6F 6D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 BA D8 5D";

private string HexData = "5B 00 00 00 92 00 00 06 82 94 00 01 33 EF B8 01 00 00 00 00 00 27 0F D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 02 94 01 00 00 00 5C 01 00 02 00 00 00 00 5A 01 AC 3F 40 12 3F FA A1 00 00 00 00 5A 01 AC 4D 50 03 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 31 32 33 34 35 36 37 38 39 30 31 00 00 00 00 00 00 00 00 00 31 32 33 34 35 36 40 71 71 2E 63 6F 6D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 BA D8 5D";
private string HexData2019 = "5B 00 00 00 C9 00 00 06 82 17 00 01 34 15 F4 01 00 00 00 00 00 27 0F 00 00 00 00 5E 02 A5 07 B8 D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 02 17 01 00 00 00 8B 01 02 03 04 05 06 07 08 09 10 11 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 E7 D3 5D";

private string HexData = "";

private string Json;

string encryptType = "none";

string version = "v2011";

JT809EncryptOptions EncryptOptions;

private string ErrerMessage;
@@ -53,6 +67,20 @@
StateHasChanged();
}

private void OnSelectVersion(ChangeEventArgs e)
{
version = e.Value.ToString();
switch (version)
{
case "v2011":
HexData = HexData2011;
break;
case "v2019":
HexData = HexData2019;
break;
}
}

private void OnSelectEncryptType(ChangeEventArgs e)
{
encryptType = e.Value.ToString();
@@ -60,8 +88,10 @@

protected override void OnInitialized()
{
Serializer = Config.GetSerializer();
Serializer2011 = JT809ConfigExtensions.GetSerializer(Config2011);
Serializer2019 = JT809ConfigExtensions.GetSerializer(Config2019);
EncryptOptions = new JT809EncryptOptions();
HexData = HexData2011;
}

private void Query()
@@ -70,25 +100,44 @@
{
isOpen = false;
var data = HexData.ToHexBytes();
if (encryptType == "none")
switch (version)
{
Json = JsonConvert.SerializeObject(Serializer.Deserialize(data), Formatting.Indented);
}
else
{
IJT809Config jt809ConfigInternal = new JT809Config(Guid.NewGuid().ToString());
jt809ConfigInternal.EncryptOptions = EncryptOptions;
JT809Serializer jT809SerializerInternal = new JT809Serializer(jt809ConfigInternal);
Json = JsonConvert.SerializeObject(jT809SerializerInternal.Deserialize(data), Formatting.Indented);
case "v2011":
if (encryptType == "none")
{
Json = Serializer2011.Analyze(data, JTJsonWriterOptions.Instance);
}
else
{
IJT809Config jt809ConfigInternal = new JT809Config2011(Guid.NewGuid().ToString());
jt809ConfigInternal.EncryptOptions = EncryptOptions;
JT809Serializer jT809SerializerInternal = new JT809Serializer(jt809ConfigInternal);
Json = jT809SerializerInternal.Analyze(data, JTJsonWriterOptions.Instance);
}
break;

case "v2019":
if (encryptType == "none")
{
Json = Serializer2019.Analyze(data, JTJsonWriterOptions.Instance);
}
else
{
IJT809Config jt809ConfigInternal = new JT809Config2019(Guid.NewGuid().ToString());
jt809ConfigInternal.EncryptOptions = EncryptOptions;
JT809Serializer jT809SerializerInternal = new JT809Serializer(jt809ConfigInternal);
Json = jT809SerializerInternal.Analyze(data, JTJsonWriterOptions.Instance);
}
break;
}
}
catch(JT809Exception ex)
catch (JT809Exception ex)
{
isOpen = !isOpen;
Json = "";
ErrerMessage = ex.Message;
}
catch(Exception ex)
catch (Exception ex)
{
isOpen = !isOpen;
Json = "";
@@ -96,11 +145,22 @@
}
}

class JT809Config : JT809GlobalConfigBase
class JT809Config2011 : JT809GlobalConfigBase
{
public JT809Config2011(string configId)
{
ConfigId = configId;
}

public override string ConfigId { get; }
}

class JT809Config2019 : JT809GlobalConfigBase
{
public JT809Config(string configId)
public JT809Config2019(string configId)
{
ConfigId = configId;
Version = JT809Version.JTT2019;
}

public override string ConfigId { get; }


+ 16
- 2
src/JTTools/Program.cs View File

@@ -12,6 +12,7 @@ using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json.Serialization;
using JTTools.Configs;
using BlazorStrap;
using Newtonsoft.Json;

namespace JTTools
{
@@ -19,6 +20,18 @@ namespace JTTools
{
public static void Main(string[] args)
{
Newtonsoft.Json.JsonConvert.DefaultSettings = new Func<JsonSerializerSettings>(() =>
{
Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings();
//日期类型默认格式化处理
settings.DateFormatHandling = Newtonsoft.Json.DateFormatHandling.MicrosoftDateFormat;
settings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
//空值处理
settings.NullValueHandling = NullValueHandling.Ignore;
settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
settings.Converters.Add(new ByteArrayHexConverter());
return settings;
});
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
@@ -89,8 +102,9 @@ namespace JTTools
.AddJTActiveSafetyConfigure();
services.AddJT808Configure(new JT808_JT1078_Config())
.AddJT1078Configure();
services.AddJT809Configure()
.AddJT1078Configure();
//.AddJT1078Configure();
services.AddJT809Configure(new JT809_2011_Config());
services.AddJT809Configure(new JT809_2019_Config());
})
.Build()
.Run();


+ 1
- 1
src/JTTools/Shared/NavMenu.razor View File

@@ -19,7 +19,7 @@
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="jt809">
<span aria-hidden="true"></span>JT809析工具
<span aria-hidden="true"></span>JT809析工具
</NavLink>
</li>
<li class="nav-item px-3">


Loading…
Cancel
Save