func newOrder(ch Channels) { switch def.LocalElevator.State { case def.MOVING: //Do nothing case def.IDLE: def.LocalElevator.Dir = queue.ChooseDir(def.LocalElevator.Floor, def.LocalElevator.Dir) if queue.ShouldStop(def.LocalElevator.Floor, def.LocalElevator.Dir) { def.LocalElevator.State = def.DOOR_OPEN ch.DoorLight <- true ch.DoorTimerReset <- true ch.OrderTimerReset <- true } else { ch.MotorDir <- def.LocalElevator.Dir def.LocalElevator.State = def.MOVING } case def.DOOR_OPEN: if queue.ShouldStop(def.LocalElevator.Floor, def.LocalElevator.Dir) { ch.DoorTimerReset <- true } default: } }
func OnFloorArrival(hwCh def.HardwareChan, OutgoingMsg chan<- def.Message, newFloor int) { Elevator.Floor = newFloor hwCh.FloorLamp <- Elevator.Floor switch Elevator.Behaviour { case moving: if queue.ShouldStop(newFloor, Elevator.Dir) { hwCh.MotorDir <- def.DirStop hwCh.DoorLamp <- true hwCh.DoorTimerReset <- true queue.RemoveLocalRequestsAt(Elevator.Floor, OutgoingMsg) Elevator.Behaviour = doorOpen } } }
func floorReached(ch Channels, newFloor int) { def.LocalElevator.Floor = newFloor ch.NewFloor <- def.LocalElevator.Floor switch def.LocalElevator.State { case def.MOVING: if queue.ShouldStop(def.LocalElevator.Floor, def.LocalElevator.Dir) { def.LocalElevator.Dir = def.DIR_STOP ch.MotorDir <- def.LocalElevator.Dir def.LocalElevator.State = def.DOOR_OPEN ch.DoorLight <- true ch.DoorTimerReset <- true ch.OrderTimerReset <- true } default: } }
func OnNewRequest(OutgoingMsg chan<- def.Message, hwCh def.HardwareChan) { switch Elevator.Behaviour { case doorOpen: if queue.ShouldStop(Elevator.Floor, Elevator.Dir) { hwCh.DoorTimerReset <- true queue.RemoveLocalRequestsAt(Elevator.Floor, OutgoingMsg) } case moving: //Do nothing case idle: Elevator.Dir = queue.ChooseDirection(Elevator.Floor, Elevator.Dir) if Elevator.Dir == def.DirStop { hwCh.DoorLamp <- true hwCh.DoorTimerReset <- true queue.RemoveLocalRequestsAt(Elevator.Floor, OutgoingMsg) Elevator.Behaviour = doorOpen } else { hwCh.MotorDir <- Elevator.Dir Elevator.Behaviour = moving } } }