You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
4.1 KiB

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
{
/// <summary>
/// 参数管理
/// </summary>
public class CellParameterManager
{
public Dictionary<int, CellConfig> Parameters { get; set; } = new();
public List<string> 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<Dictionary<string, object>>();
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<Dictionary<string, object>>(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<string, object>
{
["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;
}
}
}
}