Skip to content

Commit b5d21b4

Browse files
committed
Send TCS pantograph orders via power supply events
1 parent 46bf8a6 commit b5d21b4

File tree

7 files changed

+85
-17
lines changed

7 files changed

+85
-17
lines changed

Source/Orts.Simulation/Common/Scripting/PowerSupply/LocomotivePowerSupply.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,46 @@ public virtual void HandleEventFromOtherLocomotive(int locoIndex, PowerSupplyEve
508508

509509
}
510510

511+
/// <summary>
512+
/// Called when the TCS wants to transmit an event to power supply
513+
/// </summary>
514+
/// <param name="evt"></param>
515+
public virtual void HandleEventFromTcs(PowerSupplyEvent evt)
516+
{
517+
switch (evt)
518+
{
519+
case PowerSupplyEvent.LowerPantograph:
520+
case PowerSupplyEvent.RaisePantograph:
521+
SignalEventToPantographs(evt);
522+
SignalEventToOtherTrainVehicles(evt);
523+
break;
524+
}
525+
}
526+
527+
/// <summary>
528+
/// Called when the TCS wants to transmit an event to power supply
529+
/// </summary>
530+
/// <param name="evt"></param>
531+
/// <param name="id"></param>
532+
public virtual void HandleEventFromTcs(PowerSupplyEvent evt, int id)
533+
{
534+
switch (evt)
535+
{
536+
case PowerSupplyEvent.LowerPantograph:
537+
case PowerSupplyEvent.RaisePantograph:
538+
SignalEventToPantograph(evt, id);
539+
SignalEventToOtherTrainVehiclesWithId(evt, id);
540+
break;
541+
}
542+
}
543+
544+
/// <summary>
545+
/// Called when the TCS wants to transmit an event and/or a message to power supply
546+
/// </summary>
547+
/// <param name="evt"></param>
548+
/// <param name="message"></param>
549+
public virtual void HandleEventFromTcs(PowerSupplyEvent evt, string message) {}
550+
511551
protected bool GetBoolParameter(string sectionName, string keyName, bool defaultValue) => LoadParameter(sectionName, keyName, defaultValue);
512552
protected int GetIntParameter(string sectionName, string keyName, int defaultValue) => LoadParameter(sectionName, keyName, defaultValue);
513553
protected float GetFloatParameter(string sectionName, string keyName, float defaultValue) => LoadParameter(sectionName, keyName, defaultValue);

Source/Orts.Simulation/Common/Scripting/PowerSupply/PowerSupply.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,6 @@ public virtual void HandleEvent(PowerSupplyEvent evt, int id)
113113
SignalEventToPantograph(evt, id);
114114
}
115115

116-
/// <summary>
117-
/// Called when the TCS wants to transmit an event and/or a message to power supply
118-
/// </summary>
119-
/// <param name="evt"></param>
120-
/// <param name="message"></param>
121-
public virtual void HandleEventFromTcs(PowerSupplyEvent evt, string message) {}
122-
123116
public virtual void HandleEventFromLeadLocomotive(PowerSupplyEvent evt)
124117
{
125118
// By default, send the event to every component

Source/Orts.Simulation/Common/Scripting/TrainControlSystem.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,12 +533,32 @@ internal void AttachToHost(ScriptedTrainControlSystem host)
533533
/// </summary>
534534
public Func<string, string, string, string> GetStringParameter;
535535

536+
537+
/// <summary>
538+
/// Sends an event to the power supply
539+
/// </summary>
540+
/// <param name="evt">The event to send</param>
541+
public void SignalEventToPowerSupply(PowerSupplyEvent evt)
542+
{
543+
Locomotive.LocomotivePowerSupply.HandleEventFromTcs(evt);
544+
}
545+
546+
/// <summary>
547+
/// Sends an event to the power supply
548+
/// </summary>
549+
/// <param name="evt">The event to send</param>
550+
/// <param name="id">Additional id for the event</param>
551+
public void SignalEventToPowerSupply(PowerSupplyEvent evt, int id)
552+
{
553+
Locomotive.LocomotivePowerSupply.HandleEventFromTcs(evt, id);
554+
}
555+
536556
/// <summary>
537557
/// Sends an event and/or a message to the power supply
538558
/// </summary>
539559
/// <param name="evt">The event to send</param>
540560
/// <param name="message">The message to send</param>
541-
public void SignalEventToPowerSupply(PowerSupplyEvent evt = PowerSupplyEvent.MessageFromTcs, string message = "")
561+
public void SignalEventToPowerSupply(PowerSupplyEvent evt, string message)
542562
{
543563
Locomotive.LocomotivePowerSupply.HandleEventFromTcs(evt, message);
544564
}

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/ILocomotivePowerSupply.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public interface ILocomotivePowerSupply : IPowerSupply
4545
bool ServiceRetentionCancellationButton { get; set; }
4646
bool ServiceRetentionActive { get; set; }
4747

48+
void HandleEventFromTcs(PowerSupplyEvent evt);
49+
void HandleEventFromTcs(PowerSupplyEvent evt, int id);
4850
void HandleEventFromTcs(PowerSupplyEvent evt, string message);
4951
void HandleEventFromOtherLocomotive(int locoIndex, PowerSupplyEvent evt);
5052
void HandleEventFromOtherLocomotive(int locoIndex, PowerSupplyEvent evt, int id);

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/LocomotivePowerSupply.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,16 @@ public void HandleEvent(PowerSupplyEvent evt, int id)
262262
AbstractScript?.HandleEvent(evt, id);
263263
}
264264

