Files
WCTDataMiner/tests/Gpulse.WCT.DataAnalyzer.Tests/TestFixtures.cs
Scottxjw 6d56a4a01b feat(parser): 支持 Ploss Field1 十六进制解析
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-17 10:47:33 +08:00

94 lines
3.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
namespace Gpulse.WCT.DataAnalyzer.Tests;
/// <summary>
/// 构造 CLI 测试用的日志 fixture 文件。文件名符合 FileNameParser 约定的
/// `TX面板-TX硬件-TX软件-RX类型-测试目的-日期-序号` 格式。
/// </summary>
public static class TestFixtures
{
public const string PlossFileName = "singleMold-v1.0-hex2_1-iPhone15-ploss_test-20260710-1.log";
public const string QfodFileName = "singleMold-v1.0-hex2_1-iPhone15-qfod_test-20260710-1.log";
/// <summary>
/// 两行 Ploss 记录header + FOD 16 字段)。
/// 默认值让恒等式成立Field5 - Field4 - PowLoss - ploss == DeltaP且余量 > 2000。
/// </summary>
/// <param name="Field1AsHex">
/// 当不为 null 时,覆写 Field1按十六进制字面量写入日志如 "0C" = 十进制 12
/// 用于验证解析器对 Field1 十六进制格式的支持。
/// </param>
public sealed record PlossTwoLineRow(
int PowLoss = 2200,
int DeltaP = 2500,
int Field1 = 1,
string? Field1AsHex = null,
int Field2 = 0,
int Field3 = 0,
int Field4 = 800, // RX power
int Field5 = 6000, // TX power
int Field6 = 0,
int Field7 = 0,
int Field8 = 0,
int Field9 = 500, // ploss
int Field10 = 3000, // threshold
int Field11 = 0,
int Field12 = 0, // FOD 标志
int Field13 = 0,
int Field14 = 0,
int Field15 = 0,
int Field16 = 0);
/// <summary>写两行格式 Ploss 日志文件。</summary>
public static string WritePlossLog(string dir, string fileName, params PlossTwoLineRow[] rows)
{
var path = Path.Combine(dir, fileName);
var lines = new List<string>(rows.Length * 2);
foreach (var r in rows)
{
lines.Add($"pow_loss = {r.PowLoss}, delta_p = {r.DeltaP}");
var field1 = r.Field1AsHex ?? r.Field1.ToString();
lines.Add(
$"FOD-> {field1} {r.Field2} {r.Field3} {r.Field4} {r.Field5} {r.Field6} " +
$"{r.Field7} {r.Field8} {r.Field9} {r.Field10} {r.Field11} {r.Field12} " +
$"{r.Field13} {r.Field14} {r.Field15} {r.Field16}");
}
File.WriteAllLines(path, lines);
return path;
}
/// <summary>写旧单行格式 Ploss 日志14 字段),仅指定 ploss/threshold/FOD 三个关键字段。</summary>
/// <param name="rows">每行 FOD 记录关键字段ploss/threshold/FOD</param>
/// <param name="field1Hex">若非 null 则覆盖首字段为十六进制字面量(否则固定为 "1")。</param>
public static string WriteLegacyPlossLog(
string dir,
string fileName,
(int Ploss, int Threshold, int Fod)[] rows,
string? field1Hex = null)
{
var path = Path.Combine(dir, fileName);
var head = field1Hex ?? "1";
var lines = rows
.Select(r => $"FOD-> {head} 0 0 0 0 0 0 0 {r.Ploss} {r.Threshold} 0 {r.Fod} 0 0")
.ToArray();
File.WriteAllLines(path, lines);
return path;
}
/// <summary>写 Qfod 日志文件,每行 DeltaQ 一个。</summary>
public static string WriteQfodLog(string dir, string fileName, params int[] deltaQs)
{
var path = Path.Combine(dir, fileName);
var lines = deltaQs
.Select((d, i) =>
{
var charger = i % 2;
var coil = i % 3;
var currentQ = 40 + d;
return $"{charger}#:Q {coil}->{d} {currentQ}.0 20.0 0 0";
})
.ToArray();
File.WriteAllLines(path, lines);
return path;
}
}