-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_image.go
58 lines (46 loc) · 1.15 KB
/
process_image.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"sync"
"time"
)
type processImage struct {
Meters map[string]processImageMeter `json:"meters"`
}
type processImageMeter struct {
Connected bool `json:"connected"`
LastUpdate *time.Time `json:"lastUpdate"`
Values map[string]processImageMeterValue `json:"values"`
}
type processImageMeterValue struct {
Value interface{} `json:"value"`
Unit uint8 `json:"unit"`
}
type processImageManager struct {
image processImage
lock sync.Mutex
}
func newProcessImageManager(cfg *config) *processImageManager {
v := &processImageManager{
image: processImage{
Meters: make(map[string]processImageMeter),
},
}
for _, m := range cfg.Meters {
v.image.Meters[m.Id] = processImageMeter{
Connected: false,
LastUpdate: nil,
Values: make(map[string]processImageMeterValue),
}
}
return v
}
func (i *processImageManager) updateMeterValues(meterId string, value processImageMeter) {
i.lock.Lock()
defer i.lock.Unlock()
i.image.Meters[meterId] = value
}
func (i *processImageManager) get() processImage {
i.lock.Lock()
defer i.lock.Unlock()
return i.image
}