-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
55 lines (43 loc) · 1.35 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"flag"
"math/rand"
"time"
"./config"
"./elevio"
"./hallOrderManager"
"./localElevatorFSM"
"./localOrderDelegation"
"./network"
)
func main() {
elevatorPort := flag.String("port", "15657", "port number of the elevator server")
flag.Parse()
rand.Seed(time.Now().UTC().UnixNano())
elevio.Init("localhost:"+*elevatorPort, config.N_FLOORS)
// IO Channels //
drv_buttons := make(chan elevio.ButtonEvent)
drv_floors := make(chan int)
drv_obstr := make(chan bool)
drv_stop := make(chan bool)
// Order Manager Channels //
networkChannels := network.CreateNetworkChannelStruct()
cabOrderChannel := make(chan int)
hallOrderChannel := make(chan localOrderDelegation.LocalOrder)
fsmChannels := localElevatorFSM.CreateFSMChannelStruct()
// Hardware //
go elevio.PollButtons(drv_buttons)
go elevio.PollFloorSensor(drv_floors)
go elevio.PollObstructionSwitch(drv_obstr)
go elevio.PollStopButton(drv_stop)
// Network //
id := network.GetNodeID()
go network.NetworkNode(id, fsmChannels, networkChannels)
//Elevator//
go hallOrderManager.OrderManager(id, hallOrderChannel, fsmChannels, networkChannels)
go localOrderDelegation.OrderDelegator(drv_buttons, cabOrderChannel, hallOrderChannel)
go localElevatorFSM.RunElevatorFSM(cabOrderChannel, fsmChannels, drv_floors, drv_obstr, drv_stop)
for {
time.Sleep(time.Second * 10)
}
}