Skip to content

Commit 65edb7e

Browse files
committed
Move Battery Swapping to a dedicated function
Move the Battery Swapping messages to a dedicated function, in line with the OCPP 2.1 specification which has a dedicated chapter for these.
1 parent f07bb75 commit 65edb7e

8 files changed

Lines changed: 235 additions & 58 deletions
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
ChargeTime.eu - Java-OCA-OCPP
3+
4+
MIT License
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
25+
package eu.chargetime.ocpp.v21.feature.function;
26+
27+
import eu.chargetime.ocpp.v21.model.messages.*;
28+
29+
/** Call back handler for client events of the BatterySwapping functional block. */
30+
public interface ClientBatterySwappingEventHandler {
31+
/**
32+
* Handle a {@link RequestBatterySwapRequest} and return a {@link RequestBatterySwapResponse}.
33+
*
34+
* @param request incoming {@link RequestBatterySwapRequest} to handle.
35+
* @return outgoing {@link RequestBatterySwapResponse} to reply with.
36+
*/
37+
RequestBatterySwapResponse handleRequestBatterySwapRequest(RequestBatterySwapRequest request);
38+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
ChargeTime.eu - Java-OCA-OCPP
3+
4+
MIT License
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
25+
package eu.chargetime.ocpp.v21.feature.function;
26+
27+
import eu.chargetime.ocpp.feature.FunctionFeature;
28+
import eu.chargetime.ocpp.feature.function.Function;
29+
import eu.chargetime.ocpp.model.Confirmation;
30+
import eu.chargetime.ocpp.model.Request;
31+
import eu.chargetime.ocpp.v21.feature.*;
32+
import eu.chargetime.ocpp.v21.model.messages.*;
33+
import eu.chargetime.ocpp.v21.model.types.*;
34+
import java.util.ArrayList;
35+
import java.util.UUID;
36+
37+
/** Class with client request creators and handlers for the BatterySwapping functional block. */
38+
public class ClientBatterySwappingFunction implements Function {
39+
40+
private final ClientBatterySwappingEventHandler eventHandler;
41+
private final ArrayList<FunctionFeature> features;
42+
43+
public ClientBatterySwappingFunction(ClientBatterySwappingEventHandler eventHandler) {
44+
this.eventHandler = eventHandler;
45+
features = new ArrayList<>();
46+
features.add(new BatterySwapFeature(null));
47+
features.add(new RequestBatterySwapFeature(this));
48+
}
49+
50+
@Override
51+
public FunctionFeature[] getFeatureList() {
52+
return features.toArray(new FunctionFeature[0]);
53+
}
54+
55+
@Override
56+
public Confirmation handleRequest(UUID sessionIndex, Request request) {
57+
if (request instanceof RequestBatterySwapRequest) {
58+
return eventHandler.handleRequestBatterySwapRequest((RequestBatterySwapRequest) request);
59+
}
60+
return null;
61+
}
62+
63+
/**
64+
* Create a client {@link BatterySwapRequest} with all required fields.
65+
*
66+
* @param batteryData batteryData
67+
* @param eventType Battery in/out
68+
* @param idToken A case insensitive identifier to use for the authorization and the type of
69+
* authorization to support multiple forms of identifiers.
70+
* @param requestId RequestId to correlate BatteryIn/Out events and optional
71+
* RequestBatterySwapRequest.
72+
* @return an instance of {@link BatterySwapRequest}
73+
*/
74+
public BatterySwapRequest createBatterySwapRequest(
75+
BatteryData[] batteryData,
76+
BatterySwapEventEnum eventType,
77+
IdToken idToken,
78+
Integer requestId) {
79+
return new BatterySwapRequest(batteryData, eventType, idToken, requestId);
80+
}
81+
}

ocpp-v2/src/main/java/eu/chargetime/ocpp/v21/feature/function/ClientTransactionsEventHandler.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,4 @@ public interface ClientTransactionsEventHandler {
3636
*/
3737
GetTransactionStatusResponse handleGetTransactionStatusRequest(
3838
GetTransactionStatusRequest request);
39-
40-
/**
41-
* Handle a {@link RequestBatterySwapRequest} and return a {@link RequestBatterySwapResponse}.
42-
*
43-
* @param request incoming {@link RequestBatterySwapRequest} to handle.
44-
* @return outgoing {@link RequestBatterySwapResponse} to reply with.
45-
*/
46-
RequestBatterySwapResponse handleRequestBatterySwapRequest(RequestBatterySwapRequest request);
4739
}

ocpp-v2/src/main/java/eu/chargetime/ocpp/v21/feature/function/ClientTransactionsFunction.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ public class ClientTransactionsFunction implements Function {
4444
public ClientTransactionsFunction(ClientTransactionsEventHandler eventHandler) {
4545
this.eventHandler = eventHandler;
4646
features = new ArrayList<>();
47-
features.add(new BatterySwapFeature(null));
4847
features.add(new GetTransactionStatusFeature(this));
49-
features.add(new RequestBatterySwapFeature(this));
5048
features.add(new TransactionEventFeature(null));
5149
}
5250

@@ -59,31 +57,10 @@ public FunctionFeature[] getFeatureList() {
5957
public Confirmation handleRequest(UUID sessionIndex, Request request) {
6058
if (request instanceof GetTransactionStatusRequest) {
6159
return eventHandler.handleGetTransactionStatusRequest((GetTransactionStatusRequest) request);
62-
} else if (request instanceof RequestBatterySwapRequest) {
63-
return eventHandler.handleRequestBatterySwapRequest((RequestBatterySwapRequest) request);
6460
}
6561
return null;
6662
}
6763

68-
/**
69-
* Create a client {@link BatterySwapRequest} with all required fields.
70-
*
71-
* @param batteryData batteryData
72-
* @param eventType Battery in/out
73-
* @param idToken A case insensitive identifier to use for the authorization and the type of
74-
* authorization to support multiple forms of identifiers.
75-
* @param requestId RequestId to correlate BatteryIn/Out events and optional
76-
* RequestBatterySwapRequest.
77-
* @return an instance of {@link BatterySwapRequest}
78-
*/
79-
public BatterySwapRequest createBatterySwapRequest(
80-
BatteryData[] batteryData,
81-
BatterySwapEventEnum eventType,
82-
IdToken idToken,
83-
Integer requestId) {
84-
return new BatterySwapRequest(batteryData, eventType, idToken, requestId);
85-
}
86-
8764
/**
8865
* Create a client {@link TransactionEventRequest} with all required fields.
8966
*
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
ChargeTime.eu - Java-OCA-OCPP
3+
4+
MIT License
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
25+
package eu.chargetime.ocpp.v21.feature.function;
26+
27+
import eu.chargetime.ocpp.v21.model.messages.*;
28+
import java.util.UUID;
29+
30+
/** Call back handler for server events of the BatterySwapping functional block. */
31+
public interface ServerBatterySwappingEventHandler {
32+
/**
33+
* Handle a {@link BatterySwapRequest} and return a {@link BatterySwapResponse}.
34+
*
35+
* @param sessionIndex identifier of the session on which the request was received.
36+
* @param request incoming {@link BatterySwapRequest} to handle.
37+
* @return outgoing {@link BatterySwapResponse} to reply with.
38+
*/
39+
BatterySwapResponse handleBatterySwapRequest(UUID sessionIndex, BatterySwapRequest request);
40+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
ChargeTime.eu - Java-OCA-OCPP
3+
4+
MIT License
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
25+
package eu.chargetime.ocpp.v21.feature.function;
26+
27+
import eu.chargetime.ocpp.feature.FunctionFeature;
28+
import eu.chargetime.ocpp.feature.function.Function;
29+
import eu.chargetime.ocpp.model.Confirmation;
30+
import eu.chargetime.ocpp.model.Request;
31+
import eu.chargetime.ocpp.v21.feature.*;
32+
import eu.chargetime.ocpp.v21.model.messages.*;
33+
import eu.chargetime.ocpp.v21.model.types.*;
34+
import java.util.ArrayList;
35+
import java.util.UUID;
36+
37+
/** Class with server request creators and handlers for the BatterySwapping functional block. */
38+
public class ServerBatterySwappingFunction implements Function {
39+
40+
private final ServerBatterySwappingEventHandler eventHandler;
41+
private final ArrayList<FunctionFeature> features;
42+
43+
public ServerBatterySwappingFunction(ServerBatterySwappingEventHandler eventHandler) {
44+
this.eventHandler = eventHandler;
45+
features = new ArrayList<>();
46+
features.add(new BatterySwapFeature(this));
47+
features.add(new RequestBatterySwapFeature(null));
48+
}
49+
50+
@Override
51+
public FunctionFeature[] getFeatureList() {
52+
return features.toArray(new FunctionFeature[0]);
53+
}
54+
55+
@Override
56+
public Confirmation handleRequest(UUID sessionIndex, Request request) {
57+
if (request instanceof BatterySwapRequest) {
58+
return eventHandler.handleBatterySwapRequest(sessionIndex, (BatterySwapRequest) request);
59+
}
60+
return null;
61+
}
62+
63+
/**
64+
* Create a server {@link RequestBatterySwapRequest} with all required fields.
65+
*
66+
* @param idToken A case insensitive identifier to use for the authorization and the type of
67+
* authorization to support multiple forms of identifiers.
68+
* @param requestId Request id to match with BatterySwapRequest.
69+
* @return an instance of {@link RequestBatterySwapRequest}
70+
*/
71+
public RequestBatterySwapRequest createRequestBatterySwapRequest(
72+
IdToken idToken, Integer requestId) {
73+
return new RequestBatterySwapRequest(idToken, requestId);
74+
}
75+
}

ocpp-v2/src/main/java/eu/chargetime/ocpp/v21/feature/function/ServerTransactionsEventHandler.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,6 @@ of this software and associated documentation files (the "Software"), to deal
2929

3030
/** Call back handler for server events of the Transactions functional block. */
3131
public interface ServerTransactionsEventHandler {
32-
/**
33-
* Handle a {@link BatterySwapRequest} and return a {@link BatterySwapResponse}.
34-
*
35-
* @param sessionIndex identifier of the session on which the request was received.
36-
* @param request incoming {@link BatterySwapRequest} to handle.
37-
* @return outgoing {@link BatterySwapResponse} to reply with.
38-
*/
39-
BatterySwapResponse handleBatterySwapRequest(UUID sessionIndex, BatterySwapRequest request);
40-
4132
/**
4233
* Handle a {@link TransactionEventRequest} and return a {@link TransactionEventResponse}.
4334
*

ocpp-v2/src/main/java/eu/chargetime/ocpp/v21/feature/function/ServerTransactionsFunction.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ public class ServerTransactionsFunction implements Function {
4343
public ServerTransactionsFunction(ServerTransactionsEventHandler eventHandler) {
4444
this.eventHandler = eventHandler;
4545
features = new ArrayList<>();
46-
features.add(new BatterySwapFeature(this));
4746
features.add(new GetTransactionStatusFeature(null));
48-
features.add(new RequestBatterySwapFeature(null));
4947
features.add(new TransactionEventFeature(this));
5048
}
5149

@@ -56,9 +54,7 @@ public FunctionFeature[] getFeatureList() {
5654

5755
@Override
5856
public Confirmation handleRequest(UUID sessionIndex, Request request) {
59-
if (request instanceof BatterySwapRequest) {
60-
return eventHandler.handleBatterySwapRequest(sessionIndex, (BatterySwapRequest) request);
61-
} else if (request instanceof TransactionEventRequest) {
57+
if (request instanceof TransactionEventRequest) {
6258
return eventHandler.handleTransactionEventRequest(
6359
sessionIndex, (TransactionEventRequest) request);
6460
}
@@ -73,17 +69,4 @@ public Confirmation handleRequest(UUID sessionIndex, Request request) {
7369
public GetTransactionStatusRequest createGetTransactionStatusRequest() {
7470
return new GetTransactionStatusRequest();
7571
}
76-
77-
/**
78-
* Create a server {@link RequestBatterySwapRequest} with all required fields.
79-
*
80-
* @param idToken A case insensitive identifier to use for the authorization and the type of
81-
* authorization to support multiple forms of identifiers.
82-
* @param requestId Request id to match with BatterySwapRequest.
83-
* @return an instance of {@link RequestBatterySwapRequest}
84-
*/
85-
public RequestBatterySwapRequest createRequestBatterySwapRequest(
86-
IdToken idToken, Integer requestId) {
87-
return new RequestBatterySwapRequest(idToken, requestId);
88-
}
8972
}

0 commit comments

Comments
 (0)