예제 #1
0
func main() {
	eventCh := def.EventChan{
		FloorReached: make(chan int),
		DoorTimeout:  make(chan bool),
		DeadElevator: make(chan int, 10),
	}
	hwCh := def.HardwareChan{
		MotorDir:       make(chan int, 10),
		FloorLamp:      make(chan int, 10),
		DoorLamp:       make(chan bool, 10),
		BtnPressed:     make(chan def.BtnPress, 10),
		DoorTimerReset: make(chan bool, 10),
	}
	msgCh := def.MessageChan{
		Outgoing:  make(chan def.Message, 10),
		Incoming:  make(chan def.Message, 10),
		CostReply: make(chan def.Message, 10),
		NumOnline: make(chan int),
	}

	//Initialization
	startFloor := hw.Init()
	fsm.Init(eventCh, hwCh, startFloor)
	network.Init(msgCh.Outgoing, msgCh.Incoming)
	q.RunBackup(msgCh.Outgoing)

	go EventHandler(eventCh, msgCh, hwCh)
	go assigner.CollectCosts(msgCh.CostReply, msgCh.NumOnline)
	go safeKill()

	hold := make(chan bool)
	<-hold
}
예제 #2
0
파일: main.go 프로젝트: eivindjk/SanntidGo
func main() {
	ch := fsm.Channels{
		NewOrder:          make(chan bool, 10),
		FloorReached:      make(chan int, 10),
		MotorDir:          make(chan int, 10),
		DoorLight:         make(chan bool),
		NewFloor:          make(chan int),
		OrderTimerReset:   make(chan bool),
		OrderTimerTimeout: make(chan bool),
	}

	driver.Elev_init()
	fsm.Init(ch)
	network.Init(outgoingMsg, incomingMsg, incomingTcpMsg)

	go readChannels(ch)
	go getButtons()
	go updateFloor(ch)
	go syncLights()
	go handleDeadElevator(ch)

	go def.MegaPrint(onlineLifts)

	go safeKill()
	for {
		time.Sleep(time.Second)
	}
}
예제 #3
0
func main() {
	if _, err := os.Open(config.QUEUE_FILENAME); err == nil {
		BackupHold()
		queue.FileRead(config.QUEUE_FILENAME)
		network.Init(ch_outgoing_msg, ch_incoming_msg, ch_new_elev, ch_main_alive)
	} else {
		network.Init(ch_outgoing_msg, ch_incoming_msg, ch_new_elev, ch_main_alive)
		time.Sleep(time.Millisecond)
		if _, err := os.Create(config.QUEUE_FILENAME); err != nil {
			log.Fatal("FATAL: Could not create queue file!")
		}
	}
	backup := exec.Command("gnome-terminal", "-x", "sh", "-c", "go run main/main.go")
	backup.Run()

	if !hardware.Init() {
		log.Fatal("Unable to initialize elevator hardware!")
	}
	hardware.SetMotorDirection(fsm.ChooseNewDirection())
	go MessageServer()
	go hardware.ReadButtons(ch_button_pressed)
	go hardware.SetLights()
	go hardware.FloorPoller(ch_floor_poll)
	go StateSpammer()
	go fsm.EventOrderReceived()
	fsm.Init(ch_outgoing_msg, ch_new_order)

	log.Printf("Elev addr: %s", config.Laddr)

	for {
		select {
		case button := <-ch_button_pressed:
			ch_new_order <- button
			if button.Button_type != config.BUTTON_COMMAND {
				ch_outgoing_msg <- config.Message{Msg_type: config.ADD_ORDER, Button: button}
			}
		case floor := <-ch_floor_poll:
			fsm.EventReachedFloor(floor)
		}
	}
}
예제 #4
0
파일: main.go 프로젝트: Aarvold/Heismappe
func main() {

	elevRun.Elev_init()

	go network.Init(outgoingMsg, incomingMsg)

	go elevRun.Run_elev(outgoingMsg)
	go handleOrders.Handle_orders(outgoingMsg, incomingMsg, costMsg, orderCompleted)
	go communication.Handle_msg(incomingMsg, outgoingMsg, costMsg, orderCompleted)

	go quit_program(quitChan)
	<-quitChan
}