Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
473eb22b97 |
@@ -4,6 +4,7 @@ import (
|
|||||||
"artNet/cfg"
|
"artNet/cfg"
|
||||||
"artNet/models"
|
"artNet/models"
|
||||||
ws "artNet/websocket"
|
ws "artNet/websocket"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
@@ -101,7 +102,23 @@ func (d *ArtNetDriver) Connect(ip, id string, port uint) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
client.OnMessage = func(data []byte) {
|
client.OnMessage = func(data []byte) {
|
||||||
fmt.Println(100, string(data))
|
|
||||||
|
request := json_data.NewResponse()
|
||||||
|
err = json.Unmarshal(data, &request)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if request.Subscribe != nil {
|
||||||
|
d.Subscribe(request.Subscribe...)
|
||||||
|
}
|
||||||
|
if request.Publish != nil {
|
||||||
|
d.Publish(request.Publish...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
d.Log.Error("artNet.Connect", err)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
req := json_data.NewRequest()
|
req := json_data.NewRequest()
|
||||||
@@ -112,10 +129,8 @@ func (d *ArtNetDriver) Connect(ip, id string, port uint) error {
|
|||||||
d.Log.Error("websocket send data", err)
|
d.Log.Error("websocket send data", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for err := range errChan {
|
||||||
select {
|
return err
|
||||||
case err := <-errChan:
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
17
driver/publish.go
Normal file
17
driver/publish.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package driver
|
||||||
|
|
||||||
|
import (
|
||||||
|
json_dataModels "github.com/tecamino/tecamino-json_data/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
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)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
Reference in New Issue
Block a user