Esempio n. 1
0
 //every time interval update all of the displays and internal variables, set calculations for real time
 public void updateTime(String time)
 {
     setTimeLabel(time);
     speedLimit   = currentBlock.speedLimit;
     speedLimitms = speedLimit / 3.6;
     //look ahead and find if the next two blocks have a lower speed limit than the current block
     considerSpeedLimit();
     //this section sets the speed limit and the allowed set speed for the train
     if (futureSpeedLimitms < speedLimitms)
     {
         speedLimitms = futureSpeedLimitms;
     }
     if (testMode == 0)
     {
         //figure out setSpeed;
         if (mode == 0)
         {
             setSpeed = driverSetSpeed;
         }
         else
         {
             setSpeed = ctcSetSpeed;
         }
         setSpeedms = setSpeed * 0.44704;
         if (setSpeedms > speedLimitms)
         {
             setSpeedms = speedLimitms;
         }
     }
     //calculate minumum stopping distance for authority and stations. Use this
     //information to figure out when train needs to start stopping
     considerAuthority();
     considerStations();
     resetStation();
     if (distanceToStation < minStopDistanceStation || distanceToAuthority < minStopDistanceAuthority)
     {
         forceStop = true;
     }
     if ((currSpeedms <= setSpeedms) && !forceStop && !emergencyOverride && authority > 0)
     {
         sBreakOFF();
         emergencyOFF();
         power = powerController.getPower(currSpeedms, setSpeedms);
     }
     //else if (forceStop)
     // {
     //
     // }
     else if (emergencyOverride)
     {
         emergencyON();
     }
     else
     {
         sBreakON();
         power = 0;
     }
     //set all control signals and pass them on to the train model so then next unit of time, train
     //model updates with the information
     setThermostat();
     setLights();
     TM.updatePower(power);
     TM.updateThermostat(thermostat);
     TM.updateDoorStatus(doorStatus);
     TM.updateLightStatus(lightStatus);
     //update the GUI with all relevant signals
     trainSpeedLabel.Text      = (currSpeedms * 2.23694).ToString("#.###") + "MPH";
     trainPowerLabel.Text      = (power / 1000).ToString("#.###") + "kW";
     ctcSpeedLabel.Text        = (ctcSetSpeed).ToString("#.###") + "MPH";
     ctcAuthorityLabel.Text    = authority.ToString() + " blocks";
     trainTempLabel.Text       = (temp.ToString()) + "F";
     blockIDLabel.Text         = currentBlock.blockNum.ToString();
     blockSpeedLimitLabel.Text = (speedLimit * 0.621371).ToString("#.##") + "MPH";
     //blockSpeedLimitLabel.Text = minStopDistanceAuthority.ToString();
     //tunnelStatusLabel.Text = distanceToAuthority.ToString();
     distanceLeftLabel.Text = distanceLeft.ToString("#.##");
     distanceToLabel.Text   = (distanceToStation).ToString("#.##");
     stationLabel.Text      = stationName.ToString();
     trainIDLabel.Text      = trainID.ToString();
     if (lightStatus)
     {
         tunnelStatusLabel.Text = "Underground";
     }
     else
     {
         tunnelStatusLabel.Text = "Above";
     }
     if (lightStatus)
     {
         lightsON.Checked = true;
     }
     else
     {
         lightsON.Checked = false;
     }
     //set the door status on the GUI
     if (doorStatus == 0)
     {
         leftClosed.Checked  = true;
         rightClosed.Checked = true;
     }
     else if (doorStatus == 1)
     {
         leftOpen.Checked    = true;
         rightClosed.Checked = true;
     }
     else if (doorStatus == 2)
     {
         leftClosed.Checked = true;
         rightOpen.Checked  = true;
     }
 }