Skip to content

Commit 541056e

Browse files
authored
Merge pull request #788 from Roeterdink/ImproveDebugOutputsTTTrain
Improve Debug Outputs for TTTrain.cs
2 parents ea394e5 + 94a73d5 commit 541056e

File tree

1 file changed

+73
-11
lines changed
  • Source/Orts.Simulation/Simulation/Timetables

1 file changed

+73
-11
lines changed

Source/Orts.Simulation/Simulation/Timetables/TTTrain.cs

Lines changed: 73 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
// #define DEBUG_EXTRAINFO
2828
// #define DEBUG_TRACEINFO
2929
// #define DEBUG_TTANALYSIS
30+
// #define DEBUG_DELAYS
3031
// DEBUG flag for debug prints
3132

3233
using System;
@@ -70,6 +71,8 @@ public class TTTrain : AITrain
7071
// required direction on leaving pool (if applicable)
7172
public string ForcedConsistName = String.Empty; // forced consist name for extraction from pool
7273

74+
public string ttanalysisreport = String.Empty; // string holding last analysis report, to avoid continouos output of same string
75+
7376
// Timetable Commands info
7477
public List<WaitInfo> WaitList = null; //used when in timetable mode for wait instructions
7578
public Dictionary<int, List<WaitInfo>> WaitAnyList = null; //used when in timetable mode for waitany instructions
@@ -4112,6 +4115,11 @@ public override void UpdateStationState(float elapsedClockSeconds, int presentTi
41124115
}
41134116
#endif
41144117

