Skip to content

Commit

Permalink
Add DiagnosticsStatusNotification support.
Browse files Browse the repository at this point in the history
  • Loading branch information
sumlin committed Apr 16, 2018
1 parent 72e5393 commit 505545f
Show file tree
Hide file tree
Showing 12 changed files with 497 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,15 @@ of this software and associated documentation files (the "Software"), to deal
import eu.chargetime.ocpp.feature.profile.ServerSmartChargingProfile;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.core.*;
import eu.chargetime.ocpp.model.firmware.GetDiagnosticsConfirmation;
import eu.chargetime.ocpp.model.firmware.GetDiagnosticsRequest;
import eu.chargetime.ocpp.model.firmware.*;
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequest;
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequestType;
import eu.chargetime.ocpp.test.FakeCentral.serverType;

public class FakeCentralSystem {
private IServerAPI server;

DummyHandlers dummyHandlers;
private DummyHandlers dummyHandlers;
private boolean isStarted;

FakeCentralSystem(serverType type) {
Expand Down Expand Up @@ -123,6 +122,11 @@ public boolean hasReceivedGetDiagnosticsConfirmation() {
return dummyHandlers.wasLatestConfirmation(GetDiagnosticsConfirmation.class);
}


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

public boolean hasReceivedChangeAvailabilityConfirmation(String status) {
boolean result = false;
ChangeAvailabilityConfirmation confirmation = dummyHandlers.getReceivedConfirmation(new ChangeAvailabilityConfirmation());
Expand Down Expand Up @@ -226,6 +230,12 @@ public void sendGetDiagnosticsRequest(String location) throws Exception {
send(request);
}


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

public boolean hasReceivedResetConfirmation(String status) {
boolean result = false;
ResetConfirmation confirmation = dummyHandlers.getReceivedConfirmation(new ResetConfirmation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
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.GetDiagnosticsConfirmation;
import eu.chargetime.ocpp.model.firmware.GetDiagnosticsRequest;
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageConfirmation;
Expand Down Expand Up @@ -149,6 +151,12 @@ public GetDiagnosticsConfirmation handleGetDiagnosticsRequest(GetDiagnosticsRequ
receivedRequest = request;
return new GetDiagnosticsConfirmation();
}

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

switch (type) {
Expand Down Expand Up @@ -306,6 +314,10 @@ public boolean hasHandledGetDiagnosticsRequest() {
return receivedRequest instanceof GetDiagnosticsRequest;
}

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

public boolean hasHandledChangeAvailabilityRequest() {
return receivedRequest instanceof ChangeAvailabilityRequest;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package eu.chargetime.ocpp.test.firmware.json

import eu.chargetime.ocpp.model.firmware.DiagnosticsStatus
import eu.chargetime.ocpp.test.FakeCentral
import eu.chargetime.ocpp.test.FakeCentralSystem
import eu.chargetime.ocpp.test.FakeChargePoint
import spock.lang.Shared
import spock.lang.Specification
import spock.util.concurrent.PollingConditions

/*
ChargeTime.eu - Java-OCA-OCPP
MIT License
Copyright (C) 2016-2018 Thomas Volden <tv@chargetime.eu>
Copyright (C) 2018 Mikhail Kladkevich <kladmv@ecp-share.com>
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.
*/

class JSONDiagnosticsStatusNotificationSpec extends Specification {
@Shared
FakeCentralSystem centralSystem = FakeCentral.getSystem(FakeCentral.serverType.JSON)
@Shared
FakeChargePoint chargePoint = new FakeChargePoint()

def setupSpec() {
// When a Central System is running
centralSystem.started()
}

def setup() {
chargePoint.connect()
}

def cleanup() {
chargePoint.disconnect()
}

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

when:
centralSystem.sendDiagnosticsStatusNotificationRequest(DiagnosticsStatus.Uploading)

then:
conditions.eventually {
assert chargePoint.hasHandledDiagnosticsStatusNotificationRequest()
assert centralSystem.hasReceivedDiagnosticsStatusNotificationConfirmation()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package eu.chargetime.ocpp.feature;

import eu.chargetime.ocpp.feature.profile.Profile;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationConfirmation;
import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationRequest;

/*
ChargeTime.eu - Java-OCA-OCPP
MIT License
Copyright (C) 2016-2018 Thomas Volden
Copyright (C) 2018 Mikhail Kladkevich <kladmv@ecp-share.com>
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.
*/

public class DiagnosticsStatusNotificationFeature extends Feature {

public DiagnosticsStatusNotificationFeature(Profile ownerProfile) {
super(ownerProfile);
}

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

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

@Override
public String getAction() {
return "DiagnosticsStatusNotification";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ of this software and associated documentation files (the "Software"), to deal
SOFTWARE.
*/

import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationConfirmation;
import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationRequest;
import eu.chargetime.ocpp.model.firmware.GetDiagnosticsConfirmation;
import eu.chargetime.ocpp.model.firmware.GetDiagnosticsRequest;

public interface ClientFirmwareManagementEventHandler {
GetDiagnosticsConfirmation handleGetDiagnosticsRequest(GetDiagnosticsRequest request);

DiagnosticsStatusNotificationConfirmation handleDiagnosticsStatusNotificationRequest(DiagnosticsStatusNotificationRequest request);

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ of this software and associated documentation files (the "Software"), to deal
SOFTWARE.
*/

import eu.chargetime.ocpp.feature.DiagnosticsStatusNotificationFeature;
import eu.chargetime.ocpp.feature.Feature;
import eu.chargetime.ocpp.feature.GetDiagnosticsFeature;
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.GetDiagnosticsRequest;

import java.util.HashSet;
Expand All @@ -42,6 +44,7 @@ public ClientFirmwareManagementProfile(ClientFirmwareManagementEventHandler even
this.eventHandler = eventHandler;
features = new HashSet<>();
features.add(new GetDiagnosticsFeature(this));
features.add(new DiagnosticsStatusNotificationFeature(this));
}

@Override
Expand All @@ -55,6 +58,8 @@ 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);
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ of this software and associated documentation files (the "Software"), to deal
SOFTWARE.
*/

import eu.chargetime.ocpp.feature.DiagnosticsStatusNotificationFeature;
import eu.chargetime.ocpp.feature.Feature;
import eu.chargetime.ocpp.feature.GetDiagnosticsFeature;
import eu.chargetime.ocpp.model.Confirmation;
Expand All @@ -40,6 +41,7 @@ public class ServerFirmwareManagementProfile implements Profile {
public ServerFirmwareManagementProfile() {
features = new HashSet<>();
features.add(new GetDiagnosticsFeature(this));
features.add(new DiagnosticsStatusNotificationFeature(this));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package eu.chargetime.ocpp.model.firmware;

/*
* ChargeTime.eu - Java-OCA-OCPP
*
* MIT License
*
* Copyright (C) 2016-2018 Thomas Volden <tv@chargetime.eu>
* Copyright (C) 2018 Mikhail Kladkevich <kladmv@ecp-share.com>
*
* 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.
*/

/**
* Accepted values used with {@link DiagnosticsStatusNotificationRequest}.
*/
public enum DiagnosticsStatus {
Idle,
Uploaded,
UploadFailed,
Uploading
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package eu.chargetime.ocpp.model.firmware;

/*
* ChargeTime.eu - Java-OCA-OCPP
*
* MIT License
*
* Copyright (C) 2016 Thomas Volden <tv@chargetime.eu>
* Copyright (C) 2018 Mikhail Kladkevich <kladmv@ecp-share.com>
*
* 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 javax.xml.bind.annotation.XmlRootElement;

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

public DiagnosticsStatusNotificationConfirmation() {
}

@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 5;
}

@Override
public String toString() {
return "DiagnosticsStatusNotificationConfirmation{}" + "{isValid=" + String.valueOf(validate()) + "}";
}
}
Loading

0 comments on commit 505545f

Please sign in to comment.