Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
b5d9d96c52 |
@@ -27,14 +27,19 @@ func NewClient(log *logging.Logger) *Client {
|
|||||||
return &c
|
return &c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Connect to websocket server
|
||||||
|
// ip: ip address of server
|
||||||
func (c *Client) Connect(ip, id string, port uint) (err error) {
|
func (c *Client) Connect(ip, id string, port uint) (err error) {
|
||||||
c.conn, _, err = websocket.Dial(c.ctx, fmt.Sprintf("ws://%s:%d/ws?id=%s", ip, port, id), nil)
|
c.conn, _, err = websocket.Dial(c.ctx, fmt.Sprintf("ws://%s:%d/ws?id=%s", ip, port, id), nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close connection to websocket server
|
||||||
func (c *Client) Disconnect() {
|
func (c *Client) Disconnect() {
|
||||||
c.cancel()
|
c.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Subscribe to websocket server
|
||||||
func (c *Client) Subscribe(id string) error {
|
func (c *Client) Subscribe(id string) error {
|
||||||
|
|
||||||
req := json_data.NewRequest()
|
req := json_data.NewRequest()
|
||||||
|
@@ -60,8 +60,8 @@ func (d *ArtNetDriver) LoadCfg() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, b := range d.Buses {
|
for name, b := range d.Buses {
|
||||||
d.NewBus(b.Name, b.Ip, *b.Port)
|
d.NewBus(name, b.Ip, *b.Port)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -77,10 +77,17 @@ func (d *ArtNetDriver) SetValue(bus string, address uint, value uint8) error {
|
|||||||
if _, ok := d.Buses[bus]; !ok {
|
if _, ok := d.Buses[bus]; !ok {
|
||||||
return fmt.Errorf("no bus '%s' found", bus)
|
return fmt.Errorf("no bus '%s' found", bus)
|
||||||
}
|
}
|
||||||
|
if d.Buses[bus].Data == nil {
|
||||||
|
return fmt.Errorf("no dmx data on bus '%s' found", bus)
|
||||||
|
}
|
||||||
d.Buses[bus].Data.SetValue(address, value)
|
d.Buses[bus].Data.SetValue(address, value)
|
||||||
return d.Buses[bus].SendData()
|
return d.Buses[bus].SendData()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// connect to websocket server and listen to subscriptions
|
||||||
|
// ip: ip address of server
|
||||||
|
// id: id of driver
|
||||||
|
// port: port of server
|
||||||
func (d *ArtNetDriver) Connect(ip, id string, port uint) error {
|
func (d *ArtNetDriver) Connect(ip, id string, port uint) error {
|
||||||
d.Conn = client.NewClient(d.Log)
|
d.Conn = client.NewClient(d.Log)
|
||||||
if err := d.Conn.Connect(ip, id, port); err != nil {
|
if err := d.Conn.Connect(ip, id, port); err != nil {
|
||||||
|
@@ -83,7 +83,7 @@ func (d *ArtNetDriver) RemoveBus(c *gin.Context) {
|
|||||||
if _, ok := d.Buses[busPayload.Name]; !ok {
|
if _, ok := d.Buses[busPayload.Name]; !ok {
|
||||||
r := json_dataModels.NewResponse()
|
r := json_dataModels.NewResponse()
|
||||||
r.SetMessage("bus " + busPayload.Name + " not found")
|
r.SetMessage("bus " + busPayload.Name + " not found")
|
||||||
c.JSON(http.StatusOK, r)
|
c.JSON(http.StatusBadRequest, r)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
delete(d.Buses, busPayload.Name)
|
delete(d.Buses, busPayload.Name)
|
||||||
@@ -114,7 +114,6 @@ func (d *ArtNetDriver) Start(c *gin.Context) {
|
|||||||
r := json_dataModels.NewResponse()
|
r := json_dataModels.NewResponse()
|
||||||
r.SetMessage(fmt.Sprintf("bus '%s' running", busPayload.Name))
|
r.SetMessage(fmt.Sprintf("bus '%s' running", busPayload.Name))
|
||||||
c.JSON(http.StatusOK, r)
|
c.JSON(http.StatusOK, r)
|
||||||
d.cfgHandler.SaveCfg(*d)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ArtNetDriver) Stop(c *gin.Context) {
|
func (d *ArtNetDriver) Stop(c *gin.Context) {
|
||||||
@@ -137,7 +136,39 @@ func (d *ArtNetDriver) Stop(c *gin.Context) {
|
|||||||
r := json_dataModels.NewResponse()
|
r := json_dataModels.NewResponse()
|
||||||
r.SetMessage(fmt.Sprintf("bus '%s' stopped", busPayload.Name))
|
r.SetMessage(fmt.Sprintf("bus '%s' stopped", busPayload.Name))
|
||||||
c.JSON(http.StatusOK, r)
|
c.JSON(http.StatusOK, r)
|
||||||
d.cfgHandler.SaveCfg(*d)
|
}
|
||||||
|
|
||||||
|
func (d *ArtNetDriver) Resubscribe(c *gin.Context) {
|
||||||
|
_, err := auth.GetIDFromQuery(c)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
r := json_data.NewResponse()
|
||||||
|
r.SetError()
|
||||||
|
r.SetMessage("id: " + err.Error())
|
||||||
|
c.JSON(http.StatusBadRequest, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
busPayload := models.Bus{}
|
||||||
|
if err := busPayload.ParsePayload(c); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := d.Buses[busPayload.Name]; !ok {
|
||||||
|
r := json_dataModels.NewResponse()
|
||||||
|
r.SetMessage("bus " + busPayload.Name + " not found")
|
||||||
|
c.JSON(http.StatusBadRequest, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if busPayload.Resubscribe == nil {
|
||||||
|
r := json_dataModels.NewResponse()
|
||||||
|
r.SetMessage("no resubscriptions in request")
|
||||||
|
c.JSON(http.StatusBadRequest, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
d.Subscribe(*busPayload.Resubscribe...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ArtNetDriver) Status(c *gin.Context) {
|
func (d *ArtNetDriver) Status(c *gin.Context) {
|
||||||
|
2
go.mod
2
go.mod
@@ -9,7 +9,7 @@ require (
|
|||||||
github.com/gin-gonic/gin v1.10.0
|
github.com/gin-gonic/gin v1.10.0
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
github.com/tatsushid/go-fastping v0.0.0-20160109021039-d7bb493dee3e
|
github.com/tatsushid/go-fastping v0.0.0-20160109021039-d7bb493dee3e
|
||||||
github.com/tecamino/tecamino-json_data v0.0.12
|
github.com/tecamino/tecamino-json_data v0.0.13
|
||||||
github.com/tecamino/tecamino-logger v0.2.0
|
github.com/tecamino/tecamino-logger v0.2.0
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
4
go.sum
4
go.sum
@@ -65,8 +65,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
|
|||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/tatsushid/go-fastping v0.0.0-20160109021039-d7bb493dee3e h1:nt2877sKfojlHCTOBXbpWjBkuWKritFaGIfgQwbQUls=
|
github.com/tatsushid/go-fastping v0.0.0-20160109021039-d7bb493dee3e h1:nt2877sKfojlHCTOBXbpWjBkuWKritFaGIfgQwbQUls=
|
||||||
github.com/tatsushid/go-fastping v0.0.0-20160109021039-d7bb493dee3e/go.mod h1:B4+Kq1u5FlULTjFSM707Q6e/cOHFv0z/6QRoxubDIQ8=
|
github.com/tatsushid/go-fastping v0.0.0-20160109021039-d7bb493dee3e/go.mod h1:B4+Kq1u5FlULTjFSM707Q6e/cOHFv0z/6QRoxubDIQ8=
|
||||||
github.com/tecamino/tecamino-json_data v0.0.12 h1:S4Y+WcfQNrin7P73ZI+4eJWh62IwJVhriRsPGGM8N34=
|
github.com/tecamino/tecamino-json_data v0.0.13 h1:hugbmCgXXh0F7YQAEbbJYHkSdq1caejD7SajDiMs42I=
|
||||||
github.com/tecamino/tecamino-json_data v0.0.12/go.mod h1:LLlyD7Wwqplb2BP4PeO86EokEcTRidlW5MwgPd1T2JY=
|
github.com/tecamino/tecamino-json_data v0.0.13/go.mod h1:LLlyD7Wwqplb2BP4PeO86EokEcTRidlW5MwgPd1T2JY=
|
||||||
github.com/tecamino/tecamino-logger v0.2.0 h1:NPH/Gg9qRhmVoW8b39i1eXu/LEftHc74nyISpcRG+XU=
|
github.com/tecamino/tecamino-logger v0.2.0 h1:NPH/Gg9qRhmVoW8b39i1eXu/LEftHc74nyISpcRG+XU=
|
||||||
github.com/tecamino/tecamino-logger v0.2.0/go.mod h1:0M1E9Uei/qw3e3WA1x3lBo1eP3H5oeYE7GjYrMahnj8=
|
github.com/tecamino/tecamino-logger v0.2.0/go.mod h1:0M1E9Uei/qw3e3WA1x3lBo1eP3H5oeYE7GjYrMahnj8=
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
||||||
|
13
main.go
13
main.go
@@ -21,6 +21,7 @@ func main() {
|
|||||||
serverPort := flag.Uint("serverPort", 8100, "port of server")
|
serverPort := flag.Uint("serverPort", 8100, "port of server")
|
||||||
wsPort := flag.Uint("port", 8200, "websocket port")
|
wsPort := flag.Uint("port", 8200, "websocket port")
|
||||||
debug := flag.Bool("debug", false, "debug logging")
|
debug := flag.Bool("debug", false, "debug logging")
|
||||||
|
start := flag.Bool("start", false, "starts all buses on startup")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
//change working directory only if value is given
|
//change working directory only if value is given
|
||||||
@@ -47,6 +48,7 @@ func main() {
|
|||||||
s.Routes.POST("/buses/start", artNetDriver.Start)
|
s.Routes.POST("/buses/start", artNetDriver.Start)
|
||||||
s.Routes.POST("/buses/status", artNetDriver.Status)
|
s.Routes.POST("/buses/status", artNetDriver.Status)
|
||||||
s.Routes.POST("/buses/stop", artNetDriver.Stop)
|
s.Routes.POST("/buses/stop", artNetDriver.Stop)
|
||||||
|
s.Routes.POST("/buses/resubscribe", artNetDriver.Resubscribe)
|
||||||
|
|
||||||
s.Routes.GET("/", func(c *gin.Context) {
|
s.Routes.GET("/", func(c *gin.Context) {
|
||||||
c.String(200, "ArtNet Driver WebSocket Server is running!")
|
c.String(200, "ArtNet Driver WebSocket Server is running!")
|
||||||
@@ -58,7 +60,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
artNetDriver.Log.Info("main", fmt.Sprintf("connect to server ws://%s:%d with id %s", *serverIp, serverPort, DriverName))
|
artNetDriver.Log.Info("main", fmt.Sprintf("connect to server ws://%s:%d with id %s", *serverIp, *serverPort, DriverName))
|
||||||
|
|
||||||
|
if *start {
|
||||||
|
for busName, bus := range artNetDriver.Buses {
|
||||||
|
artNetDriver.Log.Info("main", fmt.Sprintf("starting bus %s", busName))
|
||||||
|
// start bus and listen to subscriptions
|
||||||
|
bus.Start(artNetDriver.Log)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// connect to server
|
// connect to server
|
||||||
for {
|
for {
|
||||||
artNetDriver.Log.Error("main", artNetDriver.Connect(*serverIp, DriverName, *serverPort))
|
artNetDriver.Log.Error("main", artNetDriver.Connect(*serverIp, DriverName, *serverPort))
|
||||||
|
@@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/tatsushid/go-fastping"
|
"github.com/tatsushid/go-fastping"
|
||||||
json_data "github.com/tecamino/tecamino-json_data"
|
json_data "github.com/tecamino/tecamino-json_data"
|
||||||
|
json_dataModels "github.com/tecamino/tecamino-json_data/models"
|
||||||
"github.com/tecamino/tecamino-logger/logging"
|
"github.com/tecamino/tecamino-logger/logging"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -21,12 +22,13 @@ const (
|
|||||||
|
|
||||||
// Art-Net Interface
|
// Art-Net Interface
|
||||||
type Bus struct {
|
type Bus struct {
|
||||||
Name string `yaml:"name" json:"name"`
|
Name string `yaml:"name" json:"name"`
|
||||||
Ip string `yaml:"ip" json:"ip"`
|
Ip string `yaml:"ip" json:"ip"`
|
||||||
Port *int `yaml:"port" json:"port,omitempty"`
|
Port *int `yaml:"port" json:"port,omitempty"`
|
||||||
Data *DMX `yaml:"-" json:"-"`
|
Data *DMX `yaml:"-" json:"-"`
|
||||||
Watchdog context.CancelFunc `yaml:"-" json:"-"`
|
Resubscribe *[]json_dataModels.Subscription `yaml:"-" json:"resubscribe"`
|
||||||
Reachable bool `yaml:"-" json:"-"`
|
Watchdog context.CancelFunc `yaml:"-" json:"-"`
|
||||||
|
Reachable 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)
|
||||||
|
@@ -17,9 +17,8 @@ func NewSubscriptions() Subscriptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Subscriptions) AddSubscription(uid uuid.UUID, drv *json_dataModels.Driver) {
|
func (s *Subscriptions) AddSubscription(uid uuid.UUID, drv *json_dataModels.Driver) {
|
||||||
sub := Subscription{
|
(*s)[uid] = Subscription{
|
||||||
Bus: drv.Bus,
|
Bus: drv.Bus,
|
||||||
Address: drv.Address,
|
Address: drv.Address,
|
||||||
}
|
}
|
||||||
(*s)[uid] = sub
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user