@@ -141,14 +141,14 @@ func (h *controlbox) AllowWaitingForTrust(ski string) bool {
141
141
142
142
// LPC Event Handler
143
143
144
- func (h * controlbox ) sendLimit (entity spineapi.EntityRemoteInterface ) {
144
+ func (h * controlbox ) sendConsumptionLimit (entity spineapi.EntityRemoteInterface ) {
145
145
scenarios := h .uclpc .AvailableScenariosForEntity (entity )
146
146
if len (scenarios ) == 0 ||
147
147
! slices .Contains (scenarios , 1 ) {
148
148
return
149
149
}
150
150
151
- fmt .Println ("Sending a limit in 5s..." )
151
+ fmt .Println ("Sending a consumption limit in 5s..." )
152
152
time .AfterFunc (time .Second * 5 , func () {
153
153
limit := ucapi.LoadLimit {
154
154
Duration : time .Hour * 1 + time .Minute * 2 + time .Second * 3 ,
@@ -158,17 +158,17 @@ func (h *controlbox) sendLimit(entity spineapi.EntityRemoteInterface) {
158
158
159
159
resultCB := func (msg model.ResultDataType ) {
160
160
if * msg .ErrorNumber == model .ErrorNumberTypeNoError {
161
- fmt .Println ("Limit accepted." )
161
+ fmt .Println ("Consumption limit accepted." )
162
162
} else {
163
- fmt .Println ("Limit rejected. Code" , * msg .ErrorNumber , "Description" , * msg .Description )
163
+ fmt .Println ("Consumption limit rejected. Code" , * msg .ErrorNumber , "Description" , * msg .Description )
164
164
}
165
165
}
166
166
msgCounter , err := h .uclpc .WriteConsumptionLimit (entity , limit , resultCB )
167
167
if err != nil {
168
- fmt .Println ("Failed to send limit" , err )
168
+ fmt .Println ("Failed to send consumption limit" , err )
169
169
return
170
170
}
171
- fmt .Println ("Sent limit to" , entity .Device ().Ski (), "with msgCounter" , msgCounter )
171
+ fmt .Println ("Sent consumption limit to" , entity .Device ().Ski (), "with msgCounter" , msgCounter )
172
172
})
173
173
}
174
174
func (h * controlbox ) OnLPCEvent (ski string , device spineapi.DeviceRemoteInterface , entity spineapi.EntityRemoteInterface , event api.EventType ) {
@@ -178,27 +178,59 @@ func (h *controlbox) OnLPCEvent(ski string, device spineapi.DeviceRemoteInterfac
178
178
179
179
switch event {
180
180
case lpc .UseCaseSupportUpdate :
181
- h .sendLimit (entity )
181
+ h .sendConsumptionLimit (entity )
182
182
case lpc .DataUpdateLimit :
183
183
if currentLimit , err := h .uclpc .ConsumptionLimit (entity ); err == nil {
184
- fmt .Println ("New Limit received" , currentLimit .Value , "W" )
184
+ fmt .Println ("New consumption limit received" , currentLimit .Value , "W" )
185
185
}
186
186
default :
187
187
return
188
188
}
189
189
}
190
190
191
+ // LPP Event Handler
192
+
193
+ func (h * controlbox ) sendProductionLimit (entity spineapi.EntityRemoteInterface ) {
194
+ scenarios := h .uclpc .AvailableScenariosForEntity (entity )
195
+ if len (scenarios ) == 0 ||
196
+ ! slices .Contains (scenarios , 1 ) {
197
+ return
198
+ }
199
+
200
+ fmt .Println ("Sending a production limit in 5s..." )
201
+ time .AfterFunc (time .Second * 5 , func () {
202
+ limit := ucapi.LoadLimit {
203
+ Duration : time .Hour * 1 + time .Minute * 2 + time .Second * 3 ,
204
+ IsActive : true ,
205
+ Value : 100 ,
206
+ }
207
+
208
+ resultCB := func (msg model.ResultDataType ) {
209
+ if * msg .ErrorNumber == model .ErrorNumberTypeNoError {
210
+ fmt .Println ("Production limit accepted." )
211
+ } else {
212
+ fmt .Println ("Production limit rejected. Code" , * msg .ErrorNumber , "Description" , * msg .Description )
213
+ }
214
+ }
215
+ msgCounter , err := h .uclpp .WriteProductionLimit (entity , limit , resultCB )
216
+ if err != nil {
217
+ fmt .Println ("Failed to send production limit" , err )
218
+ return
219
+ }
220
+ fmt .Println ("Sent production limit to" , entity .Device ().Ski (), "with msgCounter" , msgCounter )
221
+ })
222
+ }
191
223
func (h * controlbox ) OnLPPEvent (ski string , device spineapi.DeviceRemoteInterface , entity spineapi.EntityRemoteInterface , event api.EventType ) {
192
224
if ! h .isConnected {
193
225
return
194
226
}
195
227
196
228
switch event {
197
- case lpc .UseCaseSupportUpdate :
198
- h .sendLimit (entity )
199
- case lpc .DataUpdateLimit :
200
- if currentLimit , err := h .uclpc . ConsumptionLimit (entity ); err == nil {
201
- fmt .Println ("New Limit received" , currentLimit .Value , "W" )
229
+ case lpp .UseCaseSupportUpdate :
230
+ h .sendProductionLimit (entity )
231
+ case lpp .DataUpdateLimit :
232
+ if currentLimit , err := h .uclpp . ProductionLimit (entity ); err == nil {
233
+ fmt .Println ("New production limit received" , currentLimit .Value , "W" )
202
234
}
203
235
default :
204
236
return
0 commit comments