|
| 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 | +} |
0 commit comments