@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 | |||
# Visual Studio Version 16 | |||
VisualStudioVersion = 16.0.29123.88 | |||
MinimumVisualStudioVersion = 10.0.40219.1 | |||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JTTools", "JTTools\JTTools.csproj", "{BBDC3FB3-B267-4BFB-803E-71287D361300}" | |||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JTTools", "JTTools\JTTools.csproj", "{BBDC3FB3-B267-4BFB-803E-71287D361300}" | |||
EndProject | |||
Global | |||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | |||
@@ -0,0 +1,14 @@ | |||
using JT809.Protocol.Configs; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
namespace JTTools.Dtos | |||
{ | |||
public class JT809RequestDto: JTRequestDto | |||
{ | |||
public bool IsEncrypt { get; set; } = false; | |||
public JT809EncryptOptions EncryptOptions { get; set; } | |||
} | |||
} |
@@ -0,0 +1,14 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
namespace JTTools.Dtos | |||
{ | |||
public class JTRequestDto | |||
{ | |||
public string HexData { get; set; } | |||
public bool Skip { get; set; } | |||
public bool Custom { get; set; } | |||
} | |||
} |
@@ -0,0 +1,14 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
namespace JTTools.Dtos | |||
{ | |||
public class JTResultDto | |||
{ | |||
public int Code { get; set; } | |||
public string Message { get; set; } | |||
public object Data { get; set; } | |||
} | |||
} |
@@ -1,4 +1,4 @@ | |||
<Project Sdk="Microsoft.NET.Sdk.Web"> | |||
<Project Sdk="Microsoft.NET.Sdk.Web"> | |||
<PropertyGroup> | |||
<TargetFramework>netcoreapp3.1</TargetFramework> | |||
@@ -7,7 +7,15 @@ | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.8" /> | |||
<PackageReference Include="JT1078" Version="1.0.2" /> | |||
<PackageReference Include="JT808" Version="2.2.9" /> | |||
<PackageReference Include="JT808.Protocol.Extensions.JT1078" Version="2.2.7" /> | |||
<PackageReference Include="JT808.Protocol.Extensions.JTActiveSafety" Version="1.0.2" /> | |||
<PackageReference Include="JT809" Version="2.1.3" /> | |||
<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" /> | |||
<PackageReference Include="NLog.Extensions.Logging" Version="1.6.2" /> | |||
</ItemGroup> | |||
</Project> |
@@ -0,0 +1,29 @@ | |||
using Newtonsoft.Json; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace JTTools | |||
{ | |||
public class ByteArrayHexConverter : JsonConverter | |||
{ | |||
public override bool CanConvert(Type objectType) => objectType == typeof(byte[]); | |||
public override bool CanRead => false; | |||
public override bool CanWrite => true; | |||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) => throw new NotImplementedException(); | |||
private readonly string _separator; | |||
public ByteArrayHexConverter(string separator = " ") => _separator = separator; | |||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | |||
{ | |||
var hexString = string.Join(_separator, ((byte[])value).Select(p => p.ToString("X2"))); | |||
writer.WriteValue(hexString); | |||
} | |||
} | |||
} |
@@ -0,0 +1,37 @@ | |||
using Microsoft.AspNetCore.Http; | |||
using Microsoft.AspNetCore.Mvc.Formatters; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Text.Json; | |||
using System.Text.Json.Serialization; | |||
using System.Threading.Tasks; | |||
namespace JTTools.JsonConvert | |||
{ | |||
/// <summary> | |||
/// | |||
/// ref:https://github.com/dotnet/corefx/blob/release/3.0/src/System.Text.Json/tests/Serialization/CustomConverterTests.Array.cs | |||
/// </summary> | |||
public class ByteArrayHexTextJsonConverter : JsonConverter<byte[]> | |||
{ | |||
public override byte[] Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | |||
{ | |||
//string hexJson = reader.get(); | |||
var hexJson = reader.GetString(); | |||
var list = new List<byte>(); | |||
foreach (string str in hexJson.Split(new string[] { ",", " " }, StringSplitOptions.RemoveEmptyEntries)) | |||
{ | |||
list.Add(Convert.ToByte(str, 16)); | |||
} | |||
return list.ToArray(); | |||
} | |||
public override void Write(Utf8JsonWriter writer, byte[] value, JsonSerializerOptions options) | |||
{ | |||
var hexString = string.Join(" ", (value).Select(p => p.ToString("X2"))); | |||
writer.WriteStringValue(hexString); | |||
} | |||
} | |||
} |
@@ -0,0 +1,35 @@ | |||
@page "/jt808analyze" | |||
@using JT808.Protocol; | |||
@using JT808.Protocol.Extensions; | |||
@using Newtonsoft.Json; | |||
@inject IJT808Config JT808Config | |||
<h3>jt808analyze</h3> | |||
<p>Hex: @HexData</p> | |||
<button class="btn btn-primary" @onclick="Query">分析</button> | |||
<div class="right"> | |||
@Json | |||
</div> | |||
@code { | |||
private JT808Serializer Serializer; | |||
private string HexData = "7E 02 00 00 26 12 34 56 78 90 12 00 7D 02 00 00 00 01 00 00 00 02 00 BA 7F 0E 07 E4 F1 1C 00 28 00 3C 00 00 18 10 15 10 10 10 01 04 00 00 00 64 02 02 00 7D 01 13 7E"; | |||
private string Json; | |||
protected override void OnInitialized() | |||
{ | |||
Serializer = JT808Config.GetSerializer(); | |||
} | |||
private void Query() | |||
{ | |||
var data = HexData.ToHexBytes(); | |||
Json = Serializer.Analyze(data); | |||
} | |||
} |
@@ -0,0 +1,35 @@ | |||
@page "/jt808" | |||
@using JT808.Protocol; | |||
@using JT808.Protocol.Extensions; | |||
@using Newtonsoft.Json; | |||
@inject IJT808Config JT808Config | |||
<h3>JT808Parse</h3> | |||
<p>Hex: @HexData</p> | |||
<button class="btn btn-primary" @onclick="Query">解析</button> | |||
<div class="right"> | |||
@Json | |||
</div> | |||
@code { | |||
private JT808Serializer Serializer; | |||
private string HexData = "7E 02 00 00 26 12 34 56 78 90 12 00 7D 02 00 00 00 01 00 00 00 02 00 BA 7F 0E 07 E4 F1 1C 00 28 00 3C 00 00 18 10 15 10 10 10 01 04 00 00 00 64 02 02 00 7D 01 13 7E"; | |||
private string Json; | |||
protected override void OnInitialized() | |||
{ | |||
Serializer = JT808Config.GetSerializer(); | |||
} | |||
private void Query() | |||
{ | |||
var data = HexData.ToHexBytes(); | |||
Json = JsonConvert.SerializeObject(Serializer.Deserialize(data)); | |||
} | |||
} |
@@ -10,7 +10,9 @@ | |||
<head> | |||
<meta charset="utf-8" /> | |||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |||
<title>JTTools</title> | |||
<meta name="keywords" content="JT808|gb808|JT809|gb809|JT1078|JTT1078|JT19056|gb19056|在线解析工具"/> | |||
<meta name="description" content="道路运输车辆卫星定位协议在线解析工具"/> | |||
<title>JTTools解析工具</title> | |||
<base href="~/" /> | |||
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" /> | |||
<link href="css/site.css" rel="stylesheet" /> | |||
@@ -31,6 +33,7 @@ | |||
<a class="dismiss">🗙</a> | |||
</div> | |||
<div>Copyright © 2015-2019 SmallChi. All Rights Reserved. 粤ICP备19128140号</div> | |||
<script src="_framework/blazor.server.js"></script> | |||
</body> | |||
</html> |
@@ -3,11 +3,22 @@ using System.Collections.Generic; | |||
using System.IO; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using JT808.Protocol; | |||
using JT808.Protocol.Extensions.JT1078; | |||
using JT808.Protocol.Extensions.JTActiveSafety; | |||
using JT809.Protocol; | |||
using JT809.Protocol.Extensions.JT1078; | |||
using Microsoft.AspNetCore; | |||
using Microsoft.AspNetCore.Hosting; | |||
using Microsoft.Extensions.Configuration; | |||
using Microsoft.Extensions.Hosting; | |||
using Microsoft.Extensions.Logging; | |||
using Microsoft.AspNetCore.Builder; | |||
using Microsoft.AspNetCore.Components; | |||
using Microsoft.AspNetCore.HttpsPolicy; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using JTTools.Data; | |||
using Newtonsoft.Json.Serialization; | |||
namespace JTTools | |||
{ | |||
@@ -15,14 +26,80 @@ namespace JTTools | |||
{ | |||
public static void Main(string[] args) | |||
{ | |||
CreateHostBuilder(args).Build().Run(); | |||
} | |||
public static IHostBuilder CreateHostBuilder(string[] args) => | |||
Host.CreateDefaultBuilder(args) | |||
.ConfigureWebHostDefaults(webBuilder => | |||
{ | |||
webBuilder.UseStartup<Startup>(); | |||
}); | |||
webBuilder.ConfigureServices((hostingContext, services) => | |||
{ | |||
services.AddRazorPages(); | |||
services.AddServerSideBlazor(); | |||
services.AddSingleton<WeatherForecastService>(); | |||
services.AddControllers() | |||
//Microsoft.AspNetCore.Mvc.NewtonsoftJson | |||
.AddNewtonsoftJson(jsonOptions => | |||
{ | |||
jsonOptions.SerializerSettings.Converters.Add(new ByteArrayHexConverter()); | |||
jsonOptions.SerializerSettings.ContractResolver = new DefaultContractResolver(); | |||
//jsonOptions.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented; | |||
}) | |||
//.AddJsonOptions(jsonOptions => | |||
//{ | |||
// jsonOptions.JsonSerializerOptions.MaxDepth = 64; | |||
// jsonOptions.JsonSerializerOptions.Converters.Add(new ByteArrayHexTextJsonConverter()); | |||
//}) | |||
; | |||
services.AddCors(options => | |||
options.AddPolicy("Domain", builder => | |||
builder.WithOrigins(hostingContext.Configuration.GetSection("AllowedOrigins").Value.Split(",")) | |||
.AllowAnyMethod() | |||
.AllowAnyHeader() | |||
.AllowAnyOrigin())); | |||
}) | |||
.ConfigureKestrel(ksOptions => | |||
{ | |||
ksOptions.ListenAnyIP(18888); | |||
}) | |||
.ConfigureLogging((context, logging) => { | |||
//if (Environment.OSVersion.Platform == PlatformID.Unix) | |||
//{ | |||
// NLog.LogManager.LoadConfiguration("Configs/nlog.unix.config"); | |||
//} | |||
//else | |||
//{ | |||
// NLog.LogManager.LoadConfiguration("Configs/nlog.win.config"); | |||
//} | |||
//logging.AddNLog(new NLogProviderOptions { CaptureMessageTemplates = true, CaptureMessageProperties = true }); | |||
//logging.SetMinimumLevel(LogLevel.Trace); | |||
}) | |||
.ConfigureAppConfiguration((hostingContext, config) => | |||
{ | |||
config.SetBasePath(AppDomain.CurrentDomain.BaseDirectory); | |||
config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); | |||
}) | |||
.Configure(app => { | |||
app.UseRouting(); | |||
app.UseCors("Domain"); | |||
app.UseStaticFiles(); | |||
app.UseEndpoints(endpoints => | |||
{ | |||
endpoints.MapControllers(); | |||
endpoints.MapBlazorHub(); | |||
endpoints.MapFallbackToPage("/_Host"); | |||
}); | |||
}); | |||
}) | |||
.ConfigureServices(services => | |||
{ | |||
services.AddJT808Configure() | |||
.AddJT1078Configure() | |||
.AddJTActiveSafetyConfigure(); | |||
services.AddJT809Configure() | |||
.AddJT1078Configure(); | |||
}) | |||
.Build() | |||
.Run(); | |||
} | |||
} | |||
} |
@@ -6,7 +6,7 @@ | |||
<div class="main"> | |||
<div class="top-row px-4"> | |||
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a> | |||
<iframe id="github-star" style="border:none;vertical-align: middle;" width="105" height="20" src="https://ghbtns.com/github-btn.html?user=SmallChi&repo=JTTools&type=watch&count=true"></iframe> | |||
</div> | |||
<div class="content px-4"> | |||
@@ -12,6 +12,16 @@ | |||
<span class="oi oi-home" aria-hidden="true"></span> Home | |||
</NavLink> | |||
</li> | |||
<li class="nav-item px-3"> | |||
<NavLink class="nav-link" href="jt808"> | |||
<span class="oi oi-plus" aria-hidden="true"></span> JT808解析工具 | |||
</NavLink> | |||
</li> | |||
<li class="nav-item px-3"> | |||
<NavLink class="nav-link" href="jt808analyze"> | |||
<span class="oi oi-plus" aria-hidden="true"></span> JT808分析工具 | |||
</NavLink> | |||
</li> | |||
<li class="nav-item px-3"> | |||
<NavLink class="nav-link" href="counter"> | |||
<span class="oi oi-plus" aria-hidden="true"></span> Counter | |||
@@ -1,60 +0,0 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using Microsoft.AspNetCore.Builder; | |||
using Microsoft.AspNetCore.Components; | |||
using Microsoft.AspNetCore.Hosting; | |||
using Microsoft.AspNetCore.HttpsPolicy; | |||
using Microsoft.Extensions.Configuration; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using Microsoft.Extensions.Hosting; | |||
using JTTools.Data; | |||
namespace JTTools | |||
{ | |||
public class Startup | |||
{ | |||
public Startup(IConfiguration configuration) | |||
{ | |||
Configuration = configuration; | |||
} | |||
public IConfiguration Configuration { get; } | |||
// This method gets called by the runtime. Use this method to add services to the container. | |||
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 | |||
public void ConfigureServices(IServiceCollection services) | |||
{ | |||
services.AddRazorPages(); | |||
services.AddServerSideBlazor(); | |||
services.AddSingleton<WeatherForecastService>(); | |||
} | |||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |||
{ | |||
if (env.IsDevelopment()) | |||
{ | |||
app.UseDeveloperExceptionPage(); | |||
} | |||
else | |||
{ | |||
app.UseExceptionHandler("/Error"); | |||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. | |||
app.UseHsts(); | |||
} | |||
app.UseHttpsRedirection(); | |||
app.UseStaticFiles(); | |||
app.UseRouting(); | |||
app.UseEndpoints(endpoints => | |||
{ | |||
endpoints.MapBlazorHub(); | |||
endpoints.MapFallbackToPage("/_Host"); | |||
}); | |||
} | |||
} | |||
} |
@@ -6,5 +6,6 @@ | |||
"Microsoft": "Warning", | |||
"Microsoft.Hosting.Lifetime": "Information" | |||
} | |||
} | |||
}, | |||
"AllowedOrigins": "http://jttools.smallchi.cn,https://jttools.smallchi.cn,http://localhost:8080" | |||
} |
@@ -6,5 +6,6 @@ | |||
"Microsoft.Hosting.Lifetime": "Information" | |||
} | |||
}, | |||
"AllowedHosts": "*" | |||
"AllowedHosts": "*", | |||
"AllowedOrigins": "http://jttools.smallchi.cn,https://jttools.smallchi.cn,http://localhost:8080" | |||
} |