|
|
|
@ -14,6 +14,7 @@ using CoreAgent.WebSocketTransport.Interfaces; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using CoreAgent.Domain.Interfaces.Common; |
|
|
|
using CoreAgent.Infrastructure.Handlers.API; |
|
|
|
|
|
|
|
namespace CoreAgent.Infrastructure.Services.Network |
|
|
|
{ |
|
|
|
@ -31,10 +32,10 @@ namespace CoreAgent.Infrastructure.Services.Network |
|
|
|
private readonly IWebSocketTransport _webSocketTransport; |
|
|
|
private readonly IProtocolWsClientManager _protocolWsClientManager; |
|
|
|
private readonly IServiceScopeManager _serviceScopeManager; |
|
|
|
private readonly IRanAPICommandHandlerFactory _ranAPICommandHandlerFactory; |
|
|
|
private static readonly SemaphoreSlim _startLock = new(1, 1); |
|
|
|
private const int LockTimeoutSeconds = 60; |
|
|
|
|
|
|
|
|
|
|
|
public GeneralCellularNetworkService( |
|
|
|
ILogger<CellularNetworkService> logger, |
|
|
|
ILoggerFactory loggerFactory, |
|
|
|
@ -47,7 +48,8 @@ namespace CoreAgent.Infrastructure.Services.Network |
|
|
|
IWebSocketTransport webSocketTransport, |
|
|
|
IProtocolLogObserver protocolLogObserver, |
|
|
|
IProtocolWsClientManager protocolWsClientManager, |
|
|
|
IServiceScopeManager serviceScopeManager) |
|
|
|
IServiceScopeManager serviceScopeManager, |
|
|
|
IRanAPICommandHandlerFactory ranAPICommandHandlerFactory) |
|
|
|
{ |
|
|
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); |
|
|
|
_loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory)); |
|
|
|
@ -58,6 +60,7 @@ namespace CoreAgent.Infrastructure.Services.Network |
|
|
|
_webSocketTransport = webSocketTransport ?? throw new ArgumentNullException(nameof(webSocketTransport)); |
|
|
|
_protocolWsClientManager = protocolWsClientManager ?? throw new ArgumentNullException(nameof(protocolWsClientManager)); |
|
|
|
_serviceScopeManager = serviceScopeManager ?? throw new ArgumentNullException(nameof(serviceScopeManager)); |
|
|
|
_ranAPICommandHandlerFactory = ranAPICommandHandlerFactory ?? throw new ArgumentNullException(nameof(ranAPICommandHandlerFactory)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -381,10 +384,9 @@ namespace CoreAgent.Infrastructure.Services.Network |
|
|
|
{ |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
var step12Duration = (DateTime.UtcNow - step12Start).TotalMilliseconds; |
|
|
|
_logger.LogDebug("步骤12完成:启动所有协议客户端,耗时: {Duration}ms", step12Duration.ToString("F2")); |
|
|
|
|
|
|
|
await SetBcchLogStatusAsync(); |
|
|
|
var endTime = DateTime.UtcNow; |
|
|
|
var duration = endTime - startTime; |
|
|
|
_logger.LogInformation("蜂窝网络配置 {ConfigKey} 启动成功,当前状态: {Status},总耗时: {Duration}ms", |
|
|
|
@ -484,7 +486,9 @@ namespace CoreAgent.Infrastructure.Services.Network |
|
|
|
_logger.LogInformation("获取到 {ConfigCount} 个协议客户端配置", protocolConfigs.Length); |
|
|
|
_protocolWsClientManager.StartAllClientsAsync(protocolConfigs); |
|
|
|
// 启动所有协议客户端
|
|
|
|
var startResult = _protocolWsClientManager.CheckAllClientsConnection(10); |
|
|
|
//var startResult = _protocolWsClientManager.CheckAllClientsConnection(10);
|
|
|
|
//StartAllClients
|
|
|
|
var startResult = _protocolWsClientManager.StartAllClients(protocolConfigs); |
|
|
|
if (!startResult) |
|
|
|
{ |
|
|
|
_logger.LogWarning("部分协议客户端启动失败"); |
|
|
|
@ -513,5 +517,54 @@ namespace CoreAgent.Infrastructure.Services.Network |
|
|
|
return CellularNetworkOperationResult.Failure($"启动协议客户端失败: {ex.Message}"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 设置BCCH日志状态
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>任务</returns>
|
|
|
|
private async Task SetBcchLogStatusAsync() |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
// 使用工厂创建处理器实例
|
|
|
|
var ranApiCommandHandler = _ranAPICommandHandlerFactory.CreateHandler(); |
|
|
|
|
|
|
|
// 设置BCCH日志状态为true
|
|
|
|
_logger.LogInformation("开始设置BCCH日志状态为true"); |
|
|
|
var setTrueResult = await ranApiCommandHandler.SetBcchLogStatusAsync(true); |
|
|
|
|
|
|
|
if (setTrueResult) |
|
|
|
{ |
|
|
|
_logger.LogInformation("BCCH日志状态设置为true成功"); |
|
|
|
|
|
|
|
// 等待200秒
|
|
|
|
_logger.LogInformation("等待200秒后设置BCCH日志状态为false"); |
|
|
|
await Task.Delay(TimeSpan.FromMilliseconds(200)); |
|
|
|
|
|
|
|
// 设置BCCH日志状态为false
|
|
|
|
_logger.LogInformation("200秒后开始设置BCCH日志状态为false"); |
|
|
|
var setFalseResult = await ranApiCommandHandler.SetBcchLogStatusAsync(false); |
|
|
|
|
|
|
|
if (setFalseResult) |
|
|
|
{ |
|
|
|
_logger.LogInformation("BCCH日志状态设置为false成功"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_logger.LogWarning("BCCH日志状态设置为false失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_logger.LogWarning("BCCH日志状态设置为true失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
_logger.LogError(ex, "设置BCCH日志状态时发生异常"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|