@@ -15,16 +15,27 @@ import (
15
15
16
16
"github.com/enbility/eebus-go/api"
17
17
"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"
19
24
shipapi "github.com/enbility/ship-go/api"
20
25
"github.com/enbility/ship-go/cert"
26
+ spineapi "github.com/enbility/spine-go/api"
21
27
"github.com/enbility/spine-go/model"
22
28
)
23
29
24
30
var remoteSki string
25
31
26
32
type hems struct {
27
33
myService * service.Service
34
+
35
+ uccslpc ucapi.CsLPCInterface
36
+ uccslpp ucapi.CsLPPInterface
37
+ uceglpc ucapi.EgLPCInterface
38
+ uceglpp ucapi.EgLPPInterface
28
39
}
29
40
30
41
func (h * hems ) run () {
@@ -84,8 +95,14 @@ func (h *hems) run() {
84
95
}
85
96
86
97
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 )
89
106
90
107
if len (remoteSki ) == 0 {
91
108
os .Exit (0 )
@@ -97,6 +114,54 @@ func (h *hems) run() {
97
114
// defer h.myService.Shutdown()
98
115
}
99
116
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
+
100
165
// EEBUSServiceHandler
101
166
102
167
func (h * hems ) RemoteSKIConnected (service api.ServiceInterface , ski string ) {}
@@ -158,22 +223,18 @@ func main() {
158
223
159
224
func (h * hems ) Trace (args ... interface {}) {
160
225
// h.print("TRACE", args...)
161
- h .print ("TRACE" , args ... )
162
226
}
163
227
164
228
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...)
167
230
}
168
231
169
232
func (h * hems ) Debug (args ... interface {}) {
170
- // h.print("TRACE", args...)
171
- h .print ("DEBUG" , args ... )
233
+ // h.print("DEBUG", args...)
172
234
}
173
235
174
236
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...)
177
238
}
178
239
179
240
func (h * hems ) Info (args ... interface {}) {
0 commit comments