feat(artnet): Add working artnet integration · StageAutoControl/controller@a25fe72 · GitHub
Skip to content

Commit a25fe72

Browse files
committed
feat(artnet): Add working artnet integration
1 parent 1e90280 commit a25fe72

19 files changed

Lines changed: 376 additions & 20 deletions

.editorconfig

Lines changed: 7 additions & 0 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
vendor
22
bin
33
.envrc
4-
4+
/controller

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM alpine
2+
3+
MAINTAINER Alexander Pinnecke <alexander.pinnecke@googlemail.com>
4+
5+
ADD bin/controller_linux /controller
6+
7+
ENTRYPOINT ["/controller"]

LICENSE.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
MIT License
2+
===========
3+
4+
Copyright (C) 2017 Alexander Pinnecke / StageAutoControl Contributors
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7+
8+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9+
10+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Makefile

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
PACKAGES:=$(go list ./... | grep -v /vendor/)
1+
PACKAGES:=$$(go list ./... | grep -v /vendor/)
22

3-
.phony: build test fmt
3+
.PHONY: build build build-arm build-linux build-docker test fmt all
44

5-
build:
6-
@mkdir -p bin
7-
go build -o bin/controller .
5+
all: build-all
86

97
install:
108
@glide install --strip-vendor
@@ -19,23 +17,44 @@ lint:
1917
@golint ./... | grep -vE "vendor|\.pb\.go" || printf ""
2018

2119
test:
22-
@go test ${PACKAGES}
20+
go test -v $(PACKAGES)
2321

2422
proto:
2523
protoc -I "cntl/transport" --go_out="cntl/transport" cntl/transport/dmx.proto
2624

27-
start-playback-visualizer: build
28-
./bin/controller playback \
25+
start-playback-visualizer: build-darwin
26+
./bin/controller_darwin playback \
2927
--data-dir "${SAC_DATA_DIR}" \
3028
--transport visualizer \
3129
--visualizer-endpoint localhost:1337 \
3230
"${SONG}"
3331

34-
start-playback-buffer: build
35-
./bin/controller playback \
32+
start-playback-buffer: build-darwin
33+
./bin/controller_darwin playback \
3634
--data-dir "${SAC_DATA_DIR}" \
35+
--transport buffer \
3736
"${SONG}"
3837

39-
start-api: build
40-
./bin/controller api \
38+
start-playback-artnet: build-darwin
39+
./bin/controller_darwin playback \
40+
--data-dir "${SAC_DATA_DIR}" \
41+
--transport artnet \
42+
"${SONG}"
43+
44+
start-api: build-darwin
45+
./bin/controller_darwin api \
4146
--data-dir "${SAC_DATA_DIR}"
47+
48+
build-all: build-darwin build-arm build-linux build-docker
49+
50+
build-darwin:
51+
go build -o bin/controller_darwin .
52+
53+
build-linux:
54+
GOOS=linux CGO_ENABLED=0 go build -a -ldflags '-s' -installsuffix cgo -o bin/controller_linux .
55+
56+
build-arm:
57+
GOOS=linux GOARCH=arm GOARM=6 CGO_ENABLED=0 go build -a -ldflags '-s' -installsuffix cgo -o bin/controller_arm .
58+
59+
build-docker: build-linux
60+
docker build -t stageautocontrol/controller .

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@
55
Since this is a cobra application `controller help` displays a verbose help.
66

77

