Skip to content

Commit 8dbff3d

Browse files
authored
Merge pull request ChargeTimeEU#156 from jmluy/2.0-status-notification
Support OCPP 2.0 status notification
2 parents e55f3cb + ccf0e3e commit 8dbff3d

File tree

15 files changed

+567
-25
lines changed

15 files changed

+567
-25
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ of this software and associated documentation files (the "Software"), to deal
2525
SOFTWARE.
2626
*/
2727

28-
import eu.chargetime.ocpp.*;
28+
import eu.chargetime.ocpp.IServerAPI;
29+
import eu.chargetime.ocpp.JSONConfiguration;
30+
import eu.chargetime.ocpp.JSONServer;
31+
import eu.chargetime.ocpp.NotConnectedException;
32+
import eu.chargetime.ocpp.OccurenceConstraintException;
33+
import eu.chargetime.ocpp.ServerEvents;
34+
import eu.chargetime.ocpp.UnsupportedFeatureException;
2935
import eu.chargetime.ocpp.feature.Feature;
3036
import eu.chargetime.ocpp.model.Confirmation;
3137
import eu.chargetime.ocpp.model.Request;
@@ -43,7 +49,7 @@ public class FakeCentralSystem {
4349
private IServerAPI server;
4450
private boolean isStarted;
4551
private UUID currentSession;
46-
private Request handletReuqest = null;
52+
private Request handlerRequest = null;
4753
private Confirmation receivedConfirmation;
4854

4955
public FakeCentralSystem() {
@@ -55,7 +61,7 @@ public FakeCentralSystem() {
5561

5662
public void addFeature(Feature feature) {
5763
FeatureTestDecorator monitoredFeature =
58-
new FeatureTestDecorator(feature, request -> handletReuqest = request);
64+
new FeatureTestDecorator(feature, request -> handlerRequest = request);
5965
server.addFeature(monitoredFeature);
6066
}
6167

@@ -86,7 +92,7 @@ public void stopped() {
8692
}
8793

8894
public boolean hasHandled(Request request) {
89-
if (handletReuqest != null && request != null) return handletReuqest.equals(request);
95+
if (handlerRequest != null && request != null) return handlerRequest.equals(request);
9096
return false;
9197
}
9298

@@ -96,7 +102,7 @@ public void send(Request request)
96102
send.whenComplete((confirmation, throwable) -> receivedConfirmation = confirmation);
97103
}
98104

99-
public boolean recieved(Confirmation confirmation) {
105+
public boolean received(Confirmation confirmation) {
100106
if (receivedConfirmation != null && confirmation != null)
101107
return receivedConfirmation.equals(confirmation);
102108
return false;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class FakeChargePoint {
3535
private final String url = "ws://127.0.0.1:8887";
3636
private IClientAPI client;
3737
private Confirmation receivedConfirmation = null;
38-
private Request handletReuqest;
38+
private Request handlerRequest;
3939

4040
public FakeChargePoint() {
4141
client = new JSONClient();
@@ -55,7 +55,7 @@ public void connectionClosed() {}
5555

5656
public void addFeature(Feature feature) {
5757
FeatureTestDecorator monitoredFeature =
58-
new FeatureTestDecorator(feature, request -> handletReuqest = request);
58+
new FeatureTestDecorator(feature, request -> handlerRequest = request);
5959
client.addFeature(monitoredFeature);
6060
}
6161

@@ -69,14 +69,14 @@ public void send(Request request)
6969
send.whenComplete((confirmation, throwable) -> receivedConfirmation = confirmation);
7070
}
7171

72-
public boolean recieved(Confirmation confirmation) {
72+
public boolean received(Confirmation confirmation) {
7373
if (receivedConfirmation != null && confirmation != null)
7474
return receivedConfirmation.equals(confirmation);
7575
return false;
7676
}
7777

7878
public boolean hasHandled(Request request) {
79-
if (handletReuqest != null && request != null) return handletReuqest.equals(request);
79+
if (handlerRequest != null && request != null) return handlerRequest.equals(request);
8080
return false;
8181
}
8282
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package eu.chargetime.ocpp.test.features;
2+
/*
3+
ChargeTime.eu - Java-OCA-OCPP
4+
5+
MIT License
6+
7+
Copyright (C) 2021 John Michael Luy <johnmichael.luy@gmail.com>
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in all
17+
copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
SOFTWARE.
26+
*/
27+
28+
import eu.chargetime.ocpp.feature.Feature;
29+
import eu.chargetime.ocpp.features.basic.StatusNotificationFeature;
30+
import eu.chargetime.ocpp.features.basic.handlers.IServerStatusNotificationRequestHandler;
31+
import eu.chargetime.ocpp.model.basic.StatusNotificationConfirmation;
32+
import eu.chargetime.ocpp.model.basic.StatusNotificationRequest;
33+
import eu.chargetime.ocpp.model.basic.types.ConnectorStatusEnumType;
34+
import java.time.ZonedDateTime;
35+
import java.util.UUID;
36+
37+
public class StatusNotification implements IServerStatusNotificationRequestHandler {
38+
39+
private StatusNotificationFeature feature;
40+
private StatusNotificationConfirmation confirmation;
41+
42+
public StatusNotification() {
43+
feature = new StatusNotificationFeature(this);
44+
45+
confirmation = new StatusNotificationConfirmation();
46+
}
47+
48+
@Override
49+
public StatusNotificationConfirmation handleStatusNotificationRequest(
50+
UUID sessionIndex, StatusNotificationRequest request) {
51+
return confirmation;
52+
}
53+
54+
public StatusNotificationConfirmation getConfirmation() {
55+
return confirmation;
56+
}
57+
58+
public StatusNotificationRequest createRequest() {
59+
StatusNotificationRequest request = new StatusNotificationRequest();
60+
request.setTimestamp(ZonedDateTime.now());
61+
request.setConnectorStatus(ConnectorStatusEnumType.Available);
62+
request.setEvseId(1);
63+
request.setConnectorId(1);
64+
return request;
65+
}
66+
67+
public Feature getFeature() {
68+
return feature;
69+
}
70+
}

ocpp-v2_0-test/src/test/groovy/eu.chargetime.ocpp.test/features/BootNotificationSpec.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package eu.chargetime.ocpp.test.profiles.core.json
1+
package eu.chargetime.ocpp.test.features
22

33
import eu.chargetime.ocpp.test.base.json.BaseSpec
44
import eu.chargetime.ocpp.test.features.BootNotification
@@ -25,7 +25,7 @@ class BootNotificationSpec extends BaseSpec
2525

2626
then:
2727
conditions.eventually {
28-
assert chargePoint.recieved(tester.confirmation)
28+
assert chargePoint.received(tester.confirmation)
2929
}
3030
}
3131
}

ocpp-v2_0-test/src/test/groovy/eu.chargetime.ocpp.test/features/GetVariablesSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class GetVariablesSpec extends BaseSpec
2424

2525
then:
2626
conditions.eventually {
27-
assert centralSystem.recieved(tester.confirmation)
27+
assert centralSystem.received(tester.confirmation)
2828
}
2929
}
3030
}

ocpp-v2_0-test/src/test/groovy/eu.chargetime.ocpp.test/features/SetVariablesSpec.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package eu.chargetime.ocpp.test.features
22

33
import eu.chargetime.ocpp.test.base.json.BaseSpec
4-
import eu.chargetime.ocpp.test.features.BootNotification
54
import spock.util.concurrent.PollingConditions
65

76
class SetVariablesSpec extends BaseSpec
@@ -25,7 +24,7 @@ class SetVariablesSpec extends BaseSpec
2524

2625
then:
2726
conditions.eventually {
28-
assert centralSystem.recieved(tester.confirmation)
27+
assert centralSystem.received(tester.confirmation)
2928
}
3029
}
3130
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package eu.chargetime.ocpp.test.features
2+
3+
import eu.chargetime.ocpp.test.base.json.BaseSpec
4+
import spock.util.concurrent.PollingConditions
5+
6+
class StatusNotificationSpec extends BaseSpec {
7+
def "Charge point sends Status Notification and receives a response"() {
8+
def conditions = new PollingConditions(timeout: 1)
9+
10+
given:
11+
def tester = new StatusNotification()
12+
chargePoint.addFeature(tester.feature)
13+
centralSystem.addFeature(tester.feature)
14+
def request = tester.createRequest()
15+
16+
when:
17+
chargePoint.send(request)
18+
19+
then:
20+
conditions.eventually {
21+
assert centralSystem.hasHandled(request)
22+
}
23+
24+
then:
25+
conditions.eventually {
26+
assert chargePoint.received(tester.confirmation)
27+
}
28+
}
29+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package eu.chargetime.ocpp.features.basic;
2+
/*
3+
ChargeTime.eu - Java-OCA-OCPP
4+
5+
MIT License
6+
7+
Copyright (C) 2021 John Michael Luy <johnmichael.luy@gmail.com>
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in all
17+
copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
SOFTWARE.
26+
*/
27+
28+
import eu.chargetime.ocpp.feature.Feature;
29+
import eu.chargetime.ocpp.features.basic.handlers.IServerStatusNotificationRequestHandler;
30+
import eu.chargetime.ocpp.model.Confirmation;
31+
import eu.chargetime.ocpp.model.Request;
32+
import eu.chargetime.ocpp.model.basic.StatusNotificationConfirmation;
33+
import eu.chargetime.ocpp.model.basic.StatusNotificationRequest;
34+
import java.util.UUID;
35+
36+
public class StatusNotificationFeature implements Feature {
37+
38+
private final IServerStatusNotificationRequestHandler handler;
39+
40+
public StatusNotificationFeature(IServerStatusNotificationRequestHandler handler) {
41+
this.handler = handler;
42+
}
43+
44+
@Override
45+
public Confirmation handleRequest(UUID sessionIndex, Request request) {
46+
return handler.handleStatusNotificationRequest(sessionIndex,
47+
(StatusNotificationRequest) request);
48+
}
49+
50+
@Override
51+
public Class<? extends Request> getRequestType() {
52+
return StatusNotificationRequest.class;
53+
}
54+
55+
@Override
56+
public Class<? extends Confirmation> getConfirmationType() {
57+
return StatusNotificationConfirmation.class;
58+
}
59+
60+
@Override
61+
public String getAction() {
62+
return "StatusNotification";
63+
}
64+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package eu.chargetime.ocpp.features.basic.handlers;
2+
/*
3+
ChargeTime.eu - Java-OCA-OCPP
4+
5+
MIT License
6+
7+
Copyright (C) 2021 John Michael Luy <johnmichael.luy@gmail.com>
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in all
17+
copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
SOFTWARE.
26+
*/
27+
28+
import eu.chargetime.ocpp.model.basic.StatusNotificationConfirmation;
29+
import eu.chargetime.ocpp.model.basic.StatusNotificationRequest;
30+
import java.util.UUID;
31+
32+
/** Central system handler of {@link StatusNotificationRequest}s. */
33+
public interface IServerStatusNotificationRequestHandler {
34+
StatusNotificationConfirmation handleStatusNotificationRequest(
35+
UUID sessionIndex, StatusNotificationRequest request);
36+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package eu.chargetime.ocpp.model.basic;
2+
/*
3+
ChargeTime.eu - Java-OCA-OCPP
4+
5+
MIT License
6+
7+
Copyright (C) 2021 John Michael Luy <johnmichael.luy@gmail.com>
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in all
17+
copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
SOFTWARE.
26+
*/
27+
28+
import eu.chargetime.ocpp.model.Confirmation;
29+
import eu.chargetime.ocpp.utilities.MoreObjects;
30+
import java.util.Objects;
31+
32+
public class StatusNotificationConfirmation implements Confirmation {
33+
34+
@Override
35+
public boolean validate() {
36+
return true;
37+
}
38+
39+
@Override
40+
public boolean equals(Object o) {
41+
return this == o || (o != null && getClass() == o.getClass());
42+
}
43+
44+
@Override
45+
public int hashCode() {
46+
return Objects.hash(StatusNotificationConfirmation.class);
47+
}
48+
49+
@Override
50+
public String toString() {
51+
return MoreObjects.toStringHelper(this).add("isValid", validate()).toString();
52+
}
53+
}

0 commit comments

Comments
 (0)