using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using CoreAgent.ProtocolClient.Models; using Newtonsoft.Json; namespace CoreAgent.ProtocolClient.Context { /// /// 参数管理 /// public class CellParameterManager { public Dictionary Parameters { get; set; } = new(); public List RanIds { get; set; } = new(); public void SetRanId(string ranId) { RanIds.Add(ranId); } public void AddCell(int id, CellConfig config) { if (Parameters.ContainsKey(id)) { Parameters[id] = config; } else { Parameters.Add(id, config); } } public void SetHeaders(string[] headers, ProtocolBasicInfo basicInfo) { basicInfo.Headers = headers; var cells = new List>(); for (int i = 0; i < headers.Length; i++) { var header = headers[i]; Match? info; info = Regex.Match(header, @"lte(\w+) version ([\d-]+)", RegexOptions.IgnoreCase); if (info.Success) { basicInfo.Model = info.Groups[1].Value.ToUpper(); basicInfo.Version = info.Groups[2].Value; } else if (Regex.IsMatch(header, @"Licensed to")) { basicInfo.License = header; } else if ((info = Regex.Match(header, @"Metadata:(.+)$")).Success) { var metadata = JsonConvert.DeserializeObject>(info.Groups[1].Value); } else if ((info = Regex.Match(header, @"(global_(ran_node|enb)_id)=([\d\.]+)")).Success) { this.SetRanId(info.Groups[3].Value); } else if ((info = Regex.Match(header, @"Cell 0x(\d+): (.*)")).Success) { var cell = new Dictionary { ["cell_id"] = int.Parse(info.Groups[1].Value, System.Globalization.NumberStyles.HexNumber), ["sib1Decoded"] = true, ["sib2Decoded"] = true }; var list = info.Groups[2].Value.Split(' '); foreach (var param in list) { var parts = param.Split('='); if (parts.Length == 2) { cell[parts[0]] = HeaderCellParam(parts[0], parts[1]); } } cells.Add(cell); } else if (cells.Count > 0) { info = Regex.Match(header, @"([UD]L): (.*)"); if (info.Success) { var cell = cells[cells.Count - 1]; var dir = info.Groups[1].Value; var list = info.Groups[2].Value.Split(' '); foreach (var param in list) { var parts = param.Split('='); if (parts.Length == 2) { cell[parts[0]] = HeaderCellParam(parts[0], parts[1]); } } } } } } private object HeaderCellParam(string param, string value) { switch (param) { case "br_dl_sf_bitmap": case "nb_dl_sf_bitmap": case "label": return value; default: if (int.TryParse(value, out var intValue)) return intValue; return value; } } } }