diff --git a/CoreAgent.Domain/Interfaces/Network/ICellularNetworkContext.cs b/CoreAgent.Domain/Interfaces/Network/ICellularNetworkContext.cs
index a82de91..1d2786a 100644
--- a/CoreAgent.Domain/Interfaces/Network/ICellularNetworkContext.cs
+++ b/CoreAgent.Domain/Interfaces/Network/ICellularNetworkContext.cs
@@ -111,4 +111,12 @@ public interface ICellularNetworkContext
/// 网络状态
CellularNetworkState GetNetworkState();
#endregion
-}
\ No newline at end of file
+
+ #region 小区配置管理
+ ///
+ /// 获取小区配置提供者
+ ///
+ /// 小区配置提供者
+ CellConfigurationProvider GetCellProvider();
+ #endregion
+}
\ No newline at end of file
diff --git a/CoreAgent.Domain/Models/Network/CellConfigurationProvider.cs b/CoreAgent.Domain/Models/Network/CellConfigurationProvider.cs
new file mode 100644
index 0000000..b2f1040
--- /dev/null
+++ b/CoreAgent.Domain/Models/Network/CellConfigurationProvider.cs
@@ -0,0 +1,79 @@
+using System.Collections.Generic;
+using System.Linq;
+
+namespace CoreAgent.Domain.Models.Network
+{
+ public class CellConfigurationProvider
+ {
+ private readonly List _lteCellConfigurations;
+ private readonly List _nrCellConfigurations;
+
+ public IReadOnlyList LTECellConfigurations => _lteCellConfigurations.AsReadOnly();
+ public IReadOnlyList NrCellConfigurations => _nrCellConfigurations.AsReadOnly();
+
+ public CellConfigurationProvider()
+ {
+ _lteCellConfigurations = new List();
+ _nrCellConfigurations = new List();
+ }
+
+ public void AddLTEConfiguration(LTECellConfiguration configuration)
+ {
+ var existingConfig = _lteCellConfigurations.FirstOrDefault(s => s.CellID == configuration.CellID);
+ if (existingConfig != null)
+ _lteCellConfigurations.Remove(existingConfig);
+ _lteCellConfigurations.Add(configuration);
+ }
+
+ public void AddNrConfiguration(NrCellConfiguration configuration)
+ {
+ var existingConfig = _nrCellConfigurations.FirstOrDefault(s => s.CellID == configuration.CellID);
+ if (existingConfig != null)
+ _nrCellConfigurations.Remove(existingConfig);
+ _nrCellConfigurations.Add(configuration);
+ }
+
+ private void RemoveLTEConfiguration(int cellId)
+ {
+ var config = _lteCellConfigurations.FirstOrDefault(s => s.CellID == cellId);
+ if (config != null)
+ _lteCellConfigurations.Remove(config);
+ }
+
+ private void RemoveNrConfiguration(int cellId)
+ {
+ var config = _nrCellConfigurations.FirstOrDefault(s => s.CellID == cellId);
+ if (config != null)
+ _nrCellConfigurations.Remove(config);
+ }
+
+ public LTECellConfiguration? GetLTEConfiguration(int cellId)
+ {
+ return _lteCellConfigurations.FirstOrDefault(s => s.CellID == cellId);
+ }
+
+ public NrCellConfiguration? GetNrConfiguration(int cellId)
+ {
+ return _nrCellConfigurations.FirstOrDefault(s => s.CellID == cellId);
+ }
+
+ public Dictionary GetCellPortMapping()
+ {
+ var result = new Dictionary();
+
+ // 添加LTE配置
+ foreach (var config in _lteCellConfigurations)
+ {
+ result[config.CellID] = config.RfPort;
+ }
+
+ // 添加NR配置
+ foreach (var config in _nrCellConfigurations)
+ {
+ result[config.CellID] = config.RfPort;
+ }
+
+ return result;
+ }
+ }
+}
diff --git a/CoreAgent.Domain/Models/Network/LTECellConfiguration.cs b/CoreAgent.Domain/Models/Network/LTECellConfiguration.cs
new file mode 100644
index 0000000..01c08d4
--- /dev/null
+++ b/CoreAgent.Domain/Models/Network/LTECellConfiguration.cs
@@ -0,0 +1,251 @@
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace CoreAgent.Domain.Models.Network
+{
+ ///
+ /// 小区配置实体,对应无线参数配置
+ /// 用于存储LTE小区的各种物理层和协议层配置参数
+ /// 支持JSON序列化,属性名与外部API保持一致
+ ///
+ public class LTECellConfiguration
+ {
+ ///
+ /// 小区ID
+ ///
+ [JsonProperty("cell_Id")]
+ public int CellID { get; set; }
+ /// 下行天线数量
+ [JsonProperty("n_antenna_dl")]
+ public int NAntennaDl { get; set; }
+
+ /// 上行天线数量
+ [JsonProperty("n_antenna_ul")]
+ public int NAntennaUl { get; set; }
+
+ /// 下行传输层数
+ [JsonProperty("n_layer_dl")]
+ public int NLayerDl { get; set; }
+
+ /// 上行传输层数
+ [JsonProperty("n_layer_ul")]
+ public int NLayerUl { get; set; }
+
+ /// 天线增益(dB)
+ [JsonProperty("gain")]
+ public int Gain { get; set; }
+
+ /// 上行链路是否禁用
+ [JsonProperty("ul_disabled")]
+ public bool UlDisabled { get; set; }
+
+ /// 射频端口号
+ [JsonProperty("rf_port")]
+ public int RfPort { get; set; }
+
+ /// 下行QAM调制阶数
+ [JsonProperty("dl_qam")]
+ public int DlQam { get; set; }
+
+ /// 上行QAM调制阶数
+ [JsonProperty("ul_qam")]
+ public int UlQam { get; set; }
+
+ /// 物理小区标识(PCI)
+ [JsonProperty("n_id_cell")]
+ public int NIdCell { get; set; }
+
+ /// 下行资源块数量
+ [JsonProperty("n_rb_dl")]
+ public int NRbDl { get; set; }
+
+ /// 上行资源块数量
+ [JsonProperty("n_rb_ul")]
+ public int NRbUl { get; set; }
+
+ /// 下行E-UTRA绝对射频信道号
+ [JsonProperty("dl_earfcn")]
+ public int DlEarfcn { get; set; }
+
+ /// 上行E-UTRA绝对射频信道号
+ [JsonProperty("ul_earfcn")]
+ public int UlEarfcn { get; set; }
+
+ /// LTE频段号
+ [JsonProperty("band")]
+ public int Band { get; set; }
+
+ /// 下行载波频率(Hz)
+ [JsonProperty("dl_freq")]
+ public long DlFreq { get; set; }
+
+ /// 上行载波频率(Hz)
+ [JsonProperty("ul_freq")]
+ public long UlFreq { get; set; }
+
+ /// 双工模式(FDD/TDD)
+ [JsonProperty("mode")]
+ public string Mode { get; set; } = string.Empty;
+
+ /// PRACH序列索引
+ [JsonProperty("prach_sequence_index")]
+ public int PrachSequenceIndex { get; set; }
+
+ /// 下行循环前缀类型
+ [JsonProperty("dl_cyclic_prefix")]
+ public string DlCyclicPrefix { get; set; } = string.Empty;
+
+ /// 上行循环前缀类型
+ [JsonProperty("ul_cyclic_prefix")]
+ public string UlCyclicPrefix { get; set; } = string.Empty;
+
+ /// PRACH配置索引
+ [JsonProperty("prach_config_index")]
+ public int PrachConfigIndex { get; set; }
+
+ /// PRACH频域偏移
+ [JsonProperty("prach_freq_offset")]
+ public int PrachFreqOffset { get; set; }
+
+ /// PUCCH delta shift参数
+ [JsonProperty("delta_pucch_shift")]
+ public int DeltaPucchShift { get; set; }
+
+ /// CQI报告的资源块数量
+ [JsonProperty("n_rb_cqi")]
+ public int NRbCqi { get; set; }
+
+ /// 循环移位天线端口数量
+ [JsonProperty("n_cs_an")]
+ public int NCsAn { get; set; }
+
+ /// PUCCH资源配置列表
+ [JsonProperty("pucch_allocation")]
+ public List PucchAllocation { get; set; } = new();
+
+ /// PUCCH ACK/NACK起始位置
+ [JsonProperty("pucch_ack_nack_start")]
+ public int PucchAckNackStart { get; set; }
+
+ /// PUCCH保留资源块列表
+ [JsonProperty("pucch_reserved_rbs")]
+ public List PucchReservedRbs { get; set; } = new();
+
+ /// 调度请求(SR)资源数量
+ [JsonProperty("sr_resource_count")]
+ public int SrResourceCount { get; set; }
+
+ /// CQI资源数量
+ [JsonProperty("cqi_resource_count")]
+ public int CqiResourceCount { get; set; }
+
+ /// SRS资源配置
+ [JsonProperty("srs_resources")]
+ public SrsResources SrsResources { get; set; } = new();
+
+ /// 保证比特率(GBR)配置
+ [JsonProperty("gbr")]
+ public GbrConfig Gbr { get; set; } = new();
+
+ /// 跟踪区域码(TAC)
+ [JsonProperty("tac")]
+ public int Tac { get; set; }
+
+ /// 邻区信息
+ [JsonProperty("nr_scell_list")]
+ public List NrScellList { get; set; } = new();
+
+ /// 公共陆地移动网络(PLMN)列表
+ [JsonProperty("plmn_list")]
+ public List PlmnList { get; set; } = new();
+
+ ///
+ ///
+ ///
+ ///
+ public void SetCellId(int id)
+ {
+ this.CellID =id;
+ }
+ }
+
+ ///
+ /// PUCCH资源配置结构
+ /// 定义物理上行控制信道的资源配置参数
+ ///
+ public class PucchAllocation
+ {
+ /// PUCCH格式类型
+ [JsonProperty("type")]
+ public string Type { get; set; } = string.Empty;
+
+ /// 分配的资源块数量
+ [JsonProperty("rbs")]
+ public int Rbs { get; set; }
+
+ /// PUCCH参数n
+ [JsonProperty("n")]
+ public int N { get; set; }
+ }
+
+ ///
+ /// SRS资源配置结构
+ /// 定义探测参考信号的资源配置参数
+ ///
+ public class SrsResources
+ {
+ /// 频域偏移
+ [JsonProperty("offsets")]
+ public int Offsets { get; set; }
+
+ /// 频点数量
+ [JsonProperty("freqs")]
+ public int Freqs { get; set; }
+
+ /// 总资源数量
+ [JsonProperty("total")]
+ public int Total { get; set; }
+ }
+
+ ///
+ /// 保证比特率(GBR)配置结构
+ /// 定义服务质量相关的比特率限制
+ ///
+ public class GbrConfig
+ {
+ /// 下行速率限制(bps)
+ [JsonProperty("dl_limit")]
+ public int DlLimit { get; set; }
+
+ /// 上行速率限制(bps)
+ [JsonProperty("ul_limit")]
+ public int UlLimit { get; set; }
+ }
+
+ ///
+ /// PLMN配置项
+ /// 定义公共陆地移动网络的配置信息
+ ///
+ public class PlmnItem
+ {
+ /// PLMN编码(MCC+MNC)
+ [JsonProperty("plmn")]
+ public string Plmn { get; set; } = string.Empty;
+
+ /// 是否为保留PLMN
+ [JsonProperty("reserved")]
+ public bool Reserved { get; set; }
+ }
+ ///
+ /// 邻区信息
+ ///
+ public class NrScellItem
+ {
+ [JsonProperty("cell_id")]
+ public int CellId { get; set; }
+ }
+}
diff --git a/CoreAgent.Domain/Models/Network/NrCellConfiguration.cs b/CoreAgent.Domain/Models/Network/NrCellConfiguration.cs
new file mode 100644
index 0000000..7e8f2c1
--- /dev/null
+++ b/CoreAgent.Domain/Models/Network/NrCellConfiguration.cs
@@ -0,0 +1,152 @@
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace CoreAgent.Domain.Models.Network
+{
+
+ ///
+ /// 5G NR小区配置实体,对应5G无线参数配置
+ /// 用于存储5G NR小区的各种物理层和协议层配置参数
+ /// 支持JSON序列化,属性名与外部API保持一致
+ ///
+ public class NrCellConfiguration
+ {
+ ///
+ /// 小区ID
+ ///
+ [JsonProperty("cell_Id")]
+ public int CellID { get; set; }
+ /// 下行天线数量
+ [JsonProperty("n_antenna_dl")]
+ public int NAntennaDl { get; set; }
+
+ /// 上行天线数量
+ [JsonProperty("n_antenna_ul")]
+ public int NAntennaUl { get; set; }
+
+ /// 下行传输层数
+ [JsonProperty("n_layer_dl")]
+ public int NLayerDl { get; set; }
+
+ /// 上行传输层数
+ [JsonProperty("n_layer_ul")]
+ public int NLayerUl { get; set; }
+
+ /// 天线增益(dB)
+ [JsonProperty("gain")]
+ public int Gain { get; set; }
+
+ /// 上行链路是否禁用
+ [JsonProperty("ul_disabled")]
+ public bool UlDisabled { get; set; }
+
+ /// 射频端口号
+ [JsonProperty("rf_port")]
+ public int RfPort { get; set; }
+
+ /// 下行QAM调制阶数
+ [JsonProperty("dl_qam")]
+ public int DlQam { get; set; }
+
+ /// 上行QAM调制阶数
+ [JsonProperty("ul_qam")]
+ public int UlQam { get; set; }
+
+ /// 5G NR物理小区标识
+ [JsonProperty("n_id_nrcell")]
+ public int NIdNrCell { get; set; }
+
+ /// 5G NR频段号
+ [JsonProperty("band")]
+ public int Band { get; set; }
+
+ /// 下行5G NR绝对射频信道号
+ [JsonProperty("dl_nr_arfcn")]
+ public int DlNrArfcn { get; set; }
+
+ /// 上行5G NR绝对射频信道号
+ [JsonProperty("ul_nr_arfcn")]
+ public int UlNrArfcn { get; set; }
+
+ /// 下行载波频率(Hz)
+ [JsonProperty("dl_freq")]
+ public long DlFreq { get; set; }
+
+ /// 上行载波频率(Hz)
+ [JsonProperty("ul_freq")]
+ public long UlFreq { get; set; }
+
+ /// 下行资源块数量
+ [JsonProperty("n_rb_dl")]
+ public int NRbDl { get; set; }
+
+ /// 上行资源块数量
+ [JsonProperty("n_rb_ul")]
+ public int NRbUl { get; set; }
+
+ /// SSB 5G NR绝对射频信道号
+ [JsonProperty("ssb_nr_arfcn")]
+ public int SsbNrArfcn { get; set; }
+
+ /// 下行MU-MIMO配置
+ [JsonProperty("dl_mu")]
+ public int DlMu { get; set; }
+
+ /// 上行MU-MIMO配置
+ [JsonProperty("ul_mu")]
+ public int UlMu { get; set; }
+
+ /// SSB MU-MIMO配置
+ [JsonProperty("ssb_mu")]
+ public int SsbMu { get; set; }
+
+ /// 双工模式(FDD/TDD)
+ [JsonProperty("mode")]
+ public string Mode { get; set; } = string.Empty;
+
+ /// PRACH序列索引
+ [JsonProperty("prach_sequence_index")]
+ public int PrachSequenceIndex { get; set; }
+
+ /// 保证比特率(GBR)配置
+ [JsonProperty("gbr")]
+ public GbrConfig Gbr { get; set; } = new();
+
+ /// 公共陆地移动网络(PLMN)列表
+ [JsonProperty("plmn_list")]
+ public List PlmnList { get; set; } = new();
+
+ ///
+ ///
+ ///
+ ///
+ public void SetCellId(int id)
+ {
+ this.CellID = id;
+ }
+ }
+
+ ///
+ /// 5G NR PLMN配置项
+ /// 定义5G NR公共陆地移动网络的配置信息
+ ///
+ public class NrPlmnItem
+ {
+ /// PLMN标识列表
+ [JsonProperty("plmn_ids")]
+ public List PlmnIds { get; set; } = new();
+
+ /// 是否为保留PLMN
+ [JsonProperty("reserved")]
+ public bool Reserved { get; set; }
+
+ /// 跟踪区域码(TAC)
+ [JsonProperty("tac")]
+ public int Tac { get; set; }
+ }
+
+}
diff --git a/CoreAgent.Infrastructure/Contexts/CellularNetworkContext.cs b/CoreAgent.Infrastructure/Contexts/CellularNetworkContext.cs
index 59294f9..cd65169 100644
--- a/CoreAgent.Infrastructure/Contexts/CellularNetworkContext.cs
+++ b/CoreAgent.Infrastructure/Contexts/CellularNetworkContext.cs
@@ -14,6 +14,7 @@ public class CellularNetworkContext : ICellularNetworkContext, IDisposable
{
private readonly object _lock = new();
private CellularNetworkState _networkState;
+ private CellConfigurationProvider _cellConfigurationProvider;
private readonly NetworkCommandConfig _networkCommandConfig;
private readonly AppSettings _appSettings;
private string _neConfigKey = string.Empty;
@@ -89,6 +90,7 @@ public class CellularNetworkContext : ICellularNetworkContext, IDisposable
_networkIPEndPointManager.Clear();
_neConfigKey = neConfigKey;
_networkState = new CellularNetworkState(_neConfigKey);
+ _cellConfigurationProvider = new CellConfigurationProvider();
_currentConfigType = NetworkConfigType.None;
_isInitialized = true;
}
@@ -232,6 +234,28 @@ public class CellularNetworkContext : ICellularNetworkContext, IDisposable
}
}
+ ///
+ /// 获取小区配置
+ ///
+ /// 小区配置
+ public CellConfigurationProvider GetCellProvider()
+ {
+ if (_isDisposed)
+ {
+ throw new ObjectDisposedException(nameof(CellularNetworkContext));
+ }
+
+ if (!_isInitialized)
+ {
+ throw new InvalidOperationException("上下文未初始化,请先调用 Initialize 方法");
+ }
+
+ lock (_lock)
+ {
+ return _cellConfigurationProvider ?? throw new InvalidOperationException("小区配置提供者未初始化,请确保上下文已正确初始化");
+ }
+ }
+
///
/// 重置上下文状态
///
@@ -277,6 +301,7 @@ public class CellularNetworkContext : ICellularNetworkContext, IDisposable
_deviceCode =string.Empty;
_isInitialized = false;
_networkState = new CellularNetworkState(string.Empty);
+ _cellConfigurationProvider = new CellConfigurationProvider();
_networkIPEndPointManager.Clear();
_currentConfigType = NetworkConfigType.None;
_logger.LogInformation("CellularNetworkContext 重置完成");
diff --git a/CoreAgent.Infrastructure/Services/Network/NetworkProtocolLogObserver.cs b/CoreAgent.Infrastructure/Services/Network/NetworkProtocolLogObserver.cs
index bb57f2a..54432ad 100644
--- a/CoreAgent.Infrastructure/Services/Network/NetworkProtocolLogObserver.cs
+++ b/CoreAgent.Infrastructure/Services/Network/NetworkProtocolLogObserver.cs
@@ -5,11 +5,14 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using CoreAgent.Domain.Interfaces.Network;
+using CoreAgent.Domain.Models.Network;
using CoreAgent.ProtocolClient.Models;
using CoreAgent.ProtocolClient.ProtocolEngineCore;
using CoreAgent.WebSocketTransport.Interfaces;
using CoreAgent.WebSocketTransport.Models;
+using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
+using Newtonsoft.Json.Linq;
namespace CoreAgent.Infrastructure.Services.Network
{
@@ -181,5 +184,89 @@ namespace CoreAgent.Infrastructure.Services.Network
_disposed = true;
}
+
+ public void OnLTECellConfigurationReceived(Dictionary cellConfiguration)
+ {
+ if (cellConfiguration == null)
+ {
+ _logger.LogWarning("接收到的LTE小区配置为空");
+ return;
+ }
+
+ _logger.LogInformation("开始处理LTE小区配置,配置数量: {ConfigCount}", cellConfiguration.Count);
+
+ try
+ {
+ foreach (var cell in cellConfiguration)
+ {
+ try
+ {
+ var configuration = cell.Value.ToObject();
+ if (configuration is null)
+ {
+ _logger.LogWarning("小区配置反序列化失败,小区ID: {CellId}", cell.Key);
+ continue;
+ }
+
+ configuration.SetCellId(Convert.ToInt32(cell.Key));
+ _context.GetCellProvider().AddLTEConfiguration(configuration);
+ _logger.LogDebug("LTE小区配置添加成功,小区ID: {CellId}", cell.Key);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "处理单个LTE小区配置时发生异常,小区ID: {CellId}", cell.Key);
+ }
+ }
+
+ _logger.LogInformation("LTE小区配置处理完成,成功处理数量: {SuccessCount}",
+ cellConfiguration.Count);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "处理LTE小区配置时发生异常,配置数量: {ConfigCount}", cellConfiguration.Count);
+ }
+ }
+
+ public void OnNrCellConfigurationReceived(Dictionary cellConfiguration)
+ {
+ if (cellConfiguration == null)
+ {
+ _logger.LogWarning("接收到的NR小区配置为空");
+ return;
+ }
+
+ _logger.LogInformation("开始处理NR小区配置,配置数量: {ConfigCount}", cellConfiguration.Count);
+
+ try
+ {
+ foreach (var cell in cellConfiguration)
+ {
+ try
+ {
+ var configuration = cell.Value.ToObject();
+ if (configuration is null)
+ {
+ _logger.LogWarning("小区配置反序列化失败,小区ID: {CellId}", cell.Key);
+ continue;
+ }
+
+ configuration.SetCellId(Convert.ToInt32(cell.Key));
+ _context.GetCellProvider().AddNrConfiguration(configuration);
+ _logger.LogDebug("NR小区配置添加成功,小区ID: {CellId}", cell.Key);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "处理单个NR小区配置时发生异常,小区ID: {CellId}", cell.Key);
+ }
+ }
+
+ _logger.LogInformation("NR小区配置处理完成,成功处理数量: {SuccessCount}",
+ cellConfiguration.Count);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "处理NR小区配置时发生异常,配置数量: {ConfigCount}", cellConfiguration.Count);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/CoreAgent.ProtocolClient/ProtocolEngineCore/IProtocolLogObserver.cs b/CoreAgent.ProtocolClient/ProtocolEngineCore/IProtocolLogObserver.cs
index c6ef5c0..38684d2 100644
--- a/CoreAgent.ProtocolClient/ProtocolEngineCore/IProtocolLogObserver.cs
+++ b/CoreAgent.ProtocolClient/ProtocolEngineCore/IProtocolLogObserver.cs
@@ -1,4 +1,5 @@
using CoreAgent.ProtocolClient.Models;
+using Newtonsoft.Json.Linq;
namespace CoreAgent.ProtocolClient.ProtocolEngineCore
{
@@ -13,5 +14,16 @@ namespace CoreAgent.ProtocolClient.ProtocolEngineCore
///
/// 协议日志详情列表
void OnProtocolLogsReceived(IEnumerable logDetails);
+
+ ///
+ /// 解析 LTE 参数 写入上下文
+ ///
+ ///
+ void OnLTECellConfigurationReceived(Dictionary CellConfiguration);
+ ///
+ /// 解析 NR 参数 写入上下文
+ ///
+ ///
+ void OnNrCellConfigurationReceived(Dictionary CellConfiguration);
}
}
\ No newline at end of file
diff --git a/CoreAgent.ProtocolClient/ProtocolWsClient/ProtocolWsClient.Core.cs b/CoreAgent.ProtocolClient/ProtocolWsClient/ProtocolWsClient.Core.cs
index f0e7723..38d1c75 100644
--- a/CoreAgent.ProtocolClient/ProtocolWsClient/ProtocolWsClient.Core.cs
+++ b/CoreAgent.ProtocolClient/ProtocolWsClient/ProtocolWsClient.Core.cs
@@ -22,6 +22,7 @@ namespace CoreAgent.ProtocolClient.ProtocolWsClient
private readonly ILogger _logger;
private readonly ProtocolClientConfig _config;
private readonly ProtocolClientContext _context;
+ private readonly IProtocolLogObserver _protocolLogObserver;
private bool _isReady = false;
private bool _disposed = false;
#endregion
@@ -51,6 +52,7 @@ namespace CoreAgent.ProtocolClient.ProtocolWsClient
_config = config;
_logger = loggerFactory.CreateLogger();
_context = new ProtocolClientContext(loggerFactory);
+ this._protocolLogObserver = protocolLogObserver;
_messageManager = new WebSocketMessageManager(config.Name, loggerFactory);
_authManager = new AuthenticationManager(_config, _logger, (msg) => _messageManager.SendMessage(msg));
_statsManager = new StatsManager(_config.Name, _logger, (msg, cb, err) => _messageManager.SendMessage(msg, cb, err));
diff --git a/CoreAgent.ProtocolClient/ProtocolWsClient/ProtocolWsClient.MessageDispatch.cs b/CoreAgent.ProtocolClient/ProtocolWsClient/ProtocolWsClient.MessageDispatch.cs
index e6058e5..1f2a798 100644
--- a/CoreAgent.ProtocolClient/ProtocolWsClient/ProtocolWsClient.MessageDispatch.cs
+++ b/CoreAgent.ProtocolClient/ProtocolWsClient/ProtocolWsClient.MessageDispatch.cs
@@ -58,6 +58,20 @@ namespace CoreAgent.ProtocolClient.ProtocolWsClient
var data = cell.Value.ToObject();
_context.CellParameterManager.AddCell(Convert.ToInt32(cell.Key), data);
}
+ _protocolLogObserver.OnLTECellConfigurationReceived(cells);
+ }
+ }
+ if (config["nr_cells"] != null)
+ {
+ var cells = config["nr_cells"]?.ToObject>();
+ if (cells != null)
+ {
+ //foreach (var cell in cells)
+ //{
+ // var data = cell.Value.ToObject();
+ // _context.CellParameterManager.AddCell(Convert.ToInt32(cell.Key), data);
+ //}
+ _protocolLogObserver.OnNrCellConfigurationReceived(cells);
}
}
SetState(ClientState.Connected);
diff --git a/modify.md b/modify.md
index 023e8bc..438b6ef 100644
--- a/modify.md
+++ b/modify.md
@@ -1947,6 +1947,171 @@ var result = await mediator.Send(command);
## 2025-08-21
+### 修复NetworkProtocolLogObserver中的OnLTECellConfigurationReceived和OnNrCellConfigurationReceived方法
+
+**修改时间**: 2025年8月21日
+**修改文件**:
+- `CoreAgent.Infrastructure/Services/Network/NetworkProtocolLogObserver.cs`
+
+**修改内容**:
+
+1. **修复命名错误和异常处理**:
+ - **参数命名规范化**: 将方法参数从 `CellConfiguration` 改为 `cellConfiguration`,符合C#命名约定
+ - **异常处理改进**: 移除空的异常处理块,改为记录错误而不是重新抛出异常
+ - **空值检查增强**: 添加对输入参数的空值检查,避免空引用异常
+ - **详细日志记录**: 为每个处理步骤添加详细的日志记录
+
+2. **OnLTECellConfigurationReceived方法修复**:
+ ```csharp
+ // 修复前
+ public void OnLTECellConfigurationReceived(Dictionary CellConfiguration)
+ {
+ try
+ {
+ foreach (var cell in CellConfiguration)
+ {
+ var Configuration = cell.Value.ToObject();
+ if (Configuration is null) continue;
+ Configuration.SetCellId(Convert.ToInt32(cell.Key));
+ _context.GetCellProvider().AddLTEConfiguration(Configuration);
+ }
+ }
+ catch (Exception)
+ {
+ throw;
+ }
+ }
+
+ // 修复后
+ public void OnLTECellConfigurationReceived(Dictionary cellConfiguration)
+ {
+ if (cellConfiguration == null)
+ {
+ _logger.LogWarning("接收到的LTE小区配置为空");
+ return;
+ }
+
+ _logger.LogInformation("开始处理LTE小区配置,配置数量: {ConfigCount}", cellConfiguration.Count);
+
+ try
+ {
+ foreach (var cell in cellConfiguration)
+ {
+ try
+ {
+ var configuration = cell.Value.ToObject();
+ if (configuration is null)
+ {
+ _logger.LogWarning("小区配置反序列化失败,小区ID: {CellId}", cell.Key);
+ continue;
+ }
+
+ configuration.SetCellId(Convert.ToInt32(cell.Key));
+ _context.GetCellProvider().AddLTEConfiguration(configuration);
+ _logger.LogDebug("LTE小区配置添加成功,小区ID: {CellId}", cell.Key);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "处理单个LTE小区配置时发生异常,小区ID: {CellId}", cell.Key);
+ }
+ }
+
+ _logger.LogInformation("LTE小区配置处理完成,成功处理数量: {SuccessCount}",
+ cellConfiguration.Count);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "处理LTE小区配置时发生异常,配置数量: {ConfigCount}", cellConfiguration.Count);
+ }
+ }
+ ```
+
+3. **OnNrCellConfigurationReceived方法修复**:
+ ```csharp
+ // 修复前
+ public void OnNrCellConfigurationReceived(Dictionary CellConfiguration)
+ {
+ try
+ {
+ foreach (var cell in CellConfiguration)
+ {
+ var Configuration = cell.Value.ToObject();
+ if (Configuration is null) continue;
+ Configuration.SetCellId(Convert.ToInt32(cell.Key));
+ _context.GetCellProvider().AddNrConfiguration(Configuration);
+ }
+ }
+ catch (Exception)
+ {
+ throw;
+ }
+ }
+
+ // 修复后
+ public void OnNrCellConfigurationReceived(Dictionary cellConfiguration)
+ {
+ if (cellConfiguration == null)
+ {
+ _logger.LogWarning("接收到的NR小区配置为空");
+ return;
+ }
+
+ _logger.LogInformation("开始处理NR小区配置,配置数量: {ConfigCount}", cellConfiguration.Count);
+
+ try
+ {
+ foreach (var cell in cellConfiguration)
+ {
+ try
+ {
+ var configuration = cell.Value.ToObject();
+ if (configuration is null)
+ {
+ _logger.LogWarning("小区配置反序列化失败,小区ID: {CellId}", cell.Key);
+ continue;
+ }
+
+ configuration.SetCellId(Convert.ToInt32(cell.Key));
+ _context.GetCellProvider().AddNrConfiguration(configuration);
+ _logger.LogDebug("NR小区配置添加成功,小区ID: {CellId}", cell.Key);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "处理单个NR小区配置时发生异常,小区ID: {CellId}", cell.Key);
+ }
+ }
+
+ _logger.LogInformation("NR小区配置处理完成,成功处理数量: {SuccessCount}",
+ cellConfiguration.Count);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "处理NR小区配置时发生异常,配置数量: {ConfigCount}", cellConfiguration.Count);
+ }
+ }
+ ```
+
+4. **修复的关键问题**:
+ - **命名规范**: 参数名使用小写开头,符合C#命名约定
+ - **异常处理**: 移除空的异常处理块,改为记录错误而不是重新抛出
+ - **空值检查**: 添加输入参数的空值检查,避免空引用异常
+ - **错误隔离**: 单个配置项处理失败不影响其他配置项
+ - **日志详细**: 为每个处理步骤添加详细的日志记录
+ - **错误记录**: 记录具体的错误信息和异常详情
+
+5. **设计优势**:
+ - **代码规范**: 遵循C#命名约定和编码规范
+ - **错误处理完善**: 提供详细的错误信息和异常处理
+ - **日志详细**: 便于调试和问题排查
+ - **错误隔离**: 单个错误不影响整体处理流程
+ - **可维护性**: 代码结构清晰,易于理解和维护
+
+**影响范围**:
+- 小区配置处理的稳定性和可靠性
+- 错误处理和日志记录能力
+- 代码可读性和维护性
+- 调试和问题排查能力
+
### CoreAgent.Infrastructure/Services/Network/NetworkProtocolLogObserver.cs
- **问题**: 第一次停止协议客户端成功后,第二次启动时 OnProtocolLogsReceived 方法似乎没有被调用
- **修改**: 在 OnProtocolLogsReceived 和 ProcessLogsInternal 方法中添加了详细的跟踪日志