fix missing subscribe and publish on artNet Protocol
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"artNet/cfg"
|
||||
"artNet/models"
|
||||
ws "artNet/websocket"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"path"
|
||||
|
||||
@@ -101,7 +102,23 @@ func (d *ArtNetDriver) Connect(ip, id string, port uint) error {
|
||||
}
|
||||
|
||||
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()
|
||||
@@ -112,10 +129,8 @@ func (d *ArtNetDriver) Connect(ip, id string, port uint) error {
|
||||
d.Log.Error("websocket send data", err)
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case err := <-errChan:
|
||||
for err := range 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