Skip to content

Commit 92a152b

Browse files
author
emilm
committed
Added RemoteTrigger profile
1 parent b683646 commit 92a152b

File tree

15 files changed

+908
-14
lines changed

15 files changed

+908
-14
lines changed

ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/FakeCentralSystem.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
package eu.chargetime.ocpp.test;
22

3-
import eu.chargetime.ocpp.JSONServer;
4-
import eu.chargetime.ocpp.SOAPServer;
5-
import eu.chargetime.ocpp.Server;
6-
import eu.chargetime.ocpp.ServerEvents;
7-
import eu.chargetime.ocpp.feature.profile.ServerCoreEventHandler;
8-
import eu.chargetime.ocpp.feature.profile.ServerCoreProfile;
9-
import eu.chargetime.ocpp.feature.profile.ServerSmartChargingHandler;
10-
import eu.chargetime.ocpp.feature.profile.ServerSmartChargingProfile;
3+
import eu.chargetime.ocpp.*;
4+
import eu.chargetime.ocpp.feature.profile.*;
115
import eu.chargetime.ocpp.model.Confirmation;
126
import eu.chargetime.ocpp.model.Request;
137
import eu.chargetime.ocpp.model.core.*;
8+
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequest;
9+
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequestType;
1410

1511
import java.util.Calendar;
1612
import java.util.UUID;
@@ -184,6 +180,10 @@ public StopTransactionConfirmation handleStopTransactionRequest(UUID sessionInde
184180

185181
});
186182

