-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
55 lines (44 loc) · 1.13 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"
"log"
"github.com/tarm/serial"
)
const (
MESSAGE_PORT = "/tmp/scnet_m.str"
VIDEO_PORT = "/tmp/scnet_v.str"
BUFF_SIZE = 256
)
var (
address string
messagePort string
videoPort string
)
func main() {
addressFlag := flag.String("a", "128.114.59.16", "server ip")
mPort := flag.String("mp", "7892", "port for the message server")
vPort := flag.String("vp", "7893", "port for the video server")
baudRate := flag.Int("baud", 115200, "the baud rate for the serial connection")
serialDev := flag.String("serial", "/dev/ttyAMA0", "path of the serial device to use")
flag.Parse()
address = *addressFlag
messagePort = *mPort
videoPort = *vPort
// Setup serial
c := &serial.Config{Name: *serialDev, Baud: *baudRate}
serial, err := serial.OpenPort(c)
if err != nil {
log.Panic(err)
}
mch := make(chan string, BUFF_SIZE)
vch := make(chan string, BUFF_SIZE)
listen(MESSAGE_PORT, readLineHandler(mch))
listen(VIDEO_PORT, readLineHandler(vch))
w := &WiFly{
serial: serial,
remoteAddress: address,
messagePort: messagePort,
videoPort: videoPort,
}
w.handleWiFly(mch, vch)
}