Example #1
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	nextFloorChan := make(chan int)
	var doorCloseChan <-chan time.Time
	dirChan := make(chan datatypes.Direction)
	shareOrderChan := make(chan datatypes.ExternalOrder)
	receivedOrderChan := make(chan datatypes.ExternalOrder)
	shareCostChan := make(chan datatypes.CostInfo)
	receivedCostChan := make(chan datatypes.CostInfo)
	orderFinishedChan := make(chan int, 10)

	newInternalOrderChan := make(chan datatypes.InternalOrder)
	newExternalOrderChan := make(chan datatypes.ExternalOrder, 2)
	currentFloorToOrderManagerChan := make(chan int)
	currentFloorToElevControllerChan := make(chan int)
	setInternalLightsChan := make(chan datatypes.InternalOrder, 10)
	setExternalLightsChan := make(chan datatypes.ExternalOrder, 10)
	setDoorOpenLightChan := make(chan bool)
	setMotorDirectionChan := make(chan datatypes.Direction)

	if !network.InitNetworkHandler(shareOrderChan, receivedOrderChan, shareCostChan, receivedCostChan) {
		os.Exit(1)
	}
	manager.InitOrderManager(n_FLOORS, newInternalOrderChan, newExternalOrderChan, currentFloorToOrderManagerChan, orderFinishedChan, dirChan, receivedOrderChan, receivedCostChan, shareOrderChan, shareCostChan, nextFloorChan, setInternalLightsChan, setExternalLightsChan)
	ioHandling.InitIo(n_FLOORS, newInternalOrderChan, newExternalOrderChan, currentFloorToOrderManagerChan, currentFloorToElevControllerChan, setInternalLightsChan, setExternalLightsChan, setDoorOpenLightChan, setMotorDirectionChan)
	controller.InitElevController(n_FLOORS, nextFloorChan, currentFloorToElevControllerChan, doorCloseChan, dirChan, setDoorOpenLightChan, setMotorDirectionChan, orderFinishedChan)

	select {}
}
Example #2
0
func main() {

	runtime.GOMAXPROCS(runtime.NumCPU())

	shareOrderChan := make(chan datatypes.ExternalOrder)
	receivedOrderChan := make(chan datatypes.ExternalOrder)
	shareCostChan := make(chan network.CostInfo)
	receivedCostChan := make(chan network.CostInfo)

	network.InitNetworkHandler(shareOrderChan, receivedOrderChan, shareCostChan, receivedCostChan)

	//Deklarerer slice til bruk med ordre
	orders := make([]datatypes.ExternalOrder, 0) // Denne har null som argument fordi den er tom

	//Skriv ut alle meldingene som kommer inn på kanalen recievedOrderChan mens programmet lever
	go func() {
		for {
			addNewExternalOrdersToSlice(receivedOrderChan, &orders)
		}
	}()

	//Send en testordre
	for i := 0; i < 5; i++ {
		ex_order := datatypes.ExternalOrder{New_order: false, Executed_order: true, Floor: 2, Direction: 1}
		network.BroadcastExternalOrder(ex_order)
		time.Sleep(time.Millisecond * 1)
	}
	//Send en testordre til
	ex_order1 := datatypes.ExternalOrder{New_order: true, Executed_order: true, Floor: 2, Direction: 1}
	network.BroadcastExternalOrder(ex_order1)

	time.Sleep(time.Second * 2)

	fmt.Println(orders)

	fmt.Println("Lager/oppdaterer fil til heisordre")

	//createOrderBackupFile()	//Den er muligvis unødvendig. WriteFile i backupOrders lager også en fil
	backupOrders(orders)
	fmt.Println("Tester å hente inn igjen data fra fil")
	fmt.Println("Setter orders til 0: ")
	orders = make([]datatypes.ExternalOrder, 0)
	fmt.Println(orders)
	restoreOrders(&orders)
	fmt.Println("Skriver ut info hentet fra fil")
	fmt.Println(orders)

}