265+
public void HandleEventFromTcs(PowerSupplyEvent evt)
266+
{
267+
AbstractScript?.HandleEventFromTcs(evt);
268+
}
269+
270+
public void HandleEventFromTcs(PowerSupplyEvent evt, int id)
271+
{
272+
AbstractScript?.HandleEventFromTcs(evt, id);
273+
}
274+
265275
public void HandleEventFromTcs(PowerSupplyEvent evt, string message)
266276
{
267277
AbstractScript?.HandleEventFromTcs(evt, message);

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/SteamPowerSupply.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ public void HandleEvent(PowerSupplyEvent evt, int id)
213213
{
214214
}
215215

216+
public void HandleEventFromTcs(PowerSupplyEvent evt)
217+
{
218+
}
219+
220+
public void HandleEventFromTcs(PowerSupplyEvent evt, int id)
221+
{
222+
}
223+
216224
public void HandleEventFromTcs(PowerSupplyEvent evt, string message)
217225
{
218226
}

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/TrainControlSystem.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ public void Initialize()
432432
{
433433
if (Locomotive.Pantographs.State == PantographState.Up)
434434
{
435-
Locomotive.Train.SignalEvent(PowerSupplyEvent.LowerPantograph);
435+
Locomotive.LocomotivePowerSupply.HandleEvent(PowerSupplyEvent.LowerPantograph);
436436
}
437437
};
438438
Script.SetPantographUp = (pantoID) =>
@@ -442,7 +442,7 @@ public void Initialize()
442442
Trace.TraceError($"TCS script used bad pantograph ID {pantoID}");
443443
return;
444444
}
445-
Locomotive.Train.SignalEvent(PowerSupplyEvent.RaisePantograph, pantoID);
445+
Locomotive.LocomotivePowerSupply.HandleEvent(PowerSupplyEvent.RaisePantograph, pantoID);
446446
};
447447
Script.SetPantographDown = (pantoID) =>
448448
{
@@ -451,7 +451,7 @@ public void Initialize()
451451
Trace.TraceError($"TCS script used bad pantograph ID {pantoID}");
452452
return;
453453
}
454-
Locomotive.Train.SignalEvent(PowerSupplyEvent.LowerPantograph, pantoID);
454+
Locomotive.LocomotivePowerSupply.HandleEvent(PowerSupplyEvent.LowerPantograph, pantoID);
455455
};
456456
Script.SetPowerAuthorization = (value) => PowerAuthorization = value;
457457
Script.SetCircuitBreakerClosingOrder = (value) => CircuitBreakerClosingOrder = value;
@@ -898,12 +898,7 @@ public void HandleEvent(TCSEvent evt, int eventIndex)
898898
HandleEvent(evt, message);
899899
}
900900

901-
public void HandleEvent(PowerSupplyEvent evt)
902-
{
903-
HandleEvent(evt, String.Empty);
904-
}
905-
906-
public void HandleEvent(PowerSupplyEvent evt, string message)
901+
public void HandleEvent(PowerSupplyEvent evt, string message="")
907902
{
908903
Script?.HandleEvent(evt, message);
909904
}

0 commit comments

Comments
 (0)