Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
de4758c563 | ||
![]() |
a85c9ccd66 | ||
![]() |
da78a00446 | ||
![]() |
ba3c55dc34 | ||
![]() |
e0950b44ee | ||
![]() |
76a036707f | ||
![]() |
258323f5b7 |
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@@ -36,9 +36,9 @@ jobs:
|
||||
run: |
|
||||
mkdir -p build
|
||||
if [ "${{ matrix.goos }}" == "windows" ]; then
|
||||
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -o build/tecamino-driver-artNet-${{ matrix.goos }}-${{ matrix.goarch }}.exe main.go
|
||||
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -trimpath -o build/tecamino-driver-artNet-${{ matrix.goos }}-${{ matrix.goarch }}.exe main.go
|
||||
else
|
||||
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -o build/tecamino-driver-artNet-${{ matrix.goos }}-${{ matrix.goarch }} main.go
|
||||
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -trimpath -o build/tecamino-driver-artNet-${{ matrix.goos }}-${{ matrix.goarch }} main.go
|
||||
fi
|
||||
|
||||
- name: Upload artifacts
|
||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
||||
.DS_Store
|
||||
*.cfg
|
||||
*.log
|
||||
artNetDriver-arm64
|
||||
tecamino-driver-artNet-linux-arm64
|
||||
|
@@ -82,7 +82,7 @@ func (d *ArtNetDriver) SetValue(bus string, address uint, value uint8) error {
|
||||
return fmt.Errorf("no dmx data on bus '%s' found", bus)
|
||||
}
|
||||
d.Buses[bus].Data.SetValue(address, value)
|
||||
return d.Buses[bus].SendData()
|
||||
return nil
|
||||
}
|
||||
|
||||
// connect to websocket server and listen to subscriptions
|
||||
@@ -134,3 +134,10 @@ func (d *ArtNetDriver) Connect(ip, id string, port uint) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// send data to all buses that the send flage is true
|
||||
func (d *ArtNetDriver) SendData() {
|
||||
for _, bus := range d.Buses {
|
||||
bus.Send <- bus.Data
|
||||
}
|
||||
}
|
||||
|
@@ -8,10 +8,12 @@ func (d *ArtNetDriver) Publish(pubs ...json_dataModels.Publish) error {
|
||||
if d.Subscriptions == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, pub := range pubs {
|
||||
if drv, ok := (d.Subscriptions)[pub.Uuid]; ok {
|
||||
d.SetValue(drv.Bus, drv.Address, uint8(pub.Value.(float64)))
|
||||
}
|
||||
}
|
||||
d.SendData()
|
||||
return nil
|
||||
}
|
||||
|
@@ -17,4 +17,5 @@ func (d *ArtNetDriver) Subscribe(subs ...json_dataModels.Subscription) {
|
||||
d.SetValue(drv.Bus, drv.Address, uint8(sub.Value.(float64)))
|
||||
}
|
||||
}
|
||||
d.SendData()
|
||||
}
|
||||
|
@@ -29,6 +29,7 @@ type Bus struct {
|
||||
Resubscribe *[]json_dataModels.Subscription `yaml:"-" json:"resubscribe"`
|
||||
Watchdog context.CancelFunc `yaml:"-" json:"-"`
|
||||
Reachable bool `yaml:"-" json:"-"`
|
||||
Send chan *DMX `yaml:"-" json:"-"`
|
||||
}
|
||||
|
||||
// adds new Art-Net interface to driver port 0 = 6454 (default art-net)
|
||||
@@ -102,13 +103,15 @@ func (b *Bus) Poll(interval time.Duration) error {
|
||||
}
|
||||
|
||||
// start bus
|
||||
func (b *Bus) Start(log *logging.Logger) {
|
||||
func (b *Bus) Start(log *logging.Logger) error {
|
||||
var ctx context.Context
|
||||
ctx, b.Watchdog = context.WithCancel(context.Background())
|
||||
|
||||
b.Send = make(chan *DMX, 1024)
|
||||
|
||||
go func() {
|
||||
var interval time.Duration = 10 * time.Second
|
||||
log.Info("bus.Start", fmt.Sprintf("device:%s ip:%s watchdog stopped", b.Name, b.Ip))
|
||||
log.Info("bus.Start", fmt.Sprintf("device:%s ip:%s watchdog starting", b.Name, b.Ip))
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
@@ -125,6 +128,8 @@ func (b *Bus) Start(log *logging.Logger) {
|
||||
interval = 5 * time.Second
|
||||
} else {
|
||||
b.Reachable = true
|
||||
// send data as a heartbeat for she ArtNet Protocol
|
||||
b.Send <- b.Data
|
||||
log.Info("bus.Start", fmt.Sprintf("device:%s ip:%s watchdog running", b.Name, b.Ip))
|
||||
interval = 30 * time.Second
|
||||
}
|
||||
@@ -132,26 +137,7 @@ func (b *Bus) Start(log *logging.Logger) {
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// stop bus
|
||||
func (b *Bus) Stop() {
|
||||
if b.Watchdog != nil {
|
||||
b.Watchdog()
|
||||
}
|
||||
}
|
||||
|
||||
// status bus
|
||||
func (b *Bus) Status() bool {
|
||||
return b.Watchdog != nil
|
||||
}
|
||||
|
||||
// send dmx data
|
||||
func (b *Bus) SendData() error {
|
||||
if !b.Reachable {
|
||||
return nil
|
||||
}
|
||||
// Send packet over UDP
|
||||
conn, err := net.DialUDP("udp", nil, &net.UDPAddr{
|
||||
IP: net.ParseIP(b.Ip),
|
||||
Port: *b.Port,
|
||||
@@ -160,11 +146,37 @@ func (b *Bus) SendData() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
go func() {
|
||||
defer conn.Close()
|
||||
//close send channel
|
||||
defer close(b.Send)
|
||||
|
||||
_, err = conn.Write(NewArtNetPackage(b.Data))
|
||||
for send := range b.Send {
|
||||
_, err = conn.Write(NewArtNetPackage(send))
|
||||
if err != nil {
|
||||
log.Error("bus.Start", err)
|
||||
return
|
||||
}
|
||||
time.Sleep(23 * time.Millisecond)
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
// stop bus
|
||||
func (b *Bus) Stop() {
|
||||
if b.Watchdog != nil {
|
||||
//cancels context
|
||||
b.Watchdog()
|
||||
//close send channel
|
||||
close(b.Send)
|
||||
}
|
||||
}
|
||||
|
||||
// status bus
|
||||
func (b *Bus) Status() bool {
|
||||
return b.Watchdog != nil
|
||||
}
|
||||
|
||||
func (b *Bus) ParsePayload(c *gin.Context) error {
|
||||
|
Reference in New Issue
Block a user