Represents the EB device.
Inheritance: Device
Exemplo n.º 1
0
        internal override void Elapse(ElapseData data, ref bool blocking)
        {
            if (blocking)
            {
                this.Counter = 0;
            }
            else if (!(Math.Abs(data.Vehicle.Speed.MetersPerSecond) > this.SpeedThreshold | this.Counter >= this.TimeUntilBell))
            {
                this.Counter = 0;
            }
            else
            {
                Eb counter = this;
                counter.Counter = counter.Counter + data.ElapsedTime.Seconds;
                if (this.Counter < this.TimeUntilBrake)
                {
                    if (this.Counter >= this.TimeUntilBell)
                    {
                        SoundManager.Play(EBSound, 1.0, 1.0, false);
                    }
                }
                else if (this.Train.AtsSx == null || this.Train.AtsSx.State == AtsSx.States.Disabled)
                {
                    SoundManager.Play(CommonSounds.ATSPBell, 1.0, 1.0, false);
                    if (!Train.TractionManager.BrakeInterventionDemanded)
                    {
                        Train.TractionManager.DemandBrakeApplication(this.Train.Specs.BrakeNotches + 1, "Brake application demanded by the Eb");
                    }
                }
                else if (this.Train.AtsSx.State != AtsSx.States.Disabled)
                {
                    this.Train.AtsSx.State = AtsSx.States.Emergency;
                    if (this.Train.AtsP != null && this.Train.AtsP.State == AtsP.States.Normal | this.Train.AtsP.State == AtsP.States.Pattern | this.Train.AtsP.State == AtsP.States.Brake | this.Train.AtsP.State == AtsP.States.Service | this.Train.AtsP.State == AtsP.States.Emergency)
                    {
                        this.Train.AtsP.State = AtsP.States.Standby;
                    }
                    if (this.Train.Atc != null && this.Train.Atc.State == Atc.States.Normal | this.Train.Atc.State == Atc.States.ServiceHalf | this.Train.Atc.State == Atc.States.ServiceFull | this.Train.Atc.State == Atc.States.Emergency)
                    {
                        this.Train.Atc.State = Atc.States.Ats;
                    }
                    this.Counter = 0;
                }
            }
            if (this.Counter < this.TimeUntilBrake)
            {
                if (this.Counter >= this.TimeUntilBell)
                {
                    this.Train.Panel[8]   = 1;
                    this.Train.Panel[270] = 1;
                }
                return;
            }
            int num = ((int)data.TotalTime.Milliseconds % 1000 < 500 ? 1 : 0);

            this.Train.Panel[8]   = num;
            this.Train.Panel[270] = num;
        }
Exemplo n.º 2
0
        // --- functions ---
        /// <summary>Sets up the devices from the specified train.dat file.</summary>
        /// <param name="file">The train.dat file.</param>
        /// <returns>Whether loading the train.dat file was successful.</returns>
        internal bool LoadTrainDatFile(string file)
        {
            string[] lines = File.ReadAllLines(file, Encoding.UTF8);
            for (int i = 0; i < lines.Length; i++)
            {
                int semicolon = lines[i].IndexOf(';');
                if (semicolon >= 0)
                {
                    lines[i] = lines[i].Substring(0, semicolon).Trim();
                }
                else
                {
                    lines[i] = lines[i].Trim();
                }
            }
            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].Equals("#DEVICE", StringComparison.OrdinalIgnoreCase))
                {
                    if (i < lines.Length - 1)
                    {
                        int value = int.Parse(lines[i + 1], NumberStyles.Integer, CultureInfo.InvariantCulture);
                        if (value == 0)
                        {
                            this.AtsSx = new AtsSx(this);
                        }
                        else if (value == 1)
                        {
                            this.AtsSx = new AtsSx(this);
                            this.AtsP  = new AtsP(this);
                        }
                    }
                    if (i < lines.Length - 2)
                    {
                        int value = int.Parse(lines[i + 2], NumberStyles.Integer, CultureInfo.InvariantCulture);
                        if (value == 1)
                        {
                            this.Atc = new Atc(this, false);
                        }
                        else if (value == 2)
                        {
                            this.Atc = new Atc(this, true);
                        }
                    }
                    if (i < lines.Length - 3)
                    {
                        int value = int.Parse(lines[i + 3], NumberStyles.Integer, CultureInfo.InvariantCulture);
                        if (value == 1)
                        {
                            this.Eb = new Eb(this);
                        }
                    }
                }
            }
            // --- devices ---
            List <Device> devices = new List <Device>();

            if (this.Eb != null)
            {
                devices.Add(this.Eb);
            }
            if (this.Atc != null)
            {
                devices.Add(this.Atc);
            }
            if (this.AtsP != null)
            {
                devices.Add(this.AtsP);
            }
            if (this.AtsSx != null)
            {
                devices.Add(this.AtsSx);
            }
            this.Devices = devices.ToArray();
            return(true);
        }
