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.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)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// Sets
|
||||
go d.Set(request.Set)
|
||||
|
||||
// Subscribe
|
||||
go d.Subscribe(request.Subscribe, id)
|
||||
|
||||
|
||||
@@ -122,22 +122,23 @@ func (d *Datapoint) CreateDatapoints(conns *serverModels.Connections, sets ...js
|
||||
existing.Publish(conns, OnChange)
|
||||
}
|
||||
} else {
|
||||
// Create new
|
||||
current.Datapoints[part] = &Datapoint{
|
||||
ndp := Datapoint{
|
||||
Uuid: uuid.New(),
|
||||
CreateDateTime: time.Now().UnixMilli(),
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
created = append(created, json_dataModels.Set{
|
||||
Uuid: current.Uuid,
|
||||
Path: current.Path,
|
||||
Type: current.Type,
|
||||
Value: current.Value,
|
||||
Rights: current.ReadWrite,
|
||||
Uuid: ndp.Uuid,
|
||||
Path: ndp.Path,
|
||||
Type: ndp.Type,
|
||||
Value: ndp.Value,
|
||||
Rights: ndp.ReadWrite,
|
||||
Driver: dp.Driver,
|
||||
})
|
||||
if publish {
|
||||
@@ -246,6 +247,13 @@ func (d *Datapoint) UpdateDatapointValue(conns *serverModels.Connections, value
|
||||
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) {
|
||||
parts := strings.Split(set.Path, ":")
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package models
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/coder/websocket"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -37,7 +36,7 @@ func (cl *Clients) ConnectRecievingWsConnection(id string, c *gin.Context) error
|
||||
if err != nil {
|
||||
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{
|
||||
Connected: true,
|
||||
|
||||
Reference in New Issue
Block a user