add new ip ping for udp device
add new function start and stop bus
This commit is contained in:
@@ -42,7 +42,6 @@ func (d *ArtNetDriver) CreateBus(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "bus name missing"})
|
||||
return
|
||||
} else if addr := net.ParseIP(payload.Ip); addr == nil {
|
||||
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "wrong ip '" + payload.Ip + "'"})
|
||||
return
|
||||
}
|
||||
@@ -53,6 +52,7 @@ func (d *ArtNetDriver) CreateBus(c *gin.Context) {
|
||||
}
|
||||
|
||||
bus := d.NewBus(payload.Name, payload.Ip, payload.GetPort())
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": fmt.Sprintf("bus '%s' successfully created with ip: %s and on port: %d", bus.Name, bus.Ip, bus.GetPort()),
|
||||
})
|
||||
@@ -92,3 +92,57 @@ func (d *ArtNetDriver) RemoveBus(c *gin.Context) {
|
||||
})
|
||||
d.cfgHandler.SaveCfg(*d)
|
||||
}
|
||||
|
||||
func (d *ArtNetDriver) Start(c *gin.Context) {
|
||||
_, err := auth.GetIDFromAuth(c)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "id: " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
var payload models.Bus
|
||||
|
||||
if err := c.BindJSON(&payload); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "json: " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if payload.Name == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "bus name missing"})
|
||||
return
|
||||
}
|
||||
|
||||
d.Buses[payload.Name].Start(d.Log)
|
||||
|
||||
c.JSON(http.StatusOK, models.JsonResponse{
|
||||
Message: fmt.Sprintf("bus '%s' running", payload.Name),
|
||||
})
|
||||
d.cfgHandler.SaveCfg(*d)
|
||||
}
|
||||
|
||||
func (d *ArtNetDriver) Stop(c *gin.Context) {
|
||||
_, err := auth.GetIDFromAuth(c)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "id: " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
var payload models.Bus
|
||||
|
||||
if err := c.BindJSON(&payload); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "json: " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if payload.Name == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "bus name missing"})
|
||||
return
|
||||
}
|
||||
|
||||
d.Buses[payload.Name].Stop()
|
||||
|
||||
c.JSON(http.StatusOK, models.JsonResponse{
|
||||
Message: fmt.Sprintf("bus '%s' stopped", payload.Name),
|
||||
})
|
||||
d.cfgHandler.SaveCfg(*d)
|
||||
}
|
||||
|
Reference in New Issue
Block a user