8-
## Credits
8+
## ArtNet
9+
10+
### Links
11+
12+
- [Terminology/Glossary](http://art-net.org.uk/?page_id=161#glossary)
13+
14+
### Credits
915

1016
> Art-Net™ Designed by and Copyright Artistic Licence Holdings Ltd
1117
1218
http://www.artisticlicence.com/WebSiteMaster/User%20Guides/art-net.pdf
19+
20+
MIT Licensed.

Vagrantfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Vagrant.configure("2") do |config|
2+
config.vm.define "artnet" do |nodeconfig|
3+
nodeconfig.ssh.forward_agent = true
4+
nodeconfig.ssh.insert_key = false
5+
nodeconfig.vm.box = "bento/centos-7.3"
6+
nodeconfig.vm.hostname = "artnet"
7+
nodeconfig.vm.network "private_network", ip: "192.168.50.4", netmask: "24"
8+
9+
nodeconfig.vm.provider :virtualbox do |v|
10+
v.name = "artnet"
11+
v.memory = 512
12+
v.cpus = 1
13+
v.gui = false
14+
end
15+
end
16+
end

cmd/artnet/node.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright © 2017 Alexander Pinnecke <alexander.pinnecke@googlemail.com>
2+
//
3+
4+
package artnet
5+
6+
import (
7+
"fmt"
8+
"log"
9+
"math/rand"
10+
"net"
11+
"os"
12+
"os/signal"
13+
14+
"github.com/StageAutoControl/controller/cmd"
15+
artnetTransport "github.com/StageAutoControl/controller/cntl/transport/artnet"
16+
"github.com/jsimonetti/go-artnet"
17+
"github.com/jsimonetti/go-artnet/packet/code"
18+
"github.com/spf13/cobra"
19+
)
20+
21+
// ArtNetNode represents the ArtNetTest command
22+
var ArtNetNode = &cobra.Command{
23+
Use: "artnet-node",
24+
Short: "ArtNet node to test network communication",
25+
Long: ``,
26+
Run: func(cmd *cobra.Command, args []string) {
27+
var ip net.IP
28+
var err error
29+
30+
log.Println("InterfaceName is empty, searching for suitable one ...")
31+
ip, err = artnetTransport.FindArtNetIP()
32+
if err != nil {
33+
log.Fatal(err)
34+
}
35+
36+
log.Printf("Using interface with IP %s", ip.String())
37+
38+
if len(ip) == 0 {
39+
log.Fatal("No IP found")
40+
}
41+
42+
n := artnet.NewNode(fmt.Sprintf("node-%d", rand.Int()), code.StNode, ip)
43+
44+
if err := n.Start(); err != nil {
45+
log.Fatal(err)
46+
}
47+
48+
c := make(chan os.Signal, 1)
49+
signal.Notify(c, os.Interrupt, os.Kill)
50+
<-c
51+
52+
log.Println("Stopping node ...")
53+
n.Stop()
54+
},
55+
}
56+
57+
func init() {
58+
cmd.RootCmd.AddCommand(ArtNetNode)
59+
}

cmd/artnet/server.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright © 2017 Alexander Pinnecke <alexander.pinnecke@googlemail.com>
2+
//
3+
4+
package artnet
5+
6+
import (
7+
"fmt"
8+
"log"
9+
"net"
10+
"runtime"
11+
"sync"
12+
"time"
13+
14+
"github.com/StageAutoControl/controller/cmd"
15+
artnetTransport "github.com/StageAutoControl/controller/cntl/transport/artnet"
16+
"github.com/jsimonetti/go-artnet"
17+
"github.com/spf13/cobra"
18+
)
19+
20+
// ArtNetServer represents the ArtNetTest command
21+
var ArtNetServer = &cobra.Command{
22+
Use: "artnet-server",
23+
Short: "ArtNet server to test network communication",
24+
Long: ``,
25+
Run: func(cmd *cobra.Command, args []string) {
26+
var ip net.IP
27+
var err error
28+
29+
log.Println("InterfaceName is empty, searching for suitable one ...")
30+
ip, err = artnetTransport.FindArtNetIP()
31+
if err != nil {
32+
log.Fatal(err)
33+
}
34+
35+
log.Printf("Using interface with IP %s", ip.String())
36+
37+
if len(ip) == 0 {
38+
log.Fatal("No IP found")
39+
}
40+
41+
c := artnet.NewController("controller-1", ip)
42+
var wg sync.WaitGroup
43+
44+
go func() {
45+
wg.Add(1)
46+
if err := c.Start(); err != nil {
47+
log.Fatal(err)
48+
}
49+
50+
wg.Done()
51+
}()
52+
53+
time.Sleep(10 * time.Second)
54+
c.SendDMXToAddress([512]byte{0x00, 0xff, 0x00, 0xff, 0x00}, artnet.Address{Net: 0, SubUni: 0})
55+
time.Sleep(2 * time.Second)
56+
c.SendDMXToAddress([512]byte{0xff, 0x00, 0x00, 0xff, 0x00}, artnet.Address{Net: 0, SubUni: 0})
57+
time.Sleep(2 * time.Second)
58+
c.SendDMXToAddress([512]byte{0x00, 0x00, 0xff, 0xff, 0x00}, artnet.Address{Net: 0, SubUni: 0})
59+
time.Sleep(2 * time.Second)
60+
c.SendDMXToAddress([512]byte{}, artnet.Address{Net: 0, SubUni: 0})
61+
time.Sleep(2 * time.Second)
62+
63+
c.Stop()
64+
wg.Wait()
65+
66+
fmt.Printf("num: %d", runtime.NumGoroutine())
67+
},
68+
}
69+
70+
func init() {
71+
cmd.RootCmd.AddCommand(ArtNetServer)
72+
}

cmd/playback.go

Lines changed: 9 additions & 1 deletion

0 commit comments

Comments
 (0)