2.0协议完善加简单交管配置
This commit is contained in:
@@ -36,6 +36,18 @@ namespace StandardScene.Magnetic.Tasking
|
||||
public DateTime LastDispatchAt { get; set; } = DateTime.MinValue;
|
||||
public ulong LastActionId { get; set; }
|
||||
public DateTime LastActionSentAt { get; set; } = DateTime.MinValue;
|
||||
|
||||
/// <summary>交管窗口未齐、正在等锁;此期间不消耗移动超时预算。</summary>
|
||||
public bool WaitingForTraffic { get; set; }
|
||||
|
||||
/// <summary>停在管控停止点等待按车放行;此期间不消耗移动超时预算。</summary>
|
||||
public bool WaitingForRelease { get; set; }
|
||||
|
||||
/// <summary>本任务已对哪个路径下标发过放行报文;-1 表示尚未放行。</summary>
|
||||
public int ControlReleasedIndex { get; set; } = -1;
|
||||
|
||||
/// <summary>最近一次规划的站点链路,供断线重连判断是否仍在原路径上。</summary>
|
||||
public int[] RouteSiteIds { get; set; } = Array.Empty<int>();
|
||||
}
|
||||
|
||||
public static class Fass2TaskPersistence
|
||||
@@ -47,6 +59,7 @@ namespace StandardScene.Magnetic.Tasking
|
||||
public const string TagTaskId = "Fass2Task_TaskId";
|
||||
public const string TagFieldsSignature = "Fass2Task_FieldsSig";
|
||||
public const string TagDefaultSpeed = "Fass2Task_DefaultSpeed";
|
||||
public const string TagRouteSites = "Fass2Task_RouteSites";
|
||||
|
||||
public static void Save(TagSet tags, Fass2TaskContext context)
|
||||
{
|
||||
@@ -62,6 +75,7 @@ namespace StandardScene.Magnetic.Tasking
|
||||
SetTag(tags, TagTaskId, context.TaskId.ToString());
|
||||
SetTag(tags, TagFieldsSignature, context.FieldsSignature ?? string.Empty);
|
||||
SetTag(tags, TagDefaultSpeed, context.DefaultSpeed.ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||
SetTag(tags, TagRouteSites, FormatIntList(context.RouteSiteIds));
|
||||
}
|
||||
|
||||
public static bool TryLoad(TagSet tags, out Fass2TaskContext context)
|
||||
@@ -93,6 +107,7 @@ namespace StandardScene.Magnetic.Tasking
|
||||
System.Globalization.CultureInfo.InvariantCulture,
|
||||
out var defaultSpeed);
|
||||
|
||||
tags.TryGetValue(TagRouteSites, out var routeSitesText);
|
||||
context = new Fass2TaskContext
|
||||
{
|
||||
Phase = phase,
|
||||
@@ -101,7 +116,8 @@ namespace StandardScene.Magnetic.Tasking
|
||||
CurrentIndex = currentIndex,
|
||||
TaskId = taskId,
|
||||
FieldsSignature = fieldsSignature ?? string.Empty,
|
||||
DefaultSpeed = defaultSpeed
|
||||
DefaultSpeed = defaultSpeed,
|
||||
RouteSiteIds = ParseIntList(routeSitesText)
|
||||
};
|
||||
return true;
|
||||
}
|
||||
@@ -120,6 +136,7 @@ namespace StandardScene.Magnetic.Tasking
|
||||
RemoveTag(tags, TagTaskId);
|
||||
RemoveTag(tags, TagFieldsSignature);
|
||||
RemoveTag(tags, TagDefaultSpeed);
|
||||
RemoveTag(tags, TagRouteSites);
|
||||
}
|
||||
|
||||
private static void SetTag(TagSet tags, string key, string value)
|
||||
@@ -145,5 +162,30 @@ namespace StandardScene.Magnetic.Tasking
|
||||
value = 0;
|
||||
return tags.TryGetValue(key, out var text) && int.TryParse(text, out value);
|
||||
}
|
||||
|
||||
private static string FormatIntList(int[] values)
|
||||
{
|
||||
return values == null || values.Length == 0 ? string.Empty : string.Join(",", values);
|
||||
}
|
||||
|
||||
private static int[] ParseIntList(string text)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
return Array.Empty<int>();
|
||||
}
|
||||
|
||||
var parts = text.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var ids = new List<int>(parts.Length);
|
||||
foreach (var part in parts)
|
||||
{
|
||||
if (int.TryParse(part.Trim(), out var id) && id > 0)
|
||||
{
|
||||
ids.Add(id);
|
||||
}
|
||||
}
|
||||
|
||||
return ids.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user