Exemple #1
0
func Update_orderlist(orderlist []int, newOrder int) []int {

	if order_exists(orderlist, newOrder) {
		return orderlist
	}

	tempOrderlist := append_and_sort_list(orderlist, newOrder)
	// Split up the orderlist in orders up and down
	ordersDown := get_orders_down(tempOrderlist)
	ordersUp := get_orders_up(tempOrderlist)

	var updatedOrderlist []int

	// These two conditions updates the orders based on the elevators direction and current floor
	if driver.Get_dir() >= 0 {
		for _, orderUp := range ordersUp {
			if orderUp > driver.Get_cur_floor() {
				updatedOrderlist = append(updatedOrderlist, orderUp)
			} else {
				ordersDown = append(ordersDown, orderUp)
			}
		}
		updatedOrderlist = helpFunc.Append_list(updatedOrderlist, ordersDown)
	}

	if driver.Get_dir() == -1 {
		for _, orderDown := range ordersDown {
			if -orderDown < driver.Get_cur_floor() {
				updatedOrderlist = append(updatedOrderlist, orderDown)
			} else {
				ordersUp = append(ordersUp, orderDown)
			}
		}
		updatedOrderlist = helpFunc.Append_list(updatedOrderlist, ordersUp)
	}

	return updatedOrderlist
}
Exemple #2
0
func handle_new_order(buttontype, floor int, outgoingMsg chan def.Message) {
	if external_order(buttontype) && ImConnected {
		msg := def.Message{Category: def.NewOrder, Floor: floor, Button: buttontype, Cost: -1}
		outgoingMsg <- msg
	} else if !external_order(buttontype) {
		// Internal orders: if the desired floor is under the elevator it is set as a order down
		if floor == driver.Get_cur_floor() && driver.Get_dir() == 1 {
			queue.Set_Orders(queue.Update_orderlist(queue.Get_Orders(), -floor))
		} else if floor < driver.Get_cur_floor() {
			queue.Set_Orders(queue.Update_orderlist(queue.Get_Orders(), -floor))
		} else if floor == def.NumFloors-1 {
			queue.Set_Orders(queue.Update_orderlist(queue.Get_Orders(), -floor))
		} else {
			queue.Set_Orders(queue.Update_orderlist(queue.Get_Orders(), floor))
		}

		queue.Save_backup_to_file()
	}
}