Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
05409c2544 | ||
![]() |
b484745ed1 |
@@ -141,9 +141,6 @@ func (d *ArtNetDriver) Connect(ip, id string, port uint) error {
|
|||||||
// send data to all buses that the send flage is true
|
// send data to all buses that the send flage is true
|
||||||
func (d *ArtNetDriver) SendData() {
|
func (d *ArtNetDriver) SendData() {
|
||||||
for _, bus := range d.Buses {
|
for _, bus := range d.Buses {
|
||||||
if !bus.Reachable {
|
bus.Send = bus.Reachable
|
||||||
continue
|
|
||||||
}
|
|
||||||
bus.Send <- bus.Data
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -29,7 +29,7 @@ type Bus struct {
|
|||||||
Resubscribe *[]json_dataModels.Subscription `yaml:"-" json:"resubscribe"`
|
Resubscribe *[]json_dataModels.Subscription `yaml:"-" json:"resubscribe"`
|
||||||
Watchdog context.CancelFunc `yaml:"-" json:"-"`
|
Watchdog context.CancelFunc `yaml:"-" json:"-"`
|
||||||
Reachable bool `yaml:"-" json:"-"`
|
Reachable bool `yaml:"-" json:"-"`
|
||||||
Send chan *DMX `yaml:"-" json:"-"`
|
Send bool `yaml:"-" json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// adds new Art-Net interface to driver port 0 = 6454 (default art-net)
|
// adds new Art-Net interface to driver port 0 = 6454 (default art-net)
|
||||||
@@ -107,8 +107,6 @@ func (b *Bus) Start(log *logging.Logger) error {
|
|||||||
var ctx context.Context
|
var ctx context.Context
|
||||||
ctx, b.Watchdog = context.WithCancel(context.Background())
|
ctx, b.Watchdog = context.WithCancel(context.Background())
|
||||||
|
|
||||||
b.Send = make(chan *DMX, 1024)
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
var interval time.Duration = 10 * time.Second
|
var interval time.Duration = 10 * time.Second
|
||||||
log.Info("bus.Start", fmt.Sprintf("device:%s ip:%s watchdog starting", b.Name, b.Ip))
|
log.Info("bus.Start", fmt.Sprintf("device:%s ip:%s watchdog starting", b.Name, b.Ip))
|
||||||
@@ -129,7 +127,7 @@ func (b *Bus) Start(log *logging.Logger) error {
|
|||||||
} else {
|
} else {
|
||||||
b.Reachable = true
|
b.Reachable = true
|
||||||
// send data as a heartbeat for she ArtNet Protocol
|
// send data as a heartbeat for she ArtNet Protocol
|
||||||
b.Send <- b.Data
|
b.Send = true
|
||||||
log.Info("bus.Start", fmt.Sprintf("device:%s ip:%s watchdog running", b.Name, b.Ip))
|
log.Info("bus.Start", fmt.Sprintf("device:%s ip:%s watchdog running", b.Name, b.Ip))
|
||||||
interval = 30 * time.Second
|
interval = 30 * time.Second
|
||||||
}
|
}
|
||||||
@@ -148,17 +146,26 @@ func (b *Bus) Start(log *logging.Logger) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer conn.Close()
|
ticker := time.NewTicker(23 * time.Millisecond)
|
||||||
//close send channel
|
|
||||||
defer close(b.Send)
|
|
||||||
|
|
||||||
for send := range b.Send {
|
defer func() {
|
||||||
_, err = conn.Write(NewArtNetPackage(send))
|
b.Send = false
|
||||||
|
conn.Close()
|
||||||
|
ticker.Stop()
|
||||||
|
}()
|
||||||
|
|
||||||
|
for range ticker.C {
|
||||||
|
if !b.Send {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
b.Send = false
|
||||||
|
|
||||||
|
_, err = conn.Write(NewArtNetPackage(b.Data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("bus.Start", err)
|
log.Error("bus.Start", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
time.Sleep(23 * time.Millisecond)
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
return nil
|
return nil
|
||||||
@@ -169,8 +176,8 @@ func (b *Bus) Stop() {
|
|||||||
if b.Watchdog != nil {
|
if b.Watchdog != nil {
|
||||||
//cancels context
|
//cancels context
|
||||||
b.Watchdog()
|
b.Watchdog()
|
||||||
//close send channel
|
|
||||||
close(b.Send)
|
b.Send = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -12,10 +12,10 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// Time allowed to write a message to the peer.
|
// Time allowed to write a message to the peer.
|
||||||
writeWait = 10 * time.Second
|
writeWait = 40 * time.Second
|
||||||
|
|
||||||
// Time allowed to read the next pong message from the peer.
|
// Time allowed to read the next pong message from the peer.
|
||||||
pongWait = 10 * time.Second
|
pongWait = 40 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
|
Reference in New Issue
Block a user