4118+
#if DEBUG_DELAYS
4119+
if (Delay.HasValue && Delay.Value.TotalMinutes > 5)
4120+
Trace.TraceInformation("{0} at {1} : + {2}", Name, thisStation.PlatformItem.Name, Delay.Value.ToString());
4121+
#endif
4122+
41154123
if (CheckTrain)
41164124
{
41174125
DateTime baseDTdCT = new DateTime();
@@ -8230,6 +8238,13 @@ public void FinalizeTimetableCommands()
82308238
#if DEBUG_TRACEINFO
82318239
Trace.TraceInformation("Train : " + Name);
82328240
Trace.TraceInformation("WAIT : Search for : {0} - found {1}", reqWait.referencedTrainName, otherTrain == null ? -1 : otherTrain.Number);
8241+
#endif
8242+
#if DEBUG_DELAYS
8243+
if (otherTrain == null)
8244+
{
8245+
Trace.TraceInformation("Train : " + Name);
8246+
Trace.TraceInformation("WAIT : Search for : {0} - not found", reqWait.referencedTrainName);
8247+
}
82338248
#endif
82348249
if (otherTrain != null)
82358250
{
@@ -8244,6 +8259,13 @@ public void FinalizeTimetableCommands()
82448259
#if DEBUG_TRACEINFO
82458260
Trace.TraceInformation("Train : " + Name);
82468261
Trace.TraceInformation("FOLLOW : Search for : {0} - found {1}", reqWait.referencedTrainName, otherTrain == null ? -1 : otherTrain.Number);
8262+
#endif
8263+
#if DEBUG_DELAYS
8264+
if (otherTrain == null)
8265+
{
8266+
Trace.TraceInformation("Train : " + Name);
8267+
Trace.TraceInformation("FOLLOW : Search for : {0} - not found", reqWait.referencedTrainName);
8268+
}
82478269
#endif
82488270
if (otherTrain != null)
82498271
{
@@ -8259,6 +8281,14 @@ public void FinalizeTimetableCommands()
82598281
Trace.TraceInformation("Train : " + Name);
82608282
Trace.TraceInformation("CONNECT : Search for : {0} - found {1}", reqWait.referencedTrainName, otherTrain == null ? -1 : otherTrain.Number);
82618283
#endif
8284+
#if DEBUG_DELAYS
8285+
if (otherTrain == null)
8286+
{
8287+
Trace.TraceInformation("Train : " + Name);
8288+
Trace.TraceInformation("CONNECT : Search for : {0} - not found", reqWait.referencedTrainName);
8289+
}
8290+
#endif
8291+
82628292
if (otherTrain != null)
82638293
{
82648294
ProcessConnectRequest(reqWait, otherTrain, ref newWaitItems);
@@ -9671,6 +9701,7 @@ public bool CheckEndOfRoutePositionTT()
96719701
MovementState = AI_MOVEMENT_STATE.TURNTABLE;
96729702
if (CheckTrain)
96739703
{
9704+
File.AppendAllText(@"C:\temp\checktrain.txt", "TURNTABLE : Pool : " + thisTurntablePool.PoolName + " : Table state set to " + ActiveTurntable.MovingTableState.ToString() + "\n");
96749705
File.AppendAllText(@"C:\temp\checktrain.txt", "Moving table access ; Movement State : " + MovementState + "\n");
96759706
}
96769707
return (endOfRoute);
@@ -11573,6 +11604,11 @@ public int GetUnitsToDetach(DetachInfo.DetachUnitsInfo detachUnits, int numberOf
1157311604

1157411605
default:
1157511606
iunits = numberOfUnits;
11607+
if (iunits > Cars.Count - 1)
11608+
{
11609+
Trace.TraceInformation("Train {0} : no. of units to detach ({1}) : value too large, only {2} units on train\n", Name, iunits, Cars.Count);
11610+
iunits = Cars.Count - 1;
11611+
}
1157611612
frontpos = detachUnits == DetachInfo.DetachUnitsInfo.unitsAtFront;
1157711613
break;
1157811614
}
@@ -12727,12 +12763,13 @@ public void TTAnalysisUpdateStationState1(int presentTime, StationStop thisStati
1272712763
{
1272812764

1272912765
DateTime baseDTA = new DateTime();
12766+
DateTime presentDTA = baseDTA.AddSeconds(AI.clockTime);
1273012767
DateTime arrTimeA = baseDTA.AddSeconds(presentTime);
1273112768
DateTime depTimeA = baseDTA.AddSeconds(thisStation.ActualDepart);
1273212769

1273312770
var sob = new StringBuilder();
1273412771
sob.AppendFormat("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};{12}",
12735-
Number, AI.clockTime, Name, Delay, thisStation.PlatformItem.Name, thisStation.arrivalDT.ToString("HH:mm:ss"), thisStation.departureDT.ToString("HH:mm:ss"),
12772+
Number, presentDTA.ToString("HH:mm:ss"), Name, Delay, thisStation.PlatformItem.Name, thisStation.arrivalDT.ToString("HH:mm:ss"), thisStation.departureDT.ToString("HH:mm:ss"),
1273612773
arrTimeA.ToString("HH:mm:ss"), depTimeA.ToString("HH:mm:ss"), "", "", "", "");
1273712774
File.AppendAllText(@"C:\temp\TTAnalysis.csv", sob.ToString() + "\n");
1273812775
}
@@ -12789,9 +12826,16 @@ public void TTAnalysisUpdateStationState2()
1278912826
DateTime baseDT = new DateTime();
1279012827
DateTime stopTime = baseDT.AddSeconds(AI.clockTime);
1279112828

12792-
var sob = new StringBuilder();
12793-
sob.AppendFormat("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};{12}", Number, AI.clockTime, Name, Delay, "", "", "", "", "", "", stopTime.ToString("HH:mm:ss"), signalstring.ToString(), waitforstring.ToString());
12794-
File.AppendAllText(@"C:\temp\TTAnalysis.csv", sob.ToString() + "\n");
12829+
// output string only if different from last output
12830+
12831+
if (waitforstring.ToString() != ttanalysisreport)
12832+
{
12833+
ttanalysisreport = waitforstring.ToString();
12834+
12835+
var sob = new StringBuilder();
12836+
sob.AppendFormat("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};{12}", Number, stopTime.ToString("HH:mm:ss"), Name, Delay, "", "", "", "", "", "", stopTime.ToString("HH:mm:ss"), signalstring.ToString(), waitforstring.ToString());
12837+
File.AppendAllText(@"C:\temp\TTAnalysis.csv", sob.ToString() + "\n");
12838+
}
1279512839
}
1279612840

1279712841
public void TTAnalysisUpdateBrakingState1()
@@ -12848,9 +12892,14 @@ public void TTAnalysisUpdateBrakingState1()
1284812892
DateTime baseDT = new DateTime();
1284912893
DateTime stopTime = baseDT.AddSeconds(AI.clockTime);
1285012894

12851-
var sob = new StringBuilder();
12852-
sob.AppendFormat("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};{12}", Number, AI.clockTime, Name, Delay, "", "", "", "", "", "", stopTime.ToString("HH:mm:ss"), signalstring.ToString(), waitforstring.ToString());
12853-
File.AppendAllText(@"C:\temp\TTAnalysis.csv", sob.ToString() + "\n");
12895+
if (waitforstring.ToString() != ttanalysisreport)
12896+
{
12897+
ttanalysisreport = waitforstring.ToString();
12898+
12899+
var sob = new StringBuilder();
12900+
sob.AppendFormat("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};{12}", Number, stopTime.ToString("HH:mm:ss"), Name, Delay, "", "", "", "", "", "", stopTime.ToString("HH:mm:ss"), signalstring.ToString(), waitforstring.ToString());
12901+
File.AppendAllText(@"C:\temp\TTAnalysis.csv", sob.ToString() + "\n");
12902+
}
1285412903
}
1285512904
}
1285612905

@@ -12914,9 +12963,14 @@ public void TTAnalysisUpdateBrakingState2()
1291412963
DateTime baseDT = new DateTime();
1291512964
DateTime stopTime = baseDT.AddSeconds(AI.clockTime);
1291612965

12917-
var sob = new StringBuilder();
12918-
sob.AppendFormat("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};{12}", Number, AI.clockTime, Name, Delay, "", "", "", "", "", "", stopTime.ToString("HH:mm:ss"), signalstring.ToString(), waitforstring.ToString());
12919-
File.AppendAllText(@"C:\temp\TTAnalysis.csv", sob.ToString() + "\n");
12966+
if (waitforstring.ToString() != ttanalysisreport)
12967+
{
12968+
ttanalysisreport = waitforstring.ToString();
12969+
12970+
var sob = new StringBuilder();
12971+
sob.AppendFormat("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};{12}", Number, stopTime.ToString("HH:mm:ss"), Name, Delay, "", "", "", "", "", "", stopTime.ToString("HH:mm:ss"), signalstring.ToString(), waitforstring.ToString());
12972+
File.AppendAllText(@"C:\temp\TTAnalysis.csv", sob.ToString() + "\n");
12973+
}
1292012974
}
1292112975

1292212976
public void TTAnalysisStartMoving(String info)
@@ -12926,8 +12980,9 @@ public void TTAnalysisStartMoving(String info)
1292612980

1292712981
var sob = new StringBuilder();
1292812982
sob.AppendFormat("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};{12}",
12929-
Number, AI.clockTime, Name, Delay, "", "", "", "", "", moveTimeA.ToString("HH:mm:ss"), "", "", info);
12983+
Number, moveTimeA.ToString("HH:mm:ss"), Name, Delay, "", "", "", "", "", moveTimeA.ToString("HH:mm:ss"), "", "", info);
1293012984
File.AppendAllText(@"C:\temp\TTAnalysis.csv", sob.ToString() + "\n");
12985+
ttanalysisreport = String.Empty;
1293112986
}
1293212987
}
1293312988

@@ -13378,6 +13433,13 @@ public DetachInfo(TTTrain thisTrain, TTTrainCommands commandInfo, bool atActivat
1337813433
bool portionDefined = false;
1337913434
bool formedTrainDefined = false;
1338013435

13436+
if (commandInfo.CommandQualifiers == null || commandInfo.CommandQualifiers.Count < 1)
13437+
{
13438+
Trace.TraceInformation("Train {0} : missing detach command qualifiers", thisTrain.Name);
13439+
Valid = false;
13440+
return;
13441+
}
13442+
1338113443
foreach (TTTrainCommands.TTTrainComQualifiers Qualifier in commandInfo.CommandQualifiers)
1338213444
{
1338313445
switch (Qualifier.QualifierName.Trim().ToLower())

0 commit comments

Comments
 (0)