Exemple #1
0
// NewOrder locally or remotely
func NewOrder(floor driver.Floor, dir driver.Direction) {
	if dir == driver.DirectionNone { // From inside the elevator
		shouldStop[dir][floor] = true
		driver.ButtonLightOn(floor, dir)
		AddToLog(int(floor)) //Log internal order to file
	} else { // From external panel on this or some other elevator

		if floor == 0 {
			dir = driver.DirectionDown
		} else if floor == driver.NumFloors-1 {
			dir = driver.DirectionUp
		}

		o := order{
			floor: floor,
			dir:   dir,
			timer: time.AfterFunc(calculateTimeout(floor, dir), func() {
				shouldStop[dir][floor] = true
				if currentDir == driver.DirectionNone {
					// Ping
					timeoutCh <- true
				}
				// Send network message that we have accepted
				net.SendOrder(net.OrderMessage{Type: net.AcceptedOrder, Floor: floor, Direction: dir})
				log.Info("Accepted order for floor ", floor)
			}),
		}

		pendingOrders.PushBack(&o)
	}
	driver.ButtonLightOn(floor, dir)
}
Exemple #2
0
//ImportInternalLog imports any locally saved internal orders to the active queue. Called at init.
func ImportInternalLog() {
	intSlice := ReadLog()

	for i := 0; i < len(intSlice); i++ {
		shouldStop[driver.DirectionNone][intSlice[i]] = true
		driver.ButtonLightOn(driver.Floor(intSlice[i]), driver.DirectionNone)
	}
}