예제 #1
0
    private void updateState(Hallway h) {
      DoorState previousState = state[h.ordinal()];

      DoorState newState = previousState;

      if (allDoorsClosed(h) && allDoorMotorsStopped(h)) {
        newState = DoorState.CLOSED;
      } else if (allDoorsCompletelyOpen(h) && allDoorMotorsStopped(h)) {
        newState = DoorState.OPEN;
      } else if (anyDoorMotorNudging(h)) {
        newState = DoorState.NUDGING;
      } else if (anyDoorMotorClosing(h)) {
        newState = DoorState.CLOSING;
      } else if (anyDoorMotorOpening(h)) {
        newState = DoorState.OPENING;
      }

      if (newState != previousState) {
        switch (newState) {
          case CLOSED:
            doorClosed(h);
            break;
          case OPEN:
            doorOpened(h);
            break;
          case OPENING:
            if (previousState == DoorState.CLOSING || previousState == DoorState.OPEN) {
              doorReopening(h);
            } else {
              doorOpening(h);
            }
            break;
          case CLOSING:
            doorClosing(h);
            break;
          case NUDGING:
            doorNudging(h);
            break;
        }
      }

      // set the newState
      state[h.ordinal()] = newState;
    }
예제 #2
0
 /**
  * Called once when the doors are fully open
  *
  * @param hallway which door the event pertains to
  */
 private void doorOpened(Hallway hallway) {
   nextDirection = mDesiredFloor.getDirection();
   // System.out.println(hallway.toString() + " Door Opened");
   // if the lantern flickers, violation of 8.2
   if (nextDirection == Direction.UP) {
     if (carLanterns[Direction.DOWN.ordinal()].lighted())
       warning(
           "R-T8.2 Violated: Both lanterns lit in one cycle! NextDirection "
               + nextDirection
               + " DesiredFloor "
               + mDesiredFloor.getFloor()
               + mDesiredFloor.getHallway()
               + mDesiredFloor.getDirection());
     // Check if car lantern is in compliance with requirements.
   } else if (nextDirection == Direction.DOWN) {
     if (carLanterns[Direction.UP.ordinal()].lighted())
       warning(
           "R-T8.2 Violated: Both lanterns lit in one cycle! NextDirection "
               + nextDirection
               + " DesiredFloor "
               + mDesiredFloor.getFloor()
               + mDesiredFloor.getHallway()
               + mDesiredFloor.getDirection());
     // Check if car lantern is in compliance with requirements.
   }
   // else, nextDirection == STOP and lantern not on.
   else
     for (int f = 1; f < Elevator.numFloors; f++) {
       for (Hallway h : Hallway.replicationValues) {
         for (Direction d : Direction.replicationValues) {
           if (carLights[f][h.ordinal()].lighted()
               || hallLights[f][h.ordinal()][d.ordinal()].lighted()) {
             warning(
                 "R-T8.1 Violated: Lantern not on with other pending"
                     + "calls on other floors at hallway "
                     + hallway);
           }
         }
       }
     }
 }
예제 #3
0
 /** Called when the drive is transitioning to the Stop state */
 private void driveStopping() {
   int currentFloor = floorArray.getCurrentFloor();
   Hallway h;
   if (Elevator.hasLanding(currentFloor, Hallway.FRONT)) {
     if (Elevator.hasLanding(currentFloor, Hallway.BACK)) h = Hallway.BOTH;
     else h = Hallway.FRONT;
   } else h = Hallway.BACK;
   currentFloor--;
   if (h == Hallway.BOTH) {
     if (!carLights[currentFloor][Hallway.FRONT.ordinal()].lighted()
         && !carLights[currentFloor][Hallway.BACK.ordinal()].lighted()
         && !hallLights[currentFloor][Hallway.FRONT.ordinal()][Direction.UP.ordinal()].lighted()
         && !hallLights[currentFloor][Hallway.FRONT.ordinal()][Direction.DOWN.ordinal()].lighted()
         && !hallLights[currentFloor][Hallway.BACK.ordinal()][Direction.UP.ordinal()].lighted()
         && !hallLights[currentFloor][Hallway.BACK.ordinal()][Direction.DOWN.ordinal()]
             .lighted()) {
       warning("R-T6 Violated: Stopped at floor" + currentFloor + " with no pending calls.");
     }
   } else if (!carLights[currentFloor][h.ordinal()].lighted()
       && !hallLights[currentFloor][h.ordinal()][Direction.UP.ordinal()].lighted()
       && !hallLights[currentFloor][h.ordinal()][Direction.DOWN.ordinal()].lighted()) {
     warning("R-T6 Violated: Stopped at floor" + currentFloor + " with no pending calls.");
   }
 }
