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.
109 lines
4.2 KiB
109 lines
4.2 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
using CoreAgent.ProtocolClient.Context;
|
|
using CoreAgent.ProtocolClient.Models;
|
|
using Microsoft.Extensions.Logging;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace CoreAgent.ProtocolClient.ProtocolEngineCore
|
|
{
|
|
public class LogDetailProcessor
|
|
{
|
|
private readonly ProtocolClientContext _context;
|
|
private readonly ILogger logger;
|
|
|
|
public LogDetailProcessor(ProtocolClientContext context, ILogger logger)
|
|
{
|
|
_context = context;
|
|
this.logger = logger;
|
|
}
|
|
|
|
public List<SourceProtocolLogDetail> ConvertLogsToDetails(JToken logs)
|
|
{
|
|
return logs.Type switch
|
|
{
|
|
JTokenType.Array => logs.ToObject<List<SourceProtocolLogDetail>>() ?? new List<SourceProtocolLogDetail>(),
|
|
JTokenType.Object => new List<SourceProtocolLogDetail> { logs.ToObject<SourceProtocolLogDetail>()! },
|
|
_ => new List<SourceProtocolLogDetail>()
|
|
};
|
|
}
|
|
|
|
public List<BuildProtocolLog> ConvertDetailsToProtocolLogs(List<SourceProtocolLogDetail> details)
|
|
{
|
|
var logList = new List<BuildProtocolLog>();
|
|
foreach (var logItem in details)
|
|
{
|
|
var item = logItem.DeepClone();
|
|
var protocolLog = new BuildProtocolLog
|
|
{
|
|
Timestamp = item.Timestamp,
|
|
Layer = item.Layer,
|
|
UeId = item.UeId,
|
|
Cell = item.Cell,
|
|
Direction = ConvertDirection(item.Dir),
|
|
Message = (item.Data != null && item.Data.Count > 0) ? item.Data[0] : string.Empty,
|
|
Data = (item.Data != null && item.Data.Count > 1) ? item.Data.Skip(1).ToList() : new List<string>(),
|
|
Rnti = item.Rnti,
|
|
Phy = new PhyLayerFields
|
|
{
|
|
Frame = item.Frame,
|
|
Slot = item.Slot,
|
|
Channel = item.Channel,
|
|
},
|
|
};
|
|
_context.LogContext.UpdateLogTimestampAndAssignId(ref protocolLog);
|
|
// 处理PHY层的信号记录
|
|
if (logItem.Layer == "PHY" && logItem.Data is List<string> data)
|
|
{
|
|
var signalRecord = new Dictionary<string, object>();
|
|
for (int j = data.Count - 1; j >= 0; j--)
|
|
{
|
|
var line = data[j];
|
|
var match = Regex.Match(line, @"Link:\s([\w\d]+)@(\d+)");
|
|
if (match.Success)
|
|
{
|
|
var linkName = match.Groups[1].Value;
|
|
var offset = uint.Parse(match.Groups[2].Value);
|
|
signalRecord[linkName] = new { offset = offset };
|
|
data.RemoveAt(j);
|
|
}
|
|
}
|
|
if (signalRecord.Count > 0)
|
|
{
|
|
protocolLog.DataInfo.SignalRecord = signalRecord;
|
|
_context.FeatureFlags.HasSignalRecord = true;
|
|
}
|
|
}
|
|
logList.Add(protocolLog);
|
|
}
|
|
return logList;
|
|
}
|
|
|
|
// 字符串方向转 LayerDir 枚举 int
|
|
private int ConvertDirection(string dir)
|
|
{
|
|
if (string.IsNullOrEmpty(dir)) return (int)Enums.LayerDir.None;
|
|
switch (dir.Trim().ToLower())
|
|
{
|
|
case "-":
|
|
case "none":
|
|
return (int)Enums.LayerDir.None;
|
|
case "ul":
|
|
return (int)Enums.LayerDir.UL;
|
|
case "dl":
|
|
return (int)Enums.LayerDir.DL;
|
|
case "to":
|
|
return (int)Enums.LayerDir.TO;
|
|
case "from":
|
|
return (int)Enums.LayerDir.FROM;
|
|
default:
|
|
return (int)Enums.LayerDir.None;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|