Skip to content

Commit

Permalink
Issue #64 - Changed DiagnosticsStatusNotification and FirmwareStatusN…
Browse files Browse the repository at this point in the history
…otification to be initiated from the CP.
  • Loading branch information
TVolden committed Jun 19, 2018
1 parent e3eac89 commit ba983eb
Show file tree
Hide file tree
Showing 15 changed files with 184 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ of this software and associated documentation files (the "Software"), to deal

import eu.chargetime.ocpp.ServerEvents;
import eu.chargetime.ocpp.feature.profile.ServerCoreEventHandler;
import eu.chargetime.ocpp.feature.profile.ServerFirmwareManagementEventHandler;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.SessionInformation;
import eu.chargetime.ocpp.model.core.*;
import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationConfirmation;
import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationRequest;
import eu.chargetime.ocpp.model.firmware.FirmwareStatusNotificationConfirmation;
import eu.chargetime.ocpp.model.firmware.FirmwareStatusNotificationRequest;

import java.lang.reflect.Type;
import java.util.Calendar;
Expand Down Expand Up @@ -125,6 +130,24 @@ public StopTransactionConfirmation handleStopTransactionRequest(UUID sessionInde
};
}

public ServerFirmwareManagementEventHandler createServerFirmwareManagementEventHandler() {
return new ServerFirmwareManagementEventHandler() {
@Override
public DiagnosticsStatusNotificationConfirmation handleDiagnosticsStatusNotificationRequest(DiagnosticsStatusNotificationRequest request) {
receivedRequest = request;
DiagnosticsStatusNotificationConfirmation confirmation = new DiagnosticsStatusNotificationConfirmation();
return failurePoint(confirmation);
}

@Override
public FirmwareStatusNotificationConfirmation handleFirmwareStatusNotificationRequest(FirmwareStatusNotificationRequest request) {
receivedRequest = request;
FirmwareStatusNotificationConfirmation confirmation = new FirmwareStatusNotificationConfirmation();
return failurePoint(confirmation);
}
};
}