Exemplo n.º 3
0
		// --- functions ---
		
		/// <summary>Sets up the devices from the specified train.dat file.</summary>
		/// <param name="file">The train.dat file.</param>
		/// <returns>Whether loading the train.dat file was successful.</returns>
		internal bool LoadTrainDatFile(string file) {
			string[] lines = File.ReadAllLines(file, Encoding.UTF8);
			for (int i = 0; i < lines.Length; i++) {
				int semicolon = lines[i].IndexOf(';');
				if (semicolon >= 0) {
					lines[i] = lines[i].Substring(0, semicolon).Trim();
				} else {
					lines[i] = lines[i].Trim();
				}
			}
			for (int i = 0; i < lines.Length; i++) {
				if (lines[i].Equals("#DEVICE", StringComparison.OrdinalIgnoreCase)) {
					if (i < lines.Length - 1) {
						int value = int.Parse(lines[i + 1], NumberStyles.Integer, CultureInfo.InvariantCulture);
						if (value == 0) {
							this.AtsSx = new AtsSx(this);
						} else if (value == 1) {
							this.AtsSx = new AtsSx(this);
							this.AtsP = new AtsP(this);
						}
					}
					if (i < lines.Length - 2) {
						int value = int.Parse(lines[i + 2], NumberStyles.Integer, CultureInfo.InvariantCulture);
						if (value == 1) {
							this.Atc = new Atc(this, false);
						} else if (value == 2) {
							this.Atc = new Atc(this, true);
						}
					}
					if (i < lines.Length - 3) {
						int value = int.Parse(lines[i + 3], NumberStyles.Integer, CultureInfo.InvariantCulture);
						if (value == 1) {
							this.Eb = new Eb(this);
						}
					}
				}
			}
			// --- devices ---
			List<Device> devices = new List<Device>();
			if (this.Eb != null) {
				devices.Add(this.Eb);
			}
			if (this.Atc != null) {
				devices.Add(this.Atc);
			}
			if (this.AtsP != null) {
				devices.Add(this.AtsP);
			}
			if (this.AtsSx != null) {
				devices.Add(this.AtsSx);
			}
			this.Devices = devices.ToArray();
			return true;
		}
