2.0协议完善加简单交管配置

This commit is contained in:
ykkokluo
2026-08-14 09:49:23 +08:00
parent a28bc68e23
commit 1e780c2b65
51 changed files with 4013 additions and 393 deletions
@@ -7,15 +7,15 @@ namespace StandardScene.Magnetic.Tasking
{
/// <summary>
/// 比对期望节点与上报节点,判定到站与动作是否完成(对齐 backend <c>CarResponseService</c>)。
/// 默认只闭环机构类动作;轨迹字段(Speed/Orientation 等)需显式开启。
/// </summary>
public static class Fass2ActionResolver
{
private static readonly (string Name, Func<Fass2NodeMessage, byte> Get, Action<Fass2NodeMessage, byte> Set)[] ActionFields =
/// <summary>是否在停车站比对 Speed/Orientation/Direction/Byroad 等轨迹字段。</summary>
public static bool VerifyTrajectoryFields { get; set; }
private static readonly (string Name, Func<Fass2NodeMessage, byte> Get, Action<Fass2NodeMessage, byte> Set)[] MechanismFields =
{
("StartStop", n => n.StartStop, (n, v) => n.StartStop = v),
("Direction", n => n.Direction, (n, v) => n.Direction = v),
("Orientation", n => n.Orientation, (n, v) => n.Orientation = v),
("Byroad", n => n.Byroad, (n, v) => n.Byroad = v),
("Obstacle", n => n.Obstacle, (n, v) => n.Obstacle = v),
("Audio", n => n.Audio, (n, v) => n.Audio = v),
("Light", n => n.Light, (n, v) => n.Light = v),
@@ -28,6 +28,13 @@ namespace StandardScene.Magnetic.Tasking
("Shutdown", n => n.Shutdown, (n, v) => n.Shutdown = v)
};
private static readonly (string Name, Func<Fass2NodeMessage, byte> Get, Action<Fass2NodeMessage, byte> Set)[] TrajectoryFields =
{
("Direction", n => n.Direction, (n, v) => n.Direction = v),
("Orientation", n => n.Orientation, (n, v) => n.Orientation = v),
("Byroad", n => n.Byroad, (n, v) => n.Byroad = v)
};
public static bool IsAtNode(Fass2StateReport report, ushort targetNode)
{
return report?.Node != null && report.Node.Node == targetNode;
@@ -35,7 +42,7 @@ namespace StandardScene.Magnetic.Tasking
public static bool IsVehicleMoving(byte vehicleState)
{
return vehicleState == 1;
return vehicleState is 1 or 5;
}
public static bool RequiresActionWait(Fass2NodeMessage expected)
@@ -45,12 +52,28 @@ namespace StandardScene.Magnetic.Tasking
return false;
}
if (expected.StartStop is Fass2TaskBuilder.StartStopStop or Fass2TaskBuilder.StartStopPrecision)
if (expected.StartStop is Fass2TaskBuilder.StartStopStop
or Fass2TaskBuilder.StartStopPrecision
or Fass2TaskBuilder.StartStopControlStop
or Fass2TaskBuilder.StartStopControlStart)
{
return true;
}
foreach (var field in ActionFields)
foreach (var field in MechanismFields)
{
if (field.Get(expected) != 0)
{
return true;
}
}
if (!VerifyTrajectoryFields)
{
return false;
}
foreach (var field in TrajectoryFields)
{
if (field.Get(expected) != 0)
{
@@ -83,12 +106,16 @@ namespace StandardScene.Magnetic.Tasking
return true;
}
// 过站(StartStop=1) 只要求到点且非运行态,不要求 Orientation 等轨迹字段到位。
if (expected.StartStop == Fass2TaskBuilder.StartStopPass)
{
return true;
}
if (expected.StartStop == Fass2TaskBuilder.StartStopControlStop)
{
return false;
}
return ListPendingFields(expected, actual).Count == 0;
}
@@ -105,18 +132,25 @@ namespace StandardScene.Magnetic.Tasking
pending.Add("StartStop");
}
if (expected.Speed != 0 && actual.Speed != expected.Speed)
if (VerifyTrajectoryFields)
{
pending.Add("Speed");
}
foreach (var field in ActionFields)
{
if (field.Name == "StartStop")
if (expected.Speed != 0 && actual.Speed != expected.Speed)
{
continue;
pending.Add("Speed");
}
foreach (var field in TrajectoryFields)
{
var expectedValue = field.Get(expected);
if (expectedValue != 0 && field.Get(actual) != expectedValue)
{
pending.Add(field.Name);
}
}
}
foreach (var field in MechanismFields)
{
var expectedValue = field.Get(expected);
if (expectedValue != 0 && field.Get(actual) != expectedValue)
{
@@ -143,19 +177,27 @@ namespace StandardScene.Magnetic.Tasking
hasPatch = true;
}
if (expected.Speed != 0 && (actual == null || actual.Speed != expected.Speed))
if (VerifyTrajectoryFields)
{
patch.Speed = expected.Speed;
hasPatch = true;
}
foreach (var field in ActionFields)
{
if (field.Name == "StartStop")
if (expected.Speed != 0 && (actual == null || actual.Speed != expected.Speed))
{
continue;
patch.Speed = expected.Speed;
hasPatch = true;
}
foreach (var field in TrajectoryFields)
{
var expectedValue = field.Get(expected);
if (expectedValue != 0 && (actual == null || field.Get(actual) != expectedValue))
{
field.Set(patch, expectedValue);
hasPatch = true;
}
}
}
foreach (var field in MechanismFields)
{
var expectedValue = field.Get(expected);
if (expectedValue != 0 && (actual == null || field.Get(actual) != expectedValue))
{