예제 #4
0
 /** Called when the drive is in the Slow State */
 private void driveSlow() {
   // Check if there are any calls in the specified direction.
   // If so, then violation. Otherwise, no violation.
   if (nextDirection != Direction.STOP) {
     int currentFloor = floorArray.getCurrentFloor() - 1;
     if (nextDirection == Direction.UP) {
       for (int f_u = currentFloor + 1; f_u < Elevator.numFloors; f_u++) {
         for (Hallway h : Hallway.replicationValues) {
           for (Direction d : Direction.replicationValues) {
             if (carLights[f_u][h.ordinal()].lighted()
                 || hallLights[f_u][h.ordinal()][d.ordinal()].lighted()) {
               if (nextDirection != driveActualSpeed.direction())
                 warning(
                     "R-T8.3 Violated: Elevator is sevicing direction "
                         + driveActualSpeed.direction()
                         + " instead of "
                         + (f_u + 1)
                         + " "
                         + h
                         + " in direction "
                         + nextDirection);
             }
           }
         }
       }
     } else if (nextDirection == Direction.DOWN) {
       for (int f_d = currentFloor - 1; f_d >= 1; f_d--) {
         for (Hallway h : Hallway.replicationValues) {
           for (Direction d : Direction.replicationValues) {
             if (carLights[f_d][h.ordinal()].lighted()
                 || hallLights[f_d][h.ordinal()][d.ordinal()].lighted()) {
               if (nextDirection != driveActualSpeed.direction())
                 warning(
                     "R-T8.3 Violated: Elevator is sevicing direction "
                         + driveActualSpeed.direction()
                         + " instead of "
                         + f_d
                         + " "
                         + h
                         + " in direction "
                         + nextDirection);
             }
           }
         }
       }
     }
   }
 }
예제 #5
0
 public boolean anyDoorMotorNudging(Hallway h) {
   return doorMotors[h.ordinal()][Side.LEFT.ordinal()].command() == DoorCommand.NUDGE
       || doorMotors[h.ordinal()][Side.RIGHT.ordinal()].command() == DoorCommand.NUDGE;
 }
예제 #6
0
 public boolean anyDoorMotorClosing(Hallway h) {
   return doorMotors[h.ordinal()][Side.LEFT.ordinal()].command() == DoorCommand.CLOSE
       || doorMotors[h.ordinal()][Side.RIGHT.ordinal()].command() == DoorCommand.CLOSE;
 }
예제 #7
0
 public boolean anyDoorMotorOpening(Hallway h) {
   return doorMotors[h.ordinal()][Side.LEFT.ordinal()].command() == DoorCommand.OPEN
       || doorMotors[h.ordinal()][Side.RIGHT.ordinal()].command() == DoorCommand.OPEN;
 }
예제 #8
0
 public boolean allDoorMotorsStopped(Hallway h) {
   return doorMotors[h.ordinal()][Side.LEFT.ordinal()].command() == DoorCommand.STOP
       && doorMotors[h.ordinal()][Side.RIGHT.ordinal()].command() == DoorCommand.STOP;
 }
예제 #9
0
 public boolean allDoorsClosed(Hallway h) {
   return (doorCloseds[h.ordinal()][Side.LEFT.ordinal()].isClosed()
       && doorCloseds[h.ordinal()][Side.RIGHT.ordinal()].isClosed());
 }
예제 #10
0
 public boolean anyDoorOpen(Hallway h) {
   return !doorCloseds[h.ordinal()][Side.LEFT.ordinal()].isClosed()
       || !doorCloseds[h.ordinal()][Side.RIGHT.ordinal()].isClosed();
 }
예제 #11
0
 // door utility methods
 public boolean allDoorsCompletelyOpen(Hallway h) {
   return doorOpeneds[h.ordinal()][Side.LEFT.ordinal()].isOpen()
       && doorOpeneds[h.ordinal()][Side.RIGHT.ordinal()].isOpen();
 }