Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support OCPP 2.0 status notification #156

Merged
merged 1 commit into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ of this software and associated documentation files (the "Software"), to deal
SOFTWARE.
*/

import eu.chargetime.ocpp.*;
import eu.chargetime.ocpp.IServerAPI;
import eu.chargetime.ocpp.JSONConfiguration;
import eu.chargetime.ocpp.JSONServer;
import eu.chargetime.ocpp.NotConnectedException;
import eu.chargetime.ocpp.OccurenceConstraintException;
import eu.chargetime.ocpp.ServerEvents;
import eu.chargetime.ocpp.UnsupportedFeatureException;
import eu.chargetime.ocpp.feature.Feature;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
Expand All @@ -43,7 +49,7 @@ public class FakeCentralSystem {
private IServerAPI server;
private boolean isStarted;
private UUID currentSession;
private Request handletReuqest = null;
private Request handlerRequest = null;
private Confirmation receivedConfirmation;

public FakeCentralSystem() {
Expand All @@ -55,7 +61,7 @@ public FakeCentralSystem() {

public void addFeature(Feature feature) {
FeatureTestDecorator monitoredFeature =
new FeatureTestDecorator(feature, request -> handletReuqest = request);
new FeatureTestDecorator(feature, request -> handlerRequest = request);
server.addFeature(monitoredFeature);
}

Expand Down Expand Up @@ -86,7 +92,7 @@ public void stopped() {
}

public boolean hasHandled(Request request) {
if (handletReuqest != null && request != null) return handletReuqest.equals(request);
if (handlerRequest != null && request != null) return handlerRequest.equals(request);
return false;
}

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

public boolean recieved(Confirmation confirmation) {
public boolean received(Confirmation confirmation) {
if (receivedConfirmation != null && confirmation != null)
return receivedConfirmation.equals(confirmation);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class FakeChargePoint {
private final String url = "ws://127.0.0.1:8887";
private IClientAPI client;
private Confirmation receivedConfirmation = null;
private Request handletReuqest;
private Request handlerRequest;

public FakeChargePoint() {
client = new JSONClient();
Expand All @@ -55,7 +55,7 @@ public void connectionClosed() {}

public void addFeature(Feature feature) {
FeatureTestDecorator monitoredFeature =
new FeatureTestDecorator(feature, request -> handletReuqest = request);
new FeatureTestDecorator(feature, request -> handlerRequest = request);
client.addFeature(monitoredFeature);
}

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

public boolean recieved(Confirmation confirmation) {
public boolean received(Confirmation confirmation) {
if (receivedConfirmation != null && confirmation != null)
return receivedConfirmation.equals(confirmation);
return false;
}

public boolean hasHandled(Request request) {
if (handletReuqest != null && request != null) return handletReuqest.equals(request);
if (handlerRequest != null && request != null) return handlerRequest.equals(request);
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package eu.chargetime.ocpp.test.features;
/*
ChargeTime.eu - Java-OCA-OCPP

MIT License

Copyright (C) 2021 John Michael Luy <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

import eu.chargetime.ocpp.feature.Feature;
import eu.chargetime.ocpp.features.basic.StatusNotificationFeature;
import eu.chargetime.ocpp.features.basic.handlers.IServerStatusNotificationRequestHandler;
import eu.chargetime.ocpp.model.basic.StatusNotificationConfirmation;
import eu.chargetime.ocpp.model.basic.StatusNotificationRequest;
import eu.chargetime.ocpp.model.basic.types.ConnectorStatusEnumType;
import java.time.ZonedDateTime;
import java.util.UUID;

public class StatusNotification implements IServerStatusNotificationRequestHandler {

private StatusNotificationFeature feature;
private StatusNotificationConfirmation confirmation;

public StatusNotification() {
feature = new StatusNotificationFeature(this);

confirmation = new StatusNotificationConfirmation();
}

@Override
public StatusNotificationConfirmation handleStatusNotificationRequest(
UUID sessionIndex, StatusNotificationRequest request) {
return confirmation;
}

public StatusNotificationConfirmation getConfirmation() {
return confirmation;
}

public StatusNotificationRequest createRequest() {
StatusNotificationRequest request = new StatusNotificationRequest();
request.setTimestamp(ZonedDateTime.now());
request.setConnectorStatus(ConnectorStatusEnumType.Available);
request.setEvseId(1);
request.setConnectorId(1);
return request;
}

public Feature getFeature() {
return feature;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package eu.chargetime.ocpp.test.profiles.core.json
package eu.chargetime.ocpp.test.features

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

then:
conditions.eventually {
assert chargePoint.recieved(tester.confirmation)
assert chargePoint.received(tester.confirmation)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class GetVariablesSpec extends BaseSpec

then:
conditions.eventually {
assert centralSystem.recieved(tester.confirmation)
assert centralSystem.received(tester.confirmation)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package eu.chargetime.ocpp.test.features

import eu.chargetime.ocpp.test.base.json.BaseSpec
import eu.chargetime.ocpp.test.features.BootNotification
import spock.util.concurrent.PollingConditions

class SetVariablesSpec extends BaseSpec
Expand All @@ -25,7 +24,7 @@ class SetVariablesSpec extends BaseSpec

then:
conditions.eventually {
assert centralSystem.recieved(tester.confirmation)
assert centralSystem.received(tester.confirmation)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package eu.chargetime.ocpp.test.features

import eu.chargetime.ocpp.test.base.json.BaseSpec
import spock.util.concurrent.PollingConditions

class StatusNotificationSpec extends BaseSpec {
def "Charge point sends Status Notification and receives a response"() {
def conditions = new PollingConditions(timeout: 1)

given:
def tester = new StatusNotification()
chargePoint.addFeature(tester.feature)
centralSystem.addFeature(tester.feature)
def request = tester.createRequest()

when:
chargePoint.send(request)

then:
conditions.eventually {
assert centralSystem.hasHandled(request)
}

then:
conditions.eventually {
assert chargePoint.received(tester.confirmation)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package eu.chargetime.ocpp.features.basic;
/*
ChargeTime.eu - Java-OCA-OCPP

MIT License

Copyright (C) 2021 John Michael Luy <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

import eu.chargetime.ocpp.feature.Feature;
import eu.chargetime.ocpp.features.basic.handlers.IServerStatusNotificationRequestHandler;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.basic.StatusNotificationConfirmation;
import eu.chargetime.ocpp.model.basic.StatusNotificationRequest;
import java.util.UUID;

public class StatusNotificationFeature implements Feature {

private final IServerStatusNotificationRequestHandler handler;

public StatusNotificationFeature(IServerStatusNotificationRequestHandler handler) {
this.handler = handler;
}

@Override
public Confirmation handleRequest(UUID sessionIndex, Request request) {
return handler.handleStatusNotificationRequest(sessionIndex,
(StatusNotificationRequest) request);
}

@Override
public Class<? extends Request> getRequestType() {
return StatusNotificationRequest.class;
}

@Override
public Class<? extends Confirmation> getConfirmationType() {
return StatusNotificationConfirmation.class;
}

@Override
public String getAction() {
return "StatusNotification";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package eu.chargetime.ocpp.features.basic.handlers;
/*
ChargeTime.eu - Java-OCA-OCPP

MIT License

Copyright (C) 2021 John Michael Luy <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

import eu.chargetime.ocpp.model.basic.StatusNotificationConfirmation;
import eu.chargetime.ocpp.model.basic.StatusNotificationRequest;
import java.util.UUID;

/** Central system handler of {@link StatusNotificationRequest}s. */
public interface IServerStatusNotificationRequestHandler {
StatusNotificationConfirmation handleStatusNotificationRequest(
UUID sessionIndex, StatusNotificationRequest request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package eu.chargetime.ocpp.model.basic;
/*
ChargeTime.eu - Java-OCA-OCPP

MIT License

Copyright (C) 2021 John Michael Luy <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.utilities.MoreObjects;
import java.util.Objects;

public class StatusNotificationConfirmation implements Confirmation {

@Override
public boolean validate() {
return true;
}

@Override
public boolean equals(Object o) {
return this == o || (o != null && getClass() == o.getClass());
}

@Override
public int hashCode() {
return Objects.hash(StatusNotificationConfirmation.class);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this).add("isValid", validate()).toString();
}
}
Loading