forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
master.go
55 lines (49 loc) · 1010 Bytes
/
master.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 gobot
import "time"
type Master struct {
Robots []Robot
}
func GobotMaster() *Master {
m := new(Master)
return m
}
func (m *Master) Start() {
for s := range m.Robots {
go m.Robots[s].Start()
}
for {
time.Sleep(10 * time.Millisecond)
}
}
func (m *Master) FindRobot(name string) *Robot {
for s := range m.Robots {
if m.Robots[s].Name == name {
return &m.Robots[s]
}
}
return nil
}
func (m *Master) FindRobotDevice(name string, device string) *Device {
for r := range m.Robots {
if m.Robots[r].Name == name {
for d := range m.Robots[r].devices {
if m.Robots[r].devices[d].Name == device {
return m.Robots[r].devices[d]
}
}
}
}
return nil
}
func (m *Master) FindRobotConnection(name string, connection string) *Connection {
for r := range m.Robots {
if m.Robots[r].Name == name {
for c := range m.Robots[r].connections {
if m.Robots[r].connections[c].Name == connection {
return m.Robots[r].connections[c]
}
}
}
}
return nil
}