修复在线导致的一个 Bug

This commit is contained in:
2025-12-26 16:58:12 +08:00
parent 93782bcdf1
commit 83ad6221a4
6 changed files with 190 additions and 10 deletions

View File

@@ -133,7 +133,7 @@ public class CameraCoordinator
#region --- (Reconciliation Logic) ---
/// <summary>
/// 相机状态调和(核心自愈逻辑)
/// 相机状态调和(核心自愈逻辑 - 修复版
/// 功能:校验相机物理连接、流状态,执行启动/停止/复位操作,确保状态一致性
/// </summary>
/// <param name="cam">待调和的相机设备</param>
@@ -148,12 +148,16 @@ public class CameraCoordinator
bool isFlowing = cam.IsOnline && secondsSinceLastFrame < StreamAliveThresholdSeconds;
// 3. 判定物理连接是否正常:流正常则直接判定在线;否则执行 Ping+TCP 探测
// (注意:如果哨兵已经更新了 Ping 状态ProbeHardwareAsync 内部也可以优化为直接读取,
// 但在 Coordinator 里保留主动探测作为双重保险也是合理的)
bool isPhysicalOk = isFlowing ? true : await ProbeHardwareAsync(cam).ConfigureAwait(false);
// 4. 状态调和决策:根据物理状态与设备状态的差异执行对应操作
// 场景 A: 物理在线 + 设备离线 + 用户要求运行 -> 执行启动
if (isPhysicalOk && !cam.IsOnline && cam.IsRunning)
{
// 物理在线 + 设备离线 + 需运行 → 执行启动(加登录锁防止冲突
// 加登录锁防止冲突
bool lockTaken = false;
try
{
@@ -173,14 +177,15 @@ public class CameraCoordinator
}
}
}
// 场景 B: 物理离线 + 设备在线 -> 执行强制停止
else if (!isPhysicalOk && cam.IsOnline)
{
// 物理离线 + 设备在线 → 执行停止
await cam.StopAsync().ConfigureAwait(false);
}
else if (isPhysicalOk && cam.IsOnline && !isFlowing)
// 场景 C: 物理在线 + 设备在线 + 流中断 + 【用户要求运行】 -> 判定为僵死
// 【关键修复】:增加了 && cam.IsRunning 判定,防止待机状态下被误复位
else if (isPhysicalOk && cam.IsOnline && !isFlowing && cam.IsRunning) // [cite: 504]
{
// 物理在线 + 设备在线 + 流中断 → 判定为僵死,执行复位
Console.WriteLine($"[自愈] 设备 {cam.Id} 僵死({secondsSinceLastFrame:F1}秒无帧),复位中...");
await cam.StopAsync().ConfigureAwait(false);
}