提交代码

This commit is contained in:
ldh
2026-11-19 16:42:26 +08:00
parent dd6edce089
commit 4929d5dcd5
209 changed files with 158631 additions and 1311 deletions
+193
View File
@@ -0,0 +1,193 @@
using LiteDB;
namespace HardwareControl.Core.Scanning
{
/// <summary>一次扫描的整体状态。</summary>
public enum ScanStatus
{
Running = 0,
Completed = 1,
Aborted = 2,
Failed = 3,
}
/// <summary>扫描流程当前所处阶段。</summary>
public enum ScanPhase
{
Idle = 0,
Homing = 1,
Moving = 2,
Focusing = 3,
Acquiring = 4,
Returning = 5,
Analyzing = 6,
Writing = 7,
Completed = 8,
Aborted = 9,
Failed = 10,
}
/// <summary>实时进度快照,通过 SignalR 推送给前端。</summary>
public sealed record ScanProgress(
string ScanId,
ScanPhase Phase,
int PointIndex,
int TotalPoints,
int CompletedPoints,
int Percent,
string Message,
int StageX,
int StageY,
bool StageMoving,
DateTimeOffset UpdatedAt);
/// <summary>启动扫描的返回结果。</summary>
public sealed record ScanStartResult(string ScanId, int TotalPoints);
/// <summary>位移台实时位置。</summary>
public sealed record StagePosition(
int X,
int Y,
int Z,
bool Moving,
DateTimeOffset UpdatedAt);
/// <summary>扫描结束事件。</summary>
public sealed record ScanRunSummary(string ScanId, ScanStatus Status, string? Error);
/// <summary>单个采样点采集完成事件(携带拼接光谱,用于实时绘图)。</summary>
public sealed record ScanPointAcquired(
string ScanId,
int PointIndex,
int TotalPoints,
float[] Wavelengths,
float[] Spectrum,
IReadOnlyList<ScanSegmentRecord> Segments,
DateTimeOffset AcquiredAt);
/// <summary>扫描运行的持久化记录。</summary>
public sealed class ScanRunRecord
{
[BsonId]
public string ScanId { get; set; } = string.Empty;
public DateTimeOffset StartedAt { get; set; }
public DateTimeOffset? FinishedAt { get; set; }
public ScanStatus Status { get; set; }
public string? Error { get; set; }
public int TotalPoints { get; set; }
public int CompletedPoints { get; set; }
/// <summary>传给光谱仪的曝光时间(微秒)。</summary>
public int ExposureUs { get; set; }
public int Averaging { get; set; }
public int DelayUs { get; set; }
public int WaitTimeoutMs { get; set; }
public int MoveSpeed { get; set; }
public int MoveAccel { get; set; }
/// <summary>比例尺(像素/毫米)。</summary>
public double CameraScale { get; set; }
public double CameraOffsetX { get; set; }
public double CameraOffsetY { get; set; }
public int ImageWidth { get; set; }
public int ImageHeight { get; set; }
/// <summary>带采样点标注的靶面图。</summary>
public byte[]? ImageData { get; set; }
public string? ImageMimeType { get; set; }
}
/// <summary>单个采样点的持久化记录。</summary>
public sealed class ScanPointRecord
{
[BsonId]
public int Id { get; set; }
public string ScanId { get; set; } = string.Empty;
/// <summary>从 0 开始的点序号。</summary>
public int Index { get; set; }
public int PixelX { get; set; }
public int PixelY { get; set; }
public int StageX { get; set; }
public int StageY { get; set; }
public bool Succeeded { get; set; }
public string? Error { get; set; }
public float[] Wavelengths { get; set; } = Array.Empty<float>();
public float[] Spectrum { get; set; } = Array.Empty<float>();
public ScanSegmentRecord[] Segments { get; set; } = Array.Empty<ScanSegmentRecord>();
public List<ScanElementRecord> Elements { get; set; } = new();
public double Temperature { get; set; }
public double ElectronDensity { get; set; }
public DateTimeOffset AcquiredAt { get; set; }
}
/// <summary>拼接光谱的段信息。</summary>
public sealed class ScanSegmentRecord
{
public int DeviceIndex { get; set; }
public string SerialNumber { get; set; } = string.Empty;
public double WavelengthStart { get; set; }
public double WavelengthEnd { get; set; }
public int PointCount { get; set; }
}
/// <summary>单个元素的定性/定量结果。</summary>
public sealed class ScanElementRecord
{
public string Symbol { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
/// <summary>高 / 中 / 低。</summary>
public string IntensityLevel { get; set; } = string.Empty;
public double Abundance { get; set; }
public double RawAbundance { get; set; }
/// <summary>检出 / 痕量。</summary>
public string Verdict { get; set; } = string.Empty;
/// <summary>该元素匹配谱线中的最大强度。</summary>
public double MaxIntensity { get; set; }
/// <summary>最强匹配谱线在原始光谱中的峰位(nm)。</summary>
public double MatchedWavelength { get; set; }
public int MatchedLines { get; set; }
}
}