Merge branch 'master' of ssh://git.swordlost.top:222/SikongJueluo/FPGA_WebLab into dpp
This commit is contained in:
@@ -95,6 +95,12 @@ try
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader()
|
||||
);
|
||||
options.AddPolicy("SignalR", policy => policy
|
||||
.WithOrigins("http://localhost:5173")
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod()
|
||||
.AllowCredentials()
|
||||
);
|
||||
});
|
||||
|
||||
// Use SignalR
|
||||
@@ -201,12 +207,15 @@ try
|
||||
};
|
||||
});
|
||||
app.UseSwaggerUi();
|
||||
|
||||
// SignalR
|
||||
app.UseWebSockets();
|
||||
app.UseSignalRHubSpecification();
|
||||
app.UseSignalRHubDevelopmentUI();
|
||||
|
||||
// Router
|
||||
app.MapControllers();
|
||||
app.MapHub<server.Hubs.JtagHub.JtagHub>("hubs/JtagHub").RequireCors("Users");
|
||||
app.MapHub<server.Hubs.JtagHub.JtagHub>("hubs/JtagHub");
|
||||
|
||||
// Setup Program
|
||||
MsgBus.Init();
|
||||
|
@@ -25,12 +25,19 @@ public interface IJtagReceiver
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[EnableCors("Users")]
|
||||
[EnableCors("SignalR")]
|
||||
public class JtagHub : Hub<IJtagReceiver>, IJtagHub
|
||||
{
|
||||
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
private ConcurrentDictionary<string, int> FreqTable = new();
|
||||
private ConcurrentDictionary<string, CancellationTokenSource> CancellationTokenSourceTable = new();
|
||||
private static ConcurrentDictionary<string, int> FreqTable = new();
|
||||
private static ConcurrentDictionary<string, CancellationTokenSource> CancellationTokenSourceTable = new();
|
||||
|
||||
private readonly IHubContext<JtagHub, IJtagReceiver> _hubContext;
|
||||
|
||||
public JtagHub(IHubContext<JtagHub, IJtagReceiver> hubContext)
|
||||
{
|
||||
_hubContext = hubContext;
|
||||
}
|
||||
|
||||
private Optional<Peripherals.JtagClient.Jtag> GetJtagClient(string userName)
|
||||
{
|
||||
@@ -92,33 +99,40 @@ public class JtagHub : Hub<IJtagReceiver>, IJtagHub
|
||||
}
|
||||
|
||||
await SetBoundaryScanFreq(freq);
|
||||
var cts = CancellationTokenSource.CreateLinkedTokenSource();
|
||||
var cts = new CancellationTokenSource();
|
||||
CancellationTokenSourceTable.AddOrUpdate(userName, cts, (key, value) => cts);
|
||||
|
||||
_ = Task
|
||||
.Run(
|
||||
() => BoundaryScanLogicPorts(
|
||||
Context.ConnectionId,
|
||||
userName,
|
||||
cts.Token),
|
||||
_ = Task.Run(
|
||||
() => BoundaryScanLogicPorts(Context.ConnectionId, userName, cts.Token),
|
||||
cts.Token)
|
||||
.ContinueWith((task) =>
|
||||
{
|
||||
if (!task.IsFaulted)
|
||||
if (task.IsFaulted)
|
||||
{
|
||||
return;
|
||||
// 遍历所有异常
|
||||
foreach (var ex in task.Exception.InnerExceptions)
|
||||
{
|
||||
if (ex is OperationCanceledException)
|
||||
{
|
||||
logger.Info($"Boundary scan operation cancelled for user {userName}");
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error($"Boundary scan operation failed for user {userName}: {ex}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (task.Exception.InnerException is OperationCanceledException)
|
||||
else if (task.IsCanceled)
|
||||
{
|
||||
logger.Info($"Boundary scan operation cancelled for user {userName}");
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error(task.Exception);
|
||||
logger.Info($"Boundary scan completed successfully for user {userName}");
|
||||
}
|
||||
});
|
||||
|
||||
logger.Info($"Boundary scan started for user {userName}");
|
||||
return true;
|
||||
}
|
||||
catch (Exception error)
|
||||
@@ -144,10 +158,12 @@ public class JtagHub : Hub<IJtagReceiver>, IJtagHub
|
||||
|
||||
cts.Cancel();
|
||||
cts.Token.WaitHandle.WaitOne();
|
||||
|
||||
logger.Info($"Boundary scan stopped for user {userName}");
|
||||
return true;
|
||||
}
|
||||
|
||||
private async void BoundaryScanLogicPorts(string connectionID, string userName, CancellationToken cancellationToken)
|
||||
private async Task BoundaryScanLogicPorts(string connectionID, string userName, CancellationToken cancellationToken)
|
||||
{
|
||||
var jtagCtrl = GetJtagClient(userName).OrThrow(() => new InvalidOperationException("JTAG client not found"));
|
||||
var cntFail = 0;
|
||||
@@ -161,9 +177,10 @@ public class JtagHub : Hub<IJtagReceiver>, IJtagHub
|
||||
{
|
||||
logger.Error($"User {userName} boundary scan failed for device {jtagCtrl.address}: {ret.Error}");
|
||||
cntFail++;
|
||||
continue;
|
||||
}
|
||||
|
||||
await this.Clients.Client(connectionID).OnReceiveBoundaryScanData(ret.Value);
|
||||
await _hubContext.Clients.Client(connectionID).OnReceiveBoundaryScanData(ret.Value);
|
||||
// logger.Info($"User {userName} successfully completed boundary scan for device {jtagCtrl.address}");
|
||||
|
||||
await Task.Delay(FreqTable.TryGetValue(userName, out var freq) ? 1000 / freq : 1000 / 100, cancellationToken);
|
||||
|
Reference in New Issue
Block a user