Skip to content

Commit 122d605

Browse files
committed
Demo controlbox improvements
also supports LPP, but only sends a LPC limit
1 parent a286c8d commit 122d605

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

cmd/controlbox/main.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/enbility/eebus-go/service"
1919
ucapi "github.com/enbility/eebus-go/usecases/api"
2020
"github.com/enbility/eebus-go/usecases/eg/lpc"
21+
"github.com/enbility/eebus-go/usecases/eg/lpp"
2122
shipapi "github.com/enbility/ship-go/api"
2223
"github.com/enbility/ship-go/cert"
2324
spineapi "github.com/enbility/spine-go/api"
@@ -30,6 +31,7 @@ type controlbox struct {
3031
myService *service.Service
3132

3233
uclpc ucapi.EgLPCInterface
34+
uclpp ucapi.EgLPPInterface
3335

3436
isConnected bool
3537
}
@@ -94,6 +96,9 @@ func (h *controlbox) run() {
9496
h.uclpc = lpc.NewLPC(localEntity, h.OnLPCEvent)
9597
h.myService.AddUseCase(h.uclpc)
9698

99+
h.uclpp = lpp.NewLPP(localEntity, h.OnLPPEvent)
100+
h.myService.AddUseCase(h.uclpp)
101+
97102
if len(remoteSki) == 0 {
98103
os.Exit(0)
99104
}
@@ -154,7 +159,7 @@ func (h *controlbox) sendLimit(entity spineapi.EntityRemoteInterface) {
154159
if *msg.ErrorNumber == model.ErrorNumberTypeNoError {
155160
fmt.Println("Limit accepted.")
156161
} else {
157-
fmt.Println("Limit rejected. Code", msg.ErrorNumber, "Description", msg.Description)
162+
fmt.Println("Limit rejected. Code", *msg.ErrorNumber, "Description", *msg.Description)
158163
}
159164
}
160165
msgCounter, err := h.uclpc.WriteConsumptionLimit(entity, limit, resultCB)
@@ -165,7 +170,6 @@ func (h *controlbox) sendLimit(entity spineapi.EntityRemoteInterface) {
165170
fmt.Println("Sent limit to", entity.Device().Ski(), "with msgCounter", msgCounter)
166171
})
167172
}
168-
169173
func (h *controlbox) OnLPCEvent(ski string, device spineapi.DeviceRemoteInterface, entity spineapi.EntityRemoteInterface, event api.EventType) {
170174
if !h.isConnected {
171175
return
@@ -183,6 +187,23 @@ func (h *controlbox) OnLPCEvent(ski string, device spineapi.DeviceRemoteInterfac
183187
}
184188
}
185189

190+
func (h *controlbox) OnLPPEvent(ski string, device spineapi.DeviceRemoteInterface, entity spineapi.EntityRemoteInterface, event api.EventType) {
191+
if !h.isConnected {
192+
return
193+
}
194+
195+
switch event {
196+
case lpc.UseCaseSupportUpdate:
197+
h.sendLimit(entity)
198+
case lpc.DataUpdateLimit:
199+
if currentLimit, err := h.uclpc.ConsumptionLimit(entity); err == nil {
200+
fmt.Println("New Limit received", currentLimit.Value, "W")
201+
}
202+
default:
203+
return
204+
}
205+
}
206+
186207
// main app
187208
func usage() {
188209
fmt.Println("First Run:")

0 commit comments

Comments
 (0)