Пример #1
0
func Handle_msg(incomingMsg, outgoingMsg, costMsg, orderCompleted chan def.Message) {

	for {

		msg := <-incomingMsg
		const aliveTimeout = 6 * time.Second

		switch msg.Category {
		case def.Alive:
			//if connection exists
			if connection, exist := onlineElevs[msg.Addr]; exist {
				connection.Timer.Reset(aliveTimeout)
			} else {
				add_new_connection(msg.Addr, aliveTimeout)
			}

		case def.NewOrder:
			//fmt.Printf("%sNew external order recieved to floor %d %s \n", def.ColM, helpFunc.Order_dir(msg.Floor, msg.Button), def.ColN)
			driver.Set_button_lamp(msg.Button, msg.Floor, 1)
			costMsg := def.Message{Category: def.Cost, Floor: msg.Floor, Button: msg.Button, Cost: handleOrders.Cost(queue.Get_Orders(), queue.Order_direction(msg.Floor, msg.Button))}
			outgoingMsg <- costMsg

		case def.CompleteOrder:
			driver.Set_button_lamp(msg.Button, msg.Floor, 0)
			orderCompleted <- msg

		case def.Cost:
			//see handleOrders.assign_external_order
			costMsg <- msg
		}
	}
}
Пример #2
0
func turn_off_lights() {
	if queue.Get_Orders()[0] < 0 {
		driver.Set_button_lamp(def.BtnDown, driver.Get_cur_floor(), 0)
	} else {
		driver.Set_button_lamp(def.BtnUp, driver.Get_cur_floor(), 0)
	}
}
Пример #3
0
func set_order_light(buttontype, floor int) {
	if !external_order(buttontype) {
		driver.Set_button_lamp(buttontype, floor, 1)
	} else if ImConnected {
		driver.Set_button_lamp(buttontype, floor, 1)
	}
}
Пример #4
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()
			}
		}
	}
}