ATC Dimetronic: ATP code test
This commit is contained in:
parent
da761976b4
commit
e962d851b2
3 changed files with 43 additions and 47 deletions
|
@ -269,7 +269,7 @@ namespace OpenbveFcmbTrainPlugin
|
|||
train.Panel[26] = DeviceState == DeviceStates.YARD ? 1 : 0;
|
||||
train.Panel[26] += DeviceState == DeviceStates.Initialized && stopped && blink ? 1 : 0;
|
||||
train.Panel[27] = DeviceState == DeviceStates.ATP ? 1 : 0;
|
||||
train.Panel[28] = DeviceState == DeviceStates.ATP ? 1 : 0;
|
||||
train.Panel[28] = DeviceState == DeviceStates.ATO ? 1 : 0;
|
||||
switch (AtcControlState)
|
||||
{
|
||||
case AtcControlStates.Released:
|
||||
|
|
|
@ -49,8 +49,17 @@ namespace OpenbveFcmbTrainPlugin
|
|||
/// <summary>The current state of the track.</summary>
|
||||
private TrackStates TrackState;
|
||||
|
||||
/// <summary>The maximum speed in YARD mode, in km/h.</summary>
|
||||
private readonly double YardMaximumSpeed;
|
||||
/// <summary>The upcoming signals in the route.</summary>
|
||||
private SignalData[] Signals;
|
||||
|
||||
/// <summary>The maximum speed in YARD mode.</summary>
|
||||
private readonly Speed YardMaximumSpeed;
|
||||
|
||||
/// <summary>The speed limit for each signal aspect.</summary>
|
||||
private readonly Speed[] AspectLimit = { new Speed(0), new Speed(25 / 3.6), new Speed(25 / 3.6), new Speed(25 / 3.6), new Speed(25 / 3.6), new Speed(45 / 3.6), new Speed(45 / 3.6), new Speed(45 / 3.6), new Speed(45 / 3.6), new Speed(70 / 3.6), new Speed(70 / 3.6), new Speed(70 / 3.6), new Speed(70 / 3.6) };
|
||||
|
||||
/// <summary>The target speed limit for each signal aspect.</summary>
|
||||
private readonly Speed[] AspectTargetLimit = { new Speed(0), new Speed(0), new Speed(0), new Speed(25 / 3.6), new Speed(25 / 3.6), new Speed(0), new Speed(0), new Speed(45 / 3.6), new Speed(45 / 3.6), new Speed(0), new Speed(0), new Speed(70 / 3.6), new Speed(70 / 3.6) };
|
||||
|
||||
/// <summary>Whether ATO is available or not on the train.</summary>
|
||||
private readonly bool AtoAvailable;
|
||||
|
@ -63,24 +72,31 @@ namespace OpenbveFcmbTrainPlugin
|
|||
internal Speed WarningOn { get; private set; }
|
||||
internal Speed WarningOff { get; private set; }
|
||||
internal Speed TargetLimit { get; private set; }
|
||||
internal double TargetLocation { get; private set; }
|
||||
|
||||
internal SpeedCode(Speed limit, Speed target)
|
||||
internal SpeedCode(Speed limit, Speed target, double location)
|
||||
{
|
||||
CurrentLimit = limit;
|
||||
TargetLimit = target;
|
||||
TargetLocation = location;
|
||||
if (limit == target)
|
||||
{
|
||||
// Constant speed
|
||||
WarningOn = new Speed(limit.MetersPerSecond - 3 / 3.6);
|
||||
WarningOff = new Speed(limit.MetersPerSecond - 5 / 3.6);
|
||||
WarningOn = new Speed((limit.KilometersPerHour - 3) / 3.6);
|
||||
WarningOff = new Speed((limit.KilometersPerHour - 5) / 3.6);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Reduce speed
|
||||
WarningOn = target;
|
||||
WarningOff = new Speed(target.MetersPerSecond - 2 / 3.6);
|
||||
WarningOff = new Speed((target.KilometersPerHour - 2) / 3.6);
|
||||
}
|
||||
}
|
||||
|
||||
internal SpeedCode(Speed limit, Speed target) : this(limit, target, 0)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>The current speed code received by the train.</summary>
|
||||
|
@ -95,7 +111,7 @@ namespace OpenbveFcmbTrainPlugin
|
|||
/// <summary>Creates an instance of the Bombardier ATC device.</summary>
|
||||
/// <param name="yardMaxSpeed">The maximum speed in YARD mode, in km/h.</param>
|
||||
/// <param name="atoAvailable">Whether ATO is available or not.</param>
|
||||
internal AtcDimetronic(double yardMaxSpeed, bool atoAvailable)
|
||||
internal AtcDimetronic(Speed yardMaxSpeed, bool atoAvailable)
|
||||
{
|
||||
YardMaximumSpeed = yardMaxSpeed;
|
||||
AtoAvailable = atoAvailable;
|
||||
|
@ -114,9 +130,6 @@ namespace OpenbveFcmbTrainPlugin
|
|||
DeviceState = DeviceStates.NoMode;
|
||||
}
|
||||
|
||||
// Update ATC movement permission
|
||||
UpdateSpeedCode();
|
||||
|
||||
double speed = train.State.Speed.KilometersPerHour;
|
||||
bool stopped = speed < 0.05;
|
||||
|
||||
|
@ -172,7 +185,7 @@ namespace OpenbveFcmbTrainPlugin
|
|||
train.VigilanceOverride = false;
|
||||
// Apply service/emergency brake while no driving mode is selected
|
||||
AtcControlState = AtcControlStates.BrakeEmergency;
|
||||
// ATC movement permission
|
||||
// Update ATC speed code
|
||||
CurrentSpeedCode = new SpeedCode(new Speed(0), new Speed(0));
|
||||
break;
|
||||
// ATC device is in YARD (M+25) driving mode
|
||||
|
@ -206,7 +219,10 @@ namespace OpenbveFcmbTrainPlugin
|
|||
train.Panel[25] = DeviceState == DeviceStates.Override ? 1 : 0;
|
||||
train.Panel[26] = DeviceState == DeviceStates.YARD ? 1 : 0;
|
||||
train.Panel[27] = DeviceState == DeviceStates.ATP ? 1 : 0;
|
||||
train.Panel[28] = DeviceState == DeviceStates.ATO ? 1 : 0;
|
||||
train.Panel[34] = (int)CurrentSpeedCode.CurrentLimit.KilometersPerHour * 1000;
|
||||
train.Panel[33] = 1;
|
||||
train.Panel[35] = (int)CurrentSpeedCode.TargetLimit.KilometersPerHour * 1000;
|
||||
}
|
||||
|
||||
|
||||
|
@ -228,11 +244,13 @@ namespace OpenbveFcmbTrainPlugin
|
|||
if (!OpenbveFcmbTrainPlugin.KeysPressed[(int)key])
|
||||
{
|
||||
// Allow change anytime the train is stopped or from ATP mode below YARD speed limit
|
||||
if ((DeviceState >= DeviceStates.NoMode && stopped) || (DeviceState == DeviceStates.ATP && train.State.Speed.KilometersPerHour < YardMaximumSpeed))
|
||||
if ((DeviceState >= DeviceStates.NoMode && stopped) || (DeviceState == DeviceStates.ATP && train.State.Speed.KilometersPerHour < YardMaximumSpeed.KilometersPerHour))
|
||||
{
|
||||
if (train.PhysicalHandles.Reverser == 1 || train.PhysicalHandles.Reverser == -1)
|
||||
{
|
||||
DeviceState = DeviceStates.YARD;
|
||||
// Update ATC speed code
|
||||
CurrentSpeedCode = new SpeedCode(YardMaximumSpeed, YardMaximumSpeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -247,6 +265,8 @@ namespace OpenbveFcmbTrainPlugin
|
|||
if (train.PhysicalHandles.Reverser == 1 && TrackState > TrackStates.Unprotected)
|
||||
{
|
||||
DeviceState = DeviceStates.ATP;
|
||||
// Update ATC speed code
|
||||
CurrentSpeedCode = new SpeedCode(AspectLimit[Signals[0].Aspect], AspectLimit[Signals[0].Aspect]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -261,6 +281,8 @@ namespace OpenbveFcmbTrainPlugin
|
|||
if (train.PhysicalHandles.Reverser == 1 && TrackState > TrackStates.Unprotected)
|
||||
{
|
||||
DeviceState = DeviceStates.ATO;
|
||||
// Update ATC speed code
|
||||
CurrentSpeedCode = new SpeedCode(AspectLimit[Signals[0].Aspect], AspectLimit[Signals[0].Aspect]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -309,7 +331,12 @@ namespace OpenbveFcmbTrainPlugin
|
|||
/// <param name="signal">The signal data.</param>
|
||||
internal override void SetSignal(SignalData[] signal)
|
||||
{
|
||||
Signals = signal;
|
||||
|
||||
if (DeviceState == DeviceStates.ATP || DeviceState == DeviceStates.ATO)
|
||||
{
|
||||
CurrentSpeedCode = new SpeedCode(AspectLimit[signal[0].Aspect], AspectLimit[signal[0].Aspect]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Is called when a beacon is passed.</summary>
|
||||
|
@ -400,37 +427,5 @@ namespace OpenbveFcmbTrainPlugin
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Updates the data for the current speed code.</summary>
|
||||
internal void UpdateSpeedCode()
|
||||
{
|
||||
Speed zero = new Speed(0);
|
||||
Speed yard = new Speed(YardMaximumSpeed / 3.6);
|
||||
|
||||
switch (DeviceState)
|
||||
{
|
||||
case DeviceStates.Override:
|
||||
case DeviceStates.NoMode:
|
||||
if (CurrentSpeedCode == null || CurrentSpeedCode.CurrentLimit != zero || CurrentSpeedCode.TargetLimit != zero)
|
||||
{
|
||||
CurrentSpeedCode = new SpeedCode(zero, zero);
|
||||
}
|
||||
break;
|
||||
case DeviceStates.YARD:
|
||||
if (CurrentSpeedCode == null || CurrentSpeedCode.CurrentLimit != yard || CurrentSpeedCode.TargetLimit != yard)
|
||||
{
|
||||
CurrentSpeedCode = new SpeedCode(yard, yard);
|
||||
}
|
||||
break;
|
||||
case DeviceStates.ATP:
|
||||
case DeviceStates.ATO:
|
||||
if (CurrentSpeedCode == null || CurrentSpeedCode.CurrentLimit != zero || CurrentSpeedCode.TargetLimit != zero)
|
||||
{
|
||||
CurrentSpeedCode = new SpeedCode(zero, zero);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using OpenBveApi.Runtime;
|
||||
|
||||
namespace OpenbveFcmbTrainPlugin
|
||||
{
|
||||
|
@ -29,7 +30,7 @@ namespace OpenbveFcmbTrainPlugin
|
|||
internal int AtcBombardierYardSpeedLimit = 20;
|
||||
internal int AtcBombardierBlinkTime = 500;
|
||||
|
||||
internal int AtcDimetronicYardSpeedLimit = 25;
|
||||
internal Speed AtcDimetronicYardSpeedLimit = new Speed(25 / 3.6);
|
||||
internal bool AtcDimetronicAtoAvailable;
|
||||
}
|
||||
|
||||
|
@ -199,7 +200,7 @@ namespace OpenbveFcmbTrainPlugin
|
|||
{
|
||||
if (int.TryParse(Value, out int a))
|
||||
{
|
||||
PluginSettings.AtcDimetronicYardSpeedLimit = a;
|
||||
PluginSettings.AtcDimetronicYardSpeedLimit = new Speed(a / 3.6);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Add table
Reference in a new issue