183+
ServerRemoteTriggerProfile remoteTriggerProfile = new ServerRemoteTriggerProfile(new ServerRemoteTriggerHandler() {
184+
185+
});
186+
187187
int port = 0;
188188
switch (type) {
189189
case JSON:
@@ -197,6 +197,7 @@ public StopTransactionConfirmation handleStopTransactionRequest(UUID sessionInde
197197
}
198198

199199
server.addFeatureProfile(smartChargingProfile);
200+
server.addFeatureProfile(remoteTriggerProfile);
200201

201202
server.open("localhost", port, new ServerEvents() {
202203
@Override
@@ -373,4 +374,15 @@ public boolean hasReceivedUnlockConnectorConfirmation(String status) {
373374
public void isRiggedToFailOnNextRequest() {
374375
isRigged = true;
375376
}
377+
378+
public void sendTriggerMessage(TriggerMessageRequestType type, Integer connectorId) throws Exception {
379+
TriggerMessageRequest request = new TriggerMessageRequest(type);
380+
try {
381+
request.setConnectorId(connectorId);
382+
} catch (PropertyConstraintException e) {
383+
e.printStackTrace();
384+
}
385+
386+
server.send(currentSessionIndex, request).whenComplete((confirmation, throwable) -> receivedConfirmation = confirmation);
387+
}
376388
}

ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/FakeChargePoint.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package eu.chargetime.ocpp.test;
22

33
import eu.chargetime.ocpp.*;
4-
import eu.chargetime.ocpp.feature.profile.ClientCoreEventHandler;
5-
import eu.chargetime.ocpp.feature.profile.ClientCoreProfile;
6-
import eu.chargetime.ocpp.feature.profile.ClientSmartChargingEventHandler;
7-
import eu.chargetime.ocpp.feature.profile.ClientSmartChargingProfile;
4+
import eu.chargetime.ocpp.feature.profile.*;
85
import eu.chargetime.ocpp.model.Confirmation;
96
import eu.chargetime.ocpp.model.Request;
107
import eu.chargetime.ocpp.model.core.*;
8+
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageConfirmation;
9+
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequest;
10+
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageStatus;
1111
import eu.chargetime.ocpp.model.smartcharging.ChargingProfileStatus;
1212
import eu.chargetime.ocpp.model.smartcharging.SetChargingProfileConfirmation;
1313
import eu.chargetime.ocpp.model.smartcharging.SetChargingProfileRequest;
@@ -47,8 +47,9 @@ public class FakeChargePoint
4747
private Client client;
4848
private Confirmation receivedConfirmation;
4949
private Request receivedRequest;
50-
private ClientCoreProfile core;
51-
private ClientSmartChargingProfile smartCharging;
50+
private final ClientCoreProfile core;
51+
private final ClientSmartChargingProfile smartCharging;
52+
private final ClientRemoteTriggerProfile remoteTrigger;
5253
private Throwable receivedException;
5354
private String url;
5455

@@ -131,6 +132,14 @@ public SetChargingProfileConfirmation handleSetChargingProfileRequest(SetChargin
131132
}
132133
});
133134

135+
remoteTrigger = new ClientRemoteTriggerProfile(new ClientRemoteTriggerHandler() {
136+
@Override
137+
public TriggerMessageConfirmation handleTriggerMessageRequest(TriggerMessageRequest request) {
138+
receivedRequest = request;
139+
return new TriggerMessageConfirmation(TriggerMessageStatus.Accepted);
140+
}
141+
});
142+
134143
switch (type) {
135144
case JSON:
136145
client = new JSONClient(core, "test");
@@ -143,6 +152,7 @@ public SetChargingProfileConfirmation handleSetChargingProfileRequest(SetChargin
143152
}
144153

145154
client.addFeatureProfile(smartCharging);
155+
client.addFeatureProfile(remoteTrigger);
146156
}
147157

148158
public void connect() {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package eu.chargetime.ocpp.feature;
2+
3+
import eu.chargetime.ocpp.feature.profile.Profile;
4+
import eu.chargetime.ocpp.model.Confirmation;
5+
import eu.chargetime.ocpp.model.Request;
6+
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageConfirmation;
7+
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequest;
8+
9+
/*
10+
ChargeTime.eu - Java-OCA-OCPP
11+
Copyright (C) 2017 Emil Christopher Solli Melar <[email protected]>
12+
13+
MIT License
14+
15+
Copyright (C) 2017 Emil Christopher Solli Melar
16+
17+
Permission is hereby granted, free of charge, to any person obtaining a copy
18+
of this software and associated documentation files (the "Software"), to deal
19+
in the Software without restriction, including without limitation the rights
20+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21+
copies of the Software, and to permit persons to whom the Software is
22+
furnished to do so, subject to the following conditions:
23+
24+
The above copyright notice and this permission notice shall be included in all
25+
copies or substantial portions of the Software.
26+
27+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33+
SOFTWARE.
34+
*/
35+
36+
public class TriggerMessageFeature extends Feature {
37+
public TriggerMessageFeature(Profile ownerProfile) {
38+
super(ownerProfile);
39+
}
40+
41+
@Override
42+
public Class<? extends Request> getRequestType() {
43+
return TriggerMessageRequest.class;
44+
}
45+
46+
@Override
47+
public Class<? extends Confirmation> getConfirmationType() {
48+
return TriggerMessageConfirmation.class;
49+
}
50+
51+
@Override
52+
public String getAction() {
53+
return "TriggerMessage";
54+
}
55+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package eu.chargetime.ocpp.feature.profile;
2+
3+
/*
4+
ChargeTime.eu - Java-OCA-OCPP
5+
Copyright (C) 2017 Emil Christopher Solli Melar <[email protected]>
6+
7+
MIT License
8+
9+
Copyright (C) 2017 Emil Christopher Solli Melar
10+
11+
Permission is hereby granted, free of charge, to any person obtaining a copy
12+
of this software and associated documentation files (the "Software"), to deal
13+
in the Software without restriction, including without limitation the rights
14+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15+
copies of the Software, and to permit persons to whom the Software is
16+
furnished to do so, subject to the following conditions:
17+
18+
The above copyright notice and this permission notice shall be included in all
19+
copies or substantial portions of the Software.
20+
21+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27+
SOFTWARE.
28+
*/
29+
30+
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageConfirmation;
31+
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequest;
32+
33+
public interface ClientRemoteTriggerHandler {
34+
/**
35+
* Handle a {@link TriggerMessageRequest} and return a {@link TriggerMessageConfirmation}.
36+
*
37+
* @param request incoming {@link TriggerMessageRequest} to handle.
38+
* @return outgoing {@link TriggerMessageConfirmation} to reply with.
39+
*/
40+
TriggerMessageConfirmation handleTriggerMessageRequest(TriggerMessageRequest request);
41+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package eu.chargetime.ocpp.feature.profile;
2+
3+
import eu.chargetime.ocpp.feature.Feature;
4+
import eu.chargetime.ocpp.feature.TriggerMessageFeature;
5+
import eu.chargetime.ocpp.model.Confirmation;
6+
import eu.chargetime.ocpp.model.Request;
7+
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequest;
8+
9+
import java.util.ArrayList;
10+
import java.util.UUID;
11+
12+
/*
13+
ChargeTime.eu - Java-OCA-OCPP
14+
Copyright (C) 2017 Emil Christopher Solli Melar <[email protected]>
15+
16+
MIT License
17+
18+
Copyright (C) 2017 Emil Christopher Solli Melar
19+
20+
Permission is hereby granted, free of charge, to any person obtaining a copy
21+
of this software and associated documentation files (the "Software"), to deal
22+
in the Software without restriction, including without limitation the rights
23+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
24+
copies of the Software, and to permit persons to whom the Software is
25+
furnished to do so, subject to the following conditions:
26+
27+
The above copyright notice and this permission notice shall be included in all
28+
copies or substantial portions of the Software.
29+
30+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36+
SOFTWARE.
37+
*/
38+
39+
/**
40+
* Callback handler for client events of the Remote Trigger feature profile.
41+
*/
42+
public class ClientRemoteTriggerProfile implements Profile {
43+
ClientRemoteTriggerHandler eventHandler;
44+
ArrayList<Feature> features;
45+
46+
public ClientRemoteTriggerProfile(ClientRemoteTriggerHandler handler) {
47+
features = new ArrayList<>();
48+
eventHandler = handler;
49+
50+
features.add(new TriggerMessageFeature(this));
51+
}
52+
53+
@Override
54+
public Feature[] getFeatureList() {
55+
return features.toArray(new Feature[0]);
56+
}
57+
58+
@Override
59+
public Confirmation handleRequest(UUID sessionIndex, Request request) {
60+
Confirmation result = null;
61+
62+
if (request instanceof TriggerMessageRequest) {
63+
result = eventHandler.handleTriggerMessageRequest((TriggerMessageRequest) request);
64+
}
65+
66+
return result;
67+
}
68+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package eu.chargetime.ocpp.feature.profile;
2+
3+
/*
4+
ChargeTime.eu - Java-OCA-OCPP
5+
Copyright (C) 2017 Emil Christopher Solli Melar <[email protected]>
6+
7+
MIT License
8+
9+
Copyright (C) 2017 Emil Christopher Solli Melar
10+
11+
Permission is hereby granted, free of charge, to any person obtaining a copy
12+
of this software and associated documentation files (the "Software"), to deal
13+
in the Software without restriction, including without limitation the rights
14+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15+
copies of the Software, and to permit persons to whom the Software is
16+
furnished to do so, subject to the following conditions:
17+
18+
The above copyright notice and this permission notice shall be included in all
19+
copies or substantial portions of the Software.
20+
21+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27+
SOFTWARE.
28+
*/
29+
30+
public interface ServerRemoteTriggerHandler {
31+
32+
}
33+
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package eu.chargetime.ocpp.feature.profile;
2+
3+
import eu.chargetime.ocpp.PropertyConstraintException;
4+
import eu.chargetime.ocpp.feature.Feature;
5+
import eu.chargetime.ocpp.feature.TriggerMessageFeature;
6+
import eu.chargetime.ocpp.model.Confirmation;
7+
import eu.chargetime.ocpp.model.Request;
8+
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequest;
9+
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequestType;
10+
11+
import java.util.HashSet;
12+
import java.util.UUID;
13+
14+
/*
15+
ChargeTime.eu - Java-OCA-OCPP
16+
Copyright (C) 2017 Emil Christopher Solli Melar <[email protected]>
17+
18+
MIT License
19+
20+
Copyright (C) 2017 Emil Christopher Solli Melar
21+
22+
Permission is hereby granted, free of charge, to any person obtaining a copy
23+
of this software and associated documentation files (the "Software"), to deal
24+
in the Software without restriction, including without limitation the rights
25+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26+
copies of the Software, and to permit persons to whom the Software is
27+
furnished to do so, subject to the following conditions:
28+
29+
The above copyright notice and this permission notice shall be included in all
30+
copies or substantial portions of the Software.
31+
32+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38+
SOFTWARE.
39+
*/
40+
41+
public class ServerRemoteTriggerProfile implements Profile {
42+
43+
private final ServerRemoteTriggerHandler handler;
44+
private HashSet<Feature> features;
45+
46+
public ServerRemoteTriggerProfile(ServerRemoteTriggerHandler handler) {
47+
this.handler = handler;
48+
49+
features = new HashSet<>();
50+
features.add(new TriggerMessageFeature(this));
51+
}
52+
53+
@Override
54+
public Feature[] getFeatureList() {
55+
return features.toArray(new Feature[0]);
56+
}
57+
58+
@Override
59+
public Confirmation handleRequest(UUID sessionIndex, Request request) {
60+
return null;
61+
}
62+
63+
public TriggerMessageRequest createTriggerMessageRequest(TriggerMessageRequestType type) throws PropertyConstraintException {
64+
return createTriggerMessageRequest(type, null);
65+
}
66+
67+
public TriggerMessageRequest createTriggerMessageRequest(TriggerMessageRequestType type, Integer connectorId) throws PropertyConstraintException {
68+
TriggerMessageRequest request = new TriggerMessageRequest(type);
69+
request.setConnectorId(connectorId);
70+
return request;
71+
}
72+
}

0 commit comments

Comments
 (0)