Example #1
0
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)
	}
}
Example #2
0
//Functions relating to internal behaviour
func controlInit(initializeAddressChannel chan string, blockUserChannel chan bool, blockNetworkChannel chan bool, sendNetworkChannel chan map[string]ElevatorNode, receiveNetworkChannel chan map[string]ElevatorNode, sendElevatorChannel chan map[string]ElevatorNode, receiveElevatorChannel chan map[string]ElevatorNode) {
	driver.Elev_init() //Initialize hardware
	var tempMatrix = make(map[string]ElevatorNode)
	elevatorMatrix = make(map[string]ElevatorNode)

	var preInitialOrders = new(ElevatorNode)
	err := Load(backupOrderFilePath, preInitialOrders)
	elevatorHasPreviouslyCrashed := Check(err)
	blockUserChannel <- elevatorHasPreviouslyCrashed
	blockNetworkChannel <- elevatorHasPreviouslyCrashed
	if elevatorHasPreviouslyCrashed {
		completePreCrashOrders(preInitialOrders, sendElevatorChannel, receiveElevatorChannel)
		blockUserChannel <- false
		blockNetworkChannel <- false
	}

	LocalAddress = receiveAddressFromNetwork(initializeAddressChannel)
	LocalElevator := getElevatorState()
	elevatorMatrix[LocalAddress] = LocalElevator
	if LocalAddress == "0" {
		elevatorIsOffline = true
	} else {
		elevatorIsOffline = false
		copyMapByValue(elevatorMatrix, tempMatrix)
		sendNetworkChannel <- tempMatrix
		tempMatrix = <-receiveNetworkChannel
		copyMapByValue(tempMatrix, elevatorMatrix)
	}

}
Example #3
0
//Initialization function
func elevatorModuleInit() {
	elevatorMatrix = make(map[string]control.ElevatorNode)
	matrixBeingHandled = make(map[string]control.ElevatorNode)
	for i := 0; i < driver.N_BUTTONS; i++ {
		for j := 0; j < driver.N_FLOORS; j++ {
			lightArray[i][j] = 0
		}
	}
	for i := 0; i < 2; i++ {
		for j := 0; j < driver.N_FLOORS; j++ {
			orderArray[i][j] = false
		}
	}
	driver.Elev_init()

	floor := getCurrentFloor()
	for floor == -1 {
		setDirection(driver.DIRN_DOWN)
		floor = getCurrentFloor()
	}
	setDirection(driver.DIRN_STOP)
	currentFloor = floor
	driver.Elev_set_floor_indicator(currentFloor)
	currentDirection = Still
}
Example #4
0
func userModuleInit(blockUserChan chan bool) {
	driver.Elev_init()
	waitBecauseElevatorsHavePreviouslyCrashed := <-blockUserChan
	if waitBecauseElevatorsHavePreviouslyCrashed {
		waitBecauseElevatorsHavePreviouslyCrashed = <-blockUserChan
	}
}
Example #5
0
func Elev_init() {
	fmt.Printf("%sInitialising elevator, please wait...%s\n", def.ColG, def.ColN)
	driver.Elev_init()
	driver.Set_motor_dir(-1)
	defer driver.Set_motor_dir(0)

	queue.Get_backup_from_file()

	for {
		if driver.Get_floor_sensor_signal() != -1 {
			fmt.Printf("%sInitialising was successful%s\n", def.ColG, def.ColN)
			return
		}
	}
}