Skip to content

Commit dd200cb

Browse files
authored
Merge pull request #10 from emilm/smartcharging-setchargingprofile
Added Smart Charging Profile and SetChargingProfile.req / conf
2 parents 665c2ea + 0a707cd commit dd200cb

File tree

14 files changed

+846
-0
lines changed

14 files changed

+846
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
import eu.chargetime.ocpp.ServerEvents;
77
import eu.chargetime.ocpp.feature.profile.ServerCoreEventHandler;
88
import eu.chargetime.ocpp.feature.profile.ServerCoreProfile;
9+
import eu.chargetime.ocpp.feature.profile.ServerSmartChargingHandler;
10+
import eu.chargetime.ocpp.feature.profile.ServerSmartChargingProfile;
911
import eu.chargetime.ocpp.model.Confirmation;
1012
import eu.chargetime.ocpp.model.Request;
1113
import eu.chargetime.ocpp.model.core.*;
14+
import eu.chargetime.ocpp.model.smartcharging.SetChargingProfileConfirmation;
15+
import eu.chargetime.ocpp.model.smartcharging.SetChargingProfileRequest;
1216

1317
import java.util.Calendar;
1418
import java.util.UUID;
@@ -174,6 +178,10 @@ public StopTransactionConfirmation handleStopTransactionRequest(UUID sessionInde
174178
}
175179
});
176180

181+
ServerSmartChargingProfile smartChargingProfile = new ServerSmartChargingProfile(new ServerSmartChargingHandler() {
182+
183+
});
184+
177185
int port = 0;
178186
switch (type) {
179187
case JSON:
@@ -186,6 +194,8 @@ public StopTransactionConfirmation handleStopTransactionRequest(UUID sessionInde
186194
break;
187195
}
188196

197+
server.addFeatureProfile(smartChargingProfile);
198+
189199
server.open("localhost", port, new ServerEvents() {
190200
@Override
191201
public void newSession(UUID sessionIndex, String identifier) {

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
import eu.chargetime.ocpp.*;
44
import eu.chargetime.ocpp.feature.profile.ClientCoreEventHandler;
55
import eu.chargetime.ocpp.feature.profile.ClientCoreProfile;
6+
import eu.chargetime.ocpp.feature.profile.ClientSmartChargingEventHandler;
7+
import eu.chargetime.ocpp.feature.profile.ClientSmartChargingProfile;
68
import eu.chargetime.ocpp.model.Confirmation;
79
import eu.chargetime.ocpp.model.Request;
810
import eu.chargetime.ocpp.model.core.*;
11+
import eu.chargetime.ocpp.model.smartcharging.ChargingProfileStatus;
12+
import eu.chargetime.ocpp.model.smartcharging.SetChargingProfileConfirmation;
13+
import eu.chargetime.ocpp.model.smartcharging.SetChargingProfileRequest;
914

1015
import java.net.MalformedURLException;
1116
import java.net.URL;
@@ -43,6 +48,7 @@ public class FakeChargePoint
4348
private Confirmation receivedConfirmation;
4449
private Request receivedRequest;
4550
private ClientCoreProfile core;
51+
private ClientSmartChargingProfile smartCharging;
4652
private Throwable receivedException;
4753
private String url;
4854

@@ -117,6 +123,14 @@ public UnlockConnectorConfirmation handleUnlockConnectorRequest(UnlockConnectorR
117123
}
118124
});
119125

126+
smartCharging = new ClientSmartChargingProfile(new ClientSmartChargingEventHandler() {
127+
@Override
128+
public SetChargingProfileConfirmation handleSetChargingProfileRequest(SetChargingProfileRequest request) {
129+
receivedRequest = request;
130+
return new SetChargingProfileConfirmation(ChargingProfileStatus.Accepted);
131+
}
132+
});
133+
120134
switch (type) {
121135
case JSON:
122136
client = new JSONClient(core, "test");
@@ -127,6 +141,8 @@ public UnlockConnectorConfirmation handleUnlockConnectorRequest(UnlockConnectorR
127141
url = "http://localhost:8890";
128142
break;
129143
}
144+
145+
client.addFeatureProfile(smartCharging);
130146
}
131147

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

0 commit comments

Comments
 (0)