-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
63 lines (54 loc) · 1.59 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
56
57
58
59
60
61
62
63
package main
import (
"./FSM"
"./driver"
"./network/UDP"
"./queue"
"./source"
"os"
"os/signal"
"syscall"
)
func runFSM(deleteOrderChan chan source.Order, onlineStatus chan bool) {
var floorNumber int = -1
for {
FSM.UpdateElevator()
floorNumber = driver.ElevatorGetFloorSensorSignal()
FSM.CheckIfElevatorIsStuck(floorNumber)
if floorNumber != -1 {
driver.ElevatorSetFloorIndicator(floorNumber)
FSM.ElevatorHasArrivedAtFloor(floorNumber, deleteOrderChan, onlineStatus)
FSM.CheckFloorAndSetElevetorDirection(deleteOrderChan, onlineStatus)
}
}
}
func handleProgramKill() {
c := make(chan os.Signal, 2)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
<-c
driver.ElevatorSetMotorDirection(2)
os.Exit(1)
}
func main() {
var msg source.ElevInfo
port := ":22017"
msg.ID = UDP.GetLocalID()
driver.InitializeElevator()
FSM.ElevatorStartUp()
queue.Init(msg.ID)
newMsgChanRecive := make(chan source.ElevInfo, 1)
newMsgChanTransmit := make(chan source.ElevInfo, 1)
newOrderChan := make(chan source.Order, 10)
deleteOrderChan := make(chan source.Order, 10)
deleteAddOrderChan := make(chan source.Order, 1)
onlineStatus := make(chan bool, 1)
go UDP.Receiving(port, newMsgChanRecive)
go UDP.TransmittingBroadcast(port, msg, newMsgChanTransmit, onlineStatus)
go queue.UpdateOrdersAfterReceiving(newMsgChanRecive, deleteAddOrderChan)
go queue.UpdateElevatorInfoBeforeTransmitting(newMsgChanTransmit, newOrderChan, deleteOrderChan, deleteAddOrderChan, msg)
go queue.CheckForOrdersAndDistribute(newOrderChan)
go runFSM(deleteOrderChan, onlineStatus)
for {
handleProgramKill()
}
}