func detectAndSendExternalButtonCall(newExternalOrderChan chan datatypes.ExternalOrder, n_floors int) { var order datatypes.ExternalOrder order.New_order = true order.Executed_order = false for button := driver.BUTTON_OUTSIDE_UP; button <= driver.BUTTON_OUTSIDE_DOWN; button++ { for floor := 0; floor < n_floors; floor++ { if driver.Elevator_is_button_pushed(button, floor) { order.Floor = floor if button == driver.BUTTON_OUTSIDE_UP { order.Direction = int(datatypes.UP) } else { order.Direction = int(datatypes.DOWN) } if (order.Floor != external_button_control_variable.Floor) && (order.Direction != external_button_control_variable.Direction) { newExternalOrderChan <- order external_button_control_variable = order external_button_control_variable.Timestamp = time.Now().Unix() } else if (time.Now().Unix() - external_button_control_variable.Timestamp) > 2 { external_button_control_variable.Timestamp = time.Now().Unix() newExternalOrderChan <- order } return } } } }
func handleSharedOrder(order datatypes.ExternalOrder, received_order bool, shareCostChan chan datatypes.CostInfo, receivedCostChan chan datatypes.CostInfo, shareOrderChan chan datatypes.ExternalOrder) { order.Timestamp = time.Now().Unix() if !(received_order) { shareOrderChan <- order } updateSharedOrders(order) if !(order.Executed_order) { cost := calculateCost(order) shareCostChan <- cost add_order := orderOnAuction(cost, receivedCostChan) if add_order { updatePrivateOrders(order) findNextFloorToGoTo() } } }