-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpi.go
62 lines (53 loc) · 1.55 KB
/
rpi.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
package main
import (
"flag"
"fmt"
"github.com/Che4ter/rpi_brain/arduino"
"github.com/Che4ter/rpi_brain/brain"
"github.com/Che4ter/rpi_brain/configuration"
"github.com/Che4ter/rpi_brain/ipc"
"os"
"os/signal"
"time"
)
//Define Arguments
//var argSerialPort = flag.String("serialport", "/dev/null", "ardino serial port")
var argConfigurationFile = flag.String("config", "configuration.json", "configuration file path")
var configFile string
func init() {
//Parse Arguments
flag.Parse()
fmt.Println("***********************")
fmt.Println("Pren 2 - Team 9")
fmt.Println("== The Caterpillar ==")
fmt.Println("**** v2.0 - FINAL **** ")
fmt.Println("***********************")
fmt.Println("initializing...")
configFile = *argConfigurationFile
}
func main() {
conf, _ := configuration.ParseConfiguration(configFile)
//Define Channels
arduinoSendingBridge := make(chan arduino.ArduinoPacket)
arduinoReceivingBridge := make(chan arduino.ArduinoPacket)
brainBridge := make(chan int)
ipcBridge := make(chan string)
doneBridge := make(chan bool)
//Start Routines
go ipc.RunUnixSocketServer(ipcBridge, conf)
go arduino.RunArduinoServer(arduinoSendingBridge, arduinoReceivingBridge, conf)
go brain.StartBrain(brainBridge, ipcBridge, conf, doneBridge, arduinoSendingBridge, arduinoReceivingBridge)
//Wait for Stop
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, os.Kill)
for {
select {
default:
time.Sleep(500 * time.Millisecond)
case <-quit:
fmt.Println("shutdown caterpillar... ")
fmt.Println("bye :'( ")
return
}
}
}