Skip to content

Commit 50b769c

Browse files
committed
Demo HEMS improvements
- support LPC & LPP as Energy guard and controllable system - comment SPINE message logging
1 parent 122d605 commit 50b769c

File tree

1 file changed

+71
-10
lines changed

1 file changed

+71
-10
lines changed

cmd/hems/main.go

Lines changed: 71 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,27 @@ import (
1515

1616
"github.com/enbility/eebus-go/api"
1717
"github.com/enbility/eebus-go/service"
18-
"github.com/enbility/eebus-go/usecases/eg/lpc"
18+
ucapi "github.com/enbility/eebus-go/usecases/api"
19+
"github.com/enbility/eebus-go/usecases/cs/lpc"
20+
cslpc "github.com/enbility/eebus-go/usecases/cs/lpc"
21+
cslpp "github.com/enbility/eebus-go/usecases/cs/lpp"
22+
eglpc "github.com/enbility/eebus-go/usecases/eg/lpc"
23+
eglpp "github.com/enbility/eebus-go/usecases/eg/lpp"
1924
shipapi "github.com/enbility/ship-go/api"
2025
"github.com/enbility/ship-go/cert"
26+
spineapi "github.com/enbility/spine-go/api"
2127
"github.com/enbility/spine-go/model"
2228
)
2329

2430
var remoteSki string
2531

2632
type hems struct {
2733
myService *service.Service
34+
35+
uccslpc ucapi.CsLPCInterface
36+
uccslpp ucapi.CsLPPInterface
37+
uceglpc ucapi.EgLPCInterface
38+
uceglpp ucapi.EgLPPInterface
2839
}
2940

3041
func (h *hems) run() {
@@ -84,8 +95,14 @@ func (h *hems) run() {
8495
}
8596

8697
localEntity := h.myService.LocalDevice().EntityForType(model.EntityTypeTypeCEM)
87-
uclpc := lpc.NewLPC(localEntity, nil)
88-
h.myService.AddUseCase(uclpc)
98+
h.uccslpc = cslpc.NewLPC(localEntity, h.OnLPCEvent)
99+
h.myService.AddUseCase(h.uccslpc)
100+
h.uccslpp = cslpp.NewLPP(localEntity, h.OnLPPEvent)
101+
h.myService.AddUseCase(h.uccslpp)
102+
h.uceglpc = eglpc.NewLPC(localEntity, nil)
103+
h.myService.AddUseCase(h.uceglpc)
104+
h.uceglpp = eglpp.NewLPP(localEntity, nil)
105+
h.myService.AddUseCase(h.uceglpp)
89106

90107
if len(remoteSki) == 0 {
91108
os.Exit(0)
@@ -97,6 +114,54 @@ func (h *hems) run() {
97114
// defer h.myService.Shutdown()
98115
}
99116

117+
// Controllable System LPC Event Handler
118+
119+
func (h *hems) OnLPCEvent(ski string, device spineapi.DeviceRemoteInterface, entity spineapi.EntityRemoteInterface, event api.EventType) {
120+
if entity.EntityType() != model.EntityTypeTypeGridGuard {
121+
return
122+
}
123+
124+
switch event {
125+
case lpc.WriteApprovalRequired:
126+
// get pending writes
127+
pendingWrites := h.uccslpc.PendingConsumptionLimits()
128+
129+
// approve any write
130+
for msgCounter, write := range pendingWrites {
131+
fmt.Println("Approving LPC write with msgCounter", msgCounter, "and limit", write.Value, "W")
132+
h.uccslpc.ApproveOrDenyConsumptionLimit(msgCounter, true, "")
133+
}
134+
case lpc.DataUpdateLimit:
135+
if currentLimit, err := h.uccslpc.ConsumptionLimit(); err != nil {
136+
fmt.Println("New LPC Limit set to", currentLimit.Value, "W")
137+
}
138+
}
139+
}
140+
141+
// Controllable System LPP Event Handler
142+
143+
func (h *hems) OnLPPEvent(ski string, device spineapi.DeviceRemoteInterface, entity spineapi.EntityRemoteInterface, event api.EventType) {
144+
if entity.EntityType() != model.EntityTypeTypeGridGuard {
145+
return
146+
}
147+
148+
switch event {
149+
case lpc.WriteApprovalRequired:
150+
// get pending writes
151+
pendingWrites := h.uccslpp.PendingProductionLimits()
152+
153+
// approve any write
154+
for msgCounter, write := range pendingWrites {
155+
fmt.Println("Approving LPP write with msgCounter", msgCounter, "and limit", write.Value, "W")
156+
h.uccslpp.ApproveOrDenyProductionLimit(msgCounter, true, "")
157+
}
158+
case lpc.DataUpdateLimit:
159+
if currentLimit, err := h.uccslpp.ProductionLimit(); err != nil {
160+
fmt.Println("New LPP Limit set to", currentLimit.Value, "W")
161+
}
162+
}
163+
}
164+
100165
// EEBUSServiceHandler
101166

102167
func (h *hems) RemoteSKIConnected(service api.ServiceInterface, ski string) {}
@@ -158,22 +223,18 @@ func main() {
158223

159224
func (h *hems) Trace(args ...interface{}) {
160225
// h.print("TRACE", args...)
161-
h.print("TRACE", args...)
162226
}
163227

164228
func (h *hems) Tracef(format string, args ...interface{}) {
165-
// h.print("TRACE", args...)
166-
h.printFormat("TRACE", format, args...)
229+
// h.printFormat("TRACE", format, args...)
167230
}
168231

169232
func (h *hems) Debug(args ...interface{}) {
170-
// h.print("TRACE", args...)
171-
h.print("DEBUG", args...)
233+
// h.print("DEBUG", args...)
172234
}
173235

174236
func (h *hems) Debugf(format string, args ...interface{}) {
175-
// h.print("TRACE", args...)
176-
h.printFormat("DEBUG", format, args...)
237+
// h.printFormat("DEBUG", format, args...)
177238
}
178239

179240
func (h *hems) Info(args ...interface{}) {

0 commit comments

Comments
 (0)