Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
45b3b258c1 | ||
|
|
a0fe455bce | ||
|
|
7b9641f753 | ||
|
|
3d3dab91b9 |
@@ -20,6 +20,7 @@ func (d *DBMHandler) SaveData(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
r := json_dataModels.NewResponse()
|
r := json_dataModels.NewResponse()
|
||||||
r.SendMessage(fmt.Sprintf("DBM %ddatapints saved in: %v", d.GetNumbersOfDatapoints(), time.Since(s)))
|
r.SendMessage(fmt.Sprintf("DBM %d datapoints saved in: %v", d.GetNumbersOfDatapoints(), time.Since(s)))
|
||||||
|
d.Log.Info("db.SaveData", fmt.Sprintf("DBM %d datapoints saved in: %v", d.GetNumbersOfDatapoints(), time.Since(s)))
|
||||||
c.JSON(http.StatusOK, r)
|
c.JSON(http.StatusOK, r)
|
||||||
}
|
}
|
||||||
|
|||||||
19
dbm/set.go
Normal file
19
dbm/set.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package dbm
|
||||||
|
|
||||||
|
import (
|
||||||
|
json_dataModels "github.com/tecamino/tecamino-json_data/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (d *DBMHandler) Set(sets []json_dataModels.Set) {
|
||||||
|
if sets == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
d.RLock()
|
||||||
|
defer d.RUnlock()
|
||||||
|
|
||||||
|
for _, set := range sets {
|
||||||
|
for _, dp := range d.DB.QueryDatapoints(1, set.Path) {
|
||||||
|
dp.UpdateValue(d.Conns, set.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,6 +40,9 @@ func (d *DBMHandler) WebSocket(c *gin.Context) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sets
|
||||||
|
go d.Set(request.Set)
|
||||||
|
|
||||||
// Subscribe
|
// Subscribe
|
||||||
go d.Subscribe(request.Subscribe, id)
|
go d.Subscribe(request.Subscribe, id)
|
||||||
|
|
||||||
|
|||||||
@@ -122,22 +122,23 @@ func (d *Datapoint) CreateDatapoints(conns *serverModels.Connections, sets ...js
|
|||||||
existing.Publish(conns, OnChange)
|
existing.Publish(conns, OnChange)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Create new
|
ndp := Datapoint{
|
||||||
current.Datapoints[part] = &Datapoint{
|
|
||||||
Uuid: uuid.New(),
|
Uuid: uuid.New(),
|
||||||
CreateDateTime: time.Now().UnixMilli(),
|
CreateDateTime: time.Now().UnixMilli(),
|
||||||
Subscriptions: InitSubscribtion(),
|
Subscriptions: InitSubscribtion(),
|
||||||
}
|
}
|
||||||
publish, err := current.Datapoints[part].Set(strings.Join(parts, ":"), dp)
|
// Create new
|
||||||
|
current.Datapoints[part] = &ndp
|
||||||
|
publish, err := ndp.Set(strings.Join(parts, ":"), dp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
created = append(created, json_dataModels.Set{
|
created = append(created, json_dataModels.Set{
|
||||||
Uuid: current.Uuid,
|
Uuid: ndp.Uuid,
|
||||||
Path: current.Path,
|
Path: ndp.Path,
|
||||||
Type: current.Type,
|
Type: ndp.Type,
|
||||||
Value: current.Value,
|
Value: ndp.Value,
|
||||||
Rights: current.ReadWrite,
|
Rights: ndp.ReadWrite,
|
||||||
Driver: dp.Driver,
|
Driver: dp.Driver,
|
||||||
})
|
})
|
||||||
if publish {
|
if publish {
|
||||||
@@ -246,6 +247,13 @@ func (d *Datapoint) UpdateDatapointValue(conns *serverModels.Connections, value
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Datapoint) UpdateValue(conns *serverModels.Connections, value any) error {
|
||||||
|
d.Value = d.Type.ConvertValue(value)
|
||||||
|
d.UpdateDateTime = time.Now().UnixMilli()
|
||||||
|
d.Publish(conns, OnChange)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Datapoint) RemoveDatapoint(conns *serverModels.Connections, set json_dataModels.Set) (json_dataModels.Set, error) {
|
func (d *Datapoint) RemoveDatapoint(conns *serverModels.Connections, set json_dataModels.Set) (json_dataModels.Set, error) {
|
||||||
parts := strings.Split(set.Path, ":")
|
parts := strings.Split(set.Path, ":")
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package models
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/coder/websocket"
|
"github.com/coder/websocket"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -37,7 +36,7 @@ func (cl *Clients) ConnectRecievingWsConnection(id string, c *gin.Context) error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error accept websocket client: %s", err)
|
return fmt.Errorf("error accept websocket client: %s", err)
|
||||||
}
|
}
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
(*cl)[id] = &Client{
|
(*cl)[id] = &Client{
|
||||||
Connected: true,
|
Connected: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user