Exemplo n.º 1
0
func FsmOnOrderReceived(btnFloor int, btnType ButtonType) { //should be made to orderReceived
	switch E.Behaviour {
	case DOOROPEN:
		if E.Floor == btnFloor {
			TimerStart()
		} else {
			E.MasterOrders[btnFloor][btnType] = true
		}
	case IDLE:
		E.MasterOrders[btnFloor][btnType] = true
		E.Dir = ChooseDirection(E)

		if E.Dir == STOP {
			driver.ElevSetDoorLight(true)
			E = ClearOrdersAtFloor(E)
			TimerStart()
			E.Behaviour = DOOROPEN
		} else {
			driver.ElevSetMotorDirection(int(E.Dir))
			E.Behaviour = MOVING
		}
	case MOVING:
		E.MasterOrders[btnFloor][btnType] = true
	}
	SetAllLights(E)
}
Exemplo n.º 2
0
func fsm_onNewActiveRequest(btn_floor int, btn_type Button) {
	switch elevator.Behaviour {
	case EB_DoorOpen:
		if elevator.Floor == btn_floor {
			timer_start(3000 * time.Millisecond)
		} else {
			elevator.Requests[btn_floor][btn_type] = true
		}
		break
	case EB_Moving:
		elevator.Requests[btn_floor][btn_type] = true
		break
	case EB_Idle:
		elevator.Requests[btn_floor][btn_type] = true
		elevator.Dir = requests_chooseDirection(elevator)
		if elevator.Dir == D_Idle {
			Driver.ElevSetDoorLight(true)
			elevator = requests_clearAtCurrentFloor(elevator)
			timer_start(3000 * time.Millisecond)
			elevator.Behaviour = EB_DoorOpen
		} else {
			Driver.ElevSetMotorDirection(int(elevator.Dir))
			elevator.Behaviour = EB_Moving
			lastFloorTime = time.Now().Unix()
		}
		break
	}
	setAllLights()
}
Exemplo n.º 3
0
func FsmOnDoorTimeout() {
	if E.Behaviour == DOOROPEN {
		E.Dir = ChooseDirection(E)
		driver.ElevSetDoorLight(false)
		driver.ElevSetMotorDirection(int(E.Dir))
		if E.Dir == STOP {
			E.Behaviour = IDLE
		} else {
			E.Behaviour = MOVING
		}
	}
}
Exemplo n.º 4
0
func FsmOnFloorArrival(newFloor int) {
	E.Floor = newFloor

	driver.ElevSetFloorIndicator(newFloor)

	if ShouldStop(E) && E.Behaviour == MOVING {
		driver.ElevSetMotorDirection(int(STOP))
		driver.ElevSetDoorLight(true)
		E = ClearOrdersInDirection(E)
		TimerStart()
		SetAllLights(E)
		E.Behaviour = DOOROPEN
	}
}
Exemplo n.º 5
0
func fsm_onDoorTimeout() {
	switch elevator.Behaviour {
	case EB_DoorOpen:
		elevator.Dir = requests_chooseDirection(elevator)
		Driver.ElevSetMotorDirection(int(elevator.Dir))
		Driver.ElevSetDoorLight(false)
		if elevator.Dir == D_Idle {
			elevator.Behaviour = EB_Idle
		} else {
			elevator.Behaviour = EB_Moving
			lastFloorTime = time.Now().Unix()
		}
		break
	default:
		break
	}
}
Exemplo n.º 6
0
func fsm_onFloorArrival(newFloor int) {
	lastFloorTime = time.Now().Unix()
	elevator.Floor = newFloor
	Driver.ElevSetFloorIndicator(newFloor)
	switch elevator.Behaviour {
	case EB_Moving:
		if requests_shouldStop(elevator) {
			Driver.ElevSetMotorDirection(int(D_Idle))
			Driver.ElevSetDoorLight(true)
			elevator = requests_clearAtCurrentFloor(elevator)
			timer_start(3000 * time.Millisecond)
			setAllLights()
			elevator.Behaviour = EB_DoorOpen
		}
		break
	default:
		break
	}
}