Пример #1
0
func Run_elev(outgoingMsg chan def.Message) {
	for {

		update_current_floor()

		//If we have orders and we are not between floors
		if (len(queue.Get_Orders()) > 0) && (driver.Get_cur_floor() != -1) {
			set_direction(queue.Get_Orders()[0], driver.Get_cur_floor())

			if arrived_at_destination() {
				driver.Set_motor_dir(0)

				if handleOrders.ImConnected {
					send_order_complete_msg(queue.Get_Orders()[0], outgoingMsg)
				} else {
					turn_off_lights()
				}
				//fmt.Printf("%sOrder to floor %d deleted, current floor = %d\n",def.ColB,queue.Get_Orders()[0],driver.Get_cur_floor())
				queue.Remove_first_element_in_orders()
				queue.Save_backup_to_file()
				driver.Set_button_lamp(def.BtnInside, driver.Get_cur_floor(), 0)
				open_and_close_door()
			}
		}
	}
}
Пример #2
0
func add_order_to_best_elev(rcvList map[rcvOrder][]rcvCost, newOrder rcvOrder) {
	if this_elevator_has_the_lowest_cost(rcvList[newOrder]) {
		//fmt.Printf("%sNew order added to floor = %d with cost = %d\n%s",def.ColB,helpFunc.Order_dir(newOrder.floor,newOrder.button),Cost(queue.Get_Orders(),helpFunc.Order_dir(newOrder.floor,newOrder.button)),def.ColN)
		queue.Set_Orders(queue.Update_orderlist(queue.Get_Orders(), queue.Order_direction(newOrder.floor, newOrder.button)))
		//fmt.Printf("%sUpdated orders = %v\n%s\n",def.ColB,queue.Get_Orders(),def.ColN)
		queue.Save_backup_to_file()
	}
}
Пример #3
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()
	}
}