2026-07-02 18:13:56 +08:00
|
|
|
|
using System.Text.RegularExpressions;
|
2026-07-03 10:47:27 +08:00
|
|
|
|
using WCTDataMiner.Core.Models;
|
2026-07-02 18:13:56 +08:00
|
|
|
|
|
2026-07-03 10:47:27 +08:00
|
|
|
|
namespace WCTDataMiner.Core.Parsers;
|
2026-07-02 18:13:56 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Ploss FOD日志解析器
|
|
|
|
|
|
/// 格式: FOD-> (1) X X X (2) (3) (4) (5) (6) (7) (8) (9) (10) (11) (12) (13)
|
|
|
|
|
|
/// 示例: FOD-> 4 2 1 127 10690 12013 35377 9904 1213 -2882 750 0 0 1 500 1
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class PlossParser : IParser<PlossRecord>
|
|
|
|
|
|
{
|
|
|
|
|
|
// 格式说明有3个X(忽略字段),正则需要3个 \d+ 来匹配
|
|
|
|
|
|
private static readonly Regex PlossPattern = new(
|
|
|
|
|
|
@"^FOD->\s+(\d+)\s+\d+\s+\d+\s+\d+\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(-?\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)$",
|
|
|
|
|
|
RegexOptions.Compiled
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
public bool CanParse(string line) => PlossPattern.IsMatch(line);
|
|
|
|
|
|
|
|
|
|
|
|
public ParseResult<PlossRecord> Parse(string line, Guid scenarioId)
|
|
|
|
|
|
{
|
|
|
|
|
|
var match = PlossPattern.Match(line);
|
|
|
|
|
|
if (!match.Success)
|
|
|
|
|
|
{
|
|
|
|
|
|
return ParseResult<PlossRecord>.Failure(
|
|
|
|
|
|
"FORMAT_MISMATCH",
|
|
|
|
|
|
"Line does not match Ploss pattern"
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var record = new PlossRecord
|
|
|
|
|
|
{
|
|
|
|
|
|
ScenarioId = scenarioId,
|
|
|
|
|
|
RxType = byte.Parse(match.Groups[1].Value),
|
|
|
|
|
|
RxPower = int.Parse(match.Groups[2].Value),
|
|
|
|
|
|
TxPower = int.Parse(match.Groups[3].Value),
|
|
|
|
|
|
Vcoil = int.Parse(match.Groups[4].Value),
|
|
|
|
|
|
Vin = int.Parse(match.Groups[5].Value),
|
|
|
|
|
|
Isns = int.Parse(match.Groups[6].Value),
|
|
|
|
|
|
Ploss = int.Parse(match.Groups[7].Value),
|
|
|
|
|
|
Threshold = int.Parse(match.Groups[8].Value),
|
|
|
|
|
|
TriggerCount = int.Parse(match.Groups[9].Value),
|
|
|
|
|
|
FodResult = int.Parse(match.Groups[10].Value),
|
|
|
|
|
|
ProtocolType = byte.Parse(match.Groups[11].Value),
|
|
|
|
|
|
PwmDuty = int.Parse(match.Groups[12].Value),
|
|
|
|
|
|
CoilIndex = byte.Parse(match.Groups[13].Value)
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return ParseResult<PlossRecord>.Success(record);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
return ParseResult<PlossRecord>.Failure(
|
|
|
|
|
|
"TYPE_CONVERSION",
|
|
|
|
|
|
$"Failed to convert field: {ex.Message}"
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|