Exemplo n.º 4
0
        // --- functions ---

        /// <summary>Sets up the devices from the specified configuration file.</summary>
        /// <param name="file">The configuration file.</param>
        internal void LoadConfigurationFile(string file)
        {
            string[] lines   = File.ReadAllLines(file, Encoding.UTF8);
            string   section = string.Empty;

            for (int i = 0; i < lines.Length; i++)
            {
                string line      = lines[i];
                int    semicolon = line.IndexOf(';');
                if (semicolon >= 0)
                {
                    line = line.Substring(0, semicolon).Trim();
                }
                else
                {
                    line = line.Trim();
                }
                if (line.Length != 0)
                {
                    if (line[0] == '[' & line[line.Length - 1] == ']')
                    {
                        section = line.Substring(1, line.Length - 2).ToLowerInvariant();
                        switch (section)
                        {
                        case "ats-sx":
                            this.AtsSx = new AtsSx(this);
                            break;

                        case "ats-ps":
                            this.AtsPs = new AtsPs(this);
                            break;

                        case "ats-p":
                            this.AtsP = new AtsP(this);
                            break;

                        case "atc":
                            this.Atc = new Atc(this);
                            break;

                        case "eb":
                            this.Eb = new Eb(this);
                            break;

                        case "tasc":
                            this.Tasc = new Tasc(this);
                            break;

                        case "ato":
                            this.Ato = new Ato(this);
                            break;

                        default:
                            throw new InvalidDataException("The section " + line[0] + " is not supported.");
                        }
                    }
                    else
                    {
                        int equals = line.IndexOf('=');
                        if (equals >= 0)
                        {
                            string key   = line.Substring(0, equals).Trim().ToLowerInvariant();
                            string value = line.Substring(equals + 1).Trim();
                            switch (section)
                            {
                            case "ats-sx":
                                switch (key)
                                {
                                case "durationofalarm":
                                    this.AtsSx.DurationOfAlarm = double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                                    break;

                                case "durationofinitialization":
                                    this.AtsSx.DurationOfInitialization = double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                                    break;

                                case "durationofspeedcheck":
                                    this.AtsSx.DurationOfSpeedCheck = double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                                    break;

                                default:
                                    throw new InvalidDataException("The parameter " + key + " is not supported.");
                                }
                                break;

                            case "ats-ps":
                                switch (key)
                                {
                                case "maximumspeed":
                                    this.AtsPs.TrainPermanentPattern.SetPersistentLimit((1.0 / 3.6) * double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture));
                                    break;

                                default:
                                    throw new InvalidDataException("The parameter " + key + " is not supported.");
                                }
                                break;

                            case "ats-p":
                                switch (key)
                                {
                                case "durationofinitialization":
                                    this.AtsP.DurationOfInitialization = double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                                    break;

                                case "durationofbrakerelease":
                                    this.AtsP.DurationOfBrakeRelease = double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                                    break;

                                case "designdeceleration":
                                    this.AtsP.DesignDeceleration = (1.0 / 3.6) * double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                                    break;

                                case "brakepatterndelay":
                                    this.AtsP.BrakePatternDelay = double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                                    break;

                                case "brakepatternoffset":
                                case "signaloffset":
                                    this.AtsP.BrakePatternOffset = double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                                    break;

                                case "brakepatterntolerance":
                                    this.AtsP.BrakePatternTolerance = (1.0 / 3.6) * double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                                    break;

                                case "warningpatterndelay":
                                case "reactiondelay":
                                    this.AtsP.WarningPatternDelay = double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                                    break;

                                case "warningpatternoffset":
                                    this.AtsP.WarningPatternOffset = double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                                    break;

                                case "warningpatterntolerance":
                                    this.AtsP.WarningPatternTolerance = (1.0 / 3.6) * double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                                    break;

                                case "patternspeeddifference":
                                    this.AtsP.WarningPatternTolerance = (-1.0 / 3.6) * double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                                    break;

                                case "releasespeed":
                                    this.AtsP.ReleaseSpeed = (1.0 / 3.6) * double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                                    break;

                                case "maximumspeed":
                                    this.AtsP.TrainPermanentPattern.SetPersistentLimit((1.0 / 3.6) * double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture));
                                    break;

                                default:
                                    throw new InvalidDataException("The parameter " + key + " is not supported.");
                                }
                                break;

                            case "atc":
                                switch (key)
                                {
                                case "automaticswitch":
                                    this.Atc.AutomaticSwitch = value.Equals("true", StringComparison.OrdinalIgnoreCase);
                                    break;

                                case "emergencyoperation":
                                    if (value.Equals("false", StringComparison.OrdinalIgnoreCase))
                                    {
                                        this.Atc.EmergencyOperationSignal = null;
                                    }
                                    else
                                    {
                                        double limit = (1.0 / 3.6) * double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                                        if (limit <= 0.0)
                                        {
                                            this.Atc.EmergencyOperationSignal = null;
                                        }
                                        else
                                        {
                                            this.Atc.EmergencyOperationSignal = Atc.Signal.CreateEmergencyOperationSignal(limit);
                                        }
                                    }
                                    break;

                                default:
                                    int aspect;
                                    if (int.TryParse(key, NumberStyles.Integer, CultureInfo.InvariantCulture, out aspect))
                                    {
                                        if (aspect >= 10)
                                        {
                                            Atc.Signal signal = ParseAtcCode(aspect, value);
                                            if (signal != null)
                                            {
                                                this.Atc.Signals.Add(signal);
                                                break;
                                            }
                                            else
                                            {
                                                throw new InvalidDataException("The ATC code " + value + " is not supported.");
                                            }
                                        }
                                    }
                                    throw new InvalidDataException("The parameter " + key + " is not supported.");
                                }
                                break;

                            case "eb":
                                switch (key)
                                {
                                case "timeuntilbell":
                                    this.Eb.TimeUntilBell = double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                                    break;

                                case "timeuntilbrake":
                                    this.Eb.TimeUntilBrake = double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                                    break;

                                case "speedthreshold":
                                    this.Eb.SpeedThreshold = double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                                    break;

                                default:
                                    throw new InvalidDataException("The parameter " + key + " is not supported.");
                                }
                                break;

                            case "tasc":
                                switch (key)
                                {
                                case "designdeceleration":
                                    this.Tasc.TascBrakeDeceleration = (1.0 / 3.6) * double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                                    break;

                                default:
                                    throw new InvalidDataException("The parameter " + key + " is not supported.");
                                }
                                break;
                            }
                        }
                    }
                }
            }
            // --- devices ---
            List <Device> devices = new List <Device>();

            if (this.Ato != null)
            {
                devices.Add(this.Ato);
            }
            if (this.Tasc != null)
            {
                devices.Add(this.Tasc);
            }
            if (this.Eb != null)
            {
                devices.Add(this.Eb);
            }
            if (this.Atc != null)
            {
                devices.Add(this.Atc);
            }
            if (this.AtsP != null)
            {
                devices.Add(this.AtsP);
            }
            if (this.AtsPs != null)
            {
                devices.Add(this.AtsPs);
                if (this.AtsSx == null)
                {
                    this.AtsSx = new AtsSx(this);
                }
            }
            if (this.AtsSx != null)
            {
                devices.Add(this.AtsSx);
            }
            this.Devices = devices.ToArray();
        }