Files
WCTDataMiner/tests/Gpulse.WCT.DataAnalyzer.Tests/TestFixtures.cs
2026-08-17 09:24:57 +08:00

81 lines
3.0 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>
public sealed record PlossTwoLineRow(
int PowLoss = 2200,
int DeltaP = 2500,
int Field1 = 1,
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}");
lines.Add(
$"FOD-> {r.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>
public static string WriteLegacyPlossLog(string dir, string fileName, params (int Ploss, int Threshold, int Fod)[] rows)
{
var path = Path.Combine(dir, fileName);
var lines = rows
.Select(r => $"FOD-> 1 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;
}
}