public ServerEvents generateServerEventsHandler() {
return new ServerEvents() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private void initializeServer() {
ServerRemoteTriggerProfile remoteTriggerProfile = new ServerRemoteTriggerProfile();
server.addFeatureProfile(remoteTriggerProfile);

ServerFirmwareManagementProfile firmwareManagementProfile = new ServerFirmwareManagementProfile();
ServerFirmwareManagementProfile firmwareManagementProfile = new ServerFirmwareManagementProfile(dummyHandlers.createServerFirmwareManagementEventHandler());
server.addFeatureProfile(firmwareManagementProfile);

ServerLocalAuthListProfile localAuthListProfile = new ServerLocalAuthListProfile();
Expand Down Expand Up @@ -122,6 +122,14 @@ public void stopped() {
isStarted = false;
}

public boolean hasHandledDiagnosticsStatusNotificationRequest() {
return dummyHandlers.wasLatestRequest(DiagnosticsStatusNotificationRequest.class);
}

public boolean hasHandledFirmwareStatusNotificationRequest() {
return dummyHandlers.wasLatestRequest(FirmwareStatusNotificationRequest.class);
}

public boolean hasHandledAuthorizeRequest() {
return dummyHandlers.wasLatestRequest(AuthorizeRequest.class);
}
Expand All @@ -147,14 +155,6 @@ public boolean hasReceivedGetDiagnosticsConfirmation() {
return dummyHandlers.wasLatestConfirmation(GetDiagnosticsConfirmation.class);
}

public boolean hasReceivedDiagnosticsStatusNotificationConfirmation() {
return dummyHandlers.wasLatestConfirmation(DiagnosticsStatusNotificationConfirmation.class);
}

public boolean hasReceivedFirmwareStatusNotificationConfirmation() {
return dummyHandlers.wasLatestConfirmation(FirmwareStatusNotificationConfirmation.class);
}

public boolean hasReceivedReserveNowConfirmation() {
return dummyHandlers.wasLatestConfirmation(ReserveNowConfirmation.class);
}
Expand Down Expand Up @@ -282,16 +282,6 @@ public void sendGetDiagnosticsRequest(String location) throws Exception {
send(request);
}

public void sendDiagnosticsStatusNotificationRequest(DiagnosticsStatus status) throws Exception {
DiagnosticsStatusNotificationRequest request = new DiagnosticsStatusNotificationRequest(status);
send(request);
}

public void sendFirmwareStatusNotificationRequest(FirmwareStatus status) throws Exception {
FirmwareStatusNotificationRequest request = new FirmwareStatusNotificationRequest(status);
send(request);
}

public void sendUpdateFirmwareRequest(String location, Calendar retrieveDate) throws Exception {
UpdateFirmwareRequest request = new UpdateFirmwareRequest(location, retrieveDate);
send(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,6 @@ public GetDiagnosticsConfirmation handleGetDiagnosticsRequest(GetDiagnosticsRequ
return new GetDiagnosticsConfirmation();
}

@Override
public DiagnosticsStatusNotificationConfirmation handleDiagnosticsStatusNotificationRequest(DiagnosticsStatusNotificationRequest request) {
receivedRequest = request;
return new DiagnosticsStatusNotificationConfirmation();
}

@Override
public FirmwareStatusNotificationConfirmation handleFirmwareStatusNotificationRequest(FirmwareStatusNotificationRequest request) {
receivedRequest = request;
return new FirmwareStatusNotificationConfirmation();
}

@Override
public UpdateFirmwareConfirmation handleUpdateFirmwareRequest(UpdateFirmwareRequest request) {
receivedRequest = request;
Expand Down Expand Up @@ -300,6 +288,16 @@ public void sendStatusNotificationRequest() {
}
}

public void sendDiagnosticsStatusNotificationRequest(DiagnosticsStatus status) throws Exception {
DiagnosticsStatusNotificationRequest request = new DiagnosticsStatusNotificationRequest(status);
send(request);
}

public void sendFirmwareStatusNotificationRequest(FirmwareStatus status) throws Exception {
FirmwareStatusNotificationRequest request = new FirmwareStatusNotificationRequest(status);
send(request);
}

public void clearMemory() {
receivedConfirmation = null;
receivedException = null;
Expand Down Expand Up @@ -329,6 +327,14 @@ public boolean hasReceivedAuthorizeConfirmation(String status) {
return false;
}

public boolean hasReceivedDiagnosticsStatusNotificationConfirmation() {
return (receivedConfirmation instanceof DiagnosticsStatusNotificationConfirmation);
}

public boolean hasReceivedFirmwareStatusNotificationConfirmation() {
return (receivedConfirmation instanceof FirmwareStatusNotificationConfirmation);
}

public boolean hasReceivedDataTransferConfirmation(String status) {
if (receivedConfirmation instanceof DataTransferConfirmation)
return ((DataTransferConfirmation) receivedConfirmation).getStatus().toString().equals(status);
Expand Down Expand Up @@ -363,14 +369,6 @@ public boolean hasHandledGetDiagnosticsRequest() {
return receivedRequest instanceof GetDiagnosticsRequest;
}

public boolean hasHandledDiagnosticsStatusNotificationRequest() {
return receivedRequest instanceof DiagnosticsStatusNotificationRequest;
}

public boolean hasHandledFirmwareStatusNotificationRequest() {
return receivedRequest instanceof FirmwareStatusNotificationRequest;
}

public boolean hasHandledUpdateFirmwareRequest() {
return receivedRequest instanceof UpdateFirmwareRequest;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
package eu.chargetime.ocpp.test.profiles.firmware.json

import eu.chargetime.ocpp.model.firmware.DiagnosticsStatus
import eu.chargetime.ocpp.test.base.json.JSONBaseSpec
import spock.util.concurrent.PollingConditions

/*
ChargeTime.eu - Java-OCA-OCPP
Expand Down Expand Up @@ -31,6 +26,10 @@ import spock.util.concurrent.PollingConditions
SOFTWARE.
*/

import eu.chargetime.ocpp.model.firmware.DiagnosticsStatus
import eu.chargetime.ocpp.test.base.json.JSONBaseSpec
import spock.util.concurrent.PollingConditions

class JSONDiagnosticsStatusNotificationSpec extends JSONBaseSpec {

def "Central System sends a DiagnosticsStatusNotification request and receives a response"() {
Expand All @@ -41,12 +40,12 @@ class JSONDiagnosticsStatusNotificationSpec extends JSONBaseSpec {
}

when:
centralSystem.sendDiagnosticsStatusNotificationRequest(DiagnosticsStatus.Uploading)
chargePoint.sendDiagnosticsStatusNotificationRequest(DiagnosticsStatus.Uploading)

then:
conditions.eventually {
assert chargePoint.hasHandledDiagnosticsStatusNotificationRequest()
assert centralSystem.hasReceivedDiagnosticsStatusNotificationConfirmation()
assert centralSystem.hasHandledDiagnosticsStatusNotificationRequest()
assert chargePoint.hasReceivedDiagnosticsStatusNotificationConfirmation()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
package eu.chargetime.ocpp.test.profiles.firmware.json

import eu.chargetime.ocpp.model.firmware.FirmwareStatus
import eu.chargetime.ocpp.test.base.json.JSONBaseSpec
import spock.util.concurrent.PollingConditions

/*
ChargeTime.eu - Java-OCA-OCPP
Expand Down Expand Up @@ -31,22 +26,26 @@ import spock.util.concurrent.PollingConditions
SOFTWARE.
*/

import eu.chargetime.ocpp.model.firmware.FirmwareStatus
import eu.chargetime.ocpp.test.base.json.JSONBaseSpec
import spock.util.concurrent.PollingConditions

class JSONFirmwareStatusNotificationSpec extends JSONBaseSpec {

def "Central System sends a FirmwareStatusNotification request and receives a response"() {
def "Charge point sends a FirmwareStatusNotification request and receives a response"() {
def conditions = new PollingConditions(timeout: 1)
given:
conditions.eventually {
assert centralSystem.connected()
}

when:
centralSystem.sendFirmwareStatusNotificationRequest(FirmwareStatus.Downloading)
chargePoint.sendFirmwareStatusNotificationRequest(FirmwareStatus.Downloading)

then:
conditions.eventually {
assert chargePoint.hasHandledFirmwareStatusNotificationRequest()
assert centralSystem.hasReceivedFirmwareStatusNotificationConfirmation()
assert centralSystem.hasHandledFirmwareStatusNotificationRequest()
assert chargePoint.hasReceivedFirmwareStatusNotificationConfirmation()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ of this software and associated documentation files (the "Software"), to deal
SOFTWARE.
*/

import eu.chargetime.ocpp.model.firmware.*;

import eu.chargetime.ocpp.model.firmware.GetDiagnosticsConfirmation;
import eu.chargetime.ocpp.model.firmware.GetDiagnosticsRequest;
import eu.chargetime.ocpp.model.firmware.UpdateFirmwareConfirmation;
import eu.chargetime.ocpp.model.firmware.UpdateFirmwareRequest;

public interface ClientFirmwareManagementEventHandler {
GetDiagnosticsConfirmation handleGetDiagnosticsRequest(GetDiagnosticsRequest request);

DiagnosticsStatusNotificationConfirmation handleDiagnosticsStatusNotificationRequest(DiagnosticsStatusNotificationRequest request);

FirmwareStatusNotificationConfirmation handleFirmwareStatusNotificationRequest(FirmwareStatusNotificationRequest request);

UpdateFirmwareConfirmation handleUpdateFirmwareRequest(UpdateFirmwareRequest request);

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package eu.chargetime.ocpp.feature.profile;/*
package eu.chargetime.ocpp.feature.profile;
/*
ChargeTime.eu - Java-OCA-OCPP
MIT License
Expand Down Expand Up @@ -27,8 +28,6 @@ of this software and associated documentation files (the "Software"), to deal
import eu.chargetime.ocpp.feature.*;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationRequest;
import eu.chargetime.ocpp.model.firmware.FirmwareStatusNotificationRequest;
import eu.chargetime.ocpp.model.firmware.GetDiagnosticsRequest;
import eu.chargetime.ocpp.model.firmware.UpdateFirmwareRequest;

Expand Down Expand Up @@ -60,10 +59,6 @@ public Confirmation handleRequest(UUID sessionIndex, Request request) {

if (request instanceof GetDiagnosticsRequest) {
result = eventHandler.handleGetDiagnosticsRequest((GetDiagnosticsRequest) request);
} else if (request instanceof DiagnosticsStatusNotificationRequest) {
result = eventHandler.handleDiagnosticsStatusNotificationRequest((DiagnosticsStatusNotificationRequest) request);
} else if (request instanceof FirmwareStatusNotificationRequest) {
result = eventHandler.handleFirmwareStatusNotificationRequest((FirmwareStatusNotificationRequest) request);
} else if (request instanceof UpdateFirmwareRequest) {
result = eventHandler.handleUpdateFirmwareRequest((UpdateFirmwareRequest) request);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package eu.chargetime.ocpp.feature.profile;
/*
ChargeTime.eu - Java-OCA-OCPP
MIT License
Copyright (C) 2018 Thomas Volden <tv@chargetime.eu>
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.firmware.DiagnosticsStatusNotificationConfirmation;
import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationRequest;
import eu.chargetime.ocpp.model.firmware.FirmwareStatusNotificationConfirmation;
import eu.chargetime.ocpp.model.firmware.FirmwareStatusNotificationRequest;

public interface ServerFirmwareManagementEventHandler {
DiagnosticsStatusNotificationConfirmation handleDiagnosticsStatusNotificationRequest(DiagnosticsStatusNotificationRequest request);

FirmwareStatusNotificationConfirmation handleFirmwareStatusNotificationRequest(FirmwareStatusNotificationRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@ of this software and associated documentation files (the "Software"), to deal
import eu.chargetime.ocpp.feature.*;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationRequest;
import eu.chargetime.ocpp.model.firmware.FirmwareStatusNotificationRequest;

import java.util.HashSet;
import java.util.UUID;

public class ServerFirmwareManagementProfile implements Profile {

private final ServerFirmwareManagementEventHandler eventHandler;
private HashSet<Feature> features;

public ServerFirmwareManagementProfile() {
public ServerFirmwareManagementProfile(ServerFirmwareManagementEventHandler eventHandler) {
this.eventHandler = eventHandler;
features = new HashSet<>();
features.add(new GetDiagnosticsFeature(this));
features.add(new DiagnosticsStatusNotificationFeature(this));
Expand All @@ -51,6 +55,15 @@ public Feature[] getFeatureList() {

@Override
public Confirmation handleRequest(UUID sessionIndex, Request request) {
return null;
Confirmation result = null;

if (request instanceof DiagnosticsStatusNotificationRequest) {
result = eventHandler.handleDiagnosticsStatusNotificationRequest((DiagnosticsStatusNotificationRequest) request);
} else if (request instanceof FirmwareStatusNotificationRequest) {
result = eventHandler.handleFirmwareStatusNotificationRequest((FirmwareStatusNotificationRequest) request);
}

return result;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package eu.chargetime.ocpp.model.firmware;

/*
* ChargeTime.eu - Java-OCA-OCPP
*
Expand Down Expand Up @@ -33,7 +32,7 @@
import java.util.Objects;

/**
* Sent by the Charge Point to the Central System in response to an {@link DiagnosticsStatusNotificationRequest}.
* Sent by the Central System to the Charge Point in response to an {@link DiagnosticsStatusNotificationRequest}.
*/
@XmlRootElement(name = "diagnosticsStatusNotificationResponse")
public class DiagnosticsStatusNotificationConfirmation implements Confirmation {
Expand Down
Loading

0 comments on commit ba983eb

Please sign in to comment.