@@ -18,6 +18,7 @@ import (
18
18
"github.com/enbility/eebus-go/service"
19
19
ucapi "github.com/enbility/eebus-go/usecases/api"
20
20
"github.com/enbility/eebus-go/usecases/eg/lpc"
21
+ "github.com/enbility/eebus-go/usecases/eg/lpp"
21
22
shipapi "github.com/enbility/ship-go/api"
22
23
"github.com/enbility/ship-go/cert"
23
24
spineapi "github.com/enbility/spine-go/api"
@@ -30,6 +31,7 @@ type controlbox struct {
30
31
myService * service.Service
31
32
32
33
uclpc ucapi.EgLPCInterface
34
+ uclpp ucapi.EgLPPInterface
33
35
34
36
isConnected bool
35
37
}
@@ -94,6 +96,9 @@ func (h *controlbox) run() {
94
96
h .uclpc = lpc .NewLPC (localEntity , h .OnLPCEvent )
95
97
h .myService .AddUseCase (h .uclpc )
96
98
99
+ h .uclpp = lpp .NewLPP (localEntity , h .OnLPPEvent )
100
+ h .myService .AddUseCase (h .uclpp )
101
+
97
102
if len (remoteSki ) == 0 {
98
103
os .Exit (0 )
99
104
}
@@ -154,7 +159,7 @@ func (h *controlbox) sendLimit(entity spineapi.EntityRemoteInterface) {
154
159
if * msg .ErrorNumber == model .ErrorNumberTypeNoError {
155
160
fmt .Println ("Limit accepted." )
156
161
} else {
157
- fmt .Println ("Limit rejected. Code" , msg .ErrorNumber , "Description" , msg .Description )
162
+ fmt .Println ("Limit rejected. Code" , * msg .ErrorNumber , "Description" , * msg .Description )
158
163
}
159
164
}
160
165
msgCounter , err := h .uclpc .WriteConsumptionLimit (entity , limit , resultCB )
@@ -165,7 +170,6 @@ func (h *controlbox) sendLimit(entity spineapi.EntityRemoteInterface) {
165
170
fmt .Println ("Sent limit to" , entity .Device ().Ski (), "with msgCounter" , msgCounter )
166
171
})
167
172
}
168
-
169
173
func (h * controlbox ) OnLPCEvent (ski string , device spineapi.DeviceRemoteInterface , entity spineapi.EntityRemoteInterface , event api.EventType ) {
170
174
if ! h .isConnected {
171
175
return
@@ -183,6 +187,23 @@ func (h *controlbox) OnLPCEvent(ski string, device spineapi.DeviceRemoteInterfac
183
187
}
184
188
}
185
189
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
+
186
207
// main app
187
208
func usage () {
188
209
fmt .Println ("First Run:" )
0 commit comments